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 212829
Collapse All | Expand All

(-)a/groovy.support/nbproject/project.properties (-1 / +1 lines)
Lines 36-42 Link Here
36
#
36
#
37
# Contributor(s):
37
# Contributor(s):
38
javac.compilerargs=-Xlint -Xlint:-serial
38
javac.compilerargs=-Xlint -Xlint:-serial
39
javac.source=1.6
39
javac.source=1.8
40
cp.extra=${tools.jar}
40
cp.extra=${tools.jar}
41
nbm.homepage=http://wiki.netbeans.org/groovy
41
nbm.homepage=http://wiki.netbeans.org/groovy
42
nbm.module.author=Martin Adamek, Petr Hejl, Matthias Schmidt
42
nbm.module.author=Martin Adamek, Petr Hejl, Matthias Schmidt
(-)a/groovy.support/nbproject/project.xml (-18 / +78 lines)
Lines 108-113 Link Here
108
                    </run-dependency>
108
                    </run-dependency>
109
                </dependency>
109
                </dependency>
110
                <dependency>
110
                <dependency>
111
                    <code-name-base>org.netbeans.api.templates</code-name-base>
112
                    <build-prerequisite/>
113
                    <compile-dependency/>
114
                    <run-dependency>
115
                        <specification-version>1.0</specification-version>
116
                    </run-dependency>
117
                </dependency>
118
                <dependency>
111
                    <code-name-base>org.netbeans.modules.gsf.testrunner</code-name-base>
119
                    <code-name-base>org.netbeans.modules.gsf.testrunner</code-name-base>
112
                    <build-prerequisite/>
120
                    <build-prerequisite/>
113
                    <compile-dependency/>
121
                    <compile-dependency/>
Lines 141-147 Link Here
141
                        <release-version>1</release-version>
149
                        <release-version>1</release-version>
142
                        <specification-version>1.62</specification-version>
150
                        <specification-version>1.62</specification-version>
143
                    </run-dependency>
151
                    </run-dependency>
144
                </dependency>                
152
                </dependency>
145
                <dependency>
153
                <dependency>
146
                    <code-name-base>org.netbeans.modules.java.source.base</code-name-base>
154
                    <code-name-base>org.netbeans.modules.java.source.base</code-name-base>
147
                    <build-prerequisite/>
155
                    <build-prerequisite/>
Lines 160-165 Link Here
160
                    </run-dependency>
168
                    </run-dependency>
161
                </dependency>
169
                </dependency>
162
                <dependency>
170
                <dependency>
171
                    <code-name-base>org.netbeans.modules.libs.groovy</code-name-base>
172
                    <build-prerequisite/>
173
                    <compile-dependency/>
174
                    <run-dependency>
175
                        <specification-version>1.0</specification-version>
176
                    </run-dependency>
177
                </dependency>
178
                <dependency>
163
                    <code-name-base>org.netbeans.modules.maven</code-name-base>
179
                    <code-name-base>org.netbeans.modules.maven</code-name-base>
164
                    <build-prerequisite/>
180
                    <build-prerequisite/>
165
                    <compile-dependency/>
181
                    <compile-dependency/>
Lines 323-336 Link Here
323
                    </run-dependency>
339
                    </run-dependency>
324
                </dependency>
340
                </dependency>
325
                <dependency>
341
                <dependency>
326
                    <code-name-base>org.netbeans.api.templates</code-name-base>
327
                    <build-prerequisite/>
328
                    <compile-dependency/>
329
                    <run-dependency>
330
                        <specification-version>1.0</specification-version>
331
                    </run-dependency>
332
                </dependency>
333
                <dependency>
334
                    <code-name-base>org.openide.nodes</code-name-base>
342
                    <code-name-base>org.openide.nodes</code-name-base>
335
                    <build-prerequisite/>
343
                    <build-prerequisite/>
336
                    <compile-dependency/>
344
                    <compile-dependency/>
Lines 347-360 Link Here
347
                    </run-dependency>
355
                    </run-dependency>
348
                </dependency>
356
                </dependency>
349
                <dependency>
357
                <dependency>
350
                    <code-name-base>org.openide.util.ui</code-name-base>
351
                    <build-prerequisite/>
352
                    <compile-dependency/>
353
                    <run-dependency>
354
                        <specification-version>9.3</specification-version>
355
                    </run-dependency>
356
                </dependency>
357
                <dependency>
358
                    <code-name-base>org.openide.util</code-name-base>
358
                    <code-name-base>org.openide.util</code-name-base>
359
                    <build-prerequisite/>
359
                    <build-prerequisite/>
360
                    <compile-dependency/>
360
                    <compile-dependency/>
Lines 371-376 Link Here
371
                    </run-dependency>
371
                    </run-dependency>
372
                </dependency>
372
                </dependency>
373
                <dependency>
373
                <dependency>
374
                    <code-name-base>org.openide.util.ui</code-name-base>
375
                    <build-prerequisite/>
376
                    <compile-dependency/>
377
                    <run-dependency>
378
                        <specification-version>9.3</specification-version>
379
                    </run-dependency>
380
                </dependency>
381
                <dependency>
374
                    <code-name-base>org.openide.windows</code-name-base>
382
                    <code-name-base>org.openide.windows</code-name-base>
375
                    <build-prerequisite/>
383
                    <build-prerequisite/>
376
                    <compile-dependency/>
384
                    <compile-dependency/>
Lines 379-385 Link Here
379
                    </run-dependency>
387
                    </run-dependency>
380
                </dependency>
388
                </dependency>
381
            </module-dependencies>
389
            </module-dependencies>
382
            <test-dependencies/>
390
            <test-dependencies>
391
                <test-type>
392
                    <name>unit</name>
393
                    <test-dependency>
394
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
395
                        <compile-dependency/>
396
                    </test-dependency>
397
                    <test-dependency>
398
                        <code-name-base>org.netbeans.insane</code-name-base>
399
                        <compile-dependency/>
400
                    </test-dependency>
401
                    <test-dependency>
402
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
403
                        <compile-dependency/>
404
                    </test-dependency>
405
                    <test-dependency>
406
                        <code-name-base>org.openide.filesystems</code-name-base>
407
                        <compile-dependency/>
408
                    </test-dependency>
409
                    <test-dependency>
410
                        <code-name-base>org.openide.filesystems.nb</code-name-base>
411
                        <compile-dependency/>
412
                    </test-dependency>
413
                    <test-dependency>
414
                        <code-name-base>org.openide.io</code-name-base>
415
                        <compile-dependency/>
416
                    </test-dependency>
417
                    <test-dependency>
418
                        <code-name-base>org.openide.loaders</code-name-base>
419
                        <compile-dependency/>
420
                    </test-dependency>
421
                    <test-dependency>
422
                        <code-name-base>org.openide.nodes</code-name-base>
423
                        <compile-dependency/>
