use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class MavenPropertyCompletionContributor method addVariants.
public static void addVariants(Collection<?> variants, CompletionResultSet result) {
for (Object each : variants) {
LookupElement e;
if (each instanceof LookupElement) {
e = (LookupElement) each;
} else if (each instanceof String) {
e = LookupElementBuilder.create((String) each);
} else if (each instanceof PsiNamedElement) {
e = LookupElementBuilder.create((PsiNamedElement) each);
} else {
e = LookupElementBuilder.create(each, String.valueOf(each));
}
result.addElement(e);
}
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class ScopeImpl method getNamedElements.
@NotNull
@Override
public Collection<PsiNamedElement> getNamedElements(String name, boolean includeNestedGlobals) {
if (myNamedElements == null) {
collectDeclarations();
}
if (myNamedElements.containsKey(name)) {
final Collection<PsiNamedElement> elements = myNamedElements.get(name);
elements.forEach(PyPsiUtils::assertValid);
return elements;
}
if (includeNestedGlobals && isGlobal(name)) {
for (Scope scope : myNestedScopes) {
final Collection<PsiNamedElement> globals = scope.getNamedElements(name, true);
if (!globals.isEmpty()) {
globals.forEach(PyPsiUtils::assertValid);
return globals;
}
}
}
return Collections.emptyList();
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class PyDependentModuleMembersCollector method collect.
@Override
public void collect(final PsiNamedElement member) {
if (member.getContainingFile() == myModule) {
final PyResolveContext resolveContext = PyResolveContext.defaultContext();
final PsiElement memberBody = PyMoveModuleMembersHelper.expandNamedElementBody(member);
assert memberBody != null;
memberBody.accept(new PyRecursiveElementVisitor() {
@Override
public void visitElement(PsiElement element) {
for (PsiElement result : PyUtil.multiResolveTopPriority(element, resolveContext)) {
if (result != null && isValidSameModuleDependency(result) && result != member) {
myCollection.add((PsiNamedElement) result);
}
}
super.visitElement(element);
}
});
}
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class PyIntroduceParameterHandler method isNotDeclared.
private static boolean isNotDeclared(PsiElement element) {
final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(element);
final boolean[] isValid = { true };
if (scopeOwner != null) {
final String name = element instanceof PsiNamedElement ? ((PsiNamedElement) element).getName() : element.getText();
if (name != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(name)) {
return false;
}
new PyRecursiveElementVisitor() {
@Override
public void visitPyReferenceExpression(PyReferenceExpression node) {
super.visitPyReferenceExpression(node);
final String name = node.getName();
if (name != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(name)) {
isValid[0] = false;
}
}
}.visitElement(element);
}
return !isResolvedToParameter(element) && isValid[0];
}
use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.
the class PyInvertBooleanTest method doTest.
private void doTest(List<String> files) {
files.add(0, "refactoring/invertBoolean/" + getTestName(true) + ".before.py");
myFixture.configureByFiles(files.toArray(new String[files.size()]));
final PsiElement element = myFixture.getElementAtCaret();
assertTrue(element instanceof PsiNamedElement);
final PsiNamedElement target = (PsiNamedElement) element;
final String name = target.getName();
assertNotNull(name);
new InvertBooleanProcessor(target, "not" + StringUtil.toTitleCase(name)).run();
myFixture.checkResultByFile("refactoring/invertBoolean/" + getTestName(true) + ".after.py");
}
Aggregations