Search in sources :

Example 51 with PsiType

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

the class GdslType method getName.

public String getName() {
    PsiType type = psiType;
    if (type instanceof PsiWildcardType) {
        type = ((PsiWildcardType) type).getBound();
    }
    if (type instanceof PsiClassType) {
        final PsiClass resolve = ((PsiClassType) type).resolve();
        if (resolve != null) {
            return resolve.getName();
        }
        final String canonicalText = type.getCanonicalText();
        final int i = canonicalText.indexOf('<');
        if (i < 0)
            return canonicalText;
        return canonicalText.substring(0, i);
    }
    if (type == null) {
        return "";
    }
    return type.getCanonicalText();
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiClass(com.intellij.psi.PsiClass) PsiWildcardType(com.intellij.psi.PsiWildcardType) PsiType(com.intellij.psi.PsiType)

Example 52 with PsiType

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

the class GroovyMapValueTypeEnhancer method getReferenceType.

@Override
public PsiType getReferenceType(GrReferenceExpression ref, @Nullable PsiElement resolved) {
    if (resolved != null)
        return null;
    GrExpression qualifierExpression = ref.getQualifierExpression();
    if (qualifierExpression == null)
        return null;
    PsiType mapType = qualifierExpression.getType();
    if (!InheritanceUtil.isInheritor(mapType, CommonClassNames.JAVA_UTIL_MAP)) {
        return null;
    }
    PsiElement qResolved;
    if (qualifierExpression instanceof GrReferenceExpression) {
        qResolved = ((GrReferenceExpression) qualifierExpression).resolve();
    } else if (qualifierExpression instanceof GrMethodCall) {
        qResolved = ((GrMethodCall) qualifierExpression).resolveMethod();
    } else {
        return null;
    }
    String key = ref.getReferenceName();
    if (key == null)
        return null;
    for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
        PsiType type = provider.getValueType(qualifierExpression, qResolved, key);
        if (type != null) {
            return type;
        }
    }
    if (mapType instanceof GrMapType) {
        return ((GrMapType) mapType).getTypeByStringKey(key);
    }
    return null;
}
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) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 53 with PsiType

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

the class EquivalenceChecker method safeCastExpressionsAreEquivalent.

private static boolean safeCastExpressionsAreEquivalent(GrSafeCastExpression expression1, GrSafeCastExpression expression2) {
    final GrExpression operand1 = expression1.getOperand();
    final GrExpression operand2 = expression2.getOperand();
    if (!expressionsAreEquivalent(operand1, operand2)) {
        return false;
    }
    final GrTypeElement typeElement1 = expression1.getCastTypeElement();
    final GrTypeElement typeElement2 = expression2.getCastTypeElement();
    final PsiType safe1 = typeElement1 == null ? null : typeElement1.getType();
    final PsiType safe2 = typeElement2 == null ? null : typeElement2.getType();
    return typesAreEquivalent(safe1, safe2);
}
Also used : GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) PsiType(com.intellij.psi.PsiType)

Example 54 with PsiType

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

the class EquivalenceChecker method variablesAreEquivalent.

private static boolean variablesAreEquivalent(@NotNull GrVariable var1, @NotNull GrVariable var2) {
    final GrExpression initializer1 = var1.getInitializerGroovy();
    final GrExpression initializer2 = var2.getInitializerGroovy();
    if (!expressionsAreEquivalent(initializer1, initializer2)) {
        return false;
    }
    final PsiType type1 = var1.getType();
    final PsiType type2 = var2.getType();
    if (!typesAreEquivalent(type1, type2)) {
        return false;
    }
    final String name1 = var1.getName();
    final String name2 = var2.getName();
    return name1.equals(name2);
}
Also used : PsiType(com.intellij.psi.PsiType)

Example 55 with PsiType

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

the class GroovyMethodReturnNamedArgumentProvider method getNamedArguments.

@Override
public void getNamedArguments(@NotNull GrCall call, @NotNull GroovyResolveResult resolveResult, @Nullable String argumentName, boolean forCompletion, @NotNull Map<String, NamedArgumentDescriptor> result) {
    PsiElement resolve = resolveResult.getElement();
    if (!forCompletion || !(resolve instanceof PsiMethod))
        return;
    PsiType returnType = ((PsiMethod) resolve).getReturnType();
    if (!(returnType instanceof PsiClassType))
        return;
    Map<String, NamedArgumentDescriptor> map = new HashMap<>();
    GroovyConstructorNamedArgumentProvider.processClass(call, (PsiClassType) returnType, argumentName, map);
    for (String name : map.keySet()) {
        result.put(name, NamedArgumentDescriptor.SIMPLE_UNLIKELY);
    }
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) PsiMethod(com.intellij.psi.PsiMethod) HashMap(java.util.HashMap) PsiElement(com.intellij.psi.PsiElement) 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