Search in sources :

Example 31 with PsiType

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

the class GrInplaceVariableIntroducer method addAdditionalVariables.

@Override
protected void addAdditionalVariables(TemplateBuilderImpl builder) {
    GrVariable variable = getVariable();
    assert variable != null && variable.getInitializerGroovy() != null;
    final PsiType initializerType = variable.getInitializerGroovy().getType();
    TypeConstraint[] constraints = initializerType != null && !initializerType.equals(PsiType.NULL) ? new SupertypeConstraint[] { SupertypeConstraint.create(initializerType) } : TypeConstraint.EMPTY_ARRAY;
    ChooseTypeExpression typeExpression = new ChooseTypeExpression(constraints, variable.getManager(), variable.getResolveScope(), true, GroovyApplicationSettings.getInstance().INTRODUCE_LOCAL_SELECT_DEF);
    PsiElement element = getTypeELementOrDef(variable);
    if (element == null)
        return;
    builder.replaceElement(element, "Variable_type", typeExpression, true, true);
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) TypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.TypeConstraint) ChooseTypeExpression(org.jetbrains.plugins.groovy.template.expressions.ChooseTypeExpression) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

Example 32 with PsiType

use of com.intellij.psi.PsiType in project timber by JakeWharton.

the class WrongTimberUsageDetector method getType.

private static Class<?> getType(PsiExpression expression) {
    if (expression == null) {
        return null;
    }
    if (expression instanceof PsiMethodCallExpression) {
        PsiMethodCallExpression call = (PsiMethodCallExpression) expression;
        PsiMethod method = call.resolveMethod();
        if (method == null) {
            return null;
        }
        String methodName = method.getName();
        if (methodName.equals(GET_STRING_METHOD)) {
            return String.class;
        }
    } else if (expression instanceof PsiLiteralExpression) {
        PsiLiteralExpression literalExpression = (PsiLiteralExpression) expression;
        PsiType expressionType = literalExpression.getType();
        if (LintUtils.isString(expressionType)) {
            return String.class;
        } else if (expressionType == PsiType.INT) {
            return Integer.TYPE;
        } else if (expressionType == PsiType.FLOAT) {
            return Float.TYPE;
        } else if (expressionType == PsiType.CHAR) {
            return Character.TYPE;
        } else if (expressionType == PsiType.BOOLEAN) {
            return Boolean.TYPE;
        } else if (expressionType == PsiType.NULL) {
            return Object.class;
        }
    }
    PsiType type = expression.getType();
    if (type != null) {
        Class<?> typeClass = getTypeClass(type);
        return typeClass != null ? typeClass : Object.class;
    }
    return null;
}
Also used : PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) PsiMethod(com.intellij.psi.PsiMethod) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression) PsiType(com.intellij.psi.PsiType)

Example 33 with PsiType

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

the class TargetType method create.

@Nullable
public static TargetType create(final PsiArrayType arrayType) {
    PsiType currentComponentType = arrayType.getComponentType();
    while (currentComponentType instanceof PsiArrayType) {
        currentComponentType = ((PsiArrayType) currentComponentType).getComponentType();
    }
    if (!(currentComponentType instanceof PsiClassType)) {
        return null;
    }
    final String targetQName = arrayType.getCanonicalText();
    return new TargetType(targetQName, true, arrayType);
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiArrayType(com.intellij.psi.PsiArrayType) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 34 with PsiType

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

the class StringBufferFieldInspection method buildErrorString.

@Override
@NotNull
public String buildErrorString(Object... infos) {
    final PsiType type = (PsiType) infos[0];
    final String typeName = type.getPresentableText();
    return InspectionGadgetsBundle.message("stringbuffer.field.problem.descriptor", typeName);
}
Also used : PsiType(com.intellij.psi.PsiType) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with PsiType

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

the class BadExceptionThrownInspectionBase method buildErrorString.

@Override
@NotNull
public String buildErrorString(Object... infos) {
    final PsiType type = (PsiType) infos[0];
    final String exceptionName = type.getPresentableText();
    return InspectionGadgetsBundle.message("bad.exception.thrown.problem.descriptor", exceptionName);
}
Also used : PsiType(com.intellij.psi.PsiType) NotNull(org.jetbrains.annotations.NotNull)

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