use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement in project intellij-community by JetBrains.
the class GrMethodBaseImpl method setReturnType.
@Override
@Nullable
public GrTypeElement setReturnType(@Nullable PsiType newReturnType) {
GrTypeElement typeElement = getReturnTypeElementGroovy();
if (newReturnType == null || newReturnType == PsiType.NULL) {
if (typeElement != null)
typeElement.delete();
insertPlaceHolderToModifierList();
return null;
}
final GrTypeElement stub = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(newReturnType);
GrTypeElement newTypeElement;
if (typeElement == null) {
final GrTypeParameterList typeParemeterList = getTypeParameterList();
PsiElement anchor = typeParemeterList != null ? typeParemeterList : getModifierList();
newTypeElement = (GrTypeElement) addAfter(stub, anchor);
} else {
newTypeElement = (GrTypeElement) typeElement.replace(stub);
}
return newTypeElement;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement in project intellij-community by JetBrains.
the class GrParameterImpl method setType.
@Override
public void setType(@Nullable PsiType type) {
final GrTypeElement typeElement = getTypeElementGroovy();
if (type == null) {
if (typeElement != null)
typeElement.delete();
return;
}
GrTypeElement newTypeElement;
try {
newTypeElement = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(type);
} catch (IncorrectOperationException e) {
LOG.error(e);
return;
}
if (typeElement == null) {
final GrModifierList modifierList = getModifierList();
newTypeElement = (GrTypeElement) addAfter(newTypeElement, modifierList);
} else {
newTypeElement = (GrTypeElement) typeElement.replace(newTypeElement);
}
JavaCodeStyleManager.getInstance(getProject()).shortenClassReferences(newTypeElement);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement in project intellij-community by JetBrains.
the class GrClassReferenceTypePointer method calcType.
@Nullable
@Override
protected GrClassReferenceType calcType() {
final GrReferenceElement reference = mySmartPsiElementPointer.getElement();
if (reference != null) {
return new GrClassReferenceType(reference);
}
try {
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myProject);
GrTypeElement typeElement = factory.createTypeElement(myReferenceText, null);
return (GrClassReferenceType) typeElement.getType();
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement 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 org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement 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;
}
Aggregations