use of com.intellij.psi.PsiNamedElement in project intellij-plugins by JetBrains.
the class DartGotoImplementationTest method testIterableSubclasses.
public void testIterableSubclasses() throws Throwable {
myFixture.configureByText("foo.dart", "");
myFixture.doHighlighting();
final DartSdk sdk = DartSdk.getDartSdk(getProject());
assertNotNull(sdk);
DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "set.dart");
DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "string.dart");
DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "list.dart");
DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "iterable.dart");
final DartClass iterableClass = PsiTreeUtil.findChildOfType(getFile(), DartClass.class);
assertNotNull(iterableClass);
assertEquals("Iterable", iterableClass.getName());
getEditor().getCaretModel().moveToOffset(iterableClass.getTextOffset());
final GotoTargetHandler.GotoData data = CodeInsightTestUtil.gotoImplementation(myFixture.getEditor(), myFixture.getFile());
final List<String> actual = ContainerUtil.map(data.targets, psiElement -> psiElement instanceof PsiNamedElement ? ((PsiNamedElement) psiElement).getName() : psiElement.toString());
// only subclasses from dart:core are known to analyzer at this point
assertSameElements(actual, "List", "Set", "Runes");
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class AliasingPsiTargetUtil method renameTargets.
public static void renameTargets(AliasingPsiTarget target, @NotNull String newDelegateName) {
final PsiNamedElement namedElement = (PsiNamedElement) target.getNavigationElement();
if (!newDelegateName.equals(namedElement.getName())) {
final RenameRefactoring refactoring = RefactoringFactory.getInstance(namedElement.getProject()).createRename(namedElement, newDelegateName);
refactoring.run();
}
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class AutomaticRenamer method findUsagesForElement.
private boolean findUsagesForElement(PsiNamedElement element, List<UsageInfo> result, final boolean searchInStringsAndComments, final boolean searchInNonJavaFiles, List<UnresolvableCollisionUsageInfo> unresolvedUsages, Map<PsiElement, String> allRenames) {
final String newName = getNewName(element);
if (newName != null) {
final LinkedHashMap<PsiNamedElement, String> renames = new LinkedHashMap<>();
renames.putAll(myRenames);
if (allRenames != null) {
for (PsiElement psiElement : allRenames.keySet()) {
if (psiElement instanceof PsiNamedElement) {
renames.put((PsiNamedElement) psiElement, allRenames.get(psiElement));
}
}
}
final UsageInfo[] usages = RenameUtil.findUsages(element, newName, searchInStringsAndComments, searchInNonJavaFiles, renames);
for (final UsageInfo usage : usages) {
if (usage instanceof UnresolvableCollisionUsageInfo) {
if (unresolvedUsages != null) {
unresolvedUsages.add((UnresolvableCollisionUsageInfo) usage);
}
return false;
}
}
ContainerUtil.addAll(result, usages);
}
return true;
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class AutomaticRenamer method suggestAllNames.
protected void suggestAllNames(final String oldClassName, String newClassName) {
final NameSuggester suggester = new NameSuggester(oldClassName, newClassName);
for (int varIndex = myElements.size() - 1; varIndex >= 0; varIndex--) {
final PsiNamedElement element = myElements.get(varIndex);
final String name = element.getName();
if (!myRenames.containsKey(element) && name != null) {
String newName = suggestNameForElement(element, suggester, newClassName, oldClassName);
if (!newName.equals(name)) {
myRenames.put(element, newName);
} else {
myRenames.put(element, null);
}
}
if (myRenames.get(element) == null) {
myElements.remove(varIndex);
}
}
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class AutomaticRenamer method findUsages.
public void findUsages(List<UsageInfo> result, final boolean searchInStringsAndComments, final boolean searchInNonJavaFiles, List<UnresolvableCollisionUsageInfo> unresolvedUsages, Map<PsiElement, String> allRenames) {
for (Iterator<PsiNamedElement> iterator = myElements.iterator(); iterator.hasNext(); ) {
final PsiNamedElement variable = iterator.next();
RenameProcessor.assertNonCompileElement(variable);
final boolean success = findUsagesForElement(variable, result, searchInStringsAndComments, searchInNonJavaFiles, unresolvedUsages, allRenames);
if (!success) {
iterator.remove();
}
}
}
Aggregations