Mon, 12 Sep 2011 11:40:07 -0700
Merge
1.1 --- a/.hgtags Mon Sep 12 11:39:08 2011 -0700 1.2 +++ b/.hgtags Mon Sep 12 11:40:07 2011 -0700 1.3 @@ -122,3 +122,7 @@ 1.4 c455e2ae5c93014ae3fc475aba4509b5f70465f7 jdk7-b145 1.5 9425dd4f53d5bfcd992d9aecea0eb7d8b2d4f62b jdk7-b146 1.6 58bc532d63418ac3c9b42460d89cdaf595c6f3e1 jdk7-b147 1.7 +e9f118c2bd3c4690d8d2e6b108b5bad7e226634c jdk8-b01 1.8 +b3c059de2a61fc122c99d555cdd8b85f112393c1 jdk8-b02 1.9 +f497fac86cf9ada4801ecaf49eb0d2307a2b61c8 jdk8-b03 1.10 +5df63fd8fa64741e829281ee6febe9954932841b jdk8-b04
2.1 --- a/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java Mon Sep 12 11:39:08 2011 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/api/ClientCodeWrapper.java Mon Sep 12 11:40:07 2011 -0700 2.3 @@ -609,6 +609,10 @@ 2.4 public String getMessage(Locale locale) { 2.5 return d.getMessage(locale); 2.6 } 2.7 + 2.8 + public String toString() { 2.9 + return d.toString(); 2.10 + } 2.11 } 2.12 2.13 protected class WrappedTaskListener implements TaskListener {
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Sep 12 11:39:08 2011 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Sep 12 11:40:07 2011 -0700 3.3 @@ -594,7 +594,15 @@ 3.4 lintEnv = lintEnv.next; 3.5 3.6 // Having found the enclosing lint value, we can initialize the lint value for this class 3.7 - env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.attributes_field, env.info.enclVar.flags()); 3.8 + // ... but ... 3.9 + // There's a problem with evaluating annotations in the right order, such that 3.10 + // env.info.enclVar.attributes_field might not yet have been evaluated, and so might be 3.11 + // null. In that case, calling augment will throw an NPE. To avoid this, for now we 3.12 + // revert to the jdk 6 behavior and ignore the (unevaluated) attributes. 3.13 + if (env.info.enclVar.attributes_field == null) 3.14 + env.info.lint = lintEnv.info.lint; 3.15 + else 3.16 + env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.attributes_field, env.info.enclVar.flags()); 3.17 3.18 Lint prevLint = chk.setLint(env.info.lint); 3.19 JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
4.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Mon Sep 12 11:39:08 2011 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Mon Sep 12 11:40:07 2011 -0700 4.3 @@ -1689,6 +1689,8 @@ 4.4 // outer instance of a super(...) call appears as first parameter). 4.5 genArgs(tree.args, 4.6 TreeInfo.symbol(tree.meth).externalType(types).getParameterTypes()); 4.7 + code.statBegin(tree.pos); 4.8 + code.markStatBegin(); 4.9 result = m.invoke(); 4.10 } 4.11
5.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Mon Sep 12 11:39:08 2011 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Mon Sep 12 11:40:07 2011 -0700 5.3 @@ -27,15 +27,15 @@ 5.4 5.5 import java.util.*; 5.6 5.7 +import com.sun.tools.javac.code.*; 5.8 import com.sun.tools.javac.tree.*; 5.9 -import com.sun.tools.javac.code.*; 5.10 +import com.sun.tools.javac.tree.JCTree.*; 5.11 import com.sun.tools.javac.util.*; 5.12 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; 5.13 +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; 5.14 import com.sun.tools.javac.util.List; 5.15 + 5.16 import static com.sun.tools.javac.util.ListBuffer.lb; 5.17 - 5.18 -import com.sun.tools.javac.tree.JCTree.*; 5.19 - 5.20 import static com.sun.tools.javac.parser.Token.*; 5.21 5.22 /** The parser maps a token sequence into an abstract syntax 5.23 @@ -254,26 +254,44 @@ 5.24 } 5.25 5.26 private JCErroneous syntaxError(int pos, String key, Token... args) { 5.27 - return syntaxError(pos, null, key, args); 5.28 + return syntaxError(pos, List.<JCTree>nil(), key, args); 5.29 } 5.30 5.31 private JCErroneous syntaxError(int pos, List<JCTree> errs, String key, Token... args) { 5.32 setErrorEndPos(pos); 5.33 - reportSyntaxError(pos, key, (Object[])args); 5.34 - return toP(F.at(pos).Erroneous(errs)); 5.35 + JCErroneous err = F.at(pos).Erroneous(errs); 5.36 + reportSyntaxError(err, key, (Object[])args); 5.37 + if (errs != null) { 5.38 + JCTree last = errs.last(); 5.39 + if (last != null) 5.40 + storeEnd(last, pos); 5.41 + } 5.42 + return toP(err); 5.43 } 5.44 5.45 private int errorPos = Position.NOPOS; 5.46 + 5.47 /** 5.48 - * Report a syntax error at given position using the given 5.49 - * argument unless one was already reported at the same position. 5.50 + * Report a syntax using the given the position parameter and arguments, 5.51 + * unless one was already reported at the same position. 5.52 */ 5.53 private void reportSyntaxError(int pos, String key, Object... args) { 5.54 + JCDiagnostic.DiagnosticPosition diag = new JCDiagnostic.SimpleDiagnosticPosition(pos); 5.55 + reportSyntaxError(diag, key, args); 5.56 + } 5.57 + 5.58 + /** 5.59 + * Report a syntax error using the given DiagnosticPosition object and 5.60 + * arguments, unless one was already reported at the same position. 5.61 + */ 5.62 + private void reportSyntaxError(JCDiagnostic.DiagnosticPosition diagPos, String key, Object... args) { 5.63 + int pos = diagPos.getPreferredPosition(); 5.64 if (pos > S.errPos() || pos == Position.NOPOS) { 5.65 - if (S.token() == EOF) 5.66 - error(pos, "premature.eof"); 5.67 - else 5.68 - error(pos, key, args); 5.69 + if (S.token() == EOF) { 5.70 + error(diagPos, "premature.eof"); 5.71 + } else { 5.72 + error(diagPos, key, args); 5.73 + } 5.74 } 5.75 S.errPos(pos); 5.76 if (S.pos() == errorPos) 5.77 @@ -311,7 +329,7 @@ 5.78 /** Report an illegal start of expression/type error at given position. 5.79 */ 5.80 JCExpression illegal(int pos) { 5.81 - setErrorEndPos(S.pos()); 5.82 + setErrorEndPos(pos); 5.83 if ((mode & EXPR) != 0) 5.84 return syntaxError(pos, "illegal.start.of.expr"); 5.85 else 5.86 @@ -340,7 +358,7 @@ 5.87 * indexed by the tree nodes they refer to. 5.88 * defined only if option flag keepDocComment is set. 5.89 */ 5.90 - Map<JCTree, String> docComments; 5.91 + private final Map<JCTree, String> docComments; 5.92 5.93 /** Make an entry into docComments hashtable, 5.94 * provided flag keepDocComments is set and given doc comment is non-null. 5.95 @@ -462,6 +480,10 @@ 5.96 return t; 5.97 } 5.98 5.99 + JCExpression literal(Name prefix) { 5.100 + return literal(prefix, S.pos()); 5.101 + } 5.102 + 5.103 /** 5.104 * Literal = 5.105 * INTLITERAL 5.106 @@ -474,8 +496,7 @@ 5.107 * | FALSE 5.108 * | NULL 5.109 */ 5.110 - JCExpression literal(Name prefix) { 5.111 - int pos = S.pos(); 5.112 + JCExpression literal(Name prefix, int pos) { 5.113 JCExpression t = errorTree; 5.114 switch (S.token()) { 5.115 case INTLITERAL: 5.116 @@ -869,7 +890,7 @@ 5.117 (S.token() == INTLITERAL || S.token() == LONGLITERAL) && 5.118 S.radix() == 10) { 5.119 mode = EXPR; 5.120 - t = literal(names.hyphen); 5.121 + t = literal(names.hyphen, pos); 5.122 } else { 5.123 t = term3(); 5.124 return F.at(pos).Unary(unoptag(token), t); 5.125 @@ -1267,15 +1288,17 @@ 5.126 case GTGT: 5.127 S.token(GT); 5.128 break; 5.129 + case GT: 5.130 + S.nextToken(); 5.131 + break; 5.132 default: 5.133 - accept(GT); 5.134 + args.append(syntaxError(S.pos(), "expected", GT)); 5.135 break; 5.136 } 5.137 return args.toList(); 5.138 } 5.139 } else { 5.140 - syntaxError(S.pos(), "expected", LT); 5.141 - return List.nil(); 5.142 + return List.<JCExpression>of(syntaxError(S.pos(), "expected", LT)); 5.143 } 5.144 } 5.145 5.146 @@ -1300,12 +1323,12 @@ 5.147 return F.at(pos).Wildcard(t, bound); 5.148 } else if (S.token() == IDENTIFIER) { 5.149 //error recovery 5.150 - reportSyntaxError(S.prevEndPos(), "expected3", 5.151 - GT, EXTENDS, SUPER); 5.152 TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND); 5.153 JCExpression wc = toP(F.at(pos).Wildcard(t, null)); 5.154 JCIdent id = toP(F.at(S.pos()).Ident(ident())); 5.155 - return F.at(pos).Erroneous(List.<JCTree>of(wc, id)); 5.156 + JCErroneous err = F.at(pos).Erroneous(List.<JCTree>of(wc, id)); 5.157 + reportSyntaxError(err, "expected3", GT, EXTENDS, SUPER); 5.158 + return err; 5.159 } else { 5.160 TypeBoundKind t = toP(F.at(pos).TypeBoundKind(BoundKind.UNBOUND)); 5.161 return toP(F.at(pos).Wildcard(t, null)); 5.162 @@ -1391,7 +1414,7 @@ 5.163 while (S.token() == DOT) { 5.164 if (diamondFound) { 5.165 //cannot select after a diamond 5.166 - illegal(S.pos()); 5.167 + illegal(); 5.168 } 5.169 int pos = S.pos(); 5.170 S.nextToken(); 5.171 @@ -1419,15 +1442,16 @@ 5.172 pos = typeArgs.head.pos; 5.173 } 5.174 setErrorEndPos(S.prevEndPos()); 5.175 - reportSyntaxError(pos, "cannot.create.array.with.type.arguments"); 5.176 - return toP(F.at(newpos).Erroneous(typeArgs.prepend(e))); 5.177 + JCErroneous err = F.at(pos).Erroneous(typeArgs.prepend(e)); 5.178 + reportSyntaxError(err, "cannot.create.array.with.type.arguments"); 5.179 + return toP(err); 5.180 } 5.181 return e; 5.182 } else if (S.token() == LPAREN) { 5.183 return classCreatorRest(newpos, null, typeArgs, t); 5.184 } else { 5.185 - reportSyntaxError(S.pos(), "expected2", 5.186 - LPAREN, LBRACKET); 5.187 + setErrorEndPos(S.pos()); 5.188 + reportSyntaxError(S.pos(), "expected2", LPAREN, LBRACKET); 5.189 t = toP(F.at(newpos).NewClass(null, typeArgs, t, List.<JCExpression>nil(), null)); 5.190 return toP(F.at(newpos).Erroneous(List.<JCTree>of(t))); 5.191 } 5.192 @@ -1457,7 +1481,8 @@ 5.193 if (S.token() == LBRACE) { 5.194 return arrayInitializer(newpos, elemtype); 5.195 } else { 5.196 - return syntaxError(S.pos(), "array.dimension.missing"); 5.197 + JCExpression t = toP(F.at(newpos).NewArray(elemtype, List.<JCExpression>nil(), null)); 5.198 + return syntaxError(S.pos(), List.<JCTree>of(t), "array.dimension.missing"); 5.199 } 5.200 } else { 5.201 ListBuffer<JCExpression> dims = new ListBuffer<JCExpression>(); 5.202 @@ -1843,7 +1868,7 @@ 5.203 5.204 /** CatchClause = CATCH "(" FormalParameter ")" Block 5.205 */ 5.206 - JCCatch catchClause() { 5.207 + protected JCCatch catchClause() { 5.208 int pos = S.pos(); 5.209 accept(CATCH); 5.210 accept(LPAREN); 5.211 @@ -1973,7 +1998,7 @@ 5.212 JCModifiers modifiersOpt() { 5.213 return modifiersOpt(null); 5.214 } 5.215 - JCModifiers modifiersOpt(JCModifiers partial) { 5.216 + protected JCModifiers modifiersOpt(JCModifiers partial) { 5.217 long flags; 5.218 ListBuffer<JCAnnotation> annotations = new ListBuffer<JCAnnotation>(); 5.219 int pos; 5.220 @@ -2006,6 +2031,7 @@ 5.221 case SYNCHRONIZED: flag = Flags.SYNCHRONIZED; break; 5.222 case STRICTFP : flag = Flags.STRICTFP; break; 5.223 case MONKEYS_AT : flag = Flags.ANNOTATION; break; 5.224 + case ERROR : flag = 0; S.nextToken(); break; 5.225 default: break loop; 5.226 } 5.227 if ((flags & flag) != 0) error(S.pos(), "repeated.modifier"); 5.228 @@ -2219,9 +2245,12 @@ 5.229 5.230 /** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression 5.231 */ 5.232 - JCTree resource() { 5.233 - return variableDeclaratorRest(S.pos(), optFinal(Flags.FINAL), 5.234 - parseType(), ident(), true, null); 5.235 + protected JCTree resource() { 5.236 + JCModifiers optFinal = optFinal(Flags.FINAL); 5.237 + JCExpression type = parseType(); 5.238 + int pos = S.pos(); 5.239 + Name ident = ident(); 5.240 + return variableDeclaratorRest(pos, optFinal, type, ident, true, null); 5.241 } 5.242 5.243 /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration} 5.244 @@ -2568,7 +2597,7 @@ 5.245 * | ModifiersOpt Type Ident 5.246 * ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" ) 5.247 */ 5.248 - List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { 5.249 + protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { 5.250 if (S.token() == SEMI) { 5.251 S.nextToken(); 5.252 return List.<JCTree>nil(); 5.253 @@ -2770,7 +2799,7 @@ 5.254 /** FormalParameter = { FINAL | '@' Annotation } Type VariableDeclaratorId 5.255 * LastFormalParameter = { FINAL | '@' Annotation } Type '...' Ident | FormalParameter 5.256 */ 5.257 - JCVariableDecl formalParameter() { 5.258 + protected JCVariableDecl formalParameter() { 5.259 JCModifiers mods = optFinal(Flags.PARAMETER); 5.260 JCExpression type = parseType(); 5.261 if (S.token() == ELLIPSIS) { 5.262 @@ -2788,6 +2817,10 @@ 5.263 log.error(DiagnosticFlag.SYNTAX, pos, key, args); 5.264 } 5.265 5.266 + void error(DiagnosticPosition pos, String key, Object ... args) { 5.267 + log.error(DiagnosticFlag.SYNTAX, pos, key, args); 5.268 + } 5.269 + 5.270 void warning(int pos, String key, Object ... args) { 5.271 log.warning(pos, key, args); 5.272 } 5.273 @@ -2807,8 +2840,9 @@ 5.274 case JCTree.ERRONEOUS: 5.275 return t; 5.276 default: 5.277 - error(t.pos, "not.stmt"); 5.278 - return F.at(t.pos).Erroneous(List.<JCTree>of(t)); 5.279 + JCExpression ret = F.at(t.pos).Erroneous(List.<JCTree>of(t)); 5.280 + error(ret, "not.stmt"); 5.281 + return ret; 5.282 } 5.283 } 5.284
6.1 --- a/src/share/classes/com/sun/tools/javac/parser/Scanner.java Mon Sep 12 11:39:08 2011 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/parser/Scanner.java Mon Sep 12 11:40:07 2011 -0700 6.3 @@ -982,8 +982,16 @@ 6.4 } 6.5 6.6 /** Sets the current token. 6.7 + * This method is primarily used to update the token stream when the 6.8 + * parser is handling the end of nested type arguments such as 6.9 + * {@code List<List<String>>} and needs to disambiguate between 6.10 + * repeated use of ">" and relation operators such as ">>" and ">>>". Noting 6.11 + * that this does not handle arbitrary tokens containing Unicode escape 6.12 + * sequences. 6.13 */ 6.14 public void token(Token token) { 6.15 + pos += this.token.name.length() - token.name.length(); 6.16 + prevEndPos = pos; 6.17 this.token = token; 6.18 } 6.19
7.1 --- a/src/share/classes/com/sun/tools/javac/util/AbstractLog.java Mon Sep 12 11:39:08 2011 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/util/AbstractLog.java Mon Sep 12 11:40:07 2011 -0700 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 7.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 * 7.9 * This code is free software; you can redistribute it and/or modify it 7.10 @@ -96,6 +96,19 @@ 7.11 7.12 /** Report an error, unless another error was already reported at same 7.13 * source position. 7.14 + * @param flag A flag to set on the diagnostic 7.15 + * @param pos The source position at which to report the error. 7.16 + * @param key The key for the localized error message. 7.17 + * @param args Fields of the error message. 7.18 + */ 7.19 + public void error(DiagnosticFlag flag, DiagnosticPosition pos, String key, Object ... args) { 7.20 + JCDiagnostic d = diags.error(source, pos, key, args); 7.21 + d.setFlag(flag); 7.22 + report(d); 7.23 + } 7.24 + 7.25 + /** Report an error, unless another error was already reported at same 7.26 + * source position. 7.27 * @param pos The source position at which to report the error. 7.28 * @param key The key for the localized error message. 7.29 * @param args Fields of the error message.
8.1 --- a/test/tools/javac/7079713/TestCircularClassfile.java Mon Sep 12 11:39:08 2011 -0700 8.2 +++ b/test/tools/javac/7079713/TestCircularClassfile.java Mon Sep 12 11:40:07 2011 -0700 8.3 @@ -149,6 +149,7 @@ 8.4 //step 3: move a classfile from the temp folder to the test subfolder 8.5 File fileToMove = new File(tmpDir, tk.targetClass); 8.6 File target = new File(destDir, tk.targetClass); 8.7 + target.delete(); 8.8 boolean success = fileToMove.renameTo(target); 8.9 8.10 if (!success) {
9.1 --- a/test/tools/javac/TryWithResources/BadTwr.out Mon Sep 12 11:39:08 2011 -0700 9.2 +++ b/test/tools/javac/TryWithResources/BadTwr.out Mon Sep 12 11:40:07 2011 -0700 9.3 @@ -1,5 +1,5 @@ 9.4 -BadTwr.java:13:39: compiler.err.already.defined: r1, main(java.lang.String...) 9.5 -BadTwr.java:18:13: compiler.err.already.defined: args, main(java.lang.String...) 9.6 +BadTwr.java:13:46: compiler.err.already.defined: r1, main(java.lang.String...) 9.7 +BadTwr.java:18:20: compiler.err.already.defined: args, main(java.lang.String...) 9.8 BadTwr.java:21:13: compiler.err.cant.assign.val.to.final.var: thatsIt 9.9 -BadTwr.java:26:17: compiler.err.already.defined: name, main(java.lang.String...) 9.10 +BadTwr.java:26:24: compiler.err.already.defined: name, main(java.lang.String...) 9.11 4 errors
10.1 --- a/test/tools/javac/TryWithResources/DuplicateResourceDecl.out Mon Sep 12 11:39:08 2011 -0700 10.2 +++ b/test/tools/javac/TryWithResources/DuplicateResourceDecl.out Mon Sep 12 11:40:07 2011 -0700 10.3 @@ -1,2 +1,2 @@ 10.4 -DuplicateResourceDecl.java:12:45: compiler.err.already.defined: c, main(java.lang.String[]) 10.5 +DuplicateResourceDecl.java:12:56: compiler.err.already.defined: c, main(java.lang.String[]) 10.6 1 error
11.1 --- a/test/tools/javac/TryWithResources/ResourceInterface.out Mon Sep 12 11:39:08 2011 -0700 11.2 +++ b/test/tools/javac/TryWithResources/ResourceInterface.out Mon Sep 12 11:40:07 2011 -0700 11.3 @@ -1,2 +1,2 @@ 11.4 -ResourceInterface.java:38:13: compiler.err.unreported.exception.implicit.close: ResourceInterface.E1, r2 11.5 +ResourceInterface.java:38:23: compiler.err.unreported.exception.implicit.close: ResourceInterface.E1, r2 11.6 1 error
12.1 --- a/test/tools/javac/TryWithResources/TwrFlow.out Mon Sep 12 11:39:08 2011 -0700 12.2 +++ b/test/tools/javac/TryWithResources/TwrFlow.out Mon Sep 12 11:40:07 2011 -0700 12.3 @@ -1,3 +1,3 @@ 12.4 TwrFlow.java:14:11: compiler.err.except.never.thrown.in.try: java.io.IOException 12.5 -TwrFlow.java:12:13: compiler.err.unreported.exception.implicit.close: CustomCloseException, twrFlow 12.6 +TwrFlow.java:12:21: compiler.err.unreported.exception.implicit.close: CustomCloseException, twrFlow 12.7 2 errors
13.1 --- a/test/tools/javac/TryWithResources/TwrLint.out Mon Sep 12 11:39:08 2011 -0700 13.2 +++ b/test/tools/javac/TryWithResources/TwrLint.out Mon Sep 12 11:40:07 2011 -0700 13.3 @@ -1,3 +1,3 @@ 13.4 TwrLint.java:14:15: compiler.warn.try.explicit.close.call 13.5 -TwrLint.java:13:13: compiler.warn.try.resource.not.referenced: r3 13.6 +TwrLint.java:13:21: compiler.warn.try.resource.not.referenced: r3 13.7 2 warnings
14.1 --- a/test/tools/javac/TryWithResources/TwrOnNonResource.out Mon Sep 12 11:39:08 2011 -0700 14.2 +++ b/test/tools/javac/TryWithResources/TwrOnNonResource.out Mon Sep 12 11:40:07 2011 -0700 14.3 @@ -1,4 +1,4 @@ 14.4 -TwrOnNonResource.java:12:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 14.5 -TwrOnNonResource.java:15:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 14.6 -TwrOnNonResource.java:18:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 14.7 +TwrOnNonResource.java:12:30: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 14.8 +TwrOnNonResource.java:15:30: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 14.9 +TwrOnNonResource.java:18:30: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 14.10 3 errors
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/annotations/T7043371.java Mon Sep 12 11:40:07 2011 -0700 15.3 @@ -0,0 +1,43 @@ 15.4 +/* 15.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +/* 15.28 + * @test 15.29 + * @bug 7043371 15.30 + * @summary javac7 fails with NPE during compilation 15.31 + * @compile T7043371.java 15.32 + */ 15.33 + 15.34 +@interface Anno { 15.35 + String value(); 15.36 +} 15.37 + 15.38 +class B { 15.39 + @Anno(value=A.a) 15.40 + public static final int b = 0; 15.41 +} 15.42 + 15.43 +class A { 15.44 + @Deprecated 15.45 + public static final String a = "a"; 15.46 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/annotations/T7073477.java Mon Sep 12 11:40:07 2011 -0700 16.3 @@ -0,0 +1,39 @@ 16.4 +/* 16.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 +/* 16.28 + * @test 16.29 + * @bug 7073477 16.30 + * @summary NPE in com.sun.tools.javac.code.Symbol$VarSymbol.getConstValue 16.31 + * @compile T7073477.java 16.32 + */ 16.33 + 16.34 +@SuppressWarnings(T7073477A.S) 16.35 +class T7073477 { 16.36 +} 16.37 + 16.38 +class T7073477A { 16.39 + @SuppressWarnings("") 16.40 + static final String S = ""; 16.41 +} 16.42 +
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/api/7086261/T7086261.java Mon Sep 12 11:40:07 2011 -0700 17.3 @@ -0,0 +1,78 @@ 17.4 +/* 17.5 + * Copyright (c) 20011, Oracle and/or its affiliates. All rights reserved. 17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 17.7 + * 17.8 + * This code is free software; you can redistribute it and/or modify it 17.9 + * under the terms of the GNU General Public License version 2 only, as 17.10 + * published by the Free Software Foundation. 17.11 + * 17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17.15 + * version 2 for more details (a copy is included in the LICENSE file that 17.16 + * accompanied this code). 17.17 + * 17.18 + * You should have received a copy of the GNU General Public License version 17.19 + * 2 along with this work; if not, write to the Free Software Foundation, 17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17.21 + * 17.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 17.23 + * or visit www.oracle.com if you need additional information or have any 17.24 + * questions. 17.25 + */ 17.26 + 17.27 +/* 17.28 + * @test 17.29 + * @bug 7086261 17.30 + * @summary javac doesn't report error as expected, it only reports ClientCodeWrapper$DiagnosticSourceUnwrapper 17.31 + */ 17.32 + 17.33 +import javax.tools.*; 17.34 + 17.35 +import com.sun.tools.javac.api.ClientCodeWrapper.DiagnosticSourceUnwrapper; 17.36 +import com.sun.tools.javac.util.JCDiagnostic; 17.37 + 17.38 +import java.net.URI; 17.39 +import java.util.Arrays; 17.40 + 17.41 +import static javax.tools.StandardLocation.*; 17.42 +import static javax.tools.JavaFileObject.Kind.*; 17.43 + 17.44 + 17.45 +public class T7086261 { 17.46 + 17.47 + static class ErroneousSource extends SimpleJavaFileObject { 17.48 + public ErroneousSource() { 17.49 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 17.50 + } 17.51 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 17.52 + return "class Test { NonexistentClass c = null; }"; 17.53 + } 17.54 + } 17.55 + 17.56 + static class DiagnosticChecker implements DiagnosticListener<javax.tools.JavaFileObject> { 17.57 + public void report(Diagnostic message) { 17.58 + if (!(message instanceof DiagnosticSourceUnwrapper)) { 17.59 + throw new AssertionError("Wrapped diagnostic expected!"); 17.60 + } 17.61 + String actual = message.toString(); 17.62 + JCDiagnostic jd = (JCDiagnostic)((DiagnosticSourceUnwrapper)message).d; 17.63 + String expected = jd.toString(); 17.64 + if (!actual.equals(expected)) { 17.65 + throw new AssertionError("expected = " + expected + "\nfound = " + actual); 17.66 + } 17.67 + } 17.68 + }; 17.69 + 17.70 + void test() throws Throwable { 17.71 + JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); 17.72 + JavaFileManager jfm = javac.getStandardFileManager(null, null, null); 17.73 + JavaCompiler.CompilationTask task = 17.74 + javac.getTask(null, jfm, new DiagnosticChecker(), null, null, Arrays.asList(new ErroneousSource())); 17.75 + task.call(); 17.76 + } 17.77 + 17.78 + public static void main(String[] args) throws Throwable { 17.79 + new T7086261().test(); 17.80 + } 17.81 +}
18.1 --- a/test/tools/javac/diags/examples/EmptyCharLiteral.java Mon Sep 12 11:39:08 2011 -0700 18.2 +++ b/test/tools/javac/diags/examples/EmptyCharLiteral.java Mon Sep 12 11:40:07 2011 -0700 18.3 @@ -1,5 +1,5 @@ 18.4 /* 18.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 18.6 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 18.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.8 * 18.9 * This code is free software; you can redistribute it and/or modify it 18.10 @@ -23,7 +23,6 @@ 18.11 18.12 // key: compiler.err.empty.char.lit 18.13 // key: compiler.err.unclosed.char.lit 18.14 -// key: compiler.err.expected 18.15 // key: compiler.err.premature.eof 18.16 18.17 class X {
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/jvm/T7024096.java Mon Sep 12 11:40:07 2011 -0700 19.3 @@ -0,0 +1,31 @@ 19.4 +/* 19.5 + * @test /nodynamiccopyright/ 19.6 + * @bug 7024096 19.7 + * @summary Stack trace has invalid line numbers 19.8 + * @author Bruce Chapman 19.9 + * @compile T7024096.java 19.10 + * @run main T7024096 19.11 + */ 19.12 + 19.13 +public class T7024096 { 19.14 + private static final int START = 14; // starting line number for the test 19.15 + public static void main(String[] args) { 19.16 + T7024096 m = new T7024096(); 19.17 + m.nest(START); 19.18 + m.nest(START + 1, m.nest(START + 1), m.nest(START + 1), 19.19 + m.nest(START + 2), 19.20 + m.nest(START + 3, m.nest(START + 3))); 19.21 + } 19.22 + 19.23 + public T7024096 nest(int expectedline, T7024096... args) { 19.24 + Exception e = new Exception("expected line#: " + expectedline); 19.25 + int myline = e.getStackTrace()[1].getLineNumber(); 19.26 + if( myline != expectedline) { 19.27 + throw new RuntimeException("Incorrect line number " + 19.28 + "expected: " + expectedline + 19.29 + ", got: " + myline, e); 19.30 + } 19.31 + System.out.format("Got expected line number %d correct %n", myline); 19.32 + return null; 19.33 + } 19.34 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/tools/javac/parser/netbeans/JavacParserTest.java Mon Sep 12 11:40:07 2011 -0700 20.3 @@ -0,0 +1,716 @@ 20.4 +/* 20.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. 20.11 + * 20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.15 + * version 2 for more details (a copy is included in the LICENSE file that 20.16 + * accompanied this code). 20.17 + * 20.18 + * You should have received a copy of the GNU General Public License version 20.19 + * 2 along with this work; if not, write to the Free Software Foundation, 20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.21 + * 20.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.23 + * or visit www.oracle.com if you need additional information or have any 20.24 + * questions. 20.25 + */ 20.26 + 20.27 +/* 20.28 + * @test 20.29 + * @bug 7073631 20.30 + * @summary tests error and diagnostics positions 20.31 + * @author jan.lahoda@oracle.com 20.32 + */ 20.33 + 20.34 +import com.sun.source.tree.BinaryTree; 20.35 +import com.sun.source.tree.BlockTree; 20.36 +import com.sun.source.tree.ClassTree; 20.37 +import com.sun.source.tree.CompilationUnitTree; 20.38 +import com.sun.source.tree.ExpressionStatementTree; 20.39 +import com.sun.source.tree.ExpressionTree; 20.40 +import com.sun.source.tree.MethodInvocationTree; 20.41 +import com.sun.source.tree.MethodTree; 20.42 +import com.sun.source.tree.ModifiersTree; 20.43 +import com.sun.source.tree.StatementTree; 20.44 +import com.sun.source.tree.Tree; 20.45 +import com.sun.source.tree.Tree.Kind; 20.46 +import com.sun.source.tree.VariableTree; 20.47 +import com.sun.source.tree.WhileLoopTree; 20.48 +import com.sun.source.util.SourcePositions; 20.49 +import com.sun.source.util.TreeScanner; 20.50 +import com.sun.source.util.Trees; 20.51 +import com.sun.tools.javac.api.JavacTaskImpl; 20.52 +import com.sun.tools.javac.tree.JCTree; 20.53 +import java.io.IOException; 20.54 +import java.net.URI; 20.55 +import java.util.Arrays; 20.56 +import java.util.LinkedList; 20.57 +import java.util.List; 20.58 +import javax.tools.Diagnostic; 20.59 +import javax.tools.DiagnosticCollector; 20.60 +import javax.tools.DiagnosticListener; 20.61 +import javax.tools.JavaCompiler; 20.62 +import javax.tools.JavaFileObject; 20.63 +import javax.tools.SimpleJavaFileObject; 20.64 +import javax.tools.ToolProvider; 20.65 + 20.66 +public class JavacParserTest extends TestCase { 20.67 + final JavaCompiler tool; 20.68 + public JavacParserTest(String testName) { 20.69 + tool = ToolProvider.getSystemJavaCompiler(); 20.70 + System.out.println("java.home=" + System.getProperty("java.home")); 20.71 + } 20.72 + 20.73 + static class MyFileObject extends SimpleJavaFileObject { 20.74 + 20.75 + private String text; 20.76 + 20.77 + public MyFileObject(String text) { 20.78 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 20.79 + this.text = text; 20.80 + } 20.81 + 20.82 + @Override 20.83 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 20.84 + return text; 20.85 + } 20.86 + } 20.87 + 20.88 + public void testPositionForSuperConstructorCalls() throws IOException { 20.89 + assert tool != null; 20.90 + 20.91 + String code = "package test; public class Test {public Test() {super();}}"; 20.92 + 20.93 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.94 + null, Arrays.asList(new MyFileObject(code))); 20.95 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.96 + SourcePositions pos = Trees.instance(ct).getSourcePositions(); 20.97 + 20.98 + MethodTree method = 20.99 + (MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0); 20.100 + ExpressionStatementTree es = 20.101 + (ExpressionStatementTree) method.getBody().getStatements().get(0); 20.102 + 20.103 + assertEquals("testPositionForSuperConstructorCalls", 20.104 + 72 - 24, pos.getStartPosition(cut, es)); 20.105 + assertEquals("testPositionForSuperConstructorCalls", 20.106 + 80 - 24, pos.getEndPosition(cut, es)); 20.107 + 20.108 + MethodInvocationTree mit = (MethodInvocationTree) es.getExpression(); 20.109 + 20.110 + assertEquals("testPositionForSuperConstructorCalls", 20.111 + 72 - 24, pos.getStartPosition(cut, mit)); 20.112 + assertEquals("testPositionForSuperConstructorCalls", 20.113 + 79 - 24, pos.getEndPosition(cut, mit)); 20.114 + 20.115 + assertEquals("testPositionForSuperConstructorCalls", 20.116 + 72 - 24, pos.getStartPosition(cut, mit.getMethodSelect())); 20.117 + assertEquals("testPositionForSuperConstructorCalls", 20.118 + 77 - 24, pos.getEndPosition(cut, mit.getMethodSelect())); 20.119 + 20.120 + } 20.121 + 20.122 + public void testPositionForEnumModifiers() throws IOException { 20.123 + 20.124 + String code = "package test; public enum Test {A;}"; 20.125 + 20.126 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.127 + null, Arrays.asList(new MyFileObject(code))); 20.128 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.129 + SourcePositions pos = Trees.instance(ct).getSourcePositions(); 20.130 + 20.131 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 20.132 + ModifiersTree mt = clazz.getModifiers(); 20.133 + 20.134 + assertEquals("testPositionForEnumModifiers", 20.135 + 38 - 24, pos.getStartPosition(cut, mt)); 20.136 + assertEquals("testPositionForEnumModifiers", 20.137 + 44 - 24, pos.getEndPosition(cut, mt)); 20.138 + } 20.139 + 20.140 + public void testNewClassWithEnclosing() throws IOException { 20.141 + 20.142 + 20.143 + String code = "package test; class Test { " + 20.144 + "class d {} private void method() { " + 20.145 + "Object o = Test.this.new d(); } }"; 20.146 + 20.147 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.148 + null, Arrays.asList(new MyFileObject(code))); 20.149 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.150 + SourcePositions pos = Trees.instance(ct).getSourcePositions(); 20.151 + 20.152 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 20.153 + ExpressionTree est = 20.154 + ((VariableTree) ((MethodTree) clazz.getMembers().get(1)).getBody().getStatements().get(0)).getInitializer(); 20.155 + 20.156 + assertEquals("testNewClassWithEnclosing", 20.157 + 97 - 24, pos.getStartPosition(cut, est)); 20.158 + assertEquals("testNewClassWithEnclosing", 20.159 + 114 - 24, pos.getEndPosition(cut, est)); 20.160 + } 20.161 + 20.162 + public void testPreferredPositionForBinaryOp() throws IOException { 20.163 + 20.164 + String code = "package test; public class Test {" + 20.165 + "private void test() {" + 20.166 + "Object o = null; boolean b = o != null && o instanceof String;" + 20.167 + "} private Test() {}}"; 20.168 + 20.169 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.170 + null, Arrays.asList(new MyFileObject(code))); 20.171 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.172 + 20.173 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 20.174 + MethodTree method = (MethodTree) clazz.getMembers().get(0); 20.175 + VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1); 20.176 + BinaryTree cond = (BinaryTree) condSt.getInitializer(); 20.177 + 20.178 + JCTree condJC = (JCTree) cond; 20.179 + 20.180 + assertEquals("testNewClassWithEnclosing", 20.181 + 117 - 24, condJC.pos); 20.182 + } 20.183 + 20.184 + public void testPositionBrokenSource126732a() throws IOException { 20.185 + String[] commands = new String[]{ 20.186 + "return Runnable()", 20.187 + "do { } while (true)", 20.188 + "throw UnsupportedOperationException()", 20.189 + "assert true", 20.190 + "1 + 1",}; 20.191 + 20.192 + for (String command : commands) { 20.193 + 20.194 + String code = "package test;\n" 20.195 + + "public class Test {\n" 20.196 + + " public static void test() {\n" 20.197 + + " " + command + " {\n" 20.198 + + " new Runnable() {\n" 20.199 + + " };\n" 20.200 + + " }\n" 20.201 + + "}"; 20.202 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, 20.203 + null, null, Arrays.asList(new MyFileObject(code))); 20.204 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.205 + 20.206 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 20.207 + MethodTree method = (MethodTree) clazz.getMembers().get(0); 20.208 + List<? extends StatementTree> statements = 20.209 + method.getBody().getStatements(); 20.210 + 20.211 + StatementTree ret = statements.get(0); 20.212 + StatementTree block = statements.get(1); 20.213 + 20.214 + Trees t = Trees.instance(ct); 20.215 + int len = code.indexOf(command + " {") + (command + " ").length(); 20.216 + assertEquals(command, len, 20.217 + t.getSourcePositions().getEndPosition(cut, ret)); 20.218 + assertEquals(command, len, 20.219 + t.getSourcePositions().getStartPosition(cut, block)); 20.220 + } 20.221 + } 20.222 + 20.223 + public void testPositionBrokenSource126732b() throws IOException { 20.224 + String[] commands = new String[]{ 20.225 + "break", 20.226 + "break A", 20.227 + "continue ", 20.228 + "continue A",}; 20.229 + 20.230 + for (String command : commands) { 20.231 + 20.232 + String code = "package test;\n" 20.233 + + "public class Test {\n" 20.234 + + " public static void test() {\n" 20.235 + + " while (true) {\n" 20.236 + + " " + command + " {\n" 20.237 + + " new Runnable() {\n" 20.238 + + " };\n" 20.239 + + " }\n" 20.240 + + " }\n" 20.241 + + "}"; 20.242 + 20.243 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, 20.244 + null, null, Arrays.asList(new MyFileObject(code))); 20.245 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.246 + 20.247 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 20.248 + MethodTree method = (MethodTree) clazz.getMembers().get(0); 20.249 + List<? extends StatementTree> statements = 20.250 + ((BlockTree) ((WhileLoopTree) method.getBody().getStatements().get(0)).getStatement()).getStatements(); 20.251 + 20.252 + StatementTree ret = statements.get(0); 20.253 + StatementTree block = statements.get(1); 20.254 + 20.255 + Trees t = Trees.instance(ct); 20.256 + int len = code.indexOf(command + " {") + (command + " ").length(); 20.257 + assertEquals(command, len, 20.258 + t.getSourcePositions().getEndPosition(cut, ret)); 20.259 + assertEquals(command, len, 20.260 + t.getSourcePositions().getStartPosition(cut, block)); 20.261 + } 20.262 + } 20.263 + 20.264 + public void testErrorRecoveryForEnhancedForLoop142381() throws IOException { 20.265 + 20.266 + String code = "package test; class Test { " + 20.267 + "private void method() { " + 20.268 + "java.util.Set<String> s = null; for (a : s) {} } }"; 20.269 + 20.270 + final List<Diagnostic<? extends JavaFileObject>> errors = 20.271 + new LinkedList<Diagnostic<? extends JavaFileObject>>(); 20.272 + 20.273 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, 20.274 + new DiagnosticListener<JavaFileObject>() { 20.275 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 20.276 + errors.add(diagnostic); 20.277 + } 20.278 + }, null, null, Arrays.asList(new MyFileObject(code))); 20.279 + 20.280 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.281 + 20.282 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 20.283 + StatementTree forStatement = 20.284 + ((MethodTree) clazz.getMembers().get(0)).getBody().getStatements().get(1); 20.285 + 20.286 + assertEquals("testErrorRecoveryForEnhancedForLoop142381", 20.287 + Kind.ENHANCED_FOR_LOOP, forStatement.getKind()); 20.288 + assertFalse("testErrorRecoveryForEnhancedForLoop142381", errors.isEmpty()); 20.289 + } 20.290 + 20.291 + public void testPositionAnnotationNoPackage187551() throws IOException { 20.292 + 20.293 + String code = "\n@interface Test {}"; 20.294 + 20.295 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.296 + null, Arrays.asList(new MyFileObject(code))); 20.297 + 20.298 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.299 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 20.300 + Trees t = Trees.instance(ct); 20.301 + 20.302 + assertEquals("testPositionAnnotationNoPackage187551", 20.303 + 1, t.getSourcePositions().getStartPosition(cut, clazz)); 20.304 + } 20.305 + 20.306 + public void testPositionsSane() throws IOException { 20.307 + performPositionsSanityTest("package test; class Test { " + 20.308 + "private void method() { " + 20.309 + "java.util.List<? extends java.util.List<? extends String>> l; " + 20.310 + "} }"); 20.311 + performPositionsSanityTest("package test; class Test { " + 20.312 + "private void method() { " + 20.313 + "java.util.List<? super java.util.List<? super String>> l; " + 20.314 + "} }"); 20.315 + performPositionsSanityTest("package test; class Test { " + 20.316 + "private void method() { " + 20.317 + "java.util.List<? super java.util.List<?>> l; } }"); 20.318 + } 20.319 + 20.320 + private void performPositionsSanityTest(String code) throws IOException { 20.321 + 20.322 + final List<Diagnostic<? extends JavaFileObject>> errors = 20.323 + new LinkedList<Diagnostic<? extends JavaFileObject>>(); 20.324 + 20.325 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, 20.326 + new DiagnosticListener<JavaFileObject>() { 20.327 + 20.328 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 20.329 + errors.add(diagnostic); 20.330 + } 20.331 + }, null, null, Arrays.asList(new MyFileObject(code))); 20.332 + 20.333 + final CompilationUnitTree cut = ct.parse().iterator().next(); 20.334 + final Trees trees = Trees.instance(ct); 20.335 + 20.336 + new TreeScanner<Void, Void>() { 20.337 + 20.338 + private long parentStart = 0; 20.339 + private long parentEnd = Integer.MAX_VALUE; 20.340 + 20.341 + @Override 20.342 + public Void scan(Tree node, Void p) { 20.343 + if (node == null) { 20.344 + return null; 20.345 + } 20.346 + 20.347 + long start = trees.getSourcePositions().getStartPosition(cut, node); 20.348 + 20.349 + if (start == (-1)) { 20.350 + return null; //synthetic tree 20.351 + } 20.352 + assertTrue(node.toString() + ":" + start + "/" + parentStart, 20.353 + parentStart <= start); 20.354 + 20.355 + long prevParentStart = parentStart; 20.356 + 20.357 + parentStart = start; 20.358 + 20.359 + long end = trees.getSourcePositions().getEndPosition(cut, node); 20.360 + 20.361 + assertTrue(node.toString() + ":" + end + "/" + parentEnd, 20.362 + end <= parentEnd); 20.363 + 20.364 + long prevParentEnd = parentEnd; 20.365 + 20.366 + parentEnd = end; 20.367 + 20.368 + super.scan(node, p); 20.369 + 20.370 + parentStart = prevParentStart; 20.371 + parentEnd = prevParentEnd; 20.372 + 20.373 + return null; 20.374 + } 20.375 + 20.376 + private void assertTrue(String message, boolean b) { 20.377 + if (!b) fail(message); 20.378 + } 20.379 + }.scan(cut, null); 20.380 + } 20.381 + 20.382 + public void testCorrectWilcardPositions() throws IOException { 20.383 + performWildcardPositionsTest("package test; import java.util.List; " + 20.384 + "class Test { private void method() { List<? extends List<? extends String>> l; } }", 20.385 + 20.386 + Arrays.asList("List<? extends List<? extends String>> l;", 20.387 + "List<? extends List<? extends String>>", 20.388 + "List", 20.389 + "? extends List<? extends String>", 20.390 + "List<? extends String>", 20.391 + "List", 20.392 + "? extends String", 20.393 + "String")); 20.394 + performWildcardPositionsTest("package test; import java.util.List; " + 20.395 + "class Test { private void method() { List<? super List<? super String>> l; } }", 20.396 + 20.397 + Arrays.asList("List<? super List<? super String>> l;", 20.398 + "List<? super List<? super String>>", 20.399 + "List", 20.400 + "? super List<? super String>", 20.401 + "List<? super String>", 20.402 + "List", 20.403 + "? super String", 20.404 + "String")); 20.405 + performWildcardPositionsTest("package test; import java.util.List; " + 20.406 + "class Test { private void method() { List<? super List<?>> l; } }", 20.407 + 20.408 + Arrays.asList("List<? super List<?>> l;", 20.409 + "List<? super List<?>>", 20.410 + "List", 20.411 + "? super List<?>", 20.412 + "List<?>", 20.413 + "List", 20.414 + "?")); 20.415 + performWildcardPositionsTest("package test; import java.util.List; " + 20.416 + "class Test { private void method() { " + 20.417 + "List<? extends List<? extends List<? extends String>>> l; } }", 20.418 + 20.419 + Arrays.asList("List<? extends List<? extends List<? extends String>>> l;", 20.420 + "List<? extends List<? extends List<? extends String>>>", 20.421 + "List", 20.422 + "? extends List<? extends List<? extends String>>", 20.423 + "List<? extends List<? extends String>>", 20.424 + "List", 20.425 + "? extends List<? extends String>", 20.426 + "List<? extends String>", 20.427 + "List", 20.428 + "? extends String", 20.429 + "String")); 20.430 + performWildcardPositionsTest("package test; import java.util.List; " + 20.431 + "class Test { private void method() { " + 20.432 + "List<? extends List<? extends List<? extends String >>> l; } }", 20.433 + Arrays.asList("List<? extends List<? extends List<? extends String >>> l;", 20.434 + "List<? extends List<? extends List<? extends String >>>", 20.435 + "List", 20.436 + "? extends List<? extends List<? extends String >>", 20.437 + "List<? extends List<? extends String >>", 20.438 + "List", 20.439 + "? extends List<? extends String >", 20.440 + "List<? extends String >", 20.441 + "List", 20.442 + "? extends String", 20.443 + "String")); 20.444 + } 20.445 + 20.446 + public void performWildcardPositionsTest(final String code, 20.447 + List<String> golden) throws IOException { 20.448 + 20.449 + final List<Diagnostic<? extends JavaFileObject>> errors = 20.450 + new LinkedList<Diagnostic<? extends JavaFileObject>>(); 20.451 + 20.452 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, 20.453 + new DiagnosticListener<JavaFileObject>() { 20.454 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 20.455 + errors.add(diagnostic); 20.456 + } 20.457 + }, null, null, Arrays.asList(new MyFileObject(code))); 20.458 + 20.459 + final CompilationUnitTree cut = ct.parse().iterator().next(); 20.460 + final List<String> content = new LinkedList<String>(); 20.461 + final Trees trees = Trees.instance(ct); 20.462 + 20.463 + new TreeScanner<Void, Void>() { 20.464 + @Override 20.465 + public Void scan(Tree node, Void p) { 20.466 + if (node == null) { 20.467 + return null; 20.468 + } 20.469 + long start = trees.getSourcePositions().getStartPosition(cut, node); 20.470 + 20.471 + if (start == (-1)) { 20.472 + return null; //synthetic tree 20.473 + } 20.474 + long end = trees.getSourcePositions().getEndPosition(cut, node); 20.475 + String s = code.substring((int) start, (int) end); 20.476 + content.add(s); 20.477 + 20.478 + return super.scan(node, p); 20.479 + } 20.480 + }.scan(((MethodTree) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0)).getBody().getStatements().get(0), null); 20.481 + 20.482 + assertEquals("performWildcardPositionsTest",golden.toString(), 20.483 + content.toString()); 20.484 + } 20.485 + 20.486 + public void testStartPositionForMethodWithoutModifiers() throws IOException { 20.487 + 20.488 + String code = "package t; class Test { <T> void t() {} }"; 20.489 + 20.490 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.491 + null, Arrays.asList(new MyFileObject(code))); 20.492 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.493 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 20.494 + MethodTree mt = (MethodTree) clazz.getMembers().get(0); 20.495 + Trees t = Trees.instance(ct); 20.496 + int start = (int) t.getSourcePositions().getStartPosition(cut, mt); 20.497 + int end = (int) t.getSourcePositions().getEndPosition(cut, mt); 20.498 + 20.499 + assertEquals("testStartPositionForMethodWithoutModifiers", 20.500 + "<T> void t() {}", code.substring(start, end)); 20.501 + } 20.502 + 20.503 + public void testStartPositionEnumConstantInit() throws IOException { 20.504 + 20.505 + String code = "package t; enum Test { AAA; }"; 20.506 + 20.507 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.508 + null, Arrays.asList(new MyFileObject(code))); 20.509 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.510 + ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); 20.511 + VariableTree enumAAA = (VariableTree) clazz.getMembers().get(0); 20.512 + Trees t = Trees.instance(ct); 20.513 + int start = (int) t.getSourcePositions().getStartPosition(cut, 20.514 + enumAAA.getInitializer()); 20.515 + 20.516 + assertEquals("testStartPositionEnumConstantInit", -1, start); 20.517 + } 20.518 + 20.519 + public void testVariableInIfThen1() throws IOException { 20.520 + 20.521 + String code = "package t; class Test { " + 20.522 + "private static void t(String name) { " + 20.523 + "if (name != null) String nn = name.trim(); } }"; 20.524 + 20.525 + DiagnosticCollector<JavaFileObject> coll = 20.526 + new DiagnosticCollector<JavaFileObject>(); 20.527 + 20.528 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 20.529 + null, Arrays.asList(new MyFileObject(code))); 20.530 + 20.531 + ct.parse(); 20.532 + 20.533 + List<String> codes = new LinkedList<String>(); 20.534 + 20.535 + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 20.536 + codes.add(d.getCode()); 20.537 + } 20.538 + 20.539 + assertEquals("testVariableInIfThen1", 20.540 + Arrays.<String>asList("compiler.err.variable.not.allowed"), 20.541 + codes); 20.542 + } 20.543 + 20.544 + public void testVariableInIfThen2() throws IOException { 20.545 + 20.546 + String code = "package t; class Test { " + 20.547 + "private static void t(String name) { " + 20.548 + "if (name != null) class X {} } }"; 20.549 + DiagnosticCollector<JavaFileObject> coll = 20.550 + new DiagnosticCollector<JavaFileObject>(); 20.551 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 20.552 + null, Arrays.asList(new MyFileObject(code))); 20.553 + 20.554 + ct.parse(); 20.555 + 20.556 + List<String> codes = new LinkedList<String>(); 20.557 + 20.558 + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 20.559 + codes.add(d.getCode()); 20.560 + } 20.561 + 20.562 + assertEquals("testVariableInIfThen2", 20.563 + Arrays.<String>asList("compiler.err.class.not.allowed"), codes); 20.564 + } 20.565 + 20.566 + public void testVariableInIfThen3() throws IOException { 20.567 + 20.568 + String code = "package t; class Test { "+ 20.569 + "private static void t(String name) { " + 20.570 + "if (name != null) abstract } }"; 20.571 + DiagnosticCollector<JavaFileObject> coll = 20.572 + new DiagnosticCollector<JavaFileObject>(); 20.573 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, coll, null, 20.574 + null, Arrays.asList(new MyFileObject(code))); 20.575 + 20.576 + ct.parse(); 20.577 + 20.578 + List<String> codes = new LinkedList<String>(); 20.579 + 20.580 + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { 20.581 + codes.add(d.getCode()); 20.582 + } 20.583 + 20.584 + assertEquals("testVariableInIfThen3", 20.585 + Arrays.<String>asList("compiler.err.illegal.start.of.expr"), 20.586 + codes); 20.587 + } 20.588 + 20.589 + //see javac bug #6882235, NB bug #98234: 20.590 + public void testMissingExponent() throws IOException { 20.591 + 20.592 + String code = "\nclass Test { { System.err.println(0e); } }"; 20.593 + 20.594 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.595 + null, Arrays.asList(new MyFileObject(code))); 20.596 + 20.597 + assertNotNull(ct.parse().iterator().next()); 20.598 + } 20.599 + 20.600 + public void testTryResourcePos() throws IOException { 20.601 + 20.602 + final String code = "package t; class Test { " + 20.603 + "{ try (java.io.InputStream in = null) { } } }"; 20.604 + 20.605 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.606 + null, Arrays.asList(new MyFileObject(code))); 20.607 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.608 + 20.609 + new TreeScanner<Void, Void>() { 20.610 + @Override 20.611 + public Void visitVariable(VariableTree node, Void p) { 20.612 + if ("in".contentEquals(node.getName())) { 20.613 + JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; 20.614 + System.out.println(node.getName() + "," + var.pos); 20.615 + assertEquals("testTryResourcePos", "in = null) { } } }", 20.616 + code.substring(var.pos)); 20.617 + } 20.618 + return super.visitVariable(node, p); 20.619 + } 20.620 + }.scan(cut, null); 20.621 + } 20.622 + 20.623 + public void testVarPos() throws IOException { 20.624 + 20.625 + final String code = "package t; class Test { " + 20.626 + "{ java.io.InputStream in = null; } }"; 20.627 + 20.628 + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null, 20.629 + null, Arrays.asList(new MyFileObject(code))); 20.630 + CompilationUnitTree cut = ct.parse().iterator().next(); 20.631 + 20.632 + new TreeScanner<Void, Void>() { 20.633 + 20.634 + @Override 20.635 + public Void visitVariable(VariableTree node, Void p) { 20.636 + if ("in".contentEquals(node.getName())) { 20.637 + JCTree.JCVariableDecl var = (JCTree.JCVariableDecl) node; 20.638 + assertEquals("testVarPos","in = null; } }", 20.639 + code.substring(var.pos)); 20.640 + } 20.641 + return super.visitVariable(node, p); 20.642 + } 20.643 + }.scan(cut, null); 20.644 + } 20.645 + 20.646 + void testsNotWorking() throws IOException { 20.647 + 20.648 + // Fails with nb-javac, needs further investigation 20.649 + testPositionBrokenSource126732a(); 20.650 + testPositionBrokenSource126732b(); 20.651 + 20.652 + // Fails, these tests yet to be addressed 20.653 + testVariableInIfThen1(); 20.654 + testVariableInIfThen2(); 20.655 + testPositionForEnumModifiers(); 20.656 + testStartPositionEnumConstantInit(); 20.657 + } 20.658 + void testPositions() throws IOException { 20.659 + testPositionsSane(); 20.660 + testCorrectWilcardPositions(); 20.661 + testPositionAnnotationNoPackage187551(); 20.662 + testPositionForSuperConstructorCalls(); 20.663 + testPreferredPositionForBinaryOp(); 20.664 + testStartPositionForMethodWithoutModifiers(); 20.665 + testVarPos(); 20.666 + testVariableInIfThen3(); 20.667 + testTryResourcePos(); 20.668 + } 20.669 + 20.670 + public static void main(String... args) throws IOException { 20.671 + JavacParserTest jpt = new JavacParserTest("JavacParserTest"); 20.672 + jpt.testPositions(); 20.673 + System.out.println("PASS"); 20.674 + } 20.675 +} 20.676 + 20.677 +abstract class TestCase { 20.678 + 20.679 + void assertEquals(String message, int i, int pos) { 20.680 + if (i != pos) { 20.681 + fail(message); 20.682 + } 20.683 + } 20.684 + 20.685 + void assertFalse(String message, boolean empty) { 20.686 + throw new UnsupportedOperationException("Not yet implemented"); 20.687 + } 20.688 + 20.689 + void assertEquals(String message, int i, long l) { 20.690 + if (i != l) { 20.691 + fail(message + ":" + i + ":" + l); 20.692 + } 20.693 + } 20.694 + 20.695 + void assertEquals(String message, Object o1, Object o2) { 20.696 + System.out.println(o1); 20.697 + System.out.println(o2); 20.698 + if (o1 != null && o2 != null && !o1.equals(o2)) { 20.699 + fail(message); 20.700 + } 20.701 + if (o1 == null && o2 != null) { 20.702 + fail(message); 20.703 + } 20.704 + } 20.705 + 20.706 + void assertNotNull(Object o) { 20.707 + if (o == null) { 20.708 + fail(); 20.709 + } 20.710 + } 20.711 + 20.712 + void fail() { 20.713 + fail("test failed"); 20.714 + } 20.715 + 20.716 + void fail(String message) { 20.717 + throw new RuntimeException(message); 20.718 + } 20.719 +}