/** * Returns {@code true} if {@code type} is a parameterized type and {@code false} otherwise. * * @param type the type to be evaluated * @return {@code true} if {@code type} is a parameterized type and {@code false} otherwise */ public static boolean isParameterizedType(PsiType type) { if (!(type instanceof PsiClassType)) { return false; } Boolean accepted = type.accept( new PsiTypeVisitor<Boolean>() { @Nullable @Override public Boolean visitClassType(PsiClassType classType) { return classType.getParameterCount() > 0; } }); return Boolean.TRUE.equals(accepted); } }
@Nullable public A visitIntersectionType(PsiIntersectionType intersectionType) { PsiType type = intersectionType.getConjuncts()[0]; return type.accept(this); }
@Nullable @Override public Boolean visitWildcardType(PsiWildcardType wildcardType) { final PsiType bound = wildcardType.getBound(); if (bound != null) return bound.accept(this); return false; }
@Override public Boolean visitArrayType(PsiArrayType arrayType) { return arrayType.getComponentType().accept(this); }
@Nullable @Override public Boolean visitIntersectionType(PsiIntersectionType intersectionType) { for (PsiType psiType : intersectionType.getConjuncts()) { if (psiType.accept(this)) return true; } return false; }
@Nullable @Override public Boolean visitArrayType(PsiArrayType arrayType) { return arrayType.getComponentType().accept(this); }
@Override public PsiType visitWildcardType(PsiWildcardType wildcardType) { return wildcardType.getExtendsBound().accept(this); }
public static boolean containsWildcards(@NotNull PsiType leftBound) { return leftBound.accept(new WildcardDetector()); }
public static boolean depends(PsiType type, TypeParamsChecker visitor, PsiTypeParameter... param2Check) { if (!visitor.startedInference()) return false; final Boolean accept = type.accept(visitor); if (param2Check.length > 0) { return visitor.used(param2Check); } return accept != null && accept.booleanValue(); }
@Override public PsiType visitEllipsisType(PsiEllipsisType ellipsisType) { final PsiType componentType = ellipsisType.getComponentType(); final PsiType newComponentType = componentType.accept(this); if (newComponentType == componentType) return ellipsisType; return newComponentType != null ? newComponentType.createArrayType() : null; }
@Override public Boolean visitClassType(PsiClassType classType) { final PsiType[] parameters = classType.getParameters(); for (PsiType parameter : parameters) { if (parameter.accept(this)) return true; } return super.visitClassType(classType); }
@Override public PsiType visitArrayType(PsiArrayType arrayType) { final PsiType componentType = arrayType.getComponentType(); final PsiType newComponentType = componentType.accept(this); if (newComponentType == componentType) return arrayType; return newComponentType != null ? newComponentType.createArrayType() : null; }
@Override public PsiType visitArrayType(PsiArrayType arrayType) { PsiType componentType = arrayType.getComponentType(); PsiType type = componentType.accept(this); if (type == componentType) return arrayType; return type.createArrayType(); }
@Override public PsiType visitArrayType(PsiArrayType arrayType) { final PsiType componentType = arrayType.getComponentType(); final PsiType newComponentType = componentType.accept(this); if (newComponentType == componentType) return arrayType; return newComponentType != null ? newComponentType.createArrayType() : null; } });
@Override public PsiType visitEllipsisType(PsiEllipsisType ellipsisType) { final PsiType componentType = ellipsisType.getComponentType(); final PsiType newComponentType = componentType.accept(this); if (newComponentType == componentType) return ellipsisType; return newComponentType != null ? newComponentType.createArrayType() : null; }
@Nullable public A visitLambdaExpressionType(PsiLambdaExpressionType lambdaExpressionType) { final PsiLambdaExpression lambdaExpression = lambdaExpressionType.getExpression(); final PsiType interfaceType = lambdaExpression.getFunctionalInterfaceType(); if (interfaceType != null) return interfaceType.accept(this); return visitType(lambdaExpressionType); }
@Override public Boolean visitClassType(PsiClassType classType) { boolean used = false; for (PsiType paramType : classType.getParameters()) { final Boolean paramAccepted = paramType.accept(this); used |= paramAccepted != null && paramAccepted.booleanValue(); } final PsiClass resolve = classType.resolve(); if (resolve instanceof PsiTypeParameter) { final PsiTypeParameter typeParameter = (PsiTypeParameter)resolve; if (check(typeParameter)) { myUsedTypeParams.add(typeParameter); return true; } } return used; }
public A visitMethodReferenceType(PsiMethodReferenceType methodReferenceType) { final PsiMethodReferenceExpression expression = methodReferenceType.getExpression(); final PsiType interfaceType = expression.getFunctionalInterfaceType(); if (interfaceType != null) return interfaceType.accept(this); return visitType(methodReferenceType); } }
@Override public PsiType visitWildcardType(final PsiWildcardType wildcardType) { final PsiType bound = wildcardType.getBound(); PsiManager manager = wildcardType.getManager(); if (bound != null) { final PsiType acceptedBound = bound.accept(this); if (acceptedBound instanceof PsiWildcardType) { if (((PsiWildcardType)acceptedBound).isExtends() != wildcardType.isExtends()) return PsiWildcardType.createUnbounded(manager); return acceptedBound; } if (wildcardType.isExtends() && acceptedBound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) return PsiWildcardType.createUnbounded(manager); if (acceptedBound.equals(bound)) return wildcardType; return wildcardType.isExtends() ? PsiWildcardType.createExtends(manager, acceptedBound) : PsiWildcardType.createSuper(manager, acceptedBound); } return wildcardType; }
final PsiType accepted = typeArgument.accept(this); if (typeArgument instanceof PsiIntersectionType && !(accepted instanceof PsiWildcardType)) { toPut = PsiWildcardType.createExtends(typeParameter.getManager(), accepted);