Search in sources :

Example 1 with KnownDecorator

use of com.jetbrains.python.psi.PyKnownDecoratorUtil.KnownDecorator in project intellij-community by JetBrains.

the class PyKnownDecoratorUtil method asKnownDecorator.

@Nullable
public static KnownDecorator asKnownDecorator(@NotNull PyDecorator decorator, @NotNull TypeEvalContext context) {
    final QualifiedName qualifiedName = decorator.getQualifiedName();
    if (qualifiedName == null) {
        return null;
    }
    if (context.maySwitchToAST(decorator)) {
        PyQualifiedNameOwner resolved = as(resolveDecorator(decorator), PyQualifiedNameOwner.class);
        if (resolved instanceof PyFunction && PyNames.INIT.equals(resolved.getName())) {
            resolved = ((PyFunction) resolved).getContainingClass();
        }
        if (resolved != null && resolved.getQualifiedName() != null) {
            final QualifiedName resolvedName = QualifiedName.fromDottedString(resolved.getQualifiedName());
            final KnownDecorator knownDecorator = ourByShortName.get(resolvedName.getLastComponent());
            if (knownDecorator != null && resolvedName.equals(knownDecorator.getQualifiedName())) {
                return knownDecorator;
            }
        }
    } else {
        return ourByShortName.get(qualifiedName.getLastComponent());
    }
    return null;
}
Also used : QualifiedName(com.intellij.psi.util.QualifiedName) KnownDecorator(com.jetbrains.python.psi.PyKnownDecoratorUtil.KnownDecorator) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

QualifiedName (com.intellij.psi.util.QualifiedName)1 KnownDecorator (com.jetbrains.python.psi.PyKnownDecoratorUtil.KnownDecorator)1 Nullable (org.jetbrains.annotations.Nullable)1