Search in sources :

Example 1 with ImportedResolveResult

use of com.jetbrains.python.psi.resolve.ImportedResolveResult in project intellij-community by JetBrains.

the class DocStringTypeReference method multiResolve.

@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    PsiElement result = null;
    final ResolveResultList results = new ResolveResultList();
    if (myType instanceof PyClassType) {
        result = ((PyClassType) myType).getPyClass();
    } else if (myType instanceof PyImportedModuleType) {
        result = ((PyImportedModuleType) myType).getImportedModule().resolve();
    } else if (myType instanceof PyModuleType) {
        result = ((PyModuleType) myType).getModule();
    }
    if (result != null) {
        if (myImportElement != null) {
            results.add(new ImportedResolveResult(result, RatedResolveResult.RATE_NORMAL, myImportElement));
        } else {
            results.poke(result, RatedResolveResult.RATE_NORMAL);
        }
    }
    return results.toArray(ResolveResult.EMPTY_ARRAY);
}
Also used : ImportedResolveResult(com.jetbrains.python.psi.resolve.ImportedResolveResult) ResolveResultList(com.jetbrains.python.psi.impl.ResolveResultList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ImportedResolveResult

use of com.jetbrains.python.psi.resolve.ImportedResolveResult in project intellij-community by JetBrains.

the class PyResolveTest method testUnresolvedImport.

public void testUnresolvedImport() {
    final ResolveResult[] results = multiResolve();
    assertEquals(1, results.length);
    UsefulTestCase.assertInstanceOf(results[0], ImportedResolveResult.class);
    ImportedResolveResult result = (ImportedResolveResult) results[0];
    assertNull(result.getElement());
}
Also used : ImportedResolveResult(com.jetbrains.python.psi.resolve.ImportedResolveResult) ImportedResolveResult(com.jetbrains.python.psi.resolve.ImportedResolveResult) ResolveResult(com.intellij.psi.ResolveResult)

Example 3 with ImportedResolveResult

use of com.jetbrains.python.psi.resolve.ImportedResolveResult in project intellij by bazelbuild.

the class BlazePyBuiltinReferenceResolveProvider method resolveName.

@Override
public List<RatedResolveResult> resolveName(PyQualifiedExpression element, TypeEvalContext context) {
    if (!Blaze.isBlazeProject(element.getProject())) {
        return ImmutableList.of();
    }
    PyBuiltinCache cache = getBuiltInCache(element);
    if (cache == null) {
        return ImmutableList.of();
    }
    String referencedName = element.getReferencedName();
    if (referencedName == null) {
        return ImmutableList.of();
    }
    List<RatedResolveResult> result = Lists.newArrayList();
    PyFile bfile = cache.getBuiltinsFile();
    if (bfile != null && !PyUtil.isClassPrivateName(referencedName)) {
        PsiElement resultElement = bfile.getElementNamed(referencedName);
        if (resultElement == null && "__builtins__".equals(referencedName)) {
            // resolve __builtins__ reference
            resultElement = bfile;
        }
        if (resultElement != null) {
            result.add(new ImportedResolveResult(resultElement, PyReferenceImpl.getRate(resultElement, context), null));
        }
    }
    return result;
}
Also used : ImportedResolveResult(com.jetbrains.python.psi.resolve.ImportedResolveResult) PyFile(com.jetbrains.python.psi.PyFile) RatedResolveResult(com.jetbrains.python.psi.resolve.RatedResolveResult) PsiElement(com.intellij.psi.PsiElement) PyBuiltinCache(com.jetbrains.python.psi.impl.PyBuiltinCache)

Aggregations

ImportedResolveResult (com.jetbrains.python.psi.resolve.ImportedResolveResult)3 PsiElement (com.intellij.psi.PsiElement)1 ResolveResult (com.intellij.psi.ResolveResult)1 PyFile (com.jetbrains.python.psi.PyFile)1 PyBuiltinCache (com.jetbrains.python.psi.impl.PyBuiltinCache)1 ResolveResultList (com.jetbrains.python.psi.impl.ResolveResultList)1 RatedResolveResult (com.jetbrains.python.psi.resolve.RatedResolveResult)1 NotNull (org.jetbrains.annotations.NotNull)1