Bug 427357 - [1.8][dom ast] 'this' parameter unavailable in AST for static method declaration
Summary: [1.8][dom ast] 'this' parameter unavailable in AST for static method declaration
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 426988
  Show dependency tree
 
Reported: 2014-02-04 07:05 EST by Noopur Gupta CLA
Modified: 2014-02-21 09:08 EST (History)
4 users (show)

See Also:
srikanth_sankaran: review+


Attachments
Fix + Test (4.02 KB, patch)
2014-02-05 07:02 EST, Jay Arthanareeswaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Noopur Gupta CLA 2014-02-04 07:05:28 EST
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.
Comment 1 Srikanth Sankaran CLA 2014-02-04 07:39:48 EST
Jay, thanks for following up.
Comment 2 Markus Keller CLA 2014-02-04 13:15:10 EST
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.
Comment 3 Jay Arthanareeswaran CLA 2014-02-05 03:50:39 EST
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?
Comment 4 Jay Arthanareeswaran CLA 2014-02-05 07:02:48 EST
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
Comment 5 Srikanth Sankaran CLA 2014-02-06 05:58:34 EST
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)
Comment 6 shankha banerjee CLA 2014-02-21 07:46:52 EST
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/).
Comment 7 shankha banerjee CLA 2014-02-21 07:47:14 EST
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.
Comment 8 Markus Keller CLA 2014-02-21 09:08:51 EST
(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