|
31 | 31 | */ |
32 | 32 | package com.jme3.gde.core.sceneexplorer.nodes.actions.impl; |
33 | 33 |
|
| 34 | +import java.util.ArrayList; |
| 35 | +import java.util.Collections; |
34 | 36 | import java.util.EnumSet; |
| 37 | +import java.util.HashSet; |
35 | 38 | import java.util.Iterator; |
36 | | -import java.util.LinkedList; |
37 | 39 | import java.util.List; |
38 | 40 | import java.util.Set; |
39 | 41 | import javax.lang.model.element.TypeElement; |
|
53 | 55 | import org.netbeans.api.java.source.JavaSource.Phase; |
54 | 56 | import org.netbeans.api.java.source.Task; |
55 | 57 | import org.netbeans.api.project.Project; |
| 58 | +import org.netbeans.api.project.ProjectUtils; |
56 | 59 | import org.netbeans.api.project.SourceGroup; |
57 | 60 | import org.netbeans.api.project.Sources; |
| 61 | +import org.openide.filesystems.FileObject; |
58 | 62 | import org.openide.util.Exceptions; |
59 | 63 |
|
60 | 64 | @SuppressWarnings({"unchecked", "rawtypes"}) |
@@ -84,74 +88,92 @@ private void scanControls() { |
84 | 88 | } |
85 | 89 |
|
86 | 90 | private List<String> getSources() { |
87 | | - Sources sources = proj.getLookup().lookup(Sources.class); |
88 | | - final List<String> list = new LinkedList<String>(); |
89 | | - if (sources != null) { |
| 91 | + Project root = ProjectUtils.rootOf(proj); |
| 92 | + Set<Project> containedProjects = ProjectUtils.getContainedProjects(root, true); |
| 93 | + List<Project> projects = new ArrayList<>(); |
| 94 | + projects.add(root); |
| 95 | + if (containedProjects != null) { |
| 96 | + projects.addAll(containedProjects); |
| 97 | + } |
| 98 | + if (projects.isEmpty()) { |
| 99 | + return Collections.emptyList(); |
| 100 | + } |
| 101 | + |
| 102 | + Set<String> list = new HashSet<>(); |
| 103 | + for (Project project : projects) { |
| 104 | + Sources sources = project.getLookup().lookup(Sources.class); |
| 105 | + if (sources == null) { |
| 106 | + continue; |
| 107 | + } |
| 108 | + |
90 | 109 | 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 | | - } |
| 110 | + if (groups == null) { |
| 111 | + continue; |
| 112 | + } |
136 | 113 |
|
137 | | - TypeMirror superClass = elem.getSuperclass(); |
138 | | - if (superClass == null || superClass.getKind() == TypeKind.NONE) { |
139 | | - break; |
140 | | - } |
| 114 | + for (SourceGroup sourceGroup : groups) { |
| 115 | + FileObject rootFolder = sourceGroup.getRootFolder(); |
| 116 | + final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.getClassPath(rootFolder, ClassPath.BOOT), |
| 117 | + ClassPath.getClassPath(rootFolder, ClassPath.COMPILE), |
| 118 | + ClassPath.getClassPath(rootFolder, ClassPath.SOURCE)); |
| 119 | + |
| 120 | + Set<SearchScope> set = EnumSet.of(ClassIndex.SearchScope.SOURCE); |
| 121 | + Set<ElementHandle<TypeElement>> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set); |
| 122 | + for (Iterator<ElementHandle<TypeElement>> it = types.iterator(); it.hasNext();) { |
| 123 | + final ElementHandle<TypeElement> elementHandle = it.next(); |
| 124 | + JavaSource js = JavaSource.create(cpInfo); |
| 125 | + try { |
| 126 | + js.runUserActionTask(new Task<CompilationController>() { |
| 127 | + @Override |
| 128 | + public void run(CompilationController control) |
| 129 | + throws Exception { |
| 130 | + control.toPhase(Phase.RESOLVED); |
| 131 | + //TODO: check with proper casting check.. gotta get TypeMirror of Control interface.. |
| 132 | + // TypeUtilities util = control.getTypeUtilities();//.isCastable(Types., null) |
| 133 | + // util.isCastable(null, null); |
| 134 | + TypeElement elem = elementHandle.resolve(control); |
| 135 | + if (elem == null) { |
| 136 | + return; |
| 137 | + } |
141 | 138 |
|
142 | | - elem = (TypeElement)((DeclaredType)superClass).asElement(); // Iterate deeper |
143 | | - } while (elem != null); |
| 139 | + String elementName = elem.getQualifiedName().toString(); |
| 140 | + |
| 141 | + if (list.contains(elementName)) /* No duplicates */ { |
| 142 | + return; |
144 | 143 | } |
145 | | - }, false); |
146 | | - } catch (Exception ioe) { |
147 | | - Exceptions.printStackTrace(ioe); |
148 | | - } |
149 | | - } |
150 | 144 |
|
| 145 | + do { |
| 146 | + //Check if it implements control interface |
| 147 | + for (TypeMirror typeMirror : elem.getInterfaces()) { |
| 148 | + String interfaceName = typeMirror.toString(); |
| 149 | + if ("com.jme3.scene.control.Control".equals(interfaceName) && !list.contains(elementName)) { |
| 150 | + list.add(elementName); |
| 151 | + break; |
| 152 | + } |
| 153 | + } |
| 154 | + //Check if it is an AbstractControl |
| 155 | + String className = elem.toString(); |
| 156 | + if ("com.jme3.scene.control.AbstractControl".equals(className) && !list.contains(elementName)) { |
| 157 | + list.add(elementName); |
| 158 | + } |
| 159 | + |
| 160 | + TypeMirror superClass = elem.getSuperclass(); |
| 161 | + if (superClass == null || superClass.getKind() == TypeKind.NONE) { |
| 162 | + break; |
| 163 | + } |
| 164 | + |
| 165 | + elem = (TypeElement) ((DeclaredType) superClass).asElement(); // Iterate deeper |
| 166 | + } while (elem != null); |
| 167 | + } |
| 168 | + }, false); |
| 169 | + } catch (Exception ioe) { |
| 170 | + Exceptions.printStackTrace(ioe); |
| 171 | + } |
151 | 172 | } |
152 | 173 | } |
153 | 174 | } |
154 | | - return list; |
| 175 | + |
| 176 | + return new ArrayList<>(list); |
155 | 177 | } |
156 | 178 |
|
157 | 179 | public void load(Project proj) { |
|
0 commit comments