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;
}
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;
}
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);
}
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());
}
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;
}
Aggregations