本文整理汇总了Java中com.intellij.psi.search.searches.ReferencesSearch.search方法的典型用法代码示例。如果您正苦于以下问题:Java ReferencesSearch.search方法的具体用法?Java ReferencesSearch.search怎么用?Java ReferencesSearch.search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.search.searches.ReferencesSearch
的用法示例。
在下文中一共展示了ReferencesSearch.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findUsages
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@Nullable
@Override
public List<UsageInfo> findUsages( PsiFile psiFile, PsiDirectory newParent, boolean searchInComments, boolean searchInNonJavaFiles )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( psiFile );
ManModule module = ManProject.getModule( mod );
PsiClass psiClass = findPsiClass( psiFile );
if( psiClass == null )
{
return Collections.emptyList();
}
Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref: search.findAll() )
{
usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), psiClass,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
}
return usages;
}
示例2: findUsages
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static List<UsageInfo> findUsages( PsiElement element, PsiElement ctx )
{
// Module mod = ModuleUtilCore.findModuleForPsiElement( element );
// if( mod == null )
// {
// return Collections.emptyList();
// }
Query<PsiReference> search = ReferencesSearch.search( element, GlobalSearchScope.moduleScope( ModuleUtilCore.findModuleForPsiElement( ctx ) ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref : search.findAll() )
{
MoveRenameUsageInfo usageInfo = new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), element,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) );
usages.add( usageInfo );
}
return usages;
}
示例3: findUsages
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
public static UsageInfo[] findUsages(final PsiElement element,
boolean searchInStringsAndComments,
boolean searchInNonJavaFiles,
final String newQName) {
PsiManager manager = element.getManager();
ArrayList<UsageInfo> results = new ArrayList<UsageInfo>();
Set<PsiReference> foundReferences = new HashSet<PsiReference>();
GlobalSearchScope projectScope = GlobalSearchScope.projectScope(manager.getProject());
for (PsiReference reference : ReferencesSearch.search(element, projectScope, false)) {
TextRange range = reference.getRangeInElement();
if (foundReferences.contains(reference)) continue;
results.add(new MoveRenameUsageInfo(reference.getElement(), reference, range.getStartOffset(), range.getEndOffset(), element, false));
foundReferences.add(reference);
}
findNonCodeUsages(searchInStringsAndComments, searchInNonJavaFiles, element, newQName, results);
preprocessUsages(results);
return results.toArray(new UsageInfo[results.size()]);
}
示例4: findUsages
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@Override
@NotNull
protected UsageInfo[] findUsages() {
ArrayList<UsageInfo> result = new ArrayList<UsageInfo>();
for (int i = 0; i < myElementsToMove.length; i++) {
PsiElement element = myElementsToMove[i];
if (mySearchForReferences) {
for (PsiReference reference : ReferencesSearch.search(element, GlobalSearchScope.projectScope(myProject))) {
result.add(new MyUsageInfo(reference.getElement(), i, reference));
}
}
findElementUsages(result, element);
}
return result.toArray(new UsageInfo[result.size()]);
}
示例5: processIntention
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
if (!(element instanceof GrReferenceElement)) return;
final GrReferenceElement ref = (GrReferenceElement)element;
final PsiElement resolved = ref.resolve();
if (!(resolved instanceof PsiClass)) return;
final String qname = ((PsiClass)resolved).getQualifiedName();
final GrImportStatement importStatement =
GroovyPsiElementFactory.getInstance(project).createImportStatementFromText(qname, true, true, null);
final PsiFile containingFile = element.getContainingFile();
if (!(containingFile instanceof GroovyFile)) return;
((GroovyFile)containingFile).addImport(importStatement);
for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile))) {
final PsiElement refElement = reference.getElement();
if (refElement == null) continue;
final PsiElement parent = refElement.getParent();
if (parent instanceof GrQualifiedReference<?>) {
org.jetbrains.plugins.groovy.codeStyle.GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>)parent);
}
}
}
示例6: processUsagesForMethod
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private void processUsagesForMethod(final boolean deleteMethodHierarchy, PsiMethod method, int[] paramPermutation, String getterName, PsiMethod delegatedMethod,
List<FixableUsageInfo> usages) {
for (PsiReference reference : ReferencesSearch.search(method)) {
final PsiElement referenceElement = reference.getElement();
final PsiMethodCallExpression call = (PsiMethodCallExpression)referenceElement.getParent();
final String access;
if (call.getMethodExpression().getQualifierExpression() == null) {
access = field.getName();
} else {
access = getterName + "()";
if (getter == null) {
getter = GenerateMembersUtil.generateGetterPrototype(field);
}
}
usages.add(new InlineDelegatingCall(call, paramPermutation, access, delegatedMethod.getName()));
}
if (deleteMethodHierarchy) {
usages.add(new DeleteMethod(method));
}
}
示例7: getAssignmentToInline
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static Pair<PyStatement, Boolean> getAssignmentToInline(ScopeOwner containerBlock, PyReferenceExpression expr,
PyTargetExpression local, Project project) {
if (expr != null) {
try {
final List<ReadWriteInstruction> candidates = PyDefUseUtil.getLatestDefs(containerBlock, local.getName(), expr, true);
if (candidates.size() == 1) {
final PyStatement expression = getAssignmentByLeftPart((PyElement)candidates.get(0).getElement());
return Pair.create(expression, false);
}
return Pair.create(null, candidates.size() > 0);
}
catch (PyDefUseUtil.InstructionNotFoundException ignored) {
}
}
final Query<PsiReference> query = ReferencesSearch.search(local, GlobalSearchScope.allScope(project), false);
final PsiReference first = query.findFirst();
final PyElement lValue = first != null ? (PyElement)first.resolve() : null;
return lValue != null ? Pair.create(getAssignmentByLeftPart(lValue), false) : EMPTY_DEF_RESULT;
}
示例8: findUsages
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@NotNull protected UsageInfo[] findUsages() {
ArrayList<EncapsulateFieldUsageInfo> array = ContainerUtil.newArrayList();
for (FieldDescriptor fieldDescriptor : myFieldDescriptors) {
for (final PsiReference reference : ReferencesSearch.search(fieldDescriptor.getField())) {
final PsiElement element = reference.getElement();
if (element == null) continue;
final EncapsulateFieldHelper helper = EncapsulateFieldHelper.getHelper(element.getLanguage());
if (helper != null) {
EncapsulateFieldUsageInfo usageInfo = helper.createUsage(myDescriptor, fieldDescriptor, reference);
if (usageInfo != null) {
array.add(usageInfo);
}
}
}
}
EncapsulateFieldUsageInfo[] usageInfos = array.toArray(new EncapsulateFieldUsageInfo[array.size()]);
return UsageViewUtil.removeDuplicatedUsages(usageInfos);
}
示例9: performRefactoring
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
protected void performRefactoring(@NotNull UsageInfo[] usageInfos) {
final PsiClass psiClass = buildClass();
if (psiClass != null) {
fixJavadocForConstructor(psiClass);
super.performRefactoring(usageInfos);
if (!myUseExistingClass) {
for (PsiReference reference : ReferencesSearch.search(method)) {
final PsiElement place = reference.getElement();
VisibilityUtil.escalateVisibility(psiClass, place);
for (PsiMethod constructor : psiClass.getConstructors()) {
VisibilityUtil.escalateVisibility(constructor, place);
}
}
}
}
}
示例10: storeTypeManifoldReferences
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private void storeTypeManifoldReferences( @NotNull PsiElement element )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( element );
if( mod == null )
{
return;
}
ManModule module = ManProject.getModule( mod );
PsiClass psiClass = findPsiClass( (PsiFileSystemItem)element, module );
if( psiClass == null )
{
return;
}
Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.projectScope( mod.getProject() ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref: search.findAll() )
{
usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), element,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
}
_usages = usages;
if( psiClass instanceof ManifoldPsiClass )
{
PsiElement fakeElement = ManGotoDeclarationHandler.find( psiClass, (ManifoldPsiClass)psiClass );
if( fakeElement instanceof PsiNamedElement && isTopLevelClassDeclaration( fakeElement ) )
{
_classDeclElement = (PsiNamedElement)fakeElement;
}
}
}
示例11: execute
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@Override
public boolean execute(@NotNull final ReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
final PsiElement refElement = p.getElementToSearch();
boolean isAnnotation = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return PsiUtil.isAnnotationMethod(refElement);
}
});
if (isAnnotation) {
final PsiMethod method = (PsiMethod)refElement;
PsiClass containingClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
@Override
public PsiClass compute() {
boolean isValueMethod =
PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(method.getName()) && method.getParameterList().getParametersCount() == 0;
return isValueMethod ? method.getContainingClass() : null;
}
});
if (containingClass != null) {
SearchScope scope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
@Override
public SearchScope compute() {
return p.getEffectiveSearchScope();
}
});
final Query<PsiReference> query = ReferencesSearch.search(containingClass, scope, p.isIgnoreAccessScope());
return query.forEach(createImplicitDefaultAnnotationMethodConsumer(consumer));
}
}
return true;
}
示例12: findUsages
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
@NotNull
protected UsageInfo[] findUsages() {
GlobalSearchScope projectScope = GlobalSearchScope.projectScope(myProject);
List<UsageInfo> result = new ArrayList<UsageInfo>();
boolean hadTypeParameters = myClass.hasTypeParameters();
for (final PsiReference reference : ReferencesSearch.search(myClass, projectScope, false)) {
if (reference.getElement() instanceof PsiJavaCodeReferenceElement) {
PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)reference.getElement();
PsiElement parent = referenceElement.getParent();
if (parent instanceof PsiTypeElement && parent.getParent() instanceof PsiInstanceOfExpression) continue;
if (parent instanceof PsiNewExpression && PsiUtil.isLanguageLevel7OrHigher(parent)) {
final PsiReferenceParameterList parameterList = referenceElement.getParameterList();
if (parameterList != null) {
final PsiTypeElement[] parameterElements = parameterList.getTypeParameterElements();
if (parameterElements.length == 1 && parameterElements[0].getType() instanceof PsiDiamondType) continue;
}
}
if (parent instanceof PsiTypeElement || parent instanceof PsiNewExpression || parent instanceof PsiAnonymousClass ||
parent instanceof PsiReferenceList) {
if (!hadTypeParameters || referenceElement.getTypeParameters().length > 0) {
result.add(new UsageInfo(referenceElement));
}
}
}
}
return result.toArray(new UsageInfo[result.size()]);
}
示例13: shortenUsages
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static boolean shortenUsages(PsiElement resolved, PsiFile containingFile) {
boolean isAnythingShortened = false;
for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile))) {
final PsiElement refElement = reference.getElement();
if (refElement instanceof GrQualifiedReference<?>) {
boolean shortened = GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>)refElement);
isAnythingShortened |= shortened;
}
}
return isAnythingShortened;
}
示例14: processUsages
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static boolean processUsages(PsiElement tag, XmlAttributeValue value, LocalSearchScope scope) {
final Query<PsiReference> query = ReferencesSearch.search(tag, scope, true);
for (PsiReference reference : query) {
final PsiElement e = reference.getElement();
if (e != value) {
final XmlTag t = PsiTreeUtil.getParentOfType(e, XmlTag.class);
if (t != null && !PsiTreeUtil.isAncestor(tag, t, true)) {
return true;
}
}
}
return false;
}
示例15: makeMethodCallsVarargs
import com.intellij.psi.search.searches.ReferencesSearch; //导入方法依赖的package包/类
private static void makeMethodCallsVarargs(PsiElement element)
throws IncorrectOperationException {
final PsiMethod method = (PsiMethod)element.getParent();
final Query<PsiReference> query =
ReferencesSearch.search(method, method.getUseScope(), false);
for (PsiReference reference : query) {
final PsiElement referenceElement = reference.getElement();
if (!(referenceElement instanceof PsiReferenceExpression)) {
continue;
}
final PsiReferenceExpression referenceExpression =
(PsiReferenceExpression)referenceElement;
final PsiMethodCallExpression methodCallExpression =
(PsiMethodCallExpression)referenceExpression.getParent();
final PsiExpressionList argumentList =
methodCallExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length == 0) {
continue;
}
final PsiExpression lastArgument = arguments[arguments.length - 1];
if (!(lastArgument instanceof PsiNewExpression)) {
continue;
}
final PsiNewExpression newExpression =
(PsiNewExpression)lastArgument;
final PsiArrayInitializerExpression arrayInitializerExpression =
newExpression.getArrayInitializer();
if (arrayInitializerExpression == null) {
continue;
}
final PsiExpression[] initializers =
arrayInitializerExpression.getInitializers();
for (PsiExpression initializer : initializers) {
argumentList.add(initializer);
}
lastArgument.delete();
}
}