use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyPackageUtilTest method checkSetupArgumentText.
private static void checkSetupArgumentText(@NotNull Module module, @NotNull String keyword, @Nullable String text) {
final PyCallExpression setupCall = PyPackageUtil.findSetupCall(module);
assertNotNull(setupCall);
final PyExpression argument = setupCall.getKeywordArgument(keyword);
if (text == null) {
assertNull(argument);
} else {
assertNotNull(argument);
assertEquals(text, argument.getText());
}
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class OldStyleConvertToFStringProcessor method convertSubstitutionChunk.
@Override
protected boolean convertSubstitutionChunk(@NotNull SubstitutionChunk subsChunk, @NotNull StringBuilder fStringText) {
final char conversionChar = subsChunk.getConversionType();
String widthAndPrecision = StringUtil.notNullize(subsChunk.getWidth());
if (StringUtil.isNotEmpty(subsChunk.getPrecision())) {
widthAndPrecision += "." + subsChunk.getPrecision();
}
final String conversionFlags = subsChunk.getConversionFlags();
fStringText.append("{");
final PySubstitutionChunkReference reference = createReference(subsChunk);
final PyExpression resolveResult = adjustResolveResult(reference.resolve());
assert resolveResult != null;
final PsiElement adjusted = prepareExpressionToInject(resolveResult, subsChunk);
if (adjusted == null)
return false;
fStringText.append(adjusted.getText());
// TODO mostly duplicates the logic of ConvertFormatOperatorToMethodIntention
if (conversionChar == 'r') {
fStringText.append("!r");
}
if ((conversionChar != 'r' && conversionChar != 's') || StringUtil.isNotEmpty(conversionFlags) || StringUtil.isNotEmpty(widthAndPrecision)) {
fStringText.append(":");
}
fStringText.append(convertFormatSpec(StringUtil.notNullize(conversionFlags), widthAndPrecision, String.valueOf(conversionChar)));
if (StringUtil.isNotEmpty(widthAndPrecision)) {
fStringText.append(widthAndPrecision);
}
if ('i' == conversionChar || 'u' == conversionChar) {
fStringText.append("d");
} else if ('s' != conversionChar && 'r' != conversionChar) {
fStringText.append(conversionChar);
}
fStringText.append("}");
return true;
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyConvertLiteralToTupleIntention method prepareOriginalElementCopy.
@NotNull
@Override
protected PsiElement prepareOriginalElementCopy(@NotNull PsiElement copy) {
final PySequenceExpression sequenceExpression = unwrapCollection(copy);
final PyExpression[] elements = sequenceExpression.getElements();
if (elements.length == 1) {
final PyExpression onlyElement = elements[0];
final PsiElement next = PyPsiUtils.getNextNonCommentSibling(onlyElement, true);
if (next != null && next.getNode().getElementType() != PyTokenTypes.COMMA) {
final PyElementGenerator generator = PyElementGenerator.getInstance(copy.getProject());
final ASTNode anchor = onlyElement.getNode().getTreeNext();
sequenceExpression.getNode().addChild(generator.createComma(), anchor);
}
}
return copy;
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyWithItemImpl method getTarget.
@Override
public PyExpression getTarget() {
ASTNode[] children = getNode().getChildren(null);
boolean foundAs = false;
for (ASTNode child : children) {
if (child.getElementType() == PyTokenTypes.AS_KEYWORD) {
foundAs = true;
} else if (foundAs && child.getPsi() instanceof PyExpression) {
return (PyExpression) child.getPsi();
}
}
return null;
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyYieldExpressionImpl method getType.
@Override
public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
final PyExpression e = getExpression();
PyType type = e != null ? context.getType(e) : null;
if (isDelegating()) {
final PyClassLikeType classType = as(type, PyClassLikeType.class);
final PyCollectionType collectionType = as(type, PyCollectionType.class);
if (classType != null && collectionType != null) {
if (PyTypingTypeProvider.GENERATOR.equals(classType.getClassQName())) {
final List<PyType> elementTypes = collectionType.getElementTypes(context);
if (elementTypes.size() == 3) {
return elementTypes.get(2);
}
}
}
return PyNoneType.INSTANCE;
}
return type;
}
Aggregations