use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class PyQualifiedReference method addImplicitResolveResults.
private void addImplicitResolveResults(String referencedName, ResolveResultList ret) {
final Project project = myElement.getProject();
final GlobalSearchScope scope = PyProjectScopeBuilder.excludeSdkTestsScope(project);
final Collection functions = PyFunctionNameIndex.find(referencedName, project, scope);
final PsiFile containingFile = myElement.getContainingFile();
final List<QualifiedName> imports;
if (containingFile instanceof PyFile) {
imports = collectImports((PyFile) containingFile);
} else {
imports = Collections.emptyList();
}
for (Object function : functions) {
if (!(function instanceof PyFunction)) {
FileBasedIndex.getInstance().scheduleRebuild(StubUpdatingIndex.INDEX_ID, new Throwable("found non-function object " + function + " in function list"));
break;
}
PyFunction pyFunction = (PyFunction) function;
if (pyFunction.getContainingClass() != null) {
ret.add(new ImplicitResolveResult(pyFunction, getImplicitResultRate(pyFunction, imports)));
}
}
final Collection attributes = PyInstanceAttributeIndex.find(referencedName, project, scope);
for (Object attribute : attributes) {
if (!(attribute instanceof PyTargetExpression)) {
FileBasedIndex.getInstance().scheduleRebuild(StubUpdatingIndex.INDEX_ID, new Throwable("found non-target expression object " + attribute + " in target expression list"));
break;
}
ret.add(new ImplicitResolveResult((PyTargetExpression) attribute, getImplicitResultRate((PyTargetExpression) attribute, imports)));
}
}
use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class PyQualifiedReference method collectAssignedAttributes.
/**
* Returns expressions accessible from scope of "anchor" with names that start with provided "qualifierQName".
* Can be used for completion.
*/
@NotNull
public static Collection<PyExpression> collectAssignedAttributes(@NotNull final QualifiedName qualifierQName, @NotNull final PsiElement anchor) {
final Set<String> names = new HashSet<>();
final List<PyExpression> results = new ArrayList<>();
for (ScopeOwner owner = ScopeUtil.getScopeOwner(anchor); owner != null; owner = ScopeUtil.getScopeOwner(owner)) {
final Scope scope = ControlFlowCache.getScope(owner);
for (final PyTargetExpression target : scope.getTargetExpressions()) {
final QualifiedName targetQName = target.asQualifiedName();
if (targetQName != null) {
if (targetQName.getComponentCount() == qualifierQName.getComponentCount() + 1 && targetQName.matchesPrefix(qualifierQName)) {
final String name = target.getName();
if (!names.contains(name)) {
names.add(name);
results.add(target);
}
}
}
}
}
return results;
}
use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class PyTargetExpressionImpl method resolveAssignedValue.
@Nullable
@Override
public PsiElement resolveAssignedValue(@NotNull PyResolveContext resolveContext) {
final TypeEvalContext context = resolveContext.getTypeEvalContext();
if (context.maySwitchToAST(this)) {
final PyExpression value = findAssignedValue();
if (value != null) {
final List<PsiElement> results = PyUtil.multiResolveTopPriority(value, resolveContext);
return !results.isEmpty() ? results.get(0) : null;
}
return null;
} else {
final QualifiedName qName = getAssignedQName();
if (qName != null) {
final ScopeOwner owner = ScopeUtil.getScopeOwner(this);
if (owner instanceof PyTypedElement) {
final List<String> components = qName.getComponents();
if (!components.isEmpty()) {
PsiElement resolved = owner;
for (String component : components) {
if (!(resolved instanceof PyTypedElement)) {
return null;
}
final PyType qualifierType = context.getType((PyTypedElement) resolved);
if (qualifierType == null) {
return null;
}
final List<? extends RatedResolveResult> results = qualifierType.resolveMember(component, null, AccessDirection.READ, resolveContext);
if (results == null || results.isEmpty()) {
return null;
}
resolved = results.get(0).getElement();
}
return resolved;
}
}
}
return null;
}
}
use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class PyImportStatementImpl method multiResolveName.
@NotNull
@Override
public List<RatedResolveResult> multiResolveName(@NotNull String name) {
final PyImportElement[] elements = getImportElements();
if (elements.length == 1) {
final PyImportElement element = elements[0];
final QualifiedName importedQName = element.getImportedQName();
if (importedQName != null && importedQName.getComponentCount() > 1 && name.equals(importedQName.getLastComponent())) {
return ResolveResultList.to(resolveImplicitSubModule());
}
}
return Collections.emptyList();
}
use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.
the class PythonStringUtil method intersect.
@Nullable
public static String intersect(String fullName, String elementStringValue) {
QualifiedName fullQName = QualifiedName.fromDottedString(fullName);
QualifiedName stringQName = QualifiedName.fromDottedString(elementStringValue);
String[] s1 = stringQName.getComponents().toArray(new String[stringQName.getComponentCount()]);
String[] s2 = fullQName.getComponents().toArray(new String[fullQName.getComponentCount()]);
for (int i = s1.length - 1; i >= 0; i--) {
boolean flag = true;
if (i > s2.length - 1) {
continue;
}
for (int j = 0; j <= i; j++) {
if (!s1[i - j].equals(s2[s2.length - j - 1])) {
flag = false;
break;
}
}
if (flag) {
StringBuilder res = new StringBuilder("");
for (int j = 0; j <= i; j++) {
if (j > 0) {
res.append(".");
}
res.append(s1[j]);
}
return res.toString();
}
}
return null;
}
Aggregations