Search in sources :

Example 66 with PsiType

use of com.intellij.psi.PsiType 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 67 with PsiType

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

the class GrDisjunctionTypeElementImpl method getType.

@NotNull
@Override
public PsiType getType() {
    PsiType cachedType = myCachedType;
    if (cachedType != null)
        return myCachedType;
    final GrTypeElement[] typeElements = getTypeElements();
    final ArrayList<PsiType> types = new ArrayList<>();
    for (GrTypeElement typeElement : typeElements) {
        types.add(typeElement.getType());
    }
    cachedType = new PsiDisjunctionType(types, getManager());
    myCachedType = cachedType;
    return cachedType;
}
Also used : GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) PsiDisjunctionType(com.intellij.psi.PsiDisjunctionType) ArrayList(java.util.ArrayList) PsiType(com.intellij.psi.PsiType) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with PsiType

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

the class ExternalBuilderStrategySupport method createFieldSetter.

@Nullable
public static LightMethodBuilder createFieldSetter(@NotNull PsiClass builderClass, @NotNull PsiMethod setter, @NotNull PsiAnnotation annotation) {
    final String name = PropertyUtil.getPropertyNameBySetter(setter);
    final PsiType type = PropertyUtil.getPropertyType(setter);
    if (type == null)
        return null;
    return DefaultBuilderStrategySupport.createFieldSetter(builderClass, name, type, annotation, setter);
}
Also used : PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with PsiType

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

the class JavaElementLookupRenderer method renderElement.

@Override
public void renderElement(final LookupItem item, final Object element, final LookupElementPresentation presentation) {
    presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(item, presentation.isReal()));
    presentation.setItemText(PsiUtilCore.getName((PsiElement) element));
    presentation.setStrikeout(isToStrikeout(item));
    presentation.setTailText((String) item.getAttribute(LookupItem.TAIL_TEXT_ATTR), item.getAttribute(LookupItem.TAIL_TEXT_SMALL_ATTR) != null);
    PsiType type = ((BeanPropertyElement) element).getPropertyType();
    presentation.setTypeText(type == null ? null : type.getPresentableText());
}
Also used : BeanPropertyElement(com.intellij.psi.impl.beanProperties.BeanPropertyElement) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

Example 70 with PsiType

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

the class ComponentTypeOfMacro method calculateLookupItems.

@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
    if (params.length != 1)
        return null;
    LookupElement[] lookupItems = params[0].calculateLookupItems(context);
    if (lookupItems == null)
        return null;
    List<LookupElement> result = ContainerUtil.newArrayList();
    for (LookupElement element : lookupItems) {
        PsiTypeLookupItem lookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
        if (lookupItem != null) {
            PsiType psiType = lookupItem.getType();
            if (psiType instanceof PsiArrayType) {
                result.add(PsiTypeLookupItem.createLookupItem(((PsiArrayType) psiType).getComponentType(), null));
            }
        }
    }
    return lookupItems;
}
Also used : PsiTypeLookupItem(com.intellij.codeInsight.lookup.PsiTypeLookupItem) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiArrayType(com.intellij.psi.PsiArrayType) 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