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