Skip to content

Commit

Permalink
chore: deprecate public CtTypeReference fields in TypeFactory (#5646)
Browse files Browse the repository at this point in the history
Co-authored-by: I-Al-Istannen <i-al-istannen@users.noreply.github.com>
Co-authored-by: Martin Wittlinger <wittlinger.martin@gmail.com>
  • Loading branch information
3 people committed Apr 3, 2024
1 parent 8409386 commit e7d4b9b
Show file tree
Hide file tree
Showing 54 changed files with 267 additions and 148 deletions.
9 changes: 5 additions & 4 deletions src/main/java/spoon/metamodel/MetamodelProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void setValueType(CtTypeReference<?> valueType) {
if (valueType instanceof CtTypeParameterReference) {
valueType = ((CtTypeParameterReference) valueType).getBoundingType();
if (valueType == null) {
valueType = f.Type().OBJECT;
valueType = f.Type().objectType();
}
}
if (valueType.isImplicit()) {
Expand Down Expand Up @@ -338,8 +338,9 @@ private int getIdxOfBestMatchByReturnType(List<MMMethod> methods, MMMethodKind k
CtTypeReference<?> returnType1 = methods.get(0).getActualCtMethod().getType();
CtTypeReference<?> returnType2 = methods.get(1).getActualCtMethod().getType();
Factory f = returnType1.getFactory();
boolean is1Iterable = returnType1.isSubtypeOf(f.Type().ITERABLE);
boolean is2Iterable = returnType2.isSubtypeOf(f.Type().ITERABLE);
CtTypeReference<?> iterableRef = f.Type().createReference(Iterable.class);
boolean is1Iterable = returnType1.isSubtypeOf(iterableRef);
boolean is2Iterable = returnType2.isSubtypeOf(iterableRef);
if (is1Iterable != is2Iterable) {
// they are not some. Only one of them is iterable
if (is1Iterable) {
Expand Down Expand Up @@ -419,7 +420,7 @@ private static CtTypeReference<?> getTypeofItems(CtTypeReference<?> valueType) {
if (itemValueType instanceof CtTypeParameterReference) {
itemValueType = ((CtTypeParameterReference) itemValueType).getBoundingType();
if (itemValueType == null) {
itemValueType = valueType.getFactory().Type().OBJECT;
itemValueType = valueType.getFactory().Type().objectType();
}
}
return itemValueType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private void configureByTemplateParameter(CtType<?> templateType, Map<String, Ob

CtTypeReference<?> paramType = paramField.getType();

if (paramType.isSubtypeOf(f.Type().ITERABLE) || paramType instanceof CtArrayTypeReference<?>) {
if (paramType.isSubtypeOf(f.Type().createReference(Iterable.class)) || paramType instanceof CtArrayTypeReference<?>) {
//parameter is a multivalue
// here we need to replace all named element and all references whose simpleName == stringMarker
parameter(parameterName).setContainerKind(ContainerKind.LIST).byNamedElement(stringMarker).byReferenceName(stringMarker);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/reflect/factory/CodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public <T> CtLiteral<T> createLiteral(T value) {
public CtTextBlock createTextBlock(String value) {
CtTextBlock textblock = factory.Core().createTextBlock();
textblock.setValue(value);
textblock.setType((CtTypeReference<String>) factory.Type().STRING);
textblock.setType(factory.Type().stringType());
return textblock;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/reflect/factory/ExecutableFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private CtTypeReference<?> getMethodParameterType(CtTypeReference<?> paramType)
}
}
if (paramType == null) {
paramType = factory.Type().OBJECT;
return factory.Type().objectType();
}
return paramType.clone();
}
Expand Down
162 changes: 139 additions & 23 deletions src/main/java/spoon/reflect/factory/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,150 @@ public class TypeFactory extends SubFactory {
// TODO (leventov) it is questionable to me that nulltype should also be here
CtTypeReference.NULL_TYPE_NAME);

/**
* @deprecated Use {@link #nullType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<?> NULL_TYPE = createReference(CtTypeReference.NULL_TYPE_NAME);
/**
* @deprecated Use {@link #voidType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Void> VOID = createReference(Void.class);
/**
* @deprecated Use {@link #stringType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<String> STRING = createReference(String.class);
/**
* @deprecated Use {@link #booleanType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Boolean> BOOLEAN = createReference(Boolean.class);
/**
* @deprecated Use {@link #byteType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Byte> BYTE = createReference(Byte.class);
/**
* @deprecated Use {@link #characterType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Character> CHARACTER = createReference(Character.class);
/**
* @deprecated Use {@link #integerType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Integer> INTEGER = createReference(Integer.class);
/**
* @deprecated Use {@link #longType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Long> LONG = createReference(Long.class);
/**
* @deprecated Use {@link #floatType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Float> FLOAT = createReference(Float.class);
/**
* @deprecated Use {@link #doubleType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Double> DOUBLE = createReference(Double.class);
/**
* @deprecated Use {@link #voidPrimitiveType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Void> VOID_PRIMITIVE = createReference(void.class);
/**
* @deprecated Use {@link #booleanPrimitiveType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Boolean> BOOLEAN_PRIMITIVE = createReference(boolean.class);
/**
* @deprecated Use {@link #bytePrimitiveType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Byte> BYTE_PRIMITIVE = createReference(byte.class);
/**
* @deprecated Use {@link #characterPrimitiveType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Character> CHARACTER_PRIMITIVE = createReference(char.class);
/**
* @deprecated Use {@link #integerPrimitiveType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Integer> INTEGER_PRIMITIVE = createReference(int.class);
/**
* @deprecated Use {@link #longPrimitiveType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Long> LONG_PRIMITIVE = createReference(long.class);
/**
* @deprecated Use {@link #floatPrimitiveType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Float> FLOAT_PRIMITIVE = createReference(float.class);
/**
* @deprecated Use {@link #doublePrimitiveType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Double> DOUBLE_PRIMITIVE = createReference(double.class);
/**
* @deprecated Use {@link #shortType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Short> SHORT = createReference(Short.class);
/**
* @deprecated Use {@link #shortPrimitiveType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Short> SHORT_PRIMITIVE = createReference(short.class);
/**
* @deprecated Use {@link #dateType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Date> DATE = createReference(Date.class);
/**
* @deprecated Use {@link #objectType()} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Object> OBJECT = createReference(Object.class);
/**
* @deprecated Use {@link #createReference(Class) TypeFactory#createReference(Iterable.class)} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Iterable> ITERABLE = createReference(Iterable.class);
/**
* @deprecated Use {@link #createReference(Class) TypeFactory#createReference(Collection.class)} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Collection> COLLECTION = createReference(Collection.class);
/**
* @deprecated Use {@link #createReference(Class) TypeFactory#createReference(List.class)} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<List> LIST = createReference(List.class);
/**
* @deprecated Use {@link #createReference(Class) TypeFactory#createReference(Set.class)} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Set> SET = createReference(Set.class);
/**
* @deprecated Use {@link #createReference(Class) TypeFactory#createReference(Map.class)} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Map> MAP = createReference(Map.class);
/**
* @deprecated Use {@link #createReference(Class) TypeFactory#createReference(Enum.class)} instead.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<Enum> ENUM = createReference(Enum.class);
/**
* @deprecated Deprecated for removal without replacement.
*/
@Deprecated(since = "11.0.0", forRemoval = true)
public final CtTypeReference<?> OMITTED_TYPE_ARG_TYPE = createReference(CtTypeReference.OMITTED_TYPE_ARG_NAME);

// This map MUST provide a useful computeIfAbsent method in the face of concurrency.
Expand All @@ -100,154 +216,154 @@ public class TypeFactory extends SubFactory {
* Returns a reference on the null type (type of null).
*/
public CtTypeReference<?> nullType() {
return NULL_TYPE.clone();
return ((CtTypeReference<?>) createReference(CtTypeReference.NULL_TYPE_NAME)).clone();
}

/**
* Returns a reference on the void type.
*/
public CtTypeReference<Void> voidType() {
return VOID.clone();
return createReference(Void.class);
}

/**
* Returns a reference on the void primitive type.
*/
public CtTypeReference<Void> voidPrimitiveType() {
return VOID_PRIMITIVE.clone();
return createReference(void.class);
}

/**
* Returns a reference on the string type.
*/
public CtTypeReference<String> stringType() {
return STRING.clone();
return createReference(String.class);
}

/**
* Returns a reference on the boolean type.
*/
public CtTypeReference<Boolean> booleanType() {
return BOOLEAN.clone();
return createReference(Boolean.class);
}

/**
* Returns a reference on the boolean primitive type.
*/
public CtTypeReference<Boolean> booleanPrimitiveType() {
return BOOLEAN_PRIMITIVE.clone();
return createReference(boolean.class);
}

/**
* Returns a reference on the byte type.
*/
public CtTypeReference<Byte> byteType() {
return BYTE.clone();
return createReference(Byte.class);
}

/**
* Returns a reference on the byte primitive type.
*/
public CtTypeReference<Byte> bytePrimitiveType() {
return BYTE_PRIMITIVE.clone();
return createReference(byte.class);
}

/**
* Returns a reference on the character type.
*/
public CtTypeReference<Character> characterType() {
return CHARACTER.clone();
return createReference(Character.class);
}

/**
* Returns a reference on the character primitive type.
*/
public CtTypeReference<Character> characterPrimitiveType() {
return CHARACTER_PRIMITIVE.clone();
return createReference(char.class);
}

/**
* Returns a reference on the integer type.
*/
public CtTypeReference<Integer> integerType() {
return INTEGER.clone();
return createReference(Integer.class);
}

/**
* Returns a reference on the integer primitive type.
*/
public CtTypeReference<Integer> integerPrimitiveType() {
return INTEGER_PRIMITIVE.clone();
return createReference(int.class);
}

/**
* Returns a reference on the long type.
*/
public CtTypeReference<Long> longType() {
return LONG.clone();
return createReference(Long.class);
}

/**
* Returns a reference on the long primitive type.
*/
public CtTypeReference<Long> longPrimitiveType() {
return LONG_PRIMITIVE.clone();
return createReference(long.class);
}

/**
* Returns a reference on the float type.
*/
public CtTypeReference<Float> floatType() {
return FLOAT.clone();
return createReference(Float.class);
}

/**
* Returns a reference on the float primitive type.
*/
public CtTypeReference<Float> floatPrimitiveType() {
return FLOAT_PRIMITIVE.clone();
return createReference(float.class);
}

/**
* Returns a reference on the double type.
*/
public CtTypeReference<Double> doubleType() {
return DOUBLE.clone();
return createReference(Double.class);
}

/**
* Returns a reference on the double primitive type.
*/
public CtTypeReference<Double> doublePrimitiveType() {
return DOUBLE_PRIMITIVE.clone();
return createReference(double.class);
}

/**
* Returns a reference on the short type.
*/
public CtTypeReference<Short> shortType() {
return SHORT.clone();
return createReference(Short.class);
}

/**
* Returns a reference on the short primitive type.
*/
public CtTypeReference<Short> shortPrimitiveType() {
return SHORT_PRIMITIVE.clone();
return createReference(short.class);
}

/**
* Returns a reference on the date type.
*/
public CtTypeReference<Date> dateType() {
return DATE.clone();
return createReference(Date.class);
}

/**
* Returns a reference on the object type.
*/
public CtTypeReference<Object> objectType() {
return OBJECT.clone();
return createReference(Object.class);
}

/**
Expand Down Expand Up @@ -728,7 +844,7 @@ public <T> CtIntersectionTypeReference<T> createIntersectionTypeReferenceWithBou
* Returns the default bounding type value
*/
public CtTypeReference getDefaultBoundingType() {
return OBJECT;
return objectType();
}

/**
Expand Down

0 comments on commit e7d4b9b

Please sign in to comment.