Search in sources :

Example 21 with PsiLiteralExpression

use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.

the class ShiftUtils method isPowerOfTwo.

public static boolean isPowerOfTwo(PsiExpression rhs) {
    if (!(rhs instanceof PsiLiteralExpression)) {
        return false;
    }
    final PsiLiteralExpression literal = (PsiLiteralExpression) rhs;
    final Object value = literal.getValue();
    if (!(value instanceof Number)) {
        return false;
    }
    if (value instanceof Double || value instanceof Float) {
        return false;
    }
    int intValue = ((Number) value).intValue();
    if (intValue <= 1) {
        return false;
    }
    while (intValue % 2 == 0) {
        intValue >>= 1;
    }
    return intValue == 1;
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression)

Example 22 with PsiLiteralExpression

use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.

the class ShiftUtils method isIntLiteral.

public static boolean isIntLiteral(PsiExpression rhs) {
    if (!(rhs instanceof PsiLiteralExpression)) {
        return false;
    }
    final PsiLiteralExpression literal = (PsiLiteralExpression) rhs;
    final Object value = literal.getValue();
    if (!(value instanceof Number)) {
        return false;
    }
    return !(value instanceof Double) && !(value instanceof Float);
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression)

Example 23 with PsiLiteralExpression

use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.

the class ShiftUtils method isPowerOfTwo.

public static boolean isPowerOfTwo(PsiExpression rhs) {
    if (!(rhs instanceof PsiLiteralExpression)) {
        return false;
    }
    final PsiLiteralExpression literal = (PsiLiteralExpression) rhs;
    final Object value = literal.getValue();
    if (!(value instanceof Number)) {
        return false;
    }
    if (value instanceof Double || value instanceof Float) {
        return false;
    }
    int intValue = ((Number) value).intValue();
    if (intValue <= 0) {
        return false;
    }
    while (intValue % 2 == 0) {
        intValue >>= 1;
    }
    return intValue == 1;
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression)

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