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.

View | Details | Raw Unified | Return to bug 199080
Collapse All | Expand All

(-)a/java.source/apichanges.xml (+13 lines)
Lines 108-113 Link Here
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
109
109
110
    <changes>
110
    <changes>
111
        <change id="TreeUtilities.findMethodParameterSpan">
112
             <api name="general"/>
113
             <summary>Find span of the MethodTree#getParameters() parameter list in the source.</summary>
114
             <version major="0" minor="81"/>
115
             <date day="1" month="6" year="2011"/>
116
             <author login="ralphbenjamin"/>
117
             <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
118
             <description>
119
                 <code>TreeUtilities</code> has a new <code>findMethodParameterSpan(MethodTree method)</code> method.
120
             </description>
121
             <class package="org.netbeans.api.java.source" name="TreeUtilities"/>
122
             <issue number="199080"/>
123
        </change>
111
        <change id="TreePathHandle-from-ElementHandle">
124
        <change id="TreePathHandle-from-ElementHandle">
112
             <api name="general"/>
125
             <api name="general"/>
113
             <summary>TreePathHandle can be created from ElementHandle</summary>
126
             <summary>TreePathHandle can be created from ElementHandle</summary>
(-)a/java.source/nbproject/project.properties (-1 / +1 lines)
Lines 46-52 Link Here
46
javadoc.title=Java Source
46
javadoc.title=Java Source
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
49
spec.version.base=0.80.0
49
spec.version.base=0.81.0
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source/src/org/netbeans/api/java/source/TreeUtilities.java (+44 lines)
Lines 644-649 Link Here
644
        return findNameSpan(var.getName().toString(), var);
644
        return findNameSpan(var.getName().toString(), var);
645
    }
645
    }
646
    
646
    
647
    /**Find span of the {@link MethodTree#getParameters()} parameter list in the source.
648
     * Returns the position of the opening and closing parentheses of the parameter list
649
     * in the source code that was parsed (ie. {@link CompilationInfo.getText()}, which
650
     * may differ from the positions in the source document if it has been already altered.
651
     * 
652
     * @param method method which parameter list should be searched for
653
     * @return the span of the parameter list, or null if cannot be found
654
     * @since 0.81
655
     */
656
    public int[] findMethodParameterSpan(MethodTree method) {
657
        JCTree jcTree = (JCTree) method;
658
        int pos = jcTree.pos;
659
        
660
        if (pos < 0)
661
            return null;
662
        
663
        TokenSequence<JavaTokenId> tokenSequence = info.getTokenHierarchy().tokenSequence(JavaTokenId.language());
664
        tokenSequence.move(pos);
665
        
666
        int startPos = -1;
667
        int endPos = -1;
668
        while(tokenSequence.moveNext()) {
669
            if(tokenSequence.token().id() == JavaTokenId.LPAREN) {
670
                startPos = tokenSequence.offset();
671
            }
672
            if(tokenSequence.token().id() == JavaTokenId.RPAREN) {
673
                endPos = tokenSequence.offset();
674
                break;
675
            }
676
            if(tokenSequence.token().id() == JavaTokenId.LBRACE) {
677
                return null;
678
            }
679
        }
680
        
681
        if(startPos == -1 || endPos == -1) {
682
            return null;
683
        }
684
        
685
        return new int[] {
686
            startPos,
687
            endPos
688
        };
689
    }
690
    
647
    /**Find span of the {@link MemberSelectTree#getIdentifier()} identifier in the source.
691
    /**Find span of the {@link MemberSelectTree#getIdentifier()} identifier in the source.
648
     * Returns starting and ending offset of the name in the source code that was parsed
692
     * Returns starting and ending offset of the name in the source code that was parsed
649
     * (ie. {@link CompilationInfo.getText()}, which may differ from the positions in the source
693
     * (ie. {@link CompilationInfo.getText()}, which may differ from the positions in the source
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java (+22 lines)
Lines 307-312 Link Here
307
        assertNull(span);
307
        assertNull(span);
308
    }
308
    }
309
    
309
    
310
    public void testFindMethodParameterSpan1() throws Exception {
311
        prepareTest("Test", "package test; public class Test {public void test() {}}");
312
        
313
        TreePath tp = info.getTreeUtilities().pathFor(77 - 30);
314
        MethodTree ct = (MethodTree) tp.getLeaf();
315
        
316
        int[] span = info.getTreeUtilities().findMethodParameterSpan(ct);
317
        
318
        assertTrue(Arrays.toString(span), Arrays.equals(span, new int[] {79 - 30, 80 - 30}));
319
    }
320
    
321
    public void testFindMethodParameterSpan2() throws Exception {
322
        prepareTest("Test", "package test; public class Test {public void test(String name) {}}");
323
        
324
        TreePath tp = info.getTreeUtilities().pathFor(77 - 30);
325
        MethodTree ct = (MethodTree) tp.getLeaf();
326
        
327
        int[] span = info.getTreeUtilities().findMethodParameterSpan(ct);
328
        
329
        assertTrue(Arrays.toString(span), Arrays.equals(span, new int[] {79 - 30, 91 - 30}));
330
    }
331
    
310
    public void testTreePath124760a() throws Exception {
332
    public void testTreePath124760a() throws Exception {
311
        prepareTest("Test", "package test; public class Test {public Test(int iii[]){}}");
333
        prepareTest("Test", "package test; public class Test {public Test(int iii[]){}}");
312
        
334
        

Return to bug 199080