Search in sources :

Example 31 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class IntroduceParameterProcessor method findUsages.

@NotNull
protected UsageInfo[] findUsages() {
    ArrayList<UsageInfo> result = new ArrayList<>();
    PsiMethod[] overridingMethods = OverridingMethodsSearch.search(myMethodToSearchFor).toArray(PsiMethod.EMPTY_ARRAY);
    for (PsiMethod overridingMethod : overridingMethods) {
        result.add(new UsageInfo(overridingMethod));
    }
    if (!myGenerateDelegate) {
        PsiReference[] refs = MethodReferencesSearch.search(myMethodToSearchFor, GlobalSearchScope.projectScope(myProject), true).toArray(PsiReference.EMPTY_ARRAY);
        for (PsiReference ref1 : refs) {
            PsiElement ref = ref1.getElement();
            if (ref instanceof PsiMethod && ((PsiMethod) ref).isConstructor()) {
                DefaultConstructorImplicitUsageInfo implicitUsageInfo = new DefaultConstructorImplicitUsageInfo((PsiMethod) ref, ((PsiMethod) ref).getContainingClass(), myMethodToSearchFor);
                result.add(implicitUsageInfo);
            } else if (ref instanceof PsiClass) {
                result.add(new NoConstructorClassUsageInfo((PsiClass) ref));
            } else if (!IntroduceParameterUtil.insideMethodToBeReplaced(ref, myMethodToReplaceIn)) {
                result.add(new ExternalUsageInfo(ref));
            } else {
                result.add(new ChangedMethodCallInfo(ref));
            }
        }
    }
    if (myReplaceAllOccurrences) {
        for (PsiElement expr : getOccurrences()) {
            result.add(new InternalUsageInfo(expr));
        }
    } else {
        if (myExpressionToSearch != null && myExpressionToSearch.isValid()) {
            result.add(new InternalUsageInfo(myExpressionToSearch));
        }
    }
    final UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]);
    return UsageViewUtil.removeDuplicatedUsages(usageInfos);
}
Also used : ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class JavaIntroduceParameterMethodUsagesProcessor method processAddDefaultConstructor.

public boolean processAddDefaultConstructor(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) {
    if (!(usage.getElement() instanceof PsiClass) || !isJavaUsage(usage))
        return true;
    PsiClass aClass = (PsiClass) usage.getElement();
    if (!(aClass instanceof PsiAnonymousClass)) {
        final PsiElementFactory factory = JavaPsiFacade.getInstance(data.getProject()).getElementFactory();
        PsiMethod constructor = factory.createMethodFromText(aClass.getName() + "(){}", aClass);
        constructor = (PsiMethod) CodeStyleManager.getInstance(data.getProject()).reformat(constructor);
        constructor = (PsiMethod) aClass.add(constructor);
        PsiUtil.setModifierProperty(constructor, VisibilityUtil.getVisibilityModifier(aClass.getModifierList()), true);
        processAddSuperCall(data, new UsageInfo(constructor), usages);
    } else {
        return true;
    }
    return false;
}
Also used : UsageInfo(com.intellij.usageView.UsageInfo)

Example 33 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class MakeClassStaticProcessor method findDefaultConstructorReferences.

private void findDefaultConstructorReferences(final ArrayList<UsageInfo> result) {
    for (PsiReference ref : ReferencesSearch.search(myMember)) {
        PsiElement element = ref.getElement();
        if (element.getParent() instanceof PsiNewExpression) {
            PsiNewExpression newExpression = (PsiNewExpression) element.getParent();
            PsiElement qualifier = newExpression.getQualifier();
            if (qualifier instanceof PsiThisExpression)
                qualifier = null;
            if (!PsiTreeUtil.isAncestor(myMember, element, true) || qualifier != null) {
                result.add(new UsageInfo(element));
            } else {
                result.add(new InternalUsageInfo(element, myMember));
            }
        }
    }
}
Also used : UsageInfo(com.intellij.usageView.UsageInfo)

Example 34 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class MigrationUtil method doMigration.

static void doMigration(PsiElement elementToBind, String newQName, UsageInfo[] usages, ArrayList<SmartPsiElementPointer<PsiElement>> refsToShorten) {
    try {
        SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(elementToBind.getProject());
        // rename all references
        for (UsageInfo usage : usages) {
            if (usage instanceof MigrationProcessor.MigrationUsageInfo) {
                final MigrationProcessor.MigrationUsageInfo usageInfo = (MigrationProcessor.MigrationUsageInfo) usage;
                if (Comparing.equal(newQName, usageInfo.mapEntry.getNewName())) {
                    PsiElement element = usage.getElement();
                    if (element == null || !element.isValid())
                        continue;
                    PsiElement psiElement;
                    if (element instanceof PsiJavaCodeReferenceElement) {
                        psiElement = ((PsiJavaCodeReferenceElement) element).bindToElement(elementToBind);
                    } else {
                        psiElement = bindNonJavaReference(elementToBind, element, usage);
                    }
                    if (psiElement != null) {
                        refsToShorten.add(smartPointerManager.createSmartPsiElementPointer(psiElement));
                    }
                }
            }
        }
    } catch (IncorrectOperationException e) {
        // should not happen!
        LOG.error(e);
    }
}
Also used : IncorrectOperationException(com.intellij.util.IncorrectOperationException) UsageInfo(com.intellij.usageView.UsageInfo)

Example 35 with UsageInfo

use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.

the class MakeMethodOrClassStaticProcessor method makeClassParameterFinal.

protected boolean makeClassParameterFinal(UsageInfo[] usages) {
    for (UsageInfo usage : usages) {
        if (usage instanceof InternalUsageInfo) {
            final InternalUsageInfo internalUsageInfo = (InternalUsageInfo) usage;
            PsiElement referencedElement = internalUsageInfo.getReferencedElement();
            if (!(referencedElement instanceof PsiField) || mySettings.getNameForField((PsiField) referencedElement) == null) {
                if (internalUsageInfo.isInsideAnonymous()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

UsageInfo (com.intellij.usageView.UsageInfo)283 PsiElement (com.intellij.psi.PsiElement)70 NotNull (org.jetbrains.annotations.NotNull)57 ArrayList (java.util.ArrayList)41 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)38 IncorrectOperationException (com.intellij.util.IncorrectOperationException)34 PsiFile (com.intellij.psi.PsiFile)33 MultiMap (com.intellij.util.containers.MultiMap)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 Nullable (org.jetbrains.annotations.Nullable)20 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)19 DefaultConstructorImplicitUsageInfo (com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)17 NoConstructorClassUsageInfo (com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo)17 Project (com.intellij.openapi.project.Project)16 HashSet (com.intellij.util.containers.HashSet)15 TextRange (com.intellij.openapi.util.TextRange)12 PsiReference (com.intellij.psi.PsiReference)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)11 PsiClass (com.intellij.psi.PsiClass)11 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)11