Fri, 29 Jan 2010 16:06:51 -0800
6919889: assorted position errors in compiler syntax trees
Reviewed-by: darcy
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java Wed Jan 27 14:46:37 2010 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Fri Jan 29 16:06:51 2010 -0800 1.3 @@ -113,6 +113,7 @@ 1.4 public static final int ENUM = 1<<14; 1.5 1.6 public static final int StandardFlags = 0x0fff; 1.7 + public static final int ModifierFlags = StandardFlags & ~INTERFACE; 1.8 1.9 // Because the following access flags are overloaded with other 1.10 // bit positions, we translate them when reading and writing class
2.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Jan 27 14:46:37 2010 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Jan 29 16:06:51 2010 -0800 2.3 @@ -761,23 +761,28 @@ 2.4 JCExpression[] odStack = newOdStack(); 2.5 List<Token[]> savedOp = opStackSupply.elems; 2.6 Token[] opStack = newOpStack(); 2.7 + List<int[]> savedPos = posStackSupply.elems; 2.8 + int[] posStack = newPosStack(); 2.9 // optimization, was odStack = new Tree[...]; opStack = new Tree[...]; 2.10 int top = 0; 2.11 odStack[0] = t; 2.12 int startPos = S.pos(); 2.13 Token topOp = ERROR; 2.14 + int topOpPos = Position.NOPOS; 2.15 while (prec(S.token()) >= minprec) { 2.16 + posStack[top] = topOpPos; 2.17 opStack[top] = topOp; 2.18 top++; 2.19 topOp = S.token(); 2.20 - int pos = S.pos(); 2.21 + topOpPos = S.pos(); 2.22 S.nextToken(); 2.23 - odStack[top] = topOp == INSTANCEOF ? parseType() : term3(); 2.24 + odStack[top] = (topOp == INSTANCEOF) ? parseType() : term3(); 2.25 while (top > 0 && prec(topOp) >= prec(S.token())) { 2.26 - odStack[top-1] = makeOp(pos, topOp, odStack[top-1], 2.27 + odStack[top-1] = makeOp(topOpPos, topOp, odStack[top-1], 2.28 odStack[top]); 2.29 top--; 2.30 topOp = opStack[top]; 2.31 + topOpPos = posStack[top]; 2.32 } 2.33 } 2.34 assert top == 0; 2.35 @@ -792,6 +797,7 @@ 2.36 2.37 odStackSupply.elems = savedOd; // optimization 2.38 opStackSupply.elems = savedOp; // optimization 2.39 + posStackSupply.elems = savedPos; // optimization 2.40 return t; 2.41 } 2.42 //where 2.43 @@ -845,6 +851,7 @@ 2.44 */ 2.45 ListBuffer<JCExpression[]> odStackSupply = new ListBuffer<JCExpression[]>(); 2.46 ListBuffer<Token[]> opStackSupply = new ListBuffer<Token[]>(); 2.47 + ListBuffer<int[]> posStackSupply = new ListBuffer<int[]>(); 2.48 2.49 private JCExpression[] newOdStack() { 2.50 if (odStackSupply.elems == odStackSupply.last) 2.51 @@ -862,6 +869,14 @@ 2.52 return opStack; 2.53 } 2.54 2.55 + private int[] newPosStack() { 2.56 + if (posStackSupply.elems == posStackSupply.last) 2.57 + posStackSupply.append(new int[infixPrecedenceLevels + 1]); 2.58 + int[] posStack = posStackSupply.elems.head; 2.59 + posStackSupply.elems = posStackSupply.elems.tail; 2.60 + return posStack; 2.61 + } 2.62 + 2.63 /** Expression3 = PrefixOp Expression3 2.64 * | "(" Expr | TypeNoParams ")" Expression3 2.65 * | Primary {Selector} {PostfixOp} 2.66 @@ -939,7 +954,7 @@ 2.67 args.append(typeArgument()); 2.68 } 2.69 accept(GT); 2.70 - t = F.at(pos1).TypeApply(t, args.toList()); 2.71 + t = toP(F.at(pos1).TypeApply(t, args.toList())); 2.72 checkGenerics(); 2.73 while (S.token() == DOT) { 2.74 S.nextToken(); 2.75 @@ -950,7 +965,8 @@ 2.76 t = bracketsOpt(toP(t)); 2.77 } else if ((mode & EXPR) != 0) { 2.78 mode = EXPR; 2.79 - t = F.at(pos1).Binary(op, t, term2Rest(t1, TreeInfo.shiftPrec)); 2.80 + JCExpression e = term2Rest(t1, TreeInfo.shiftPrec); 2.81 + t = F.at(pos1).Binary(op, t, e); 2.82 t = termRest(term1Rest(term2Rest(t, TreeInfo.orPrec))); 2.83 } else { 2.84 accept(GT); 2.85 @@ -998,7 +1014,8 @@ 2.86 case SUPER: 2.87 if ((mode & EXPR) != 0) { 2.88 mode = EXPR; 2.89 - t = to(superSuffix(typeArgs, F.at(pos).Ident(names._super))); 2.90 + t = to(F.at(pos).Ident(names._super)); 2.91 + t = superSuffix(typeArgs, t); 2.92 typeArgs = null; 2.93 } else return illegal(); 2.94 break; 2.95 @@ -1380,13 +1397,15 @@ 2.96 S.nextToken(); 2.97 JCExpression result; 2.98 if (S.token() == EXTENDS) { 2.99 - TypeBoundKind t = to(F.at(S.pos()).TypeBoundKind(BoundKind.EXTENDS)); 2.100 + TypeBoundKind t = to(F.at(pos).TypeBoundKind(BoundKind.EXTENDS)); 2.101 S.nextToken(); 2.102 - result = F.at(pos).Wildcard(t, parseType()); 2.103 + JCExpression bound = parseType(); 2.104 + result = F.at(pos).Wildcard(t, bound); 2.105 } else if (S.token() == SUPER) { 2.106 - TypeBoundKind t = to(F.at(S.pos()).TypeBoundKind(BoundKind.SUPER)); 2.107 + TypeBoundKind t = to(F.at(pos).TypeBoundKind(BoundKind.SUPER)); 2.108 S.nextToken(); 2.109 - result = F.at(pos).Wildcard(t, parseType()); 2.110 + JCExpression bound = parseType(); 2.111 + result = F.at(pos).Wildcard(t, bound); 2.112 } else if (S.token() == IDENTIFIER) { 2.113 //error recovery 2.114 reportSyntaxError(S.prevEndPos(), "expected3", 2.115 @@ -1396,7 +1415,7 @@ 2.116 JCIdent id = toP(F.at(S.pos()).Ident(ident())); 2.117 result = F.at(pos).Erroneous(List.<JCTree>of(wc, id)); 2.118 } else { 2.119 - TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND); 2.120 + TypeBoundKind t = toP(F.at(pos).TypeBoundKind(BoundKind.UNBOUND)); 2.121 result = toP(F.at(pos).Wildcard(t, null)); 2.122 } 2.123 if (!annotations.isEmpty()) 2.124 @@ -2117,14 +2136,21 @@ 2.125 return modifiersOpt(null); 2.126 } 2.127 JCModifiers modifiersOpt(JCModifiers partial) { 2.128 - long flags = (partial == null) ? 0 : partial.flags; 2.129 + long flags; 2.130 + ListBuffer<JCAnnotation> annotations = new ListBuffer<JCAnnotation>(); 2.131 + int pos; 2.132 + if (partial == null) { 2.133 + flags = 0; 2.134 + pos = S.pos(); 2.135 + } else { 2.136 + flags = partial.flags; 2.137 + annotations.appendList(partial.annotations); 2.138 + pos = partial.pos; 2.139 + } 2.140 if (S.deprecatedFlag()) { 2.141 flags |= Flags.DEPRECATED; 2.142 S.resetDeprecatedFlag(); 2.143 } 2.144 - ListBuffer<JCAnnotation> annotations = new ListBuffer<JCAnnotation>(); 2.145 - if (partial != null) annotations.appendList(partial.annotations); 2.146 - int pos = S.pos(); 2.147 int lastPos = Position.NOPOS; 2.148 loop: 2.149 while (true) { 2.150 @@ -2150,12 +2176,12 @@ 2.151 if (flag == Flags.ANNOTATION) { 2.152 checkAnnotations(); 2.153 if (S.token() != INTERFACE) { 2.154 - JCAnnotation ann = annotation(lastPos, AnnotationKind.DEFAULT_ANNO); 2.155 - // if first modifier is an annotation, set pos to annotation's. 2.156 - if (flags == 0 && annotations.isEmpty()) 2.157 - pos = ann.pos; 2.158 - annotations.append(ann); 2.159 - lastPos = ann.pos; 2.160 + JCAnnotation ann = annotation(lastPos, AnnotationKind.DEFAULT_ANNO); 2.161 + // if first modifier is an annotation, set pos to annotation's. 2.162 + if (flags == 0 && annotations.isEmpty()) 2.163 + pos = ann.pos; 2.164 + annotations.append(ann); 2.165 + lastPos = ann.pos; 2.166 flag = 0; 2.167 } 2.168 } 2.169 @@ -2169,7 +2195,7 @@ 2.170 2.171 /* A modifiers tree with no modifier tokens or annotations 2.172 * has no text position. */ 2.173 - if (flags == 0 && annotations.isEmpty()) 2.174 + if ((flags & Flags.ModifierFlags) == 0 && annotations.isEmpty()) 2.175 pos = Position.NOPOS; 2.176 2.177 JCModifiers mods = F.at(pos).Modifiers(flags, annotations.toList()); 2.178 @@ -2226,7 +2252,8 @@ 2.179 if (t1.getTag() == JCTree.IDENT && S.token() == EQ) { 2.180 int pos = S.pos(); 2.181 accept(EQ); 2.182 - return toP(F.at(pos).Assign(t1, annotationValue())); 2.183 + JCExpression v = annotationValue(); 2.184 + return toP(F.at(pos).Assign(t1, v)); 2.185 } else { 2.186 return t1; 2.187 } 2.188 @@ -2543,10 +2570,9 @@ 2.189 } 2.190 2.191 List<JCTree> defs = enumBody(name); 2.192 - JCModifiers newMods = 2.193 - F.at(mods.pos).Modifiers(mods.flags|Flags.ENUM, mods.annotations); 2.194 + mods.flags |= Flags.ENUM; 2.195 JCClassDecl result = toP(F.at(pos). 2.196 - ClassDef(newMods, name, List.<JCTypeParameter>nil(), 2.197 + ClassDef(mods, name, List.<JCTypeParameter>nil(), 2.198 null, implementing, defs)); 2.199 attach(result, dc); 2.200 return result; 2.201 @@ -2695,16 +2721,8 @@ 2.202 } else { 2.203 pos = S.pos(); 2.204 List<JCTypeParameter> typarams = typeParametersOpt(); 2.205 - // Hack alert: if there are type arguments but no Modifiers, the start 2.206 - // position will be lost unless we set the Modifiers position. There 2.207 - // should be an AST node for type parameters (BugId 5005090). 2.208 - if (typarams.length() > 0 && mods.pos == Position.NOPOS) { 2.209 - mods.pos = pos; 2.210 - } 2.211 - 2.212 List<JCAnnotation> annosAfterParams = annotationsOpt(AnnotationKind.DEFAULT_ANNO); 2.213 2.214 - Token token = S.token(); 2.215 Name name = S.name(); 2.216 pos = S.pos(); 2.217 JCExpression type; 2.218 @@ -2715,7 +2733,11 @@ 2.219 type = to(F.at(pos).TypeIdent(TypeTags.VOID)); 2.220 S.nextToken(); 2.221 } else { 2.222 - mods.annotations = mods.annotations.appendList(annosAfterParams); 2.223 + if (annosAfterParams.nonEmpty()) { 2.224 + mods.annotations = mods.annotations.appendList(annosAfterParams); 2.225 + if (mods.pos == Position.NOPOS) 2.226 + mods.pos = mods.annotations.head.pos; 2.227 + } 2.228 // method returns types are un-annotated types 2.229 type = unannotatedType(); 2.230 } 2.231 @@ -2813,6 +2835,7 @@ 2.232 } 2.233 } 2.234 } 2.235 + 2.236 JCMethodDecl result = 2.237 toP(F.at(pos).MethodDef(mods, name, type, typarams, 2.238 params, receiverAnnotations, thrown,
3.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Wed Jan 27 14:46:37 2010 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Fri Jan 29 16:06:51 2010 -0800 3.3 @@ -307,8 +307,18 @@ 3.4 case(JCTree.POSTINC): 3.5 case(JCTree.POSTDEC): 3.6 return getStartPos(((JCUnary) tree).arg); 3.7 - case(JCTree.ANNOTATED_TYPE): 3.8 - return getStartPos(((JCAnnotatedType) tree).underlyingType); 3.9 + case(JCTree.ANNOTATED_TYPE): { 3.10 + JCAnnotatedType node = (JCAnnotatedType) tree; 3.11 + if (node.annotations.nonEmpty()) 3.12 + return getStartPos(node.annotations.head); 3.13 + return getStartPos(node.underlyingType); 3.14 + } 3.15 + case(JCTree.NEWCLASS): { 3.16 + JCNewClass node = (JCNewClass)tree; 3.17 + if (node.encl != null) 3.18 + return getStartPos(node.encl); 3.19 + break; 3.20 + } 3.21 case(JCTree.VARDEF): { 3.22 JCVariableDecl node = (JCVariableDecl)tree; 3.23 if (node.mods.pos != Position.NOPOS) { 3.24 @@ -406,6 +416,8 @@ 3.25 return getEndPos(((JCUnary) tree).arg, endPositions); 3.26 case(JCTree.WHILELOOP): 3.27 return getEndPos(((JCWhileLoop) tree).body, endPositions); 3.28 + case(JCTree.ANNOTATED_TYPE): 3.29 + return getEndPos(((JCAnnotatedType) tree).underlyingType, endPositions); 3.30 case(JCTree.ERRONEOUS): { 3.31 JCErroneous node = (JCErroneous)tree; 3.32 if (node.errs != null && node.errs.nonEmpty())
4.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java Wed Jan 27 14:46:37 2010 -0800 4.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java Fri Jan 29 16:06:51 2010 -0800 4.3 @@ -480,7 +480,7 @@ 4.4 4.5 public JCModifiers Modifiers(long flags, List<JCAnnotation> annotations) { 4.6 JCModifiers tree = new JCModifiers(flags, annotations); 4.7 - boolean noFlags = (flags & Flags.StandardFlags) == 0; 4.8 + boolean noFlags = (flags & Flags.ModifierFlags) == 0; 4.9 tree.pos = (noFlags && annotations.isEmpty()) ? Position.NOPOS : pos; 4.10 return tree; 4.11 }
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/T6654037.java Fri Jan 29 16:06:51 2010 -0800 5.3 @@ -0,0 +1,76 @@ 5.4 +/* 5.5 + * Copyright 2008-2010 Sun Microsystems, Inc. All Rights Reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 5.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 5.24 + * have any questions. 5.25 + */ 5.26 + 5.27 +/* 5.28 + * @test 5.29 + * @bug 6654037 5.30 + * @summary JCTree.pos may be incorrect for BinaryTrees 5.31 + */ 5.32 + 5.33 +import com.sun.source.tree.BinaryTree; 5.34 +import com.sun.source.tree.ClassTree; 5.35 +import com.sun.source.tree.CompilationUnitTree; 5.36 +import com.sun.source.tree.MethodTree; 5.37 +import com.sun.source.tree.VariableTree; 5.38 +import com.sun.tools.javac.api.JavacTaskImpl; 5.39 +import com.sun.tools.javac.tree.JCTree; 5.40 +import java.net.URI; 5.41 +import java.util.Arrays; 5.42 +import javax.tools.JavaCompiler; 5.43 +import javax.tools.JavaFileObject; 5.44 +import javax.tools.SimpleJavaFileObject; 5.45 +import javax.tools.ToolProvider; 5.46 + 5.47 +public class T6654037 { 5.48 + 5.49 + public static void main(String[] args) throws Exception { 5.50 + final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N 5.51 + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 5.52 + assert tool != null; 5.53 + 5.54 + String code = "package test; public class Test {private void test() {Object o = null; boolean b = o != null && o instanceof String;} private Test() {}}"; 5.55 + 5.56 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code))); 5.57 + CompilationUnitTree cut = ct.parse().iterator().next(); 5.58 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 5.59 + MethodTree method = (MethodTree) clazz.getMembers().get(0); 5.60 + VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1); 5.61 + BinaryTree cond = (BinaryTree) condSt.getInitializer(); 5.62 + JCTree condJC = (JCTree) cond; 5.63 + 5.64 + if (condJC.pos != 93) 5.65 + throw new IllegalStateException("Unexpected position=" + condJC.pos); 5.66 + } 5.67 + 5.68 + static class MyFileObject extends SimpleJavaFileObject { 5.69 + private String text; 5.70 + public MyFileObject(String text) { 5.71 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 5.72 + this.text = text; 5.73 + } 5.74 + @Override 5.75 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 5.76 + return text; 5.77 + } 5.78 + } 5.79 +}
6.1 --- a/test/tools/javac/generics/diamond/neg/Neg01.out Wed Jan 27 14:46:37 2010 -0800 6.2 +++ b/test/tools/javac/generics/diamond/neg/Neg01.out Fri Jan 29 16:06:51 2010 -0800 6.3 @@ -1,31 +1,31 @@ 6.4 Neg01.java:18:15: compiler.err.not.within.bounds: java.lang.String 6.5 Neg01.java:18:37: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>) 6.6 -Neg01.java:19:25: compiler.err.not.within.bounds: ? extends java.lang.String 6.7 +Neg01.java:19:15: compiler.err.not.within.bounds: ? extends java.lang.String 6.8 Neg01.java:19:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 6.9 Neg01.java:20:23: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String, kindname.class, Neg01<java.lang.Number> 6.10 -Neg01.java:21:23: compiler.err.not.within.bounds: ? super java.lang.String 6.11 +Neg01.java:21:15: compiler.err.not.within.bounds: ? super java.lang.String 6.12 Neg01.java:21:45: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<? super java.lang.String>) 6.13 Neg01.java:23:15: compiler.err.not.within.bounds: java.lang.String 6.14 Neg01.java:23:37: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>) 6.15 -Neg01.java:24:25: compiler.err.not.within.bounds: ? extends java.lang.String 6.16 +Neg01.java:24:15: compiler.err.not.within.bounds: ? extends java.lang.String 6.17 Neg01.java:24:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 6.18 Neg01.java:25:23: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String, kindname.class, Neg01<java.lang.Number> 6.19 Neg01.java:25:38: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , , kindname.class, Neg01<java.lang.Number> 6.20 -Neg01.java:26:23: compiler.err.not.within.bounds: ? super java.lang.String 6.21 +Neg01.java:26:15: compiler.err.not.within.bounds: ? super java.lang.String 6.22 Neg01.java:26:45: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<? super java.lang.String>) 6.23 Neg01.java:28:15: compiler.err.not.within.bounds: java.lang.String 6.24 Neg01.java:28:37: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>) 6.25 -Neg01.java:29:25: compiler.err.not.within.bounds: ? extends java.lang.String 6.26 +Neg01.java:29:15: compiler.err.not.within.bounds: ? extends java.lang.String 6.27 Neg01.java:29:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 6.28 Neg01.java:30:24: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String,java.lang.String, kindname.class, Neg01<java.lang.Number> 6.29 Neg01.java:31:9: compiler.err.cant.resolve.location: kindname.class, Foo, , , kindname.class, Neg01<X> 6.30 Neg01.java:31:35: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String,java.lang.String, kindname.class, Neg01<java.lang.Number> 6.31 Neg01.java:33:15: compiler.err.not.within.bounds: java.lang.String 6.32 Neg01.java:33:38: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<java.lang.String>) 6.33 -Neg01.java:34:25: compiler.err.not.within.bounds: ? extends java.lang.String 6.34 +Neg01.java:34:15: compiler.err.not.within.bounds: ? extends java.lang.String 6.35 Neg01.java:34:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 6.36 Neg01.java:35:24: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , java.lang.String,java.lang.String, kindname.class, Neg01<java.lang.Number> 6.37 Neg01.java:35:43: compiler.err.cant.resolve.location.args: kindname.constructor, Neg01, , , kindname.class, Neg01<java.lang.Number> 6.38 -Neg01.java:36:23: compiler.err.not.within.bounds: ? super java.lang.String 6.39 +Neg01.java:36:15: compiler.err.not.within.bounds: ? super java.lang.String 6.40 Neg01.java:36:46: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg01<X>, Neg01<? super java.lang.String>) 6.41 30 errors
7.1 --- a/test/tools/javac/generics/diamond/neg/Neg02.out Wed Jan 27 14:46:37 2010 -0800 7.2 +++ b/test/tools/javac/generics/diamond/neg/Neg02.out Fri Jan 29 16:06:51 2010 -0800 7.3 @@ -1,61 +1,61 @@ 7.4 Neg02.java:19:13: compiler.err.not.within.bounds: java.lang.String 7.5 Neg02.java:19:33: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>) 7.6 -Neg02.java:20:23: compiler.err.not.within.bounds: ? extends java.lang.String 7.7 +Neg02.java:20:13: compiler.err.not.within.bounds: ? extends java.lang.String 7.8 Neg02.java:20:43: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 7.9 Neg02.java:21:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number> 7.10 -Neg02.java:22:21: compiler.err.not.within.bounds: ? super java.lang.String 7.11 +Neg02.java:22:13: compiler.err.not.within.bounds: ? super java.lang.String 7.12 Neg02.java:22:41: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>) 7.13 Neg02.java:24:13: compiler.err.not.within.bounds: java.lang.String 7.14 Neg02.java:24:33: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>) 7.15 -Neg02.java:25:23: compiler.err.not.within.bounds: ? extends java.lang.String 7.16 +Neg02.java:25:13: compiler.err.not.within.bounds: ? extends java.lang.String 7.17 Neg02.java:25:43: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 7.18 Neg02.java:26:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number> 7.19 Neg02.java:26:34: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number> 7.20 -Neg02.java:27:21: compiler.err.not.within.bounds: ? super java.lang.String 7.21 +Neg02.java:27:13: compiler.err.not.within.bounds: ? super java.lang.String 7.22 Neg02.java:27:41: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>) 7.23 Neg02.java:29:13: compiler.err.not.within.bounds: java.lang.String 7.24 Neg02.java:29:33: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>) 7.25 -Neg02.java:30:23: compiler.err.not.within.bounds: ? extends java.lang.String 7.26 +Neg02.java:30:13: compiler.err.not.within.bounds: ? extends java.lang.String 7.27 Neg02.java:30:44: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 7.28 Neg02.java:31:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number> 7.29 -Neg02.java:32:21: compiler.err.not.within.bounds: ? super java.lang.String 7.30 +Neg02.java:32:13: compiler.err.not.within.bounds: ? super java.lang.String 7.31 Neg02.java:32:42: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>) 7.32 Neg02.java:34:13: compiler.err.not.within.bounds: java.lang.String 7.33 Neg02.java:34:34: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>) 7.34 -Neg02.java:35:23: compiler.err.not.within.bounds: ? extends java.lang.String 7.35 +Neg02.java:35:13: compiler.err.not.within.bounds: ? extends java.lang.String 7.36 Neg02.java:35:44: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 7.37 Neg02.java:36:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number> 7.38 Neg02.java:36:39: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number> 7.39 -Neg02.java:37:21: compiler.err.not.within.bounds: ? super java.lang.String 7.40 +Neg02.java:37:13: compiler.err.not.within.bounds: ? super java.lang.String 7.41 Neg02.java:37:42: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>) 7.42 Neg02.java:41:13: compiler.err.not.within.bounds: java.lang.String 7.43 Neg02.java:41:39: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>) 7.44 -Neg02.java:42:23: compiler.err.not.within.bounds: ? extends java.lang.String 7.45 +Neg02.java:42:13: compiler.err.not.within.bounds: ? extends java.lang.String 7.46 Neg02.java:42:49: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 7.47 Neg02.java:43:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number> 7.48 -Neg02.java:44:21: compiler.err.not.within.bounds: ? super java.lang.String 7.49 +Neg02.java:44:13: compiler.err.not.within.bounds: ? super java.lang.String 7.50 Neg02.java:44:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>) 7.51 Neg02.java:46:13: compiler.err.not.within.bounds: java.lang.String 7.52 Neg02.java:46:39: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>) 7.53 -Neg02.java:47:23: compiler.err.not.within.bounds: ? extends java.lang.String 7.54 +Neg02.java:47:13: compiler.err.not.within.bounds: ? extends java.lang.String 7.55 Neg02.java:47:49: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 7.56 Neg02.java:48:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg02.Foo<java.lang.Number> 7.57 Neg02.java:48:40: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number> 7.58 -Neg02.java:49:21: compiler.err.not.within.bounds: ? super java.lang.String 7.59 +Neg02.java:49:13: compiler.err.not.within.bounds: ? super java.lang.String 7.60 Neg02.java:49:47: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>) 7.61 Neg02.java:51:13: compiler.err.not.within.bounds: java.lang.String 7.62 Neg02.java:51:39: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>) 7.63 -Neg02.java:52:23: compiler.err.not.within.bounds: ? extends java.lang.String 7.64 +Neg02.java:52:13: compiler.err.not.within.bounds: ? extends java.lang.String 7.65 Neg02.java:52:50: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 7.66 Neg02.java:53:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number> 7.67 -Neg02.java:54:21: compiler.err.not.within.bounds: ? super java.lang.String 7.68 +Neg02.java:54:13: compiler.err.not.within.bounds: ? super java.lang.String 7.69 Neg02.java:54:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>) 7.70 Neg02.java:56:13: compiler.err.not.within.bounds: java.lang.String 7.71 Neg02.java:56:40: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<java.lang.String>) 7.72 -Neg02.java:57:23: compiler.err.not.within.bounds: ? extends java.lang.String 7.73 +Neg02.java:57:13: compiler.err.not.within.bounds: ? extends java.lang.String 7.74 Neg02.java:57:50: compiler.err.cant.apply.diamond: X, (compiler.misc.no.unique.maximal.instance.exists: X, java.lang.String,java.lang.Number) 7.75 Neg02.java:58:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg02.Foo<java.lang.Number> 7.76 Neg02.java:58:45: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg02.Foo<java.lang.Number> 7.77 -Neg02.java:59:21: compiler.err.not.within.bounds: ? super java.lang.String 7.78 +Neg02.java:59:13: compiler.err.not.within.bounds: ? super java.lang.String 7.79 Neg02.java:59:48: compiler.err.cant.apply.diamond: X, (compiler.misc.no.conforming.instance.exists: X, Neg02.Foo<X>, Neg02.Foo<? super java.lang.String>) 7.80 60 errors
8.1 --- a/test/tools/javac/generics/diamond/neg/Neg03.out Wed Jan 27 14:46:37 2010 -0800 8.2 +++ b/test/tools/javac/generics/diamond/neg/Neg03.out Fri Jan 29 16:06:51 2010 -0800 8.3 @@ -1,91 +1,91 @@ 8.4 Neg03.java:19:13: compiler.err.not.within.bounds: java.lang.String 8.5 Neg03.java:19:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.6 -Neg03.java:20:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.7 +Neg03.java:20:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.8 Neg03.java:20:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.9 Neg03.java:21:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.10 -Neg03.java:22:21: compiler.err.not.within.bounds: ? super java.lang.String 8.11 +Neg03.java:22:13: compiler.err.not.within.bounds: ? super java.lang.String 8.12 Neg03.java:22:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.13 Neg03.java:24:13: compiler.err.not.within.bounds: java.lang.String 8.14 Neg03.java:24:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.15 -Neg03.java:25:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.16 +Neg03.java:25:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.17 Neg03.java:25:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.18 Neg03.java:26:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.19 Neg03.java:26:34: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number> 8.20 -Neg03.java:27:21: compiler.err.not.within.bounds: ? super java.lang.String 8.21 +Neg03.java:27:13: compiler.err.not.within.bounds: ? super java.lang.String 8.22 Neg03.java:27:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.23 Neg03.java:29:13: compiler.err.not.within.bounds: java.lang.String 8.24 Neg03.java:29:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.25 -Neg03.java:30:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.26 +Neg03.java:30:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.27 Neg03.java:30:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.28 Neg03.java:31:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.29 -Neg03.java:32:21: compiler.err.not.within.bounds: ? super java.lang.String 8.30 +Neg03.java:32:13: compiler.err.not.within.bounds: ? super java.lang.String 8.31 Neg03.java:32:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.32 Neg03.java:34:13: compiler.err.not.within.bounds: java.lang.String 8.33 Neg03.java:34:34: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.34 -Neg03.java:35:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.35 +Neg03.java:35:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.36 Neg03.java:35:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.37 Neg03.java:36:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.38 Neg03.java:36:39: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number> 8.39 -Neg03.java:37:21: compiler.err.not.within.bounds: ? super java.lang.String 8.40 +Neg03.java:37:13: compiler.err.not.within.bounds: ? super java.lang.String 8.41 Neg03.java:37:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.42 Neg03.java:41:13: compiler.err.not.within.bounds: java.lang.String 8.43 Neg03.java:41:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.44 -Neg03.java:42:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.45 +Neg03.java:42:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.46 Neg03.java:42:52: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.47 Neg03.java:43:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.48 -Neg03.java:44:21: compiler.err.not.within.bounds: ? super java.lang.String 8.49 +Neg03.java:44:13: compiler.err.not.within.bounds: ? super java.lang.String 8.50 Neg03.java:44:50: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.51 Neg03.java:46:13: compiler.err.not.within.bounds: java.lang.String 8.52 Neg03.java:46:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.53 -Neg03.java:47:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.54 +Neg03.java:47:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.55 Neg03.java:47:52: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.56 Neg03.java:48:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.57 Neg03.java:48:43: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number> 8.58 -Neg03.java:49:21: compiler.err.not.within.bounds: ? super java.lang.String 8.59 +Neg03.java:49:13: compiler.err.not.within.bounds: ? super java.lang.String 8.60 Neg03.java:49:50: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.61 Neg03.java:51:13: compiler.err.not.within.bounds: java.lang.String 8.62 Neg03.java:51:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.63 -Neg03.java:52:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.64 +Neg03.java:52:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.65 Neg03.java:52:53: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.66 Neg03.java:53:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.67 -Neg03.java:54:21: compiler.err.not.within.bounds: ? super java.lang.String 8.68 +Neg03.java:54:13: compiler.err.not.within.bounds: ? super java.lang.String 8.69 Neg03.java:54:51: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.70 Neg03.java:56:13: compiler.err.not.within.bounds: java.lang.String 8.71 Neg03.java:56:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.72 -Neg03.java:57:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.73 +Neg03.java:57:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.74 Neg03.java:57:53: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.75 Neg03.java:58:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.76 Neg03.java:58:48: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number> 8.77 -Neg03.java:59:21: compiler.err.not.within.bounds: ? super java.lang.String 8.78 +Neg03.java:59:13: compiler.err.not.within.bounds: ? super java.lang.String 8.79 Neg03.java:59:51: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.80 Neg03.java:63:13: compiler.err.not.within.bounds: java.lang.String 8.81 Neg03.java:63:28: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.82 -Neg03.java:64:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.83 +Neg03.java:64:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.84 Neg03.java:64:38: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.85 Neg03.java:65:23: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.86 -Neg03.java:66:21: compiler.err.not.within.bounds: ? super java.lang.String 8.87 +Neg03.java:66:13: compiler.err.not.within.bounds: ? super java.lang.String 8.88 Neg03.java:66:36: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.89 Neg03.java:68:13: compiler.err.not.within.bounds: java.lang.String 8.90 Neg03.java:68:28: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.91 -Neg03.java:69:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.92 +Neg03.java:69:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.93 Neg03.java:69:38: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.94 Neg03.java:70:23: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.95 Neg03.java:70:36: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number> 8.96 -Neg03.java:71:21: compiler.err.not.within.bounds: ? super java.lang.String 8.97 +Neg03.java:71:13: compiler.err.not.within.bounds: ? super java.lang.String 8.98 Neg03.java:71:36: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.99 Neg03.java:73:13: compiler.err.not.within.bounds: java.lang.String 8.100 Neg03.java:73:28: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.101 -Neg03.java:74:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.102 +Neg03.java:74:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.103 Neg03.java:74:39: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.104 Neg03.java:75:24: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.105 -Neg03.java:76:21: compiler.err.not.within.bounds: ? super java.lang.String 8.106 +Neg03.java:76:13: compiler.err.not.within.bounds: ? super java.lang.String 8.107 Neg03.java:76:37: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.108 Neg03.java:78:13: compiler.err.not.within.bounds: java.lang.String 8.109 Neg03.java:78:29: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<java.lang.String>) 8.110 -Neg03.java:79:23: compiler.err.not.within.bounds: ? extends java.lang.String 8.111 +Neg03.java:79:13: compiler.err.not.within.bounds: ? extends java.lang.String 8.112 Neg03.java:79:39: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 8.113 Neg03.java:80:24: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Neg03<U>.Foo<java.lang.Number> 8.114 Neg03.java:80:41: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Neg03<U>.Foo<java.lang.Number> 8.115 -Neg03.java:81:21: compiler.err.not.within.bounds: ? super java.lang.String 8.116 +Neg03.java:81:13: compiler.err.not.within.bounds: ? super java.lang.String 8.117 Neg03.java:81:37: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Neg03<U>.Foo<V>, Neg03<U>.Foo<? super java.lang.String>) 8.118 90 errors
9.1 --- a/test/tools/javac/generics/diamond/neg/Neg04.out Wed Jan 27 14:46:37 2010 -0800 9.2 +++ b/test/tools/javac/generics/diamond/neg/Neg04.out Fri Jan 29 16:06:51 2010 -0800 9.3 @@ -1,31 +1,31 @@ 9.4 Neg04.java:18:13: compiler.err.not.within.bounds: java.lang.String 9.5 Neg04.java:18:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>) 9.6 -Neg04.java:19:23: compiler.err.not.within.bounds: ? extends java.lang.String 9.7 +Neg04.java:19:13: compiler.err.not.within.bounds: ? extends java.lang.String 9.8 Neg04.java:19:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 9.9 Neg04.java:20:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Foo<java.lang.Number> 9.10 -Neg04.java:21:21: compiler.err.not.within.bounds: ? super java.lang.String 9.11 +Neg04.java:21:13: compiler.err.not.within.bounds: ? super java.lang.String 9.12 Neg04.java:21:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>) 9.13 Neg04.java:23:13: compiler.err.not.within.bounds: java.lang.String 9.14 Neg04.java:23:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>) 9.15 -Neg04.java:24:23: compiler.err.not.within.bounds: ? extends java.lang.String 9.16 +Neg04.java:24:13: compiler.err.not.within.bounds: ? extends java.lang.String 9.17 Neg04.java:24:43: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 9.18 Neg04.java:25:21: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String, kindname.class, Foo<java.lang.Number> 9.19 Neg04.java:25:34: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Foo<java.lang.Number> 9.20 -Neg04.java:26:21: compiler.err.not.within.bounds: ? super java.lang.String 9.21 +Neg04.java:26:13: compiler.err.not.within.bounds: ? super java.lang.String 9.22 Neg04.java:26:41: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>) 9.23 Neg04.java:28:13: compiler.err.not.within.bounds: java.lang.String 9.24 Neg04.java:28:33: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>) 9.25 -Neg04.java:29:23: compiler.err.not.within.bounds: ? extends java.lang.String 9.26 +Neg04.java:29:13: compiler.err.not.within.bounds: ? extends java.lang.String 9.27 Neg04.java:29:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 9.28 Neg04.java:30:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Foo<java.lang.Number> 9.29 -Neg04.java:31:21: compiler.err.not.within.bounds: ? super java.lang.String 9.30 +Neg04.java:31:13: compiler.err.not.within.bounds: ? super java.lang.String 9.31 Neg04.java:31:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>) 9.32 Neg04.java:33:13: compiler.err.not.within.bounds: java.lang.String 9.33 Neg04.java:33:34: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<java.lang.String>) 9.34 -Neg04.java:34:23: compiler.err.not.within.bounds: ? extends java.lang.String 9.35 +Neg04.java:34:13: compiler.err.not.within.bounds: ? extends java.lang.String 9.36 Neg04.java:34:44: compiler.err.cant.apply.diamond: V, (compiler.misc.no.unique.maximal.instance.exists: V, java.lang.String,java.lang.Number) 9.37 Neg04.java:35:22: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , java.lang.String,java.lang.String, kindname.class, Foo<java.lang.Number> 9.38 Neg04.java:35:39: compiler.err.cant.resolve.location.args: kindname.constructor, Foo, , , kindname.class, Foo<java.lang.Number> 9.39 -Neg04.java:36:21: compiler.err.not.within.bounds: ? super java.lang.String 9.40 +Neg04.java:36:13: compiler.err.not.within.bounds: ? super java.lang.String 9.41 Neg04.java:36:42: compiler.err.cant.apply.diamond: V, (compiler.misc.no.conforming.instance.exists: V, Foo<V>, Foo<? super java.lang.String>) 9.42 30 errors
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/javac/treepostests/TreePosTest.java Fri Jan 29 16:06:51 2010 -0800 10.3 @@ -0,0 +1,752 @@ 10.4 +/* 10.5 + * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. 10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 + * 10.8 + * This code is free software; you can redistribute it and/or modify it 10.9 + * under the terms of the GNU General Public License version 2 only, as 10.10 + * published by the Free Software Foundation. 10.11 + * 10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.15 + * version 2 for more details (a copy is included in the LICENSE file that 10.16 + * accompanied this code). 10.17 + * 10.18 + * You should have received a copy of the GNU General Public License version 10.19 + * 2 along with this work; if not, write to the Free Software Foundation, 10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.21 + * 10.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 10.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 10.24 + * have any questions. 10.25 + */ 10.26 + 10.27 +import java.awt.BorderLayout; 10.28 +import java.awt.Color; 10.29 +import java.awt.Dimension; 10.30 +import java.awt.EventQueue; 10.31 +import java.awt.Font; 10.32 +import java.awt.GridBagConstraints; 10.33 +import java.awt.GridBagLayout; 10.34 +import java.awt.Rectangle; 10.35 +import java.awt.event.ActionEvent; 10.36 +import java.awt.event.ActionListener; 10.37 +import java.awt.event.MouseAdapter; 10.38 +import java.awt.event.MouseEvent; 10.39 +import java.io.File; 10.40 +import java.io.IOException; 10.41 +import java.io.PrintStream; 10.42 +import java.io.PrintWriter; 10.43 +import java.io.StringWriter; 10.44 +import java.lang.reflect.Field; 10.45 +import java.lang.reflect.Modifier; 10.46 +import java.nio.charset.Charset; 10.47 +import java.util.ArrayList; 10.48 +import java.util.Collections; 10.49 +import java.util.HashMap; 10.50 +import java.util.HashSet; 10.51 +import java.util.Iterator; 10.52 +import java.util.List; 10.53 +import java.util.Map; 10.54 +import java.util.Set; 10.55 +import javax.swing.DefaultComboBoxModel; 10.56 +import javax.swing.JComboBox; 10.57 +import javax.swing.JComponent; 10.58 +import javax.swing.JFrame; 10.59 +import javax.swing.JLabel; 10.60 +import javax.swing.JPanel; 10.61 +import javax.swing.JScrollPane; 10.62 +import javax.swing.JTextArea; 10.63 +import javax.swing.JTextField; 10.64 +import javax.swing.SwingUtilities; 10.65 +import javax.swing.event.CaretEvent; 10.66 +import javax.swing.event.CaretListener; 10.67 +import javax.swing.text.BadLocationException; 10.68 +import javax.swing.text.DefaultHighlighter; 10.69 +import javax.swing.text.Highlighter; 10.70 +import javax.tools.Diagnostic; 10.71 +import javax.tools.DiagnosticListener; 10.72 +import javax.tools.JavaFileObject; 10.73 +import javax.tools.StandardJavaFileManager; 10.74 + 10.75 +import com.sun.source.tree.CompilationUnitTree; 10.76 +import com.sun.source.util.JavacTask; 10.77 +import com.sun.tools.javac.api.JavacTool; 10.78 +import com.sun.tools.javac.code.Flags; 10.79 +import com.sun.tools.javac.tree.JCTree; 10.80 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 10.81 +import com.sun.tools.javac.tree.JCTree.JCNewClass; 10.82 +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; 10.83 +import com.sun.tools.javac.tree.TreeInfo; 10.84 +import com.sun.tools.javac.tree.TreeScanner; 10.85 + 10.86 +import static com.sun.tools.javac.util.Position.NOPOS; 10.87 + 10.88 +/** 10.89 + * Utility and test program to check validity of tree positions for tree nodes. 10.90 + * The program can be run standalone, or as a jtreg test. In standalone mode, 10.91 + * errors can be displayed in a gui viewer. For info on command line args, 10.92 + * run program with no args. 10.93 + * 10.94 + * <p> 10.95 + * jtreg: Note that by using the -r switch in the test description below, this test 10.96 + * will process all java files in the langtools/test directory, thus implicitly 10.97 + * covering any new language features that may be tested in this test suite. 10.98 + */ 10.99 + 10.100 +/* 10.101 + * @test 10.102 + * @bug 6919889 10.103 + * @summary assorted position errors in compiler syntax trees 10.104 + * @run main TreePosTest -q -r -ef ./tools/javac/typeAnnotations . 10.105 + */ 10.106 +public class TreePosTest { 10.107 + /** 10.108 + * Main entry point. 10.109 + * If test.src is set, program runs in jtreg mode, and will throw an Error 10.110 + * if any errors arise, otherwise System.exit will be used, unless the gui 10.111 + * viewer is being used. In jtreg mode, the default base directory for file 10.112 + * args is the value of ${test.src}. In jtreg mode, the -r option can be 10.113 + * given to change the default base directory to the root test directory. 10.114 + */ 10.115 + public static void main(String... args) { 10.116 + String testSrc = System.getProperty("test.src"); 10.117 + File baseDir = (testSrc == null) ? null : new File(testSrc); 10.118 + boolean ok = new TreePosTest().run(baseDir, args); 10.119 + if (!ok) { 10.120 + if (testSrc != null) // jtreg mode 10.121 + throw new Error("failed"); 10.122 + else 10.123 + System.exit(1); 10.124 + } 10.125 + } 10.126 + 10.127 + /** 10.128 + * Run the program. A base directory can be provided for file arguments. 10.129 + * In jtreg mode, the -r option can be given to change the default base 10.130 + * directory to the test root directory. For other options, see usage(). 10.131 + * @param baseDir base directory for any file arguments. 10.132 + * @param args command line args 10.133 + * @return true if successful or in gui mode 10.134 + */ 10.135 + boolean run(File baseDir, String... args) { 10.136 + if (args.length == 0) { 10.137 + usage(System.out); 10.138 + return true; 10.139 + } 10.140 + 10.141 + List<File> files = new ArrayList<File>(); 10.142 + for (int i = 0; i < args.length; i++) { 10.143 + String arg = args[i]; 10.144 + if (arg.equals("-encoding") && i + 1 < args.length) 10.145 + encoding = args[++i]; 10.146 + else if (arg.equals("-gui")) 10.147 + gui = true; 10.148 + else if (arg.equals("-q")) 10.149 + quiet = true; 10.150 + else if (arg.equals("-v")) 10.151 + verbose = true; 10.152 + else if (arg.equals("-t") && i + 1 < args.length) 10.153 + tags.add(args[++i]); 10.154 + else if (arg.equals("-ef") && i + 1 < args.length) 10.155 + excludeFiles.add(new File(baseDir, args[++i])); 10.156 + else if (arg.equals("-r")) { 10.157 + if (excludeFiles.size() > 0) 10.158 + throw new Error("-r must be used before -ef"); 10.159 + File d = baseDir; 10.160 + while (!new File(d, "TEST.ROOT").exists()) { 10.161 + d = d.getParentFile(); 10.162 + if (d == null) 10.163 + throw new Error("cannot find TEST.ROOT"); 10.164 + } 10.165 + baseDir = d; 10.166 + } 10.167 + else if (arg.startsWith("-")) 10.168 + throw new Error("unknown option: " + arg); 10.169 + else { 10.170 + while (i < args.length) 10.171 + files.add(new File(baseDir, args[i++])); 10.172 + } 10.173 + } 10.174 + 10.175 + for (File file: files) { 10.176 + if (file.exists()) 10.177 + test(file); 10.178 + else 10.179 + error("File not found: " + file); 10.180 + } 10.181 + 10.182 + if (fileCount != 1) 10.183 + System.err.println(fileCount + " files read"); 10.184 + if (errors > 0) 10.185 + System.err.println(errors + " errors"); 10.186 + 10.187 + return (gui || errors == 0); 10.188 + } 10.189 + 10.190 + /** 10.191 + * Print command line help. 10.192 + * @param out output stream 10.193 + */ 10.194 + void usage(PrintStream out) { 10.195 + out.println("Usage:"); 10.196 + out.println(" java TreePosTest options... files..."); 10.197 + out.println(""); 10.198 + out.println("where options include:"); 10.199 + out.println("-gui Display returns in a GUI viewer"); 10.200 + out.println("-q Quiet: don't report on inapplicable files"); 10.201 + out.println("-v Verbose: report on files as they are being read"); 10.202 + out.println("-t tag Limit checks to tree nodes with this tag"); 10.203 + out.println(" Can be repeated if desired"); 10.204 + out.println("-ef file Exclude file or directory"); 10.205 + out.println(""); 10.206 + out.println("files may be directories or files"); 10.207 + out.println("directories will be scanned recursively"); 10.208 + out.println("non java files, or java files which cannot be parsed, will be ignored"); 10.209 + out.println(""); 10.210 + } 10.211 + 10.212 + /** 10.213 + * Test a file. If the file is a directory, it will be recursively scanned 10.214 + * for java files. 10.215 + * @param file the file or directory to test 10.216 + */ 10.217 + void test(File file) { 10.218 + if (excludeFiles.contains(file)) { 10.219 + if (!quiet) 10.220 + error("File " + file + " excluded"); 10.221 + return; 10.222 + } 10.223 + 10.224 + if (file.isDirectory()) { 10.225 + for (File f: file.listFiles()) { 10.226 + test(f); 10.227 + } 10.228 + return; 10.229 + } 10.230 + 10.231 + if (file.isFile() && file.getName().endsWith(".java")) { 10.232 + try { 10.233 + if (verbose) 10.234 + System.err.println(file); 10.235 + fileCount++; 10.236 + PosTester p = new PosTester(); 10.237 + p.test(read(file)); 10.238 + } catch (ParseException e) { 10.239 + if (!quiet) { 10.240 + error("Error parsing " + file + "\n" + e.getMessage()); 10.241 + } 10.242 + } catch (IOException e) { 10.243 + error("Error reading " + file + ": " + e); 10.244 + } 10.245 + return; 10.246 + } 10.247 + 10.248 + if (!quiet) 10.249 + error("File " + file + " ignored"); 10.250 + } 10.251 + 10.252 + /** 10.253 + * Read a file. 10.254 + * @param file the file to be read 10.255 + * @return the tree for the content of the file 10.256 + * @throws IOException if any IO errors occur 10.257 + * @throws TreePosTest.ParseException if any errors occur while parsing the file 10.258 + */ 10.259 + JCCompilationUnit read(File file) throws IOException, ParseException { 10.260 + StringWriter sw = new StringWriter(); 10.261 + PrintWriter pw = new PrintWriter(sw); 10.262 + Reporter r = new Reporter(pw); 10.263 + JavacTool tool = JavacTool.create(); 10.264 + Charset cs = (encoding == null ? null : Charset.forName(encoding)); 10.265 + StandardJavaFileManager fm = tool.getStandardFileManager(r, null, null); 10.266 + Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file); 10.267 + JavacTask task = tool.getTask(pw, fm, r, Collections.<String>emptyList(), null, files); 10.268 + Iterable<? extends CompilationUnitTree> trees = task.parse(); 10.269 + pw.flush(); 10.270 + if (r.errors > 0) 10.271 + throw new ParseException(sw.toString()); 10.272 + Iterator<? extends CompilationUnitTree> iter = trees.iterator(); 10.273 + if (!iter.hasNext()) 10.274 + throw new Error("no trees found"); 10.275 + JCCompilationUnit t = (JCCompilationUnit) iter.next(); 10.276 + if (iter.hasNext()) 10.277 + throw new Error("too many trees found"); 10.278 + return t; 10.279 + } 10.280 + 10.281 + /** 10.282 + * Report an error. When the program is complete, the program will either 10.283 + * exit or throw an Error if any errors have been reported. 10.284 + * @param msg the error message 10.285 + */ 10.286 + void error(String msg) { 10.287 + System.err.println(msg); 10.288 + errors++; 10.289 + } 10.290 + 10.291 + /** Number of files that have been analyzed. */ 10.292 + int fileCount; 10.293 + /** Number of errors reported. */ 10.294 + int errors; 10.295 + /** Flag: don't report irrelevant files. */ 10.296 + boolean quiet; 10.297 + /** Flag: report files as they are processed. */ 10.298 + boolean verbose; 10.299 + /** Flag: show errors in GUI viewer. */ 10.300 + boolean gui; 10.301 + /** Option: encoding for test files. */ 10.302 + String encoding; 10.303 + /** The GUI viewer for errors. */ 10.304 + Viewer viewer; 10.305 + /** The set of tags for tree nodes to be analyzed; if empty, all tree nodes 10.306 + * are analyzed. */ 10.307 + Set<String> tags = new HashSet<String>(); 10.308 + /** Set of files and directories to be excluded from analysis. */ 10.309 + Set<File> excludeFiles = new HashSet<File>(); 10.310 + /** Table of printable names for tree tag values. */ 10.311 + TagNames tagNames = new TagNames(); 10.312 + 10.313 + /** 10.314 + * Main class for testing assertions concerning tree positions for tree nodes. 10.315 + */ 10.316 + private class PosTester extends TreeScanner { 10.317 + void test(JCCompilationUnit tree) { 10.318 + sourcefile = tree.sourcefile; 10.319 + endPosTable = tree.endPositions; 10.320 + encl = new Info(); 10.321 + tree.accept(this); 10.322 + } 10.323 + 10.324 + @Override 10.325 + public void scan(JCTree tree) { 10.326 + if (tree == null) 10.327 + return; 10.328 + 10.329 + Info self = new Info(tree, endPosTable); 10.330 + if (check(self)) { 10.331 + // Modifiers nodes are present throughout the tree even where 10.332 + // there is no corresponding source text. 10.333 + // Redundant semicolons in a class definition can cause empty 10.334 + // initializer blocks with no positions. 10.335 + if ((self.tag == JCTree.MODIFIERS || self.tag == JCTree.BLOCK) 10.336 + && self.pos == NOPOS) { 10.337 + // If pos is NOPOS, so should be the start and end positions 10.338 + check("start == NOPOS", encl, self, self.start == NOPOS); 10.339 + check("end == NOPOS", encl, self, self.end == NOPOS); 10.340 + } else { 10.341 + // For this node, start , pos, and endpos should be all defined 10.342 + check("start != NOPOS", encl, self, self.start != NOPOS); 10.343 + check("pos != NOPOS", encl, self, self.pos != NOPOS); 10.344 + check("end != NOPOS", encl, self, self.end != NOPOS); 10.345 + // The following should normally be ordered 10.346 + // encl.start <= start <= pos <= end <= encl.end 10.347 + // In addition, the position of the enclosing node should be 10.348 + // within this node. 10.349 + // The primary exceptions are for array type nodes, because of the 10.350 + // need to support legacy syntax: 10.351 + // e.g. int a[]; int[] b[]; int f()[] { return null; } 10.352 + // and because of inconsistent nesting of left and right of 10.353 + // array declarations: 10.354 + // e.g. int[][] a = new int[2][]; 10.355 + check("encl.start <= start", encl, self, encl.start <= self.start); 10.356 + check("start <= pos", encl, self, self.start <= self.pos); 10.357 + if (!(self.tag == JCTree.TYPEARRAY 10.358 + && (encl.tag == JCTree.VARDEF || encl.tag == JCTree.TYPEARRAY))) { 10.359 + check("encl.pos <= start || end <= encl.pos", 10.360 + encl, self, encl.pos <= self.start || self.end <= encl.pos); 10.361 + } 10.362 + check("pos <= end", encl, self, self.pos <= self.end); 10.363 + if (!(self.tag == JCTree.TYPEARRAY && encl.tag == JCTree.TYPEARRAY)) { 10.364 + check("end <= encl.end", encl, self, self.end <= encl.end); 10.365 + } 10.366 + } 10.367 + } 10.368 + 10.369 + Info prevEncl = encl; 10.370 + encl = self; 10.371 + tree.accept(this); 10.372 + encl = prevEncl; 10.373 + } 10.374 + 10.375 + @Override 10.376 + public void visitVarDef(JCVariableDecl tree) { 10.377 + // enum member declarations are desugared in the parser and have 10.378 + // ill-defined semantics for tree positions, so for now, we 10.379 + // skip the synthesized bits and just check parts which came from 10.380 + // the original source text 10.381 + if ((tree.mods.flags & Flags.ENUM) != 0) { 10.382 + scan(tree.mods); 10.383 + if (tree.init != null) { 10.384 + if (tree.init.getTag() == JCTree.NEWCLASS) { 10.385 + JCNewClass init = (JCNewClass) tree.init; 10.386 + if (init.args != null && init.args.nonEmpty()) { 10.387 + scan(init.args); 10.388 + } 10.389 + if (init.def != null && init.def.defs != null) { 10.390 + scan(init.def.defs); 10.391 + } 10.392 + } 10.393 + } 10.394 + } else 10.395 + super.visitVarDef(tree); 10.396 + } 10.397 + 10.398 + boolean check(Info x) { 10.399 + return tags.size() == 0 || tags.contains(tagNames.get(x.tag)); 10.400 + } 10.401 + 10.402 + void check(String label, Info encl, Info self, boolean ok) { 10.403 + if (!ok) { 10.404 + if (gui) { 10.405 + if (viewer == null) 10.406 + viewer = new Viewer(); 10.407 + viewer.addEntry(sourcefile, label, encl, self); 10.408 + } 10.409 + 10.410 + String s = self.tree.toString(); 10.411 + String msg = sourcefile.getName() + ": " + label + ": " + 10.412 + "encl:" + encl + " this:" + self + "\n" + 10.413 + s.substring(0, Math.min(80, s.length())).replaceAll("[\r\n]+", " "); 10.414 + error(msg); 10.415 + } 10.416 + } 10.417 + 10.418 + JavaFileObject sourcefile; 10.419 + Map<JCTree, Integer> endPosTable; 10.420 + Info encl; 10.421 + 10.422 + } 10.423 + 10.424 + /** 10.425 + * Utility class providing easy access to position and other info for a tree node. 10.426 + */ 10.427 + private class Info { 10.428 + Info() { 10.429 + tree = null; 10.430 + tag = JCTree.ERRONEOUS; 10.431 + start = 0; 10.432 + pos = 0; 10.433 + end = Integer.MAX_VALUE; 10.434 + } 10.435 + 10.436 + Info(JCTree tree, Map<JCTree, Integer> endPosTable) { 10.437 + this.tree = tree; 10.438 + tag = tree.getTag(); 10.439 + start = TreeInfo.getStartPos(tree); 10.440 + pos = tree.pos; 10.441 + end = TreeInfo.getEndPos(tree, endPosTable); 10.442 + } 10.443 + 10.444 + @Override 10.445 + public String toString() { 10.446 + return tagNames.get(tree.getTag()) + "[start:" + start + ",pos:" + pos + ",end:" + end + "]"; 10.447 + } 10.448 + 10.449 + final JCTree tree; 10.450 + final int tag; 10.451 + final int start; 10.452 + final int pos; 10.453 + final int end; 10.454 + } 10.455 + 10.456 + /** 10.457 + * Names for tree tags. 10.458 + * javac does not provide an API to convert tag values to strings, so this class uses 10.459 + * reflection to determine names of public static final int values in JCTree. 10.460 + */ 10.461 + private static class TagNames { 10.462 + String get(int tag) { 10.463 + if (map == null) { 10.464 + map = new HashMap<Integer, String>(); 10.465 + Class c = JCTree.class; 10.466 + for (Field f : c.getDeclaredFields()) { 10.467 + if (f.getType().equals(int.class)) { 10.468 + int mods = f.getModifiers(); 10.469 + if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)) { 10.470 + try { 10.471 + map.put(f.getInt(null), f.getName()); 10.472 + } catch (IllegalAccessException e) { 10.473 + } 10.474 + } 10.475 + } 10.476 + } 10.477 + } 10.478 + String name = map.get(tag); 10.479 + return (name == null) ? "??" : name; 10.480 + } 10.481 + 10.482 + private Map<Integer, String> map; 10.483 + } 10.484 + 10.485 + /** 10.486 + * Thrown when errors are found parsing a java file. 10.487 + */ 10.488 + private static class ParseException extends Exception { 10.489 + ParseException(String msg) { 10.490 + super(msg); 10.491 + } 10.492 + } 10.493 + 10.494 + /** 10.495 + * DiagnosticListener to report diagnostics and count any errors that occur. 10.496 + */ 10.497 + private static class Reporter implements DiagnosticListener<JavaFileObject> { 10.498 + Reporter(PrintWriter out) { 10.499 + this.out = out; 10.500 + } 10.501 + 10.502 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 10.503 + out.println(diagnostic); 10.504 + switch (diagnostic.getKind()) { 10.505 + case ERROR: 10.506 + errors++; 10.507 + } 10.508 + } 10.509 + int errors; 10.510 + PrintWriter out; 10.511 + } 10.512 + 10.513 + /** 10.514 + * GUI viewer for issues found by TreePosTester. The viewer provides a drop 10.515 + * down list for selecting error conditions, a header area providing details 10.516 + * about an error, and a text area with the ranges of text highlighted as 10.517 + * appropriate. 10.518 + */ 10.519 + private class Viewer extends JFrame { 10.520 + /** 10.521 + * Create a viewer. 10.522 + */ 10.523 + Viewer() { 10.524 + initGUI(); 10.525 + } 10.526 + 10.527 + /** 10.528 + * Add another entry to the list of errors. 10.529 + * @param file The file containing the error 10.530 + * @param check The condition that was being tested, and which failed 10.531 + * @param encl the enclosing tree node 10.532 + * @param self the tree node containing the error 10.533 + */ 10.534 + void addEntry(JavaFileObject file, String check, Info encl, Info self) { 10.535 + Entry e = new Entry(file, check, encl, self); 10.536 + DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel(); 10.537 + m.addElement(e); 10.538 + if (m.getSize() == 1) 10.539 + entries.setSelectedItem(e); 10.540 + } 10.541 + 10.542 + /** 10.543 + * Initialize the GUI window. 10.544 + */ 10.545 + private void initGUI() { 10.546 + JPanel head = new JPanel(new GridBagLayout()); 10.547 + GridBagConstraints lc = new GridBagConstraints(); 10.548 + GridBagConstraints fc = new GridBagConstraints(); 10.549 + fc.anchor = GridBagConstraints.WEST; 10.550 + fc.fill = GridBagConstraints.HORIZONTAL; 10.551 + fc.gridwidth = GridBagConstraints.REMAINDER; 10.552 + 10.553 + entries = new JComboBox(); 10.554 + entries.addActionListener(new ActionListener() { 10.555 + public void actionPerformed(ActionEvent e) { 10.556 + showEntry((Entry) entries.getSelectedItem()); 10.557 + } 10.558 + }); 10.559 + fc.insets.bottom = 10; 10.560 + head.add(entries, fc); 10.561 + fc.insets.bottom = 0; 10.562 + head.add(new JLabel("check:"), lc); 10.563 + head.add(checkField = createTextField(80), fc); 10.564 + fc.fill = GridBagConstraints.NONE; 10.565 + head.add(setBackground(new JLabel("encl:"), enclColor), lc); 10.566 + head.add(enclPanel = new InfoPanel(), fc); 10.567 + head.add(setBackground(new JLabel("self:"), selfColor), lc); 10.568 + head.add(selfPanel = new InfoPanel(), fc); 10.569 + add(head, BorderLayout.NORTH); 10.570 + 10.571 + body = new JTextArea(); 10.572 + body.setFont(Font.decode(Font.MONOSPACED)); 10.573 + body.addCaretListener(new CaretListener() { 10.574 + public void caretUpdate(CaretEvent e) { 10.575 + int dot = e.getDot(); 10.576 + int mark = e.getMark(); 10.577 + if (dot == mark) 10.578 + statusText.setText("dot: " + dot); 10.579 + else 10.580 + statusText.setText("dot: " + dot + ", mark:" + mark); 10.581 + } 10.582 + }); 10.583 + JScrollPane p = new JScrollPane(body, 10.584 + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 10.585 + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 10.586 + p.setPreferredSize(new Dimension(640, 480)); 10.587 + add(p, BorderLayout.CENTER); 10.588 + 10.589 + statusText = createTextField(80); 10.590 + add(statusText, BorderLayout.SOUTH); 10.591 + 10.592 + pack(); 10.593 + setLocationRelativeTo(null); // centered on screen 10.594 + setVisible(true); 10.595 + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 10.596 + } 10.597 + 10.598 + /** Show an entry that has been selected. */ 10.599 + private void showEntry(Entry e) { 10.600 + try { 10.601 + // update simple fields 10.602 + setTitle(e.file.getName()); 10.603 + checkField.setText(e.check); 10.604 + enclPanel.setInfo(e.encl); 10.605 + selfPanel.setInfo(e.self); 10.606 + // show file text with highlights 10.607 + body.setText(e.file.getCharContent(true).toString()); 10.608 + Highlighter highlighter = body.getHighlighter(); 10.609 + highlighter.removeAllHighlights(); 10.610 + addHighlight(highlighter, e.encl, enclColor); 10.611 + addHighlight(highlighter, e.self, selfColor); 10.612 + scroll(body, getMinPos(enclPanel.info, selfPanel.info)); 10.613 + } catch (IOException ex) { 10.614 + body.setText("Cannot read " + e.file.getName() + ": " + e); 10.615 + } 10.616 + } 10.617 + 10.618 + /** Create a test field. */ 10.619 + private JTextField createTextField(int width) { 10.620 + JTextField f = new JTextField(width); 10.621 + f.setEditable(false); 10.622 + f.setBorder(null); 10.623 + return f; 10.624 + } 10.625 + 10.626 + /** Add a highlighted region based on the positions in an Info object. */ 10.627 + private void addHighlight(Highlighter h, Info info, Color c) { 10.628 + int start = info.start; 10.629 + int end = info.end; 10.630 + if (start == -1 && end == -1) 10.631 + return; 10.632 + if (start == -1) 10.633 + start = end; 10.634 + if (end == -1) 10.635 + end = start; 10.636 + try { 10.637 + h.addHighlight(info.start, info.end, 10.638 + new DefaultHighlighter.DefaultHighlightPainter(c)); 10.639 + if (info.pos != -1) { 10.640 + Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40% 10.641 + h.addHighlight(info.pos, info.pos + 1, 10.642 + new DefaultHighlighter.DefaultHighlightPainter(c2)); 10.643 + } 10.644 + } catch (BadLocationException e) { 10.645 + e.printStackTrace(); 10.646 + } 10.647 + } 10.648 + 10.649 + /** Get the minimum valid position in a set of info objects. */ 10.650 + private int getMinPos(Info... values) { 10.651 + int i = Integer.MAX_VALUE; 10.652 + for (Info info: values) { 10.653 + if (info.start >= 0) i = Math.min(i, info.start); 10.654 + if (info.pos >= 0) i = Math.min(i, info.pos); 10.655 + if (info.end >= 0) i = Math.min(i, info.end); 10.656 + } 10.657 + return (i == Integer.MAX_VALUE) ? 0 : i; 10.658 + } 10.659 + 10.660 + /** Set the background on a component. */ 10.661 + private JComponent setBackground(JComponent comp, Color c) { 10.662 + comp.setOpaque(true); 10.663 + comp.setBackground(c); 10.664 + return comp; 10.665 + } 10.666 + 10.667 + /** Scroll a text area to display a given position near the middle of the visible area. */ 10.668 + private void scroll(final JTextArea t, final int pos) { 10.669 + // Using invokeLater appears to give text a chance to sort itself out 10.670 + // before the scroll happens; otherwise scrollRectToVisible doesn't work. 10.671 + // Maybe there's a better way to sync with the text... 10.672 + EventQueue.invokeLater(new Runnable() { 10.673 + public void run() { 10.674 + try { 10.675 + Rectangle r = t.modelToView(pos); 10.676 + JScrollPane p = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, t); 10.677 + r.y = Math.max(0, r.y - p.getHeight() * 2 / 5); 10.678 + r.height += p.getHeight() * 4 / 5; 10.679 + t.scrollRectToVisible(r); 10.680 + } catch (BadLocationException ignore) { 10.681 + } 10.682 + } 10.683 + }); 10.684 + } 10.685 + 10.686 + private JComboBox entries; 10.687 + private JTextField checkField; 10.688 + private InfoPanel enclPanel; 10.689 + private InfoPanel selfPanel; 10.690 + private JTextArea body; 10.691 + private JTextField statusText; 10.692 + 10.693 + private Color selfColor = new Color(0.f, 1.f, 0.f, 0.2f); // 20% green 10.694 + private Color enclColor = new Color(1.f, 0.f, 0.f, 0.2f); // 20% red 10.695 + 10.696 + /** Panel to display an Info object. */ 10.697 + private class InfoPanel extends JPanel { 10.698 + InfoPanel() { 10.699 + add(tagName = createTextField(20)); 10.700 + add(new JLabel("start:")); 10.701 + add(addListener(start = createTextField(6))); 10.702 + add(new JLabel("pos:")); 10.703 + add(addListener(pos = createTextField(6))); 10.704 + add(new JLabel("end:")); 10.705 + add(addListener(end = createTextField(6))); 10.706 + } 10.707 + 10.708 + void setInfo(Info info) { 10.709 + this.info = info; 10.710 + tagName.setText(tagNames.get(info.tag)); 10.711 + start.setText(String.valueOf(info.start)); 10.712 + pos.setText(String.valueOf(info.pos)); 10.713 + end.setText(String.valueOf(info.end)); 10.714 + } 10.715 + 10.716 + JTextField addListener(final JTextField f) { 10.717 + f.addMouseListener(new MouseAdapter() { 10.718 + @Override 10.719 + public void mouseClicked(MouseEvent e) { 10.720 + body.setCaretPosition(Integer.valueOf(f.getText())); 10.721 + body.getCaret().setVisible(true); 10.722 + } 10.723 + }); 10.724 + return f; 10.725 + } 10.726 + 10.727 + Info info; 10.728 + JTextField tagName; 10.729 + JTextField start; 10.730 + JTextField pos; 10.731 + JTextField end; 10.732 + } 10.733 + 10.734 + /** Object to record information about an error to be displayed. */ 10.735 + private class Entry { 10.736 + Entry(JavaFileObject file, String check, Info encl, Info self) { 10.737 + this.file = file; 10.738 + this.check = check; 10.739 + this.encl = encl; 10.740 + this.self= self; 10.741 + } 10.742 + 10.743 + @Override 10.744 + public String toString() { 10.745 + return file.getName() + " " + check + " " + getMinPos(encl, self); 10.746 + } 10.747 + 10.748 + final JavaFileObject file; 10.749 + final String check; 10.750 + final Info encl; 10.751 + final Info self; 10.752 + } 10.753 + } 10.754 +} 10.755 +