sdedic commented on code in PR #3995:
URL: https://github.com/apache/netbeans/pull/3995#discussion_r924870096
##########
java/junit.ui/src/org/netbeans/modules/junit/ui/actions/TestClassInfoTask.java:
##########
@@ -178,6 +177,15 @@ private static void collect(CompilationInfo info, TreePath
clazz, List<TreePath>
}
}
+ private static String getEnclosingType(String fqClassName, String
fileName) {
+ // drop the package name
+ String classOnly = fqClassName.substring(fqClassName.lastIndexOf('.')
+ 1);
+ if (classOnly.startsWith(fileName) && classOnly.length() >
fileName.length()) {
+ return classOnly.substring(fileName.length());
+ }
+ return null;
Review Comment:
Note: there may be multiple toplevel classes in a file: how is supposed the
`SingleMethod` to capture that ?
##########
ide/projectapi/src/org/netbeans/spi/project/SingleMethod.java:
##########
@@ -31,6 +32,7 @@ public final class SingleMethod {
private FileObject file;
private String methodName;
+ private String enclosingType = null;
Review Comment:
Unnecessary `null` assignment; but possible the field could be `final` as as
well as the others
##########
java/maven.junit/src/org/netbeans/modules/maven/junit/JUnitOutputListenerProvider.java:
##########
@@ -681,6 +681,13 @@ private void generateTest() {
}
}
+ String classname = testcase.getAttributeValue("classname");
+ // keep the embedded class in classnames and add to display
name
+ int suiteNameLength = suite.getName().length();
+ if (classname.length() > suiteNameLength &&
classname.startsWith(suite.getName())) {
+ displayName = classname.substring(suiteNameLength) + "." +
methodName;
Review Comment:
Q: when is this code path executed ? I have tried running the whole
testsuite, and a single method within a nested class, but did not hit the
branch. I am asking bcs it seems as there should be '.' or '$' at
`suiteNameLength`-th character, so '.' would be duplicated.
##########
ide/projectapi/src/org/netbeans/spi/project/SingleMethod.java:
##########
@@ -54,6 +56,19 @@ public SingleMethod(FileObject file, String methodName) {
this.methodName = methodName;
}
+ public SingleMethod(FileObject file, String methodName, String
enclosingType) {
Review Comment:
Document the syntax of the enclosing type: should it be FQN, or just
fragment starting from the simple name of the toplevel class in the file ... ?
Note that from the other usages, it seems that the `enclosingType` must start
with `$` character. While possible, it's not a nice API ;)
##########
ide/projectapi/src/org/netbeans/spi/project/SingleMethod.java:
##########
@@ -54,6 +56,19 @@ public SingleMethod(FileObject file, String methodName) {
this.methodName = methodName;
}
+ public SingleMethod(FileObject file, String methodName, String
enclosingType) {
+ super();
+ if (file == null) {
+ throw new IllegalArgumentException("file is <null>");
Review Comment:
Consider to use `org.openide.util.Parameters.notNull()`
##########
java/maven.junit.ui/src/org/netbeans/modules/maven/junit/ui/MavenJUnitNodeOpener.java:
##########
@@ -114,11 +114,16 @@ public void run(CompilationController
compilationController) throws Exception {
compilationController.toPhase(Phase.ELEMENTS_RESOLVED);
Trees trees = compilationController.getTrees();
CompilationUnitTree compilationUnitTree =
compilationController.getCompilationUnit();
+ String desiredClassName =
extractDeepestClass(node.getTestcase().getClassName());
List<? extends Tree> typeDecls =
compilationUnitTree.getTypeDecls();
for (Tree tree : typeDecls) {
Element element =
trees.getElement(trees.getPath(compilationUnitTree, tree));
- if (element != null && element.getKind() ==
ElementKind.CLASS &&
element.getSimpleName().contentEquals(fo2open[0].getName())) {
- List<? extends ExecutableElement>
methodElements = ElementFilter.methodsIn(element.getEnclosedElements());
+ Element classElement =
getClassElement(element, desiredClassName);
Review Comment:
this could eventually return another ClassElement within the compilation
unit with the same **simple name**, i.e. in a case
```
class Foo {
class A {
class C {}
}
class B {
class C{}
}
}
```
the `extractDeepestClass(B.C)` seems to produce "C", and
`getClassElement("C")` could find A.C instead of B.C ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists