src/share/classes/com/sun/tools/javac/parser/JavacParser.java

Print this page

        

*** 1162,1193 **** t = creator(pos, typeArgs); typeArgs = null; } else return illegal(); break; case MONKEYS_AT: ! // Only annotated cast types are valid List<JCAnnotation> typeAnnos = typeAnnotationsOpt(); if (typeAnnos.isEmpty()) { // else there would be no '@' throw new AssertionError("Expected type annotations, but found none!"); } JCExpression expr = term3(); if ((mode & TYPE) == 0) { // Type annotations on class literals no longer legal ! if (!expr.hasTag(Tag.SELECT)) { ! return illegal(typeAnnos.head.pos); } ! JCFieldAccess sel = (JCFieldAccess)expr; if (sel.name != names._class) { return illegal(); } else { log.error(token.pos, "no.annotations.on.dot.class"); return expr; } } else { // Type annotations targeting a cast t = insertAnnotationsToMostInner(expr, typeAnnos, false); } break; --- 1162,1203 ---- t = creator(pos, typeArgs); typeArgs = null; } else return illegal(); break; case MONKEYS_AT: ! // Only annotated cast types and method references are valid List<JCAnnotation> typeAnnos = typeAnnotationsOpt(); if (typeAnnos.isEmpty()) { // else there would be no '@' throw new AssertionError("Expected type annotations, but found none!"); } JCExpression expr = term3(); if ((mode & TYPE) == 0) { // Type annotations on class literals no longer legal ! switch (expr.getTag()) { ! case REFERENCE: { ! JCMemberReference mref = (JCMemberReference) expr; ! mref.expr = toP(F.at(pos).AnnotatedType(typeAnnos, mref.expr)); ! t = mref; ! break; } ! case SELECT: { ! JCFieldAccess sel = (JCFieldAccess) expr; if (sel.name != names._class) { return illegal(); } else { log.error(token.pos, "no.annotations.on.dot.class"); return expr; } + } + default: + return illegal(typeAnnos.head.pos); + } + } else { // Type annotations targeting a cast t = insertAnnotationsToMostInner(expr, typeAnnos, false); } break;
*** 1455,1476 **** } /** * If we see an identifier followed by a '&lt;' it could be an unbound * method reference or a binary expression. To disambiguate, look for a ! * matching '&gt;' and see if the subsequent terminal is either '.' or '#'. */ @SuppressWarnings("fallthrough") boolean isUnboundMemberRef() { int pos = 0, depth = 0; ! for (Token t = S.token(pos) ; ; t = S.token(++pos)) { switch (t.kind) { case IDENTIFIER: case UNDERSCORE: case QUES: case EXTENDS: case SUPER: case DOT: case RBRACKET: case LBRACKET: case COMMA: case BYTE: case SHORT: case INT: case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case CHAR: break; case LT: depth++; break; case GTGTGT: depth--; case GTGT: --- 1465,1508 ---- } /** * If we see an identifier followed by a '&lt;' it could be an unbound * method reference or a binary expression. To disambiguate, look for a ! * matching '&gt;' and see if the subsequent terminal is either '.' or '::'. */ @SuppressWarnings("fallthrough") boolean isUnboundMemberRef() { int pos = 0, depth = 0; ! outer: for (Token t = S.token(pos) ; ; t = S.token(++pos)) { switch (t.kind) { case IDENTIFIER: case UNDERSCORE: case QUES: case EXTENDS: case SUPER: case DOT: case RBRACKET: case LBRACKET: case COMMA: case BYTE: case SHORT: case INT: case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case CHAR: + case MONKEYS_AT: + break; + + case LPAREN: + // skip annotation values + int nesting = 0; + for (; ; pos++) { + TokenKind tk2 = S.token(pos).kind; + switch (tk2) { + case EOF: + return false; + case LPAREN: + nesting++; break; + case RPAREN: + nesting--; + if (nesting == 0) { + continue outer; + } + break; + } + } + case LT: depth++; break; case GTGTGT: depth--; case GTGT:
*** 1492,1502 **** } /** * If we see an identifier followed by a '&lt;' it could be an unbound * method reference or a binary expression. To disambiguate, look for a ! * matching '&gt;' and see if the subsequent terminal is either '.' or '#'. */ @SuppressWarnings("fallthrough") ParensResult analyzeParens() { int depth = 0; boolean type = false; --- 1524,1534 ---- } /** * If we see an identifier followed by a '&lt;' it could be an unbound * method reference or a binary expression. To disambiguate, look for a ! * matching '&gt;' and see if the subsequent terminal is either '.' or '::'. */ @SuppressWarnings("fallthrough") ParensResult analyzeParens() { int depth = 0; boolean type = false;