424
                    </test-dependency>
425
                    <test-dependency>
426
                        <code-name-base>org.openide.text</code-name-base>
427
                        <compile-dependency/>
428
                    </test-dependency>
429
                    <test-dependency>
430
                        <code-name-base>org.openide.util</code-name-base>
431
                        <compile-dependency/>
432
                    </test-dependency>
433
                    <test-dependency>
434
                        <code-name-base>org.openide.util.lookup</code-name-base>
435
                        <compile-dependency/>
436
                    </test-dependency>
437
                    <test-dependency>
438
                        <code-name-base>org.netbeans.modules.libs.groovy</code-name-base>
439
                        <compile-dependency/>
440
                    </test-dependency>
441
                </test-type>
442
            </test-dependencies>
383
            <friend-packages>
443
            <friend-packages>
384
                <friend>org.netbeans.modules.groovy.antproject</friend>
444
                <friend>org.netbeans.modules.groovy.antproject</friend>
385
                <friend>org.netbeans.modules.groovy.editor</friend>
445
                <friend>org.netbeans.modules.groovy.editor</friend>
(-)a/groovy.support/src/org/netbeans/modules/groovy/support/actions/DebugMethodAction.java (-111 lines)
Lines 1-111 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.groovy.support.actions;
44
45
import java.util.Collection;
46
import org.netbeans.modules.gsf.testrunner.ui.api.TestMethodDebuggerProvider;
47
import org.openide.awt.ActionID;
48
import org.openide.awt.ActionReference;
49
import org.openide.awt.ActionRegistration;
50
import org.openide.nodes.Node;
51
import org.openide.util.HelpCtx;
52
import org.openide.util.Lookup;
53
import org.openide.util.NbBundle;
54
import org.openide.util.actions.NodeAction;
55
56
/**
57
 *
58
 * @author Martin Janicek
59
 */
60
//@ActionID(id = "org.netbeans.modules.groovy.support.actions.DebugMethodAction", category = "CommonTestRunner")
61
//@ActionRegistration(displayName = "#LBL_Action_DebugTestMethod")
62
//@ActionReference(path = "Editors/text/x-groovy/Popup", position=860)
63
//@NbBundle.Messages({"LBL_Action_DebugTestMethod=Debug Focused Test Method"})
64
public class DebugMethodAction extends NodeAction {
65
66
    public DebugMethodAction() {
67
        putValue("noIconInMenu", Boolean.TRUE);                         //NOI18N
68
    }
69
70
    @Override
71
    public String getName() {
72
        return NbBundle.getMessage(DebugMethodAction.class, "LBL_Action_DebugTestMethod");
73
    }
74
75
    @Override
76
    public HelpCtx getHelpCtx() {
77
        return HelpCtx.DEFAULT_HELP;
78
    }
79
80
    @Override
81
    public boolean asynchronous() {
82
        return false;
83
    }
84
85
    @Override
86
    protected void performAction(Node[] activatedNodes) {
87
        Collection<? extends TestMethodDebuggerProvider> providers = Lookup.getDefault().lookupAll(TestMethodDebuggerProvider.class);
88
        for (TestMethodDebuggerProvider provider : providers) {
89
            if(provider.canHandle(activatedNodes[0])) {
90
                provider.debugTestMethod(activatedNodes[0]);
91
                break;
92
            }
93
        }
94
    }
95
96
    @Override
97
    protected boolean enable(Node[] activatedNodes) {
98
        return false;
99
//        if (activatedNodes.length == 0) {
100
//            return false;
101
//        }
102
//        Collection<? extends TestMethodDebuggerProvider> providers = Lookup.getDefault().lookupAll(TestMethodDebuggerProvider.class);
103
//        for (TestMethodDebuggerProvider provider : providers) {
104
//            if(provider.canHandle(activatedNodes[0])) {
105
//                return true;
106
//            }
107
//        }
108
//        return false;
109
    }
110
111
}
(-)a/groovy.support/src/org/netbeans/modules/groovy/support/actions/GroovyTestClassInfoTask.java (-131 lines)
Lines 1-131 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.groovy.support.actions;
43
44
import com.sun.source.tree.Tree.Kind;
45
import com.sun.source.util.TreePath;
46
import java.util.Iterator;
47
import java.util.List;
48
import javax.lang.model.element.AnnotationMirror;
49
import javax.lang.model.element.Element;
50
import javax.lang.model.element.ElementKind;
51
import javax.lang.model.element.TypeElement;
52
import javax.lang.model.util.Elements;
53
import org.netbeans.api.java.source.CancellableTask;
54
import org.netbeans.api.java.source.CompilationController;
55
import org.netbeans.api.java.source.JavaSource.Phase;
56
import org.openide.filesystems.FileObject;
57
58
/**
59
 *
60
 * @author Martin Janicek
61
 */
62
public final class GroovyTestClassInfoTask implements CancellableTask<CompilationController> {
63
64
    private FileObject fileObject;
65
66
    private final int caretPosition;
67
    private String className;
68
    private String methodName;
69
70
    private static String ANNOTATION = "org.junit.Test"; //NOI18N
71
    private static String TESTCASE = "junit.framework.TestCase"; //NOI18N
72
73
    GroovyTestClassInfoTask(int caretPosition) {
74
        this.caretPosition = caretPosition;
75
    }
76
77
    @Override
78
    public void cancel() {
79
    }
80
81
    @Override
82
    public void run(CompilationController controller) throws Exception {
83
        controller.toPhase(Phase.RESOLVED);
84
        fileObject = controller.getFileObject();
85
        TypeElement typeElement = null;
86
        List<? extends TypeElement> topLevelElements = controller.getTopLevelElements();
87
        for (Iterator<? extends TypeElement> it = topLevelElements.iterator(); it.hasNext();) {
88
            typeElement = it.next();
89
            if (typeElement.getKind() == ElementKind.CLASS) {
90
                className = typeElement.getSimpleName().toString();
91
                break;
92
            }
93
        }
94
        Elements elements = controller.getElements();
95
        TypeElement testcase = elements.getTypeElement(TESTCASE);
96
        boolean junit3 = (testcase != null && typeElement != null) ? controller.getTypes().isSubtype(typeElement.asType(), testcase.asType()) : false;
97
        TreePath tp = controller.getTreeUtilities().pathFor(caretPosition);
98
        while (tp != null && tp.getLeaf().getKind() != Kind.METHOD) {
99
            tp = tp.getParentPath();
100
        }
101
        if (tp != null) {
102
            Element element = controller.getTrees().getElement(tp);
103
            String mn = element.getSimpleName().toString();
104
            if (junit3){
105
                methodName = mn.startsWith("test") ? mn : null; //NOI18N
106
            }else{
107
                List<? extends AnnotationMirror> allAnnotationMirrors = elements.getAllAnnotationMirrors(element);
108
                for (Iterator<? extends AnnotationMirror> it = allAnnotationMirrors.iterator(); it.hasNext();) {
109
                    AnnotationMirror annotationMirror = it.next();
110
                    typeElement = (TypeElement) annotationMirror.getAnnotationType().asElement();
111
                    if (typeElement.getQualifiedName().contentEquals(ANNOTATION)) {
112
                        methodName = mn;
113
                        break;
114
                    }
115
                }
116
            }
117
        }
118
    }
119
120
    public FileObject getFileObject() {
121
        return fileObject;
122
    }
123
124
    String getClassName() {
125
        return className;
126
    }
127
128
    String getMethodName() {
129
        return methodName;
130
    }
131
}
(-)a/groovy.support/src/org/netbeans/modules/groovy/support/actions/TestMethodAction.java (-108 lines)
Lines 1-108 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.groovy.support.actions;
44
45
import java.util.Collection;
46
import org.netbeans.modules.gsf.testrunner.ui.api.TestMethodRunnerProvider;
47
import org.openide.awt.ActionID;
48
import org.openide.awt.ActionReference;
49
import org.openide.awt.ActionRegistration;
50
import org.openide.nodes.Node;
51
import org.openide.util.*;
52
import org.openide.util.actions.NodeAction;
53
54
/**
55
 *
56
 * @author mjanicek
57
 */
