Search in sources :

Example 21 with UsageInfo

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

the class GrChangeSignatureProcessor method preprocessUsages.

@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    MultiMap<PsiElement, String> conflictDescriptions = new MultiMap<>();
    collectConflictsFromExtensions(refUsages, conflictDescriptions, myChangeInfo);
    final UsageInfo[] usagesIn = refUsages.get();
    RenameUtil.addConflictDescriptions(usagesIn, conflictDescriptions);
    Set<UsageInfo> usagesSet = new HashSet<>(Arrays.asList(usagesIn));
    RenameUtil.removeConflictUsages(usagesSet);
    if (!conflictDescriptions.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            throw new ConflictsInTestsException(conflictDescriptions.values());
        }
        ConflictsDialog dialog = prepareConflictsDialog(conflictDescriptions, usagesIn);
        if (!dialog.showAndGet()) {
            if (dialog.isShowConflicts())
                prepareSuccessful();
            return false;
        }
    }
    refUsages.set(usagesSet.toArray(new UsageInfo[usagesSet.size()]));
    prepareSuccessful();
    return true;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(com.intellij.util.containers.HashSet)

Example 22 with UsageInfo

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

the class GrChageSignatureUsageSearcher method findSimpleUsagesWithoutParameters.

private PsiMethod[] findSimpleUsagesWithoutParameters(final PsiMethod method, final ArrayList<UsageInfo> result, boolean isToModifyArgs, boolean isToThrowExceptions, boolean isOriginal) {
    GlobalSearchScope projectScope = GlobalSearchScope.projectScope(method.getProject());
    PsiMethod[] overridingMethods = OverridingMethodsSearch.search(method).toArray(PsiMethod.EMPTY_ARRAY);
    for (PsiMethod overridingMethod : overridingMethods) {
        if (GroovyLanguage.INSTANCE.equals(overridingMethod.getLanguage())) {
            result.add(new OverriderUsageInfo(overridingMethod, method, isOriginal, isToModifyArgs, isToThrowExceptions));
        }
    }
    boolean needToChangeCalls = !myChangeInfo.isGenerateDelegate() && (myChangeInfo.isNameChanged() || myChangeInfo.isParameterSetOrOrderChanged() || myChangeInfo.isExceptionSetOrOrderChanged() || myChangeInfo.isVisibilityChanged());
    if (needToChangeCalls) {
        PsiReference[] refs = MethodReferencesSearch.search(method, projectScope, true).toArray(PsiReference.EMPTY_ARRAY);
        for (PsiReference ref : refs) {
            PsiElement element = ref.getElement();
            if (!GroovyLanguage.INSTANCE.equals(element.getLanguage()))
                continue;
            boolean isToCatchExceptions = isToThrowExceptions && needToCatchExceptions(RefactoringUtil.getEnclosingMethod(element));
            if (PsiUtil.isMethodUsage(element)) {
                result.add(new GrMethodCallUsageInfo(element, isToModifyArgs, isToCatchExceptions, method));
            } else if (element instanceof GrDocTagValueToken) {
                result.add(new UsageInfo(ref.getElement()));
            } else if (element instanceof GrMethod && ((GrMethod) element).isConstructor()) {
                DefaultConstructorImplicitUsageInfo implicitUsageInfo = new DefaultConstructorImplicitUsageInfo((GrMethod) element, ((GrMethod) element).getContainingClass(), method);
                result.add(implicitUsageInfo);
            } else if (element instanceof PsiClass) {
                LOG.assertTrue(method.isConstructor());
                final PsiClass psiClass = (PsiClass) element;
                if (psiClass instanceof GrAnonymousClassDefinition) {
                    result.add(new GrMethodCallUsageInfo(element, isToModifyArgs, isToCatchExceptions, method));
                    continue;
                }
                /*if (!(myChangeInfo instanceof JavaChangeInfoImpl)) continue; todo propagate methods
          if (shouldPropagateToNonPhysicalMethod(method, result, psiClass,
                                                 ((JavaChangeInfoImpl)myChangeInfo).propagateParametersMethods)) {
            continue;
          }
          if (shouldPropagateToNonPhysicalMethod(method, result, psiClass,
                                                 ((JavaChangeInfoImpl)myChangeInfo).propagateExceptionsMethods)) {
            continue;
          }*/
                result.add(new NoConstructorClassUsageInfo(psiClass));
            } else if (ref instanceof PsiCallReference) {
                result.add(new CallReferenceUsageInfo((PsiCallReference) ref));
            } else {
                result.add(new MoveRenameUsageInfo(element, ref, method));
            }
        }
    } else if (myChangeInfo.isParameterTypesChanged()) {
        PsiReference[] refs = MethodReferencesSearch.search(method, projectScope, true).toArray(PsiReference.EMPTY_ARRAY);
        for (PsiReference reference : refs) {
            final PsiElement element = reference.getElement();
            if (element instanceof GrDocTagValueToken) {
                result.add(new UsageInfo(reference));
            }
        }
    }
    // Conflicts
    if (method instanceof GrMethod) {
        detectLocalsCollisionsInMethod((GrMethod) method, result, isOriginal);
    }
    for (final PsiMethod overridingMethod : overridingMethods) {
        if (overridingMethod instanceof GrMethod) {
            detectLocalsCollisionsInMethod((GrMethod) overridingMethod, result, isOriginal);
        }
    }
    return overridingMethods;
}
Also used : GrDocTagValueToken(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTagValueToken) GrAnonymousClassDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)

