use of com.intellij.usageView.UsageInfo in project intellij-community by JetBrains.
the class PyTestCase method findUsage.
/**
* Finds all usages of element. Works much like method in {@link com.intellij.testFramework.fixtures.CodeInsightTestFixture#findUsages(com.intellij.psi.PsiElement)},
* but supports {@link com.intellij.find.findUsages.CustomUsageSearcher} and {@link com.intellij.psi.search.searches.ReferencesSearch} as well
*
* @param element what to find
* @return usages
*/
@NotNull
protected Collection<PsiElement> findUsage(@NotNull final PsiElement element) {
final Collection<PsiElement> result = new ArrayList<>();
final CollectProcessor<Usage> usageCollector = new CollectProcessor<>();
for (final CustomUsageSearcher searcher : CustomUsageSearcher.EP_NAME.getExtensions()) {
searcher.processElementUsages(element, usageCollector, new FindUsagesOptions(myFixture.getProject()));
}
for (final Usage usage : usageCollector.getResults()) {
if (usage instanceof PsiElementUsage) {
result.add(((PsiElementUsage) usage).getElement());
}
}
for (final PsiReference reference : ReferencesSearch.search(element).findAll()) {
result.add(reference.getElement());
}
for (final UsageInfo info : myFixture.findUsages(element)) {
result.add(info.getElement());
}
return result;
}
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 intellij-community by JetBrains.
the class PyMoveModuleMembersProcessor method performRefactoring.
@Override
protected void performRefactoring(@NotNull final UsageInfo[] usages) {
final MultiMap<PsiElement, UsageInfo> usagesByElement = MultiMap.create();
for (UsageInfo usage : usages) {
usagesByElement.putValue(((MyUsageInfo) usage).myMovedElement, usage);
}
CommandProcessor.getInstance().executeCommand(myElements[0].getProject(), new Runnable() {
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
final PyFile destination = PyUtil.getOrCreateFile(myDestination, myProject);
CommonRefactoringUtil.checkReadOnlyStatus(myProject, destination);
for (final PsiNamedElement e : myElements) {
// TODO: Check for resulting circular imports
CommonRefactoringUtil.checkReadOnlyStatus(myProject, e);
assert e instanceof PyClass || e instanceof PyFunction || e instanceof PyTargetExpression;
final String name = e.getName();
if (name == null) {
continue;
}
if (e instanceof PyClass && destination.findTopLevelClass(name) != null) {
throw new IncorrectOperationException(PyBundle.message("refactoring.move.error.destination.file.contains.class.$0", name));
}
if (e instanceof PyFunction && destination.findTopLevelFunction(name) != null) {
throw new IncorrectOperationException(PyBundle.message("refactoring.move.error.destination.file.contains.function.$0", name));
}
if (e instanceof PyTargetExpression && destination.findTopLevelAttribute(name) != null) {
throw new IncorrectOperationException(PyBundle.message("refactoring.move.error.destination.file.contains.global.variable.$0", name));
}
final Collection<UsageInfo> usageInfos = usagesByElement.get(e);
final boolean usedFromOutside = ContainerUtil.exists(usageInfos, new Condition<UsageInfo>() {
@Override
public boolean value(UsageInfo usageInfo) {
final PsiElement element = usageInfo.getElement();
return element != null && !PsiTreeUtil.isAncestor(e, element, false);
}
});
if (usedFromOutside) {
PyMoveRefactoringUtil.checkValidImportableFile(e, destination.getVirtualFile());
}
new PyMoveSymbolProcessor(e, destination, usageInfos, myElements).moveElement();
}
}
});
}
}, REFACTORING_NAME, null);
}
Aggregations