Search in sources :

Example 91 with PsiType

use of com.intellij.psi.PsiType in project android by JetBrains.

the class PsiCFGPartialMethodSignatureBuilder method buildFromPsiMethod.

public static PsiCFGPartialMethodSignature buildFromPsiMethod(PsiMethod psiMethod) {
    PsiCFGPartialMethodSignature retSignature = new PsiCFGPartialMethodSignature();
    retSignature.methodName = psiMethod.getName().trim();
    if (psiMethod.isVarArgs()) {
        retSignature.isVarArgs = true;
    }
    PsiParameter[] paramList = psiMethod.getParameterList().getParameters();
    if (paramList == null || paramList.length == 0) {
        retSignature.parameterTypes = PsiType.EMPTY_ARRAY;
    } else {
        retSignature.parameterTypes = new PsiType[paramList.length];
        for (int i = 0; i < paramList.length; i++) {
            PsiType curParamType = paramList[i].getType();
            retSignature.parameterTypes[i] = curParamType;
        }
    }
    return retSignature;
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiType(com.intellij.psi.PsiType)

Example 92 with PsiType

use of com.intellij.psi.PsiType in project android by JetBrains.

the class GradleSettingsFile method getProjectLocation.

/**
   * Obtains custom module location from the Gradle script. Currently it only recognizes File ctor invocation with a string constant.
   */
@Nullable
private static File getProjectLocation(@Nullable GrExpression rValue) {
    if (rValue instanceof GrNewExpression) {
        PsiType type = rValue.getType();
        String typeName = type != null ? type.getCanonicalText() : null;
        if (File.class.getName().equals(typeName) || File.class.getSimpleName().equals(typeName)) {
            String path = getSingleStringArgumentValue(((GrNewExpression) rValue));
            return path == null ? null : new File(path);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 93 with PsiType

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

the class ConvertToScientificNotationPredicate 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.DOUBLE.equals(type) && !PsiType.FLOAT.equals(type)) {
        return false;
    }
    String text = expression.getText();
    if (text == null) {
        return false;
    }
    text = text.toLowerCase();
    text = StringUtil.trimStart(text, "-");
    if (!text.contains(".") && text.startsWith("0")) {
        //Octal integer
        return false;
    }
    return !text.contains("e");
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) PsiType(com.intellij.psi.PsiType)

Example 94 with PsiType

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

the class ConvertIntegerToDecimalPredicate 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();
        if (text == null || text.length() < 2) {
            return false;
        }
        if ("0".equals(text) || "0L".equals(text) || "0l".equals(text)) {
            return false;
        }
        return text.charAt(0) == '0';
    }
    if (PsiType.DOUBLE.equals(type) || PsiType.FLOAT.equals(type)) {
        @NonNls final String text = expression.getText();
        if (text == null || text.length() < 2) {
            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 95 with PsiType

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

the class ConvertNumberIntentionBase method processIntention.

@Override
protected void processIntention(@NotNull final PsiElement element) throws IncorrectOperationException {
    final PsiExpression expression = (PsiExpression) element;
    final Number value = (Number) ExpressionUtils.computeConstantExpression(expression);
    if (value == null)
        return;
    final PsiType type = expression.getType();
    final boolean negated = ExpressionUtils.isNegative(expression);
    final String resultString = convertValue(value, type, negated);
    if (resultString == null)
        return;
    if (negated) {
        PsiReplacementUtil.replaceExpression((PsiExpression) expression.getParent(), resultString);
    } else {
        PsiReplacementUtil.replaceExpression(expression, resultString);
    }
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiType(com.intellij.psi.PsiType)

Aggregations

PsiType (com.intellij.psi.PsiType)157 PsiElement (com.intellij.psi.PsiElement)34 Nullable (org.jetbrains.annotations.Nullable)24 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)24 NotNull (org.jetbrains.annotations.NotNull)21 PsiClassType (com.intellij.psi.PsiClassType)20 PsiClass (com.intellij.psi.PsiClass)14 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)13 PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)12 ArrayList (java.util.ArrayList)9 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)9 PsiArrayType (com.intellij.psi.PsiArrayType)7 PsiExpression (com.intellij.psi.PsiExpression)7 PsiField (com.intellij.psi.PsiField)7 NonNls (org.jetbrains.annotations.NonNls)7 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)7 PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)6 PsiMethod (com.intellij.psi.PsiMethod)6 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)6 GrLiteral (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral)6