use of com.intellij.codeInsight.lookup.LookupElement 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.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.
the class Variants method addToLookupElementByPsiElement.
/*
* Private Instance Methods
*/
private void addToLookupElementByPsiElement(@NotNull Call call) {
if (call instanceof Named) {
Named named = (Named) call;
PsiElement nameIdentifier = named.getNameIdentifier();
if (nameIdentifier != null) {
if (lookupElementByPsiElement == null || !lookupElementByPsiElement.containsKey(nameIdentifier)) {
if (lookupElementByPsiElement == null) {
lookupElementByPsiElement = new THashMap<PsiElement, LookupElement>();
}
String name = nameIdentifier.getText();
lookupElementByPsiElement.put(nameIdentifier, LookupElementBuilder.createWithSmartPointer(name, nameIdentifier).withRenderer(new org.elixir_lang.code_insight.lookup.element_renderer.CallDefinitionClause(name)));
}
}
}
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.
the class CallDefinitionClause method callDefinitionClauseLookupElements.
/*
* Private Instance Methods
*/
@NotNull
private static Iterable<LookupElement> callDefinitionClauseLookupElements(@NotNull Call scope) {
Call[] childCalls = macroChildCalls(scope);
List<LookupElement> lookupElementList = null;
if (childCalls != null && childCalls.length > 0) {
for (Call childCall : childCalls) {
if (org.elixir_lang.structure_view.element.CallDefinitionClause.is(childCall)) {
Pair<String, IntRange> nameArityRange = nameArityRange(childCall);
if (nameArityRange != null) {
String name = nameArityRange.first;
if (name != null) {
if (lookupElementList == null) {
lookupElementList = new ArrayList<LookupElement>();
}
lookupElementList.add(org.elixir_lang.code_insight.lookup.element.CallDefinitionClause.createWithSmartPointer(nameArityRange.first, childCall));
}
}
}
}
}
if (lookupElementList == null) {
lookupElementList = Collections.emptyList();
}
return lookupElementList;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-elixir by KronicDeth.
the class Variants method executeOnVariable.
/*
*
* Instance Methods
*
*/
/*
* Protected Instance Methods
*/
/**
* Decides whether {@code match} matches the criteria being searched for. All other {@link #execute} methods
* eventually end here.
*
* @return {@code false}, as all variables should be found. Prefix filtering will be done later by IDEA core.
*/
@Override
protected boolean executeOnVariable(@NotNull PsiNamedElement match, @NotNull ResolveState state) {
PsiReference reference = match.getReference();
String name = null;
PsiElement declaration = match;
if (reference != null) {
PsiElement resolved = reference.resolve();
if (resolved != null) {
declaration = resolved;
if (resolved instanceof PsiNamedElement) {
PsiNamedElement namedResolved = (PsiNamedElement) resolved;
name = namedResolved.getName();
}
}
}
if (name == null) {
name = match.getName();
}
if (name != null) {
if (lookupElementByElement == null) {
lookupElementByElement = new THashMap<PsiElement, LookupElement>();
}
if (!lookupElementByElement.containsKey(declaration)) {
final String finalName = name;
lookupElementByElement.put(declaration, LookupElementBuilder.createWithSmartPointer(name, declaration).withRenderer(new org.elixir_lang.code_insight.lookup.element_renderer.Variable(finalName)));
}
}
return true;
}
use of com.intellij.codeInsight.lookup.LookupElement in project intellij-community by JetBrains.
the class RenameWrongRefFix method invoke.
@Override
public void invoke(@NotNull Project project, final Editor editor, PsiFile file) {
PsiReferenceExpression[] refs = CreateFromUsageUtils.collectExpressions(myRefExpr, PsiMember.class, PsiFile.class);
PsiElement element = PsiTreeUtil.getParentOfType(myRefExpr, PsiMember.class, PsiFile.class);
LookupElement[] items = collectItems();
ReferenceNameExpression refExpr = new ReferenceNameExpression(items, myRefExpr.getReferenceName());
TemplateBuilderImpl builder = new TemplateBuilderImpl(element);
for (PsiReferenceExpression expr : refs) {
if (!expr.equals(myRefExpr)) {
builder.replaceElement(expr.getReferenceNameElement(), OTHER_VARIABLE_NAME, INPUT_VARIABLE_NAME, false);
} else {
builder.replaceElement(expr.getReferenceNameElement(), INPUT_VARIABLE_NAME, refExpr, true);
}
}
final float proportion = EditorUtil.calcVerticalScrollProportion(editor);
editor.getCaretModel().moveToOffset(element.getTextRange().getStartOffset());
/*for (int i = refs.length - 1; i >= 0; i--) {
TextRange range = refs[i].getReferenceNameElement().getTextRange();
document.deleteString(range.getStartOffset(), range.getEndOffset());
}
*/
Template template = builder.buildInlineTemplate();
editor.getCaretModel().moveToOffset(element.getTextRange().getStartOffset());
TemplateManager.getInstance(project).startTemplate(editor, template);
EditorUtil.setVerticalScrollProportion(editor, proportion);
}
Aggregations