mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Move MethodReferencesSearch (and necessary closure) to java-indexing-api.
Remove references to StfFileTypes from SimpleAccessorReferencesSearch and extract them into one more CustomPropertyScopeProvider
This commit is contained in:
-1
@@ -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,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-6
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user