58
//@ActionID(id = "org.netbeans.modules.groovy.support.actions.TestMethodAction", category = "CommonTestRunner")
59
//@ActionRegistration(displayName = "#LBL_Action_RunTestMethod")
60
//@ActionReference(path = "Editors/text/x-groovy/Popup", position=850)
61
//@NbBundle.Messages({"LBL_Action_RunTestMethod=Run Focused Test Method"})
62
public class TestMethodAction extends NodeAction {
63
64
    public TestMethodAction() {
65
        putValue("noIconInMenu", Boolean.TRUE);                         //NOI18N
66
    }
67
68
    @Override
69
    public String getName() {
70
        return NbBundle.getMessage(TestMethodAction.class, "LBL_Action_RunTestMethod");
71
    }
72
73
    @Override
74
    public HelpCtx getHelpCtx() {
75
        return HelpCtx.DEFAULT_HELP;
76
    }
77
78
    @Override
79
    public boolean asynchronous() {
80
        return false;
81
    }
82
83
    @Override
84
    protected void performAction(Node[] activatedNodes) {
85
        Collection<? extends TestMethodRunnerProvider> providers = Lookup.getDefault().lookupAll(TestMethodRunnerProvider.class);
86
        for (TestMethodRunnerProvider provider : providers) {
87
            if (provider.canHandle(activatedNodes[0])) {
88
                provider.runTestMethod(activatedNodes[0]);
89
                break;
90
            }
91
        }
92
    }
93
94
    @Override
95
    protected boolean enable(Node[] activatedNodes) {
96
        return false;
97
//        if (activatedNodes.length == 0) {
98
//            return false;
99
//        }
100
//        Collection<? extends TestMethodRunnerProvider> providers = Lookup.getDefault().lookupAll(TestMethodRunnerProvider.class);
101
//        for (TestMethodRunnerProvider provider : providers) {
102
//            if (provider.canHandle(activatedNodes[0])) {
103
//                return true;
104
//            }
105
//        }
106
//        return false;
107
    }
108
}
(-)a/groovy.support/src/org/netbeans/modules/groovy/support/actions/TestMethodUtil.java (-28 / +264 lines)
Lines 39-55 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.groovy.support.actions;
42
package org.netbeans.modules.groovy.support.actions;
44
43
44
import java.awt.EventQueue;
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.lang.ref.Reference;
46
import java.io.LineNumberReader;
47
import java.util.concurrent.Future;
47
import java.io.StringReader;
48
import java.util.logging.Level;
48
import java.lang.reflect.InvocationTargetException;
49
import java.util.logging.Logger;
49
import java.lang.reflect.Method;
50
import java.util.Collections;
51
import java.util.List;
52
import java.util.concurrent.atomic.AtomicInteger;
53
import java.util.concurrent.atomic.AtomicReference;
50
import javax.swing.JEditorPane;
54
import javax.swing.JEditorPane;
51
import javax.swing.text.Document;
55
import javax.swing.text.Document;
52
import org.netbeans.api.java.source.JavaSource;
56
import org.codehaus.groovy.ast.ClassNode;
57
import org.codehaus.groovy.ast.MethodNode;
58
import org.codehaus.groovy.ast.ModuleNode;
59
import org.netbeans.modules.parsing.api.ParserManager;
60
import org.netbeans.modules.parsing.api.ResultIterator;
61
import org.netbeans.modules.parsing.api.Source;
62
import org.netbeans.modules.parsing.api.UserTask;
63
import org.netbeans.modules.parsing.spi.ParseException;
64
import org.netbeans.modules.parsing.spi.Parser.Result;
53
import org.netbeans.spi.project.SingleMethod;
65
import org.netbeans.spi.project.SingleMethod;
54
import org.openide.cookies.EditorCookie;
66
import org.openide.cookies.EditorCookie;
55
import org.openide.filesystems.FileObject;
67
import org.openide.filesystems.FileObject;
Lines 58-63 Link Here
58
import org.openide.loaders.DataObject;
70
import org.openide.loaders.DataObject;
59
import org.openide.nodes.Node;
71
import org.openide.nodes.Node;
60
import org.openide.text.NbDocument;
72
import org.openide.text.NbDocument;
73
import org.openide.util.Parameters;
61
74
62
/**
75
/**
63
 *
76
 *
Lines 65-101 Link Here
65
 */
78
 */
