|
32 | 32 | package com.jme3.gde.core.appstates; |
33 | 33 |
|
34 | 34 | import java.io.IOException; |
| 35 | +import java.util.ArrayList; |
| 36 | +import java.util.Collections; |
35 | 37 | import java.util.EnumSet; |
36 | | -import java.util.LinkedList; |
37 | 38 | import java.util.List; |
38 | 39 | import java.util.Set; |
39 | 40 | import javax.lang.model.element.TypeElement; |
|
54 | 55 | import org.netbeans.api.project.ProjectUtils; |
55 | 56 | import org.netbeans.api.project.SourceGroup; |
56 | 57 | import org.netbeans.api.project.Sources; |
| 58 | +import org.openide.filesystems.FileObject; |
57 | 59 | import org.openide.util.Exceptions; |
58 | 60 |
|
59 | 61 | @SuppressWarnings({"unchecked", "rawtypes"}) |
@@ -83,37 +85,56 @@ private void scanControls() { |
83 | 85 | } |
84 | 86 |
|
85 | 87 | 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 | + |
89 | 106 | 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); |
113 | 133 | } |
114 | 134 | } |
115 | 135 | } |
116 | 136 | } |
| 137 | + |
117 | 138 | return list; |
118 | 139 | } |
119 | 140 |
|
|
0 commit comments