use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class PyRenameArgumentQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
if (!(element instanceof PsiNamedElement))
return;
final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
if (virtualFile != null) {
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
final TemplateBuilderImpl builder = new TemplateBuilderImpl(element);
final String name = ((PsiNamedElement) element).getName();
assert name != null;
assert editor != null;
builder.replaceElement(element, TextRange.create(0, name.length()), name);
builder.run(editor, false);
}
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class DictionarySuggestionProvider method getSuggestedNames.
@Override
public SuggestedNameInfo getSuggestedNames(PsiElement element, PsiElement nameSuggestionContext, Set<String> result) {
assert result != null;
if (!active || nameSuggestionContext == null) {
return null;
}
String text = nameSuggestionContext.getText();
if (nameSuggestionContext instanceof PsiNamedElement) {
//noinspection ConstantConditions
text = ((PsiNamedElement) element).getName();
}
if (text == null) {
return null;
}
Project project = element.getProject();
SpellCheckerManager manager = SpellCheckerManager.getInstance(project);
manager.getSuggestions(text).stream().filter(newName -> RenameUtil.isValidName(project, element, newName)).forEach(result::add);
return SuggestedNameInfo.NULL_INFO;
}
use of com.intellij.psi.PsiNamedElement in project intellij-elixir by KronicDeth.
the class Variants method executeOnAliasedName.
/*
* Protected Instance Methods
*/
/**
* Decides whether {@code match} matches the criteria being searched for. All other {@link #execute} methods
* eventually end here.
*
* @param match
* @param aliasedName
* @param state
* @return {@code true} to keep processing; {@code false} to stop processing.
*/
@Override
protected boolean executeOnAliasedName(@NotNull PsiNamedElement match, @NotNull final String aliasedName, @NotNull ResolveState state) {
if (lookupElementList == null) {
lookupElementList = new ArrayList<LookupElement>();
}
lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedName, match));
String unaliasedName = UnaliasedName.unaliasedName(match);
if (unaliasedName != null) {
Project project = match.getProject();
Collection<String> indexedNameCollection = StubIndex.getInstance().getAllKeys(AllName.KEY, project);
List<String> unaliasedNestedNames = ContainerUtil.findAll(indexedNameCollection, new org.elixir_lang.Module.IsNestedUnder(unaliasedName));
if (unaliasedNestedNames.size() > 0) {
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
for (String unaliasedNestedName : unaliasedNestedNames) {
Collection<NamedElement> unaliasedNestedNamedElementCollection = StubIndex.getElements(AllName.KEY, unaliasedNestedName, project, scope, NamedElement.class);
if (unaliasedNestedNamedElementCollection.size() > 0) {
List<String> unaliasedNestedNamePartList = split(unaliasedNestedName);
List<String> unaliasedNamePartList = split(unaliasedName);
List<String> aliasedNamePartList = split(aliasedName);
List<String> aliasedNestedNamePartList = new ArrayList<String>();
aliasedNestedNamePartList.addAll(aliasedNamePartList);
for (int i = unaliasedNamePartList.size(); i < unaliasedNestedNamePartList.size(); i++) {
aliasedNestedNamePartList.add(unaliasedNestedNamePartList.get(i));
}
String aliasedNestedName = concat(aliasedNestedNamePartList);
for (NamedElement unaliasedNestedNamedElement : unaliasedNestedNamedElementCollection) {
lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedNestedName, unaliasedNestedNamedElement));
}
}
}
}
}
return true;
}
use of com.intellij.psi.PsiNamedElement in project intellij-elixir by KronicDeth.
the class Module method aliasedName.
@Nullable
private String aliasedName(@NotNull QualifiedAlias element) {
String aliasedName = null;
PsiElement[] children = element.getChildren();
int operatorIndex = org.elixir_lang.psi.operation.Normalized.operatorIndex(children);
PsiElement unqualified = org.elixir_lang.psi.operation.infix.Normalized.rightOperand(children, operatorIndex);
assert children.length == 3;
if (unqualified instanceof PsiNamedElement) {
PsiNamedElement namedElement = (PsiNamedElement) unqualified;
aliasedName = namedElement.getName();
}
return aliasedName;
}
use of com.intellij.psi.PsiNamedElement in project intellij-elixir by KronicDeth.
the class UnaliasedName method down.
/*
* Private Static Methods
*/
@Nullable
private static String down(@NotNull PsiElement element) {
String unaliasedName = null;
if (element instanceof QualifiableAlias) {
PsiNamedElement namedElement = (PsiNamedElement) element;
unaliasedName = namedElement.getName();
}
return unaliasedName;
}
Aggregations