Skip to content

Commit 45b1752

Browse files
committed
Traverse through the project structure for controls (Gradle)
1 parent 88208f1 commit 45b1752

File tree

1 file changed

+83
-60
lines changed

1 file changed

+83
-60
lines changed

jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/NewCustomControlVisualPanel1.java

Lines changed: 83 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
*/
3232
package com.jme3.gde.core.sceneexplorer.nodes.actions.impl;
3333

34+
import java.util.ArrayList;
35+
import java.util.Collections;
3436
import java.util.EnumSet;
3537
import java.util.Iterator;
36-
import java.util.LinkedList;
3738
import java.util.List;
3839
import java.util.Set;
3940
import javax.lang.model.element.TypeElement;
@@ -53,6 +54,7 @@
5354
import org.netbeans.api.java.source.JavaSource.Phase;
5455
import org.netbeans.api.java.source.Task;
5556
import org.netbeans.api.project.Project;
57+
import org.netbeans.api.project.ProjectUtils;
5658
import org.netbeans.api.project.SourceGroup;
5759
import org.netbeans.api.project.Sources;
5860
import org.openide.util.Exceptions;
@@ -84,73 +86,94 @@ private void scanControls() {
8486
}
8587

8688
private List<String> getSources() {
87-
Sources sources = proj.getLookup().lookup(Sources.class);
88-
final List<String> list = new LinkedList<String>();
89-
if (sources != null) {
89+
Project root = ProjectUtils.rootOf(proj);
90+
Set<Project> containedProjects = ProjectUtils.getContainedProjects(root, true);
91+
List<Project> projects = new ArrayList<>();
92+
projects.add(root);
93+
if (containedProjects != null) {
94+
projects.addAll(containedProjects);
95+
}
96+
if (projects.isEmpty()) {
97+
return Collections.emptyList();
98+
}
99+
100+
List<String> list = new ArrayList<>();
101+
for (Project project : projects) {
102+
Sources sources = project.getLookup().lookup(Sources.class);
103+
if (sources == null) {
104+
continue;
105+
}
106+
90107
SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
91-
if (groups != null) {
92-
for (SourceGroup sourceGroup : groups) {
93-
final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.BOOT),
94-
ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE),
95-
ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.SOURCE));
96-
97-
Set<SearchScope> set = EnumSet.of(ClassIndex.SearchScope.SOURCE);
98-
Set<ElementHandle<TypeElement>> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set);
99-
for (Iterator<ElementHandle<TypeElement>> it = types.iterator(); it.hasNext();) {
100-
final ElementHandle<TypeElement> elementHandle = it.next();
101-
JavaSource js = JavaSource.create(cpInfo);
102-
try {
103-
js.runUserActionTask(new Task<CompilationController>() {
104-
@Override
105-
public void run(CompilationController control)
106-
throws Exception {
107-
control.toPhase(Phase.RESOLVED);
108-
//TODO: check with proper casting check.. gotta get TypeMirror of Control interface..
109-
// TypeUtilities util = control.getTypeUtilities();//.isCastable(Types., null)
110-
// util.isCastable(null, null);
111-
TypeElement elem = elementHandle.resolve(control);
112-
if (elem == null)
113-
return;
114-
115-
String elementName = elem.getQualifiedName().toString();
116-
117-
if (list.contains(elementName)) /* No duplicates */
118-
return;
119-
120-
do {
121-
//Check if it implements control interface
122-
for (TypeMirror typeMirror : elem.getInterfaces()) {
123-
String interfaceName = typeMirror.toString();
124-
if ("com.jme3.scene.control.Control".equals(interfaceName)) {
125-
if (!list.contains(elementName))
126-
list.add(elementName);
127-
break;
128-
}
129-
}
130-
//Check if it is an AbstractControl
131-
String className = elem.toString();
132-
if ("com.jme3.scene.control.AbstractControl".equals(className)) {
133-
if (!list.contains(elementName))
134-
list.add(elementName);
135-
}
108+
if (groups == null) {
109+
continue;
110+
}
136111

137-
TypeMirror superClass = elem.getSuperclass();
138-
if (superClass == null || superClass.getKind() == TypeKind.NONE) {
139-
break;
140-
}
112+
for (SourceGroup sourceGroup : groups) {
113+
final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.BOOT),
114+
ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE),
115+
ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.SOURCE));
116+
117+
Set<SearchScope> set = EnumSet.of(ClassIndex.SearchScope.SOURCE);
118+
Set<ElementHandle<TypeElement>> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set);
119+
for (Iterator<ElementHandle<TypeElement>> it = types.iterator(); it.hasNext();) {
120+
final ElementHandle<TypeElement> elementHandle = it.next();
121+
JavaSource js = JavaSource.create(cpInfo);
122+
try {
123+
js.runUserActionTask(new Task<CompilationController>() {
124+
@Override
125+
public void run(CompilationController control)
126+
throws Exception {
127+
control.toPhase(Phase.RESOLVED);
128+
//TODO: check with proper casting check.. gotta get TypeMirror of Control interface..
129+
// TypeUtilities util = control.getTypeUtilities();//.isCastable(Types., null)
130+
// util.isCastable(null, null);
131+
TypeElement elem = elementHandle.resolve(control);
132+
if (elem == null) {
133+
return;
134+
}
135+
136+
String elementName = elem.getQualifiedName().toString();
141137

142-
elem = (TypeElement)((DeclaredType)superClass).asElement(); // Iterate deeper
143-
} while (elem != null);
138+
if (list.contains(elementName)) /* No duplicates */ {
139+
return;
144140
}
145-
}, false);
146-
} catch (Exception ioe) {
147-
Exceptions.printStackTrace(ioe);
148-
}
149-
}
150141

142+
do {
143+
//Check if it implements control interface
144+
for (TypeMirror typeMirror : elem.getInterfaces()) {
145+
String interfaceName = typeMirror.toString();
146+
if ("com.jme3.scene.control.Control".equals(interfaceName)) {
147+
if (!list.contains(elementName)) {
148+
list.add(elementName);
149+
}
150+
break;
151+
}
152+
}
153+
//Check if it is an AbstractControl
154+
String className = elem.toString();
155+
if ("com.jme3.scene.control.AbstractControl".equals(className)) {
156+
if (!list.contains(elementName)) {
157+
list.add(elementName);
158+
}
159+
}
160+
161+
TypeMirror superClass = elem.getSuperclass();
162+
if (superClass == null || superClass.getKind() == TypeKind.NONE) {
163+
break;
164+
}
165+
166+
elem = (TypeElement) ((DeclaredType) superClass).asElement(); // Iterate deeper
167+
} while (elem != null);
168+
}
169+
}, false);
170+
} catch (Exception ioe) {
171+
Exceptions.printStackTrace(ioe);
172+
}
151173
}
152174
}
153175
}
176+
154177
return list;
155178
}
156179

0 commit comments

Comments
 (0)