Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 439637

Summary: [1.8][clean up][quick assist] Convert lambda to anonymous must qualify implicit references to 'this'
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jerome.cambon, noopur_gupta
Version: 4.5   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Markus Keller CLA 2014-07-15 12:02:44 EDT
Follow-up to bug 430573. Convert lambda to anonymous must also qualify implicit references to 'this' in method invocations or field references iff the same names are also declared in the functional interface (or in a superinterface, see the "comb rule" in JLS8 15.12.1).

package p;

import java.util.function.*;

public class A {
    public static final int CONST = -1;
    A() {
        IntSupplier i = () -> getAsInt();
        
        Predicate<String> p = s -> test(s);
        Predicate<String> p2 = s -> or(true, false);
        Fooable f = () -> CONST;
    }
    
    public int getAsInt() {
        return 7;
    }
    
    boolean test(String s) {
        return s.length() == 7;
    }
    
    public boolean or(boolean a, boolean b) {
        return a || b;
    }
}

@FunctionalInterface
interface Fooable {
    int CONST = 42;
    int foo();
}

We should only qualify references if there's a name conflict. org.eclipse.jdt.internal.corext.fix.CodeStyleFix probably has some helpful implementation hints in CodeStyleVisitor and ThisQualifierVisitor#hasConflict(..).
Comment 1 Noopur Gupta CLA 2015-04-17 04:50:07 EDT
*** Bug 433823 has been marked as a duplicate of this bug. ***
Comment 2 Eclipse Genie CLA 2020-04-25 18:26:28 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.