sdedic commented on code in PR #6329: URL: https://github.com/apache/netbeans/pull/6329#discussion_r1407713032
########## java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/api/SourceLauncher.java: ########## @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.file.launcher.api; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil; +import org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider; +import org.openide.filesystems.FileObject; +import org.openide.modules.SpecificationVersion; +import org.openide.util.Lookup; + +/**Holds utilities for source file launcher. + * + */ +public final class SourceLauncher { + + private static final String ENABLE_PREVIEW = "--enable-preview"; + private static final String SOURCE = "--source"; + private static final String CLASS_PATH = "--class-path"; + private static final String CLASSPATH = "-classpath"; + private static final String CP = "-cp"; + private static final String MODULE_PATH = "--module-path"; + private static final String P = "-p"; + + /**Returns {@code true} if and only if the given file is known as a + * file that is handled by a source file launcher. This, in particular, + * typically means the file is outside of a project. + * + * @param file the file to test + * @return {@code true} if and only if the file is known as a file handled by the + * source launcher. {@code false} otherwise. + */ + public static boolean isSourceLauncherFile(FileObject file) { + MultiSourceRootProvider msrp = Lookup.getDefault().lookup(MultiSourceRootProvider.class); + return msrp != null && msrp.isSourceLauncher(file); + } + + public static String joinCommandLines(Iterable<? extends String> inputLines) { + Map<String, String> joinedOptions = new HashMap<>(); + + for (String value : inputLines) { + List<String> args = SingleSourceFileUtil.parseLine(value); + + for (int i = 0; i < args.size(); i++) { + switch (args.get(i)) { + case ENABLE_PREVIEW: + joinedOptions.put(ENABLE_PREVIEW, null); + break; + case CLASSPATH: case CLASS_PATH: case CP: + if (i + 1 < args.size()) { + joinedOptions.put(CLASS_PATH, mergePaths(joinedOptions.get(CLASS_PATH), args.get(i + 1))); + i++; + } + break; + case MODULE_PATH: case P: + if (i + 1 < args.size()) { + joinedOptions.put(MODULE_PATH, mergePaths(joinedOptions.get(MODULE_PATH), args.get(i + 1))); + i++; + } + break; + case SOURCE: + if (i + 1 < args.size()) { + String version = args.get(i + 1); + String testVersion = version; + if (testVersion.startsWith("1.")) { + testVersion = testVersion.substring(2); + } + String existingVersion = joinedOptions.get("--source"); Review Comment: nitpick: use existing constants for strings. ########## java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java: ########## @@ -315,7 +316,10 @@ public void indexingComplete(Set<URL> indexedRoots) { delegates = this.delegates.toArray(new TextDocumentServiceImpl[this.delegates.size()]); } for (TextDocumentServiceImpl delegate : delegates) { - delegate.reRunDiagnostics(); + ProxyLookup augmentedLookup = new ProxyLookup(Lookups.fixed(delegate.client), Lookup.getDefault()); + Lookups.executeWith(augmentedLookup, () -> { Review Comment: probably not needed, but `Server.ConsumeWithLookup` also passes sessionLookup contents and `OperationContext` to client requests. ########## java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java: ########## @@ -0,0 +1,300 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.file.launcher.queries; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.WeakHashMap; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.classpath.GlobalPathRegistry; +import org.netbeans.api.java.classpath.JavaClassPathConstants; +import org.netbeans.api.java.lexer.JavaTokenId; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.api.lexer.TokenHierarchy; +import org.netbeans.api.lexer.TokenSequence; +import org.netbeans.api.queries.FileEncodingQuery; +import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil; +import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation; +import org.netbeans.spi.java.classpath.ClassPathFactory; +import org.netbeans.spi.java.classpath.ClassPathImplementation; +import static org.netbeans.spi.java.classpath.ClassPathImplementation.PROP_RESOURCES; +import org.netbeans.spi.java.classpath.ClassPathProvider; +import org.netbeans.spi.java.classpath.PathResourceImplementation; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; +import org.openide.util.lookup.ServiceProvider; +import org.openide.util.lookup.ServiceProviders; + +@ServiceProviders({ + @ServiceProvider(service=ClassPathProvider.class, position=9_999), + @ServiceProvider(service=MultiSourceRootProvider.class) +}) +public class MultiSourceRootProvider implements ClassPathProvider { + + public static boolean DISABLE_MULTI_SOURCE_ROOT = false; + + //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?) + private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>(); + private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>(); + private Map<FileObject, ClassPath> file2AllPath = new WeakHashMap<>(); + private Map<FileObject, ClassPath> file2ClassPath = new WeakHashMap<>(); + private Map<FileObject, ClassPath> file2ModulePath = new WeakHashMap<>(); + + @Override + public ClassPath findClassPath(FileObject file, String type) { + switch (type) { + case ClassPath.SOURCE: return getSourcePath(file); + case ClassPath.COMPILE: + return attributeBasedPath(file, file2AllPath, "-classpath", "-cp", "--class-path", "--module-path", "-p"); + case JavaClassPathConstants.MODULE_CLASS_PATH: + return attributeBasedPath(file, file2ClassPath, "-classpath", "-cp", "--class-path"); + case JavaClassPathConstants.MODULE_COMPILE_PATH: + return attributeBasedPath(file, file2ModulePath, "--module-path", "-p"); + case ClassPath.BOOT: + case JavaClassPathConstants.MODULE_BOOT_PATH: + return getBootPath(file); + } + return null; + } + + private ClassPath getSourcePath(FileObject file) { + if (DISABLE_MULTI_SOURCE_ROOT) return null; + synchronized (this) { + //XXX: what happens if there's a Java file in user's home??? + if (file.isData() && "text/x-java".equals(file.getMIMEType())) { + return file2SourceCP.computeIfAbsent(file, f -> { + try { + String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file)); + String packName = findPackage(content); + FileObject root = file.getParent(); + + if (packName != null) { + List<String> packageParts = Arrays.asList(packName.split("\\.")); + + Collections.reverse(packageParts); + + for (String packagePart : packageParts) { + if (!root.getNameExt().equalsIgnoreCase(packagePart)) { + //ignore files outside of proper package structure, + //those may too easily lead to using a too general + //directory as a root, leading to too much indexing: + return null; + } + root = root.getParent(); + } + } + + return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak.... + ClassPath srcCP = ClassPathSupport.createClassPath(r); + GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP}); + return srcCP; + }); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + return null; + }); + } else { + FileObject folder = file; + + while (!folder.isRoot()) { + ClassPath cp = root2SourceCP.get(folder); + + if (cp != null) { + return cp; + } + + folder = folder.getParent(); + } + + return null; + } + } + } + + private synchronized FileObject getSourceRootImpl(FileObject file) { + for (FileObject root : root2SourceCP.keySet()) { + if (FileUtil.isParentOf(root, file) || root.equals(file)) { Review Comment: nitpick: flip the clauses, equals() is faster and hopefully peopel won't write much 'single source' packages. ########## java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java: ########## @@ -0,0 +1,300 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.file.launcher.queries; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.WeakHashMap; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.classpath.GlobalPathRegistry; +import org.netbeans.api.java.classpath.JavaClassPathConstants; +import org.netbeans.api.java.lexer.JavaTokenId; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.api.lexer.TokenHierarchy; +import org.netbeans.api.lexer.TokenSequence; +import org.netbeans.api.queries.FileEncodingQuery; +import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil; +import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation; +import org.netbeans.spi.java.classpath.ClassPathFactory; +import org.netbeans.spi.java.classpath.ClassPathImplementation; +import static org.netbeans.spi.java.classpath.ClassPathImplementation.PROP_RESOURCES; +import org.netbeans.spi.java.classpath.ClassPathProvider; +import org.netbeans.spi.java.classpath.PathResourceImplementation; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; +import org.openide.util.lookup.ServiceProvider; +import org.openide.util.lookup.ServiceProviders; + +@ServiceProviders({ + @ServiceProvider(service=ClassPathProvider.class, position=9_999), + @ServiceProvider(service=MultiSourceRootProvider.class) +}) +public class MultiSourceRootProvider implements ClassPathProvider { + + public static boolean DISABLE_MULTI_SOURCE_ROOT = false; + + //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?) + private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>(); + private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>(); + private Map<FileObject, ClassPath> file2AllPath = new WeakHashMap<>(); + private Map<FileObject, ClassPath> file2ClassPath = new WeakHashMap<>(); + private Map<FileObject, ClassPath> file2ModulePath = new WeakHashMap<>(); + + @Override + public ClassPath findClassPath(FileObject file, String type) { + switch (type) { + case ClassPath.SOURCE: return getSourcePath(file); + case ClassPath.COMPILE: + return attributeBasedPath(file, file2AllPath, "-classpath", "-cp", "--class-path", "--module-path", "-p"); + case JavaClassPathConstants.MODULE_CLASS_PATH: + return attributeBasedPath(file, file2ClassPath, "-classpath", "-cp", "--class-path"); + case JavaClassPathConstants.MODULE_COMPILE_PATH: + return attributeBasedPath(file, file2ModulePath, "--module-path", "-p"); + case ClassPath.BOOT: + case JavaClassPathConstants.MODULE_BOOT_PATH: + return getBootPath(file); + } + return null; + } + + private ClassPath getSourcePath(FileObject file) { + if (DISABLE_MULTI_SOURCE_ROOT) return null; + synchronized (this) { + //XXX: what happens if there's a Java file in user's home??? + if (file.isData() && "text/x-java".equals(file.getMIMEType())) { + return file2SourceCP.computeIfAbsent(file, f -> { + try { + String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file)); + String packName = findPackage(content); + FileObject root = file.getParent(); + + if (packName != null) { + List<String> packageParts = Arrays.asList(packName.split("\\.")); + + Collections.reverse(packageParts); + + for (String packagePart : packageParts) { + if (!root.getNameExt().equalsIgnoreCase(packagePart)) { + //ignore files outside of proper package structure, + //those may too easily lead to using a too general + //directory as a root, leading to too much indexing: + return null; + } + root = root.getParent(); + } + } + + return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak.... Review Comment: weak = ? Do you want to store Reference<Classpath> instead of Classpath in the map ? ########## java/java.lsp.server/vscode/src/nbcode.ts: ########## @@ -75,7 +75,7 @@ export function launch( } ideArgs.push(...extraArgs); - if (env['netbeans_debug'] && extraArgs && extraArgs.find(s => s.includes("--list"))) { + if (extraArgs && extraArgs.find(s => s.includes("--list"))) { Review Comment: Why was the env variable condition removed ? ########## java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/LauncherSourceLevelQueryImpl.java: ########## @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.file.launcher.queries; + +import java.util.List; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil; +import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation; +import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2; +import org.openide.filesystems.FileObject; +import org.openide.util.ChangeSupport; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author lahvac + */ +@ServiceProvider(service=SourceLevelQueryImplementation2.class, position=9_999) +public class LauncherSourceLevelQueryImpl implements SourceLevelQueryImplementation2 { + + @Override + public Result getSourceLevel(FileObject javaFile) { + SingleFileOptionsQueryImplementation.Result delegate = SingleSourceFileUtil.getOptionsFor(javaFile); + + if (delegate != null) { + return new ResultImpl(delegate); + } else { + return null; + } + } + + private static final class ResultImpl implements ChangeListener, Result { + + private static final String DEFAULT_SOURCE_LEVEL = + JavaPlatformManager.getDefault().getDefaultPlatform().getSpecification().getVersion().toString(); + + private final ChangeSupport cs = new ChangeSupport(this); + private final SingleFileOptionsQueryImplementation.Result delegate; + private String sourceLevel; + + public ResultImpl(SingleFileOptionsQueryImplementation.Result delegate) { + this.delegate = delegate; + this.delegate.addChangeListener(this); + updateDelegate(); + } + + private void updateDelegate() { + List<String> parsed = SingleSourceFileUtil.parseLine(delegate.getOptions()); + String sourceLevel = DEFAULT_SOURCE_LEVEL; + + for (int i = 0; i < parsed.size(); i++) { + if ("--source".equals(parsed.get(i)) && i + 1 < parsed.size()) { + sourceLevel = parsed.get(i + 1); + } + } + + synchronized (this) { + this.sourceLevel = sourceLevel; Review Comment: nitpick: only fire changes if != ? ########## java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java: ########## @@ -0,0 +1,300 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.file.launcher.queries; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.WeakHashMap; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.netbeans.api.java.classpath.ClassPath; +import org.netbeans.api.java.classpath.GlobalPathRegistry; +import org.netbeans.api.java.classpath.JavaClassPathConstants; +import org.netbeans.api.java.lexer.JavaTokenId; +import org.netbeans.api.java.platform.JavaPlatformManager; +import org.netbeans.api.lexer.TokenHierarchy; +import org.netbeans.api.lexer.TokenSequence; +import org.netbeans.api.queries.FileEncodingQuery; +import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil; +import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation; +import org.netbeans.spi.java.classpath.ClassPathFactory; +import org.netbeans.spi.java.classpath.ClassPathImplementation; +import static org.netbeans.spi.java.classpath.ClassPathImplementation.PROP_RESOURCES; +import org.netbeans.spi.java.classpath.ClassPathProvider; +import org.netbeans.spi.java.classpath.PathResourceImplementation; +import org.netbeans.spi.java.classpath.support.ClassPathSupport; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; +import org.openide.util.lookup.ServiceProvider; +import org.openide.util.lookup.ServiceProviders; + +@ServiceProviders({ + @ServiceProvider(service=ClassPathProvider.class, position=9_999), + @ServiceProvider(service=MultiSourceRootProvider.class) +}) +public class MultiSourceRootProvider implements ClassPathProvider { + + public static boolean DISABLE_MULTI_SOURCE_ROOT = false; + + //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?) + private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>(); + private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>(); + private Map<FileObject, ClassPath> file2AllPath = new WeakHashMap<>(); + private Map<FileObject, ClassPath> file2ClassPath = new WeakHashMap<>(); + private Map<FileObject, ClassPath> file2ModulePath = new WeakHashMap<>(); + + @Override + public ClassPath findClassPath(FileObject file, String type) { + switch (type) { + case ClassPath.SOURCE: return getSourcePath(file); + case ClassPath.COMPILE: + return attributeBasedPath(file, file2AllPath, "-classpath", "-cp", "--class-path", "--module-path", "-p"); + case JavaClassPathConstants.MODULE_CLASS_PATH: + return attributeBasedPath(file, file2ClassPath, "-classpath", "-cp", "--class-path"); + case JavaClassPathConstants.MODULE_COMPILE_PATH: + return attributeBasedPath(file, file2ModulePath, "--module-path", "-p"); + case ClassPath.BOOT: + case JavaClassPathConstants.MODULE_BOOT_PATH: + return getBootPath(file); + } + return null; + } + + private ClassPath getSourcePath(FileObject file) { + if (DISABLE_MULTI_SOURCE_ROOT) return null; + synchronized (this) { + //XXX: what happens if there's a Java file in user's home??? + if (file.isData() && "text/x-java".equals(file.getMIMEType())) { + return file2SourceCP.computeIfAbsent(file, f -> { + try { + String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file)); + String packName = findPackage(content); + FileObject root = file.getParent(); + + if (packName != null) { + List<String> packageParts = Arrays.asList(packName.split("\\.")); + + Collections.reverse(packageParts); + + for (String packagePart : packageParts) { + if (!root.getNameExt().equalsIgnoreCase(packagePart)) { + //ignore files outside of proper package structure, + //those may too easily lead to using a too general + //directory as a root, leading to too much indexing: + return null; + } + root = root.getParent(); + } + } + + return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak.... + ClassPath srcCP = ClassPathSupport.createClassPath(r); + GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP}); + return srcCP; + }); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + return null; + }); + } else { + FileObject folder = file; + + while (!folder.isRoot()) { + ClassPath cp = root2SourceCP.get(folder); + + if (cp != null) { + return cp; + } + + folder = folder.getParent(); + } + + return null; + } + } + } + + private synchronized FileObject getSourceRootImpl(FileObject file) { + for (FileObject root : root2SourceCP.keySet()) { + if (FileUtil.isParentOf(root, file) || root.equals(file)) { + return root; + } + } + + return null; + } + + public FileObject getSourceRoot(FileObject file) { + FileObject root = getSourceRootImpl(file); + + if (root == null) { + getSourcePath(file); + root = getSourceRootImpl(file); + } + + return root; + } + + public boolean isSourceLauncher(FileObject file) { + return getSourceRoot(file) != null; + } + + private ClassPath getBootPath(FileObject file) { + if (isSourceLauncher(file)) { + return JavaPlatformManager.getDefault() + .getDefaultPlatform() + .getBootstrapLibraries(); + } + + return null; + } + + private static final Set<JavaTokenId> IGNORED_TOKENS = EnumSet.of( + JavaTokenId.BLOCK_COMMENT, + JavaTokenId.JAVADOC_COMMENT, + JavaTokenId.LINE_COMMENT, + JavaTokenId.WHITESPACE + ); + + private static final Set<JavaTokenId> STOP_TOKENS = EnumSet.of( Review Comment: maybe `import` could also stop - or is it intentional to allow for common order mismatches ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
