use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class ConvertOctalLiteralToDecimalFix method doFix.
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
if (!(element instanceof PsiLiteralExpression)) {
return;
}
final PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
final Object value = literalExpression.getValue();
if (value == null) {
return;
}
final String decimalText = value + (PsiType.LONG.equals(literalExpression.getType()) ? "L" : "");
PsiReplacementUtil.replaceExpression(literalExpression, decimalText);
}
use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class RemoveLeadingZeroFix method doFix.
@Override
protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiLiteralExpression literal = (PsiLiteralExpression) descriptor.getPsiElement();
final String text = literal.getText();
final int max = text.length() - (PsiType.LONG.equals(literal.getType()) ? 2 : 1);
if (max < 1) {
return;
}
int index = 0;
while (index < max && (text.charAt(index) == '0' || text.charAt(index) == '_')) {
index++;
}
final String textWithoutLeadingZeros = text.substring(index);
PsiReplacementUtil.replaceExpression(literal, textWithoutLeadingZeros);
}
use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class StringToCharIntention method processIntention.
@Override
public void processIntention(PsiElement element) throws IncorrectOperationException {
final PsiLiteralExpression stringLiteral = (PsiLiteralExpression) element;
final String stringLiteralText = stringLiteral.getText();
final String charLiteral = charForStringLiteral(stringLiteralText);
PsiReplacementUtil.replaceExpression(stringLiteral, charLiteral);
}
use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class ConvertIntegerToHexPredicate method satisfiedBy.
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiLiteralExpression)) {
return false;
}
final PsiLiteralExpression expression = (PsiLiteralExpression) element;
final PsiType type = expression.getType();
if (PsiType.INT.equals(type) || PsiType.LONG.equals(type)) {
@NonNls final String text = expression.getText();
return !(text.startsWith("0x") || text.startsWith("0X"));
}
if (PsiType.DOUBLE.equals(type) || PsiType.FLOAT.equals(type)) {
if (!PsiUtil.isLanguageLevel5OrHigher(expression)) {
return false;
}
@NonNls final String text = expression.getText();
if (text == null) {
return false;
}
return !text.startsWith("0x") && !text.startsWith("0X");
}
return false;
}
use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class ConvertIntegerToOctalPredicate method satisfiedBy.
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiLiteralExpression)) {
return false;
}
final PsiLiteralExpression expression = (PsiLiteralExpression) element;
final PsiType type = expression.getType();
if (!(PsiType.INT.equals(type) || PsiType.LONG.equals(type))) {
return false;
}
@NonNls final String text = expression.getText();
if (text.charAt(0) != '0') {
return true;
}
if (text.length() < 2) {
return true;
}
final char c1 = text.charAt(1);
if (c1 != '_' && (c1 < '0' || c1 > '7')) {
return true;
}
return false;
}
Aggregations