Search in sources :

Example 6 with RatedResolveResult

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

the class ResolveResultList method poke.

// Allows to add non-null elements and discard nulls in a hassle-free way.
public boolean poke(final PsiElement what, final int rate) {
    PyPsiUtils.assertValid(what);
    if (what == null)
        return false;
    if (!(what instanceof LightElement) && !what.isValid()) {
        throw new PsiInvalidElementAccessException(what, "Trying to resolve a reference to an invalid element");
    }
    super.add(new RatedResolveResult(rate, what));
    return true;
}
Also used : PsiInvalidElementAccessException(com.intellij.psi.PsiInvalidElementAccessException) RatedResolveResult(com.jetbrains.python.psi.resolve.RatedResolveResult) LightElement(com.intellij.psi.impl.light.LightElement)

Example 7 with RatedResolveResult

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

the class PyClassTypeImpl method resolveInner.

@NotNull
private static List<? extends RatedResolveResult> resolveInner(@NotNull PyClass cls, boolean isDefinition, @NotNull String name, @Nullable PyExpression location) {
    final PyResolveProcessor processor = new PyResolveProcessor(name);
    final Collection<PsiElement> result;
    if (!isDefinition && !cls.processInstanceLevelDeclarations(processor, location)) {
        result = processor.getElements();
    } else {
        cls.processClassLevelDeclarations(processor);
        result = processor.getElements();
    }
    return ContainerUtil.map(result, element -> new RatedResolveResult(RatedResolveResult.RATE_NORMAL, element));
}
Also used : PyResolveProcessor(com.jetbrains.python.psi.resolve.PyResolveProcessor) RatedResolveResult(com.jetbrains.python.psi.resolve.RatedResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with RatedResolveResult

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

the class PyClassTypeImpl method resolveMetaClassMember.

@Nullable
private List<? extends RatedResolveResult> resolveMetaClassMember(@NotNull String name, @Nullable PyExpression location, @NotNull AccessDirection direction, @NotNull PyResolveContext resolveContext) {
    final TypeEvalContext context = resolveContext.getTypeEvalContext();
    if (!myClass.isNewStyleClass(context)) {
        return null;
    }
    final PyClassLikeType typeType = getMetaClassType(context, true);
    if (typeType == null) {
        return null;
    }
    if (isDefinition()) {
        final List<? extends RatedResolveResult> typeMembers = typeType.resolveMember(name, location, direction, resolveContext);
        if (!ContainerUtil.isEmpty(typeMembers)) {
            return typeMembers;
        }
        final List<? extends RatedResolveResult> typeInstanceMembers = typeType.toInstance().resolveMember(name, location, direction, resolveContext);
        if (!ContainerUtil.isEmpty(typeInstanceMembers)) {
            return typeInstanceMembers;
        }
    } else if (typeType instanceof PyClassType) {
        final List<PyTargetExpression> typeInstanceAttributes = ((PyClassType) typeType).getPyClass().getInstanceAttributes();
        if (!ContainerUtil.isEmpty(typeInstanceAttributes)) {
            final List<RatedResolveResult> typeInstanceAttributesWithSpecifiedName = typeInstanceAttributes.stream().filter(member -> name.equals(member.getName())).map(member -> new RatedResolveResult(PyReferenceImpl.getRate(member, context), member)).collect(Collectors.toList());
            if (!typeInstanceAttributesWithSpecifiedName.isEmpty()) {
                return typeInstanceAttributesWithSpecifiedName;
            }
        }
    }
    return null;
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) PyNames(com.jetbrains.python.PyNames) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) ContainerUtil(com.intellij.util.containers.ContainerUtil) PyUtil.as(com.jetbrains.python.psi.PyUtil.as) PyResolveProcessor(com.jetbrains.python.psi.resolve.PyResolveProcessor) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) CompletionVariantsProcessor(com.jetbrains.python.psi.resolve.CompletionVariantsProcessor) Lists(com.google.common.collect.Lists) PsiElement(com.intellij.psi.PsiElement) ResolveResultList(com.jetbrains.python.psi.impl.ResolveResultList) PsiFile(com.intellij.psi.PsiFile) com.jetbrains.python.psi(com.jetbrains.python.psi) QualifiedName(com.intellij.psi.util.QualifiedName) CompletionUtil(com.intellij.codeInsight.completion.CompletionUtil) PyCustomMemberUtils(com.jetbrains.python.codeInsight.PyCustomMemberUtils) PsiInvalidElementAccessException(com.intellij.psi.PsiInvalidElementAccessException) ProcessingContext(com.intellij.util.ProcessingContext) Extensions(com.intellij.openapi.extensions.Extensions) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) PyReferenceImpl(com.jetbrains.python.psi.impl.references.PyReferenceImpl) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RatedResolveResult(com.jetbrains.python.psi.resolve.RatedResolveResult) PyBuiltinCache(com.jetbrains.python.psi.impl.PyBuiltinCache) Nullable(org.jetbrains.annotations.Nullable) PyResolveResultRater(com.jetbrains.python.psi.impl.PyResolveResultRater) Maybe(com.jetbrains.python.toolbox.Maybe) PyResolveImportUtil.resolveTopLevelMember(com.jetbrains.python.psi.resolve.PyResolveImportUtil.resolveTopLevelMember) Processor(com.intellij.util.Processor) PyCustomMember(com.jetbrains.python.codeInsight.PyCustomMember) ObjectUtils(com.intellij.util.ObjectUtils) PyResolveImportUtil.fromFoothold(com.jetbrains.python.psi.resolve.PyResolveImportUtil.fromFoothold) NotNull(org.jetbrains.annotations.NotNull) ResolveResultList(com.jetbrains.python.psi.impl.ResolveResultList) RatedResolveResult(com.jetbrains.python.psi.resolve.RatedResolveResult) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RatedResolveResult (com.jetbrains.python.psi.resolve.RatedResolveResult)8 PsiElement (com.intellij.psi.PsiElement)5 PyResolveContext (com.jetbrains.python.psi.resolve.PyResolveContext)5 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)4 Sets (com.google.common.collect.Sets)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 PsiFile (com.intellij.psi.PsiFile)3 PsiInvalidElementAccessException (com.intellij.psi.PsiInvalidElementAccessException)3 ArrayUtil (com.intellij.util.ArrayUtil)3 ProcessingContext (com.intellij.util.ProcessingContext)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 com.jetbrains.python.psi (com.jetbrains.python.psi)3 PyResolveProcessor (com.jetbrains.python.psi.resolve.PyResolveProcessor)3 Lists (com.google.common.collect.Lists)2 CompletionUtil (com.intellij.codeInsight.completion.CompletionUtil)2 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)2 Extensions (com.intellij.openapi.extensions.Extensions)2 com.intellij.openapi.util (com.intellij.openapi.util)2 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)2