mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] console: resolve to bundled Groovy classes if Groovy not present in module and its dependencies
This commit is contained in:
@@ -576,6 +576,7 @@
|
||||
|
||||
<java.elementFinder implementation="org.jetbrains.plugins.groovy.lang.psi.impl.javaView.GroovyClassFinder"/>
|
||||
<java.elementFinder implementation="org.jetbrains.plugins.groovy.gant.GantClassFinder"/>
|
||||
<java.elementFinder implementation="org.jetbrains.plugins.groovy.console.GroovyBundledClassFinder"/>
|
||||
<java.shortNamesCache implementation="org.jetbrains.plugins.groovy.lang.stubs.GroovyShortNamesCache"/>
|
||||
|
||||
<projectService
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed 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.jetbrains.plugins.groovy.console;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.StandardFileSystems;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.NonClasspathClassFinder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.config.GroovyFacetUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class GroovyBundledClassFinder extends NonClasspathClassFinder {
|
||||
|
||||
public GroovyBundledClassFinder(Project project) {
|
||||
super(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<VirtualFile> calcClassRoots() {
|
||||
return getBundledGroovyJarRoots();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<VirtualFile> getBundledGroovyJarRoots() {
|
||||
final VirtualFile bundledJar = LocalFileSystem.getInstance().findFileByIoFile(GroovyFacetUtil.getBundledGroovyJar());
|
||||
if (bundledJar != null) {
|
||||
final VirtualFile root = StandardFileSystems.getJarRootForLocalFile(bundledJar);
|
||||
if (root != null) {
|
||||
return Collections.singletonList(root);
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -20,9 +20,12 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.ResolveScopeProvider;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.NonClasspathDirectoriesScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroovyConsoleResolveScopeProvider extends ResolveScopeProvider {
|
||||
|
||||
@Nullable
|
||||
@@ -30,6 +33,15 @@ public class GroovyConsoleResolveScopeProvider extends ResolveScopeProvider {
|
||||
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) {
|
||||
final GroovyConsoleStateService projectConsole = GroovyConsoleStateService.getInstance(project);
|
||||
final Module module = projectConsole.getSelectedModule(file);
|
||||
return module == null || module.isDisposed() ? null : GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
|
||||
if (module == null || module.isDisposed()) return null;
|
||||
|
||||
final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module);
|
||||
if (!GroovyConsoleUtil.hasGroovyAll(module)) {
|
||||
final List<VirtualFile> bundledGroovyJarRoots = GroovyBundledClassFinder.getBundledGroovyJarRoots();
|
||||
if (!bundledGroovyJarRoots.isEmpty()) {
|
||||
return new NonClasspathDirectoriesScope(bundledGroovyJarRoots).uniteWith(moduleScope);
|
||||
}
|
||||
}
|
||||
return moduleScope;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user