# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\ws\main # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: junit/src/org/netbeans/modules/junit/DefaultPlugin.java --- junit/src/org/netbeans/modules/junit/DefaultPlugin.java +++ junit/src/org/netbeans/modules/junit/DefaultPlugin.java @@ -55,6 +55,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -121,6 +122,8 @@ import static org.netbeans.api.java.classpath.ClassPath.SOURCE; import static org.netbeans.api.java.classpath.ClassPath.COMPILE; import static org.netbeans.api.java.project.JavaProjectConstants.SOURCES_TYPE_JAVA; +import org.netbeans.api.java.source.ClassIndex; +import org.netbeans.api.java.source.ClassIndex.SearchScope; import org.netbeans.modules.gsf.testrunner.api.UnitTestsUsage; import org.netbeans.modules.java.testrunner.GuiUtils; import static org.openide.ErrorManager.ERROR; @@ -317,6 +320,7 @@ false); } + /** * */ @@ -342,11 +346,31 @@ return null; } - ClassPath oppoRootsClassPath = ClassPathSupport - .createClassPath(oppoRootsURLs); - final List oppoFiles = oppoRootsClassPath - .findAllResources(oppoResourceName); - if (oppoFiles.isEmpty()) { + ClassPath oppoRootsClassPath = ClassPathSupport.createClassPath(oppoRootsURLs); + Set oppositeFiles = new java.util.LinkedHashSet(); + if (sourceToTest) { + + FileObject fo = sourceLocation.getFileObject(); + ClassPath bootCp = ClassPath.getClassPath(fo, ClassPath.BOOT); + ClassPath compileCp = ClassPath.getClassPath(fo, ClassPath.COMPILE); + final ClasspathInfo info = ClasspathInfo.create(bootCp, compileCp, oppoRootsClassPath); + + final Set> result = info.getClassIndex().getDeclaredTypes(String.format(".*%s.*(Test|IT)", fo.getName()), ClassIndex.NameKind.REGEXP, EnumSet.of(ClassIndex.SearchScope.SOURCE)); + for (ElementHandle te : result) { + + Set resources = info.getClassIndex().getResources(te, EnumSet.of(ClassIndex.SearchKind.TYPE_REFERENCES), EnumSet.of(SearchScope.SOURCE)); + oppositeFiles.addAll(resources); + System.out.println("resources = " + resources); + } + } else { + oppositeFiles.addAll(oppoRootsClassPath.findAllResources(oppoResourceName)); + } + + + + + + if (oppositeFiles.isEmpty()) { //if (sourceToTest) { // PENDING - offer creation of new test class //} @@ -355,7 +379,8 @@ // final ElementHandle elementHandle = sourceLocation.getElementHandle(); // if (elementHandle == null) { - return new Location(oppoFiles.get(0)/*, null*/); + //FIXME: handle more than one match + return new Location(oppositeFiles.iterator().next()/*, null*/); // } // /* Build SOURCE classpath: */