This commit is contained in:
Lana Steuck 2011-03-10 20:51:07 -08:00
commit 59ccd77845
164 changed files with 4394 additions and 1107 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -280,7 +280,7 @@ public class AptJavaCompiler extends com.sun.tools.javac.main.JavaCompiler {
} }
if (verbose) if (verbose)
printVerbose("total", Long.toString(System.currentTimeMillis() - msec)); log.printVerbose("total", Long.toString(System.currentTimeMillis() - msec));
chk.reportDeferredDiagnostics(); chk.reportDeferredDiagnostics();

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,15 +48,15 @@ public class Bark extends Log {
* Preregisters factories to create and use a Bark object for use as * Preregisters factories to create and use a Bark object for use as
* both a Log and a Bark. * both a Log and a Bark.
*/ */
public static void preRegister(final Context context) { public static void preRegister(Context context) {
context.put(barkKey, new Context.Factory<Bark>() { context.put(barkKey, new Context.Factory<Bark>() {
public Bark make() { public Bark make(Context c) {
return new Bark(context); return new Bark(c);
} }
}); });
context.put(Log.logKey, new Context.Factory<Log>() { context.put(Log.logKey, new Context.Factory<Log>() {
public Log make() { public Log make(Context c) {
return Bark.instance(context); return Bark.instance(c);
} }
}); });
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -156,7 +156,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
if (index < 0) { if (index < 0) {
return htmlstr; return htmlstr;
} }
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
int previndex = 0; int previndex = 0;
while (true) { while (true) {
// Search for lowercase version of {@docRoot} // Search for lowercase version of {@docRoot}
@ -2279,7 +2279,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
*/ */
public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags, public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags,
boolean isFirstSentence) { boolean isFirstSentence) {
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
// Array of all possible inline tags for this javadoc run // Array of all possible inline tags for this javadoc run
configuration.tagletManager.checkTags(doc, tags, true); configuration.tagletManager.checkTags(doc, tags, true);
for (int i = 0; i < tags.length; i++) { for (int i = 0; i < tags.length; i++) {
@ -2315,7 +2315,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
StringTokenizer lines = new StringTokenizer(text, "\r\n", true); StringTokenizer lines = new StringTokenizer(text, "\r\n", true);
StringBuffer textBuff = new StringBuffer(); StringBuffer textBuff = new StringBuffer();
while (lines.hasMoreTokens()) { while (lines.hasMoreTokens()) {
StringBuffer line = new StringBuffer(lines.nextToken()); StringBuilder line = new StringBuilder(lines.nextToken());
Util.replaceTabs(configuration.sourcetab, line); Util.replaceTabs(configuration.sourcetab, line);
textBuff.append(line.toString()); textBuff.append(line.toString());
} }
@ -2473,7 +2473,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
return text; return text;
} }
int endindex = startindex + tobe.length(); int endindex = startindex + tobe.length();
StringBuffer replaced = new StringBuffer(); StringBuilder replaced = new StringBuilder();
if (startindex > 0) { if (startindex > 0) {
replaced.append(text.substring(0, startindex)); replaced.append(text.substring(0, startindex));
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,7 +30,6 @@ import java.util.*;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.tools.doclets.internal.toolkit.*; import com.sun.tools.doclets.internal.toolkit.*;
import com.sun.tools.doclets.internal.toolkit.taglets.*; import com.sun.tools.doclets.internal.toolkit.taglets.*;
import com.sun.tools.doclets.internal.toolkit.util.*;
import com.sun.tools.doclets.formats.html.markup.*; import com.sun.tools.doclets.formats.html.markup.*;
/** /**
@ -53,7 +52,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl
} }
public List<FieldDoc> members(ClassDoc cd) { public List<FieldDoc> members(ClassDoc cd) {
return Util.asList(cd.serializableFields()); return Arrays.asList(cd.serializableFields());
} }
protected void printTypeLinkNoDimension(Type type) { protected void printTypeLinkNoDimension(Type type) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -266,7 +266,7 @@ public class SourceToHTMLConverter {
private static void addLine(Content pre, String line, int tabLength, private static void addLine(Content pre, String line, int tabLength,
int currentLineNo) { int currentLineNo) {
if (line != null) { if (line != null) {
StringBuffer lineBuffer = new StringBuffer(Util.escapeHtmlChars(line)); StringBuilder lineBuffer = new StringBuilder(Util.escapeHtmlChars(line));
Util.replaceTabs(tabLength, lineBuffer); Util.replaceTabs(tabLength, lineBuffer);
pre.addContent(new RawHtml(lineBuffer.toString())); pre.addContent(new RawHtml(lineBuffer.toString()));
Content anchor = HtmlTree.A_NAME("line." + Integer.toString(currentLineNo)); Content anchor = HtmlTree.A_NAME("line." + Integer.toString(currentLineNo));

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -375,8 +375,7 @@ public class SerializedFormBuilder extends AbstractBuilder {
*/ */
public void buildFieldSerializationOverview(ClassDoc classDoc, Content classContentTree) { public void buildFieldSerializationOverview(ClassDoc classDoc, Content classContentTree) {
if (classDoc.definesSerializableFields()) { if (classDoc.definesSerializableFields()) {
FieldDoc serialPersistentField = FieldDoc serialPersistentField = classDoc.serializableFields()[0];
Util.asList(classDoc.serializableFields()).get(0);
// Check to see if there are inline comments, tags or deprecation // Check to see if there are inline comments, tags or deprecation
// information to be printed. // information to be printed.
if (fieldWriter.shouldPrintOverview(serialPersistentField)) { if (fieldWriter.shouldPrintOverview(serialPersistentField)) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -382,7 +382,7 @@ public class Util {
out.close(); out.close();
} }
} catch (IOException ie) { } catch (IOException ie) {
ie.printStackTrace(); ie.printStackTrace(System.err);
throw new DocletAbortException(); throw new DocletAbortException();
} }
} }
@ -399,12 +399,12 @@ public class Util {
String pkgPath = DirectoryManager.getDirectoryPath(pkgDoc); String pkgPath = DirectoryManager.getDirectoryPath(pkgDoc);
String completePath = new SourcePath(configuration.sourcepath). String completePath = new SourcePath(configuration.sourcepath).
getDirectory(pkgPath) + DirectoryManager.URL_FILE_SEPARATOR; getDirectory(pkgPath) + DirectoryManager.URL_FILE_SEPARATOR;
//Make sure that both paths are using the same seperators. //Make sure that both paths are using the same separators.
completePath = Util.replaceText(completePath, File.separator, completePath = Util.replaceText(completePath, File.separator,
DirectoryManager.URL_FILE_SEPARATOR); DirectoryManager.URL_FILE_SEPARATOR);
pkgPath = Util.replaceText(pkgPath, File.separator, pkgPath = Util.replaceText(pkgPath, File.separator,
DirectoryManager.URL_FILE_SEPARATOR); DirectoryManager.URL_FILE_SEPARATOR);
return completePath.substring(0, completePath.indexOf(pkgPath)); return completePath.substring(0, completePath.lastIndexOf(pkgPath));
} catch (Exception e){ } catch (Exception e){
return ""; return "";
} }
@ -536,15 +536,6 @@ public class Util {
findAllInterfaceTypes(results, (ClassDoc) type, true, configuration); findAllInterfaceTypes(results, (ClassDoc) type, true, configuration);
} }
public static <T extends ProgramElementDoc> List<T> asList(T[] members) {
List<T> list = new ArrayList<T>();
for (int i = 0; i < members.length; i++) {
list.add(members[i]);
}
return list;
}
/** /**
* Enclose in quotes, used for paths and filenames that contains spaces * Enclose in quotes, used for paths and filenames that contains spaces
*/ */
@ -583,14 +574,7 @@ public class Util {
if (oldStr == null || newStr == null || oldStr.equals(newStr)) { if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
return originalStr; return originalStr;
} }
StringBuffer result = new StringBuffer(originalStr); return originalStr.replace(oldStr, newStr);
int startIndex = 0;
while ((startIndex = result.indexOf(oldStr, startIndex)) != -1) {
result = result.replace(startIndex, startIndex + oldStr.length(),
newStr);
startIndex += newStr.length();
}
return result.toString();
} }
/** /**
@ -833,19 +817,17 @@ public class Util {
* @param tabLength the length of each tab. * @param tabLength the length of each tab.
* @param s the String to scan. * @param s the String to scan.
*/ */
public static void replaceTabs(int tabLength, StringBuffer s) { public static void replaceTabs(int tabLength, StringBuilder s) {
int index, col; if (whitespace == null || whitespace.length() < tabLength)
StringBuffer whitespace; whitespace = String.format("%" + tabLength + "s", " ");
while ((index = s.indexOf("\t")) != -1) { int index = 0;
whitespace = new StringBuffer(); while ((index = s.indexOf("\t", index)) != -1) {
col = index; int spaceCount = tabLength - index % tabLength;
do { s.replace(index, index+1, whitespace.substring(0, spaceCount));
whitespace.append(" "); index += spaceCount;
col++;
} while ((col%tabLength) != 0);
s.replace(index, index+1, whitespace.toString());
} }
} }
private static String whitespace;
/** /**
* The documentation for values() and valueOf() in Enums are set by the * The documentation for values() and valueOf() in Enums are set by the

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -157,19 +157,19 @@ public final class JavacTool implements JavaCompiler {
/** /**
* Register that a compilation is about to start. * Register that a compilation is about to start.
*/ */
void beginContext(final Context context) { void beginContext(Context context) {
if (compilationInProgress) if (compilationInProgress)
throw new IllegalStateException("Compilation in progress"); throw new IllegalStateException("Compilation in progress");
compilationInProgress = true; compilationInProgress = true;
final JavaFileManager givenFileManager = context.get(JavaFileManager.class); final JavaFileManager givenFileManager = context.get(JavaFileManager.class);
context.put(JavaFileManager.class, (JavaFileManager)null); context.put(JavaFileManager.class, (JavaFileManager)null);
context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() { context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
public JavaFileManager make() { public JavaFileManager make(Context c) {
if (givenFileManager != null) { if (givenFileManager != null) {
context.put(JavaFileManager.class, givenFileManager); c.put(JavaFileManager.class, givenFileManager);
return givenFileManager; return givenFileManager;
} else { } else {
return new JavacFileManager(context, true, null); return new JavacFileManager(c, true, null);
} }
} }
}); });

View file

@ -43,7 +43,7 @@ public class Flags {
private Flags() {} // uninstantiable private Flags() {} // uninstantiable
public static String toString(long flags) { public static String toString(long flags) {
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
String sep = ""; String sep = "";
for (Flag s : asFlagSet(flags)) { for (Flag s : asFlagSet(flags)) {
buf.append(sep); buf.append(sep);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -163,6 +163,7 @@ public class Kinds {
case PARAMETER: case PARAMETER:
case LOCAL_VARIABLE: case LOCAL_VARIABLE:
case EXCEPTION_PARAMETER: case EXCEPTION_PARAMETER:
case RESOURCE_VARIABLE:
return KindName.VAR; return KindName.VAR;
case CONSTRUCTOR: case CONSTRUCTOR:

View file

@ -831,6 +831,8 @@ public abstract class Symbol implements Element {
ClassType t = (ClassType)type; ClassType t = (ClassType)type;
if (t.interfaces_field == null) // FIXME: shouldn't be null if (t.interfaces_field == null) // FIXME: shouldn't be null
t.interfaces_field = List.nil(); t.interfaces_field = List.nil();
if (t.all_interfaces_field != null)
return Type.getModelTypes(t.all_interfaces_field);
return t.interfaces_field; return t.interfaces_field;
} else { } else {
return List.nil(); return List.nil();
@ -846,7 +848,7 @@ public abstract class Symbol implements Element {
// An interface has no superclass; its supertype is Object. // An interface has no superclass; its supertype is Object.
return t.isInterface() return t.isInterface()
? Type.noType ? Type.noType
: t.supertype_field; : t.supertype_field.getModelType();
} else { } else {
return Type.noType; return Type.noType;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,8 @@
package com.sun.tools.javac.code; package com.sun.tools.javac.code;
import java.util.*; import java.util.*;
import javax.lang.model.type.TypeVisitor;
import javax.lang.model.element.ElementVisitor;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
@ -345,7 +347,12 @@ public class Symtab {
target = Target.instance(context); target = Target.instance(context);
// Create the unknown type // Create the unknown type
unknownType = new Type(TypeTags.UNKNOWN, null); unknownType = new Type(TypeTags.UNKNOWN, null) {
@Override
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitUnknown(this, p);
}
};
// create the basic builtin symbols // create the basic builtin symbols
rootPackage = new PackageSymbol(names.empty, null); rootPackage = new PackageSymbol(names.empty, null);
@ -355,14 +362,21 @@ public class Symtab {
return messages.getLocalizedString("compiler.misc.unnamed.package"); return messages.getLocalizedString("compiler.misc.unnamed.package");
} }
}; };
noSymbol = new TypeSymbol(0, names.empty, Type.noType, rootPackage); noSymbol = new TypeSymbol(0, names.empty, Type.noType, rootPackage) {
public <R, P> R accept(ElementVisitor<R, P> v, P p) {
return v.visitUnknown(this, p);
}
};
noSymbol.kind = Kinds.NIL; noSymbol.kind = Kinds.NIL;
// create the error symbols // create the error symbols
errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage); errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage);
unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage);
errType = new ErrorType(errSymbol, Type.noType); errType = new ErrorType(errSymbol, Type.noType);
unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage);
unknownSymbol.members_field = new Scope.ErrorScope(unknownSymbol);
unknownSymbol.type = unknownType;
// initialize builtin types // initialize builtin types
initType(byteType, "byte", "Byte"); initType(byteType, "byte", "Byte");
initType(shortType, "short", "Short"); initType(shortType, "short", "Short");
@ -382,9 +396,11 @@ public class Symtab {
// VGJ // VGJ
boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol); boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol);
boundClass.members_field = new Scope.ErrorScope(boundClass);
// the builtin class of all methods // the builtin class of all methods
methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol); methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol);
methodClass.members_field = new Scope.ErrorScope(boundClass);
// Create class to hold all predefined constants and operations. // Create class to hold all predefined constants and operations.
predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage); predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage);

View file

