Skip to content

Commit 3855957

Browse files
committed
Traverse through the project structure for app states (Gradle)
1 parent d688e6c commit 3855957

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

jme3-core/src/com/jme3/gde/core/appstates/NewAppStateVisualPanel1.java

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
package com.jme3.gde.core.appstates;
3333

3434
import java.io.IOException;
35+
import java.util.ArrayList;
36+
import java.util.Collections;
3537
import java.util.EnumSet;
36-
import java.util.LinkedList;
3738
import java.util.List;
3839
import java.util.Set;
3940
import javax.lang.model.element.TypeElement;
@@ -54,6 +55,7 @@
5455
import org.netbeans.api.project.ProjectUtils;
5556
import org.netbeans.api.project.SourceGroup;
5657
import org.netbeans.api.project.Sources;
58+
import org.openide.filesystems.FileObject;
5759
import org.openide.util.Exceptions;
5860

5961
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -83,37 +85,56 @@ private void scanControls() {
8385
}
8486

8587
private List<String> getSources() {
86-
Sources sources = ProjectUtils.getSources(proj);
87-
final List<String> list = new LinkedList<>();
88-
if (sources != null) {
88+
Project root = ProjectUtils.rootOf(proj);
89+
Set<Project> containedProjects = ProjectUtils.getContainedProjects(root, true);
90+
List<Project> projects = new ArrayList<>();
91+
projects.add(root);
92+
if (containedProjects != null) {
93+
projects.addAll(containedProjects);
94+
}
95+
if (projects.isEmpty()) {
96+
return Collections.emptyList();
97+
}
98+
99+
List<String> list = new ArrayList<>();
100+
for (Project project : projects) {
101+
Sources sources = ProjectUtils.getSources(project);
102+
if (sources == null) {
103+
continue;
104+
}
105+
89106
SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
90-
if (groups != null) {
91-
for (SourceGroup sourceGroup : groups) {
92-
ClasspathInfo cpInfo = ClasspathInfo.create(
93-
ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.BOOT),
94-
ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE),
95-
ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.SOURCE)
96-
);
97-
98-
Set<SearchScope> set = EnumSet.of(ClassIndex.SearchScope.SOURCE);
99-
Set<ElementHandle<TypeElement>> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set);
100-
for (ElementHandle<TypeElement> elementHandle : types) {
101-
JavaSource js = JavaSource.create(cpInfo);
102-
try {
103-
js.runUserActionTask((CompilationController control) -> {
104-
control.toPhase(JavaSource.Phase.RESOLVED);
105-
TypeElement elem = elementHandle.resolve(control);
106-
if (elem != null && doesInheritFromAppState(elem, control.getTypes())) {
107-
list.add(elem.getQualifiedName().toString());
108-
}
109-
}, false);
110-
} catch (IOException ioe) {
111-
Exceptions.printStackTrace(ioe);
112-
}
107+
if (groups == null) {
108+
continue;
109+
}
110+
111+
for (SourceGroup sourceGroup : groups) {
112+
FileObject rootFolder = sourceGroup.getRootFolder();
113+
ClasspathInfo cpInfo = ClasspathInfo.create(
114+
ClassPath.getClassPath(rootFolder, ClassPath.BOOT),
115+
ClassPath.getClassPath(rootFolder, ClassPath.COMPILE),
116+
ClassPath.getClassPath(rootFolder, ClassPath.SOURCE)
117+
);
118+
119+
Set<SearchScope> set = EnumSet.of(ClassIndex.SearchScope.SOURCE);
120+
Set<ElementHandle<TypeElement>> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set);
121+
for (ElementHandle<TypeElement> elementHandle : types) {
122+
JavaSource js = JavaSource.create(cpInfo);
123+
try {
124+
js.runUserActionTask((CompilationController control) -> {
125+
control.toPhase(JavaSource.Phase.RESOLVED);
126+
TypeElement elem = elementHandle.resolve(control);
127+
if (elem != null && doesInheritFromAppState(elem, control.getTypes())) {
128+
list.add(elem.getQualifiedName().toString());
129+
}
130+
}, false);
131+
} catch (IOException ioe) {
132+
Exceptions.printStackTrace(ioe);
113133
}
114134
}
115135
}
116136
}
137+
117138
return list;
118139
}
119140

0 commit comments

Comments
 (0)