a better NPE fix

This commit is contained in:
peter
2010-06-26 22:10:05 +04:00
parent 529b5533df
commit 614d5a6061
16 changed files with 29 additions and 31 deletions
@@ -41,6 +41,6 @@ public class JavaAnnotationIndex extends StringStubIndexExtension<PsiAnnotation>
}
public Collection<PsiAnnotation> get(final String s, final Project project, final GlobalSearchScope scope) {
return super.get(s, project, new JavaSourceFilterScope(scope, project));
return super.get(s, project, new JavaSourceFilterScope(scope));
}
}
@@ -42,6 +42,6 @@ public class JavaAnonymousClassBaseRefOccurenceIndex extends StringStubIndexExte
}
public Collection<PsiAnonymousClass> get(final String s, final Project project, final GlobalSearchScope scope) {
return super.get(s, project, new JavaSourceFilterScope(scope, project));
return super.get(s, project, new JavaSourceFilterScope(scope));
}
}
@@ -41,6 +41,6 @@ public class JavaFieldNameIndex extends StringStubIndexExtension<PsiField> {
}
public Collection<PsiField> get(final String s, final Project project, final GlobalSearchScope scope) {
return super.get(s, project, new JavaSourceFilterScope(scope, project));
return super.get(s, project, new JavaSourceFilterScope(scope));
}
}
@@ -41,6 +41,6 @@ public class JavaFullClassNameIndex extends IntStubIndexExtension<PsiClass> {
}
public Collection<PsiClass> get(final Integer integer, final Project project, final GlobalSearchScope scope) {
return super.get(integer, project, new JavaSourceFilterScope(scope, project));
return super.get(integer, project, new JavaSourceFilterScope(scope));
}
}
@@ -41,6 +41,6 @@ public class JavaMethodNameIndex extends StringStubIndexExtension<PsiMethod> {
}
public Collection<PsiMethod> get(final String s, final Project project, final GlobalSearchScope scope) {
return super.get(s, project, new JavaSourceFilterScope(scope, project));
return super.get(s, project, new JavaSourceFilterScope(scope));
}
}
@@ -41,7 +41,7 @@ public class JavaShortClassNameIndex extends StringStubIndexExtension<PsiClass>
}
public Collection<PsiClass> get(final String s, final Project project, final GlobalSearchScope scope) {
return super.get(s, project, new JavaSourceFilterScope(scope, project));
return super.get(s, project, new JavaSourceFilterScope(scope));
}
}
@@ -12,6 +12,7 @@ import com.intellij.psi.*;
import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.java.stubs.index.JavaAnonymousClassBaseRefOccurenceIndex;
import com.intellij.psi.impl.java.stubs.index.JavaSuperClassNameOccurenceIndex;
import com.intellij.psi.search.EverythingGlobalScope;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.AllClassesSearch;
@@ -60,7 +61,7 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
});
}
final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : null;
final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : new EverythingGlobalScope(psiManager.getProject());
final String searchKey = aClass.getName();
if (StringUtil.isEmpty(searchKey)) {
return true;
@@ -34,7 +34,7 @@ public class JavaLikeSourceFilterScope extends JavaSourceFilterScope {
private final ProjectFileIndex myIndex;
public JavaLikeSourceFilterScope(final GlobalSearchScope delegate, final Project project) {
super(delegate, project);
super(delegate);
myDelegate = delegate;
myIndex = ProjectRootManager.getInstance(project).getFileIndex();
}
@@ -21,7 +21,6 @@ package com.intellij.psi.impl.search;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.VirtualFile;
@@ -31,9 +30,9 @@ import com.intellij.psi.search.GlobalSearchScope;
public class JavaSourceFilterScope extends DelegatingGlobalSearchScope {
private final ProjectFileIndex myIndex;
public JavaSourceFilterScope(final GlobalSearchScope delegate, final Project project) {
super(delegate, project);
myIndex = ProjectRootManager.getInstance(project).getFileIndex();
public JavaSourceFilterScope(final GlobalSearchScope delegate) {
super(delegate);
myIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
}
public boolean contains(final VirtualFile file) {
@@ -1,7 +1,6 @@
package com.intellij.psi.search;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
@@ -11,8 +10,8 @@ import org.jetbrains.annotations.NotNull;
public class DelegatingGlobalSearchScope extends GlobalSearchScope {
protected final GlobalSearchScope myBaseScope;
public DelegatingGlobalSearchScope(GlobalSearchScope baseScope, Project project) {
super(project);
public DelegatingGlobalSearchScope(@NotNull GlobalSearchScope baseScope) {
super(baseScope.getProject());
myBaseScope = baseScope;
}
@@ -534,7 +534,7 @@ public abstract class GlobalSearchScope extends SearchScope implements ProjectAw
private final FileType[] myFileTypes;
private FileTypeRestrictionScope(@NotNull GlobalSearchScope scope, @NotNull FileType[] fileTypes) {
super(scope, scope.getProject());
super(scope);
myFileTypes = fileTypes;
}
@@ -62,7 +62,7 @@ public class MethodLateBoundReferencesSearcher extends QueryExecutorBase<PsiRefe
final VirtualFile vfile = file.getOriginalFile().getVirtualFile();
final Project project = method.getProject();
if (vfile != null && ProjectRootManager.getInstance(project).getFileIndex().isInSource(vfile)) {
return new GrSourceFilterScope((GlobalSearchScope)scope, project);
return new GrSourceFilterScope((GlobalSearchScope)scope);
}
}
return scope;
@@ -15,7 +15,6 @@
*/
package org.jetbrains.plugins.groovy.lang.psi.impl.search;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.VirtualFile;
@@ -30,9 +29,9 @@ import org.jetbrains.plugins.groovy.GroovyFileType;
public class GrSourceFilterScope extends DelegatingGlobalSearchScope {
private final ProjectFileIndex myIndex;
public GrSourceFilterScope(@NotNull final GlobalSearchScope delegate, final Project project) {
super(delegate, project);
myIndex = ProjectRootManager.getInstance(project).getFileIndex();
public GrSourceFilterScope(@NotNull final GlobalSearchScope delegate) {
super(delegate);
myIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
}
public boolean contains(final VirtualFile file) {
@@ -40,6 +40,6 @@ public class GrFullClassNameIndex extends IntStubIndexExtension<PsiClass> {
}
public Collection<PsiClass> get(final Integer integer, final Project project, final GlobalSearchScope scope) {
return super.get(integer, project, new GrSourceFilterScope(scope, project));
return super.get(integer, project, new GrSourceFilterScope(scope));
}
}
@@ -40,6 +40,6 @@ public class GrFullScriptNameIndex extends IntStubIndexExtension<GroovyFile> {
}
public Collection<GroovyFile> get(final Integer integer, final Project project, final GlobalSearchScope scope) {
return super.get(integer, project, new GrSourceFilterScope(scope, project));
return super.get(integer, project, new GrSourceFilterScope(scope));
}
}
@@ -52,7 +52,7 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
@NotNull
public PsiClass[] getClassesByName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
final Collection<? extends PsiElement> plainClasses = StubIndex.getInstance().get(GrShortClassNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope, myProject));
final Collection<? extends PsiElement> plainClasses = StubIndex.getInstance().get(GrShortClassNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope));
Collection<PsiClass> allClasses = getAllScriptClasses(name, scope);
if (allClasses.isEmpty() && plainClasses.isEmpty()) return PsiClass.EMPTY_ARRAY;
@@ -65,7 +65,7 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
@Nullable
public PsiClass getClassByFQName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
final Collection<PsiElement> classes = new ArrayList<PsiElement>(StubIndex.getInstance().get(GrFullClassNameIndex.KEY, name.hashCode(), myProject, new GrSourceFilterScope(scope, myProject)));
final Collection<PsiElement> classes = new ArrayList<PsiElement>(StubIndex.getInstance().get(GrFullClassNameIndex.KEY, name.hashCode(), myProject, new GrSourceFilterScope(scope)));
final Collection<PsiClass> scriptClasses = getScriptClassesByFQName(name, scope);
classes.addAll(scriptClasses);
for (PsiElement clazz : classes) {
@@ -79,7 +79,7 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
}
public Collection<PsiClass> getScriptClassesByFQName(final String name, final GlobalSearchScope scope) {
Collection<GroovyFile> scripts = StubIndex.getInstance().get(GrFullScriptNameIndex.KEY, name.hashCode(), myProject, new GrSourceFilterScope(scope, myProject));
Collection<GroovyFile> scripts = StubIndex.getInstance().get(GrFullScriptNameIndex.KEY, name.hashCode(), myProject, new GrSourceFilterScope(scope));
scripts = ContainerUtil.findAll(scripts, new Condition<GroovyFile>() {
public boolean value(final GroovyFile groovyFile) {
final PsiClass clazz = groovyFile.getScriptClass();
@@ -97,7 +97,7 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
public PsiClass[] getClassesByFQName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
final Collection<PsiClass> result = getScriptClassesByFQName(name, scope);
final Collection<? extends PsiElement> classes = StubIndex.getInstance().get(GrFullClassNameIndex.KEY, name.hashCode(), myProject, new GrSourceFilterScope(scope, myProject));
final Collection<? extends PsiElement> classes = StubIndex.getInstance().get(GrFullClassNameIndex.KEY, name.hashCode(), myProject, new GrSourceFilterScope(scope));
if (!classes.isEmpty()) {
//hashcode doesn't guarantee equals
for (PsiElement psiClass : classes) {
@@ -111,7 +111,7 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
}
private Collection<PsiClass> getAllScriptClasses(String name, GlobalSearchScope scope) {
Collection<GroovyFile> files = StubIndex.getInstance().get(GrScriptClassNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope, myProject));
Collection<GroovyFile> files = StubIndex.getInstance().get(GrScriptClassNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope));
files = ContainerUtil.findAll(files, new Condition<GroovyFile>() {
public boolean value(GroovyFile groovyFile) {
return groovyFile.isScript();
@@ -143,8 +143,8 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
@NotNull
public PsiMethod[] getMethodsByName(@NonNls @NotNull String name, @NotNull GlobalSearchScope scope) {
final Collection<? extends PsiMethod> methods = StubIndex.getInstance().get(GrMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope, myProject));
final Collection<? extends PsiMethod> annMethods = StubIndex.getInstance().get(GrAnnotationMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope, myProject));
final Collection<? extends PsiMethod> methods = StubIndex.getInstance().get(GrMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope));
final Collection<? extends PsiMethod> annMethods = StubIndex.getInstance().get(GrAnnotationMethodNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope));
if (methods.isEmpty() && annMethods.isEmpty()) return PsiMethod.EMPTY_ARRAY;
return ArrayUtil
.mergeArrays(annMethods.toArray(new PsiMethod[annMethods.size()]), methods.toArray(new PsiMethod[methods.size()]), PsiMethod.class);
@@ -168,7 +168,7 @@ public class GroovyShortNamesCache extends PsiShortNamesCache {
@NotNull
public PsiField[] getFieldsByName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
final Collection<? extends PsiField> fields = StubIndex.getInstance().get(GrFieldNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope, myProject));
final Collection<? extends PsiField> fields = StubIndex.getInstance().get(GrFieldNameIndex.KEY, name, myProject, new GrSourceFilterScope(scope));
if (fields.isEmpty()) return PsiField.EMPTY_ARRAY;
return fields.toArray(new PsiField[fields.size()]);
}