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;
}
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());
}
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());
}
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);
}
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;
}
Aggregations