Search in sources :

Example 6 with DefaultConstructorImplicitUsageInfo

use of com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo in project intellij-community by JetBrains.

the class ExtractClosureFromMethodProcessor method findUsages.

@NotNull
@Override
protected UsageInfo[] findUsages() {
    List<UsageInfo> result = new ArrayList<>();
    final PsiMethod toSearchFor = (PsiMethod) myHelper.getToSearchFor();
    for (PsiReference ref1 : MethodReferencesSearch.search(toSearchFor, GlobalSearchScope.projectScope(myProject), true)) {
        PsiElement ref = ref1.getElement();
        if (ref.getLanguage() != GroovyLanguage.INSTANCE) {
            result.add(new OtherLanguageUsageInfo(ref1));
            continue;
        }
        if (ref instanceof PsiMethod && ((PsiMethod) ref).isConstructor()) {
            DefaultConstructorImplicitUsageInfo implicitUsageInfo = new DefaultConstructorImplicitUsageInfo((PsiMethod) ref, ((PsiMethod) ref).getContainingClass(), toSearchFor);
            result.add(implicitUsageInfo);
        } else if (ref instanceof PsiClass) {
            result.add(new NoConstructorClassUsageInfo((PsiClass) ref));
        } else if (!PsiTreeUtil.isAncestor(myMethod, ref, false)) {
            result.add(new ExternalUsageInfo(ref));
        } else {
            result.add(new ChangedMethodCallInfo(ref));
        }
    }
    Collection<PsiMethod> overridingMethods = OverridingMethodsSearch.search(toSearchFor).findAll();
    for (PsiMethod overridingMethod : overridingMethods) {
        result.add(new UsageInfo(overridingMethod));
    }
    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 7 with DefaultConstructorImplicitUsageInfo

use of com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo in project intellij-community by JetBrains.

the class JavaChangeSignatureUsageSearcher 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) {
        result.add(new OverriderUsageInfo(overridingMethod, method, isOriginal, isToModifyArgs, isToThrowExceptions));
    }
    boolean needToChangeCalls = !myChangeInfo.isGenerateDelegate() && (myChangeInfo.isNameChanged() || myChangeInfo.isParameterSetOrOrderChanged() || myChangeInfo.isExceptionSetOrOrderChanged() || myChangeInfo.isVisibilityChanged());
    if (needToChangeCalls) {
        int parameterCount = method.getParameterList().getParametersCount();
        PsiReference[] refs = MethodReferencesSearch.search(method, projectScope, true).toArray(PsiReference.EMPTY_ARRAY);
        for (PsiReference ref : refs) {
            PsiElement element = ref.getElement();
            boolean isToCatchExceptions = isToThrowExceptions && needToCatchExceptions(RefactoringUtil.getEnclosingMethod(element));
            if (!isToCatchExceptions) {
                if (RefactoringUtil.isMethodUsage(element)) {
                    PsiExpressionList list = RefactoringUtil.getArgumentListByMethodReference(element);
                    if (list == null || !method.isVarArgs() && list.getExpressions().length != parameterCount)
                        continue;
                }
            }
            if (RefactoringUtil.isMethodUsage(element)) {
                result.add(new MethodCallUsageInfo(element, isToModifyArgs, isToCatchExceptions));
            } else if (element instanceof PsiDocTagValue) {
                result.add(new UsageInfo(element));
            } else if (element instanceof PsiMethod && ((PsiMethod) element).isConstructor()) {
                if (JavaLanguage.INSTANCE.equals(element.getLanguage())) {
                    DefaultConstructorImplicitUsageInfo implicitUsageInfo = new DefaultConstructorImplicitUsageInfo((PsiMethod) element, ((PsiMethod) element).getContainingClass(), method);
                    result.add(implicitUsageInfo);
                }
            } else if (element instanceof PsiClass) {
                LOG.assertTrue(method.isConstructor());
                final PsiClass psiClass = (PsiClass) element;
                if (JavaLanguage.INSTANCE.equals(psiClass.getLanguage())) {
                    if (myChangeInfo instanceof JavaChangeInfoImpl) {
                        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 if (element instanceof PsiMethodReferenceExpression && MethodReferenceUsageInfo.needToExpand(myChangeInfo)) {
                result.add(new MethodReferenceUsageInfo(element, method, isToModifyArgs, isToCatchExceptions));
            } else {
                result.add(new MoveRenameUsageInfo(element, ref, method));
            }
        }
    //if (method.isConstructor() && parameterCount == 0) {
    //    RefactoringUtil.visitImplicitConstructorUsages(method.getContainingClass(),
    //                                                   new DefaultConstructorUsageCollector(result));
    //}
    } 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 PsiDocTagValue) {
                result.add(new UsageInfo(reference));
            } else if (element instanceof XmlElement) {
                result.add(new MoveRenameUsageInfo(reference, method));
            } else if (element instanceof PsiMethodReferenceExpression) {
                result.add(new UsageInfo(reference));
            }
        }
    }
    // Conflicts
    detectLocalsCollisionsInMethod(method, result, isOriginal);
    for (final PsiMethod overridingMethod : overridingMethods) {
        detectLocalsCollisionsInMethod(overridingMethod, result, isOriginal);
    }
    return overridingMethods;
}
Also used : MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) PsiDocTagValue(com.intellij.psi.javadoc.PsiDocTagValue) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo) XmlElement(com.intellij.psi.xml.XmlElement) 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)

Aggregations

DefaultConstructorImplicitUsageInfo (com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)7 NoConstructorClassUsageInfo (com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo)7 UsageInfo (com.intellij.usageView.UsageInfo)6 ArrayList (java.util.ArrayList)4 TIntArrayList (gnu.trove.TIntArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 UnresolvableCollisionUsageInfo (com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo)2 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)2 GrAnonymousClassDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition)2 PsiElement (com.intellij.psi.PsiElement)1 PsiManager (com.intellij.psi.PsiManager)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiDocTagValue (com.intellij.psi.javadoc.PsiDocTagValue)1 XmlElement (com.intellij.psi.xml.XmlElement)1 GrDocTagValueToken (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTagValueToken)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1