diff --git a/jme3-core/src/com/jme3/gde/core/appstates/NewAppStateVisualPanel1.java b/jme3-core/src/com/jme3/gde/core/appstates/NewAppStateVisualPanel1.java index 84b8352d..d85ecefe 100644 --- a/jme3-core/src/com/jme3/gde/core/appstates/NewAppStateVisualPanel1.java +++ b/jme3-core/src/com/jme3/gde/core/appstates/NewAppStateVisualPanel1.java @@ -32,8 +32,9 @@ package com.jme3.gde.core.appstates; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; import java.util.EnumSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; import javax.lang.model.element.TypeElement; @@ -54,6 +55,7 @@ import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; +import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; @SuppressWarnings({"unchecked", "rawtypes"}) @@ -83,37 +85,56 @@ private void scanControls() { } private List getSources() { - Sources sources = ProjectUtils.getSources(proj); - final List list = new LinkedList<>(); - if (sources != null) { + Project root = ProjectUtils.rootOf(proj); + Set containedProjects = ProjectUtils.getContainedProjects(root, true); + List projects = new ArrayList<>(); + projects.add(root); + if (containedProjects != null) { + projects.addAll(containedProjects); + } + if (projects.isEmpty()) { + return Collections.emptyList(); + } + + List list = new ArrayList<>(); + for (Project project : projects) { + Sources sources = ProjectUtils.getSources(project); + if (sources == null) { + continue; + } + SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); - if (groups != null) { - for (SourceGroup sourceGroup : groups) { - ClasspathInfo cpInfo = ClasspathInfo.create( - ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.BOOT), - ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE), - ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.SOURCE) - ); - - Set set = EnumSet.of(ClassIndex.SearchScope.SOURCE); - Set> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set); - for (ElementHandle elementHandle : types) { - JavaSource js = JavaSource.create(cpInfo); - try { - js.runUserActionTask((CompilationController control) -> { - control.toPhase(JavaSource.Phase.RESOLVED); - TypeElement elem = elementHandle.resolve(control); - if (elem != null && doesInheritFromAppState(elem, control.getTypes())) { - list.add(elem.getQualifiedName().toString()); - } - }, false); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } + if (groups == null) { + continue; + } + + for (SourceGroup sourceGroup : groups) { + FileObject rootFolder = sourceGroup.getRootFolder(); + ClasspathInfo cpInfo = ClasspathInfo.create( + ClassPath.getClassPath(rootFolder, ClassPath.BOOT), + ClassPath.getClassPath(rootFolder, ClassPath.COMPILE), + ClassPath.getClassPath(rootFolder, ClassPath.SOURCE) + ); + + Set set = EnumSet.of(ClassIndex.SearchScope.SOURCE); + Set> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set); + for (ElementHandle elementHandle : types) { + JavaSource js = JavaSource.create(cpInfo); + try { + js.runUserActionTask((CompilationController control) -> { + control.toPhase(JavaSource.Phase.RESOLVED); + TypeElement elem = elementHandle.resolve(control); + if (elem != null && doesInheritFromAppState(elem, control.getTypes())) { + list.add(elem.getQualifiedName().toString()); + } + }, false); + } catch (IOException ioe) { + Exceptions.printStackTrace(ioe); } } } } + return list; } diff --git a/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java b/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java index d19e45d9..aeb49776 100644 --- a/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java +++ b/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java @@ -166,30 +166,30 @@ private void loadClassLoader() { } SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); List urls = new LinkedList<>(); - for (SourceGroup sourceGroup : groups) { - ClassPath path = ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.EXECUTE); - if (path == null) { - continue; - } - - classPaths.add(path); - path.addPropertyChangeListener(classPathListener); - FileObject[] roots = path.getRoots(); - for (FileObject fileObject : roots) { - if (!fileObject.equals(getAssetFolder())) { - fileObject.addRecursiveListener(listener); - logger.log(Level.FINE, "Add classpath:{0}", fileObject); - classPathItems.add(new ClassPathItem(fileObject, listener)); - urls.add(fileObject.toURL()); + for (SourceGroup sourceGroup : groups) { + ClassPath path = ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.EXECUTE); + if (path == null) { + continue; } - if (fileObject.toURL().toExternalForm().startsWith("jar")) { - logger.log(Level.FINE, "Add locator:{0}", fileObject.toURL()); - jarItems.add(fileObject); - registerLocator(fileObject.toURL().toExternalForm(), - "com.jme3.asset.plugins.UrlLocator"); + + classPaths.add(path); + path.addPropertyChangeListener(classPathListener); + FileObject[] roots = path.getRoots(); + for (FileObject fileObject : roots) { + if (!fileObject.equals(getAssetFolder())) { + fileObject.addRecursiveListener(listener); + logger.log(Level.FINE, "Add classpath:{0}", fileObject); + classPathItems.add(new ClassPathItem(fileObject, listener)); + urls.add(fileObject.toURL()); + } + if (fileObject.toURL().toExternalForm().startsWith("jar")) { + logger.log(Level.FINE, "Add locator:{0}", fileObject.toURL()); + jarItems.add(fileObject); + registerLocator(fileObject.toURL().toExternalForm(), + "com.jme3.asset.plugins.UrlLocator"); + } } } - } loadGradleClassLoader(urls); @@ -223,7 +223,7 @@ private void loadGradleClassLoader(List urls) { for (File file : runtimeFiles) { // logger.info(file.getName() + " : " + file.getAbsolutePath()); FileObject fo = FileUtil.toFileObject(file); - if (fo != null && !fo.isFolder()) { + if (fo != null) { logger.info(fo.toURL().toExternalForm()); if (!fo.equals(getAssetFolder())) { fo.addRecursiveListener(listener); diff --git a/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/NewCustomControlVisualPanel1.java b/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/NewCustomControlVisualPanel1.java index 3adbe5b9..6b2acf10 100644 --- a/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/NewCustomControlVisualPanel1.java +++ b/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/NewCustomControlVisualPanel1.java @@ -31,9 +31,11 @@ */ package com.jme3.gde.core.sceneexplorer.nodes.actions.impl; +import java.util.ArrayList; +import java.util.Collections; import java.util.EnumSet; +import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Set; import javax.lang.model.element.TypeElement; @@ -53,8 +55,10 @@ import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.Task; import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.SourceGroup; import org.netbeans.api.project.Sources; +import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; @SuppressWarnings({"unchecked", "rawtypes"}) @@ -84,74 +88,92 @@ private void scanControls() { } private List getSources() { - Sources sources = proj.getLookup().lookup(Sources.class); - final List list = new LinkedList(); - if (sources != null) { + Project root = ProjectUtils.rootOf(proj); + Set containedProjects = ProjectUtils.getContainedProjects(root, true); + List projects = new ArrayList<>(); + projects.add(root); + if (containedProjects != null) { + projects.addAll(containedProjects); + } + if (projects.isEmpty()) { + return Collections.emptyList(); + } + + Set list = new HashSet<>(); + for (Project project : projects) { + Sources sources = project.getLookup().lookup(Sources.class); + if (sources == null) { + continue; + } + SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); - if (groups != null) { - for (SourceGroup sourceGroup : groups) { - final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.BOOT), - ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.COMPILE), - ClassPath.getClassPath(sourceGroup.getRootFolder(), ClassPath.SOURCE)); - - Set set = EnumSet.of(ClassIndex.SearchScope.SOURCE); - Set> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set); - for (Iterator> it = types.iterator(); it.hasNext();) { - final ElementHandle elementHandle = it.next(); - JavaSource js = JavaSource.create(cpInfo); - try { - js.runUserActionTask(new Task() { - @Override - public void run(CompilationController control) - throws Exception { - control.toPhase(Phase.RESOLVED); - //TODO: check with proper casting check.. gotta get TypeMirror of Control interface.. -// TypeUtilities util = control.getTypeUtilities();//.isCastable(Types., null) -// util.isCastable(null, null); - TypeElement elem = elementHandle.resolve(control); - if (elem == null) - return; - - String elementName = elem.getQualifiedName().toString(); - - if (list.contains(elementName)) /* No duplicates */ - return; - - do { - //Check if it implements control interface - for (TypeMirror typeMirror : elem.getInterfaces()) { - String interfaceName = typeMirror.toString(); - if ("com.jme3.scene.control.Control".equals(interfaceName)) { - if (!list.contains(elementName)) - list.add(elementName); - break; - } - } - //Check if it is an AbstractControl - String className = elem.toString(); - if ("com.jme3.scene.control.AbstractControl".equals(className)) { - if (!list.contains(elementName)) - list.add(elementName); - } + if (groups == null) { + continue; + } - TypeMirror superClass = elem.getSuperclass(); - if (superClass == null || superClass.getKind() == TypeKind.NONE) { - break; - } + for (SourceGroup sourceGroup : groups) { + FileObject rootFolder = sourceGroup.getRootFolder(); + final ClasspathInfo cpInfo = ClasspathInfo.create(ClassPath.getClassPath(rootFolder, ClassPath.BOOT), + ClassPath.getClassPath(rootFolder, ClassPath.COMPILE), + ClassPath.getClassPath(rootFolder, ClassPath.SOURCE)); + + Set set = EnumSet.of(ClassIndex.SearchScope.SOURCE); + Set> types = cpInfo.getClassIndex().getDeclaredTypes("", NameKind.PREFIX, set); + for (Iterator> it = types.iterator(); it.hasNext();) { + final ElementHandle elementHandle = it.next(); + JavaSource js = JavaSource.create(cpInfo); + try { + js.runUserActionTask(new Task() { + @Override + public void run(CompilationController control) + throws Exception { + control.toPhase(Phase.RESOLVED); + //TODO: check with proper casting check.. gotta get TypeMirror of Control interface.. + // TypeUtilities util = control.getTypeUtilities();//.isCastable(Types., null) + // util.isCastable(null, null); + TypeElement elem = elementHandle.resolve(control); + if (elem == null) { + return; + } - elem = (TypeElement)((DeclaredType)superClass).asElement(); // Iterate deeper - } while (elem != null); + String elementName = elem.getQualifiedName().toString(); + + if (list.contains(elementName)) /* No duplicates */ { + return; } - }, false); - } catch (Exception ioe) { - Exceptions.printStackTrace(ioe); - } - } + do { + //Check if it implements control interface + for (TypeMirror typeMirror : elem.getInterfaces()) { + String interfaceName = typeMirror.toString(); + if ("com.jme3.scene.control.Control".equals(interfaceName) && !list.contains(elementName)) { + list.add(elementName); + break; + } + } + //Check if it is an AbstractControl + String className = elem.toString(); + if ("com.jme3.scene.control.AbstractControl".equals(className) && !list.contains(elementName)) { + list.add(elementName); + } + + TypeMirror superClass = elem.getSuperclass(); + if (superClass == null || superClass.getKind() == TypeKind.NONE) { + break; + } + + elem = (TypeElement) ((DeclaredType) superClass).asElement(); // Iterate deeper + } while (elem != null); + } + }, false); + } catch (Exception ioe) { + Exceptions.printStackTrace(ioe); + } } } } - return list; + + return new ArrayList<>(list); } public void load(Project proj) {