notnull, cleanup

This commit is contained in:
Alexey Kudravtsev
2013-07-01 11:46:15 +04:00
parent 5b34dd2a4b
commit 3967e65a0c
8 changed files with 67 additions and 88 deletions
@@ -22,8 +22,8 @@ import org.jetbrains.annotations.NotNull;
* @author ven
*/
public class PsiCapturedWildcardType extends PsiType {
private final PsiWildcardType myExistential;
private final PsiElement myContext;
@NotNull private final PsiWildcardType myExistential;
@NotNull private final PsiElement myContext;
public boolean equals(final Object o) {
if (!(o instanceof PsiCapturedWildcardType)) return false;
@@ -36,13 +36,14 @@ public class PsiCapturedWildcardType extends PsiType {
return myExistential.hashCode() + 31 * myContext.hashCode();
}
private PsiCapturedWildcardType(PsiWildcardType existential, final PsiElement context) {
private PsiCapturedWildcardType(@NotNull PsiWildcardType existential, @NotNull PsiElement context) {
super(PsiAnnotation.EMPTY_ARRAY);//todo
myExistential = existential;
myContext = context;
}
public static PsiCapturedWildcardType create(PsiWildcardType existential, final PsiElement context) {
@NotNull
public static PsiCapturedWildcardType create(@NotNull PsiWildcardType existential, @NotNull PsiElement context) {
return new PsiCapturedWildcardType(existential, context);
}
@@ -104,10 +105,12 @@ public class PsiCapturedWildcardType extends PsiType {
}
}
@NotNull
public PsiWildcardType getWildcard() {
return myExistential;
}
@NotNull
public PsiElement getContext() {
return myContext;
}
@@ -72,11 +72,11 @@ public abstract class MethodSignatureBase implements MethodSignature {
public PsiTypeParameter[] getTypeParameters() {
return myTypeParameters;
}
public PsiType[] getErasedParameterTypes() {
PsiType[] result = myErasedParameterTypes;
if (result == null) {
result = myErasedParameterTypes = MethodSignatureUtil.getErasedParameterTypes(this);
myErasedParameterTypes = result = MethodSignatureUtil.getErasedParameterTypes(this);
}
return result;
}
@@ -445,8 +445,6 @@ public class TypeConversionUtil {
/**
* @param tokenType JavaTokenType enumeration
* @param lOperand
* @param rOperand
* @param strict true if operator result type should be convertible to the left operand
* @return true if lOperand operator rOperand expression is syntactically correct
*/
@@ -480,16 +478,14 @@ public class TypeConversionUtil {
}
else {
if (isPrimitiveAndNotNull(ltype)) {
if (rtype instanceof PsiClassType && ((PsiClassType)rtype).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_7)) {
return areTypesConvertible(ltype, rtype);
}
return false;
return rtype instanceof PsiClassType &&
((PsiClassType)rtype).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_7) &&
areTypesConvertible(ltype, rtype);
}
if (isPrimitiveAndNotNull(rtype)) {
if (ltype instanceof PsiClassType && ((PsiClassType)ltype).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_7)) {
return areTypesConvertible(rtype, ltype);
}
return false;
return ltype instanceof PsiClassType &&
((PsiClassType)ltype).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_7) &&
areTypesConvertible(rtype, ltype);
}
isApplicable = areTypesConvertible(ltype, rtype) || areTypesConvertible(rtype, ltype);
}
@@ -693,10 +689,7 @@ public class TypeConversionUtil {
final PsiType lType = lLambdaExpression.getFunctionalInterfaceType();
return Comparing.equal(rType, lType);
}
if (left instanceof PsiArrayType) {
return false;
}
return LambdaUtil.isAcceptable(rLambdaExpression, left, false);
return !(left instanceof PsiArrayType) && LambdaUtil.isAcceptable(rLambdaExpression, left, false);
}
if (left instanceof PsiIntersectionType) {
@@ -745,9 +738,7 @@ public class TypeConversionUtil {
if (lCompType instanceof PsiPrimitiveType) {
return lCompType.equals(rCompType);
}
else {
return !(rCompType instanceof PsiPrimitiveType) && isAssignable(lCompType, rCompType, allowUncheckedConversion);
}
return !(rCompType instanceof PsiPrimitiveType) && isAssignable(lCompType, rCompType, allowUncheckedConversion);
}
if (left instanceof PsiDisjunctionType) {
@@ -828,12 +819,10 @@ public class TypeConversionUtil {
if (left instanceof PsiPrimitiveType && !PsiType.NULL.equals(left)) {
return right instanceof PsiClassType && isAssignable(left, right);
}
else {
return left instanceof PsiClassType
&& right instanceof PsiPrimitiveType
&& !PsiType.NULL.equals(right)
&& isAssignable(left, right);
}
return left instanceof PsiClassType
&& right instanceof PsiPrimitiveType
&& !PsiType.NULL.equals(right)
&& isAssignable(left, right);
}
private static final Key<CachedValue<Set<String>>> POSSIBLE_BOXED_HOLDER_TYPES = Key.create("Types that may be possibly assigned from primitive ones");
@@ -932,7 +921,7 @@ public class TypeConversionUtil {
}
private static final RecursionGuard ourGuard = RecursionManager.createGuard("isAssignable");
public static boolean typesAgree(PsiType typeLeft, PsiType typeRight, final boolean allowUncheckedConversion) {
if (typeLeft instanceof PsiWildcardType) {
final PsiWildcardType leftWildcard = (PsiWildcardType)typeLeft;
@@ -985,7 +974,7 @@ public class TypeConversionUtil {
}
}
private static Boolean containsWildcards(PsiType leftBound) {
private static boolean containsWildcards(@NotNull PsiType leftBound) {
final WildcardDetector wildcardDetector = new WildcardDetector();
if (leftBound instanceof PsiIntersectionType) {
for (PsiType conjunctType :((PsiIntersectionType)leftBound).getConjuncts()) {
@@ -993,7 +982,7 @@ public class TypeConversionUtil {
}
return true;
}
return leftBound.accept(wildcardDetector);
}
@@ -1020,9 +1009,6 @@ public class TypeConversionUtil {
* <code>superClass</code> must be a super class/interface of <code>derivedClass</code> (as in
* <code>InheritanceUtil.isInheritor(derivedClass, superClass, true)</code>
*
* @param superClass
* @param derivedClass
* @param derivedSubstitutor
* @return substitutor (never returns <code>null</code>)
* @see InheritanceUtil#isInheritor(PsiClass, PsiClass, boolean)
*/
@@ -1228,7 +1214,7 @@ public class TypeConversionUtil {
return typeParameterErasure(typeParameter, PsiSubstitutor.EMPTY);
}
private static PsiType typeParameterErasure(@NotNull PsiTypeParameter typeParameter, final PsiSubstitutor beforeSubstitutor) {
private static PsiType typeParameterErasure(@NotNull PsiTypeParameter typeParameter, @NotNull PsiSubstitutor beforeSubstitutor) {
final PsiClassType[] extendsList = typeParameter.getExtendsList().getReferencedTypes();
if (extendsList.length > 0) {
final PsiClass psiClass = extendsList[0].resolve();
@@ -1274,7 +1260,7 @@ public class TypeConversionUtil {
return erasure(type, PsiSubstitutor.EMPTY);
}
public static PsiType erasure(@Nullable final PsiType type, final PsiSubstitutor beforeSubstitutor) {
public static PsiType erasure(@Nullable final PsiType type, @NotNull final PsiSubstitutor beforeSubstitutor) {
if (type == null) return null;
return type.accept(new PsiTypeVisitor<PsiType>() {
@Override
@@ -1283,9 +1269,7 @@ public class TypeConversionUtil {
if (aClass instanceof PsiTypeParameter) {
return typeParameterErasure((PsiTypeParameter)aClass, beforeSubstitutor);
}
else {
return classType.rawType();
}
return classType.rawType();
}
@Override
@@ -504,7 +504,7 @@ public class PsiImplUtil {
return normalized;
}
private static PsiType doNormalizeWildcardByPosition(final PsiType type, final PsiExpression expression, final PsiExpression toplevel) {
private static PsiType doNormalizeWildcardByPosition(final PsiType type, @NotNull PsiExpression expression, final PsiExpression toplevel) {
if (type instanceof PsiCapturedWildcardType) {
return doNormalizeWildcardByPosition(((PsiCapturedWildcardType)type).getWildcard(), expression, toplevel);
}
@@ -130,10 +130,8 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
// First bound
return substitute(extendsTypes[0]);
}
else {
// Object
return PsiType.getJavaLangObject(typeParameter.getManager(), typeParameter.getResolveScope());
}
// Object
return PsiType.getJavaLangObject(typeParameter.getManager(), typeParameter.getResolveScope());
}
private abstract static class SubstitutionVisitorBase extends PsiTypeVisitorEx<PsiType> {
@@ -357,8 +355,8 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
if (substitutedBoundType != null && !(substitutedBoundType instanceof PsiWildcardType) && !substitutedBoundType.equalsToText(
CommonClassNames.JAVA_LANG_OBJECT)) {
if (originalBound == null ||
(!TypeConversionUtil.erasure(substitutedBoundType).isAssignableFrom(TypeConversionUtil.erasure(originalBound)) &&
!TypeConversionUtil.erasure(substitutedBoundType).isAssignableFrom(originalBound))) { //erasure is essential to avoid infinite recursion
!TypeConversionUtil.erasure(substitutedBoundType).isAssignableFrom(TypeConversionUtil.erasure(originalBound)) &&
!TypeConversionUtil.erasure(substitutedBoundType).isAssignableFrom(originalBound)) { //erasure is essential to avoid infinite recursion
if (wildcardType.isExtends()) {
final PsiType glb = GenericsUtil.getGreatestLowerBound(wildcardType.getBound(), substitutedBoundType);
if (glb != null) {
@@ -375,52 +373,45 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
}
if (captureContext != null) {
LOG.assertTrue(substituted instanceof PsiWildcardType);
substituted = oldSubstituted instanceof PsiCapturedWildcardType && substituted == ((PsiCapturedWildcardType)oldSubstituted).getWildcard()
? oldSubstituted : PsiCapturedWildcardType.create((PsiWildcardType)substituted, captureContext);
}
return substituted;
}
private PsiType correctExternalSubstitution(PsiType substituted, final PsiType original) {
if (original == null) return null;
if (substituted == null) {
return original.accept(new PsiTypeVisitor<PsiType>() {
@Override
public PsiType visitArrayType(PsiArrayType arrayType) {
return new PsiArrayType(arrayType.getComponentType().accept(this));
}
@Override
public PsiType visitEllipsisType(PsiEllipsisType ellipsisType) {
return new PsiEllipsisType(ellipsisType.getComponentType().accept(this));
}
@Override
public PsiType visitClassType(PsiClassType classType) {
PsiClass aClass = classType.resolve();
if (aClass != null) {
if (aClass instanceof PsiTypeParameter) {
return rawTypeForTypeParameter((PsiTypeParameter)aClass);
}
else {
return JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory().createType(aClass);
}
}
else {
return classType;
}
}
@Override
public PsiType visitType(PsiType type) {
LOG.error(type.getInternalCanonicalText());
return null;
}
});
private PsiType correctExternalSubstitution(PsiType substituted, @NotNull PsiType original) {
if (substituted != null) {
return substituted;
}
return substituted;
return original.accept(new PsiTypeVisitor<PsiType>() {
@Override
public PsiType visitArrayType(PsiArrayType arrayType) {
return new PsiArrayType(arrayType.getComponentType().accept(this));
}
@Override
public PsiType visitEllipsisType(PsiEllipsisType ellipsisType) {
return new PsiEllipsisType(ellipsisType.getComponentType().accept(this));
}
@Override
public PsiType visitClassType(PsiClassType classType) {
PsiClass aClass = classType.resolve();
if (aClass == null) {
return classType;
}
if (aClass instanceof PsiTypeParameter) {
return rawTypeForTypeParameter((PsiTypeParameter)aClass);
}
return JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory().createType(aClass);
}
@Override
public PsiType visitType(PsiType type) {
LOG.error(type.getInternalCanonicalText());
return null;
}
});
}
@Override
@@ -31,7 +31,7 @@ public class LightClassReference extends LightElement implements PsiJavaCodeRefe
private final PsiElement myContext;
private final GlobalSearchScope myResolveScope;
private final PsiClass myRefClass;
private PsiSubstitutor mySubstitutor;
private final PsiSubstitutor mySubstitutor;
private LightReferenceParameterList myParameterList;
@@ -37,7 +37,7 @@ public class IdentityCharTable implements CharTable {
@NotNull
@Override
public CharSequence intern(@NotNull CharSequence baseText, int startOffset, int endOffset) {
if (endOffset - startOffset == baseText.length()) return baseText.toString();
if (startOffset == 0 && endOffset == baseText.length()) return baseText;
return baseText.subSequence(startOffset, endOffset);
}
}
@@ -940,6 +940,7 @@ public class GeneratedParserUtilBase {
super(DUMMY_BLOCK);
}
@NotNull
@Override
public PsiReference[] getReferences() {
return PsiReference.EMPTY_ARRAY;