changeset 2335:e717501c1f77

Use JCReceiverVariableDecl to support receiver parameters in nested constructors.
author wmdietl
date Wed, 20 Mar 2013 14:59:34 +0100
parents 56a016f19c7d
children 35fca9f10e60
files src/share/classes/com/sun/tools/javac/parser/JavacParser.java
diffstat 1 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Wed Mar 20 14:58:51 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Wed Mar 20 14:59:34 2013 +0100
@@ -262,7 +262,7 @@
 
     /** The type of the method receiver, as specified by a first "this" parameter.
      */
-    JCVariableDecl receiverParam;
+    JCReceiverVariableDecl receiverParam;
 
 
     /** When terms are parsed, the mode determines which is expected:
@@ -2997,7 +2997,22 @@
             syntaxError(pos, "expected", IDENTIFIER);
             name = token.name();
         } else {
-            name = ident();
+            if (allowThisIdent) {
+                JCExpression pn = qualident(false);
+                if (pn.hasTag(Tag.IDENT) && !((JCIdent)pn).name.contentEquals(TokenKind.THIS.name)) {
+                    name = ((JCIdent)pn).name;
+                } else {
+                    if ((mods.flags & Flags.VARARGS) != 0) {
+                        log.error(token.pos, "varargs.and.receiver");
+                    }
+                    if (token.kind == LBRACKET) {
+                        log.error(token.pos, "array.and.receiver");
+                    }
+                    return toP(F.at(pos).ReceiverVarDef(mods, pn, type));
+                }
+            } else {
+                name = ident();
+            }
         }
         if ((mods.flags & Flags.VARARGS) != 0 &&
                 token.kind == LBRACKET) {
@@ -3485,7 +3500,7 @@
         if (isInterface && (mods.flags & Flags.STATIC) != 0) {
             checkStaticInterfaceMethods();
         }
-        JCVariableDecl prevReceiverParam = this.receiverParam;
+        JCReceiverVariableDecl prevReceiverParam = this.receiverParam;
         try {
             this.receiverParam = null;
             // Parsing formalParameters sets the receiverParam, if present
@@ -3610,8 +3625,8 @@
         if (token.kind != RPAREN) {
             this.allowThisIdent = true;
             lastParam = formalParameter(lambdaParameters);
-            if (lastParam.name.contentEquals(TokenKind.THIS.name)) {
-                this.receiverParam = lastParam;
+            if (lastParam instanceof JCReceiverVariableDecl) {
+                this.receiverParam = (JCReceiverVariableDecl) lastParam;
             } else {
                 params.append(lastParam);
             }