changeset 53709:199d0206bef5 datum

changes to JavacParser to streamline merges
author vromero
date Thu, 29 Nov 2018 11:38:47 -0500
parents 7a36d214ae9d
children c282a08448a4 b252a2418004
files src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java
diffstat 1 files changed, 76 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Nov 29 11:12:01 2018 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Nov 29 11:38:47 2018 -0500
@@ -3934,7 +3934,71 @@
                 }
                 return List.of(block(pos, mods.flags));
             } else {
-                return methodOrFieldMemberDecl(className, mods, isInterface, dc, false);
+                pos = token.pos;
+                List<JCTypeParameter> typarams = typeParametersOpt();
+                // if there are type parameters but no modifiers, save the start
+                // position of the method in the modifiers.
+                if (typarams.nonEmpty() && mods.pos == Position.NOPOS) {
+                    mods.pos = pos;
+                    storeEnd(mods, pos);
+                }
+                List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION);
+
+                if (annosAfterParams.nonEmpty()) {
+                    checkSourceLevel(annosAfterParams.head.pos, Feature.ANNOTATIONS_AFTER_TYPE_PARAMS);
+                    mods.annotations = mods.annotations.appendList(annosAfterParams);
+                    if (mods.pos == Position.NOPOS)
+                        mods.pos = mods.annotations.head.pos;
+                }
+
+                Token tk = token;
+                pos = token.pos;
+                JCExpression type;
+                boolean isVoid = token.kind == VOID;
+                if (isVoid) {
+                    type = to(F.at(pos).TypeIdent(TypeTag.VOID));
+                    nextToken();
+                } else {
+                    // method returns types are un-annotated types
+                    type = unannotatedType(false);
+                }
+                if (token.kind == LPAREN && !isInterface && type.hasTag(IDENT)) {
+                    if (isInterface || tk.name() != className)
+                        log.error(DiagnosticFlag.SYNTAX, pos, Errors.InvalidMethDeclRetTypeReq);
+                    else if (annosAfterParams.nonEmpty())
+                        illegal(annosAfterParams.head.pos);
+                    return List.of(methodDeclaratorRest(
+                        pos, mods, null, names.init, typarams,
+                        isInterface, true, false, dc));
+                } else {
+                    pos = token.pos;
+                    Name name = ident();
+                    if (token.kind == LPAREN) {
+                        return List.of(methodDeclaratorRest(
+                            pos, mods, type, name, typarams,
+                            isInterface, isVoid, false, dc));
+                    } else if (!isVoid && typarams.isEmpty()) {
+                        List<JCTree> defs =
+                            variableDeclaratorsRest(pos, mods, type, name, isInterface, dc,
+                                                    new ListBuffer<JCTree>(), false).toList();
+                        accept(SEMI);
+                        storeEnd(defs.last(), S.prevToken().endPos);
+                        return defs;
+                    } else {
+                        pos = token.pos;
+                        List<JCTree> err;
+                        if (isVoid || typarams.nonEmpty()) {
+                            JCMethodDecl m =
+                                    toP(F.at(pos).MethodDef(mods, name, type, typarams,
+                                                            List.nil(), List.nil(), null, null));
+                            attach(m, dc);
+                            err = List.of(m);
+                        } else {
+                            err = List.nil();
+                        }
+                        return List.of(syntaxError(token.pos, err, Errors.Expected(LPAREN)));
+                    }
+                }
             }
         }
     }
@@ -3945,7 +4009,13 @@
                 peekToken(TokenKind.IDENTIFIER, TokenKind.LT));
     }
 
-    private List<JCTree> methodOrFieldMemberDecl(Name className, JCModifiers mods, boolean isInterface, Comment dc, boolean isRecord) {
+    protected List<JCTree> recordBodyDeclaration(Name className) {
+        Comment dc = token.comment(CommentStyle.JAVADOC);
+        JCModifiers mods = modifiersOpt();
+        return methodOrFieldMemberDecl(className, mods, false, dc);
+    }
+
+    private List<JCTree> methodOrFieldMemberDecl(Name className, JCModifiers mods, boolean isInterface, Comment dc) {
         int pos = token.pos;
         List<JCTypeParameter> typarams = typeParametersOpt();
         // if there are type parameters but no modifiers, save the start
@@ -3975,23 +4045,23 @@
             type = unannotatedType(false);
         }
         if ((token.kind == LPAREN && !isInterface ||
-                isRecord && token.kind == LBRACE) && type.hasTag(IDENT)) {
+                token.kind == LBRACE) && type.hasTag(IDENT)) {
             if (isInterface || tk.name() != className)
                 log.error(pos, Errors.InvalidMethDeclRetTypeReq);
             else if (annosAfterParams.nonEmpty())
                 illegal(annosAfterParams.head.pos);
             return List.of(methodDeclaratorRest(
                 pos, mods, null, names.init, typarams,
-                isInterface, true, isRecord, dc));
+                isInterface, true, true, dc));
         } else {
             pos = token.pos;
             Name name = ident();
             if (token.kind == LPAREN) {
                 return List.of(methodDeclaratorRest(
                     pos, mods, type, name, typarams,
-                    isInterface, isVoid, isRecord, dc));
+                    isInterface, isVoid, true, dc));
             } else if (!isVoid && typarams.isEmpty()) {
-                if (!isRecord || isRecord && (mods.flags & Flags.STATIC) != 0) {
+                if ((mods.flags & Flags.STATIC) != 0) {
                     List<JCTree> defs =
                         variableDeclaratorsRest(pos, mods, type, name, isInterface, dc,
                                                 new ListBuffer<JCTree>(), false).toList();
@@ -4014,13 +4084,6 @@
             }
         }
     }
-
-    protected List<JCTree> recordBodyDeclaration(Name className) {
-        Comment dc = token.comment(CommentStyle.JAVADOC);
-        JCModifiers mods = modifiersOpt();
-        return methodOrFieldMemberDecl(className, mods, false, dc, true);
-    }
-
     /** MethodDeclaratorRest =
      *      FormalParameters BracketsOpt [THROWS TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";")
      *  VoidMethodDeclaratorRest =