66
public final class TestMethodUtil {
79
public final class TestMethodUtil {
67
80
68
    private static final Logger LOGGER = Logger.getLogger(TestMethodUtil.class.getName());
81
    private static final String GROOVY_PARSER_RESULT_CLASS_NAME = "org.netbeans.modules.groovy.editor.api.parser.GroovyParserResult";
69
    private Reference<JavaSource> resolver;
82
83
    private static final String GPR_GET_ROOT_ELEMENT = "getRootElement";
84
85
    private static final String AST_GET_MODULE_NODE = "getModuleNode";
70
86
71
    static boolean isTestClass(Node activatedNode) {
87
    static boolean isTestClass(Node activatedNode) {
72
        FileObject fo = getFileObjectFromNode(activatedNode);
88
        FileObject fo = getFileObjectFromNode(activatedNode);
73
        if (fo != null) {
89
        if (fo != null) {
74
            if (!isGroovyFile(fo)) {
75
                return false;
76
            }
77
            //TODO add more checks here when action gets enabled?
90
            //TODO add more checks here when action gets enabled?
91
            return isGroovyFile(fo);
78
        }
92
        }
79
        return false;
93
        return false;
80
    }
94
    }
81
95
82
    static SingleMethod getTestMethod(Document doc, int cursor){
96
    /**
83
        SingleMethod sm = null;
97
     * Given the text from a Document, will read through the lines, adding 1 to
84
        if (doc != null){
98
     * a counter for each line, plus the length of the given line until the
85
            JavaSource js = JavaSource.forDocument(doc);
99
     * value is greater than or equal to the cursor, and this gives us the line.
86
            GroovyTestClassInfoTask task = new GroovyTestClassInfoTask(cursor);
100
     * Next, the offset in the line which would make the counter equal to the
101
     * cursor value is taken to represent the column. This is done to map to the
102
     * Groovy AST nodes line and columns to match to classes and methods. The
103
     * return from this method can be used to find the class and method the
104
     * cursor is in. Remember, the Groovy lines and columns are index 1 with
105
     * relation to the AST node classes.
106
     *
107
     * @param srcText the Groovy source as represented in the edited Groovy
108
     * document; it must be this text as the expectation is a line will always
109
     * end in a \n
110
     * @param cursor the cursor offset in the given text.
111
     * @return the line and column of the cursor offset in the text as an
112
     * integer array such that index 0 is the line, and index 1 is the column
113
     */
114
    public static int[] getLineAndColumn(final String srcText, final int cursor) {
115
        Parameters.notNull("srcText", srcText);
116
        Parameters.notEmpty("srcText", srcText);
117
        int[] ret = new int[]{-1, -1};
118
        if (cursor > 0) {
87
            try {
119
            try {
88
                if (js != null) {
120
                final StringReader sr = new StringReader(srcText);
89
                    Future<Void> f = js.runWhenScanFinished(task, true);
121
                final LineNumberReader lr = new LineNumberReader(sr);
90
                    if (f.isDone() && task.getFileObject() != null && task.getMethodName() != null){
122
                int counter = 0;
91
                        sm = new SingleMethod(task.getFileObject(), task.getMethodName());
123
                String line;
124
                while ((line = lr.readLine()) != null) {
125
                    //remember, we went over a line, and it has a \n
126
                    counter += line.length();
127
                    if (counter >= cursor) {
128
                        //lr incs line number at every line it reads,
129
                        //and started at 0
130
                        ret[0] = lr.getLineNumber();
131
                        //if we take away what we just added, then take the whole
132
                        //away from the cursor, then we are left with the number
133
                        //it takes to equal the cursor, and then since the chars
134
                        //and positions in the line are 0 indexed, we need to add
135
                        //1; if 0 or 0 length, then that should also work out
136
                        //correctly as if the cursor is on the line, it is in
137
                        //column 1
138
                        ret[1] = (cursor - (counter - line.length())) + 1;
139
                        break;
92
                    }
140
                    }
141
                    //account for the newline now as we don't care about it
142
                    //until we are done with the "current" line. The extra value
143
                    //will throw off the above calculation if added too soon, but
144
                    //if not added at all will also throw it off. So, add it here.
145
                    counter++;
93
                }
146
                }
94
            } catch (IOException ex) {
147
            } catch (IOException ex) {
95
                LOGGER.log(Level.WARNING, null, ex);
148
                throw new RuntimeException(ex);
149
            }
150
        } else if (cursor == 0) {
151
            //first line and start of first line
152
            ret[0] = 1;
153
            ret[1] = 1;
154
        }
155
        return ret;
156
    }
157
158
    /**
159
     * Given a start and end line and a start and end column plus a given line
160
     * and column, tests if the given line and column falls between the start
161
     * and end values in relation to Groovy code and the Groovy AST.
162
     *
163
     * @param startLine the start line
164
     * @param startCol the start column
165
     * @param endLine the end line
166
     * @param endCol the end column
167
     * @param line the line to test
168
     * @param col the column to test
169
     * @return whether the line and column fall between the given start and end
170
     * values
171
     */
172
    public static boolean isBetweenLinesAndColumns(final int startLine,
173
            final int startCol,
174
            final int endLine,
175
            final int endCol,
176
            final int line,
177
            final int col) {
178
        boolean ret = false;
179
        if (line >= startLine && line <= endLine) {
180
            //at the momment we are approximately
181
            //in the method bounds, so we'll assume
182
            //true, then adjust accordingly
183
            //as this is simpler than embedded ifs
184
            //and logic as we only care about the col
185
            //if we are on one of the bounding lines
186
            ret = true;
187
188
            //even though above we say true, we may take it back
189
            //if on the same line as the start line and not in
190
            //the method bounds
191
            if (line == startLine && !(col >= startCol)) {
192
                ret = false;
193
            }
194
195
            //even though above we may say true, we may take it back
196
            //if on the same line as the end line and not in
197
            //the method bounds            
198
            if (line == endLine && !(col <= endCol)) {
199
                ret = false;
96
            }
200
            }
97
        }
201
        }
98
        return sm;
202
        return ret;
203
    }
204
205
    /**
206
     * Gets the Groovy AST ModuleNode associated with the given Source result.
207
     * This is currently done with reflection due to the dependency graph of
208
     * "Groovy Support" and "Groovy Editor". This is hopefully just temporary
209
     * until the modules can be refactored into a better DAG.
210
     *
211
     * @param r the Result to extract from
212
     * @return the ModuleNode if the Result is in fact a "GroovyParserResult",
213
     * the sources have been parsed, and the {@link ModuleNode ModuleNode} has
214
     * been set. If not set or the wrong "Result" time, then null will be
215
     * returned.
216
     */
217
    public static ModuleNode extractModuleNode(final Result r) {
218
        //below line long to show up properly in enumerations
219
        //TODO TestMethodUtil.extractModuleNode refactor "Groovy Support" and "Groovy Editor" to have a better DAG to remove need to use reflection to extract Groovy ModuleNode
220
        ModuleNode ret = null;
221
        try {
222
            //no need to test result type as it will have the method or it won't
223
            //and this makes it easier to test
224
            final Method getRE = r.getClass().getMethod(GPR_GET_ROOT_ELEMENT);
225
            final Object astRoot = getRE.invoke(r);
226
            if (astRoot != null) {
227
                final Method getMN = astRoot.getClass().getMethod(AST_GET_MODULE_NODE);
228
                final ModuleNode lmn = ModuleNode.class.cast(getMN.invoke(astRoot));
229
                ret = lmn;
230
            }
231
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
232
            //push it up to the NB caller
233
            throw new RuntimeException("The given result doesn't appear to come from parsing a Groovy file.", e);
234
        }
235
        return ret;
236
    }
237
238
    /**
239
     * Given a root {@link ModuleNode ModuleNode}, finds and returns the
240
     * {@link ClassNode ClassNode} for the given line and column. It is possible
241
     * in some situations for this to be null.
242
     *
243
     * @param root the root ModuleNode
244
     * @param line the line
245
     * @param col the column
246
     * @return the ClassNode for the line and column (cursor)
247
     */
248
    public static ClassNode getClassNodeForLineAndColumn(final ModuleNode root,
249
            final int line,
250
            final int col) {
251
        ClassNode ret = null;
252
        if (root != null) {
253
            final List<ClassNode> classes = root.getClasses();
254
            for (ClassNode cn : classes) {
255
                if (isBetweenLinesAndColumns(cn.getLineNumber(), cn.getColumnNumber(),
256
                        cn.getLastLineNumber(), cn.getLastColumnNumber(),
257
                        line, col)) {
258
                    return cn;
259
                }
260
            }
261
        }
262
        return ret;
263
    }
264
265
    /**
266
     * Given a {@link ClassNode ClassNode}, finds and returns the
267
     * {@link MethodNode MethodNode} for the given line and column. It is
268
     * possible in some situations for this to be null.
269
     *
270
     * @param cn the ClassNode
271
     * @param line the line
272
     * @param col the column
273
     * @return the MethodNode for the line and column (cursor)
274
     */
275
    public static MethodNode getMethodNodeForLineAndColumn(final ClassNode cn,
276
            final int line,
277
            final int col) {
278
        MethodNode ret = null;
279
        if (cn != null) {
280
            final List<MethodNode> methods = cn.getMethods();
281
            for (MethodNode mn : methods) {
282
                if (isBetweenLinesAndColumns(mn.getLineNumber(), mn.getColumnNumber(),
283
                        mn.getLastLineNumber(), mn.getLastColumnNumber(),
284
                        line, col)) {
285
                    return mn;
286
                }
287
            }
288
        }
289
        return ret;
290
    }
291
292
    public static SingleMethod getTestMethod(final Document doc, final int cursor) {
293
        final AtomicReference<SingleMethod> sm = new AtomicReference<>();
294
        if (doc != null) {
295
296
            Source s = Source.create(doc);
297
            try {
298
                ParserManager.parseWhenScanFinished(Collections.<Source>singleton(s), new UserTask() {
299
                    @Override
300
                    public void run(ResultIterator rit) throws Exception {
301
                        Result r = rit.getParserResult();
302
                        //0:line, 1:column
303
                        final int[] lc = getLineAndColumn(doc.getText(0, doc.getLength()), cursor);
304
                        final int line = lc[0];
305
                        final int col = lc[1];
306
                        final ModuleNode root = extractModuleNode(r);
307
                        final ClassNode cn = getClassNodeForLineAndColumn(root, line, col);
308
                        final MethodNode mn = getMethodNodeForLineAndColumn(cn, line, col);
309
                        if (mn != null) {
310
                            final SingleMethod lsm = new SingleMethod(s.getFileObject(), mn.getName());
311
                            sm.set(lsm);
312
                        }
313
                    }
314
315
                });
316
            } catch (ParseException e) {
317
                throw new RuntimeException(e);
318
            }
319
        }
320
        return sm.get();
99
    }
321
    }
100
322
101
    static boolean canHandle(Node activatedNode) {
323
    static boolean canHandle(Node activatedNode) {
Lines 105-116 Link Here
105
                return false;
327
                return false;
106
            }
328
            }
107
329
108
            EditorCookie ec = activatedNode.getLookup().lookup(EditorCookie.class);
330
            final EditorCookie ec = activatedNode.getLookup().lookup(EditorCookie.class);
109
            if (ec != null) {
331
            if (ec != null) {
110
                JEditorPane pane = NbDocument.findRecentEditorPane(ec);
332
                final AtomicReference<Document> doc = new AtomicReference<>();
111
                if (pane != null) {
333
                final AtomicInteger dot = new AtomicInteger();
112
                    SingleMethod sm = getTestMethod(pane.getDocument(), pane.getCaret().getDot());
334
                try {
113
                    if(sm != null) {
335
                    EventQueue.invokeAndWait(() -> {
336
                        final JEditorPane pane = NbDocument.findRecentEditorPane(ec);
337
                        if (pane != null) {
338
                            doc.set(pane.getDocument());
339
                            dot.set(pane.getCaret().getDot());
340
                        }
341
                    });
342
                } catch (InterruptedException | InvocationTargetException e) {
343
                    throw new RuntimeException(e);
344
                }
345
                if (doc.get() != null) {
346
                    SingleMethod sm = getTestMethod(doc.get(), dot.get());
347
                    if (sm != null) {
114
                        return true;
348
                        return true;
115
                    }
349
                    }
116
                }
350
                }
Lines 136-141 Link Here
136
    }
370
    }
137
371
138
    private static boolean isGroovyFile(FileObject fileObj) {
372
    private static boolean isGroovyFile(FileObject fileObj) {
139
        return "groovy".equals(fileObj.getExt()) || "text/x-groovy".equals(FileUtil.getMIMEType(fileObj)); //NOI18N
373
        final String ext = fileObj.getExt();
374
        final String mtype = FileUtil.getMIMEType(fileObj);
375
        return "groovy".equals(ext) || "text/x-groovy".equals(mtype); //NOI18N
140
    }
376
    }
141
}
377
}
(-)a/groovy.support/src/org/netbeans/modules/groovy/support/resources/layer.xml (+8 lines)
Lines 53-58 Link Here
53
                        <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-ToggleBreakpointAction.instance"/>
