Search in sources :

Example 6 with PsiLiteralExpression

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);
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PsiLiteralExpression

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);
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression)

Example 8 with PsiLiteralExpression

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);
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression)

Example 9 with PsiLiteralExpression

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;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) PsiType(com.intellij.psi.PsiType)

Example 10 with PsiLiteralExpression

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;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) PsiType(com.intellij.psi.PsiType)

Aggregations

PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)23 PsiType (com.intellij.psi.PsiType)6 PsiElement (com.intellij.psi.PsiElement)5 NonNls (org.jetbrains.annotations.NonNls)4 Nullable (org.jetbrains.annotations.Nullable)4 TextRange (com.intellij.openapi.util.TextRange)2 PsiExpression (com.intellij.psi.PsiExpression)2 I18nQuickFixHandler (com.intellij.codeInspection.i18n.I18nQuickFixHandler)1 I18nizeAction (com.intellij.codeInspection.i18n.I18nizeAction)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 CaretModel (com.intellij.openapi.editor.CaretModel)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)1 PsiField (com.intellij.psi.PsiField)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1