use of com.jetbrains.python.psi.PyNumericLiteralExpression in project intellij-community by JetBrains.
the class ReplaceOctalNumericLiteralQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement numericLiteralExpression = descriptor.getPsiElement();
if (numericLiteralExpression instanceof PyNumericLiteralExpression) {
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
String text = numericLiteralExpression.getText();
numericLiteralExpression.replace(elementGenerator.createExpressionFromText("0o" + text.substring(1)));
}
}
use of com.jetbrains.python.psi.PyNumericLiteralExpression in project intellij-community by JetBrains.
the class PyNumericLiteralTest method configureByText.
@NotNull
private PyNumericLiteralExpression configureByText(@NotNull String text) {
final PsiElement element = myFixture.configureByText(PythonFileType.INSTANCE, text).findElementAt(0);
assertNotNull(element);
final PyNumericLiteralExpression numericLiteralExpression = PyUtil.as(element.getParent(), PyNumericLiteralExpression.class);
assertNotNull(numericLiteralExpression);
return numericLiteralExpression;
}
use of com.jetbrains.python.psi.PyNumericLiteralExpression in project intellij-community by JetBrains.
the class PyNumericLiteralTest method doTestLiteral.
private void doTestLiteral(@NotNull String text, boolean isInteger, @Nullable Long expectedLong, @NotNull BigInteger expectedInt, @NotNull BigDecimal expectedDecimal, @NotNull String expectedType) {
final PyNumericLiteralExpression literal = configureByText(text);
assertEquals(isInteger, literal.isIntegerLiteral());
assertEquals(expectedLong, literal.getLongValue());
assertEquals(expectedInt, literal.getBigIntegerValue());
assertEquals(0, expectedDecimal.compareTo(literal.getBigDecimalValue()));
final PyType type = TypeEvalContext.codeInsightFallback(myFixture.getProject()).getType(literal);
assertNotNull(type);
assertEquals(expectedType, type.getName());
}
use of com.jetbrains.python.psi.PyNumericLiteralExpression in project intellij-community by JetBrains.
the class RemoveTrailingLQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement numericLiteralExpression = descriptor.getPsiElement();
if (numericLiteralExpression instanceof PyNumericLiteralExpression) {
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
String text = numericLiteralExpression.getText();
numericLiteralExpression.replace(elementGenerator.createExpressionFromText(text.substring(0, text.length() - 1)));
}
}
use of com.jetbrains.python.psi.PyNumericLiteralExpression in project intellij-community by JetBrains.
the class PyRemoveUnderscoresInNumericLiteralsQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
if (element instanceof PyNumericLiteralExpression) {
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
final String text = element.getText();
element.replace(elementGenerator.createExpressionFromText(LanguageLevel.forElement(element), text.replaceAll("_", "")));
}
}
Aggregations