use of com.jetbrains.python.psi.types.PyClassType in project intellij-community by JetBrains.
the class PyDebugProcess method typeToPosition.
@Nullable
private static XSourcePosition typeToPosition(PyType pyType) {
final PyClassType classType = PyUtil.as(pyType, PyClassType.class);
if (classType != null) {
return XDebuggerUtil.getInstance().createPositionByElement(classType.getPyClass());
}
final PyModuleType moduleType = PyUtil.as(pyType, PyModuleType.class);
if (moduleType != null) {
return XDebuggerUtil.getInstance().createPositionByElement(moduleType.getModule());
}
return null;
}
use of com.jetbrains.python.psi.types.PyClassType in project intellij-community by JetBrains.
the class PyOperatorReference method resolveMember.
@NotNull
private List<RatedResolveResult> resolveMember(@Nullable PyExpression object, @Nullable String name) {
final ArrayList<RatedResolveResult> results = new ArrayList<>();
if (object != null && name != null) {
final TypeEvalContext typeEvalContext = myContext.getTypeEvalContext();
PyType type = typeEvalContext.getType(object);
typeEvalContext.trace("Side text is %s, type is %s", object.getText(), type);
if (type instanceof PyClassLikeType) {
if (((PyClassLikeType) type).isDefinition()) {
type = ((PyClassLikeType) type).getMetaClassType(typeEvalContext, true);
}
}
if (type != null) {
List<? extends RatedResolveResult> res = type.resolveMember(name, object, AccessDirection.of(myElement), myContext);
if (res != null && res.size() > 0) {
results.addAll(res);
} else if (typeEvalContext.tracing()) {
VirtualFile vFile = null;
if (type instanceof PyClassType) {
final PyClass pyClass = ((PyClassType) type).getPyClass();
vFile = pyClass.getContainingFile().getVirtualFile();
}
type.resolveMember(name, object, AccessDirection.of(myElement), myContext);
typeEvalContext.trace("Could not resolve member %s in type %s from file %s", name, type, vFile);
}
}
}
return results;
}
use of com.jetbrains.python.psi.types.PyClassType in project intellij-community by JetBrains.
the class PyAddSpecifierToFormatQuickFix method applyFix.
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PyBinaryExpression expression = PsiTreeUtil.getParentOfType(element, PyBinaryExpression.class);
if (expression == null)
return;
PyExpression rightExpression = expression.getRightExpression();
if (rightExpression instanceof PyParenthesizedExpression) {
rightExpression = ((PyParenthesizedExpression) rightExpression).getContainedExpression();
}
if (rightExpression == null)
return;
final PsiFile file = element.getContainingFile();
final Document document = FileDocumentManager.getInstance().getDocument(file.getVirtualFile());
if (document == null)
return;
final int offset = element.getTextOffset();
final TypeEvalContext context = TypeEvalContext.userInitiated(file.getProject(), file);
final PyClassType strType = PyBuiltinCache.getInstance(element).getStrType();
final PyClassType floatType = PyBuiltinCache.getInstance(element).getFloatType();
final PyClassType intType = PyBuiltinCache.getInstance(element).getIntType();
final PyExpression leftExpression = expression.getLeftExpression();
if (leftExpression instanceof PyStringLiteralExpression) {
final List<PyStringFormatParser.SubstitutionChunk> chunks = filterSubstitutions(parsePercentFormat(((PyStringLiteralExpression) leftExpression).getStringValue()));
PyExpression[] elements;
if (rightExpression instanceof PyTupleExpression) {
elements = ((PyTupleExpression) rightExpression).getElements();
} else {
elements = new PyExpression[] { rightExpression };
}
int shift = 2;
for (int i = 0; i < chunks.size(); i++) {
final PyStringFormatParser.SubstitutionChunk chunk = chunks.get(i);
if (elements.length <= i)
return;
final PyType type = context.getType(elements[i]);
final char conversionType = chunk.getConversionType();
if (conversionType == '