Search in sources :

Example 6 with NoConstructorClassUsageInfo

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

the class GrIntroduceParameterProcessor method findUsages.

@NotNull
@Override
protected UsageInfo[] findUsages() {
    ArrayList<UsageInfo> result = new ArrayList<>();
    final PsiMethod toSearchFor = ((PsiMethod) mySettings.getToSearchFor());
    if (!mySettings.generateDelegate()) {
        Collection<PsiReference> refs = MethodReferencesSearch.search(toSearchFor, GlobalSearchScope.projectScope(myProject), true).findAll();
        for (PsiReference ref1 : refs) {
            PsiElement ref = ref1.getElement();
            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) {
                if (ref instanceof GrAnonymousClassDefinition) {
                    result.add(new ExternalUsageInfo(((GrAnonymousClassDefinition) ref).getBaseClassReferenceGroovy()));
                } else if (ref instanceof PsiAnonymousClass) {
                    result.add(new ExternalUsageInfo(((PsiAnonymousClass) ref).getBaseClassReference()));
                } else {
                    result.add(new NoConstructorClassUsageInfo((PsiClass) ref));
                }
            } else if (!PsiTreeUtil.isAncestor(mySettings.getToReplaceIn(), ref, false)) {
                result.add(new ExternalUsageInfo(ref));
            } else {
                result.add(new ChangedMethodCallInfo(ref));
            }
        }
    }
    if (mySettings.replaceAllOccurrences()) {
        if (mySettings.getVar() != null) {
            for (PsiElement element : GrIntroduceHandlerBase.collectVariableUsages(mySettings.getVar(), mySettings.getToReplaceIn())) {
                result.add(new InternalUsageInfo(element));
            }
        } else {
            PsiElement[] exprs = GroovyIntroduceParameterUtil.getOccurrences(mySettings);
            for (PsiElement expr : exprs) {
                result.add(new InternalUsageInfo(expr));
            }
        }
    } else {
        if (mySettings.getExpression() != null) {
            result.add(new InternalUsageInfo(mySettings.getExpression()));
        }
    }
    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 : GrAnonymousClassDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition) 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 NoConstructorClassUsageInfo

use of com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo 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)

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