Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when comparing CtParameterReference objects of lambdas #733

Closed
arnobl opened this issue Jun 30, 2016 · 1 comment
Closed

Problem when comparing CtParameterReference objects of lambdas #733

arnobl opened this issue Jun 30, 2016 · 1 comment

Comments

@arnobl
Copy link
Contributor

arnobl commented Jun 30, 2016

Sorry guys but I have another problem using spoon-core-5.2.0-20160629.235159-96.jar. The problem was not here using spoon-core-5.2.0-20160626.235126-95.jar.

This time I can reproduce the problem using this test case:

    @Test
    public void testSpoon() {
        final spoon.Launcher launcher = new spoon.Launcher();
        launcher.addInputResource("src/test/resources/java/widgetsIdentification/LambdaOnFieldWidgetsEqualCond.java");
        launcher.getEnvironment().setNoClasspath(true);
        launcher.getEnvironment().setComplianceLevel(8);
        launcher.buildModel();

        launcher.getModel().getElements(new TypeFilter<CtExecutable<?>>(CtExecutable.class) {
            @Override
            public boolean matches(CtExecutable<?> exec) {
                final List<CtParameterReference<?>> guiParams = exec.getParameters().stream().map(param -> param.getReference()).collect(Collectors.toList());

                if(guiParams.size()!=1) return false;

                final CtParameterReference<?> param = guiParams.get(0);

                exec.getBody().getElements(new TypeFilter<CtParameterReference<?>>(CtParameterReference.class) {
                    @Override
                    public boolean matches(CtParameterReference<?> p) {
                        assertEquals(p, param);
                        return super.matches(p);
                    }
                });

                return super.matches(exec);
            }
        });
    }

The tested code is:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

class Foo {
    final JButton b = new JButton();
    final JButton a = new JButton();
    public Foo() {
        b.addActionListener(e -> {
                if(e.getSource()==a) {
                    System.out.println(((JButton) e.getSource()).getName()); // Command 1
                }
        });
    }
}

The problem seems to come from:

    public <T> void visitCtParameterReference(CtParameterReference<T> reference) {
...
        this.biScan(reference.getDeclaringExecutable(), other.getDeclaringExecutable());
...
    }

in the EqualsVisitor class.

Maybe a problem when cloning lambda references?

The test passes using spoon-core-5.2.0-20160626.235126-95 but not using spoon-core-5.2.0-20160629.235159-96.jar.

@GerardPaligot
Copy link
Contributor

Thanks for the report. PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants