diff options
author | 2017-01-19 08:07:15 +0100 | |
---|---|---|
committer | 2017-01-20 14:39:02 +0100 | |
commit | 9d99bc45df4a6fcfb929cf6e641459f8b33077e3 (patch) | |
tree | 9226baa9157b225578c3266b3472907e2d086f94 /third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/TypesUtils.java | |
parent | b46631bcc83c02988d1993c671b67dc8e6b86fe7 (diff) |
Downgrade checker framework to 1.8.10
Fixes #2254.
Change-Id: Ia411fa321fdac9d6acdaac60a8463b92ee1ae407
Diffstat (limited to 'third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/TypesUtils.java')
-rw-r--r-- | third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/TypesUtils.java | 144 |
1 files changed, 14 insertions, 130 deletions
diff --git a/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/TypesUtils.java b/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/TypesUtils.java index 949bf1362f..f024a60feb 100644 --- a/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/TypesUtils.java +++ b/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/TypesUtils.java @@ -1,18 +1,8 @@ package org.checkerframework.javacutil; -import com.sun.tools.javac.code.Symtab; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.code.TypeTag; -import com.sun.tools.javac.model.JavacTypes; -import com.sun.tools.javac.processing.JavacProcessingEnvironment; -import com.sun.tools.javac.util.Context; - import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.Element; import javax.lang.model.element.Name; -import javax.lang.model.element.NestingKind; import javax.lang.model.element.TypeElement; -import javax.lang.model.element.TypeParameterElement; import javax.lang.model.type.ArrayType; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; @@ -22,7 +12,12 @@ import javax.lang.model.type.WildcardType; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; -import static com.sun.tools.javac.code.TypeTag.WILDCARD; +import com.sun.tools.javac.code.Symtab; +import com.sun.tools.javac.code.Type; +import com.sun.tools.javac.code.TypeTag; +import com.sun.tools.javac.model.JavacTypes; +import com.sun.tools.javac.processing.JavacProcessingEnvironment; +import com.sun.tools.javac.util.Context; /** * A utility class that helps with {@link TypeMirror}s. @@ -98,13 +93,12 @@ public final class TypesUtils { */ public static boolean isDeclaredOfName(TypeMirror type, CharSequence qualifiedName) { return type.getKind() == TypeKind.DECLARED - && getQualifiedName((DeclaredType) type).contentEquals(qualifiedName); + && getQualifiedName((DeclaredType)type).contentEquals(qualifiedName); } public static boolean isBoxedPrimitive(TypeMirror type) { - if (type.getKind() != TypeKind.DECLARED) { + if (type.getKind() != TypeKind.DECLARED) return false; - } String qualifiedName = getQualifiedName((DeclaredType)type).toString(); @@ -124,29 +118,17 @@ public final class TypesUtils { DeclaredType dt = (DeclaredType) type; TypeElement elem = (TypeElement) dt.asElement(); Name name = elem.getQualifiedName(); - if ("java.lang.Throwable".contentEquals(name)) { + if ("java.lang.Throwable".contentEquals(name)) return true; - } type = elem.getSuperclass(); } return false; } /** - * Returns true iff the argument is an anonymous type. - * - * @return whether the argument is an anonymous type - */ - public static boolean isAnonymous(TypeMirror type) { - return (type instanceof DeclaredType) - && (((TypeElement) ((DeclaredType) type).asElement()).getNestingKind() - .equals(NestingKind.ANONYMOUS)); - } - - /** * Returns true iff the argument is a primitive type. * - * @return whether the argument is a primitive type + * @return whether the argument is a primitive type */ public static boolean isPrimitive(TypeMirror type) { switch (type.getKind()) { @@ -295,27 +277,8 @@ public final class TypesUtils { return type; } - /** - * Get the type parameter for this wildcard from the underlying type's bound field - * This field is sometimes null, in that case this method will return null - * @return the TypeParameterElement the wildcard is an argument to - */ - public static TypeParameterElement wildcardToTypeParam(final Type.WildcardType wildcard) { - - final Element typeParamElement; - if (wildcard.bound != null) { - typeParamElement = wildcard.bound.asElement(); - } else { - typeParamElement = null; - } - - return (TypeParameterElement) typeParamElement; - } - - /** - * Version of com.sun.tools.javac.code.Types.wildUpperBound(Type) - * that works with both jdk8 (called upperBound there) and jdk8u. - */ + // Version of com.sun.tools.javac.code.Types.wildUpperBound(Type) + // that works with both jdk8 (called upperBound there) and jdk8u. // TODO: contrast to upperBound. public static Type wildUpperBound(ProcessingEnvironment env, TypeMirror tm) { Type t = (Type) tm; @@ -328,27 +291,13 @@ public final class TypesUtils { } else { return wildUpperBound(env, w.type); } - } else { + } + else { return TypeAnnotationUtils.unannotatedType(t); } } /** - * Version of com.sun.tools.javac.code.Types.wildLowerBound(Type) - * that works with both jdk8 (called upperBound there) and jdk8u. - */ - public static Type wildLowerBound(ProcessingEnvironment env, TypeMirror tm) { - Type t = (Type) tm; - if (t.hasTag(WILDCARD)) { - Context context = ((JavacProcessingEnvironment) env).getContext(); - Symtab syms = Symtab.instance(context); - Type.WildcardType w = (Type.WildcardType) TypeAnnotationUtils.unannotatedType(t); - return w.isExtendsBound() ? syms.botType : wildLowerBound(env, w.type); - } else { - return t.unannotatedType(); - } - } - /** * Returns the {@link TypeMirror} for a given {@link Class}. */ public static TypeMirror typeFromClass(Types types, Elements elements, Class<?> clazz) { @@ -378,69 +327,4 @@ public final class TypesUtils { JavacTypes t = (JavacTypes) types; return t.getArrayType(componentType); } - - /** - * Returns true if declaredType is a Class that is used to box primitive type - * (e.g. declaredType=java.lang.Double and primitiveType=22.5d ) - */ - public static boolean isBoxOf(TypeMirror declaredType, TypeMirror primitiveType) { - if (declaredType.getKind() != TypeKind.DECLARED) { - return false; - } - - final String qualifiedName = getQualifiedName((DeclaredType) declaredType).toString(); - switch (primitiveType.getKind()) { - case BOOLEAN: return qualifiedName.equals("java.lang.Boolean"); - case BYTE: return qualifiedName.equals("java.lang.Byte"); - case CHAR: return qualifiedName.equals("java.lang.Character"); - case DOUBLE: return qualifiedName.equals("java.lang.Double"); - case FLOAT: return qualifiedName.equals("java.lang.Float"); - case INT: return qualifiedName.equals("java.lang.Integer"); - case LONG: return qualifiedName.equals("java.lang.Long"); - case SHORT: return qualifiedName.equals("java.lang.Short"); - - default: - return false; - } - } - - /** - * Given a bounded type (wildcard or typevar) get the concrete type of its upper bound. If - * the bounded type extends other bounded types, this method will iterate through their bounds - * until a class, interface, or intersection is found. - * @return a type that is not a wildcard or typevar, or null if this type is an unbounded wildcard - */ - public static TypeMirror findConcreteUpperBound(final TypeMirror boundedType) { - TypeMirror effectiveUpper = boundedType; - outerLoop : while (true) { - switch (effectiveUpper.getKind()) { - case WILDCARD: - effectiveUpper = ((javax.lang.model.type.WildcardType) effectiveUpper).getExtendsBound(); - if (effectiveUpper == null) { - return null; - } - break; - - case TYPEVAR: - effectiveUpper = ((TypeVariable) effectiveUpper).getUpperBound(); - break; - - default: - break outerLoop; - } - } - return effectiveUpper; - } - - /** - * Returns true if the erased type of subtype is a subtype of the erased type of supertype. - * - * @param types Types - * @param subtype possible subtype - * @param supertype possible supertype - * @return true if the erased type of subtype is a subtype of the erased type of supertype - */ - public static boolean isErasedSubtype(Types types, TypeMirror subtype, TypeMirror supertype) { - return types.isSubtype(types.erasure(subtype), types.erasure(supertype)); - } } |