Skip to content

Commit

Permalink
Rename wasRaw to isUnderlyingTypeRaw
Browse files Browse the repository at this point in the history
  • Loading branch information
smillst authored Jun 16, 2021
1 parent 5eae0d9 commit 8ae3a75
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 37 deletions.
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ Version 3.X.X (? ?, 2021)

**Implementation details:**

Method renamings (the old methods remain but are deprecated):
* `AnnotatedDeclaredType#wasRaw` => `isUnderlyingTypeRaw`
* `AnnotatedDeclaredType#setWasRaw` => `setIsUnderlyingTypeRaw`

**Closed issues:**


Version 3.14.0 (June 1, 2021)
----------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3490,7 +3490,7 @@ protected boolean checkMethodReferenceAsOverride(
(ExecutableElement) TreeUtils.elementFromTree(memberReferenceTree);

if (enclosingType.getKind() == TypeKind.DECLARED
&& ((AnnotatedDeclaredType) enclosingType).wasRaw()) {
&& ((AnnotatedDeclaredType) enclosingType).isUnderlyingTypeRaw()) {
if (memRefKind == ReferenceKind.UNBOUND) {
// The method reference is of the form: Type # instMethod and Type is a raw type.
// If the first parameter of the function type, p1, is a subtype of type, then type should
Expand Down Expand Up @@ -3591,7 +3591,8 @@ private boolean checkMethodReferenceInference(
// Method type args
requiresInference = true;
} else if (memberReferenceTree.getMode() == ReferenceMode.NEW) {
if (type.getKind() == TypeKind.DECLARED && ((AnnotatedDeclaredType) type).wasRaw()) {
if (type.getKind() == TypeKind.DECLARED
&& ((AnnotatedDeclaredType) type).isUnderlyingTypeRaw()) {
// Class type args
requiresInference = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public AnnotatedTypeMirror visitDeclared(

final AnnotatedDeclaredType copy = makeOrReturnCopy(original, originalToCopy);

if (original.wasRaw()) {
copy.setWasRaw();
if (original.isUnderlyingTypeRaw()) {
copy.setIsUnderlyingTypeRaw();
}

if (original.enclosingType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,7 @@ public AnnotatedDeclaredType fromNewClass(NewClassTree newClassTree) {
fromNewClassContextHelper(type, ctxtype);
} else {
// give up trying and set to raw.
type.setWasRaw();
type.setIsUnderlyingTypeRaw();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,9 @@ public static class AnnotatedDeclaredType extends AnnotatedTypeMirror {
* TODO: improve inference.
*
* <p>Ideally, the field would be final. However, when we determine the supertype of a raw type,
* we need to set wasRaw for the supertype.
* we need to set isUnderlyingTypeRaw for the supertype.
*/
private boolean wasRaw;
private boolean isUnderlyingTypeRaw;

/** The enclosing type. May be null. */
protected @Nullable AnnotatedDeclaredType enclosingType;
Expand All @@ -878,7 +878,8 @@ private AnnotatedDeclaredType(
super(type, atypeFactory);
TypeElement typeelem = (TypeElement) type.asElement();
DeclaredType declty = (DeclaredType) typeelem.asType();
wasRaw = !declty.getTypeArguments().isEmpty() && type.getTypeArguments().isEmpty();
isUnderlyingTypeRaw =
!declty.getTypeArguments().isEmpty() && type.getTypeArguments().isEmpty();

TypeMirror encl = type.getEnclosingType();
if (encl.getKind() == TypeKind.DECLARED) {
Expand Down Expand Up @@ -958,7 +959,7 @@ public void setTypeArguments(List<? extends AnnotatedTypeMirror> ts) {
public List<AnnotatedTypeMirror> getTypeArguments() {
if (typeArgs != null) {
return typeArgs;
} else if (wasRaw()) {
} else if (isUnderlyingTypeRaw()) {
// Initialize the type arguments with uninferred wildcards.
BoundsInitializer.initializeTypeArgs(this);
return typeArgs;
Expand All @@ -973,21 +974,44 @@ public List<AnnotatedTypeMirror> getTypeArguments() {
}

/**
* Returns true if the type was raw, that is, type arguments were not provided but instead
* inferred.
* Returns true if the underlying type is raw. The receiver of this method is not raw, however;
* its annotated type arguments have been inferred.
*
* @return true iff the type was raw
*/
public boolean isUnderlyingTypeRaw() {
return isUnderlyingTypeRaw;
}

/**
* Returns true if the underlying type is raw. The receiver of this method is not raw, however;
* its annotated type arguments have been inferred.
*
* @return true iff the type was raw
* @deprecated Use {@link #isUnderlyingTypeRaw()} instead
*/
@Deprecated // 2021-06-16
public boolean wasRaw() {
return wasRaw;
return isUnderlyingTypeRaw();
}

/**
* Set the wasRaw flag to true. This should only be necessary when determining the supertypes of
* a raw type.
* Set the isUnderlyingTypeRaw flag to true. This should only be necessary when determining the
* supertypes of a raw type.
*/
protected void setIsUnderlyingTypeRaw() {
this.isUnderlyingTypeRaw = true;
}

/**
* Set the isUnderlyingTypeRaw flag to true. This should only be necessary when determining the
* supertypes of a raw type.
*
* @deprecated Use {@link #setIsUnderlyingTypeRaw()} instead
*/
@Deprecated // 2021-06-16
protected void setWasRaw() {
this.wasRaw = true;
setIsUnderlyingTypeRaw();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class BoundsInitializer {
*/
public static void initializeTypeArgs(AnnotatedDeclaredType declaredType) {
final DeclaredType underlyingType = (DeclaredType) declaredType.underlyingType;
if (underlyingType.getTypeArguments().isEmpty() && !declaredType.wasRaw()) {
if (underlyingType.getTypeArguments().isEmpty() && !declaredType.isUnderlyingTypeRaw()) {
// No type arguments to infer.
return;
}
Expand All @@ -73,7 +73,7 @@ public static void initializeTypeArgs(AnnotatedDeclaredType declaredType) {
Map<TypeVariable, AnnotatedTypeMirror> typeArgMap = new HashMap<>(numTypeParameters);
for (int i = 0; i < numTypeParameters; i++) {
TypeMirror javaTypeArg;
if (declaredType.wasRaw()) {
if (declaredType.isUnderlyingTypeRaw()) {
TypeVariable typeVariable = (TypeVariable) typeElement.getTypeParameters().get(i).asType();
javaTypeArg = getUpperBoundAsWildcard(typeVariable, declaredType.atypeFactory);
} else {
Expand All @@ -85,7 +85,7 @@ public static void initializeTypeArgs(AnnotatedDeclaredType declaredType) {
if (typeArg.getKind() == TypeKind.WILDCARD) {
AnnotatedWildcardType wildcardType = (AnnotatedWildcardType) typeArg;
wildcardType.setTypeVariable(typeElement.getTypeParameters().get(i));
if (declaredType.wasRaw()) {
if (declaredType.isUnderlyingTypeRaw()) {
wildcardType.setUninferredTypeArgument();
}
}
Expand Down Expand Up @@ -603,7 +603,7 @@ public void initializeExtendsBound(AnnotatedWildcardType wildcard) {
*/
private void initializeTypeArgs(AnnotatedDeclaredType declaredType) {
DeclaredType underlyingType = (DeclaredType) declaredType.underlyingType;
if (underlyingType.getTypeArguments().isEmpty() && !declaredType.wasRaw()) {
if (underlyingType.getTypeArguments().isEmpty() && !declaredType.isUnderlyingTypeRaw()) {
return;
}
TypeElement typeElement =
Expand All @@ -617,7 +617,7 @@ private void initializeTypeArgs(AnnotatedDeclaredType declaredType) {
AnnotatedTypeMirror atmArg =
AnnotatedTypeMirror.createType(javaTypeArg, declaredType.atypeFactory, false);
typeArgs.add(atmArg);
if (atmArg.getKind() == TypeKind.WILDCARD && declaredType.wasRaw()) {
if (atmArg.getKind() == TypeKind.WILDCARD && declaredType.isUnderlyingTypeRaw()) {
((AnnotatedWildcardType) atmArg).setUninferredTypeArgument();
}
}
Expand Down Expand Up @@ -661,7 +661,7 @@ private void initializeTypeArgs(AnnotatedDeclaredType declaredType) {
*/
private TypeMirror getJavaType(
AnnotatedDeclaredType type, List<? extends TypeParameterElement> parameters, int i) {
if (type.wasRaw()) {
if (type.isUnderlyingTypeRaw()) {
TypeVariable typeVariable = (TypeVariable) parameters.get(i).asType();
if (rawTypeWildcards.containsKey(typeVariable)) {
return rawTypeWildcards.get(typeVariable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,11 @@ public Boolean visitDeclared_Declared(
}

final boolean result =
visitTypeArgs(subtypeAsSuper, supertype, subtype.wasRaw(), supertype.wasRaw());
visitTypeArgs(
subtypeAsSuper,
supertype,
subtype.isUnderlyingTypeRaw(),
supertype.isUnderlyingTypeRaw());
isSubtypeVisitHistory.put(subtypeAsSuper, supertype, currentTop, result);

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Compares two annotated type mirrors for structural equality using only the primary annotations
* and underlying types of the two input types and their component types. Note, this leaves out
* other fields specific to some AnnotatedTypeMirrors (like directSupertypes, wasRaw,
* other fields specific to some AnnotatedTypeMirrors (like directSupertypes, isUnderlyingTypeRaw,
* isUninferredTypeArgument etc...). Ideally, both EqualityAtmComparer and HashcodeAtmVisitor would
* visit relevant fields.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public List<AnnotatedDeclaredType> visitDeclared(AnnotatedDeclaredType type, Voi
Map<TypeParameterElement, AnnotatedTypeMirror> mapping = new HashMap<>();

if (type.getTypeArguments().size() != typeElement.getTypeParameters().size()) {
if (!type.wasRaw()) {
if (!type.isUnderlyingTypeRaw()) {
throw new BugInCF(
"AnnotatedDeclaredType's element has a different number of type parameters than"
+ " type.%ntype=%s%nelement=%s",
Expand Down Expand Up @@ -229,12 +229,12 @@ private List<AnnotatedDeclaredType> supertypesFromElement(
}

for (TypeMirror st : typeElement.getInterfaces()) {
if (type.wasRaw()) {
if (type.isUnderlyingTypeRaw()) {
st = types.erasure(st);
}
AnnotatedDeclaredType ast = (AnnotatedDeclaredType) atypeFactory.toAnnotatedType(st, false);
supertypes.add(ast);
if (type.wasRaw()) {
if (type.isUnderlyingTypeRaw()) {
if (st.getKind() == TypeKind.DECLARED) {
final List<? extends TypeMirror> typeArgs = ((DeclaredType) st).getTypeArguments();
final List<AnnotatedTypeMirror> annotatedTypeArgs = ast.getTypeArguments();
Expand All @@ -247,9 +247,9 @@ private List<AnnotatedDeclaredType> supertypesFromElement(
}
ElementAnnotationApplier.annotateSupers(supertypes, typeElement);

if (type.wasRaw()) {
if (type.isUnderlyingTypeRaw()) {
for (AnnotatedDeclaredType adt : supertypes) {
adt.setWasRaw();
adt.setIsUnderlyingTypeRaw();
}
}
return supertypes;
Expand Down Expand Up @@ -292,9 +292,9 @@ private List<AnnotatedDeclaredType> supertypesFromTree(
if (elem.getKind() == ElementKind.ENUM) {
supertypes.add(createEnumSuperType(type, elem));
}
if (type.wasRaw()) {
if (type.isUnderlyingTypeRaw()) {
for (AnnotatedDeclaredType adt : supertypes) {
adt.setWasRaw();
adt.setIsUnderlyingTypeRaw();
}
}
return supertypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public List<TypeCompound> visitDeclared(

// we sometimes fix-up raw types with wildcards, do not write these into the bytecode as there
// are no corresponding type arguments and therefore no location to actually add them to
if (!type.wasRaw()) {
if (!type.isUnderlyingTypeRaw()) {
int arg = 0;
for (AnnotatedTypeMirror ta : type.getTypeArguments()) {
TypeAnnotationPosition newpos = TypeAnnotationUtils.copyTAPosition(tapos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Void visitDeclared(AnnotatedDeclaredType declaredType, Void aVoid) {
if (pause) {
return null;
}
if (declaredType.wasRaw()) {
if (declaredType.isUnderlyingTypeRaw()) {
// Copy annotations from the declaration to the wildcards.
AnnotatedDeclaredType declaration =
(AnnotatedDeclaredType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private static void fixUpRawTypes(
final AnnotatedDeclaredType declaredAsSuper = (AnnotatedDeclaredType) asSuperType;
final AnnotatedDeclaredType declaredSubtype = (AnnotatedDeclaredType) originalSubtype;

if (!declaredAsSuper.wasRaw()
if (!declaredAsSuper.isUnderlyingTypeRaw()
|| !declaredAsSuper.getTypeArguments().isEmpty()
|| declaredSubtype.getTypeArguments().isEmpty()) {
return;
Expand Down Expand Up @@ -536,14 +536,14 @@ private static void addTypeVarMappings(
}

List<AnnotatedTypeMirror> baseParams = base.getTypeArguments();
if (ownerParams.size() != baseParams.size() && !base.wasRaw()) {
if (ownerParams.size() != baseParams.size() && !base.isUnderlyingTypeRaw()) {
throw new BugInCF(
StringsPlume.joinLines(
"Unexpected number of parameters.",
"enclosingType=" + enclosingType,
"baseType=" + base));
}
if (!ownerParams.isEmpty() && baseParams.isEmpty() && base.wasRaw()) {
if (!ownerParams.isEmpty() && baseParams.isEmpty() && base.isUnderlyingTypeRaw()) {
// If base type was raw and the type arguments are missing, set them to the erased
// type of the type variable (which is the erased type of the upper bound).
baseParams = CollectionsPlume.mapList(AnnotatedTypeVariable::getErased, ownerParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Void visitDeclared_Declared(
AnnotatedDeclaredType subtype,
AnnotatedDeclaredType supertype,
Set<AFConstraint> constraints) {
if (subtype.wasRaw() || supertype.wasRaw()) {
if (subtype.isUnderlyingTypeRaw() || supertype.isUnderlyingTypeRaw()) {
// The error will be caught in {@link DefaultTypeArgumentInference#infer} and
// inference will be aborted, but type-checking will continue.
throw new BugInCF("Can't infer type arguments when raw types are involved.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Void visitDeclared_Declared(
AnnotatedDeclaredType parameter,
AnnotatedDeclaredType argument,
Set<AFConstraint> constraints) {
if (argument.wasRaw() || parameter.wasRaw()) {
if (argument.isUnderlyingTypeRaw() || parameter.isUnderlyingTypeRaw()) {
return null;
}

Expand Down

0 comments on commit 8ae3a75

Please sign in to comment.