Community
Participate
Working Groups
We have the following problem ids in org.eclipse.jdt.core.compiler.IProblem for the cases where the explicit 'this' parameter is present at incorrect locations: IllegalDeclarationOfThisParameter ExplicitThisParameterNotBelow18 DisallowedExplicitThisParameter ExplicitThisParameterNotInLambda We can provide a quick fix "Remove explicit 'this' parameter" which will remove the 'this' parameter (along with its type use annotations, if any). Example: Hover over 'this' at different locations in the following code to view the error: ---------------------------------------------- package com.test.todo; import java.util.function.Function; public class Test { void m1(int i, Test this) { } static void m2(Test this) { } Runnable r= new Runnable() { public void run(Runnable this) { } }; Function<String, String> f= (Function this, String s) -> s; } ----------------------------------------------
The quick fix can also be used as a quick assist to remove the explicit 'this' parameter if required.
For the cases where the invalid (to be removed) 'this' parameter is present in a method (not lambda expr), it should be present in either the parameters list of MethodDeclaration or its type should be set in the MethodDeclaration.RECEIVER_TYPE_PROPERTY. Only then it can be removed from the AST. If it is not present anywhere in the AST then how can it be removed (see case #m2 below)? Consider the following example: 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 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. For #m2, since it is not a valid receiver parameter, probably it should be present only in parameters list (as in #m1) and not set in RECEIVER_TYPE_PROPERTY. Markus, please share your thoughts on: 1. Is the new quick fix required? 2. AST for 'this' in case of #m2. 3. Where to check the value of IMethodBinding.getDeclaredReceiverType() in AST view?