Merge branch 'upsource-master'

This commit is contained in:
Evgeny Pasynkov
2012-07-30 16:13:19 +02:00
25 changed files with 56 additions and 13 deletions
@@ -24,7 +24,6 @@ import com.intellij.codeInsight.generation.PsiFieldMember;
import com.intellij.codeInsight.generation.PsiMethodMember;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.AssignFieldFromParameterAction;
import com.intellij.codeInsight.intention.impl.CreateFieldFromParameterAction;
import com.intellij.codeInsight.intention.impl.FieldFromParameterUtils;
import com.intellij.ide.util.MemberChooser;
import com.intellij.openapi.application.ApplicationManager;
@@ -47,7 +47,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class JavaDocInfoGenerator {
@@ -1,49 +0,0 @@
/*
* Copyright 2000-2009 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.
*/
/*
* @author max
*/
package com.intellij.psi.impl.java.stubs.index;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.impl.search.JavaSourceFilterScope;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StringStubIndexExtension;
import com.intellij.psi.stubs.StubIndexKey;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
public class JavaAnnotationIndex extends StringStubIndexExtension<PsiAnnotation> {
private static final JavaAnnotationIndex ourInstance = new JavaAnnotationIndex();
public static JavaAnnotationIndex getInstance() {
return ourInstance;
}
@NotNull
@Override
public StubIndexKey<String, PsiAnnotation> getKey() {
return JavaStubIndexKeys.ANNOTATIONS;
}
@Override
public Collection<PsiAnnotation> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
return super.get(s, project, new JavaSourceFilterScope(scope));
}
}
@@ -1,132 +0,0 @@
/*
* Copyright 2000-2009 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.
*/
/*
* @author max
*/
package com.intellij.psi.impl.search;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.PsiShortNamesCache;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.AllClassesSearch;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class AllClassesSearchExecutor implements QueryExecutor<PsiClass, AllClassesSearch.SearchParameters> {
@Override
public boolean execute(@NotNull final AllClassesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiClass> consumer) {
SearchScope scope = queryParameters.getScope();
if (scope instanceof GlobalSearchScope) {
return processAllClassesInGlobalScope((GlobalSearchScope)scope, consumer, queryParameters);
}
PsiElement[] scopeRoots = ((LocalSearchScope)scope).getScope();
for (final PsiElement scopeRoot : scopeRoots) {
if (!processScopeRootForAllClasses(scopeRoot, consumer)) return false;
}
return true;
}
private static boolean processAllClassesInGlobalScope(final GlobalSearchScope scope, final Processor<PsiClass> processor, AllClassesSearch.SearchParameters parameters) {
final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(parameters.getProject());
final String[] names = ApplicationManager.getApplication().runReadAction(new Computable<String[]>() {
@Override
public String[] compute() {
return cache.getAllClassNames();
}
});
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator != null) {
indicator.checkCanceled();
}
List<String> sorted = new ArrayList<String>(names.length);
for (int i = 0; i < names.length; i++) {
String name = names[i];
if (parameters.nameMatches(name)) {
sorted.add(name);
}
if (indicator != null && i % 512 == 0) {
indicator.checkCanceled();
}
}
if (indicator != null) {
indicator.checkCanceled();
}
Collections.sort(sorted, new Comparator<String>() {
@Override
public int compare(final String o1, final String o2) {
return o1.compareToIgnoreCase(o2);
}
});
for (final String name : sorted) {
ProgressManager.checkCanceled();
final PsiClass[] classes = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass[]>() {
@Override
public PsiClass[] compute() {
return cache.getClassesByName(name, scope);
}
});
for (PsiClass psiClass : classes) {
ProgressManager.checkCanceled();
if (!processor.process(psiClass)) {
return false;
}
}
}
return true;
}
private static boolean processScopeRootForAllClasses(PsiElement scopeRoot, final Processor<PsiClass> processor) {
if (scopeRoot == null) return true;
final boolean[] stopped = new boolean[]{false};
scopeRoot.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
if (!stopped[0]) {
super.visitElement(element);
}
}
@Override public void visitClass(PsiClass aClass) {
stopped[0] = !processor.process(aClass);
super.visitClass(aClass);
}
});
return !stopped[0];
}
}
@@ -1,134 +0,0 @@
package com.intellij.psi.impl.search;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.AnnotatedElementsSearch;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import com.intellij.util.indexing.FileBasedIndex;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
/**
* @author max
*/
public class AnnotatedElementsSearcher implements QueryExecutor<PsiModifierListOwner, AnnotatedElementsSearch.Parameters> {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.search.AnnotatedMembersSearcher");
@Override
public boolean execute(@NotNull final AnnotatedElementsSearch.Parameters p, @NotNull final Processor<PsiModifierListOwner> consumer) {
final PsiClass annClass = p.getAnnotationClass();
assert annClass.isAnnotationType() : "Annotation type should be passed to annotated members search";
final String annotationFQN = annClass.getQualifiedName();
assert annotationFQN != null;
final PsiManagerImpl psiManager = (PsiManagerImpl)annClass.getManager();
final SearchScope useScope = p.getScope();
Class<? extends PsiModifierListOwner>[] types = p.getTypes();
for (PsiElement elt : getAnnotationCandidates(annClass, useScope)) {
if (notAnnotation(elt)) continue;
final PsiAnnotation ann = (PsiAnnotation)elt;
final PsiJavaCodeReferenceElement ref = ApplicationManager.getApplication().runReadAction(new Computable<PsiJavaCodeReferenceElement>() {
@Override
public PsiJavaCodeReferenceElement compute() {
return ann.getNameReferenceElement();
}
});
if (ref == null) continue;
PsiElement parent = ann.getParent();
if (!(parent instanceof PsiModifierList)) continue; // Can be a PsiNameValuePair, if annotation is used to annotate annotation parameters
final PsiElement owner = parent.getParent();
if (!isInstanceof(owner, types)) continue;
final PsiModifierListOwner candidate = (PsiModifierListOwner)owner;
if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
if (!candidate.isValid()) {
return false;
}
if (!psiManager.areElementsEquivalent(ref.resolve(), annClass)) {
return false;
}
if (useScope instanceof GlobalSearchScope &&
!((GlobalSearchScope)useScope).contains(candidate.getContainingFile().getVirtualFile())) {
return false;
}
return true;
}
})) {
continue;
}
if (!consumer.process(candidate)) {
return false;
}
}
return true;
}
private static Collection<? extends PsiElement> getAnnotationCandidates(final PsiClass annClass, SearchScope useScope) {
AccessToken token = ReadAction.start();
try {
if (useScope instanceof GlobalSearchScope) {
return JavaAnnotationIndex.getInstance().get(annClass.getName(), annClass.getProject(), (GlobalSearchScope)useScope);
}
final ArrayList<PsiAnnotation> result = new ArrayList<PsiAnnotation>();
for (PsiElement element : ((LocalSearchScope)useScope).getScope()) {
element.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element instanceof PsiAnnotation) {
result.add((PsiAnnotation)element);
}
}
});
}
return result;
}
finally {
token.finish();
}
}
public static boolean isInstanceof(PsiElement owner, Class<? extends PsiModifierListOwner>[] types) {
for (Class<? extends PsiModifierListOwner> type : types) {
if(type.isInstance(owner)) return true;
}
return false;
}
private static boolean notAnnotation(final PsiElement found) {
if (found instanceof PsiAnnotation) return false;
VirtualFile faultyContainer = PsiUtil.getVirtualFile(found);
LOG.error("Non annotation in annotations list: " + faultyContainer+"; element:"+found);
if (faultyContainer != null && faultyContainer.isValid()) {
FileBasedIndex.getInstance().requestReindex(faultyContainer);
}
return true;
}
}
@@ -1,84 +0,0 @@
/*
* Copyright 2000-2009 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 com.intellij.psi.impl.search;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.*;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.AllOverridingMethodsSearch;
import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.psi.util.MethodSignature;
import com.intellij.psi.util.MethodSignatureUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* @author ven
*/
public class JavaAllOverridingMethodsSearcher implements QueryExecutor<Pair<PsiMethod, PsiMethod>, AllOverridingMethodsSearch.SearchParameters> {
@Override
public boolean execute(@NotNull final AllOverridingMethodsSearch.SearchParameters p, @NotNull final Processor<Pair<PsiMethod, PsiMethod>> consumer) {
final PsiClass psiClass = p.getPsiClass();
PsiMethod[] methodsArray = psiClass.getMethods();
final List<PsiMethod> methods = new ArrayList<PsiMethod>(methodsArray.length);
for (PsiMethod method : methodsArray) {
if (PsiUtil.canBeOverriden(method)) methods.add(method);
}
final SearchScope scope = p.getScope();
Processor<PsiClass> inheritorsProcessor = new Processor<PsiClass>() {
@Override
public boolean process(PsiClass inheritor) {
//could be null if not java inheritor, TODO only JavaClassInheritors are needed
PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(psiClass, inheritor, PsiSubstitutor.EMPTY);
if (substitutor == null) return true;
for (PsiMethod method : methods) {
if (method.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) &&
!JavaPsiFacade.getInstance(inheritor.getProject()).arePackagesTheSame(psiClass, inheritor)) continue;
MethodSignature signature = method.getSignature(substitutor);
PsiMethod inInheritor = MethodSignatureUtil.findMethodBySuperSignature(inheritor, signature, false);
if (inInheritor == null || inInheritor.hasModifierProperty(PsiModifier.STATIC)) {
if (psiClass.isInterface() && !inheritor.isInterface()) { //check for sibling implementation
final PsiClass superClass = inheritor.getSuperClass();
if (superClass != null && !superClass.isInheritor(psiClass, true)) {
inInheritor = MethodSignatureUtil.findMethodInSuperClassBySignatureInDerived(inheritor, superClass, signature, true);
if (inInheritor != null && !inInheritor.hasModifierProperty(PsiModifier.STATIC)) {
if (!consumer.process(new Pair<PsiMethod, PsiMethod>(method, inInheritor))) return false;
}
}
}
continue;
}
if (!consumer.process(new Pair<PsiMethod, PsiMethod>(method, inInheritor))) return false;
}
return true;
}
};
return ClassInheritorsSearch.search(psiClass, scope, true).forEach(inheritorsProcessor);
}
}
@@ -1,41 +0,0 @@
package com.intellij.psi.impl.search;
import com.intellij.psi.PsiMethod;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
/**
* @author peter
*/
public class MethodDeepestSuperSearcher implements QueryExecutor<PsiMethod, PsiMethod> {
@Override
public boolean execute(@NotNull PsiMethod method, @NotNull Processor<PsiMethod> consumer) {
final Set<PsiMethod> methods = new THashSet<PsiMethod>();
methods.add(method);
return findDeepestSuperOrSelfSignature(method, methods, null, consumer);
}
private static boolean findDeepestSuperOrSelfSignature(PsiMethod method,
Set<PsiMethod> set,
Set<PsiMethod> guard,
Processor<PsiMethod> processor) {
if (guard != null && !guard.add(method)) return true;
PsiMethod[] supers = method.findSuperMethods();
if (supers.length == 0 && set.add(method) && !processor.process(method)) {
return false;
}
for (PsiMethod superMethod : supers) {
if (guard == null) {
guard = new THashSet<PsiMethod>();
guard.add(method);
}
if (!findDeepestSuperOrSelfSignature(superMethod, set, guard, processor)) return false;
}
return true;
}
}
@@ -1,98 +0,0 @@
/*
* Copyright 2000-2009 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 com.intellij.psi.impl.search;
import com.intellij.psi.*;
import com.intellij.psi.search.RequestResultProcessor;
import com.intellij.psi.util.MethodSignature;
import com.intellij.psi.util.MethodSignatureUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
/**
* @author peter
*/
public final class MethodTextOccurrenceProcessor extends RequestResultProcessor {
private static final PsiReferenceService ourReferenceService = PsiReferenceService.getService();
private final PsiMethod[] myMethods;
private final PsiClass myContainingClass;
private final boolean myStrictSignatureSearch;
public MethodTextOccurrenceProcessor(@NotNull final PsiClass aClass, final boolean strictSignatureSearch, final PsiMethod... methods) {
super(strictSignatureSearch, Arrays.asList(methods));
myMethods = methods;
myContainingClass = aClass;
myStrictSignatureSearch = strictSignatureSearch;
}
@Override
public boolean processTextOccurrence(PsiElement element, int offsetInElement, final Processor<PsiReference> consumer) {
for (PsiReference ref : ourReferenceService.getReferences(element, new PsiReferenceService.Hints(myMethods[0], offsetInElement))) {
if (ReferenceRange.containsOffsetInElement(ref, offsetInElement) && !processReference(consumer, ref)) {
return false;
}
}
return true;
}
private boolean processReference(Processor<PsiReference> consumer, PsiReference ref) {
for (PsiMethod method : myMethods) {
if (!method.isValid()) {
continue;
}
if (ref instanceof ResolvingHint && !((ResolvingHint)ref).canResolveTo(PsiMethod.class)) {
return true;
}
if (ref.isReferenceTo(method)) {
return consumer.process(ref);
}
PsiElement refElement = ref.resolve();
if (refElement instanceof PsiMethod) {
PsiMethod refMethod = (PsiMethod)refElement;
PsiClass refMethodClass = refMethod.getContainingClass();
if (refMethodClass == null) continue;
if (!refMethod.hasModifierProperty(PsiModifier.STATIC)) {
PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(myContainingClass, refMethodClass, PsiSubstitutor.EMPTY);
if (substitutor != null) {
MethodSignature superSignature = method.getSignature(substitutor);
MethodSignature refSignature = refMethod.getSignature(PsiSubstitutor.EMPTY);
if (MethodSignatureUtil.isSubsignature(superSignature, refSignature)) {
if (!consumer.process(ref)) return false;
}
}
}
if (!myStrictSignatureSearch) {
PsiManager manager = method.getManager();
if (manager.areElementsEquivalent(refMethodClass, myContainingClass)) {
if (!consumer.process(ref)) return false;
}
}
}
}
return true;
}
}
@@ -1,77 +0,0 @@
package com.intellij.psi.impl.search;
import com.intellij.openapi.application.QueryExecutorBase;
import com.intellij.psi.*;
import com.intellij.psi.search.SearchRequestCollector;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.UsageSearchContext;
import com.intellij.psi.search.searches.MethodReferencesSearch;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
/**
* @author max
*/
public class MethodUsagesSearcher extends QueryExecutorBase<PsiReference, MethodReferencesSearch.SearchParameters> {
protected MethodUsagesSearcher() {
super(true);
}
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
final PsiMethod method = p.getMethod();
final SearchRequestCollector collector = p.getOptimizer();
final SearchScope searchScope = p.getScope();
final PsiManager psiManager = method.getManager();
final PsiClass aClass = method.getContainingClass();
if (aClass == null) return;
final boolean strictSignatureSearch = p.isStrictSignatureSearch();
if (method.isConstructor()) {
new ConstructorReferencesSearchHelper(psiManager).
processConstructorReferences(consumer, method, searchScope, !strictSignatureSearch, strictSignatureSearch, collector);
}
if (PsiUtil.isAnnotationMethod(method) &&
PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(method.getName()) &&
method.getParameterList().getParametersCount() == 0) {
ReferencesSearch.search(method.getContainingClass(), p.getScope()).forEach(PsiAnnotationMethodReferencesSearcher.createImplicitDefaultAnnotationMethodConsumer(
consumer));
}
boolean needStrictSignatureSearch = strictSignatureSearch && (aClass instanceof PsiAnonymousClass
|| aClass.hasModifierProperty(PsiModifier.FINAL)
|| method.hasModifierProperty(PsiModifier.STATIC)
|| method.hasModifierProperty(PsiModifier.FINAL)
|| method.hasModifierProperty(PsiModifier.PRIVATE));
if (needStrictSignatureSearch) {
ReferencesSearch.searchOptimized(method, searchScope, false, collector, consumer);
return;
}
final String textToSearch = method.getName();
final PsiMethod[] methods = strictSignatureSearch ? new PsiMethod[]{method} : aClass.findMethodsByName(textToSearch, false);
SearchScope accessScope = methods[0].getUseScope();
for (int i = 1; i < methods.length; i++) {
PsiMethod method1 = methods[i];
accessScope = accessScope.union(method1.getUseScope());
}
final SearchScope restrictedByAccess = searchScope.intersectWith(accessScope);
short searchContext = UsageSearchContext.IN_CODE | UsageSearchContext.IN_COMMENTS | UsageSearchContext.IN_FOREIGN_LANGUAGES;
collector.searchWord(textToSearch, restrictedByAccess, searchContext, true,
new MethodTextOccurrenceProcessor(aClass, strictSignatureSearch, methods));
SimpleAccessorReferenceSearcher.addPropertyAccessUsages(method, restrictedByAccess, collector);
}
}
@@ -1,66 +0,0 @@
/*
* Copyright 2000-2009 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 com.intellij.psi.impl.search;
import com.intellij.openapi.application.QueryExecutorBase;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiReference;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.SearchRequestCollector;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.UsageSearchContext;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
/**
* @author ven
*/
public class SimpleAccessorReferenceSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> {
public SimpleAccessorReferenceSearcher() {
super(true);
}
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
PsiElement refElement = queryParameters.getElementToSearch();
if (!(refElement instanceof PsiMethod)) return;
addPropertyAccessUsages((PsiMethod)refElement, queryParameters.getEffectiveSearchScope(), queryParameters.getOptimizer());
}
static void addPropertyAccessUsages(PsiMethod method, SearchScope scope, SearchRequestCollector collector) {
final String propertyName = PropertyUtil.getPropertyName(method);
if (StringUtil.isNotEmpty(propertyName)) {
SearchScope additional = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(method.getProject()),
StdFileTypes.JSP, StdFileTypes.JSPX,
StdFileTypes.XML, StdFileTypes.XHTML);
for (CustomPropertyScopeProvider provider : Extensions.getExtensions(CustomPropertyScopeProvider.EP_NAME)) {
additional = additional.union(provider.getScope(method.getProject()));
}
assert propertyName != null;
final SearchScope propScope = scope.intersectWith(method.getUseScope()).intersectWith(additional);
collector.searchWord(propertyName, propScope, UsageSearchContext.IN_FOREIGN_LANGUAGES, true, method);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -15,12 +15,15 @@
*/
package com.intellij.psi.impl.search;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.SearchScope;
public interface CustomPropertyScopeProvider {
ExtensionPointName<CustomPropertyScopeProvider> EP_NAME = new ExtensionPointName<CustomPropertyScopeProvider>("com.intellij.customPropertyScopeProvider");
SearchScope getScope(final Project project);
public class SimpleAccessorScopeProvider implements CustomPropertyScopeProvider {
public SearchScope getScope(final Project project) {
return GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project),
StdFileTypes.JSP, StdFileTypes.JSPX,
StdFileTypes.XML, StdFileTypes.XHTML);
}
}