53
                        <attr name="originalFile" stringvalue="Actions/Debug/org-netbeans-modules-debugger-ui-actions-ToggleBreakpointAction.instance"/>
54
                        <attr name="position" intvalue="1750"/>
54
                        <attr name="position" intvalue="1750"/>
55
                    </file>
55
                    </file>
56
                    <file name="org-netbeans-modules-gsf-testrunner-TestMethodRunnerAction.shadow">
57
                        <attr name="originalFile" stringvalue="Actions/CommonTestRunner/org-netbeans-modules-gsf-testrunner-TestMethodRunnerAction.instance"/>
58
                        <attr name="position" intvalue="850"/>
59
                    </file>
60
                    <file name="org-netbeans-modules-gsf-testrunner-TestMethodDebuggerAction.shadow">
61
                        <attr name="originalFile" stringvalue="Actions/CommonTestRunner/org-netbeans-modules-gsf-testrunner-TestMethodDebuggerAction.instance"/>
62
                        <attr name="position" intvalue="860"/>
63
                    </file>
56
                </folder>
64
                </folder>
57
                <folder name="GlyphGutterActions">
65
                <folder name="GlyphGutterActions">
58
                    <file name="org-netbeans-modules-debugger-ui-actions-ToggleBreakpointAction.shadow">
66
                    <file name="org-netbeans-modules-debugger-ui-actions-ToggleBreakpointAction.shadow">
