Search in sources :

Example 26 with PsiType

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

the class GroovyNameSuggestionProvider method getSuggestedNames.

@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, @Nullable PsiElement nameSuggestionContext, Set<String> result) {
    if (nameSuggestionContext == null)
        nameSuggestionContext = element;
    if (element instanceof GrVariable && nameSuggestionContext instanceof GroovyPsiElement) {
        final PsiType type = ((GrVariable) element).getTypeGroovy();
        if (type != null) {
            final String[] names = GroovyNameSuggestionUtil.suggestVariableNameByType(type, new DefaultGroovyVariableNameValidator((GroovyPsiElement) nameSuggestionContext));
            result.addAll(Arrays.asList(names));
            return new SuggestedNameInfo(names) {

                @Override
                public void nameChosen(String name) {
                    JavaStatisticsManager.incVariableNameUseCount(name, JavaCodeStyleManager.getInstance(element.getProject()).getVariableKind((GrVariable) element), ((GrVariable) element).getName(), type);
                }
            };
        }
    }
    return null;
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo) PsiType(com.intellij.psi.PsiType)

Example 27 with PsiType

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

the class ClassGenerator method shouldBeGenerated.

private static boolean shouldBeGenerated(PsiMethod method) {
    for (PsiMethod psiMethod : method.findSuperMethods()) {
        if (!psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
            final PsiType type = method.getReturnType();
            final PsiType superType = psiMethod.getReturnType();
            if (type != null && superType != null && !superType.isAssignableFrom(type)) {
                return false;
            }
        }
    }
    return true;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiType(com.intellij.psi.PsiType)

Example 28 with PsiType

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

the class MapKeysCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    GrReferenceExpression expression = (GrReferenceExpression) element.getParent();
    GrExpression qualifierExpression = expression.getQualifierExpression();
    if (qualifierExpression == null)
        return;
    PsiType mapType = qualifierExpression.getType();
    if (!InheritanceUtil.isInheritor(mapType, CommonClassNames.JAVA_UTIL_MAP)) {
        return;
    }
    PsiElement resolve = null;
    if (qualifierExpression instanceof GrMethodCall) {
        resolve = ((GrMethodCall) qualifierExpression).resolveMethod();
    } else if (qualifierExpression instanceof GrReferenceExpression) {
        resolve = ((GrReferenceExpression) qualifierExpression).resolve();
    }
    for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
        GroovyMapCompletionUtil.addKeyVariants(provider, qualifierExpression, resolve, result);
    }
    if (mapType instanceof GrMapType) {
        for (String key : ((GrMapType) mapType).getStringKeys()) {
            LookupElement lookup = LookupElementBuilder.create(key);
            lookup = PrioritizedLookupElement.withPriority(lookup, 1);
            result.addElement(lookup);
        }
    }
}
Also used : GrMapType(org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GroovyMapContentProvider(org.jetbrains.plugins.groovy.extensions.GroovyMapContentProvider) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) PsiType(com.intellij.psi.PsiType)

Example 29 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 30 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)

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