Community
Participate
Working Groups
abstract class Test2 { abstract void m0(Test2 this, int i); void m1(int i, Test2 this) { } static void m2(Test2 this, int i) { } Function<String, String> f1= (String s, Function this) -> s; Function<String, String> f2= (Function this, String s) -> s; } Here, 'this' parameter info is present as given below: - In #m0: present in RECEIVER_TYPE_PROPERTY, not present in parameters list. - In #m1: not present in RECEIVER_TYPE_PROPERTY, present in parameters list. - In #m2: not present in RECEIVER_TYPE_PROPERTY, not present in parameters list. - In f1 and f2: present in parameters list of LambdaExpression. Cases for #m0 and f1/f2 are fine. Case for #m1 also seems Ok? In case of #m2, 'this' parameter info is not present anywhere in the AST, which is wrong. When 'this' parameter is added at an incorrect location, it should be present at a consistent place somewhere in the AST.
Jay, thanks for following up.
When the 'this' parameter is in a grammatically illegal position (in lambda's parameter list, or not the first parameter in a method declaration), then recovery is nice but not absolutely necessary. The critical example is the static method m2, where the source conforms to the Java 8 grammar. In this case, the AST should contain the receiverType, so that we can e.g. offer a quick fix that removes the 'static' modifier or the receiver parameter.
So, just to confirm that I got the requirement right - we only need to address the case of method m2, where the (disallowed) receiver appears as the first parameter, right? So, if the receiver appears in the AST as RECEIVER_TYPE and the MethodDeclaration node is set as MALFORMED, is it okay?
Created attachment 239656 [details] Fix + Test Patch simply gets rid of the code that sets the AbstractMethodDeclaration#receiver to null when it's the first formal parameter in all cases except in a lambda expression. And I haven't bothered to set the nodes to malformed. Hope this is fine. In other words: In Lambda: 1. The receiver parameter would be part of PARAMETERS regardless of where it occurs (1st parameter or otherwise) All other places: 1. If it's first parameter, it's exposed via RECEIVER_TYPE property. 2. Otherwise, it's part of PARAMETERS property
Fix and tests available here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=aa70d91abcd9d16b058d62bcd2e8b6cfb7fb819c (Jay, by mistake I released this in my name, sorry)
test427357 in ASTConverter18Test.java passed with the code imported from SR2. File -> import -> plugi development -> plugin & fragments -> next -> the active target platform -> import as projects with src folder I could not figure out a way to open up AST view with BETA_JAVA8 bundles for AST. The wiki page only specifies till 3.7.1 (http://www.eclipse.org/jdt/ui/astview/).
Verified as working for Eclipse + Java 8 RC1 Eclipse Kepler 4.3.2(RC4) Build id: M20140212-0800 + Eclipse Java Development Tools Patch for Java 8 Support (BETA) 1.0.0.v20140220-2054.
(In reply to shankha banerjee from comment #6) > I could not figure out a way to open up AST view with BETA_JAVA8 bundles for > AST. We usually only produce an official ASTView version after the next jdt.core release is done. But to just see the ASTNode structure, you can also use an older version of the ASTView plug-in. The trick to get a JLS8 AST is to select "Use SharedASTProvider.getAST" from the view menu. If you need the latest version of the ASTView, you need to check it out from the eclipse.jdt.ui repo and then either use it in a runtime workbench, or export the plug-in into your Eclipse install (File > Export... > Deployable Plug-ins... > Destination: Install into host). (In reply to Jayaprakash Arthanareeswaran from comment #4) > And I haven't bothered > to set the nodes to malformed. Hope this is fine. Yes, for a receiver parameter in a static/abstract method, that's fine (since that's not a syntax error). But if the 'this' appears as name of a method parameter, then we should mark the name as malformed. Fixed that with http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=0f16652d495864a2012fd0fc0ed568e6ea4bc1e1