Search in sources :

Example 1 with PsiWildcardType

use of com.intellij.psi.PsiWildcardType 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 2 with PsiWildcardType

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

the class ClosureAsAnonymousParameterEnhancer method getClosureParameterType.

@Nullable
@Override
protected PsiType getClosureParameterType(GrClosableBlock closure, int index) {
    List<PsiType> expectedTypes;
    if (closure.getParent() instanceof GrSafeCastExpression) {
        GrSafeCastExpression safeCastExpression = (GrSafeCastExpression) closure.getParent();
        GrTypeElement typeElement = safeCastExpression.getCastTypeElement();
        if (typeElement != null) {
            PsiType castType = typeElement.getType();
            expectedTypes = ContainerUtil.newArrayList(GroovyExpectedTypesProvider.getDefaultExpectedTypes(safeCastExpression));
            for (Iterator<PsiType> iterator = expectedTypes.iterator(); iterator.hasNext(); ) {
                if (!TypesUtil.isAssignable(iterator.next(), castType, closure)) {
                    iterator.remove();
                }
            }
            if (expectedTypes.isEmpty())
                expectedTypes.add(castType);
        } else {
            expectedTypes = GroovyExpectedTypesProvider.getDefaultExpectedTypes(closure);
        }
    } else {
        expectedTypes = GroovyExpectedTypesProvider.getDefaultExpectedTypes(closure);
    }
    for (PsiType constraint : expectedTypes) {
        final PsiType suggestion = GppClosureParameterTypeProvider.getSingleMethodParameterType(constraint, index, closure);
        if (suggestion != null) {
            if (GroovyConfigUtils.getInstance().isVersionAtLeast(closure, GroovyConfigUtils.GROOVY2_3)) {
                if (suggestion instanceof PsiWildcardType && ((PsiWildcardType) suggestion).isSuper()) {
                    return ((PsiWildcardType) suggestion).getBound();
                }
            }
            return TypesUtil.substituteAndNormalizeType(suggestion, PsiSubstitutor.EMPTY, null, closure);
        }
    }
    return null;
}
Also used : GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) GrSafeCastExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSafeCastExpression) PsiWildcardType(com.intellij.psi.PsiWildcardType) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PsiWildcardType

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

the class GradleClosureAsAnonymousParameterEnhancer method getClosureParameterType.

@Nullable
@Override
protected PsiType getClosureParameterType(GrClosableBlock closure, int index) {
    PsiFile file = closure.getContainingFile();
    if (file == null || !FileUtilRt.extensionEquals(file.getName(), GradleConstants.EXTENSION))
        return null;
    PsiType psiType = super.getClosureParameterType(closure, index);
    if (psiType instanceof PsiWildcardType) {
        PsiWildcardType wildcardType = (PsiWildcardType) psiType;
        if (wildcardType.isSuper() && wildcardType.getBound() != null && wildcardType.getBound().equalsToText(GradleCommonClassNames.GRADLE_API_SOURCE_SET)) {
            return wildcardType.getBound();
        }
        if (wildcardType.isSuper() && wildcardType.getBound() != null && wildcardType.getBound().equalsToText(GradleCommonClassNames.GRADLE_API_DISTRIBUTION)) {
            return wildcardType.getBound();
        }
    }
    return null;
}
Also used : PsiFile(com.intellij.psi.PsiFile) PsiWildcardType(com.intellij.psi.PsiWildcardType) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiType (com.intellij.psi.PsiType)3 PsiWildcardType (com.intellij.psi.PsiWildcardType)3 Nullable (org.jetbrains.annotations.Nullable)2 PsiClass (com.intellij.psi.PsiClass)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiFile (com.intellij.psi.PsiFile)1 GrSafeCastExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSafeCastExpression)1 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)1