Skip to content

Commit

Permalink
Removed unwanted recursion.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Aug 14, 2016
1 parent a6dff34 commit 5edfeb9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 61 deletions.
Expand Up @@ -697,7 +697,7 @@ public S load() throws ClassNotFoundException {
}
return AnnotationValue.ForComplexArray.of(typeDescription);
} else {
return new AnnotationValue.Trivial<Object>(value);
return new AnnotationValue.ForConstant<Object>(value);
}
}

Expand Down Expand Up @@ -1097,7 +1097,7 @@ public Builder defineTypeArray(String property, TypeDescription... typeDescripti
* @return A builder with the additional {@code boolean} property.
*/
public Builder define(String property, boolean value) {
return define(property, new AnnotationValue.Trivial<Boolean>(value));
return define(property, new AnnotationValue.ForConstant<Boolean>(value));
}

/**
Expand All @@ -1108,7 +1108,7 @@ public Builder define(String property, boolean value) {
* @return A builder with the additional {@code byte} property.
*/
public Builder define(String property, byte value) {
return define(property, new AnnotationValue.Trivial<Byte>(value));
return define(property, new AnnotationValue.ForConstant<Byte>(value));
}

/**
Expand All @@ -1119,7 +1119,7 @@ public Builder define(String property, byte value) {
* @return A builder with the additional {@code char} property.
*/
public Builder define(String property, char value) {
return define(property, new AnnotationValue.Trivial<Character>(value));
return define(property, new AnnotationValue.ForConstant<Character>(value));
}

/**
Expand All @@ -1130,7 +1130,7 @@ public Builder define(String property, char value) {
* @return A builder with the additional {@code short} property.
*/
public Builder define(String property, short value) {
return define(property, new AnnotationValue.Trivial<Short>(value));
return define(property, new AnnotationValue.ForConstant<Short>(value));
}

/**
Expand All @@ -1141,7 +1141,7 @@ public Builder define(String property, short value) {
* @return A builder with the additional {@code int} property.
*/
public Builder define(String property, int value) {
return define(property, new AnnotationValue.Trivial<Integer>(value));
return define(property, new AnnotationValue.ForConstant<Integer>(value));
}

/**
Expand All @@ -1152,7 +1152,7 @@ public Builder define(String property, int value) {
* @return A builder with the additional {@code long} property.
*/
public Builder define(String property, long value) {
return define(property, new AnnotationValue.Trivial<Long>(value));
return define(property, new AnnotationValue.ForConstant<Long>(value));
}

/**
Expand All @@ -1163,7 +1163,7 @@ public Builder define(String property, long value) {
* @return A builder with the additional {@code float} property.
*/
public Builder define(String property, float value) {
return define(property, new AnnotationValue.Trivial<Float>(value));
return define(property, new AnnotationValue.ForConstant<Float>(value));
}

/**
Expand All @@ -1174,7 +1174,7 @@ public Builder define(String property, float value) {
* @return A builder with the additional {@code double} property.
*/
public Builder define(String property, double value) {
return define(property, new AnnotationValue.Trivial<Double>(value));
return define(property, new AnnotationValue.ForConstant<Double>(value));
}

/**
Expand All @@ -1185,7 +1185,7 @@ public Builder define(String property, double value) {
* @return A builder with the additional {@link java.lang.String} property.
*/
public Builder define(String property, String value) {
return define(property, new AnnotationValue.Trivial<String>(value));
return define(property, new AnnotationValue.ForConstant<String>(value));
}

/**
Expand All @@ -1196,7 +1196,7 @@ public Builder define(String property, String value) {
* @return A builder with the additional {@code boolean} array property.
*/
public Builder defineArray(String property, boolean... value) {
return define(property, new AnnotationValue.Trivial<boolean[]>(value));
return define(property, new AnnotationValue.ForConstant<boolean[]>(value));
}

/**
Expand All @@ -1207,7 +1207,7 @@ public Builder defineArray(String property, boolean... value) {
* @return A builder with the additional {@code byte} array property.
*/
public Builder defineArray(String property, byte... value) {
return define(property, new AnnotationValue.Trivial<byte[]>(value));
return define(property, new AnnotationValue.ForConstant<byte[]>(value));
}

/**
Expand All @@ -1218,7 +1218,7 @@ public Builder defineArray(String property, byte... value) {
* @return A builder with the additional {@code char} array property.
*/
public Builder defineArray(String property, char... value) {
return define(property, new AnnotationValue.Trivial<char[]>(value));
return define(property, new AnnotationValue.ForConstant<char[]>(value));
}

/**
Expand All @@ -1229,7 +1229,7 @@ public Builder defineArray(String property, char... value) {
* @return A builder with the additional {@code short} array property.
*/
public Builder defineArray(String property, short... value) {
return define(property, new AnnotationValue.Trivial<short[]>(value));
return define(property, new AnnotationValue.ForConstant<short[]>(value));
}

/**
Expand All @@ -1240,7 +1240,7 @@ public Builder defineArray(String property, short... value) {
* @return A builder with the additional {@code int} array property.
*/
public Builder defineArray(String property, int... value) {
return define(property, new AnnotationValue.Trivial<int[]>(value));
return define(property, new AnnotationValue.ForConstant<int[]>(value));
}

/**
Expand All @@ -1251,7 +1251,7 @@ public Builder defineArray(String property, int... value) {
* @return A builder with the additional {@code long} array property.
*/
public Builder defineArray(String property, long... value) {
return define(property, new AnnotationValue.Trivial<long[]>(value));
return define(property, new AnnotationValue.ForConstant<long[]>(value));
}

/**
Expand All @@ -1262,7 +1262,7 @@ public Builder defineArray(String property, long... value) {
* @return A builder with the additional {@code float} array property.
*/
public Builder defineArray(String property, float... value) {
return define(property, new AnnotationValue.Trivial<float[]>(value));
return define(property, new AnnotationValue.ForConstant<float[]>(value));
}

/**
Expand All @@ -1273,7 +1273,7 @@ public Builder defineArray(String property, float... value) {
* @return A builder with the additional {@code double} array property.
*/
public Builder defineArray(String property, double... value) {
return define(property, new AnnotationValue.Trivial<double[]>(value));
return define(property, new AnnotationValue.ForConstant<double[]>(value));
}

/**
Expand All @@ -1284,7 +1284,7 @@ public Builder defineArray(String property, double... value) {
* @return A builder with the additional {@link java.lang.String} array property.
*/
public Builder defineArray(String property, String... value) {
return define(property, new AnnotationValue.Trivial<String[]>(value));
return define(property, new AnnotationValue.ForConstant<String[]>(value));
}

/**
Expand Down
Expand Up @@ -186,7 +186,7 @@ public <S> S resolve(Class<? extends S> type) {
*
* @param <U> The type where primitive values are represented by their boxed type.
*/
class Trivial<U> extends AbstractBase<U, U> {
class ForConstant<U> extends AbstractBase<U, U> {

/**
* The represented value.
Expand All @@ -203,7 +203,7 @@ class Trivial<U> extends AbstractBase<U, U> {
*
* @param value The value to represent.
*/
public Trivial(U value) {
public ForConstant(U value) {
this.value = value;
propertyDispatcher = PropertyDispatcher.of(value.getClass());
}
Expand All @@ -221,7 +221,7 @@ public AnnotationValue.Loaded<U> load(ClassLoader classLoader) {
@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& propertyDispatcher.equals(value, ((Trivial) other).value);
&& propertyDispatcher.equals(value, ((ForConstant) other).value);
}

@Override
Expand All @@ -231,7 +231,7 @@ public int hashCode() {

@Override
public String toString() {
return "AnnotationValue.Trivial{" +
return "AnnotationValue.ForConstant{" +
"value=" + value +
", propertyDispatcher=" + propertyDispatcher +
'}';
Expand Down Expand Up @@ -347,12 +347,12 @@ public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
ForAnnotation that = (ForAnnotation) other;
return equals(that.annotationDescription);
return annotationDescription.equals(that.annotationDescription);
}

@Override
public int hashCode() {
return hashCode();
return annotationDescription.hashCode();
}

@Override
Expand Down
Expand Up @@ -7808,7 +7808,7 @@ protected AnnotationExtractor(AnnotationRegistrant annotationRegistrant, Compone
public void visit(String name, Object value) {
annotationRegistrant.register(name, value instanceof Type
? new RawTypeValue(Default.this, (Type) value)
: new AnnotationValue.Trivial<Object>(value));
: new AnnotationValue.ForConstant<Object>(value));
}

@Override
Expand Down
Expand Up @@ -629,41 +629,41 @@ public void testGetActualModifiers() throws Exception {
@SuppressWarnings("unchecked")
public void testIsDefault() throws Exception {
Map<String, AnnotationValue<?, ?>> properties = new LinkedHashMap<String, AnnotationValue<?, ?>>();
properties.put("boolean_property", new AnnotationValue.Trivial<Boolean>(true));
properties.put("boolean_property_array", new AnnotationValue.Trivial<boolean[]>(new boolean[]{true}));
properties.put("byte_property", new AnnotationValue.Trivial<Byte>((byte) 0));
properties.put("byte_property_array", new AnnotationValue.Trivial<byte[]>(new byte[]{0}));
properties.put("short_property", new AnnotationValue.Trivial<Short>((short) 0));
properties.put("short_property_array", new AnnotationValue.Trivial<short[]>(new short[]{0}));
properties.put("int_property", new AnnotationValue.Trivial<Integer>(0));
properties.put("int_property_array", new AnnotationValue.Trivial<int[]>(new int[]{0}));
properties.put("long_property", new AnnotationValue.Trivial<Long>(0L));
properties.put("long_property_array", new AnnotationValue.Trivial<long[]>(new long[]{0}));
properties.put("float_property", new AnnotationValue.Trivial<Float>(0f));
properties.put("float_property_array", new AnnotationValue.Trivial<float[]>(new float[]{0}));
properties.put("double_property", new AnnotationValue.Trivial<Double>(0d));
properties.put("double_property_array", new AnnotationValue.Trivial<double[]>(new double[]{0d}));
properties.put("string_property", new AnnotationValue.Trivial<String>("foo"));
properties.put("string_property_array", new AnnotationValue.Trivial<String[]>(new String[]{"foo"}));
properties.put("boolean_property", new AnnotationValue.ForConstant<Boolean>(true));
properties.put("boolean_property_array", new AnnotationValue.ForConstant<boolean[]>(new boolean[]{true}));
properties.put("byte_property", new AnnotationValue.ForConstant<Byte>((byte) 0));
properties.put("byte_property_array", new AnnotationValue.ForConstant<byte[]>(new byte[]{0}));
properties.put("short_property", new AnnotationValue.ForConstant<Short>((short) 0));
properties.put("short_property_array", new AnnotationValue.ForConstant<short[]>(new short[]{0}));
properties.put("int_property", new AnnotationValue.ForConstant<Integer>(0));
properties.put("int_property_array", new AnnotationValue.ForConstant<int[]>(new int[]{0}));
properties.put("long_property", new AnnotationValue.ForConstant<Long>(0L));
properties.put("long_property_array", new AnnotationValue.ForConstant<long[]>(new long[]{0}));
properties.put("float_property", new AnnotationValue.ForConstant<Float>(0f));
properties.put("float_property_array", new AnnotationValue.ForConstant<float[]>(new float[]{0}));
properties.put("double_property", new AnnotationValue.ForConstant<Double>(0d));
properties.put("double_property_array", new AnnotationValue.ForConstant<double[]>(new double[]{0d}));
properties.put("string_property", new AnnotationValue.ForConstant<String>("foo"));
properties.put("string_property_array", new AnnotationValue.ForConstant<String[]>(new String[]{"foo"}));
AnnotationDescription annotationDescription = mock(AnnotationDescription.class);
when(annotationDescription.getAnnotationType()).thenReturn(new TypeDescription.ForLoadedType(SampleAnnotation.class));
properties.put("annotation_property", new AnnotationValue.Trivial<AnnotationDescription>(annotationDescription));
properties.put("annotation_property_array", new AnnotationValue.Trivial<AnnotationDescription[]>(new AnnotationDescription[]{annotationDescription}));
properties.put("annotation_property", new AnnotationValue.ForConstant<AnnotationDescription>(annotationDescription));
properties.put("annotation_property_array", new AnnotationValue.ForConstant<AnnotationDescription[]>(new AnnotationDescription[]{annotationDescription}));
EnumerationDescription enumerationDescription = mock(EnumerationDescription.class);
when(enumerationDescription.getEnumerationType()).thenReturn(new TypeDescription.ForLoadedType(SampleEnumeration.class));
properties.put("enum_property", new AnnotationValue.Trivial<EnumerationDescription>(enumerationDescription));
properties.put("enum_property_array", new AnnotationValue.Trivial<EnumerationDescription[]>(new EnumerationDescription[]{enumerationDescription}));
properties.put("enum_property", new AnnotationValue.ForConstant<EnumerationDescription>(enumerationDescription));
properties.put("enum_property_array", new AnnotationValue.ForConstant<EnumerationDescription[]>(new EnumerationDescription[]{enumerationDescription}));
MethodList<?> methods = new TypeDescription.ForLoadedType(AnnotationValues.class).getDeclaredMethods();
for (Map.Entry<String, AnnotationValue<?, ?>> entry : properties.entrySet()) {
assertThat(methods.filter(named(entry.getKey())).getOnly().isDefaultValue(entry.getValue()), is(true));
assertThat(methods.filter(named(entry.getKey())).getOnly().isDefaultValue(mock(AnnotationValue.class)), is(false));
}
when(annotationDescription.getAnnotationType()).thenReturn(TypeDescription.OBJECT);
assertThat(methods.filter(named("annotation_property")).getOnly().isDefaultValue(new AnnotationValue.Trivial<AnnotationDescription>(annotationDescription)), is(false));
assertThat(methods.filter(named("annotation_property_array")).getOnly().isDefaultValue(new AnnotationValue.Trivial<AnnotationDescription[]>(new AnnotationDescription[]{annotationDescription})), is(false));
assertThat(methods.filter(named("annotation_property")).getOnly().isDefaultValue(new AnnotationValue.ForConstant<AnnotationDescription>(annotationDescription)), is(false));
assertThat(methods.filter(named("annotation_property_array")).getOnly().isDefaultValue(new AnnotationValue.ForConstant<AnnotationDescription[]>(new AnnotationDescription[]{annotationDescription})), is(false));
when(enumerationDescription.getEnumerationType()).thenReturn(TypeDescription.OBJECT);
assertThat(methods.filter(named("enum_property")).getOnly().isDefaultValue(new AnnotationValue.Trivial<EnumerationDescription>(enumerationDescription)), is(false));
assertThat(methods.filter(named("enum_property_array")).getOnly().isDefaultValue(new AnnotationValue.Trivial<EnumerationDescription[]>(new EnumerationDescription[]{enumerationDescription})), is(false));
assertThat(methods.filter(named("enum_property")).getOnly().isDefaultValue(new AnnotationValue.ForConstant<EnumerationDescription>(enumerationDescription)), is(false));
assertThat(methods.filter(named("enum_property_array")).getOnly().isDefaultValue(new AnnotationValue.ForConstant<EnumerationDescription[]>(new EnumerationDescription[]{enumerationDescription})), is(false));
}

@Retention(RetentionPolicy.RUNTIME)
Expand Down
Expand Up @@ -1180,7 +1180,7 @@ public void testMethodIllegalDefaultValue() throws Exception {
Collections.<ParameterDescription.Token>emptyList(),
Collections.<TypeDescription.Generic>emptyList(),
Collections.<AnnotationDescription>emptyList(),
new AnnotationValue.Trivial<String>(FOO),
new AnnotationValue.ForConstant<String>(FOO),
TypeDescription.Generic.UNDEFINED))
.validated();
}
Expand Down

0 comments on commit 5edfeb9

Please sign in to comment.