This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 239256 - Add parameter to a Lambda should follow syntax
Summary: Add parameter to a Lambda should follow syntax
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 8.0
Hardware: PC Linux
: P2 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks: 238836
  Show dependency tree
 
Reported: 2013-12-09 08:50 UTC by Ralph Ruijs
Modified: 2013-12-12 02:59 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ralph Ruijs 2013-12-09 08:50:26 UTC
When changing the parameters of a lambda expression the Type of the variable should not be printed if this was not the case in the original expression.

The tests in LambdaTest.java specify null if the type should not be printed, but if a type should be printed can not be retrieved from the LambdaExpressionTree.


Test:
    public void testAddSecondLambdaParamWithType() throws Exception {
        testFile = new File(getWorkDir(), "Test.java");
        TestUtilities.copyStringToFile(testFile, 
            "package hierbas.del.litoral;\n\n" +
            "public class Test {\n" +
            "    public static void taragui() {\n" +
            "        ChangeListener l = (e) -> {};\n" + 
            "    }\n" +
            "}\n"
            );
        String golden =
            "package hierbas.del.litoral;\n\n" +
            "public class Test {\n" +
            "    public static void taragui() {\n" +
            "        ChangeListener l = (e, f) -> {};\n" + 
            "    }\n" +
            "}\n";
        JavaSource src = getJavaSource(testFile);
        
        Task<WorkingCopy> task = new Task<WorkingCopy>() {

            public void run(final WorkingCopy workingCopy) throws IOException {
                workingCopy.toPhase(Phase.RESOLVED);
                final TreeMaker make = workingCopy.getTreeMaker();
                new TreeScanner<Void, Void>() {
                    @Override public Void visitLambdaExpression(LambdaExpressionTree node, Void p) {
                        VariableTree vt = node.getParameters().get(0);
                        workingCopy.rewrite(node, make.addLambdaParameter(node, make.Variable(vt.getModifiers(), "f", vt.getType(), vt.getInitializer())));
                        return super.visitLambdaExpression(node, p);
                    }
                }.scan(workingCopy.getCompilationUnit(), null);
            }

        };
        src.runModificationTask(task).commit();
        String res = TestUtilities.copyFileToString(testFile);
        System.err.println(res);
        assertEquals(golden, res);
    }
Comment 1 Svata Dedic 2013-12-10 08:31:56 UTC
Note that when working with Lambdas, one has to detect whether the parameters are implicit or explicit; isSynthetic(paramDef.getType()) should return true for implicit typing. Checks for paramDef.getType() == null are not sufficient as the implied type is computed during attribTree and stored in the tree.

Fixed in jet-main#a99aff87d658
Comment 2 Quality Engineering 2013-12-12 02:59:28 UTC
Integrated into 'main-silver', will be available in build *201312120002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/1a9855d0bae4
User: Svata Dedic <sdedic@netbeans.org>
Log: #239256: added support for implicit parameter manipulations