(-)a/groovy.support/test/unit/src/org/netbeans/modules/groovy/support/actions/TestMethodUtilTest.java (+199 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2016 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2016 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.groovy.support.actions;
43
44
import groovy.lang.GroovyClassLoader;
45
import java.io.File;
46
import java.io.IOException;
47
import java.util.List;
48
import java.util.UUID;
49
import org.codehaus.groovy.ast.ClassNode;
50
import org.codehaus.groovy.ast.MethodNode;
51
import org.codehaus.groovy.ast.ModuleNode;
52
import org.codehaus.groovy.control.CompilationUnit;
53
import org.codehaus.groovy.control.CompilerConfiguration;
54
import org.codehaus.groovy.control.SourceUnit;
55
import org.netbeans.junit.NbTestCase;
56
import org.netbeans.modules.parsing.spi.Parser.Result;
57
58
public class TestMethodUtilTest extends NbTestCase {
59
60
    private File compileDir;
61
62
    private StringBuilder groovyScript;
63
64
    private ModuleNode moduleNode;
65
66
    public TestMethodUtilTest(final String name) {
67
        super(name);
68
    }
69
70
    @Override
71
    protected void setUp() throws IOException {
72
        compileDir = new File(this.getWorkDir(), UUID.randomUUID().toString());
73
        compileDir.mkdir();
74
        groovyScript = new StringBuilder()
75
                .append("class AGroovyClass {\n")
76
                .append("public void method1() {\n")
77
                .append("//some comment\n")
78
                .append("}\n")
79
                .append("//just some comment not in a method\n")
80
                .append("}\n")
81
                .append("//comment outside of class");
82
        moduleNode = createGroovyModuleNode();
83
    }
84
85
    @Override
86
    protected void tearDown() {
87
        compileDir.deleteOnExit();
88
    }
89
90
    private ModuleNode createGroovyModuleNode() {
91
        final CompilerConfiguration conf = new CompilerConfiguration();
92
        conf.setTargetDirectory(compileDir);
93
        final CompilationUnit cu
94
                = new CompilationUnit(
95
                        new GroovyClassLoader(
96
                                getClass().getClassLoader()
97
                        )
98
                );
99
        cu.configure(conf);
100
        final SourceUnit sn = cu.addSource("AGroovyClass.groovy", groovyScript.toString());
101
        try {
102
            cu.compile();
103
        } catch (Exception e) {
104
            //this groovy compile bit didn't work when running tests
105
            //but did work when debugging them, so odd, but the AST is in
106
            //place either way, and is all we need for this
107
            this.log(e.getMessage());
108
        }
109
        final ModuleNode mn = sn.getAST();
110
        return mn;
111
    }
112
113
    public void testGetLineAndColumn() {
114
        final StringBuilder g = new StringBuilder()
115
                .append("class MyClass {\n")
116
                .append("public void method1() {\n")
117
                .append("//cursor here before h\n")
118
                .append("}\n")
119
                .append("}");
120
        //3rd line, 10th column ... 3,10
121
        int cursor = g.lastIndexOf("here");
122
        int[] lc = TestMethodUtil.getLineAndColumn(g.toString(), cursor);
123
        assert lc[0] == 3;
124
        assert lc[1] == 10;
125
126
        cursor = g.lastIndexOf("//");
127
        lc = TestMethodUtil.getLineAndColumn(g.toString(), cursor);
128
        assert lc[0] == 3;
129
        assert lc[1] == 1;
130
131
        lc = TestMethodUtil.getLineAndColumn(g.toString(), 0);
132
        assert lc[0] == 1;
133
        assert lc[1] == 1;
134
    }
135
136
    public void testIsBetweenLinesAndColumns() {
137
        assert TestMethodUtil.isBetweenLinesAndColumns(0, 0, 0, 0, 0, 0);
138
        assert TestMethodUtil.isBetweenLinesAndColumns(1, 5, 2, 10, 2, 10);
139
        assert !TestMethodUtil.isBetweenLinesAndColumns(1, 5, 2, 10, 2, 11);
140
        assert !TestMethodUtil.isBetweenLinesAndColumns(1, 5, 2, 10, 3, 10);
141
        assert TestMethodUtil.isBetweenLinesAndColumns(1, 5, 1, 30, 1, 20);
142
        assert !TestMethodUtil.isBetweenLinesAndColumns(1, 5, 1, 30, 1, 31);
143
        assert !TestMethodUtil.isBetweenLinesAndColumns(1, 5, 1, 30, 1, 4);
144
        assert !TestMethodUtil.isBetweenLinesAndColumns(2, 5, 4, 30, 1, 4);
145
    }
146
147
    //setup some simple classes to mock behavior of the
148
    //reflection code in TestMethodUtil
149
    private class TestASTRoot {
150
151
        public ModuleNode getModuleNode() {
152
            return moduleNode;
153
        }
154
    }
155
156
    private class TestGroovyParserResult extends Result {
157
158
        public TestGroovyParserResult() {
159
            super(null);
160
        }
161
162
        @Override
163
        protected void invalidate() {
164
165
        }
166
167
        public TestASTRoot getRootElement() {
168
            return new TestASTRoot();
169
        }
170
171
    }
172
173
    public void testExtractModuleNode() {
174
        final TestGroovyParserResult r = new TestGroovyParserResult();
175
        final ModuleNode lmn = TestMethodUtil.extractModuleNode(r);
176
        assert moduleNode.equals(lmn);
177
    }
178
179
    public void testGetClassNodeForLineAndColumn() throws IOException {
180
        List<ClassNode> classes = moduleNode.getClasses();
181
182
        assert classes.size() > 0;
183
        assert TestMethodUtil.getClassNodeForLineAndColumn(moduleNode, 0, 0) == null;
184
        final ClassNode cn = TestMethodUtil.getClassNodeForLineAndColumn(moduleNode, 5, 2);
185
        assert cn != null;
186
        assert "AGroovyClass".equals(cn.getNameWithoutPackage());
187
        assert TestMethodUtil.getClassNodeForLineAndColumn(moduleNode, 7, 5) == null;
188
    }
189
190
    public void testGetMethodNodeForLineAndColumn() {
191
        final ClassNode cn = TestMethodUtil.getClassNodeForLineAndColumn(moduleNode, 5, 2);
192
        assert cn != null;
193
        MethodNode mn = TestMethodUtil.getMethodNodeForLineAndColumn(cn, 5, 2);
194
        assert mn == null;
195
        mn = TestMethodUtil.getMethodNodeForLineAndColumn(cn, 3, 2);
196
        assert mn != null;
197
        assert "method1".equals(mn.getName());
198
    }
199
}
(-)a/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/TestMethodDebuggerAction.java (-34 / +38 lines)
Lines 65-78 Link Here
65
 * @author Theofanis Oikonomou
65
 * @author Theofanis Oikonomou
66
 */
66
 */
67
@ActionID(id = "org.netbeans.modules.gsf.testrunner.TestMethodDebuggerAction", category = "CommonTestRunner")
67
@ActionID(id = "org.netbeans.modules.gsf.testrunner.TestMethodDebuggerAction", category = "CommonTestRunner")
68
@ActionRegistration(displayName = "#LBL_Action_DebugTestMethod")
68
@ActionRegistration(lazy = false, displayName = "#LBL_Action_DebugTestMethod")
69
@ActionReferences(value = {@ActionReference(path = "Editors/text/x-java/Popup", position=1797)})
69
@ActionReferences(value = {
70
    @ActionReference(path = "Editors/text/x-java/Popup", position = 1797)})
70
@NbBundle.Messages({"LBL_Action_DebugTestMethod=Debug Focused Test Method"})
71
@NbBundle.Messages({"LBL_Action_DebugTestMethod=Debug Focused Test Method"})
71
public class TestMethodDebuggerAction extends NodeAction {
72
public class TestMethodDebuggerAction extends NodeAction {
73
72
    private RequestProcessor.Task debugMethodTask;
74
    private RequestProcessor.Task debugMethodTask;
73
    private TestMethodDebuggerProvider debugMethodProvider;
75
    private TestMethodDebuggerProvider debugMethodProvider;
74
    
76
75
    /** Creates a new instance of TestMethodDebuggerAction */
77
    /**
78
     * Creates a new instance of TestMethodDebuggerAction
79
     */
76
    public TestMethodDebuggerAction() {
80
    public TestMethodDebuggerAction() {
77
        putValue("noIconInMenu", Boolean.TRUE);                         //NOI18N
81
        putValue("noIconInMenu", Boolean.TRUE);                         //NOI18N
78
    }
82
    }
Lines 86-92 Link Here
86
    public HelpCtx getHelpCtx() {
90
    public HelpCtx getHelpCtx() {
87
        return HelpCtx.DEFAULT_HELP;
91
        return HelpCtx.DEFAULT_HELP;
88
    }
92
    }
89
    
93
90
    @Override
94
    @Override
91
    public boolean asynchronous() {
95
    public boolean asynchronous() {
92
        return false;
96
        return false;
Lines 96-126 Link Here
96
    protected void performAction(final Node[] activatedNodes) {
100
    protected void performAction(final Node[] activatedNodes) {
97
        final Collection<? extends TestMethodDebuggerProvider> providers = Lookup.getDefault().lookupAll(TestMethodDebuggerProvider.class);
101
        final Collection<? extends TestMethodDebuggerProvider> providers = Lookup.getDefault().lookupAll(TestMethodDebuggerProvider.class);
98
        RequestProcessor RP = new RequestProcessor("TestMethodDebuggerAction", 1, true);   // NOI18N
102
        RequestProcessor RP = new RequestProcessor("TestMethodDebuggerAction", 1, true);   // NOI18N
99
	debugMethodTask = RP.create(new Runnable() {
103
        debugMethodTask = RP.create(new Runnable() {
100
	    @Override
104
            @Override
101
	    public void run() {
105
            public void run() {
102
		for (TestMethodDebuggerProvider provider : providers) {
106
                for (TestMethodDebuggerProvider provider : providers) {
103
		    if (provider.canHandle(activatedNodes[0])) {
107
                    if (provider.canHandle(activatedNodes[0])) {
104
			debugMethodProvider = provider;
108
                        debugMethodProvider = provider;
105
			break;
109
                        break;
106
		    }
110
                    }
107
		}
111
                }
108
	    }
112
            }
109
	});
113
        });
110
	final ProgressHandle ph = ProgressHandleFactory.createHandle(Bundle.Search_For_Provider(), debugMethodTask);
114
        final ProgressHandle ph = ProgressHandleFactory.createHandle(Bundle.Search_For_Provider(), debugMethodTask);
111
	debugMethodTask.addTaskListener(new TaskListener() {
115
        debugMethodTask.addTaskListener(new TaskListener() {
112
	    @Override
116
            @Override
113
	    public void taskFinished(org.openide.util.Task task) {
117
            public void taskFinished(org.openide.util.Task task) {
114
		ph.finish();
118
                ph.finish();
115
		if(debugMethodProvider == null) {
119
                if (debugMethodProvider == null) {
116
		    StatusDisplayer.getDefault().setStatusText(Bundle.No_Provider_Found());
120
                    StatusDisplayer.getDefault().setStatusText(Bundle.No_Provider_Found());
117
		} else {
121
                } else {
118
		    debugMethodProvider.debugTestMethod(activatedNodes[0]);
122
                    debugMethodProvider.debugTestMethod(activatedNodes[0]);
119
		}
123
                }
120
	    }
124
            }
121
	});
125
        });
122
	ph.start();
126
        ph.start();
123
	debugMethodTask.schedule(0);
127
        debugMethodTask.schedule(0);
124
    }
128
    }
125
129
126
    @Override
130
    @Override
Lines 128-136 Link Here
128
        if (activatedNodes.length == 0) {
132
        if (activatedNodes.length == 0) {
129
            return false;
133
            return false;
130
        }
134
        }
131
        if(debugMethodTask != null && !debugMethodTask.isFinished()) {
135
        if (debugMethodTask != null && !debugMethodTask.isFinished()) {
132
	    return false;
136
            return false;
133
	}
137
        }
134
        Collection<? extends TestMethodDebuggerProvider> providers = Lookup.getDefault().lookupAll(TestMethodDebuggerProvider.class);
138
        Collection<? extends TestMethodDebuggerProvider> providers = Lookup.getDefault().lookupAll(TestMethodDebuggerProvider.class);
135
        for (TestMethodDebuggerProvider provider : providers) {
139
        for (TestMethodDebuggerProvider provider : providers) {
136
            if (provider.isTestClass(activatedNodes[0])) {
140
            if (provider.isTestClass(activatedNodes[0])) {
Lines 139-143 Link Here
139
        }
143
        }
140
        return false;
144
        return false;
141
    }
145
    }
142
    
146
143
}
147
}
(-)a/gsf.testrunner.ui/src/org/netbeans/modules/gsf/testrunner/ui/TestMethodRunnerAction.java (-35 / +39 lines)
Lines 60-73 Link Here
60
 * @author Theofanis Oikonomou
60
 * @author Theofanis Oikonomou
61
 */
61
 */
62
@ActionID(id = "org.netbeans.modules.gsf.testrunner.TestMethodRunnerAction", category = "CommonTestRunner")
62
@ActionID(id = "org.netbeans.modules.gsf.testrunner.TestMethodRunnerAction", category = "CommonTestRunner")
63
@ActionRegistration(displayName = "#LBL_Action_RunTestMethod")
63
@ActionRegistration(lazy = false, displayName = "#LBL_Action_RunTestMethod")
64
@ActionReferences(value = {@ActionReference(path = "Editors/text/x-java/Popup", position=1795)})
64
@ActionReferences(value = {
65
    @ActionReference(path = "Editors/text/x-java/Popup", position = 1795)})
65
@NbBundle.Messages({"LBL_Action_RunTestMethod=Run Focused Test Method"})
66
@NbBundle.Messages({"LBL_Action_RunTestMethod=Run Focused Test Method"})
66
public class TestMethodRunnerAction extends NodeAction {
67
public class TestMethodRunnerAction extends NodeAction {
68
67
    private RequestProcessor.Task runMethodTask;
69
    private RequestProcessor.Task runMethodTask;
68
    private TestMethodRunnerProvider runMethodProvider;
70
    private TestMethodRunnerProvider runMethodProvider;
69
    
71
70
    /** Creates a new instance of TestMethodRunnerAction */
72
    /**
73
     * Creates a new instance of TestMethodRunnerAction
74
     */
71
    public TestMethodRunnerAction() {
75
    public TestMethodRunnerAction() {
72
        putValue("noIconInMenu", Boolean.TRUE);                         //NOI18N
76
        putValue("noIconInMenu", Boolean.TRUE);                         //NOI18N
73
    }
77
    }
Lines 81-87 Link Here
81
    public HelpCtx getHelpCtx() {
85
    public HelpCtx getHelpCtx() {
82
        return HelpCtx.DEFAULT_HELP;
86
        return HelpCtx.DEFAULT_HELP;
83
    }
87
    }
84
    
88
85
    @Override
89
    @Override
86
    public boolean asynchronous() {
90
    public boolean asynchronous() {
87
        return false;
91
        return false;
Lines 89-125 Link Here
89
93
90
    @Override
94
    @Override
91
    @NbBundle.Messages({"Search_For_Provider=Searching for provider to handle the test method",
95
    @NbBundle.Messages({"Search_For_Provider=Searching for provider to handle the test method",
92
	"No_Provider_Found=No provider can handle the test method",
96
        "No_Provider_Found=No provider can handle the test method",
93
	"Scanning_In_Progress=Scanning in progress, cannot yet identify the name of the test method"})
97
        "Scanning_In_Progress=Scanning in progress, cannot yet identify the name of the test method"})
94
    protected void performAction(final Node[] activatedNodes) {
98
    protected void performAction(final Node[] activatedNodes) {
95
        final Collection<? extends TestMethodRunnerProvider> providers = Lookup.getDefault().lookupAll(TestMethodRunnerProvider.class);
99
        final Collection<? extends TestMethodRunnerProvider> providers = Lookup.getDefault().lookupAll(TestMethodRunnerProvider.class);
96
	RequestProcessor RP = new RequestProcessor("TestMethodRunnerAction", 1, true);   // NOI18N
100
        RequestProcessor RP = new RequestProcessor("TestMethodRunnerAction", 1, true);   // NOI18N
97
	runMethodTask = RP.create(new Runnable() {
101
        runMethodTask = RP.create(new Runnable() {
98
	    @Override
102
            @Override
99
	    public void run() {
103
            public void run() {
100
		for (TestMethodRunnerProvider provider : providers) {
104
                for (TestMethodRunnerProvider provider : providers) {
101
		    if (provider.canHandle(activatedNodes[0])) {
105
                    if (provider.canHandle(activatedNodes[0])) {
102
			runMethodProvider = provider;
106
                        runMethodProvider = provider;
103
			break;
107
                        break;
104
		    }
108
                    }
105
		}
109
                }
106
	    }
110
            }
107
	});
111
        });
108
	final ProgressHandle ph = ProgressHandleFactory.createHandle(Bundle.Search_For_Provider(), runMethodTask);
112
        final ProgressHandle ph = ProgressHandleFactory.createHandle(Bundle.Search_For_Provider(), runMethodTask);
109
	runMethodTask.addTaskListener(new TaskListener() {
113
        runMethodTask.addTaskListener(new TaskListener() {
110
	    @Override
114
            @Override
111
	    public void taskFinished(org.openide.util.Task task) {
115
            public void taskFinished(org.openide.util.Task task) {
112
		ph.finish();
116
                ph.finish();
113
		if(runMethodProvider == null) {
117
                if (runMethodProvider == null) {
114
                    boolean isIndexing = IndexingManager.getDefault().isIndexing();
118
                    boolean isIndexing = IndexingManager.getDefault().isIndexing();
115
                    StatusDisplayer.getDefault().setStatusText(isIndexing ? Bundle.Scanning_In_Progress() : Bundle.No_Provider_Found());
119
                    StatusDisplayer.getDefault().setStatusText(isIndexing ? Bundle.Scanning_In_Progress() : Bundle.No_Provider_Found());
116
		} else {
120
                } else {
117
		    runMethodProvider.runTestMethod(activatedNodes[0]);
121
                    runMethodProvider.runTestMethod(activatedNodes[0]);
118
		}
122
                }
119
	    }
123
            }
120
	});
124
        });
121
	ph.start();
125
        ph.start();
122
	runMethodTask.schedule(0);
126
        runMethodTask.schedule(0);
123
    }
127
    }
124
128
125
    @Override
129
    @Override
Lines 127-135 Link Here
127
        if (activatedNodes.length == 0) {
131
        if (activatedNodes.length == 0) {
128
            return false;
132
            return false;
129
        }
133
        }
130
	if(runMethodTask != null && !runMethodTask.isFinished()) {
134
        if (runMethodTask != null && !runMethodTask.isFinished()) {
131
	    return false;
135
            return false;
132
	}
136
        }
133
        Collection<? extends TestMethodRunnerProvider> providers = Lookup.getDefault().lookupAll(TestMethodRunnerProvider.class);
137
        Collection<? extends TestMethodRunnerProvider> providers = Lookup.getDefault().lookupAll(TestMethodRunnerProvider.class);
134
        for (TestMethodRunnerProvider provider : providers) {
138
        for (TestMethodRunnerProvider provider : providers) {
135
            if (provider.isTestClass(activatedNodes[0])) {
139
            if (provider.isTestClass(activatedNodes[0])) {
(-)a/libs.groovy/nbproject/project.xml (+1 lines)
Lines 46-51 Link Here
46
            <module-dependencies/>
46
            <module-dependencies/>
47
            <friend-packages>
47
            <friend-packages>
48
                <friend>org.netbeans.modules.groovy.editor</friend>
48
                <friend>org.netbeans.modules.groovy.editor</friend>
49
                <friend>org.netbeans.modules.groovy.support</friend>
49
                <friend>org.netbeans.modules.groovy.refactoring</friend>
50
                <friend>org.netbeans.modules.groovy.refactoring</friend>
50
                <package>groovy.lang</package>
51
                <package>groovy.lang</package>
51
                <package>groovyjarjarantlr</package>
52
                <package>groovyjarjarantlr</package>

Return to bug 212829