@ -93,6 +93,22 @@ public class Type implements PrimitiveType {
return null; return null;
} }
/**
* Get the representation of this type used for modelling purposes.
* By default, this is itself. For ErrorType, a different value
* may be provided,
*/
public Type getModelType() {
return this;
}
public static List<Type> getModelTypes(List<Type> ts) {
ListBuffer<Type> lb = new ListBuffer<Type>();
for (Type t: ts)
lb.append(t.getModelType());
return lb.toList();
}
public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); } public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); }
/** Define a type given its tag and type symbol /** Define a type given its tag and type symbol
@ -190,7 +206,7 @@ public class Type implements PrimitiveType {
if (ts.isEmpty()) { if (ts.isEmpty()) {
return ""; return "";
} else { } else {
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
buf.append(ts.head.toString()); buf.append(ts.head.toString());
for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail) for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail)
buf.append(",").append(l.head.toString()); buf.append(",").append(l.head.toString());
@ -464,7 +480,7 @@ public class Type implements PrimitiveType {
boolean isPrintingBound = false; boolean isPrintingBound = false;
public String toString() { public String toString() {
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
s.append(kind.toString()); s.append(kind.toString());
if (kind != UNBOUND) if (kind != UNBOUND)
s.append(type); s.append(type);
@ -538,6 +554,10 @@ public class Type implements PrimitiveType {
*/ */
public List<Type> interfaces_field; public List<Type> interfaces_field;
/** All the interfaces of this class, including missing ones.
*/
public List<Type> all_interfaces_field;
public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) { public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
super(CLASS, tsym); super(CLASS, tsym);
this.outer_field = outer; this.outer_field = outer;
@ -578,7 +598,7 @@ public class Type implements PrimitiveType {
/** The Java source which this type represents. /** The Java source which this type represents.
*/ */
public String toString() { public String toString() {
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
if (getEnclosingType().tag == CLASS && tsym.owner.kind == TYP) { if (getEnclosingType().tag == CLASS && tsym.owner.kind == TYP) {
buf.append(getEnclosingType().toString()); buf.append(getEnclosingType().toString());
buf.append("."); buf.append(".");
@ -596,7 +616,7 @@ public class Type implements PrimitiveType {
//where //where
private String className(Symbol sym, boolean longform) { private String className(Symbol sym, boolean longform) {
if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) { if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) {
StringBuffer s = new StringBuffer(supertype_field.toString()); StringBuilder s = new StringBuilder(supertype_field.toString());
for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) { for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) {
s.append("&"); s.append("&");
s.append(is.head.toString()); s.append(is.head.toString());

View file

@ -1992,7 +1992,11 @@ public class Types {
* @return true if t is a sub signature of s. * @return true if t is a sub signature of s.
*/ */
public boolean isSubSignature(Type t, Type s) { public boolean isSubSignature(Type t, Type s) {
return hasSameArgs(t, s) || hasSameArgs(t, erasure(s)); return isSubSignature(t, s, true);
}
public boolean isSubSignature(Type t, Type s, boolean strict) {
return hasSameArgs(t, s, strict) || hasSameArgs(t, erasure(s), strict);
} }
/** /**
@ -2129,10 +2133,24 @@ public class Types {
* where correspondence is by position in the type parameter list. * where correspondence is by position in the type parameter list.
*/ */
public boolean hasSameArgs(Type t, Type s) { public boolean hasSameArgs(Type t, Type s) {
return hasSameArgs(t, s, true);
}
public boolean hasSameArgs(Type t, Type s, boolean strict) {
return hasSameArgs(t, s, strict ? hasSameArgs_strict : hasSameArgs_nonstrict);
}
private boolean hasSameArgs(Type t, Type s, TypeRelation hasSameArgs) {
return hasSameArgs.visit(t, s); return hasSameArgs.visit(t, s);
} }
// where // where
private TypeRelation hasSameArgs = new TypeRelation() { private class HasSameArgs extends TypeRelation {
boolean strict;
public HasSameArgs(boolean strict) {
this.strict = strict;
}
public Boolean visitType(Type t, Type s) { public Boolean visitType(Type t, Type s) {
throw new AssertionError(); throw new AssertionError();
@ -2147,7 +2165,7 @@ public class Types {
@Override @Override
public Boolean visitForAll(ForAll t, Type s) { public Boolean visitForAll(ForAll t, Type s) {
if (s.tag != FORALL) if (s.tag != FORALL)
return false; return strict ? false : visitMethodType(t.asMethodType(), s);
ForAll forAll = (ForAll)s; ForAll forAll = (ForAll)s;
return hasSameBounds(t, forAll) return hasSameBounds(t, forAll)
@ -2159,6 +2177,10 @@ public class Types {
return false; return false;
} }
}; };
TypeRelation hasSameArgs_strict = new HasSameArgs(true);
TypeRelation hasSameArgs_nonstrict = new HasSameArgs(false);
// </editor-fold> // </editor-fold>
// <editor-fold defaultstate="collapsed" desc="subst"> // <editor-fold defaultstate="collapsed" desc="subst">
@ -2534,7 +2556,7 @@ public class Types {
} }
// where // where
private String typaramsString(List<Type> tvars) { private String typaramsString(List<Type> tvars) {
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
s.append('<'); s.append('<');
boolean first = true; boolean first = true;
for (Type t : tvars) { for (Type t : tvars) {
@ -2545,7 +2567,7 @@ public class Types {
s.append('>'); s.append('>');
return s.toString(); return s.toString();
} }
private void appendTyparamString(TypeVar t, StringBuffer buf) { private void appendTyparamString(TypeVar t, StringBuilder buf) {
buf.append(t); buf.append(t);
if (t.bound == null || if (t.bound == null ||
t.bound.tsym.getQualifiedName() == names.java_lang_Object) t.bound.tsym.getQualifiedName() == names.java_lang_Object)
@ -2832,12 +2854,26 @@ public class Types {
while (ts.head.tag != CLASS && ts.head.tag != TYPEVAR) while (ts.head.tag != CLASS && ts.head.tag != TYPEVAR)
ts = ts.tail; ts = ts.tail;
Assert.check(!ts.isEmpty()); Assert.check(!ts.isEmpty());
List<Type> cl = closure(ts.head); //step 1 - compute erased candidate set (EC)
List<Type> cl = erasedSupertypes(ts.head);
for (Type t : ts.tail) { for (Type t : ts.tail) {
if (t.tag == CLASS || t.tag == TYPEVAR) if (t.tag == CLASS || t.tag == TYPEVAR)
cl = intersect(cl, closure(t)); cl = intersect(cl, erasedSupertypes(t));
} }
return compoundMin(cl); //step 2 - compute minimal erased candidate set (MEC)
List<Type> mec = closureMin(cl);
//step 3 - for each element G in MEC, compute lci(Inv(G))
List<Type> candidates = List.nil();
for (Type erasedSupertype : mec) {
List<Type> lci = List.of(asSuper(ts.head, erasedSupertype.tsym));
for (Type t : ts) {
lci = intersect(lci, List.of(asSuper(t, erasedSupertype.tsym)));
}
candidates = candidates.appendList(lci);
}
//step 4 - let MEC be { G1, G2 ... Gn }, then we have that
//lub = lci(Inv(G1)) & lci(Inv(G2)) & ... & lci(Inv(Gn))
return compoundMin(candidates);
default: default:
// calculate lub(A, B[]) // calculate lub(A, B[])
@ -2851,6 +2887,18 @@ public class Types {
} }
} }
// where // where
List<Type> erasedSupertypes(Type t) {
ListBuffer<Type> buf = lb();
for (Type sup : closure(t)) {
if (sup.tag == TYPEVAR) {
buf.append(sup);
} else {
buf.append(erasure(sup));
}
}
return buf.toList();
}
private Type arraySuperType = null; private Type arraySuperType = null;
private Type arraySuperType() { private Type arraySuperType() {
// initialized lazily to avoid problems during compiler startup // initialized lazily to avoid problems during compiler startup

View file

@ -1425,7 +1425,7 @@ public class Attr extends JCTree.Visitor {
// qualifier omitted; check for existence // qualifier omitted; check for existence
// of an appropriate implicit qualifier. // of an appropriate implicit qualifier.
rs.resolveImplicitThis(tree.meth.pos(), rs.resolveImplicitThis(tree.meth.pos(),
localEnv, site); localEnv, site, true);
} }
} else if (tree.meth.getTag() == JCTree.SELECT) { } else if (tree.meth.getTag() == JCTree.SELECT) {
log.error(tree.meth.pos(), "illegal.qual.not.icls", log.error(tree.meth.pos(), "illegal.qual.not.icls",
@ -1581,15 +1581,7 @@ public class Attr extends JCTree.Visitor {
// symbol + type back into the attributed tree. // symbol + type back into the attributed tree.
Type clazztype = attribType(clazz, env); Type clazztype = attribType(clazz, env);
Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype, cdef != null); Pair<Scope,Scope> mapping = getSyntheticScopeMapping(clazztype, cdef != null);
if (!TreeInfo.isDiamond(tree)) { clazztype = chk.checkDiamond(tree, clazztype);
clazztype = chk.checkClassType(
tree.clazz.pos(), clazztype, true);
} else if (!clazztype.isErroneous() &&
!clazztype.tsym.type.isParameterized()) {
log.error(tree.clazz.pos(),
"cant.apply.diamond.1",
clazztype, diags.fragment("diamond.non.generic", clazztype));
}
chk.validate(clazz, localEnv); chk.validate(clazz, localEnv);
if (tree.encl != null) { if (tree.encl != null) {
// We have to work in this case to store // We have to work in this case to store
@ -1614,10 +1606,12 @@ public class Attr extends JCTree.Visitor {
List<Type> argtypes = attribArgs(tree.args, localEnv); List<Type> argtypes = attribArgs(tree.args, localEnv);
List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv);
if (TreeInfo.isDiamond(tree) && clazztype.tsym.type.isParameterized()) { if (TreeInfo.isDiamond(tree) && !clazztype.isErroneous()) {
clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes); clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes);
clazz.type = clazztype; clazz.type = clazztype;
} else if (allowDiamondFinder && } else if (allowDiamondFinder &&
tree.def == null &&
!clazztype.isErroneous() &&
clazztype.getTypeArguments().nonEmpty() && clazztype.getTypeArguments().nonEmpty() &&
findDiamonds) { findDiamonds) {
boolean prevDeferDiags = log.deferDiagnostics; boolean prevDeferDiags = log.deferDiagnostics;
@ -1641,8 +1635,7 @@ public class Attr extends JCTree.Visitor {
if (inferred != null && if (inferred != null &&
!inferred.isErroneous() && !inferred.isErroneous() &&
inferred.tag == CLASS && inferred.tag == CLASS &&
types.isAssignable(inferred, pt.tag == NONE ? clazztype : pt, Warner.noWarnings) && types.isAssignable(inferred, pt.tag == NONE ? clazztype : pt, Warner.noWarnings)) {
chk.checkDiamond((ClassType)inferred).isEmpty()) {
String key = types.isSameType(clazztype, inferred) ? String key = types.isSameType(clazztype, inferred) ?
"diamond.redundant.args" : "diamond.redundant.args" :
"diamond.redundant.args.1"; "diamond.redundant.args.1";
@ -1857,34 +1850,9 @@ public class Attr extends JCTree.Visitor {
ex.diagnostic); ex.diagnostic);
} }
} }
clazztype = chk.checkClassType(tree.clazz.pos(), return chk.checkClassType(tree.clazz.pos(),
clazztype, clazztype,
true); true);
if (clazztype.tag == CLASS) {
List<Type> invalidDiamondArgs = chk.checkDiamond((ClassType)clazztype);
if (!clazztype.isErroneous() && invalidDiamondArgs.nonEmpty()) {
//one or more types inferred in the previous steps is either a
//captured type or an intersection type --- we need to report an error.
String subkey = invalidDiamondArgs.size() > 1 ?
"diamond.invalid.args" :
"diamond.invalid.arg";
//The error message is of the kind:
//
//cannot infer type arguments for {clazztype}<>;
//reason: {subkey}
//
//where subkey is a fragment of the kind:
//
//type argument(s) {invalidDiamondArgs} inferred for {clazztype}<> is not allowed in this context
log.error(tree.clazz.pos(),
"cant.apply.diamond.1",
diags.fragment("diamond", clazztype.tsym),
diags.fragment(subkey,
invalidDiamondArgs,
diags.fragment("diamond", clazztype.tsym)));
}
}
return clazztype;
} }
/** Creates a synthetic scope containing fake generic constructors. /** Creates a synthetic scope containing fake generic constructors.
@ -2806,7 +2774,7 @@ public class Attr extends JCTree.Visitor {
sym.location()); sym.location());
owntype = new MethodType(owntype.getParameterTypes(), owntype = new MethodType(owntype.getParameterTypes(),
types.erasure(owntype.getReturnType()), types.erasure(owntype.getReturnType()),
owntype.getThrownTypes(), types.erasure(owntype.getThrownTypes()),
syms.methodClass); syms.methodClass);
} }
if (useVarargs) { if (useVarargs) {
@ -2980,7 +2948,7 @@ public class Attr extends JCTree.Visitor {
// (see comment for TypeVar.bound). // (see comment for TypeVar.bound).
// In this case, generate a class tree that represents the // In this case, generate a class tree that represents the
// bound class, ... // bound class, ...
JCTree extending; JCExpression extending;
List<JCExpression> implementing; List<JCExpression> implementing;
if ((bs.head.tsym.flags() & INTERFACE) == 0) { if ((bs.head.tsym.flags() & INTERFACE) == 0) {
extending = tree.bounds.head; extending = tree.bounds.head;

View file

@ -664,40 +664,25 @@ public class Check {
return true; return true;
} }
/** Check that the type inferred using the diamond operator does not contain /** Check that usage of diamond operator is correct (i.e. diamond should not
* non-denotable types such as captured types or intersection types. * be used with non-generic classes or in anonymous class creation expressions)
* @param t the type inferred using the diamond operator
*/ */
List<Type> checkDiamond(ClassType t) { Type checkDiamond(JCNewClass tree, Type t) {
DiamondTypeChecker dtc = new DiamondTypeChecker(); if (!TreeInfo.isDiamond(tree) ||
ListBuffer<Type> buf = ListBuffer.lb(); t.isErroneous()) {
for (Type arg : t.getTypeArguments()) { return checkClassType(tree.clazz.pos(), t, true);
if (!dtc.visit(arg, null)) { } else if (tree.def != null) {
buf.append(arg); log.error(tree.clazz.pos(),
} "cant.apply.diamond.1",
} t, diags.fragment("diamond.and.anon.class", t));
return buf.toList(); return types.createErrorType(t);
} } else if (!t.tsym.type.isParameterized()) {
log.error(tree.clazz.pos(),
static class DiamondTypeChecker extends Types.SimpleVisitor<Boolean, Void> { "cant.apply.diamond.1",
public Boolean visitType(Type t, Void s) { t, diags.fragment("diamond.non.generic", t));
return true; return types.createErrorType(t);
} } else {
@Override return t;
public Boolean visitClassType(ClassType t, Void s) {
if (t.isCompound()) {
return false;
}
for (Type targ : t.getTypeArguments()) {
if (!visit(targ, s)) {
return false;
}
}
return true;
}
@Override
public Boolean visitCapturedType(CapturedType t, Void s) {
return false;
} }
} }
@ -1679,7 +1664,8 @@ public class Check {
"(" + types.memberType(t2, s2).getParameterTypes() + ")"); "(" + types.memberType(t2, s2).getParameterTypes() + ")");
return s2; return s2;
} }
} else if (checkNameClash((ClassSymbol)site.tsym, s1, s2)) { } else if (checkNameClash((ClassSymbol)site.tsym, s1, s2) &&
!checkCommonOverriderIn(s1, s2, site)) {
log.error(pos, log.error(pos,
"name.clash.same.erasure.no.override", "name.clash.same.erasure.no.override",
s1, s1.location(), s1, s1.location(),
@ -2113,7 +2099,7 @@ public class Check {
if (s1 == s2 || !sym.overrides(s2, site.tsym, types, false)) continue; if (s1 == s2 || !sym.overrides(s2, site.tsym, types, false)) continue;
//if (i) the signature of 'sym' is not a subsignature of m1 (seen as //if (i) the signature of 'sym' is not a subsignature of m1 (seen as
//a member of 'site') and (ii) m1 has the same erasure as m2, issue an error //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error
if (!types.isSubSignature(sym.type, types.memberType(site, s1)) && if (!types.isSubSignature(sym.type, types.memberType(site, s1), false) &&
types.hasSameArgs(s1.erasure(types), s2.erasure(types))) { types.hasSameArgs(s1.erasure(types), s2.erasure(types))) {
sym.flags_field |= CLASH; sym.flags_field |= CLASH;
String key = s2 == sym ? String key = s2 == sym ?
@ -2145,7 +2131,7 @@ public class Check {
for (Symbol s : types.membersClosure(site).getElementsByName(sym.name, cf)) { for (Symbol s : types.membersClosure(site).getElementsByName(sym.name, cf)) {
//if (i) the signature of 'sym' is not a subsignature of m1 (seen as //if (i) the signature of 'sym' is not a subsignature of m1 (seen as
//a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error
if (!types.isSubSignature(sym.type, types.memberType(site, s)) && if (!types.isSubSignature(sym.type, types.memberType(site, s), false) &&
types.hasSameArgs(s.erasure(types), sym.erasure(types))) { types.hasSameArgs(s.erasure(types), sym.erasure(types))) {
log.error(pos, log.error(pos,
"name.clash.same.erasure.no.hide", "name.clash.same.erasure.no.hide",
@ -2666,7 +2652,7 @@ public class Check {
if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS)) { if ((sym.flags() & VARARGS) != (e.sym.flags() & VARARGS)) {
varargsDuplicateError(pos, sym, e.sym); varargsDuplicateError(pos, sym, e.sym);
return true; return true;
} else if (sym.kind == MTH && !hasSameSignature(sym.type, e.sym.type)) { } else if (sym.kind == MTH && !types.hasSameArgs(sym.type, e.sym.type, false)) {
duplicateErasureError(pos, sym, e.sym); duplicateErasureError(pos, sym, e.sym);
sym.flags_field |= CLASH; sym.flags_field |= CLASH;
return true; return true;
@ -2678,15 +2664,6 @@ public class Check {
} }
return true; return true;
} }
//where
boolean hasSameSignature(Type mt1, Type mt2) {
if (mt1.tag == FORALL && mt2.tag == FORALL) {
ForAll fa1 = (ForAll)mt1;
ForAll fa2 = (ForAll)mt2;
mt2 = types.subst(fa2, fa2.tvars, fa1.tvars);
}
return types.hasSameArgs(mt1.asMethodType(), mt2.asMethodType());
}
/** Report duplicate declaration error. /** Report duplicate declaration error.
*/ */

View file

@ -272,7 +272,7 @@ public class Flow extends TreeScanner {
/** The list of unreferenced automatic resources. /** The list of unreferenced automatic resources.
*/ */
Map<VarSymbol, JCVariableDecl> unrefdResources; Scope unrefdResources;
/** Set when processing a loop body the second time for DU analysis. */ /** Set when processing a loop body the second time for DU analysis. */
boolean loopPassTwo = false; boolean loopPassTwo = false;
@ -804,14 +804,16 @@ public class Flow extends TreeScanner {
ListBuffer<PendingExit> prevPendingExits = pendingExits; ListBuffer<PendingExit> prevPendingExits = pendingExits;
boolean prevLoopPassTwo = loopPassTwo; boolean prevLoopPassTwo = loopPassTwo;
pendingExits = new ListBuffer<PendingExit>(); pendingExits = new ListBuffer<PendingExit>();
int prevErrors = log.nerrors;
do { do {
Bits uninitsEntry = uninits.dup(); Bits uninitsEntry = uninits.dup();
uninitsEntry.excludeFrom(nextadr);
scanStat(tree.body); scanStat(tree.body);
alive |= resolveContinues(tree); alive |= resolveContinues(tree);
scanCond(tree.cond); scanCond(tree.cond);
if (log.nerrors != 0 || if (log.nerrors != prevErrors ||
loopPassTwo || loopPassTwo ||
uninitsEntry.diffSet(uninitsWhenTrue).nextBit(firstadr)==-1) uninitsEntry.dup().diffSet(uninitsWhenTrue).nextBit(firstadr)==-1)
break; break;
inits = initsWhenTrue; inits = initsWhenTrue;
uninits = uninitsEntry.andSet(uninitsWhenTrue); uninits = uninitsEntry.andSet(uninitsWhenTrue);
@ -831,8 +833,10 @@ public class Flow extends TreeScanner {
Bits initsCond; Bits initsCond;
Bits uninitsCond; Bits uninitsCond;
pendingExits = new ListBuffer<PendingExit>(); pendingExits = new ListBuffer<PendingExit>();
int prevErrors = log.nerrors;
do { do {
Bits uninitsEntry = uninits.dup(); Bits uninitsEntry = uninits.dup();
uninitsEntry.excludeFrom(nextadr);
scanCond(tree.cond); scanCond(tree.cond);
initsCond = initsWhenFalse; initsCond = initsWhenFalse;
uninitsCond = uninitsWhenFalse; uninitsCond = uninitsWhenFalse;
@ -841,9 +845,9 @@ public class Flow extends TreeScanner {
alive = !tree.cond.type.isFalse(); alive = !tree.cond.type.isFalse();
scanStat(tree.body); scanStat(tree.body);
alive |= resolveContinues(tree); alive |= resolveContinues(tree);
if (log.nerrors != 0 || if (log.nerrors != prevErrors ||
loopPassTwo || loopPassTwo ||
uninitsEntry.diffSet(uninits).nextBit(firstadr) == -1) uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1)
break; break;
uninits = uninitsEntry.andSet(uninits); uninits = uninitsEntry.andSet(uninits);
loopPassTwo = true; loopPassTwo = true;
@ -864,8 +868,10 @@ public class Flow extends TreeScanner {
Bits initsCond; Bits initsCond;
Bits uninitsCond; Bits uninitsCond;
pendingExits = new ListBuffer<PendingExit>(); pendingExits = new ListBuffer<PendingExit>();
int prevErrors = log.nerrors;
do { do {
Bits uninitsEntry = uninits.dup(); Bits uninitsEntry = uninits.dup();
uninitsEntry.excludeFrom(nextadr);
if (tree.cond != null) { if (tree.cond != null) {
scanCond(tree.cond); scanCond(tree.cond);
initsCond = initsWhenFalse; initsCond = initsWhenFalse;
@ -883,7 +889,7 @@ public class Flow extends TreeScanner {
scanStat(tree.body); scanStat(tree.body);
alive |= resolveContinues(tree); alive |= resolveContinues(tree);
scan(tree.step); scan(tree.step);
if (log.nerrors != 0 || if (log.nerrors != prevErrors ||
loopPassTwo || loopPassTwo ||
uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1) uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1)
break; break;
@ -897,8 +903,6 @@ public class Flow extends TreeScanner {
alive = resolveBreaks(tree, prevPendingExits) || alive = resolveBreaks(tree, prevPendingExits) ||
tree.cond != null && !tree.cond.type.isTrue(); tree.cond != null && !tree.cond.type.isTrue();
nextadr = nextadrPrev; nextadr = nextadrPrev;
inits.excludeFrom(nextadr);
uninits.excludeFrom(nextadr);
} }
public void visitForeachLoop(JCEnhancedForLoop tree) { public void visitForeachLoop(JCEnhancedForLoop tree) {
@ -913,13 +917,15 @@ public class Flow extends TreeScanner {
letInit(tree.pos(), tree.var.sym); letInit(tree.pos(), tree.var.sym);
pendingExits = new ListBuffer<PendingExit>(); pendingExits = new ListBuffer<PendingExit>();
int prevErrors = log.nerrors;
do { do {
Bits uninitsEntry = uninits.dup(); Bits uninitsEntry = uninits.dup();
uninitsEntry.excludeFrom(nextadr);
scanStat(tree.body); scanStat(tree.body);
alive |= resolveContinues(tree); alive |= resolveContinues(tree);
if (log.nerrors != 0 || if (log.nerrors != prevErrors ||
loopPassTwo || loopPassTwo ||
uninitsEntry.diffSet(uninits).nextBit(firstadr) == -1) uninitsEntry.dup().diffSet(uninits).nextBit(firstadr) == -1)
break; break;
uninits = uninitsEntry.andSet(uninits); uninits = uninitsEntry.andSet(uninits);
loopPassTwo = true; loopPassTwo = true;
@ -992,7 +998,6 @@ public class Flow extends TreeScanner {
public void visitTry(JCTry tree) { public void visitTry(JCTry tree) {
List<Type> caughtPrev = caught; List<Type> caughtPrev = caught;
List<Type> thrownPrev = thrown; List<Type> thrownPrev = thrown;
Map<VarSymbol, JCVariableDecl> unrefdResourcesPrev = unrefdResources;
thrown = List.nil(); thrown = List.nil();
for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
List<JCExpression> subClauses = TreeInfo.isMultiCatch(l.head) ? List<JCExpression> subClauses = TreeInfo.isMultiCatch(l.head) ?
@ -1002,17 +1007,18 @@ public class Flow extends TreeScanner {
caught = chk.incl(ct.type, caught); caught = chk.incl(ct.type, caught);
} }
} }
ListBuffer<JCVariableDecl> resourceVarDecls = ListBuffer.lb();
Bits uninitsTryPrev = uninitsTry; Bits uninitsTryPrev = uninitsTry;
ListBuffer<PendingExit> prevPendingExits = pendingExits; ListBuffer<PendingExit> prevPendingExits = pendingExits;
pendingExits = new ListBuffer<PendingExit>(); pendingExits = new ListBuffer<PendingExit>();
Bits initsTry = inits.dup(); Bits initsTry = inits.dup();
uninitsTry = uninits.dup(); uninitsTry = uninits.dup();
unrefdResources = new LinkedHashMap<VarSymbol, JCVariableDecl>();
for (JCTree resource : tree.resources) { for (JCTree resource : tree.resources) {
if (resource instanceof JCVariableDecl) { if (resource instanceof JCVariableDecl) {
JCVariableDecl vdecl = (JCVariableDecl) resource; JCVariableDecl vdecl = (JCVariableDecl) resource;
visitVarDef(vdecl); visitVarDef(vdecl);
unrefdResources.put(vdecl.sym, vdecl); unrefdResources.enter(vdecl.sym);
resourceVarDecls.append(vdecl);
} else if (resource instanceof JCExpression) { } else if (resource instanceof JCExpression) {
scanExpr((JCExpression) resource); scanExpr((JCExpression) resource);
} else { } else {
@ -1049,11 +1055,14 @@ public class Flow extends TreeScanner {
Bits uninitsEnd = uninits; Bits uninitsEnd = uninits;
int nextadrCatch = nextadr; int nextadrCatch = nextadr;
if (!unrefdResources.isEmpty() && if (!resourceVarDecls.isEmpty() &&
lint.isEnabled(Lint.LintCategory.TRY)) { lint.isEnabled(Lint.LintCategory.TRY)) {
for (Map.Entry<VarSymbol, JCVariableDecl> e : unrefdResources.entrySet()) { for (JCVariableDecl resVar : resourceVarDecls) {
log.warning(Lint.LintCategory.TRY, e.getValue().pos(), if (unrefdResources.includes(resVar.sym)) {
"try.resource.not.referenced", e.getKey()); log.warning(Lint.LintCategory.TRY, resVar.pos(),
"try.resource.not.referenced", resVar.sym);
unrefdResources.remove(resVar.sym);
}
} }
} }
@ -1143,7 +1152,6 @@ public class Flow extends TreeScanner {
while (exits.nonEmpty()) pendingExits.append(exits.next()); while (exits.nonEmpty()) pendingExits.append(exits.next());
} }
uninitsTry.andSet(uninitsTryPrev).andSet(uninits); uninitsTry.andSet(uninitsTryPrev).andSet(uninits);
unrefdResources = unrefdResourcesPrev;
} }
public void visitConditional(JCConditional tree) { public void visitConditional(JCConditional tree) {
@ -1369,10 +1377,8 @@ public class Flow extends TreeScanner {
} }
void referenced(Symbol sym) { void referenced(Symbol sym) {
if (unrefdResources != null && unrefdResources.containsKey(sym)) {
unrefdResources.remove(sym); unrefdResources.remove(sym);
} }
}
public void visitTypeCast(JCTypeCast tree) { public void visitTypeCast(JCTypeCast tree) {
super.visitTypeCast(tree); super.visitTypeCast(tree);
@ -1430,6 +1436,7 @@ public class Flow extends TreeScanner {
alive = true; alive = true;
this.thrown = this.caught = null; this.thrown = this.caught = null;
this.classDef = null; this.classDef = null;
unrefdResources = new Scope(env.enclClass.sym);
scan(tree); scan(tree);
} finally { } finally {
// note that recursive invocations of this method fail hard // note that recursive invocations of this method fail hard
@ -1444,6 +1451,7 @@ public class Flow extends TreeScanner {
this.make = null; this.make = null;
this.thrown = this.caught = null; this.thrown = this.caught = null;
this.classDef = null; this.classDef = null;
unrefdResources = null;
} }
} }
} }

View file

@ -465,10 +465,9 @@ public class Infer {
// quantify result type with them // quantify result type with them
final List<Type> inferredTypes = insttypes.toList(); final List<Type> inferredTypes = insttypes.toList();
final List<Type> all_tvars = tvars; //this is the wrong tvars final List<Type> all_tvars = tvars; //this is the wrong tvars
final MethodType mt2 = new MethodType(mt.argtypes, null, mt.thrown, syms.methodClass); return new UninferredMethodType(mt, restvars.toList()) {
mt2.restype = new ForAll(restvars.toList(), mt.restype) {
@Override @Override
public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) { List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
for (Type t : restundet.toList()) { for (Type t : restundet.toList()) {
UndetVar uv = (UndetVar)t; UndetVar uv = (UndetVar)t;
if (uv.qtype == tv) { if (uv.qtype == tv) {
@ -481,21 +480,17 @@ public class Infer {
} }
return List.nil(); return List.nil();
} }
@Override @Override
public Type inst(List<Type> inferred, Types types) throws NoInstanceException { void check(List<Type> inferred, Types types) throws NoInstanceException {
List<Type> formals = types.subst(mt2.argtypes, tvars, inferred);
// check that actuals conform to inferred formals // check that actuals conform to inferred formals
checkArgumentsAcceptable(env, capturedArgs, formals, allowBoxing, useVarargs, warn); checkArgumentsAcceptable(env, capturedArgs, getParameterTypes(), allowBoxing, useVarargs, warn);
// check that inferred bounds conform to their bounds // check that inferred bounds conform to their bounds
checkWithinBounds(all_tvars, checkWithinBounds(all_tvars,
types.subst(inferredTypes, tvars, inferred), warn); types.subst(inferredTypes, tvars, inferred), warn);
if (useVarargs) { if (useVarargs) {
chk.checkVararg(env.tree.pos(), formals, msym); chk.checkVararg(env.tree.pos(), getParameterTypes(), msym);
} }
return super.inst(inferred, types);
}}; }};
return mt2;
} }
else { else {
// check that actuals conform to inferred formals // check that actuals conform to inferred formals
@ -506,6 +501,62 @@ public class Infer {
} }
//where //where
/**
* A delegated type representing a partially uninferred method type.
* The return type of a partially uninferred method type is a ForAll
* type - when the return type is instantiated (see Infer.instantiateExpr)
* the underlying method type is also updated.
*/
static abstract class UninferredMethodType extends DelegatedType {
final List<Type> tvars;
public UninferredMethodType(MethodType mtype, List<Type> tvars) {
super(METHOD, new MethodType(mtype.argtypes, null, mtype.thrown, mtype.tsym));
this.tvars = tvars;
asMethodType().restype = new UninferredReturnType(tvars, mtype.restype);
}
@Override
public MethodType asMethodType() {
return qtype.asMethodType();
}
@Override
public Type map(Mapping f) {
return qtype.map(f);
}
void instantiateReturnType(Type restype, List<Type> inferred, Types types) throws NoInstanceException {
//update method type with newly inferred type-arguments
qtype = new MethodType(types.subst(getParameterTypes(), tvars, inferred),
restype,
types.subst(UninferredMethodType.this.getThrownTypes(), tvars, inferred),
UninferredMethodType.this.qtype.tsym);
check(inferred, types);
}
abstract void check(List<Type> inferred, Types types) throws NoInstanceException;
abstract List<Type> getConstraints(TypeVar tv, ConstraintKind ck);
class UninferredReturnType extends ForAll {
public UninferredReturnType(List<Type> tvars, Type restype) {
super(tvars, restype);
}
@Override
public Type inst(List<Type> actuals, Types types) {
Type newRestype = super.inst(actuals, types);
instantiateReturnType(newRestype, actuals, types);
return newRestype;
}
@Override
public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
return UninferredMethodType.this.getConstraints(tv, ck);
}
}
}
private void checkArgumentsAcceptable(Env<AttrContext> env, List<Type> actuals, List<Type> formals, private void checkArgumentsAcceptable(Env<AttrContext> env, List<Type> actuals, List<Type> formals,
boolean allowBoxing, boolean useVarargs, Warner warn) { boolean allowBoxing, boolean useVarargs, Warner warn) {
try { try {

View file

@ -2817,8 +2817,8 @@ public class Lower extends TreeTranslator {
// local class or this() call // local class or this() call
thisArg = makeThis(tree.meth.pos(), c.type.getEnclosingType().tsym); thisArg = makeThis(tree.meth.pos(), c.type.getEnclosingType().tsym);
} else { } else {
// super() call of nested class // super() call of nested class - never pick 'this'
thisArg = makeOwnerThis(tree.meth.pos(), c, false); thisArg = makeOwnerThisN(tree.meth.pos(), c, false);
} }
tree.args = tree.args.prepend(thisArg); tree.args = tree.args.prepend(thisArg);
} }

View file

@ -889,10 +889,11 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
: (c.fullname == names.java_lang_Object) : (c.fullname == names.java_lang_Object)
? Type.noType ? Type.noType
: syms.objectType; : syms.objectType;
ct.supertype_field = supertype; ct.supertype_field = modelMissingTypes(supertype, tree.extending, false);
// Determine interfaces. // Determine interfaces.
ListBuffer<Type> interfaces = new ListBuffer<Type>(); ListBuffer<Type> interfaces = new ListBuffer<Type>();
ListBuffer<Type> all_interfaces = null; // lazy init
Set<Type> interfaceSet = new HashSet<Type>(); Set<Type> interfaceSet = new HashSet<Type>();
List<JCExpression> interfaceTrees = tree.implementing; List<JCExpression> interfaceTrees = tree.implementing;
if ((tree.mods.flags & Flags.ENUM) != 0 && target.compilerBootstrap(c)) { if ((tree.mods.flags & Flags.ENUM) != 0 && target.compilerBootstrap(c)) {
@ -909,13 +910,22 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
Type i = attr.attribBase(iface, baseEnv, false, true, true); Type i = attr.attribBase(iface, baseEnv, false, true, true);
if (i.tag == CLASS) { if (i.tag == CLASS) {
interfaces.append(i); interfaces.append(i);
if (all_interfaces != null) all_interfaces.append(i);
chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet); chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet);
} else {
if (all_interfaces == null)
all_interfaces = new ListBuffer<Type>().appendList(interfaces);
all_interfaces.append(modelMissingTypes(i, iface, true));
} }
} }
if ((c.flags_field & ANNOTATION) != 0) if ((c.flags_field & ANNOTATION) != 0) {
ct.interfaces_field = List.of(syms.annotationType); ct.interfaces_field = List.of(syms.annotationType);
else ct.all_interfaces_field = ct.interfaces_field;
} else {
ct.interfaces_field = interfaces.toList(); ct.interfaces_field = interfaces.toList();
ct.all_interfaces_field = (all_interfaces == null)
? ct.interfaces_field : all_interfaces.toList();
}
if (c.fullname == names.java_lang_Object) { if (c.fullname == names.java_lang_Object) {
if (tree.extending != null) { if (tree.extending != null) {
@ -1066,6 +1076,125 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
return result; return result;
} }
Type modelMissingTypes(Type t, final JCExpression tree, final boolean interfaceExpected) {
if (t.tag != ERROR)
return t;
return new ErrorType(((ErrorType) t).getOriginalType(), t.tsym) {
private Type modelType;
@Override
public Type getModelType() {
if (modelType == null)
modelType = new Synthesizer(getOriginalType(), interfaceExpected).visit(tree);
return modelType;
}
};
}
// where
private class Synthesizer extends JCTree.Visitor {
Type originalType;
boolean interfaceExpected;
List<ClassSymbol> synthesizedSymbols = List.nil();
Type result;
Synthesizer(Type originalType, boolean interfaceExpected) {
this.originalType = originalType;
this.interfaceExpected = interfaceExpected;
}
Type visit(JCTree tree) {
tree.accept(this);
return result;
}
List<Type> visit(List<? extends JCTree> trees) {
ListBuffer<Type> lb = new ListBuffer<Type>();
for (JCTree t: trees)
lb.append(visit(t));
return lb.toList();
}
@Override
public void visitTree(JCTree tree) {
result = syms.errType;
}
@Override
public void visitIdent(JCIdent tree) {
if (tree.type.tag != ERROR) {
result = tree.type;
} else {
result = synthesizeClass(tree.name, syms.unnamedPackage).type;
}
}
@Override
public void visitSelect(JCFieldAccess tree) {
if (tree.type.tag != ERROR) {
result = tree.type;
} else {
Type selectedType;
boolean prev = interfaceExpected;
try {
interfaceExpected = false;
selectedType = visit(tree.selected);
} finally {
interfaceExpected = prev;
}
ClassSymbol c = synthesizeClass(tree.name, selectedType.tsym);
result = c.type;
}
}
@Override
public void visitTypeApply(JCTypeApply tree) {
if (tree.type.tag != ERROR) {
result = tree.type;
} else {
ClassType clazzType = (ClassType) visit(tree.clazz);
if (synthesizedSymbols.contains(clazzType.tsym))
synthesizeTyparams((ClassSymbol) clazzType.tsym, tree.arguments.size());
final List<Type> actuals = visit(tree.arguments);
result = new ErrorType(tree.type, clazzType.tsym) {
@Override
public List<Type> getTypeArguments() {
return actuals;
}
};
}
}
ClassSymbol synthesizeClass(Name name, Symbol owner) {
int flags = interfaceExpected ? INTERFACE : 0;
ClassSymbol c = new ClassSymbol(flags, name, owner);
c.members_field = new Scope.ErrorScope(c);
c.type = new ErrorType(originalType, c) {
@Override
public List<Type> getTypeArguments() {
return typarams_field;
}
};
synthesizedSymbols = synthesizedSymbols.prepend(c);
return c;
}
void synthesizeTyparams(ClassSymbol sym, int n) {
ClassType ct = (ClassType) sym.type;
Assert.check(ct.typarams_field.isEmpty());
if (n == 1) {
TypeVar v = new TypeVar(names.fromString("T"), sym, syms.botType);
ct.typarams_field = ct.typarams_field.prepend(v);
} else {
for (int i = n; i > 0; i--) {
TypeVar v = new TypeVar(names.fromString("T" + i), sym, syms.botType);
ct.typarams_field = ct.typarams_field.prepend(v);
}
}
}
}
/* *************************************************************************** /* ***************************************************************************
* tree building * tree building
****************************************************************************/ ****************************************************************************/

View file

@ -45,7 +45,9 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
import javax.lang.model.element.ElementVisitor; import javax.lang.model.element.ElementVisitor;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
/** Helper class for name resolution, used mostly by the attribution phase. /** Helper class for name resolution, used mostly by the attribution phase.
* *
@ -896,7 +898,8 @@ public class Resolve {
bestSoFar, bestSoFar,
allowBoxing, allowBoxing,
useVarargs, useVarargs,
operator); operator,
new HashSet<TypeSymbol>());
} }
// where // where
private Symbol findMethod(Env<AttrContext> env, private Symbol findMethod(Env<AttrContext> env,
@ -909,11 +912,13 @@ public class Resolve {
Symbol bestSoFar, Symbol bestSoFar,
boolean allowBoxing, boolean allowBoxing,
boolean useVarargs, boolean useVarargs,
boolean operator) { boolean operator,
Set<TypeSymbol> seen) {
for (Type ct = intype; ct.tag == CLASS || ct.tag == TYPEVAR; ct = types.supertype(ct)) { for (Type ct = intype; ct.tag == CLASS || ct.tag == TYPEVAR; ct = types.supertype(ct)) {
while (ct.tag == TYPEVAR) while (ct.tag == TYPEVAR)
ct = ct.getUpperBound(); ct = ct.getUpperBound();
ClassSymbol c = (ClassSymbol)ct.tsym; ClassSymbol c = (ClassSymbol)ct.tsym;
if (!seen.add(c)) return bestSoFar;
if ((c.flags() & (ABSTRACT | INTERFACE | ENUM)) == 0) if ((c.flags() & (ABSTRACT | INTERFACE | ENUM)) == 0)
abstractok = false; abstractok = false;
for (Scope.Entry e = c.members().lookup(name); for (Scope.Entry e = c.members().lookup(name);
@ -942,7 +947,7 @@ public class Resolve {
bestSoFar = findMethod(env, site, name, argtypes, bestSoFar = findMethod(env, site, name, argtypes,
typeargtypes, typeargtypes,
l.head, abstractok, bestSoFar, l.head, abstractok, bestSoFar,
allowBoxing, useVarargs, operator); allowBoxing, useVarargs, operator, seen);
} }
if (concrete != bestSoFar && if (concrete != bestSoFar &&
concrete.kind < ERR && bestSoFar.kind < ERR && concrete.kind < ERR && bestSoFar.kind < ERR &&
@ -1736,14 +1741,15 @@ public class Resolve {
*/ */
Symbol resolveSelfContaining(DiagnosticPosition pos, Symbol resolveSelfContaining(DiagnosticPosition pos,
Env<AttrContext> env, Env<AttrContext> env,
Symbol member) { Symbol member,
boolean isSuperCall) {
Name name = names._this; Name name = names._this;
Env<AttrContext> env1 = env; Env<AttrContext> env1 = isSuperCall ? env.outer : env;
boolean staticOnly = false; boolean staticOnly = false;
while (env1.outer != null) { if (env1 != null) {
while (env1 != null && env1.outer != null) {
if (isStatic(env1)) staticOnly = true; if (isStatic(env1)) staticOnly = true;
if (env1.enclClass.sym.isSubClass(member.owner, types) && if (env1.enclClass.sym.isSubClass(member.owner, types)) {
isAccessible(env, env1.enclClass.sym.type, member)) {
Symbol sym = env1.info.scope.lookup(name).sym; Symbol sym = env1.info.scope.lookup(name).sym;
if (sym != null) { if (sym != null) {
if (staticOnly) sym = new StaticError(sym); if (staticOnly) sym = new StaticError(sym);
@ -1755,6 +1761,7 @@ public class Resolve {
staticOnly = true; staticOnly = true;
env1 = env1.outer; env1 = env1.outer;
} }
}
log.error(pos, "encl.class.required", member); log.error(pos, "encl.class.required", member);
return syms.errSymbol; return syms.errSymbol;
} }
@ -1764,9 +1771,13 @@ public class Resolve {
* JLS2 8.8.5.1 and 15.9.2 * JLS2 8.8.5.1 and 15.9.2
*/ */
Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) { Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t) {
return resolveImplicitThis(pos, env, t, false);
}
Type resolveImplicitThis(DiagnosticPosition pos, Env<AttrContext> env, Type t, boolean isSuperCall) {
Type thisType = (((t.tsym.owner.kind & (MTH|VAR)) != 0) Type thisType = (((t.tsym.owner.kind & (MTH|VAR)) != 0)
? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this) ? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this)
: resolveSelfContaining(pos, env, t.tsym)).type; : resolveSelfContaining(pos, env, t.tsym, isSuperCall)).type;
if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym) if (env.info.isSelfCall && thisType.tsym == env.enclClass.sym)
log.error(pos, "cant.ref.before.ctor.called", "this"); log.error(pos, "cant.ref.before.ctor.called", "this");
return thisType; return thisType;

View file

@ -44,13 +44,13 @@ import com.sun.tools.javac.util.Context;
public class CacheFSInfo extends FSInfo { public class CacheFSInfo extends FSInfo {
/** /**
* Register a Context.Factory to create a singleton CacheFSInfo. * Register a Context.Factory to create a CacheFSInfo.
*/ */
public static void preRegister(final Context context) { public static void preRegister(Context context) {
context.put(FSInfo.class, new Context.Factory<FSInfo>() { context.put(FSInfo.class, new Context.Factory<FSInfo>() {
public FSInfo make() { public FSInfo make(Context c) {
FSInfo instance = new CacheFSInfo(); FSInfo instance = new CacheFSInfo();
context.put(FSInfo.class, instance); c.put(FSInfo.class, instance);
return instance; return instance;
} }
}); });

View file

@ -129,10 +129,10 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
/** /**
* Register a Context.Factory to create a JavacFileManager. * Register a Context.Factory to create a JavacFileManager.
*/ */
public static void preRegister(final Context context) { public static void preRegister(Context context) {
context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() { context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
public JavaFileManager make() { public JavaFileManager make(Context c) {
return new JavacFileManager(context, true, null); return new JavacFileManager(c, true, null);
} }
}); });
} }

View file

@ -2183,7 +2183,7 @@ public class ClassReader implements Completer {
} }
currentClassFile = classfile; currentClassFile = classfile;
if (verbose) { if (verbose) {
printVerbose("loading", currentClassFile.toString()); log.printVerbose("loading", currentClassFile.toString());
} }
if (classfile.getKind() == JavaFileObject.Kind.CLASS) { if (classfile.getKind() == JavaFileObject.Kind.CLASS) {
filling = true; filling = true;
@ -2452,13 +2452,13 @@ public class ClassReader implements Completer {
for (File file : fm.getLocation(SOURCE_PATH)) { for (File file : fm.getLocation(SOURCE_PATH)) {
path = path.prepend(file); path = path.prepend(file);
} }
printVerbose("sourcepath", path.reverse().toString()); log.printVerbose("sourcepath", path.reverse().toString());
} else if (wantSourceFiles) { } else if (wantSourceFiles) {
List<File> path = List.nil(); List<File> path = List.nil();
for (File file : fm.getLocation(CLASS_PATH)) { for (File file : fm.getLocation(CLASS_PATH)) {
path = path.prepend(file); path = path.prepend(file);
} }
printVerbose("sourcepath", path.reverse().toString()); log.printVerbose("sourcepath", path.reverse().toString());
} }
if (wantClassFiles) { if (wantClassFiles) {
List<File> path = List.nil(); List<File> path = List.nil();
@ -2468,7 +2468,7 @@ public class ClassReader implements Completer {
for (File file : fm.getLocation(CLASS_PATH)) { for (File file : fm.getLocation(CLASS_PATH)) {
path = path.prepend(file); path = path.prepend(file);
} }
printVerbose("classpath", path.reverse().toString()); log.printVerbose("classpath", path.reverse().toString());
} }
} }
} }
@ -2519,14 +2519,6 @@ public class ClassReader implements Completer {
} }
} }
/** Output for "-verbose" option.
* @param key The key to look up the correct internationalized string.
* @param arg An argument for substitution into the output string.
*/
private void printVerbose(String key, CharSequence arg) {
log.printNoteLines("verbose." + key, arg);
}
/** Output for "-checkclassfile" option. /** Output for "-checkclassfile" option.
* @param key The key to look up the correct internationalized string. * @param key The key to look up the correct internationalized string.
* @param arg An argument for substitution into the output string. * @param arg An argument for substitution into the output string.

View file

@ -1447,7 +1447,7 @@ public class ClassWriter extends ClassFile {
try { try {
writeClassFile(out, c); writeClassFile(out, c);
if (verbose) if (verbose)
log.printErrLines("verbose.wrote.file", outFile); log.printVerbose("wrote.file", outFile);
out.close(); out.close();
out = null; out = null;
} finally { } finally {

View file

@ -298,6 +298,13 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
*/ */
protected JavaCompiler delegateCompiler; protected JavaCompiler delegateCompiler;
/**
* Command line options.
*/
protected Options options;
protected Context context;
/** /**
* Flag set if any annotation processing occurred. * Flag set if any annotation processing occurred.
**/ **/
@ -308,11 +315,9 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
**/ **/
protected boolean implicitSourceFilesRead; protected boolean implicitSourceFilesRead;
protected Context context;
/** Construct a new compiler using a shared context. /** Construct a new compiler using a shared context.
*/ */
public JavaCompiler(final Context context) { public JavaCompiler(Context context) {
this.context = context; this.context = context;
context.put(compilerKey, this); context.put(compilerKey, this);
@ -354,7 +359,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
reader.sourceCompleter = this; reader.sourceCompleter = this;
Options options = Options.instance(context); options = Options.instance(context);
verbose = options.isSet(VERBOSE); verbose = options.isSet(VERBOSE);
sourceOutput = options.isSet(PRINTSOURCE); // used to be -s sourceOutput = options.isSet(PRINTSOURCE); // used to be -s
@ -580,7 +585,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
null, List.<JCTree>nil()); null, List.<JCTree>nil());
if (content != null) { if (content != null) {
if (verbose) { if (verbose) {
printVerbose("parsing.started", filename); log.printVerbose("parsing.started", filename);
} }
if (taskListener != null) { if (taskListener != null) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename); TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename);
@ -589,7 +594,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo); Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo);
tree = parser.parseCompilationUnit(); tree = parser.parseCompilationUnit();
if (verbose) { if (verbose) {
printVerbose("parsing.done", Long.toString(elapsed(msec))); log.printVerbose("parsing.done", Long.toString(elapsed(msec)));
} }
} }
@ -676,7 +681,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
try { try {
new Pretty(out, true).printUnit(env.toplevel, cdef); new Pretty(out, true).printUnit(env.toplevel, cdef);
if (verbose) if (verbose)
printVerbose("wrote.file", outFile); log.printVerbose("wrote.file", outFile);
} finally { } finally {
out.close(); out.close();
} }
@ -792,6 +797,11 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
throw new AssertionError("attempt to reuse JavaCompiler"); throw new AssertionError("attempt to reuse JavaCompiler");
hasBeenUsed = true; hasBeenUsed = true;
// forcibly set the equivalent of -Xlint:-options, so that no further
// warnings about command line options are generated from this point on
options.put(XLINT_CUSTOM + "-" + LintCategory.OPTIONS.option, "true");
options.remove(XLINT_CUSTOM + LintCategory.OPTIONS.option);
start_msec = now(); start_msec = now();
try { try {
@ -857,7 +867,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
if (verbose) { if (verbose) {
elapsed_msec = elapsed(start_msec); elapsed_msec = elapsed(start_msec);
printVerbose("total", Long.toString(elapsed_msec)); log.printVerbose("total", Long.toString(elapsed_msec));
} }
reportDeferredDiagnostics(); reportDeferredDiagnostics();
@ -963,7 +973,6 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
public void initProcessAnnotations(Iterable<? extends Processor> processors) { public void initProcessAnnotations(Iterable<? extends Processor> processors) {
// Process annotations if processing is not disabled and there // Process annotations if processing is not disabled and there
// is at least one Processor available. // is at least one Processor available.
Options options = Options.instance(context);
if (options.isSet(PROC, "none")) { if (options.isSet(PROC, "none")) {
processAnnotations = false; processAnnotations = false;
} else if (procEnvImpl == null) { } else if (procEnvImpl == null) {
@ -1022,7 +1031,6 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
// If there are no annotation processors present, and // If there are no annotation processors present, and
// annotation processing is to occur with compilation, // annotation processing is to occur with compilation,
// emit a warning. // emit a warning.
Options options = Options.instance(context);
if (options.isSet(PROC, "only")) { if (options.isSet(PROC, "only")) {
log.warning("proc.proc-only.requested.no.procs"); log.warning("proc.proc-only.requested.no.procs");
todo.clear(); todo.clear();
@ -1108,9 +1116,13 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
} }
boolean explicitAnnotationProcessingRequested() { boolean explicitAnnotationProcessingRequested() {
Options options = Options.instance(context);
return return
explicitAnnotationProcessingRequested || explicitAnnotationProcessingRequested ||
explicitAnnotationProcessingRequested(options);
}
static boolean explicitAnnotationProcessingRequested(Options options) {
return
options.isSet(PROCESSOR) || options.isSet(PROCESSOR) ||
options.isSet(PROCESSORPATH) || options.isSet(PROCESSORPATH) ||
options.isSet(PROC, "only") || options.isSet(PROC, "only") ||
@ -1142,7 +1154,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
if (verboseCompilePolicy) if (verboseCompilePolicy)
printNote("[attribute " + env.enclClass.sym + "]"); printNote("[attribute " + env.enclClass.sym + "]");
if (verbose) if (verbose)
printVerbose("checking.attribution", env.enclClass.sym); log.printVerbose("checking.attribution", env.enclClass.sym);
if (taskListener != null) { if (taskListener != null) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym); TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
@ -1508,7 +1520,8 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
} }
public void reportDeferredDiagnostics() { public void reportDeferredDiagnostics() {
if (annotationProcessingOccurred if (errorCount() == 0
&& annotationProcessingOccurred
&& implicitSourceFilesRead && implicitSourceFilesRead
&& implicitSourcePolicy == ImplicitSourcePolicy.UNSET) { && implicitSourcePolicy == ImplicitSourcePolicy.UNSET) {
if (explicitAnnotationProcessingRequested()) if (explicitAnnotationProcessingRequested())
@ -1562,14 +1575,6 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
Log.printLines(log.noticeWriter, lines); Log.printLines(log.noticeWriter, lines);
} }
/** Output for "-verbose" option.
* @param key The key to look up the correct internationalized string.
* @param arg An argument for substitution into the output string.
*/
protected void printVerbose(String key, Object arg) {
log.printNoteLines("verbose." + key, arg);
}
/** Print numbers of errors and warnings. /** Print numbers of errors and warnings.
*/ */
protected void printCount(String kind, int count) { protected void printCount(String kind, int count) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -367,7 +367,11 @@ public class Main {
|| options.isSet(VERSION) || options.isSet(VERSION)
|| options.isSet(FULLVERSION)) || options.isSet(FULLVERSION))
return EXIT_OK; return EXIT_OK;
if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
error("err.no.source.files.classes");
} else {
error("err.no.source.files"); error("err.no.source.files");
}
return EXIT_CMDERR; return EXIT_CMDERR;
} }
} catch (java.io.FileNotFoundException e) { } catch (java.io.FileNotFoundException e) {

View file

@ -88,6 +88,7 @@ public enum OptionName {
O("-O"), O("-O"),
XJCOV("-Xjcov"), XJCOV("-Xjcov"),
XD("-XD"), XD("-XD"),
AT("@"),
SOURCEFILE("sourcefile"); SOURCEFILE("sourcefile");
public final String optionName; public final String optionName;

View file

@ -168,6 +168,7 @@ public class RecognizedOptions {
O, O,
XJCOV, XJCOV,
XD, XD,
AT,
SOURCEFILE); SOURCEFILE);
static Set<OptionName> javacFileManagerOptions = EnumSet.of( static Set<OptionName> javacFileManagerOptions = EnumSet.of(
@ -565,12 +566,27 @@ public class RecognizedOptions {
} }
}, },
// This option exists only for the purpose of documenting itself.
// It's actually implemented by the CommandLine class.
new Option(AT, "opt.arg.file", "opt.AT") {
@Override
String helpSynopsis() {
hasSuffix = true;
return super.helpSynopsis();
}
@Override
public boolean process(Options options, String option) {
throw new AssertionError
("the @ flag should be caught by CommandLine.");
}
},
/* /*
* TODO: With apt, the matches method accepts anything if * TODO: With apt, the matches method accepts anything if
* -XclassAsDecls is used; code elsewhere does the lookup to * -XclassAsDecls is used; code elsewhere does the lookup to
* see if the class name is both legal and found. * see if the class name is both legal and found.
* *
* In apt, the process method adds the candiate class file * In apt, the process method adds the candidate class file
* name to a separate list. * name to a separate list.
*/ */
new HiddenOption(SOURCEFILE) { new HiddenOption(SOURCEFILE) {

View file

@ -2357,7 +2357,7 @@ public class JavacParser implements Parser {
List<JCTypeParameter> typarams = typeParametersOpt(); List<JCTypeParameter> typarams = typeParametersOpt();
JCTree extending = null; JCExpression extending = null;
if (S.token() == EXTENDS) { if (S.token() == EXTENDS) {
S.nextToken(); S.nextToken();
extending = parseType(); extending = parseType();

View file

@ -807,8 +807,6 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
final JavaCompiler compiler; final JavaCompiler compiler;
/** The log for the round. */ /** The log for the round. */
final Log log; final Log log;
/** The number of warnings in the previous round. */
final int priorWarnings;
/** The ASTs to be compiled. */ /** The ASTs to be compiled. */
List<JCCompilationUnit> roots; List<JCCompilationUnit> roots;
@ -826,10 +824,10 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
private Round(Context context, int number, int priorWarnings) { private Round(Context context, int number, int priorWarnings) {
this.context = context; this.context = context;
this.number = number; this.number = number;
this.priorWarnings = priorWarnings;
compiler = JavaCompiler.instance(context); compiler = JavaCompiler.instance(context);
log = Log.instance(context); log = Log.instance(context);
log.nwarnings += priorWarnings;
log.deferDiagnostics = true; log.deferDiagnostics = true;
// the following is for the benefit of JavacProcessingEnvironment.getContext() // the following is for the benefit of JavacProcessingEnvironment.getContext()
@ -904,8 +902,8 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
JavaCompiler finalCompiler(boolean errorStatus) { JavaCompiler finalCompiler(boolean errorStatus) {
try { try {
JavaCompiler c = JavaCompiler.instance(nextContext()); JavaCompiler c = JavaCompiler.instance(nextContext());
c.log.nwarnings += compiler.log.nwarnings;
if (errorStatus) { if (errorStatus) {
c.log.nwarnings += priorWarnings + compiler.log.nwarnings;
c.log.nerrors += compiler.log.nerrors; c.log.nerrors += compiler.log.nerrors;
} }
return c; return c;
@ -1045,7 +1043,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
* other values are implicitly reset. * other values are implicitly reset.
*/ */
private Context nextContext() { private Context nextContext() {
Context next = new Context(); Context next = new Context(context);
Options options = Options.instance(context); Options options = Options.instance(context);
Assert.checkNonNull(options); Assert.checkNonNull(options);

View file

@ -1588,14 +1588,6 @@ compiler.misc.diamond=\
compiler.misc.diamond.non.generic=\ compiler.misc.diamond.non.generic=\
cannot use ''<>'' with non-generic class {0} cannot use ''<>'' with non-generic class {0}
# 0: list of type, 1: message segment
compiler.misc.diamond.invalid.arg=\
type argument {0} inferred for {1} is not allowed in this context
# 0: list of type, 1: message segment
compiler.misc.diamond.invalid.args=\
type arguments {0} inferred for {1} are not allowed in this context
# 0: type, 1: list of type # 0: type, 1: list of type
compiler.misc.explicit.param.do.not.conform.to.bounds=\ compiler.misc.explicit.param.do.not.conform.to.bounds=\
explicit type argument {0} does not conform to declared bound(s) {1} explicit type argument {0} does not conform to declared bound(s) {1}
@ -1803,8 +1795,8 @@ compiler.misc.varargs.implement=\
compiler.misc.varargs.clash.with=\ compiler.misc.varargs.clash.with=\
{0} in {1} overrides {2} in {3} {0} in {1} overrides {2} in {3}
compiler.misc.non.denotable.type=\ compiler.misc.diamond.and.anon.class=\
Non-denotable type {0} not allowed here cannot use ''<>'' with anonymous inner classes
# 0: symbol kind, 1: symbol, 2: symbol, 3: message segment # 0: symbol kind, 1: symbol, 2: symbol, 3: message segment
compiler.misc.inapplicable.method=\ compiler.misc.inapplicable.method=\

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -146,6 +146,8 @@ javac.opt.printProcessorInfo=\
Print information about which annotations a processor is asked to process Print information about which annotations a processor is asked to process
javac.opt.prefer=\ javac.opt.prefer=\
Specify which file to read when both a source file and class file are found for an implicitly compiled class Specify which file to read when both a source file and class file are found for an implicitly compiled class
javac.opt.AT=\
Read options and filenames from file
## errors ## errors
@ -161,6 +163,8 @@ javac.err.invalid.target=\
invalid target release: {0} invalid target release: {0}
javac.err.no.source.files=\ javac.err.no.source.files=\
no source files no source files
javac.err.no.source.files.classes=\
no source files or class names
javac.err.req.arg=\ javac.err.req.arg=\
{0} requires an argument {0} requires an argument
javac.err.invalid.source=\ javac.err.invalid.source=\

View file

@ -567,14 +567,14 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
public JCModifiers mods; public JCModifiers mods;
public Name name; public Name name;
public List<JCTypeParameter> typarams; public List<JCTypeParameter> typarams;
public JCTree extending; public JCExpression extending;
public List<JCExpression> implementing; public List<JCExpression> implementing;
public List<JCTree> defs; public List<JCTree> defs;
public ClassSymbol sym; public ClassSymbol sym;
protected JCClassDecl(JCModifiers mods, protected JCClassDecl(JCModifiers mods,
Name name, Name name,
List<JCTypeParameter> typarams, List<JCTypeParameter> typarams,
JCTree extending, JCExpression extending,
List<JCExpression> implementing, List<JCExpression> implementing,
List<JCTree> defs, List<JCTree> defs,
ClassSymbol sym) ClassSymbol sym)
@ -2104,7 +2104,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
JCClassDecl ClassDef(JCModifiers mods, JCClassDecl ClassDef(JCModifiers mods,
Name name, Name name,
List<JCTypeParameter> typarams, List<JCTypeParameter> typarams,
JCTree extending, JCExpression extending,
List<JCExpression> implementing, List<JCExpression> implementing,
List<JCTree> defs); List<JCTree> defs);
JCMethodDecl MethodDef(JCModifiers mods, JCMethodDecl MethodDef(JCModifiers mods,

View file

@ -135,7 +135,7 @@ public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
JCClassDecl t = (JCClassDecl) node; JCClassDecl t = (JCClassDecl) node;
JCModifiers mods = copy(t.mods, p); JCModifiers mods = copy(t.mods, p);
List<JCTypeParameter> typarams = copy(t.typarams, p); List<JCTypeParameter> typarams = copy(t.typarams, p);
JCTree extending = copy(t.extending, p); JCExpression extending = copy(t.extending, p);
List<JCExpression> implementing = copy(t.implementing, p); List<JCExpression> implementing = copy(t.implementing, p);
List<JCTree> defs = copy(t.defs, p); List<JCTree> defs = copy(t.defs, p);
return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs); return M.at(t.pos).ClassDef(mods, t.name, typarams, extending, implementing, defs);

View file

@ -146,7 +146,7 @@ public class TreeMaker implements JCTree.Factory {
public JCClassDecl ClassDef(JCModifiers mods, public JCClassDecl ClassDef(JCModifiers mods,
Name name, Name name,
List<JCTypeParameter> typarams, List<JCTypeParameter> typarams,
JCTree extending, JCExpression extending,
List<JCExpression> implementing, List<JCExpression> implementing,
List<JCTree> defs) List<JCTree> defs)
{ {

View file

@ -108,7 +108,7 @@ public class Context {
* instance. * instance.
*/ */
public static interface Factory<T> { public static interface Factory<T> {
T make(); T make(Context c);
}; };
/** /**
@ -124,6 +124,8 @@ public class Context {
Object old = ht.put(key, fac); Object old = ht.put(key, fac);
if (old != null) if (old != null)
throw new AssertionError("duplicate context value"); throw new AssertionError("duplicate context value");
checkState(ft);
ft.put(key, fac); // cannot be duplicate if unique in ht
} }
/** Set the value for the key in this context. */ /** Set the value for the key in this context. */
@ -142,7 +144,7 @@ public class Context {
Object o = ht.get(key); Object o = ht.get(key);
if (o instanceof Factory<?>) { if (o instanceof Factory<?>) {
Factory<?> fac = (Factory<?>)o; Factory<?> fac = (Factory<?>)o;
o = fac.make(); o = fac.make(this);
if (o instanceof Factory<?>) if (o instanceof Factory<?>)
throw new AssertionError("T extends Context.Factory"); throw new AssertionError("T extends Context.Factory");
Assert.check(ht.get(key) == o); Assert.check(ht.get(key) == o);
@ -158,6 +160,20 @@ public class Context {
public Context() {} public Context() {}
/**
* The table of preregistered factories.
*/
private Map<Key<?>,Factory<?>> ft = new HashMap<Key<?>,Factory<?>>();
public Context(Context prev) {
kt.putAll(prev.kt); // retain all implicit keys
ft.putAll(prev.ft); // retain all factory objects
ht.putAll(prev.ft); // init main table with factories
}
/*
* The key table, providing a unique Key<T> for each Class<T>.
*/
private Map<Class<?>, Key<?>> kt = new HashMap<Class<?>, Key<?>>(); private Map<Class<?>, Key<?>> kt = new HashMap<Class<?>, Key<?>>();
private <T> Key<T> key(Class<T> clss) { private <T> Key<T> key(Class<T> clss) {
@ -198,6 +214,7 @@ public class Context {
public void clear() { public void clear() {
ht = null; ht = null;
kt = null; kt = null;
ft = null;
} }
private static void checkState(Map<?,?> t) { private static void checkState(Map<?,?> t) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -329,7 +329,6 @@ public class Log extends AbstractLog {
printLines(errWriter, localize(key, args)); printLines(errWriter, localize(key, args));
} }
/** Print the text of a message to the noticeWriter stream, /** Print the text of a message to the noticeWriter stream,
* translating newlines appropriately for the platform. * translating newlines appropriately for the platform.
*/ */
@ -337,6 +336,14 @@ public class Log extends AbstractLog {
printLines(noticeWriter, localize(key, args)); printLines(noticeWriter, localize(key, args));
} }
/**
* Print the localized text of a "verbose" message to the
* noticeWriter stream.
*/
public void printVerbose(String key, Object... args) {
printLines(noticeWriter, localize("verbose." + key, args));
}
protected void directError(String key, Object... args) { protected void directError(String key, Object... args) {
printErrLines(key, args); printErrLines(key, args);
errWriter.flush(); errWriter.flush();

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -92,8 +92,9 @@ public class AnnotationDescImpl implements AnnotationDesc {
* @com.example.foo * @com.example.foo
* Omit parens for marker annotations, and omit "value=" when allowed. * Omit parens for marker annotations, and omit "value=" when allowed.
*/ */
@Override
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer("@"); StringBuilder sb = new StringBuilder("@");
sb.append(annotation.type.tsym); sb.append(annotation.type.tsym);
ElementValuePair vals[] = elementValues(); ElementValuePair vals[] = elementValues();
@ -153,6 +154,7 @@ public class AnnotationDescImpl implements AnnotationDesc {
* Returns a string representation of this pair * Returns a string representation of this pair
* of the form "name=value". * of the form "name=value".
*/ */
@Override
public String toString() { public String toString() {
return meth.name + "=" + value(); return meth.name + "=" + value();
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,7 +30,6 @@ import com.sun.javadoc.*;
import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.TypeTags; import com.sun.tools.javac.code.TypeTags;
@ -114,6 +113,7 @@ public class AnnotationValueImpl implements AnnotationValue {
* @return the text of a Java language annotation value expression * @return the text of a Java language annotation value expression
* whose value is the value of this annotation type element. * whose value is the value of this annotation type element.
*/ */
@Override
public String toString() { public String toString() {
ToStringVisitor tv = new ToStringVisitor(); ToStringVisitor tv = new ToStringVisitor();
attr.accept(tv); attr.accept(tv);
@ -121,8 +121,9 @@ public class AnnotationValueImpl implements AnnotationValue {
} }
private class ToStringVisitor implements Attribute.Visitor { private class ToStringVisitor implements Attribute.Visitor {
private final StringBuffer sb = new StringBuffer(); private final StringBuilder sb = new StringBuilder();
@Override
public String toString() { public String toString() {
return sb.toString(); return sb.toString();
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -64,7 +64,6 @@ import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Position; import com.sun.tools.javac.util.Position;
import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
/** /**
@ -147,6 +146,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
/** /**
* Return true if this is a class, not an interface. * Return true if this is a class, not an interface.
*/ */
@Override
public boolean isClass() { public boolean isClass() {
return !Modifier.isInterface(getModifiers()); return !Modifier.isInterface(getModifiers());
} }
@ -155,6 +155,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return true if this is a ordinary class, * Return true if this is a ordinary class,
* not an enumeration, exception, an error, or an interface. * not an enumeration, exception, an error, or an interface.
*/ */
@Override
public boolean isOrdinaryClass() { public boolean isOrdinaryClass() {
if (isEnum() || isInterface() || isAnnotationType()) { if (isEnum() || isInterface() || isAnnotationType()) {
return false; return false;
@ -172,6 +173,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return true if this is an enumeration. * Return true if this is an enumeration.
* (For legacy doclets, return false.) * (For legacy doclets, return false.)
*/ */
@Override
public boolean isEnum() { public boolean isEnum() {
return (getFlags() & Flags.ENUM) != 0 return (getFlags() & Flags.ENUM) != 0
&& &&
@ -182,6 +184,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return true if this is an interface, but not an annotation type. * Return true if this is an interface, but not an annotation type.
* Overridden by AnnotationTypeDocImpl. * Overridden by AnnotationTypeDocImpl.
*/ */
@Override
public boolean isInterface() { public boolean isInterface() {
return Modifier.isInterface(getModifiers()); return Modifier.isInterface(getModifiers());
} }
@ -189,6 +192,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
/** /**
* Return true if this is an exception class * Return true if this is an exception class
*/ */
@Override
public boolean isException() { public boolean isException() {
if (isEnum() || isInterface() || isAnnotationType()) { if (isEnum() || isInterface() || isAnnotationType()) {
return false; return false;
@ -204,6 +208,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
/** /**
* Return true if this is an error class * Return true if this is an error class
*/ */
@Override
public boolean isError() { public boolean isError() {
if (isEnum() || isInterface() || isAnnotationType()) { if (isEnum() || isInterface() || isAnnotationType()) {
return false; return false;
@ -275,6 +280,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
/** /**
* Return the package that this class is contained in. * Return the package that this class is contained in.
*/ */
@Override
public PackageDoc containingPackage() { public PackageDoc containingPackage() {
PackageDocImpl p = env.getPackageDoc(tsym.packge()); PackageDocImpl p = env.getPackageDoc(tsym.packge());
if (p.setDocPath == false) { if (p.setDocPath == false) {
@ -374,6 +380,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return the qualified name and any type parameters. * Return the qualified name and any type parameters.
* Each parameter is a type variable with optional bounds. * Each parameter is a type variable with optional bounds.
*/ */
@Override
public String toString() { public String toString() {
return classToString(env, tsym, true); return classToString(env, tsym, true);
} }
@ -401,7 +408,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* qualified by their enclosing class(es) only. * qualified by their enclosing class(es) only.
*/ */
static String classToString(DocEnv env, ClassSymbol c, boolean full) { static String classToString(DocEnv env, ClassSymbol c, boolean full) {
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
if (!c.isInner()) { // if c is not an inner class if (!c.isInner()) { // if c is not an inner class
s.append(getClassName(c, full)); s.append(getClassName(c, full));
} else { } else {
@ -449,10 +456,12 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return the modifier string for this class. If it's an interface * Return the modifier string for this class. If it's an interface
* exclude 'abstract' keyword from the modifier string * exclude 'abstract' keyword from the modifier string
*/ */
@Override
public String modifiers() { public String modifiers() {
return Modifier.toString(modifierSpecifier()); return Modifier.toString(modifierSpecifier());
} }
@Override
public int modifierSpecifier() { public int modifierSpecifier() {
int modifiers = getModifiers(); int modifiers = getModifiers();
return (isInterface() || isAnnotationType()) return (isInterface() || isAnnotationType())
@ -1285,6 +1294,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return the source position of the entity, or null if * Return the source position of the entity, or null if
* no position is available. * no position is available.
*/ */
@Override
public SourcePosition position() { public SourcePosition position() {
if (tsym.sourcefile == null) return null; if (tsym.sourcefile == null) return null;
return SourcePositionImpl.make(tsym.sourcefile, return SourcePositionImpl.make(tsym.sourcefile,

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
package com.sun.tools.javadoc; package com.sun.tools.javadoc;
import java.io.DataInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.text.CollationKey; import java.text.CollationKey;
@ -33,6 +34,8 @@ import javax.tools.FileObject;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.tools.javac.util.Position; import com.sun.tools.javac.util.Position;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* abstract base class of all Doc classes. Doc item's are representations * abstract base class of all Doc classes. Doc item's are representations
@ -166,52 +169,29 @@ public abstract class DocImpl implements Doc, Comparable<Object> {
* Utility for subclasses which read HTML documentation files. * Utility for subclasses which read HTML documentation files.
*/ */
String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException {
int filesize = input.available(); byte[] filecontents = new byte[input.available()];
byte[] filecontents = new byte[filesize]; try {
input.read(filecontents, 0, filesize); DataInputStream dataIn = new DataInputStream(input);
dataIn.readFully(filecontents);
} finally {
input.close(); input.close();
}
String encoding = env.getEncoding(); String encoding = env.getEncoding();
String rawDoc = (encoding!=null) String rawDoc = (encoding!=null)
? new String(filecontents, encoding) ? new String(filecontents, encoding)
: new String(filecontents); : new String(filecontents);
String upper = null; Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*");
int bodyIdx = rawDoc.indexOf("<body"); Matcher m = bodyPat.matcher(rawDoc);
if (bodyIdx == -1) { if (m.matches()) {
bodyIdx = rawDoc.indexOf("<BODY"); return m.group(1);
if (bodyIdx == -1) { } else {
upper = rawDoc.toUpperCase(); String key = rawDoc.matches("(?is).*<body\\b.*")
bodyIdx = upper.indexOf("<BODY"); ? "javadoc.End_body_missing_from_html_file"
if (bodyIdx == -1) { : "javadoc.Body_missing_from_html_file";
env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key);
"javadoc.Body_missing_from_html_file");
return ""; return "";
} }
} }
}
bodyIdx = rawDoc.indexOf('>', bodyIdx);
if (bodyIdx == -1) {
env.error(SourcePositionImpl.make(filename, Position.NOPOS, null),
"javadoc.Body_missing_from_html_file");
return "";
}
++bodyIdx;
int endIdx = rawDoc.indexOf("</body", bodyIdx);
if (endIdx == -1) {
endIdx = rawDoc.indexOf("</BODY", bodyIdx);
if (endIdx == -1) {
if (upper == null) {
upper = rawDoc.toUpperCase();
}
endIdx = upper.indexOf("</BODY", bodyIdx);
if (endIdx == -1) {
env.error(SourcePositionImpl.make(filename, Position.NOPOS, null),
"javadoc.End_body_missing_from_html_file");
return "";
}
}
}
return rawDoc.substring(bodyIdx, endIdx);
}
/** /**
* Return the full unprocessed text of the comment. Tags * Return the full unprocessed text of the comment. Tags
@ -256,6 +236,7 @@ public abstract class DocImpl implements Doc, Comparable<Object> {
/** /**
* Returns a string representation of this Doc item. * Returns a string representation of this Doc item.
*/ */
@Override
public String toString() { public String toString() {
return qualifiedName(); return qualifiedName();
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,14 +31,13 @@ import static com.sun.javadoc.LanguageVersion.*;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
import java.net.*; import java.io.File;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.io.File;
import java.io.IOException;
import java.util.StringTokenizer;
/** /**
* Class creates, controls and invokes doclets. * Class creates, controls and invokes doclets.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -226,7 +226,7 @@ public abstract class ExecutableMemberDocImpl
} }
private String makeSignature(boolean full) { private String makeSignature(boolean full) {
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
result.append("("); result.append("(");
for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) { for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) {
Type t = types.head; Type t = types.head;
@ -251,6 +251,7 @@ public abstract class ExecutableMemberDocImpl
/** /**
* Generate a key for sorting. * Generate a key for sorting.
*/ */
@Override
CollationKey generateKey() { CollationKey generateKey() {
String k = name() + flatSignature() + typeParametersString(); String k = name() + flatSignature() + typeParametersString();
// ',' and '&' are between '$' and 'a': normalize to spaces. // ',' and '&' are between '$' and 'a': normalize to spaces.
@ -263,6 +264,7 @@ public abstract class ExecutableMemberDocImpl
* Return the source position of the entity, or null if * Return the source position of the entity, or null if
* no position is available. * no position is available.
*/ */
@Override
public SourcePosition position() { public SourcePosition position() {
if (sym.enclClass().sourcefile == null) return null; if (sym.enclClass().sourcefile == null) return null;
return SourcePositionImpl.make(sym.enclClass().sourcefile, return SourcePositionImpl.make(sym.enclClass().sourcefile,

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -142,7 +142,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
return v + (suffix == 'f' || suffix == 'F' ? "" + suffix : ""); return v + (suffix == 'f' || suffix == 'F' ? "" + suffix : "");
} }
private static String sourceForm(char c) { private static String sourceForm(char c) {
StringBuffer buf = new StringBuffer(8); StringBuilder buf = new StringBuilder(8);
buf.append('\''); buf.append('\'');
sourceChar(c, buf); sourceChar(c, buf);
buf.append('\''); buf.append('\'');
@ -152,7 +152,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
return "0x" + Integer.toString(c & 0xff, 16); return "0x" + Integer.toString(c & 0xff, 16);
} }
private static String sourceForm(String s) { private static String sourceForm(String s) {
StringBuffer buf = new StringBuffer(s.length() + 5); StringBuilder buf = new StringBuilder(s.length() + 5);
buf.append('\"'); buf.append('\"');
for (int i=0; i<s.length(); i++) { for (int i=0; i<s.length(); i++) {
char c = s.charAt(i); char c = s.charAt(i);
@ -161,7 +161,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
buf.append('\"'); buf.append('\"');
return buf.toString(); return buf.toString();
} }
private static void sourceChar(char c, StringBuffer buf) { private static void sourceChar(char c, StringBuilder buf) {
switch (c) { switch (c) {
case '\b': buf.append("\\b"); return; case '\b': buf.append("\\b"); return;
case '\t': buf.append("\\t"); return; case '\t': buf.append("\\t"); return;
@ -179,7 +179,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
return; return;
} }
} }
private static void unicodeEscape(char c, StringBuffer buf) { private static void unicodeEscape(char c, StringBuilder buf) {
final String chars = "0123456789abcdef"; final String chars = "0123456789abcdef";
buf.append("\\u"); buf.append("\\u");
buf.append(chars.charAt(15 & (c>>12))); buf.append(chars.charAt(15 & (c>>12)));
@ -201,6 +201,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
/** /**
* Is this Doc item a field (but not an enum constant? * Is this Doc item a field (but not an enum constant?
*/ */
@Override
public boolean isField() { public boolean isField() {
return !isEnumConstant(); return !isEnumConstant();
} }
@ -209,6 +210,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
* Is this Doc item an enum constant? * Is this Doc item an enum constant?
* (For legacy doclets, return false.) * (For legacy doclets, return false.)
*/ */
@Override
public boolean isEnumConstant() { public boolean isEnumConstant() {
return (getFlags() & Flags.ENUM) != 0 && return (getFlags() & Flags.ENUM) != 0 &&
!env.legacyDoclet; !env.legacyDoclet;
@ -257,6 +259,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
* Return the source position of the entity, or null if * Return the source position of the entity, or null if
* no position is available. * no position is available.
*/ */
@Override
public SourcePosition position() { public SourcePosition position() {
if (sym.enclClass().sourcefile == null) return null; if (sym.enclClass().sourcefile == null) return null;
return SourcePositionImpl.make(sym.enclClass().sourcefile, return SourcePositionImpl.make(sym.enclClass().sourcefile,

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -44,10 +44,10 @@ class JavadocClassReader extends ClassReader {
return (JavadocClassReader)instance; return (JavadocClassReader)instance;
} }
public static void preRegister(final Context context) { public static void preRegister(Context context) {
context.put(classReaderKey, new Context.Factory<ClassReader>() { context.put(classReaderKey, new Context.Factory<ClassReader>() {
public ClassReader make() { public ClassReader make(Context c) {
return new JavadocClassReader(context); return new JavadocClassReader(c);
} }
}); });
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,10 +48,10 @@ public class JavadocEnter extends Enter {
return (JavadocEnter)instance; return (JavadocEnter)instance;
} }
public static void preRegister(final Context context) { public static void preRegister(Context context) {
context.put(enterKey, new Context.Factory<Enter>() { context.put(enterKey, new Context.Factory<Enter>() {
public Enter make() { public Enter make(Context c) {
return new JavadocEnter(context); return new JavadocEnter(c);
} }
}); });
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -46,10 +46,10 @@ class JavadocMemberEnter extends MemberEnter {
return (JavadocMemberEnter)instance; return (JavadocMemberEnter)instance;
} }
public static void preRegister(final Context context) { public static void preRegister(Context context) {
context.put(memberEnterKey, new Context.Factory<MemberEnter>() { context.put(memberEnterKey, new Context.Factory<MemberEnter>() {
public MemberEnter make() { public MemberEnter make(Context c) {
return new JavadocMemberEnter(context); return new JavadocMemberEnter(c);
} }
}); });
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,10 +34,10 @@ import com.sun.tools.javac.util.*;
* @author Neal Gafter * @author Neal Gafter
*/ */
public class JavadocTodo extends Todo { public class JavadocTodo extends Todo {
public static void preRegister(final Context context) { public static void preRegister(Context context) {
context.put(todoKey, new Context.Factory<Todo>() { context.put(todoKey, new Context.Factory<Todo>() {
public Todo make() { public Todo make(Context c) {
return new JavadocTodo(context); return new JavadocTodo(c);
} }
}); });
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -57,23 +57,23 @@ public class Messager extends Log implements DocErrorReporter {
return (Messager)instance; return (Messager)instance;
} }
public static void preRegister(final Context context, public static void preRegister(Context context,
final String programName) { final String programName) {
context.put(logKey, new Context.Factory<Log>() { context.put(logKey, new Context.Factory<Log>() {
public Log make() { public Log make(Context c) {
return new Messager(context, return new Messager(c,
programName); programName);
} }
}); });
} }
public static void preRegister(final Context context, public static void preRegister(Context context,
final String programName, final String programName,
final PrintWriter errWriter, final PrintWriter errWriter,
final PrintWriter warnWriter, final PrintWriter warnWriter,
final PrintWriter noticeWriter) { final PrintWriter noticeWriter) {
context.put(logKey, new Context.Factory<Log>() { context.put(logKey, new Context.Factory<Log>() {
public Log make() { public Log make(Context c) {
return new Messager(context, return new Messager(c,
programName, programName,
errWriter, errWriter,
warnWriter, warnWriter,
@ -143,11 +143,9 @@ public class Messager extends Log implements DocErrorReporter {
* if needed. * if needed.
*/ */
private String getString(String key) { private String getString(String key) {
ResourceBundle messageRB = this.messageRB;
if (messageRB == null) { if (messageRB == null) {
try { try {
this.messageRB = messageRB = messageRB = ResourceBundle.getBundle(
ResourceBundle.getBundle(
"com.sun.tools.javadoc.resources.javadoc"); "com.sun.tools.javadoc.resources.javadoc");
} catch (MissingResourceException e) { } catch (MissingResourceException e) {
throw new Error("Fatal: Resource for javadoc is missing"); throw new Error("Fatal: Resource for javadoc is missing");
@ -456,8 +454,6 @@ public class Messager extends Log implements DocErrorReporter {
* Print exit message. * Print exit message.
*/ */
public void exitNotice() { public void exitNotice() {
int nerrors = nerrors();
int nwarnings = nwarnings();
if (nerrors > 0) { if (nerrors > 0) {
notice((nerrors > 1) ? "main.errors" : "main.error", notice((nerrors > 1) ? "main.errors" : "main.error",
"" + nerrors); "" + nerrors);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,15 +25,11 @@
package com.sun.tools.javadoc; package com.sun.tools.javadoc;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import static com.sun.javadoc.LanguageVersion.*;
import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.util.List;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
@ -55,6 +51,7 @@ public class ParameterizedTypeImpl
/** /**
* Return the generic class or interface that declared this type. * Return the generic class or interface that declared this type.
*/ */
@Override
public ClassDoc asClassDoc() { public ClassDoc asClassDoc() {
return env.getClassDoc((ClassSymbol)type.tsym); return env.getClassDoc((ClassSymbol)type.tsym);
} }
@ -111,14 +108,17 @@ public class ParameterizedTypeImpl
// Asking for the "name" of a parameterized type doesn't exactly make // Asking for the "name" of a parameterized type doesn't exactly make
// sense. It's a type expression. Return the name of its generic // sense. It's a type expression. Return the name of its generic
// type. // type.
@Override
public String typeName() { public String typeName() {
return TypeMaker.getTypeName(type, false); return TypeMaker.getTypeName(type, false);
} }
@Override
public ParameterizedType asParameterizedType() { public ParameterizedType asParameterizedType() {
return this; return this;
} }
@Override
public String toString() { public String toString() {
return parameterizedTypeToString(env, (ClassType)type, true); return parameterizedTypeToString(env, (ClassType)type, true);
} }
@ -128,7 +128,7 @@ public class ParameterizedTypeImpl
if (env.legacyDoclet) { if (env.legacyDoclet) {
return TypeMaker.getTypeName(cl, full); return TypeMaker.getTypeName(cl, full);
} }
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
if (cl.getEnclosingType().tag != CLASS) { // if not an inner class... if (cl.getEnclosingType().tag != CLASS) { // if not an inner class...
s.append(TypeMaker.getTypeName(cl, full)); s.append(TypeMaker.getTypeName(cl, full));
} else { } else {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -322,6 +322,7 @@ public class RootDocImpl extends DocImpl implements RootDoc {
/** /**
* Do lazy initialization of "documentation" string. * Do lazy initialization of "documentation" string.
*/ */
@Override
protected String documentation() { protected String documentation() {
if (documentation == null) { if (documentation == null) {
int cnt = options.length(); int cnt = options.length();
@ -348,6 +349,7 @@ public class RootDocImpl extends DocImpl implements RootDoc {
* Return the source position of the entity, or null if * Return the source position of the entity, or null if
* no position is available. * no position is available.
*/ */
@Override
public SourcePosition position() { public SourcePosition position() {
JavaFileObject path; JavaFileObject path;
return ((path = getOverviewPath()) == null) ? return ((path = getOverviewPath()) == null) ?

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -358,14 +358,14 @@ class SeeTagImpl extends TagImpl implements SeeTag, LayoutCharacters {
String parameters; String parameters;
StringBuffer typeId; StringBuilder typeId;
ListBuffer<String> paramList; ListBuffer<String> paramList;
ParameterParseMachine(String parameters) { ParameterParseMachine(String parameters) {
this.parameters = parameters; this.parameters = parameters;
this.paramList = new ListBuffer<String>(); this.paramList = new ListBuffer<String>();
typeId = new StringBuffer(); typeId = new StringBuilder();
} }
public String[] parseParameters() { public String[] parseParameters() {
@ -464,6 +464,7 @@ class SeeTagImpl extends TagImpl implements SeeTag, LayoutCharacters {
/** /**
* Return the kind of this tag. * Return the kind of this tag.
*/ */
@Override
public String kind() { public String kind() {
return "@see"; return "@see";
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -396,6 +396,10 @@ class Start {
boolean ok = root != null; boolean ok = root != null;
if (ok) ok = docletInvoker.start(root); if (ok) ok = docletInvoker.start(root);
Messager docletMessager = Messager.instance0(context);
messager.nwarnings += docletMessager.nwarnings;
messager.nerrors += docletMessager.nerrors;
// We're done. // We're done.
if (compOpts.get("-verbose") != null) { if (compOpts.get("-verbose") != null) {
tm = System.currentTimeMillis() - tm; tm = System.currentTimeMillis() - tm;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,15 +27,12 @@ package com.sun.tools.javadoc;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import static com.sun.javadoc.LanguageVersion.*;
import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Type.TypeVar; import com.sun.tools.javac.code.Type.TypeVar;
import com.sun.tools.javac.code.Type.ArrayType; import com.sun.tools.javac.code.Type.ArrayType;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
@ -109,12 +106,13 @@ public class TypeMaker {
public static String getTypeName(Type t, boolean full) { public static String getTypeName(Type t, boolean full) {
switch (t.tag) { switch (t.tag) {
case ARRAY: case ARRAY:
StringBuffer dimension = new StringBuffer(); StringBuilder s = new StringBuilder();
while (t.tag == ARRAY) { while (t.tag == ARRAY) {
dimension = dimension.append("[]"); s.append("[]");
t = ((ArrayType)t).elemtype; t = ((ArrayType)t).elemtype;
} }
return getTypeName(t, full) + dimension; s.insert(0, getTypeName(t, full));
return s.toString();
case CLASS: case CLASS:
return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full); return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full);
default: default:
@ -130,12 +128,13 @@ public class TypeMaker {
static String getTypeString(DocEnv env, Type t, boolean full) { static String getTypeString(DocEnv env, Type t, boolean full) {
switch (t.tag) { switch (t.tag) {
case ARRAY: case ARRAY:
StringBuffer dimension = new StringBuffer(); StringBuilder s = new StringBuilder();
while (t.tag == ARRAY) { while (t.tag == ARRAY) {
dimension = dimension.append("[]"); s.append("[]");
t = env.types.elemtype(t); t = env.types.elemtype(t);
} }
return getTypeString(env, t, full) + dimension; s.insert(0, getTypeString(env, t, full));
return s.toString();
case CLASS: case CLASS:
return ParameterizedTypeImpl. return ParameterizedTypeImpl.
parameterizedTypeToString(env, (ClassType)t, full); parameterizedTypeToString(env, (ClassType)t, full);
@ -157,7 +156,7 @@ public class TypeMaker {
if (env.legacyDoclet || sym.type.getTypeArguments().isEmpty()) { if (env.legacyDoclet || sym.type.getTypeArguments().isEmpty()) {
return ""; return "";
} }
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
for (Type t : sym.type.getTypeArguments()) { for (Type t : sym.type.getTypeArguments()) {
s.append(s.length() == 0 ? "<" : ", "); s.append(s.length() == 0 ? "<" : ", ");
s.append(TypeVariableImpl.typeVarToString(env, (TypeVar)t, full)); s.append(TypeVariableImpl.typeVarToString(env, (TypeVar)t, full));
@ -175,7 +174,7 @@ public class TypeMaker {
if (env.legacyDoclet || cl.getTypeArguments().isEmpty()) { if (env.legacyDoclet || cl.getTypeArguments().isEmpty()) {
return ""; return "";
} }
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
for (Type t : cl.getTypeArguments()) { for (Type t : cl.getTypeArguments()) {
s.append(s.length() == 0 ? "<" : ", "); s.append(s.length() == 0 ? "<" : ", ");
s.append(getTypeString(env, t, full)); s.append(getTypeString(env, t, full));
@ -213,9 +212,9 @@ public class TypeMaker {
* For example, a two dimensional array of String returns '[][]'. * For example, a two dimensional array of String returns '[][]'.
*/ */
public String dimension() { public String dimension() {
StringBuffer dimension = new StringBuffer(); StringBuilder dimension = new StringBuilder();
for (Type t = arrayType; t.tag == ARRAY; t = env.types.elemtype(t)) { for (Type t = arrayType; t.tag == ARRAY; t = env.types.elemtype(t)) {
dimension = dimension.append("[]"); dimension.append("[]");
} }
return dimension.toString(); return dimension.toString();
} }
@ -304,6 +303,7 @@ public class TypeMaker {
* *
* @return name of type including any dimension information. * @return name of type including any dimension information.
*/ */
@Override
public String toString() { public String toString() {
return qualifiedTypeName() + dimension(); return qualifiedTypeName() + dimension();
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -78,14 +78,17 @@ public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
/** /**
* Return the ClassDoc of the erasure of this type variable. * Return the ClassDoc of the erasure of this type variable.
*/ */
@Override
public ClassDoc asClassDoc() { public ClassDoc asClassDoc() {
return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym); return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
} }
@Override
public TypeVariable asTypeVariable() { public TypeVariable asTypeVariable() {
return this; return this;
} }
@Override
public String toString() { public String toString() {
return typeVarToString(env, (TypeVar)type, true); return typeVarToString(env, (TypeVar)type, true);
} }
@ -96,7 +99,7 @@ public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
* "extends" clause. Class names are qualified if "full" is true. * "extends" clause. Class names are qualified if "full" is true.
*/ */
static String typeVarToString(DocEnv env, TypeVar v, boolean full) { static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
StringBuffer s = new StringBuffer(v.toString()); StringBuilder s = new StringBuilder(v.toString());
List<Type> bounds = getBounds(v, env); List<Type> bounds = getBounds(v, env);
if (bounds.nonEmpty()) { if (bounds.nonEmpty()) {
boolean first = true; boolean first = true;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,6 @@ package com.sun.tools.javadoc;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import static com.sun.javadoc.LanguageVersion.*;
import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
@ -69,18 +67,24 @@ public class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType {
/** /**
* Return the ClassDoc of the erasure of this wildcard type. * Return the ClassDoc of the erasure of this wildcard type.
*/ */
@Override
public ClassDoc asClassDoc() { public ClassDoc asClassDoc() {
return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym); return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
} }
@Override
public WildcardType asWildcardType() { public WildcardType asWildcardType() {
return this; return this;
} }
@Override
public String typeName() { return "?"; } public String typeName() { return "?"; }
@Override
public String qualifiedTypeName() { return "?"; } public String qualifiedTypeName() { return "?"; }
@Override
public String simpleTypeName() { return "?"; } public String simpleTypeName() { return "?"; }
@Override
public String toString() { public String toString() {
return wildcardTypeToString(env, (Type.WildcardType)type, true); return wildcardTypeToString(env, (Type.WildcardType)type, true);
} }
@ -96,7 +100,7 @@ public class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType {
if (env.legacyDoclet) { if (env.legacyDoclet) {
return TypeMaker.getTypeName(env.types.erasure(wildThing), full); return TypeMaker.getTypeName(env.types.erasure(wildThing), full);
} }
StringBuffer s = new StringBuffer("?"); StringBuilder s = new StringBuilder("?");
List<Type> bounds = getExtendsBounds(wildThing); List<Type> bounds = getExtendsBounds(wildThing);
if (bounds.nonEmpty()) { if (bounds.nonEmpty()) {
s.append(" extends "); s.append(" extends ");

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -104,7 +104,7 @@ tag.throws.exception_not_found={0} tag, class {1} not found.
tag.End_delimiter_missing_for_possible_SeeTag=End Delimiter } missing for possible See Tag in comment string: "{0}" tag.End_delimiter_missing_for_possible_SeeTag=End Delimiter } missing for possible See Tag in comment string: "{0}"
tag.Improper_Use_Of_Link_Tag=Missing closing ''}'' character for inline tag: "{0}" tag.Improper_Use_Of_Link_Tag=Missing closing ''}'' character for inline tag: "{0}"
javadoc.File_Read_Error=Error while reading file {0} javadoc.File_Read_Error=Error while reading file {0}
javadoc.Body_missing_from_html_file=Body tag missing from HTML javadoc.Body_missing_from_html_file=Body tag missing from HTML file
javadoc.End_body_missing_from_html_file=Close body tag missing from HTML file javadoc.End_body_missing_from_html_file=Close body tag missing from HTML file
javadoc.Multiple_package_comments=Multiple sources of package comments found for package "{0}" javadoc.Multiple_package_comments=Multiple sources of package comments found for package "{0}"
javadoc.class_not_found=Class {0} not found. javadoc.class_not_found=Class {0} not found.

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 7023703
* @summary Valid code doesn't compile
* @compile/fail/ref=T7023703neg.out -XDrawDiagnostics T7023703neg.java
*/
class T7023703neg {
void testForLoop(boolean cond) {
final int bug;
final int bug2;
for (;cond;) {
final int item = 0;
bug2 = 1; //error
}
bug = 0; //ok
}
void testForEachLoop(java.util.Collection<Integer> c) {
final int bug;
final int bug2;
for (Integer i : c) {
final int item = 0;
bug2 = 1; //error
}
bug = 0; //ok
}
void testWhileLoop(boolean cond) {
final int bug;
final int bug2;
while (cond) {
final int item = 0;
bug2 = 1; //error
}
bug = 0; //ok
}
void testDoWhileLoop(boolean cond) {
final int bug;
final int bug2;
do {
final int item = 0;
bug2 = 1; //error
} while (cond);
bug = 0; //ok
}
}

View file

@ -0,0 +1,5 @@
T7023703neg.java:37:13: compiler.err.var.might.be.assigned.in.loop: bug2
T7023703neg.java:47:13: compiler.err.var.might.be.assigned.in.loop: bug2
T7023703neg.java:57:13: compiler.err.var.might.be.assigned.in.loop: bug2
T7023703neg.java:67:13: compiler.err.var.might.be.assigned.in.loop: bug2
4 errors

View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 7023703
* @summary Valid code doesn't compile
* @compile T7023703pos.java
*/
class T7023703pos {
void testForLoop() {
final int bug;
for (;"a".equals("b");) {
final int item = 0;
}
bug = 0; //ok
}
void testForEachLoop(boolean cond, java.util.Collection<Integer> c) {
final int bug;
for (Integer i : c) {
if (cond) {
final int item = 0;
}
}
bug = 0; //ok
}
void testWhileLoop() {
final int bug;
while ("a".equals("b")) {
final int item = 0;
}
bug = 0; //ok
}
void testDoWhileLoop() {
final int bug;
do {
final int item = 0;
} while ("a".equals("b"));
bug = 0; //ok
}
private static class Inner {
private final int a, b, c, d, e;
public Inner() {
a = b = c = d = e = 0;
}
}
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 7024568
* @summary Very long method resolution causing OOM error
* @compile/fail/ref=T7024568.out -XDrawDiagnostics T7024568.java
*/
class Main {
void test(Obj o) {
o.test(0, 0, 0, 0, 0, 0, 0, 0, undefined);
}
}
interface Test {
public void test(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, String str);
public void test(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, long l);
}
interface Obj extends Test, A, B, C, D, E {}
interface A extends Test {}
interface B extends A, Test {}
interface C extends A, B, Test {}
interface D extends A, B, C, Test {}
interface E extends A, B, C, D, Test {}

View file

@ -0,0 +1,2 @@
T7024568.java:32:40: compiler.err.cant.resolve.location: kindname.variable, undefined, , , (compiler.misc.location: kindname.class, Main, null)
1 error

View file

@ -1,6 +1,6 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 4279339 * @bug 4279339 6969184
* @summary Verify that an anonymous class cannot contain a static method. * @summary Verify that an anonymous class cannot contain a static method.
* @author maddox * @author maddox
* *

View file

@ -1,6 +1,6 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 4063740 * @bug 4063740 6969184
* @summary Interfaces may only be declared in top level classes. * @summary Interfaces may only be declared in top level classes.
* @author turnidge * @author turnidge
* *

View file

@ -1,6 +1,6 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 4406966 * @bug 4406966 6969184
* @summary null qualifying inner instance creation should be error. * @summary null qualifying inner instance creation should be error.
* @author gafter * @author gafter
* *

View file

@ -0,0 +1,20 @@
/*
* @test /nodynamiccopyright/
* @bug 7022711
* @summary compiler crash in try-with-resources
* @compile/fail/ref=T7022711.out -XDrawDiagnostics T7022711.java
*/
import java.io.*;
class T7022711 {
public static void main (String args[]) throws Exception {
try (DataInputStream is = new DataInputStream(new FileInputStream("x"))) {
while (true) {
is.getChar(); // method not found
}
} catch (EOFException e) {
}
}
}

View file

@ -0,0 +1,2 @@
T7022711.java:14:19: compiler.err.cant.resolve.location.args: kindname.method, getChar, , , (compiler.misc.location.1: kindname.variable, is, java.io.DataInputStream)
1 error

View file

@ -0,0 +1,250 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7023233
* @summary False positive for -Xlint:try with nested try with resources blocks
*/
import com.sun.source.util.JavacTask;
import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.util.JCDiagnostic;
import java.net.URI;
import java.util.Arrays;
import javax.tools.Diagnostic;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
public class UnusedResourcesTest {
enum XlintOption {
NONE("none"),
TRY("try");
String opt;
XlintOption(String opt) {
this.opt = opt;
}
String getXlintOption() {
return "-Xlint:" + opt;
}
}
enum TwrStmt {
TWR1("res1"),
TWR2("res2"),
TWR3("res3");
final String resourceName;
private TwrStmt(String resourceName) {
this.resourceName = resourceName;
}
}
enum SuppressLevel {
NONE,
SUPPRESS;
String getSuppressAnno() {
return this == SUPPRESS ?
"@SuppressWarnings(\"try\")" :
"";
}
}
enum ResourceUsage {
NONE(null),
USE_R1(TwrStmt.TWR1),
USE_R2(TwrStmt.TWR2),
USE_R3(TwrStmt.TWR3);
TwrStmt stmt;
private ResourceUsage(TwrStmt stmt) {
this.stmt = stmt;
}
String usedResourceName() {
return stmt != null ? stmt.resourceName : null;
}
boolean isUsedIn(TwrStmt res, TwrStmt stmt) {
return this.stmt == res &&
stmt.ordinal() >= this.stmt.ordinal();
}
String getUsage(TwrStmt stmt) {
return this != NONE && stmt.ordinal() >= this.stmt.ordinal() ?
"use(" + usedResourceName() + ");" :
"";
}
}
static class JavaSource extends SimpleJavaFileObject {
String template = "class Resource implements AutoCloseable {\n" +
"public void close() {}\n" +
"}\n" +
"class Test {\n" +
"void use(Resource r) {}\n" +
"#S void test() {\n" +
"try (Resource #R1 = new Resource()) {\n" +
"#U1_R1\n" +
"#U1_R2\n" +
"#U1_R3\n" +
"try (Resource #R2 = new Resource()) {\n" +
"#U2_R1\n" +
"#U2_R2\n" +
"#U2_R3\n" +
"try (Resource #R3 = new Resource()) {\n" +
"#U3_R1\n" +
"#U3_R2\n" +
"#U3_R3\n" +
"}\n" +
"}\n" +
"}\n" +
"}\n" +
"}\n";
String source;
public JavaSource(SuppressLevel suppressLevel, ResourceUsage usage1,
ResourceUsage usage2, ResourceUsage usage3) {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
source = template.replace("#S", suppressLevel.getSuppressAnno()).
replace("#R1", TwrStmt.TWR1.resourceName).
replace("#R2", TwrStmt.TWR2.resourceName).
replace("#R3", TwrStmt.TWR3.resourceName).
replace("#U1_R1", usage1.getUsage(TwrStmt.TWR1)).
replace("#U1_R2", usage2.getUsage(TwrStmt.TWR1)).
replace("#U1_R3", usage3.getUsage(TwrStmt.TWR1)).
replace("#U2_R1", usage1.getUsage(TwrStmt.TWR2)).
replace("#U2_R2", usage2.getUsage(TwrStmt.TWR2)).
replace("#U2_R3", usage3.getUsage(TwrStmt.TWR2)).
replace("#U3_R1", usage1.getUsage(TwrStmt.TWR3)).
replace("#U3_R2", usage2.getUsage(TwrStmt.TWR3)).
replace("#U3_R3", usage3.getUsage(TwrStmt.TWR3));
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return source;
}
}
public static void main(String... args) throws Exception {
for (XlintOption xlint : XlintOption.values()) {
for (SuppressLevel suppressLevel : SuppressLevel.values()) {
for (ResourceUsage usage1 : ResourceUsage.values()) {
for (ResourceUsage usage2 : ResourceUsage.values()) {
for (ResourceUsage usage3 : ResourceUsage.values()) {
test(xlint,
suppressLevel,
usage1,
usage2,
usage3);
}
}
}
}
}
}
// Create a single file manager and reuse it for each compile to save time.
static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
static void test(XlintOption xlint, SuppressLevel suppressLevel, ResourceUsage usage1,
ResourceUsage usage2, ResourceUsage usage3) throws Exception {
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavaSource source = new JavaSource(suppressLevel, usage1, usage2, usage3);
DiagnosticChecker dc = new DiagnosticChecker();
JavacTask ct = (JavacTask)tool.getTask(null, fm, dc,
Arrays.asList(xlint.getXlintOption()), null, Arrays.asList(source));
ct.analyze();
check(source, xlint, suppressLevel, usage1, usage2, usage3, dc);
}
static void check(JavaSource source, XlintOption xlint, SuppressLevel suppressLevel,
ResourceUsage usage1, ResourceUsage usage2, ResourceUsage usage3, DiagnosticChecker dc) {
ResourceUsage[] usages = { usage1, usage2, usage3 };
boolean[] unusedFound = { dc.unused_r1, dc.unused_r2, dc.unused_r3 };
boolean[] usedResources = { false, false, false };
for (TwrStmt res : TwrStmt.values()) {
outer: for (TwrStmt stmt : TwrStmt.values()) {
for (ResourceUsage usage : usages) {
if (usage.isUsedIn(res, stmt)) {
usedResources[res.ordinal()] = true;
break outer;
}
}
}
}
for (TwrStmt stmt : TwrStmt.values()) {
boolean unused = !usedResources[stmt.ordinal()] &&
xlint == XlintOption.TRY &&
suppressLevel != SuppressLevel.SUPPRESS;
if (unused != unusedFound[stmt.ordinal()]) {
throw new Error("invalid diagnostics for source:\n" +
source.getCharContent(true) +
"\nOptions: " + xlint.getXlintOption() +
"\nFound unused res1: " + unusedFound[0] +
"\nFound unused res2: " + unusedFound[1] +
"\nFound unused res3: " + unusedFound[2] +
"\nExpected unused res1: " + !usedResources[0] +
"\nExpected unused res2: " + !usedResources[1] +
"\nExpected unused res3: " + !usedResources[2]);
}
}
}
static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
boolean unused_r1 = false;
boolean unused_r2 = false;
boolean unused_r3 = false;
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.WARNING &&
diagnostic.getCode().contains("try.resource.not.referenced")) {
String varName = ((JCDiagnostic)diagnostic).getArgs()[0].toString();
if (varName.equals(TwrStmt.TWR1.resourceName)) {
unused_r1 = true;
} else if (varName.equals(TwrStmt.TWR2.resourceName)) {
unused_r2 = true;
} else if (varName.equals(TwrStmt.TWR3.resourceName)) {
unused_r3 = true;
}
}
}
}
}

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -119,7 +119,7 @@ public class T6557752 {
Types types = task.getTypes(); Types types = task.getTypes();
if (types.asElement(trees.getOriginalType((ErrorType)typeMirror)) != null) { if (types.asElement(trees.getOriginalType((ErrorType)typeMirror)) != null) {
throw new AssertionError("Ttypes.asElement() error!"); throw new AssertionError("Types.asElement() error!");
} }
foundError = true; foundError = true;
} }

View file

@ -34,6 +34,7 @@ import com.sun.tools.javac.code.Kinds.KindName;
import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.*;
import com.sun.tools.javac.file.*; import com.sun.tools.javac.file.*;
import com.sun.tools.javac.main.Main; import com.sun.tools.javac.main.Main;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.parser.Token; import com.sun.tools.javac.parser.Token;
import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.AbstractDiagnosticFormatter.SimpleConfiguration; import com.sun.tools.javac.util.AbstractDiagnosticFormatter.SimpleConfiguration;
@ -107,8 +108,7 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos); JavacTaskImpl t = (JavacTaskImpl) tool.getTask(out, fm, null, opts, null, fos);
Context c = t.getContext(); Context c = t.getContext();
ArgTypeMessages.preRegister(c); ArgTypeMessages.preRegister(c);
Options options = Options.instance(c); ArgTypeJavaCompiler.preRegister(c);
Log.instance(c).setDiagnosticFormatter(new ArgTypeDiagnosticFormatter(options));
Boolean ok = t.call(); Boolean ok = t.call();
return ok; return ok;
@ -144,7 +144,7 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
} }
}; };
JavacFileManager.preRegister(c); // can't create it until Log has been set up JavacFileManager.preRegister(c); // can't create it until Log has been set up
ArgTypeDiagnosticFormatter.preRegister(c); ArgTypeJavaCompiler.preRegister(c);
ArgTypeMessages.preRegister(c); ArgTypeMessages.preRegister(c);
int result = main.compile(args.toArray(new String[args.size()]), c); int result = main.compile(args.toArray(new String[args.size()]), c);
@ -170,7 +170,7 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
Context c = new Context(); Context c = new Context();
JavacFileManager.preRegister(c); // can't create it until Log has been set up JavacFileManager.preRegister(c); // can't create it until Log has been set up
ArgTypeDiagnosticFormatter.preRegister(c); ArgTypeJavaCompiler.preRegister(c);
ArgTypeMessages.preRegister(c); ArgTypeMessages.preRegister(c);
com.sun.tools.javac.main.Main m = new com.sun.tools.javac.main.Main("javac", out); com.sun.tools.javac.main.Main m = new com.sun.tools.javac.main.Main("javac", out);
int rc = m.compile(args.toArray(new String[args.size()]), c); int rc = m.compile(args.toArray(new String[args.size()]), c);
@ -189,17 +189,6 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
* arg types. * arg types.
*/ */
static class ArgTypeDiagnosticFormatter extends AbstractDiagnosticFormatter { static class ArgTypeDiagnosticFormatter extends AbstractDiagnosticFormatter {
static void preRegister(final Context context) {
context.put(Log.logKey, new Context.Factory<Log>() {
public Log make() {
Log log = new Log(context) { };
Options options = Options.instance(context);
log.setDiagnosticFormatter(new ArgTypeDiagnosticFormatter(options));
return log;
}
});
}
ArgTypeDiagnosticFormatter(Options options) { ArgTypeDiagnosticFormatter(Options options) {
super(null, new SimpleConfiguration(options, super(null, new SimpleConfiguration(options,
@ -245,15 +234,38 @@ class ArgTypeCompilerFactory implements Example.Compiler.Factory {
} }
} }
/**
* Trivial subtype of JavaCompiler to get access to the protected compilerKey field.
* The factory is used to ensure that the log is initialized with an instance of
* ArgTypeDiagnosticFormatter before we create the required JavaCompiler.
*/
static class ArgTypeJavaCompiler extends JavaCompiler {
static void preRegister(Context context) {
context.put(compilerKey, new Context.Factory<JavaCompiler>() {
public JavaCompiler make(Context c) {
Log log = Log.instance(c);
Options options = Options.instance(c);
log.setDiagnosticFormatter(new ArgTypeDiagnosticFormatter(options));
return new JavaCompiler(c);
}
});
}
// not used
private ArgTypeJavaCompiler() {
super(null);
}
}
/** /**
* Diagnostic formatter which "localizes" a message as a line * Diagnostic formatter which "localizes" a message as a line
* containing a key, and a possibly empty set of descriptive strings for the * containing a key, and a possibly empty set of descriptive strings for the
* arg types. * arg types.
*/ */
static class ArgTypeMessages extends JavacMessages { static class ArgTypeMessages extends JavacMessages {
static void preRegister(final Context c) { static void preRegister(Context context) {
c.put(JavacMessages.messagesKey, new Context.Factory<JavacMessages>() { context.put(JavacMessages.messagesKey, new Context.Factory<JavacMessages>() {
public JavacMessages make() { public JavacMessages make(Context c) {
return new ArgTypeMessages(c) { return new ArgTypeMessages(c) {
@Override @Override
public String getLocalizedString(Locale l, String key, Object... args) { public String getLocalizedString(Locale l, String key, Object... args) {

View file

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 6964768 6964461 6964469 6964487 6964460 6964481 * @bug 6964768 6964461 6964469 6964487 6964460 6964481 6980021
* @summary need test program to validate javac resource bundles * @summary need test program to validate javac resource bundles
*/ */

View file

@ -486,7 +486,7 @@ class Example implements Comparable<Example> {
if (verbose) if (verbose)
System.err.println("run_simple: " + opts + " " + files); System.err.println("run_simple: " + opts + " " + files);
List<String> args = new ArrayList<String>(opts); List<String> args = new ArrayList<String>();
if (out != null && raw) if (out != null && raw)
args.add("-XDrawDiagnostics"); args.add("-XDrawDiagnostics");
@ -522,10 +522,10 @@ class Example implements Comparable<Example> {
super(context); super(context);
} }
static void preRegister(final Context c, final Set<String> keys) { static void preRegister(Context c, final Set<String> keys) {
if (keys != null) { if (keys != null) {
c.put(JavacMessages.messagesKey, new Context.Factory<JavacMessages>() { c.put(JavacMessages.messagesKey, new Context.Factory<JavacMessages>() {
public JavacMessages make() { public JavacMessages make(Context c) {
return new MessageTracker(c) { return new MessageTracker(c) {
@Override @Override
public String getLocalizedString(Locale l, String key, Object... args) { public String getLocalizedString(Locale l, String key, Object... args) {

View file

@ -70,7 +70,6 @@ compiler.misc.kindname.static
compiler.misc.kindname.type.variable compiler.misc.kindname.type.variable
compiler.misc.kindname.type.variable.bound compiler.misc.kindname.type.variable.bound
compiler.misc.kindname.value compiler.misc.kindname.value
compiler.misc.non.denotable.type
compiler.misc.no.unique.minimal.instance.exists compiler.misc.no.unique.minimal.instance.exists
compiler.misc.resume.abort # prompt for a response compiler.misc.resume.abort # prompt for a response
compiler.misc.source.unavailable # DiagnosticSource compiler.misc.source.unavailable # DiagnosticSource

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -21,11 +21,13 @@
* questions. * questions.
*/ */
// key: compiler.misc.diamond.invalid.arg // key: compiler.misc.diamond.and.anon.class
// key: compiler.misc.diamond
// key: compiler.err.cant.apply.diamond.1 // key: compiler.err.cant.apply.diamond.1
class DiamondInvalidArg { import java.util.*;
static class Foo<X extends Number & Comparable<Number>> { }
Foo<?> foo = new Foo<>(); class DiamondAndAnonClass {
void m() {
List<String> list = new ArrayList<>() {};
}
} }

View file

@ -1,6 +1,6 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 6956758 * @bug 6969184
* *
* @summary poor error recovery after symbol not found * @summary poor error recovery after symbol not found
* @author Maurizio Cimadamore * @author Maurizio Cimadamore

View file

@ -0,0 +1,131 @@
/*
* @test /nodynamiccopyright/
* @bug 7015430
*
* @summary Incorrect thrown type determined for unchecked invocations
* @author Daniel Smith
* @compile/fail/ref=T7015430.out -Xlint:unchecked -XDrawDiagnostics T7015430.java
*
*/
class T7015430 {
static <E extends Exception> Iterable<E> empty(Iterable<E> arg) throws E {
return null;
}
<E extends Exception> T7015430(Iterable<E> arg) throws E { }
static <E extends Exception> Iterable<E> empty2(Iterable x) throws E {
return null;
}
static class Foo<X extends Exception> {
Foo() throws X {}
}
/**
* Method invocation, no unchecked
* inferred: RuntimeException - should pass
*/
void m1() {
Iterable<RuntimeException> i = java.util.Collections.emptyList();
empty(i);
}
/**
* Method invocation, unchecked, inferred arguments
* inferred: Exception - should fail
*/
void m2() {
Iterable i = java.util.Collections.EMPTY_LIST;
empty(i);
}
/**
* Method invocation, unchecked, explicit arguments
* inferred: RuntimeException - should pass
*/
void m3() {
Iterable i = java.util.Collections.EMPTY_LIST;
T7015430.<RuntimeException>empty(i);
}
/**
* Constructor invocation, no unchecked
* inferred: RuntimeException - should pass
*/
void m4() {
Iterable<RuntimeException> i = java.util.Collections.emptyList();
new T7015430(i);
}
/**
* Constructor invocation, unchecked, inferred arguments
* inferred: Exception - should fail
*/
void m5() {
Iterable i = java.util.Collections.EMPTY_LIST;
new T7015430(i);
}
/**
* Constructor invocation, unchecked, explicit arguments
* inferred: RuntimeException - should pass
*/
void m6() {
Iterable i = java.util.Collections.EMPTY_LIST;
new <RuntimeException>T7015430(i);
}
/**
* Method invocation, no unchecked, inferred arguments
* inferred: RuntimeException - should pass
*/
void m7() {
Iterable i = java.util.Collections.EMPTY_LIST;
Iterable<RuntimeException> e = empty2(i);
}
/**
* Method invocation, no unchecked, inferred arguments
* inferred: Exception - should fail
*/
void m8() {
Iterable i = java.util.Collections.EMPTY_LIST;
empty2(i);
}
/**
* Constructor invocation, unchecked, explicit arguments
* inferred: RuntimeException - should pass
*/
void m9() {
Iterable i = java.util.Collections.EMPTY_LIST;
new <RuntimeException> T7015430(i);
}
/**
* Constructor invocation, unchecked, inferred arguments
* inferred: Exception - should fail
*/
void m10() {
Iterable i = java.util.Collections.EMPTY_LIST;
new T7015430(i);
}
/**
* Constructor invocation, no unchecked, inferred arguments (diamond)
* inferred: RuntimeException - should pass
*/
void m11() {
Foo<RuntimeException> o = new Foo<>();
}
/**
* Constructor invocation, no unchecked, inferred arguments (diamond)
* inferred: Exception - should fail
*/
void m12() {
new Foo<>();
}
}

View file

@ -0,0 +1,19 @@
T7015430.java:41:15: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E>
T7015430.java:41:14: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:50:42: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
T7015430.java:50:41: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:68:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E>
T7015430.java:68:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:77:40: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
T7015430.java:77:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:104:41: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
T7015430.java:104:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:113:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E>
T7015430.java:113:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
T7015430.java:41:14: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
T7015430.java:68:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
T7015430.java:95:15: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
T7015430.java:113:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
T7015430.java:129:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
5 errors
12 warnings

View file

@ -0,0 +1,23 @@
/*
* @test /nodynamiccopyright/
* @bug 7020657 6985719
*
* @summary Javac rejects a fairly common idiom with raw override and interfaces
* @author Maurizio Cimadamore
* @compile/fail/ref=T7020657neg.out -XDrawDiagnostics T7020657neg.java
*
*/
import java.util.*;
class T7020657neg {
interface A {
int get(List<String> l);
}
interface B {
int get(List<Integer> l);
}
interface C extends A, B { }
}

View file

@ -0,0 +1,2 @@
T7020657neg.java:22:5: compiler.err.name.clash.same.erasure.no.override: get(java.util.List<java.lang.Integer>), T7020657neg.B, get(java.util.List<java.lang.String>), T7020657neg.A
1 error

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7020657 6985719
*
* @summary Javac rejects a fairly common idiom with raw override and interfaces
* @author Robert Field
* @compile T7020657pos.java
*
*/
import java.util.*;
class T7020657pos {
interface A {
int get(List<String> l);
}
interface B {
int get(List<Integer> l);
}
interface C extends A, B {
int get(List l);
}
}

View file

@ -0,0 +1,17 @@
/*
* @test /nodynamiccopyright/
* @bug 7022054
*
* @summary Invalid compiler error on covariant overriding methods with the same erasure
* @compile/fail/ref=T7022054neg1.out -XDrawDiagnostics T7022054neg1.java
*
*/
class T7022054neg1 {
static class A {
A m(String s) { return null; }
}
static class B extends A {
<X extends String> A m(X s) { return null; }
}
}

View file

@ -0,0 +1,2 @@
T7022054neg1.java:15:30: compiler.err.name.clash.same.erasure.no.override: <X>m(X), T7022054neg1.B, m(java.lang.String), T7022054neg1.A, <X>m(X), T7022054neg1.B
1 error

View file

@ -0,0 +1,17 @@
/*
* @test /nodynamiccopyright/
* @bug 7022054
*
* @summary Invalid compiler error on covariant overriding methods with the same erasure
* @compile/fail/ref=T7022054neg2.out -XDrawDiagnostics T7022054neg2.java
*
*/
class T7022054neg2 {
static class A {
static A m(String s) { return null; }
}
static class B extends A {
static <X extends String> A m(X s) { return null; }
}
}

View file

@ -0,0 +1,2 @@
T7022054neg2.java:15:37: compiler.err.name.clash.same.erasure.no.hide: <X>m(X), T7022054neg2.B, m(java.lang.String), T7022054neg2.A
1 error

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7022054
*
* @summary Invalid compiler error on covariant overriding methods with the same erasure
* @compile T7022054pos1.java
*
*/
class T7022054pos1 {
static class A {
A m(String s) { return null; }
}
static class B extends A {
<X extends B> X m(String s) { return null; }
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7022054
*
* @summary Invalid compiler error on covariant overriding methods with the same erasure
* @compile T7022054pos2.java
*
*/
class T7022054pos2 {
static class A {
static A m(String s) { return null; }
}
static class B extends A {
static <X extends B> X m(String s) { return null; }
}
}

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 6996914 * @bug 6996914 7020044
* @summary Diamond inference: problem when accessing protected constructor * @summary Diamond inference: problem when accessing protected constructor
* @run main T6996914a * @run main T6996914a
*/ */
@ -53,17 +53,6 @@ public class T6996914a {
} }
} }
enum DiamondKind {
STANDARD("new Foo<>();"),
ANON("new Foo<>() {};");
String expr;
DiamondKind(String expr) {
this.expr = expr;
}
}
enum ConstructorKind { enum ConstructorKind {
PACKAGE(""), PACKAGE(""),
PROTECTED("protected"), PROTECTED("protected"),
@ -104,14 +93,14 @@ public class T6996914a {
final static String sourceStub = final static String sourceStub =
"#I\n" + "#I\n" +
"class Test {\n" + "class Test {\n" +
" Foo<String> fs = #D\n" + " Foo<String> fs = new Foo<>();\n" +
"}\n"; "}\n";
String source; String source;
public ClientClass(PackageKind pk, DiamondKind dk) { public ClientClass(PackageKind pk) {
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
source = sourceStub.replace("#I", pk.importDecl).replace("#D", dk.expr); source = sourceStub.replace("#I", pk.importDecl);
} }
@Override @Override
@ -123,22 +112,20 @@ public class T6996914a {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
for (PackageKind pk : PackageKind.values()) { for (PackageKind pk : PackageKind.values()) {
for (ConstructorKind ck : ConstructorKind.values()) { for (ConstructorKind ck : ConstructorKind.values()) {
for (DiamondKind dk : DiamondKind.values()) { compileAndCheck(pk, ck);
compileAndCheck(pk, ck, dk);
}
} }
} }
} }
static void compileAndCheck(PackageKind pk, ConstructorKind ck, DiamondKind dk) throws Exception { static void compileAndCheck(PackageKind pk, ConstructorKind ck) throws Exception {
FooClass foo = new FooClass(pk, ck); FooClass foo = new FooClass(pk, ck);
ClientClass client = new ClientClass(pk, dk); ClientClass client = new ClientClass(pk);
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
ErrorListener el = new ErrorListener(); ErrorListener el = new ErrorListener();
JavacTask ct = (JavacTask)tool.getTask(null, null, el, JavacTask ct = (JavacTask)tool.getTask(null, null, el,
null, null, Arrays.asList(foo, client)); null, null, Arrays.asList(foo, client));
ct.analyze(); ct.analyze();
if (el.errors > 0 == check(pk, ck, dk)) { if (el.errors > 0 == check(pk, ck)) {
String msg = el.errors > 0 ? String msg = el.errors > 0 ?
"Error compiling files" : "Error compiling files" :
"No error when compiling files"; "No error when compiling files";
@ -146,10 +133,9 @@ public class T6996914a {
} }
} }
static boolean check(PackageKind pk, ConstructorKind ck, DiamondKind dk) { static boolean check(PackageKind pk, ConstructorKind ck) {
switch (pk) { switch (pk) {
case A: return ck == ConstructorKind.PUBLIC || case A: return ck == ConstructorKind.PUBLIC;
(ck == ConstructorKind.PROTECTED && dk == DiamondKind.ANON);
case DEFAULT: return ck != ConstructorKind.PRIVATE; case DEFAULT: return ck != ConstructorKind.PRIVATE;
default: throw new AssertionError("Unknown package kind"); default: throw new AssertionError("Unknown package kind");
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 6996914 * @bug 6996914 7020044
* @summary Diamond inference: problem when accessing protected constructor * @summary Diamond inference: problem when accessing protected constructor
* @compile T6996914b.java * @compile T6996914b.java
*/ */
@ -35,5 +35,4 @@ class Super<X,Y> {
class Test { class Test {
Super<String,Integer> ssi1 = new Super<>(1, "", 2); Super<String,Integer> ssi1 = new Super<>(1, "", 2);
Super<String,Integer> ssi2 = new Super<>(1, "", 2) {};
} }

View file

@ -1,6 +1,6 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 6939780 * @bug 6939780 7020044
* *
* @summary add a warning to detect diamond sites * @summary add a warning to detect diamond sites
* @author mcimadamore * @author mcimadamore

View file

@ -1,5 +1,3 @@
T6939780.java:19:28: compiler.warn.diamond.redundant.args: Foo<java.lang.Number>, Foo<java.lang.Number> T6939780.java:19:28: compiler.warn.diamond.redundant.args: Foo<java.lang.Number>, Foo<java.lang.Number>
T6939780.java:20:28: compiler.warn.diamond.redundant.args.1: Foo<java.lang.Integer>, Foo<java.lang.Number> T6939780.java:20:28: compiler.warn.diamond.redundant.args.1: Foo<java.lang.Integer>, Foo<java.lang.Number>
T6939780.java:22:28: compiler.warn.diamond.redundant.args: Foo<java.lang.Number>, Foo<java.lang.Number> 2 warnings
T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: Foo<java.lang.Integer>, Foo<java.lang.Number>
4 warnings

View file

@ -1,8 +1,9 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 6939620 * @bug 6939620 7020044
* *
* @summary Switch to 'complex' diamond inference scheme * @summary Check that diamond fails when inference violates declared bounds
* (basic test with nested class, generic/non-generic constructors)
* @author mcimadamore * @author mcimadamore
* @compile/fail/ref=Neg01.out Neg01.java -XDrawDiagnostics * @compile/fail/ref=Neg01.out Neg01.java -XDrawDiagnostics
* *
@ -20,19 +21,9 @@ class Neg01<X extends Number> {
Neg01<?> n3 = new Neg01<>(""); Neg01<?> n3 = new Neg01<>("");
Neg01<? super String> n4 = new Neg01<>(""); Neg01<? super String> n4 = new Neg01<>("");
Neg01<String> n5 = new Neg01<>(""){}; Neg01<String> n5 = new Neg01<>("", "");
Neg01<? extends String> n6 = new Neg01<>(""){}; Neg01<? extends String> n6 = new Neg01<>("", "");
Neg01<?> n7 = new Neg01<>(""){}; Neg01<?> n7 = new Neg01<>("", "");
Neg01<? super String> n8 = new Neg01<>(""){}; Foo<? super String> n8 = new Neg01<>("", "");
Neg01<String> n9 = new Neg01<>("", "");
Neg01<? extends String> n10 = new Neg01<>("", "");
Neg01<?> n11 = new Neg01<>("", "");
Foo<? super String> n12 = new Neg01<>("", "");
Neg01<String> n13 = new Neg01<>("", ""){};
Neg01<? extends String> n14 = new Neg01<>("", ""){};
Neg01<?> n15 = new Neg01<>("", ""){};
Neg01<? super String> n16 = new Neg01<>("", ""){};
} }
} }

View file

@ -1,29 +1,15 @@
Neg01.java:18:15: compiler.err.not.within.bounds: java.lang.String, X Neg01.java:19:15: compiler.err.not.within.bounds: java.lang.String, X
Neg01.java:18:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null Neg01.java:19:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:19:15: compiler.err.not.within.bounds: ? extends java.lang.String, X Neg01.java:20:15: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg01.java:19:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null Neg01.java:20:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:20:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null Neg01.java:21:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:21:15: compiler.err.not.within.bounds: ? super java.lang.String, X Neg01.java:22:15: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg01.java:21:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null Neg01.java:22:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:23:15: compiler.err.not.within.bounds: java.lang.String, X Neg01.java:24:15: compiler.err.not.within.bounds: java.lang.String, X
Neg01.java:23:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null Neg01.java:24:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:24:15: compiler.err.not.within.bounds: ? extends java.lang.String, X Neg01.java:25:15: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg01.java:24:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null Neg01.java:25:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:25:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null Neg01.java:26:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:26:15: compiler.err.not.within.bounds: ? super java.lang.String, X Neg01.java:27:9: compiler.err.cant.resolve.location: kindname.class, Foo, , , (compiler.misc.location: kindname.class, Neg01<X>, null)
Neg01.java:26:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null Neg01.java:27:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:28:15: compiler.err.not.within.bounds: java.lang.String, X 14 errors
Neg01.java:28:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:29:15: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg01.java:29:39: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:30:24: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:31:9: compiler.err.cant.resolve.location: kindname.class, Foo, , , (compiler.misc.location: kindname.class, Neg01<X>, null)
Neg01.java:31:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:33:15: compiler.err.not.within.bounds: java.lang.String, X
Neg01.java:33:29: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:34:15: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg01.java:34:39: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:35:24: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
Neg01.java:36:15: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg01.java:36:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg01), null
28 errors

View file

@ -1,8 +1,9 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 6939620 * @bug 6939620 7020044
* *
* @summary Switch to 'complex' diamond inference scheme * @summary Check that diamond fails when inference violates declared bounds
* (test with nested class, qualified/simple type expressions)
* @author mcimadamore * @author mcimadamore
* @compile/fail/ref=Neg02.out Neg02.java -XDrawDiagnostics * @compile/fail/ref=Neg02.out Neg02.java -XDrawDiagnostics
* *
@ -21,20 +22,10 @@ class Neg02 {
Foo<?> f3 = new Foo<>(""); Foo<?> f3 = new Foo<>("");
Foo<? super String> f4 = new Foo<>(""); Foo<? super String> f4 = new Foo<>("");
Foo<String> f5 = new Foo<>(""){}; Foo<String> f5 = new Foo<>("", "");
Foo<? extends String> f6 = new Foo<>(""){}; Foo<? extends String> f6 = new Foo<>("", "");
Foo<?> f7 = new Foo<>(""){}; Foo<?> f7 = new Foo<>("", "");
Foo<? super String> f8 = new Foo<>(""){}; Foo<? super String> f8 = new Foo<>("", "");
Foo<String> f9 = new Foo<>("", "");
Foo<? extends String> f10 = new Foo<>("", "");
Foo<?> f11 = new Foo<>("", "");
Foo<? super String> f12 = new Foo<>("", "");
Foo<String> f13 = new Foo<>("", ""){};
Foo<? extends String> f14 = new Foo<>("", ""){};
Foo<?> f15 = new Foo<>("", ""){};
Foo<? super String> f16 = new Foo<>("", ""){};
} }
void testQualified() { void testQualified() {
@ -43,19 +34,9 @@ class Neg02 {
Foo<?> f3 = new Neg02.Foo<>(""); Foo<?> f3 = new Neg02.Foo<>("");
Foo<? super String> f4 = new Neg02.Foo<>(""); Foo<? super String> f4 = new Neg02.Foo<>("");
Foo<String> f5 = new Neg02.Foo<>(""){}; Foo<String> f5 = new Neg02.Foo<>("", "");
Foo<? extends String> f6 = new Neg02.Foo<>(""){}; Foo<? extends String> f6 = new Neg02.Foo<>("", "");
Foo<?> f7 = new Neg02.Foo<>(""){}; Foo<?> f7 = new Neg02.Foo<>("", "");
Foo<? super String> f8 = new Neg02.Foo<>(""){}; Foo<? super String> f8 = new Neg02.Foo<>("", "");
Foo<String> f9 = new Neg02.Foo<>("", "");
Foo<? extends String> f10 = new Neg02.Foo<>("", "");
Foo<?> f11 = new Neg02.Foo<>("", "");
Foo<? super String> f12 = new Neg02.Foo<>("", "");
Foo<String> f13 = new Neg02.Foo<>("", ""){};
Foo<? extends String> f14 = new Neg02.Foo<>("", ""){};
Foo<?> f15 = new Neg02.Foo<>("", ""){};
Foo<? super String> f16 = new Neg02.Foo<>("", ""){};
} }
} }

View file

@ -1,57 +1,29 @@
Neg02.java:19:13: compiler.err.not.within.bounds: java.lang.String, X Neg02.java:20:13: compiler.err.not.within.bounds: java.lang.String, X
Neg02.java:19:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:20:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:20:13: compiler.err.not.within.bounds: ? extends java.lang.String, X Neg02.java:21:13: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg02.java:20:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:21:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:21:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:22:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:22:13: compiler.err.not.within.bounds: ? super java.lang.String, X Neg02.java:23:13: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg02.java:22:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:23:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:24:13: compiler.err.not.within.bounds: java.lang.String, X Neg02.java:25:13: compiler.err.not.within.bounds: java.lang.String, X
Neg02.java:24:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:25:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:25:13: compiler.err.not.within.bounds: ? extends java.lang.String, X Neg02.java:26:13: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg02.java:25:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:26:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:26:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:27:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:27:13: compiler.err.not.within.bounds: ? super java.lang.String, X Neg02.java:28:13: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg02.java:27:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:28:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:29:13: compiler.err.not.within.bounds: java.lang.String, X Neg02.java:32:13: compiler.err.not.within.bounds: java.lang.String, X
Neg02.java:29:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:32:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:30:13: compiler.err.not.within.bounds: ? extends java.lang.String, X Neg02.java:33:13: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg02.java:30:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:33:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:31:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:34:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:32:13: compiler.err.not.within.bounds: ? super java.lang.String, X Neg02.java:35:13: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg02.java:32:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:35:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:34:13: compiler.err.not.within.bounds: java.lang.String, X Neg02.java:37:13: compiler.err.not.within.bounds: java.lang.String, X
Neg02.java:34:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:37:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:35:13: compiler.err.not.within.bounds: ? extends java.lang.String, X Neg02.java:38:13: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg02.java:35:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:38:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:36:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:39:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:37:13: compiler.err.not.within.bounds: ? super java.lang.String, X Neg02.java:40:13: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg02.java:37:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null Neg02.java:40:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:41:13: compiler.err.not.within.bounds: java.lang.String, X 28 errors
Neg02.java:41:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:42:13: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg02.java:42:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:43:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:44:13: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg02.java:44:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:46:13: compiler.err.not.within.bounds: java.lang.String, X
Neg02.java:46:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:47:13: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg02.java:47:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:48:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:49:13: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg02.java:49:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:51:13: compiler.err.not.within.bounds: java.lang.String, X
Neg02.java:51:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:52:13: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg02.java:52:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:53:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:54:13: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg02.java:54:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:56:13: compiler.err.not.within.bounds: java.lang.String, X
Neg02.java:56:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:57:13: compiler.err.not.within.bounds: ? extends java.lang.String, X
Neg02.java:57:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:58:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
Neg02.java:59:13: compiler.err.not.within.bounds: ? super java.lang.String, X
Neg02.java:59:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg02.Foo), null
56 errors

View file

@ -1,8 +1,9 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 6939620 * @bug 6939620 7020044
* *
* @summary Switch to 'complex' diamond inference scheme * @summary Check that diamond fails when inference violates declared bounds
* (test with inner class, qualified/simple type expressions)
* @author mcimadamore * @author mcimadamore
* @compile/fail/ref=Neg03.out Neg03.java -XDrawDiagnostics * @compile/fail/ref=Neg03.out Neg03.java -XDrawDiagnostics
* *
@ -21,20 +22,10 @@ class Neg03<U> {
Foo<?> f3 = new Foo<>(""); Foo<?> f3 = new Foo<>("");
Foo<? super String> f4 = new Foo<>(""); Foo<? super String> f4 = new Foo<>("");
Foo<String> f5 = new Foo<>(""){}; Foo<String> f5 = new Foo<>("", "");
Foo<? extends String> f6 = new Foo<>(""){}; Foo<? extends String> f6 = new Foo<>("", "");
Foo<?> f7 = new Foo<>(""){}; Foo<?> f7 = new Foo<>("", "");
Foo<? super String> f8 = new Foo<>(""){}; Foo<? super String> f8 = new Foo<>("", "");
Foo<String> f9 = new Foo<>("", "");
Foo<? extends String> f10 = new Foo<>("", "");
Foo<?> f11 = new Foo<>("", "");
Foo<? super String> f12 = new Foo<>("", "");
Foo<String> f13 = new Foo<>("", ""){};
Foo<? extends String> f14 = new Foo<>("", ""){};
Foo<?> f15 = new Foo<>("", ""){};
Foo<? super String> f16 = new Foo<>("", ""){};
} }
void testQualified_1() { void testQualified_1() {
@ -43,20 +34,10 @@ class Neg03<U> {
Foo<?> f3 = new Neg03<U>.Foo<>(""); Foo<?> f3 = new Neg03<U>.Foo<>("");
Foo<? super String> f4 = new Neg03<U>.Foo<>(""); Foo<? super String> f4 = new Neg03<U>.Foo<>("");
Foo<String> f5 = new Neg03<U>.Foo<>(""){}; Foo<String> f5 = new Neg03<U>.Foo<>("", "");
Foo<? extends String> f6 = new Neg03<U>.Foo<>(""){}; Foo<? extends String> f6 = new Neg03<U>.Foo<>("", "");
Foo<?> f7 = new Neg03<U>.Foo<>(""){}; Foo<?> f7 = new Neg03<U>.Foo<>("", "");
Foo<? super String> f8 = new Neg03<U>.Foo<>(""){}; Foo<? super String> f8 = new Neg03<U>.Foo<>("", "");
Foo<String> f9 = new Neg03<U>.Foo<>("", "");
Foo<? extends String> f10 = new Neg03<U>.Foo<>("", "");
Foo<?> f11 = new Neg03<U>.Foo<>("", "");
Foo<? super String> f12 = new Neg03<U>.Foo<>("", "");
Foo<String> f13 = new Neg03<U>.Foo<>("", ""){};
Foo<? extends String> f14 = new Neg03<U>.Foo<>("", ""){};
Foo<?> f15 = new Neg03<U>.Foo<>("", ""){};
Foo<? super String> f16 = new Neg03<U>.Foo<>("", ""){};
} }
void testQualified_2(Neg03<U> n) { void testQualified_2(Neg03<U> n) {
@ -65,19 +46,9 @@ class Neg03<U> {
Foo<?> f3 = n.new Foo<>(""); Foo<?> f3 = n.new Foo<>("");
Foo<? super String> f4 = n.new Foo<>(""); Foo<? super String> f4 = n.new Foo<>("");
Foo<String> f5 = n.new Foo<>(""){}; Foo<String> f5 = n.new Foo<>("", "");
Foo<? extends String> f6 = n.new Foo<>(""){}; Foo<? extends String> f6 = n.new Foo<>("", "");
Foo<?> f7 = n.new Foo<>(""){}; Foo<?> f7 = n.new Foo<>("", "");
Foo<? super String> f8 = n.new Foo<>(""){}; Foo<? super String> f8 = n.new Foo<>("", "");
Foo<String> f9 = n.new Foo<>("", "");
Foo<? extends String> f10 = n.new Foo<>("", "");
Foo<?> f11 = n.new Foo<>("", "");
Foo<? super String> f12 = n.new Foo<>("", "");
Foo<String> f13 = n.new Foo<>("", ""){};
Foo<? extends String> f14 = n.new Foo<>("", ""){};
Foo<?> f15 = n.new Foo<>("", ""){};
Foo<? super String> f16 = n.new Foo<>("", ""){};
} }
} }

View file

@ -1,85 +1,43 @@
Neg03.java:19:13: compiler.err.not.within.bounds: java.lang.String, V Neg03.java:20:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:19:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:20:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:20:13: compiler.err.not.within.bounds: ? extends java.lang.String, V Neg03.java:21:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:20:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:21:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:21:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:22:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:22:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg03.java:23:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:22:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:23:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:24:13: compiler.err.not.within.bounds: java.lang.String, V Neg03.java:25:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:24:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:25:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:25:13: compiler.err.not.within.bounds: ? extends java.lang.String, V Neg03.java:26:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:25:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:26:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:26:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:27:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:27:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg03.java:28:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:27:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:28:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:29:13: compiler.err.not.within.bounds: java.lang.String, V Neg03.java:32:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:29:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:32:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:30:13: compiler.err.not.within.bounds: ? extends java.lang.String, V Neg03.java:33:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:30:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:33:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:31:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:34:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:32:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg03.java:35:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:32:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:35:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:34:13: compiler.err.not.within.bounds: java.lang.String, V Neg03.java:37:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:34:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:37:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:35:13: compiler.err.not.within.bounds: ? extends java.lang.String, V Neg03.java:38:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:35:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:38:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:36:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:39:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:37:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg03.java:40:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:37:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:40:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:41:13: compiler.err.not.within.bounds: java.lang.String, V Neg03.java:44:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:41:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:44:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:42:13: compiler.err.not.within.bounds: ? extends java.lang.String, V Neg03.java:45:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:42:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:45:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:43:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:46:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:44:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg03.java:47:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:44:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:46:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:46:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:47:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:47:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:47:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:48:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:49:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:49:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg03.java:49:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:49:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:50:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:51:13: compiler.err.not.within.bounds: java.lang.String, V Neg03.java:50:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:51:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:51:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:52:13: compiler.err.not.within.bounds: ? extends java.lang.String, V Neg03.java:52:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:52:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null Neg03.java:52:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:53:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null 42 errors
Neg03.java:54:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:54:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:56:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:56:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:57:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:57:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:58:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:59:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:59:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:63:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:63:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:64:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:64:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:65:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:66:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:66:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:68:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:68:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:69:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:69:38: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:70:23: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:71:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:71:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:73:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:73:28: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:74:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:74:39: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:75:24: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:76:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:76:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:78:13: compiler.err.not.within.bounds: java.lang.String, V
Neg03.java:78:29: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:79:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg03.java:79:39: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:80:24: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
Neg03.java:81:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg03.java:81:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Neg03.Foo), null
84 errors

View file

@ -1,8 +1,9 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 6939620 * @bug 6939620 7020044
* *
* @summary Switch to 'complex' diamond inference scheme * @summary Check that diamond fails when inference violates declared bounds
* (test with local class, qualified/simple type expressions)
* @author mcimadamore * @author mcimadamore
* @compile/fail/ref=Neg04.out Neg04.java -XDrawDiagnostics * @compile/fail/ref=Neg04.out Neg04.java -XDrawDiagnostics
* *
@ -20,19 +21,9 @@ class Neg04 {
Foo<?> n3 = new Foo<>(""); Foo<?> n3 = new Foo<>("");
Foo<? super String> n4 = new Foo<>(""); Foo<? super String> n4 = new Foo<>("");
Foo<String> n5 = new Foo<>(""){}; Foo<String> n5 = new Foo<>("", "");
Foo<? extends String> n6 = new Foo<>(""){}; Foo<? extends String> n6 = new Foo<>("", "");
Foo<?> n7 = new Foo<>(""){}; Foo<?> n7 = new Foo<>("", "");
Foo<? super String> n8 = new Foo<>(""){}; Foo<? super String> n8 = new Foo<>("", "");
Foo<String> n9 = new Foo<>("", "");
Foo<? extends String> n10 = new Foo<>("", "");
Foo<?> n11 = new Foo<>("", "");
Foo<? super String> n12 = new Foo<>("", "");
Foo<String> n13 = new Foo<>("", ""){};
Foo<? extends String> n14 = new Foo<>("", ""){};
Foo<?> n15 = new Foo<>("", ""){};
Foo<? super String> n16 = new Foo<>("", ""){};
} }
} }

View file

@ -1,29 +1,15 @@
Neg04.java:18:13: compiler.err.not.within.bounds: java.lang.String, V Neg04.java:19:13: compiler.err.not.within.bounds: java.lang.String, V
Neg04.java:18:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null Neg04.java:19:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:19:13: compiler.err.not.within.bounds: ? extends java.lang.String, V Neg04.java:20:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg04.java:19:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null Neg04.java:20:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:20:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null Neg04.java:21:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:21:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg04.java:22:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg04.java:21:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null Neg04.java:22:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:23:13: compiler.err.not.within.bounds: java.lang.String, V Neg04.java:24:13: compiler.err.not.within.bounds: java.lang.String, V
Neg04.java:23:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null Neg04.java:24:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:24:13: compiler.err.not.within.bounds: ? extends java.lang.String, V Neg04.java:25:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg04.java:24:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null Neg04.java:25:36: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:25:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null Neg04.java:26:21: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:26:13: compiler.err.not.within.bounds: ? super java.lang.String, V Neg04.java:27:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg04.java:26:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null Neg04.java:27:34: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:28:13: compiler.err.not.within.bounds: java.lang.String, V 14 errors
Neg04.java:28:26: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:29:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg04.java:29:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:30:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:31:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg04.java:31:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:33:13: compiler.err.not.within.bounds: java.lang.String, V
Neg04.java:33:27: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:34:13: compiler.err.not.within.bounds: ? extends java.lang.String, V
Neg04.java:34:37: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:35:22: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
Neg04.java:36:13: compiler.err.not.within.bounds: ? super java.lang.String, V
Neg04.java:36:35: compiler.err.cant.apply.diamond: (compiler.misc.diamond: Foo), null
28 errors

View file

@ -1,8 +1,8 @@
/* /*
* @test /nodynamiccopyright/ * @test /nodynamiccopyright/
* @bug 6939620 * @bug 6939620 7020044
* *
* @summary Switch to 'complex' diamond inference scheme * @summary Check that usage of rare types doesn't cause spurious diamond diagnostics
* @author mcimadamore * @author mcimadamore
* @compile/fail/ref=Neg05.out Neg05.java -XDrawDiagnostics * @compile/fail/ref=Neg05.out Neg05.java -XDrawDiagnostics
* *
@ -21,20 +21,10 @@ class Neg05<U> {
Neg05<?>.Foo<?> f3 = new Neg05.Foo<>(""); Neg05<?>.Foo<?> f3 = new Neg05.Foo<>("");
Neg05<?>.Foo<? super String> f4 = new Neg05.Foo<>(""); Neg05<?>.Foo<? super String> f4 = new Neg05.Foo<>("");
Neg05<?>.Foo<String> f5 = new Neg05.Foo<>(""){}; Neg05<?>.Foo<String> f5 = new Neg05.Foo<>("", "");
Neg05<?>.Foo<? extends String> f6 = new Neg05.Foo<>(""){}; Neg05<?>.Foo<? extends String> f6 = new Neg05.Foo<>("", "");
Neg05<?>.Foo<?> f7 = new Neg05.Foo<>(""){}; Neg05<?>.Foo<?> f7 = new Neg05.Foo<>("", "");
Neg05<?>.Foo<? super String> f8 = new Neg05.Foo<>(""){}; Neg05<?>.Foo<? super String> f8 = new Neg05.Foo<>("", "");
Neg05<?>.Foo<String> f9 = new Neg05.Foo<>("", "");
Neg05<?>.Foo<? extends String> f10 = new Neg05.Foo<>("", "");
Neg05<?>.Foo<?> f11 = new Neg05.Foo<>("", "");
Neg05<?>.Foo<? super String> f12 = new Neg05.Foo<>("", "");
Neg05<?>.Foo<String> f13 = new Neg05.Foo<>("", ""){};
Neg05<?>.Foo<? extends String> f14 = new Neg05.Foo<>("", ""){};
Neg05<?>.Foo<?> f15 = new Neg05.Foo<>("", ""){};
Neg05<?>.Foo<? super String> f16 = new Neg05.Foo<>("", ""){};
} }
void testRare_2(Neg05 n) { void testRare_2(Neg05 n) {
@ -43,19 +33,9 @@ class Neg05<U> {
Neg05<?>.Foo<?> f3 = n.new Foo<>(""); Neg05<?>.Foo<?> f3 = n.new Foo<>("");
Neg05<?>.Foo<? super String> f4 = n.new Foo<>(""); Neg05<?>.Foo<? super String> f4 = n.new Foo<>("");
Neg05<?>.Foo<String> f5 = n.new Foo<>(""){}; Neg05<?>.Foo<String> f5 = n.new Foo<>("", "");
Neg05<?>.Foo<? extends String> f6 = n.new Foo<>(""){}; Neg05<?>.Foo<? extends String> f6 = n.new Foo<>("", "");
Neg05<?>.Foo<?> f7 = n.new Foo<>(""){}; Neg05<?>.Foo<?> f7 = n.new Foo<>("", "");
Neg05<?>.Foo<? super String> f8 = n.new Foo<>(""){}; Neg05<?>.Foo<? super String> f8 = n.new Foo<>("", "");
Neg05<?>.Foo<String> f9 = n.new Foo<>("", "");
Neg05<?>.Foo<? extends String> f10 = n.new Foo<>("", "");
Neg05<?>.Foo<?> f11 = n.new Foo<>("", "");
Neg05<?>.Foo<? super String> f12 = n.new Foo<>("", "");
Neg05<?>.Foo<String> f13 = n.new Foo<>("", ""){};
Neg05<?>.Foo<? extends String> f14 = n.new Foo<>("", ""){};
Neg05<?>.Foo<?> f15 = n.new Foo<>("", ""){};
Neg05<?>.Foo<? super String> f16 = n.new Foo<>("", ""){};
} }
} }

Some files were not shown because too many files have changed in this diff Show more