mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
update resolve scope in Groovy files after adding libraries
This commit is contained in:
@@ -329,6 +329,8 @@
|
||||
|
||||
<psi.referenceContributor implementation="org.jetbrains.plugins.groovy.lang.resolve.providers.GroovyReferenceContributor"/>
|
||||
|
||||
<resolveScopeProvider implementation="org.jetbrains.plugins.groovy.lang.resolve.GroovyResolveScopeProvider"/>
|
||||
|
||||
<java.elementFinder implementation="org.jetbrains.plugins.groovy.lang.psi.impl.javaView.GroovyClassFinder"/>
|
||||
<java.elementFinder implementation="org.jetbrains.plugins.groovy.gant.GantClassFinder"/>
|
||||
<java.shortNamesCache implementation="org.jetbrains.plugins.groovy.lang.stubs.GroovyShortNamesCache"/>
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.psi;
|
||||
|
||||
import com.intellij.psi.FileResolveScopeProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -28,7 +27,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDef
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public interface GroovyFile extends GroovyFileBase, FileResolveScopeProvider {
|
||||
public interface GroovyFile extends GroovyFileBase {
|
||||
GroovyFile[] EMPTY_ARRAY = new GroovyFile[0];
|
||||
|
||||
GrImportStatement[] getImportStatements();
|
||||
|
||||
@@ -19,21 +19,14 @@ package org.jetbrains.plugins.groovy.lang.psi.impl;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.UserDataCache;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.ElementBase;
|
||||
import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.psi.impl.file.impl.FileManagerImpl;
|
||||
import com.intellij.psi.scope.DelegatingScopeProcessor;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
@@ -584,34 +577,5 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private static final UserDataCache<CachedValue<GlobalSearchScope>, GroovyFile, GlobalSearchScope> RESOLVE_SCOPE_CACHE = new UserDataCache<CachedValue<GlobalSearchScope>, GroovyFile, GlobalSearchScope>("RESOLVE_SCOPE_CACHE") {
|
||||
@Override
|
||||
protected CachedValue<GlobalSearchScope> compute(final GroovyFile file, final GlobalSearchScope baseScope) {
|
||||
return CachedValuesManager.getManager(file.getProject()).createCachedValue(new CachedValueProvider<GlobalSearchScope>() {
|
||||
public Result<GlobalSearchScope> compute() {
|
||||
GlobalSearchScope scope = GroovyScriptTypeDetector.getScriptType(file).patchResolveScope(file, baseScope);
|
||||
return Result.create(scope, file, ProjectRootManager.getInstance(file.getProject()));
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
};
|
||||
public GlobalSearchScope getFileResolveScope() {
|
||||
final PsiElement context = getContext();
|
||||
if (context instanceof GroovyFile) {
|
||||
return context.getResolveScope();
|
||||
}
|
||||
|
||||
final VirtualFile vFile = getOriginalFile().getVirtualFile();
|
||||
if (vFile == null) {
|
||||
return GlobalSearchScope.allScope(getProject());
|
||||
}
|
||||
|
||||
final GlobalSearchScope baseScope = ((FileManagerImpl)((PsiManagerEx)getManager()).getFileManager()).getDefaultResolveScope(vFile);
|
||||
if (isScript()) {
|
||||
return RESOLVE_SCOPE_CACHE.get(this, baseScope).getValue();
|
||||
}
|
||||
return baseScope;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.lang.resolve;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.ResolveScopeProvider;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType;
|
||||
import org.jetbrains.plugins.groovy.extensions.GroovyScriptTypeDetector;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GroovyResolveScopeProvider extends ResolveScopeProvider {
|
||||
@Override
|
||||
public GlobalSearchScope getResolveScope(@NotNull VirtualFile file, Project project) {
|
||||
if (file.getFileType() != GroovyFileType.GROOVY_FILE_TYPE) return null;
|
||||
|
||||
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
Module module = projectFileIndex.getModuleForFile(file);
|
||||
|
||||
if (module == null) return null; //groovy files are only in modules
|
||||
|
||||
boolean includeTests = projectFileIndex.isInTestSourceContent(file) || !projectFileIndex.isInSourceContent(file);
|
||||
final GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, includeTests);
|
||||
|
||||
final PsiFile psi = PsiManager.getInstance(project).findFile(file);
|
||||
if (psi instanceof GroovyFile && ((GroovyFile)psi).isScript()) {
|
||||
return GroovyScriptTypeDetector.getScriptType((GroovyFile)psi).patchResolveScope((GroovyFile)psi, scope);
|
||||
}
|
||||
else {
|
||||
return scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user