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