Search in sources :

Example 46 with QualifiedName

use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.

the class PyClassElementType method getSuperClassQNames.

@NotNull
public static Map<QualifiedName, QualifiedName> getSuperClassQNames(@NotNull final PyClass pyClass) {
    final Map<QualifiedName, QualifiedName> result = new LinkedHashMap<>();
    for (PyExpression expression : PyClassImpl.getUnfoldedSuperClassExpressions(pyClass)) {
        final QualifiedName importedQName = PyPsiUtils.asQualifiedName(expression);
        final QualifiedName originalQName = resolveOriginalSuperClassQName(expression);
        result.put(importedQName, originalQName);
    }
    return result;
}
Also used : QualifiedName(com.intellij.psi.util.QualifiedName) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with QualifiedName

use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.

the class PyFromImportStatementElementType method deserialize.

@NotNull
public PyFromImportStatementStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
    QualifiedName qName = QualifiedName.deserialize(dataStream);
    boolean isStarImport = dataStream.readBoolean();
    int relativeLevel = dataStream.readVarInt();
    return new PyFromImportStatementStubImpl(qName, isStarImport, relativeLevel, parentStub, getStubElementType());
}
Also used : QualifiedName(com.intellij.psi.util.QualifiedName) NotNull(org.jetbrains.annotations.NotNull)

Example 48 with QualifiedName

use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.

the class PyFromImportStatementElementType method serialize.

public void serialize(@NotNull PyFromImportStatementStub stub, @NotNull StubOutputStream dataStream) throws IOException {
    final QualifiedName qName = stub.getImportSourceQName();
    QualifiedName.serialize(qName, dataStream);
    dataStream.writeBoolean(stub.isStarImport());
    dataStream.writeVarInt(stub.getRelativeLevel());
}
Also used : QualifiedName(com.intellij.psi.util.QualifiedName)

Example 49 with QualifiedName

use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.

the class PyTargetExpressionElementType method createStub.

@NotNull
public PyTargetExpressionStub createStub(@NotNull final PyTargetExpression psi, final StubElement parentStub) {
    final String name = psi.getName();
    final PyExpression assignedValue = psi.findAssignedValue();
    final String docString = DocStringUtil.getDocStringValue(psi);
    final String typeComment = psi.getTypeCommentAnnotation();
    for (CustomTargetExpressionStubType customStubType : getCustomStubTypes()) {
        CustomTargetExpressionStub customStub = customStubType.createStub(psi);
        if (customStub != null) {
            return new PyTargetExpressionStubImpl(name, docString, typeComment, customStub, parentStub);
        }
    }
    PyTargetExpressionStub.InitializerType initializerType = PyTargetExpressionStub.InitializerType.Other;
    QualifiedName initializer = null;
    if (assignedValue instanceof PyReferenceExpression) {
        initializerType = PyTargetExpressionStub.InitializerType.ReferenceExpression;
        initializer = ((PyReferenceExpression) assignedValue).asQualifiedName();
    } else if (assignedValue instanceof PyCallExpression) {
        initializerType = PyTargetExpressionStub.InitializerType.CallExpression;
        final PyExpression callee = ((PyCallExpression) assignedValue).getCallee();
        if (callee instanceof PyReferenceExpression) {
            initializer = ((PyReferenceExpression) callee).asQualifiedName();
        }
    }
    return new PyTargetExpressionStubImpl(name, docString, initializerType, initializer, psi.isQualified(), typeComment, parentStub);
}
Also used : QualifiedName(com.intellij.psi.util.QualifiedName) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with QualifiedName

use of com.intellij.psi.util.QualifiedName in project intellij-community by JetBrains.

the class CompletionVariantsProcessor method setupItem.

private LookupElementBuilder setupItem(LookupElementBuilder item) {
    final PsiElement element = item.getPsiElement();
    if (!myPlainNamesOnly) {
        if (!mySuppressParentheses && element instanceof PyFunction && ((PyFunction) element).getProperty() == null && !PyUtil.hasCustomDecorators((PyFunction) element) && !isSingleArgDecoratorCall(myContext, (PyFunction) element)) {
            final Project project = element.getProject();
            item = item.withInsertHandler(PyFunctionInsertHandler.INSTANCE);
            final TypeEvalContext context = TypeEvalContext.codeCompletion(project, myContext != null ? myContext.getContainingFile() : null);
            final List<PyParameter> parameters = PyUtil.getParameters((PyFunction) element, context);
            final String params = StringUtil.join(parameters, pyParameter -> pyParameter.getName(), ", ");
            item = item.withTailText("(" + params + ")");
        } else if (element instanceof PyClass) {
            item = item.withInsertHandler(PyClassInsertHandler.INSTANCE);
        }
    }
    String source = null;
    if (element != null) {
        PyClass cls = null;
        if (element instanceof PyFunction) {
            cls = ((PyFunction) element).getContainingClass();
        } else if (element instanceof PyTargetExpression) {
            final PyTargetExpression expr = (PyTargetExpression) element;
            if (expr.isQualified() || ScopeUtil.getScopeOwner(expr) instanceof PyClass) {
                cls = expr.getContainingClass();
            }
        } else if (element instanceof PyClass) {
            final ScopeOwner owner = ScopeUtil.getScopeOwner(element);
            if (owner instanceof PyClass) {
                cls = (PyClass) owner;
            }
        }
        if (cls != null) {
            source = cls.getName();
        } else if (myContext == null || !PyUtil.inSameFile(myContext, element)) {
            QualifiedName path = QualifiedNameFinder.findCanonicalImportPath(element, null);
            if (path != null) {
                if (element instanceof PyFile) {
                    path = path.removeLastComponent();
                }
                source = path.toString();
            }
        }
    }
    if (source != null) {
        item = item.withTypeText(source);
    }
    return item;
}
Also used : Project(com.intellij.openapi.project.Project) ScopeOwner(com.jetbrains.python.codeInsight.controlflow.ScopeOwner) QualifiedName(com.intellij.psi.util.QualifiedName) PsiElement(com.intellij.psi.PsiElement) TypeEvalContext(com.jetbrains.python.psi.types.TypeEvalContext)

Aggregations

QualifiedName (com.intellij.psi.util.QualifiedName)63 Nullable (org.jetbrains.annotations.Nullable)22 NotNull (org.jetbrains.annotations.NotNull)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Project (com.intellij.openapi.project.Project)8 ScopeOwner (com.jetbrains.python.codeInsight.controlflow.ScopeOwner)7 PsiElement (com.intellij.psi.PsiElement)6 ArrayList (java.util.ArrayList)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 Sdk (com.intellij.openapi.projectRoots.Sdk)3 PsiFile (com.intellij.psi.PsiFile)3 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)2 StringRef (com.intellij.util.io.StringRef)2 PyClass (com.jetbrains.python.psi.PyClass)2 PyFunction (com.jetbrains.python.psi.PyFunction)2 PyClassTypeImpl (com.jetbrains.python.psi.types.PyClassTypeImpl)2 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)2 Instruction (com.intellij.codeInsight.controlflow.Instruction)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1