Example 23 with UsageInfo

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

the class GrChageSignatureUsageSearcher method addParameterUsages.

private static void addParameterUsages(PsiParameter parameter, ArrayList<UsageInfo> results, ParameterInfo info) {
    for (PsiReference psiReference : ReferencesSearch.search(parameter)) {
        PsiElement parmRef = psiReference.getElement();
        UsageInfo usageInfo = new ChangeSignatureParameterUsageInfo(parmRef, parameter.getName(), info.getName());
        results.add(usageInfo);
    }
    if (info.getName() != parameter.getName()) {
    }
}
Also used : UsageInfo(com.intellij.usageView.UsageInfo) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)

Example 24 with UsageInfo

use of com.intellij.usageView.UsageInfo in project smali by JesusFreke.

the class FindUsagesTest method assertUsages.

private void assertUsages(@NotNull TestFile testFile, @NotNull Collection<UsageInfo> usages) {
    List<UsageInfo> fileUsages = Lists.newArrayList();
    for (UsageInfo usage : usages) {
        if (usage.getFile().getName().equals(testFile.fileName)) {
            fileUsages.add(usage);
        }
    }
    for (Integer usageIndex : testFile.getUsageIndices()) {
        boolean found = false;
        for (UsageInfo usage : fileUsages) {
            int startOffset = usage.getElement().getNode().getStartOffset();
            int length = usage.getElement().getTextLength();
            if (usageIndex >= startOffset && usageIndex < startOffset + length) {
                fileUsages.remove(usage);
                found = true;
                break;
            }
        }
        Assert.assertTrue(found);
    }
    Assert.assertEquals(0, fileUsages.size());
}
Also used : UsageInfo(com.intellij.usageView.UsageInfo)

Example 25 with UsageInfo

use of com.intellij.usageView.UsageInfo in project smali by JesusFreke.

the class FindUsagesTest method doTest.

protected void doTest() {
    PsiReference reference = null;
    PsiElement targetElement = null;
    for (TestFile testFile : testFiles) {
        int refIndex = testFile.getRefIndex();
        if (refIndex != -1) {
            PsiElement element = testFile.psiFile.findElementAt(refIndex);
            UsageTarget[] targets = UsageTargetUtil.findUsageTargets(element);
            if (targets != null) {
                for (UsageTarget target : targets) {
                    if (target instanceof PsiElementUsageTarget) {
                        targetElement = ((PsiElementUsageTarget) target).getElement();
                        break;
                    }
                }
            }
            if (targetElement == null) {
                reference = testFile.psiFile.findReferenceAt(refIndex);
                if (reference != null) {
                    targetElement = reference.resolve();
                } else {
                    targetElement = TargetElementUtilBase.getInstance().getNamedElement(testFile.psiFile.findElementAt(refIndex), 0);
                }
            }
            break;
        }
    }
    Assert.assertNotNull(targetElement);
    Collection<UsageInfo> usages = findUsages(targetElement);
    for (TestFile testFile : testFiles) {
        assertUsages(testFile, usages);
    }
}
Also used : PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) UsageTarget(com.intellij.usages.UsageTarget) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget)

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