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);
}
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;
}
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));
}
}
}
}
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);
}
}
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;
}
Aggregations