use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyMethodDescriptor method getParameters.
@Override
public List<PyParameterInfo> getParameters() {
List<PyParameterInfo> parameterInfos = new ArrayList<>();
PyParameter[] parameters = myFunction.getParameterList().getParameters();
for (int i = 0; i < parameters.length; i++) {
PyParameter parameter = parameters[i];
final PyExpression defaultValue = parameter.getDefaultValue();
final String name;
if (parameter instanceof PyNamedParameter) {
if (((PyNamedParameter) parameter).isPositionalContainer()) {
name = "*" + parameter.getName();
} else if (((PyNamedParameter) parameter).isKeywordContainer()) {
name = "**" + parameter.getName();
} else {
name = parameter.getName();
}
} else {
name = parameter.getText();
}
parameterInfos.add(new PyParameterInfo(i, name, defaultValue == null ? null : defaultValue.getText(), defaultValue != null && !StringUtil.isEmptyOrSpaces(defaultValue.getText())));
}
return parameterInfos;
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyIntroduceTestCase method buildSuggestions.
protected Collection<String> buildSuggestions(Class<? extends PyExpression> parentClass) {
myFixture.configureByFile(getTestName(true) + ".py");
final IntroduceHandler handler = createHandler();
final PyExpression expr = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getCaretOffset()), parentClass);
assertNotNull(expr);
return handler.getSuggestedNames(expr);
}
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;
}
Aggregations