Skip to content

Commit c03c925

Browse files
author
nat.pryce
committed
Fixing generics warnings
1 parent 6e5a464 commit c03c925

File tree

12 files changed

+46
-52
lines changed

12 files changed

+46
-52
lines changed

hamcrest-generator/src/main/java/org/hamcrest/generator/EasyMock2FactoryWriter.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,6 @@ public void writeMethod(String generatedMethodName, FactoryMethod factoryMethodT
6969
output.append('}').append(newLine).append(newLine);
7070
}
7171

72-
private void writeGenericTypeParameters(FactoryMethod factoryMethod) {
73-
if (!factoryMethod.getGenericTypeParameters().isEmpty()) {
74-
output.append('<');
75-
boolean seenFirst = false;
76-
for (String type : factoryMethod.getGenericTypeParameters()) {
77-
if (seenFirst) {
78-
output.append(", ");
79-
} else {
80-
seenFirst = true;
81-
}
82-
output.append(type);
83-
}
84-
output.append("> ");
85-
}
86-
}
87-
8872
private void writeMethodBody(FactoryMethod factoryMethod) {
8973
indent();
9074
output.append("org.hamcrest.integration.EasyMockAdapter.adapt(").append(newLine);

hamcrest-generator/src/main/java/org/hamcrest/generator/ReflectiveFactoryReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
*/
2828
public class ReflectiveFactoryReader implements Iterable<FactoryMethod> {
2929

30-
private final Class cls;
30+
private final Class<?> cls;
3131

3232
private final ClassLoader classLoader;
3333

34-
public ReflectiveFactoryReader(Class cls) {
34+
public ReflectiveFactoryReader(Class<?> cls) {
3535
this.cls = cls;
3636
this.classLoader = cls.getClassLoader();
3737
}
@@ -137,7 +137,7 @@ private FactoryMethod buildFactoryMethod(Method javaMethod) {
137137
result.addParameter(type, "param" + (++paramNumber));
138138
}
139139

140-
for (Class exception : javaMethod.getExceptionTypes()) {
140+
for (Class<?> exception : javaMethod.getExceptionTypes()) {
141141
result.addException(typeToString(exception));
142142
}
143143

@@ -151,8 +151,8 @@ private FactoryMethod buildFactoryMethod(Method javaMethod) {
151151
* across implementations. Rock on Liskov.
152152
*/
153153
private String typeToString(Type type) {
154-
if (type instanceof Class) {
155-
Class cls = (Class) type;
154+
if (type instanceof Class<?>) {
155+
Class<?> cls = (Class<?>) type;
156156
if (cls.isArray()) {
157157
return cls.getComponentType().getName() + "[]";
158158
} else {

hamcrest-generator/src/main/java/org/hamcrest/generator/config/XmlConfigurator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void startElement(String uri, String localName, String qName, Attributes
5656
}
5757

5858
private void addClass(String className) throws ClassNotFoundException {
59-
Class cls = classLoader.loadClass(className);
59+
Class<?> cls = classLoader.loadClass(className);
6060
sugarConfiguration.addFactoryMethods(
6161
new QDoxFactoryReader(new ReflectiveFactoryReader(cls), qdox, className));
6262
}

hamcrest-integration/src/main/java/org/hamcrest/integration/EasyMock2Adapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public class EasyMock2Adapter implements IArgumentMatcher {
1919
* EasyMock {@link org.easymock.IArgumentMatcher} and
2020
* report it to EasyMock so it can be kept track of.
2121
*/
22-
public static IArgumentMatcher adapt(Matcher matcher) {
22+
public static IArgumentMatcher adapt(Matcher<?> matcher) {
2323
EasyMock2Adapter easyMock2Matcher = new EasyMock2Adapter(matcher);
2424
EasyMock.reportMatcher(easyMock2Matcher);
2525
return easyMock2Matcher;
2626
}
2727

28-
private final Matcher hamcrestMatcher;
28+
private final Matcher<?> hamcrestMatcher;
2929

30-
public EasyMock2Adapter(Matcher matcher) {
30+
public EasyMock2Adapter(Matcher<?> matcher) {
3131
this.hamcrestMatcher = matcher;
3232
}
3333

hamcrest-integration/src/main/java/org/hamcrest/integration/JMock1Adapter.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ public class JMock1Adapter implements Constraint {
1919
* Hamcrest {@link org.hamcrest.Matcher} to act as an
2020
* jMock {@link org.jmock.core.Constraint}.
2121
*/
22-
public static Constraint adapt(Matcher matcher) {
22+
public static Constraint adapt(Matcher<?> matcher) {
2323
return new JMock1Adapter(matcher);
2424
}
2525

26-
private final Matcher hamcrestMatcher;
26+
private final Matcher<?> hamcrestMatcher;
2727

28-
public JMock1Adapter(Matcher matcher) {
28+
public JMock1Adapter(Matcher<?> matcher) {
2929
this.hamcrestMatcher = matcher;
3030
}
3131

32-
@SuppressWarnings({"unchecked"})
3332
public boolean eval(Object o) {
3433
return hamcrestMatcher.matches(o);
3534
}
@@ -38,5 +37,4 @@ public StringBuffer describeTo(StringBuffer buffer) {
3837
hamcrestMatcher.describeTo(new StringDescription(buffer));
3938
return buffer;
4039
}
41-
4240
}

hamcrest-library/src/main/java/org/hamcrest/beans/HasPropertyWithValue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public class HasPropertyWithValue<T> extends TypeSafeMatcher<T> {
7070
private static final Object[] NO_ARGUMENTS = new Object[0];
7171

7272
private final String propertyName;
73-
private final Matcher value;
73+
private final Matcher<?> value;
7474

75-
public HasPropertyWithValue(String propertyName, Matcher value) {
75+
public HasPropertyWithValue(String propertyName, Matcher<?> value) {
7676
this.propertyName = propertyName;
7777
this.value = value;
7878
}
@@ -107,7 +107,7 @@ public void describeTo(Description description) {
107107
}
108108

109109
@Factory
110-
public static <T> Matcher<T> hasProperty(String propertyName, Matcher value) {
110+
public static <T> Matcher<T> hasProperty(String propertyName, Matcher<?> value) {
111111
return new HasPropertyWithValue<T>(propertyName, value);
112112
}
113113
}

hamcrest-unit-test/src/main/java/org/hamcrest/beans/HasPropertyWithValueTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void testDoesNotMatchWriteOnlyProperty() {
5050
}
5151

5252
public void testDescribeTo() {
53-
Matcher matcher = equalTo(true);
53+
Matcher<?> matcher = equalTo(true);
5454

5555
assertDescription("hasProperty(\"property\", " + StringDescription.asString(matcher) + ")",
5656
hasProperty("property", matcher));

hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsCollectionContainingTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void testHasAReadableDescription() {
4141
assertDescription("a collection containing \"a\"", hasItem(equalTo("a")));
4242
}
4343

44+
@SuppressWarnings("unchecked")
4445
public void testMatchesAllItemsInCollection() {
4546
final Matcher<Iterable<String>> matcher1 = hasItems(equalTo("a"), equalTo("b"), equalTo("c"));
4647
assertMatches("should match list containing all items",

hamcrest-unit-test/src/main/java/org/hamcrest/core/AllOfTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.hamcrest.Matcher;
1010

1111
public class AllOfTest extends AbstractMatcherTest {
12+
@SuppressWarnings("unchecked")
1213
public void testEvaluatesToTheTheLogicalConjunctionOfTwoOtherMatchers() {
1314
assertThat("good", allOf(equalTo("good"), equalTo("good")));
1415

@@ -17,11 +18,13 @@ public void testEvaluatesToTheTheLogicalConjunctionOfTwoOtherMatchers() {
1718
assertThat("good", not(allOf(equalTo("bad"), equalTo("bad"))));
1819
}
1920

21+
@SuppressWarnings("unchecked")
2022
public void testEvaluatesToTheTheLogicalConjunctionOfManyOtherMatchers() {
2123
assertThat("good", allOf(equalTo("good"), equalTo("good"), equalTo("good"), equalTo("good"), equalTo("good")));
2224
assertThat("good", not(allOf(equalTo("good"), equalTo("good"), equalTo("bad"), equalTo("good"), equalTo("good"))));
2325
}
2426

27+
@SuppressWarnings("unchecked")
2528
public void testSupportsMixedTypes() {
2629
final Matcher<SampleSubClass> all = allOf(
2730
equalTo(new SampleBaseClass("bad")),
@@ -32,6 +35,7 @@ public void testSupportsMixedTypes() {
3235
assertThat(new SampleSubClass("good"), negated);
3336
}
3437

38+
@SuppressWarnings("unchecked")
3539
protected Matcher<?> createMatcher() {
3640
return allOf(equalTo("irrelevant"), equalTo("irrelevant"));
3741
}

hamcrest-unit-test/src/main/java/org/hamcrest/core/AnyOfTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
public class AnyOfTest extends AbstractMatcherTest {
1212

13+
@SuppressWarnings("unchecked")
1314
protected Matcher<?> createMatcher() {
1415
return anyOf(equalTo("irrelevant"));
1516
}
1617

18+
@SuppressWarnings("unchecked")
1719
public void testEvaluatesToTheTheLogicalDisjunctionOfTwoOtherMatchers() {
1820
assertThat("good", anyOf(equalTo("bad"), equalTo("good")));
1921
assertThat("good", anyOf(equalTo("good"), equalTo("good")));
@@ -22,11 +24,13 @@ public void testEvaluatesToTheTheLogicalDisjunctionOfTwoOtherMatchers() {
2224
assertThat("good", not(anyOf(equalTo("bad"), equalTo("bad"))));
2325
}
2426

27+
@SuppressWarnings("unchecked")
2528
public void testEvaluatesToTheTheLogicalDisjunctionOfManyOtherMatchers() {
2629
assertThat("good", anyOf(equalTo("bad"), equalTo("good"), equalTo("bad"), equalTo("bad"), equalTo("bad")));
2730
assertThat("good", not(anyOf(equalTo("bad"), equalTo("bad"), equalTo("bad"), equalTo("bad"), equalTo("bad"))));
2831
}
2932

33+
@SuppressWarnings("unchecked")
3034
public void testSupportsMixedTypes() {
3135
final Matcher<SampleSubClass> combined = anyOf(
3236
equalTo(new SampleBaseClass("bad")),

hamcrest-unit-test/src/main/java/org/hamcrest/generator/ReflectiveFactoryReaderTest.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public class ReflectiveFactoryReaderTest extends TestCase {
1919
public static class SimpleSetOfMatchers {
2020

2121
@Factory
22-
public static Matcher firstMethod() {
22+
public static Matcher<String> firstMethod() {
2323
return null;
2424
}
2525

2626
@Factory
27-
public static Matcher secondMethod() {
27+
public static Matcher<String> secondMethod() {
2828
return null;
2929
}
3030

@@ -50,21 +50,21 @@ public void testIteratesOverFactoryMethods() {
5050
public static class MatchersWithDodgySignatures {
5151

5252
@Factory
53-
public Matcher notStatic() {
53+
public Matcher<String> notStatic() {
5454
return null;
5555
}
5656

5757
@Factory
58-
static Matcher notPublic() {
58+
static Matcher<String> notPublic() {
5959
return null;
6060
}
6161

62-
public static Matcher noAnnotation() {
62+
public static Matcher<String> noAnnotation() {
6363
return null;
6464
}
6565

6666
@Factory
67-
public static Matcher goodMethod() {
67+
public static Matcher<String> goodMethod() {
6868
return null;
6969
}
7070

@@ -96,10 +96,11 @@ public void testOnlyReadsPublicStaticAnnotatedMethodsThatReturnMatcher() {
9696
public static class GenerifiedMatchers {
9797

9898
@Factory
99-
public static Matcher<Comparator> generifiedType() {
99+
public static Matcher<Comparator<String>> generifiedType() {
100100
return null;
101101
}
102102

103+
@SuppressWarnings("unchecked")
103104
@Factory
104105
public static Matcher noGenerifiedType() {
105106
return null;
@@ -114,7 +115,7 @@ public static Matcher<Map<? extends Set<Long>, Factory>> crazyType() {
114115

115116
public void testReadsFullyQualifiedGenericType() {
116117
FactoryMethod method = readMethod(GenerifiedMatchers.class, "generifiedType");
117-
assertEquals("java.util.Comparator", method.getGenerifiedType());
118+
assertEquals("java.util.Comparator<java.lang.String>", method.getGenerifiedType());
118119
}
119120

120121
public void testReadsNullGenerifiedTypeIfNotPresent() {
@@ -132,22 +133,22 @@ public void testReadsGenericsInGenericType() {
132133
public static class ParamterizedMatchers {
133134

134135
@Factory
135-
public static Matcher withParam(String someString, int[] numbers, Collection things) {
136+
public static Matcher<String> withParam(String someString, int[] numbers, Collection<Object> things) {
136137
return null;
137138
}
138139

139140
@Factory
140-
public static Matcher withArray(String[] array) {
141+
public static Matcher<String> withArray(String[] array) {
141142
return null;
142143
}
143144

144145
@Factory
145-
public static Matcher withVarArgs(String... things) {
146+
public static Matcher<String> withVarArgs(String... things) {
146147
return null;
147148
}
148149

149150
@Factory
150-
public static Matcher withGenerifiedParam(Collection<? extends Comparable> things, Set<String[]>[] x) {
151+
public static Matcher<String> withGenerifiedParam(Collection<? extends Comparable<String>> things, Set<String[]>[] x) {
151152
return null;
152153
}
153154

@@ -160,7 +161,7 @@ public void testReadsParameterTypes() {
160161

161162
assertEquals("java.lang.String", params.get(0).getType());
162163
assertEquals("int[]", params.get(1).getType());
163-
assertEquals("java.util.Collection", params.get(2).getType());
164+
assertEquals("java.util.Collection<java.lang.Object>", params.get(2).getType());
164165
}
165166

166167
public void testReadsArrayAndVarArgParameterTypes() {
@@ -173,7 +174,7 @@ public void testReadsArrayAndVarArgParameterTypes() {
173174

174175
public void testReadsGenerifiedParameterTypes() {
175176
FactoryMethod method = readMethod(ParamterizedMatchers.class, "withGenerifiedParam");
176-
assertEquals("java.util.Collection<? extends java.lang.Comparable>",
177+
assertEquals("java.util.Collection<? extends java.lang.Comparable<java.lang.String>>",
177178
method.getParameters().get(0).getType());
178179
assertEquals("java.util.Set<java.lang.String[]>[]",
179180
method.getParameters().get(1).getType());
@@ -191,7 +192,7 @@ public void testCannotReadParameterNamesSoMakesThemUpInstead() {
191192
public static class ExceptionalMatchers {
192193

193194
@Factory
194-
public static Matcher withExceptions() throws Error, IOException, RuntimeException {
195+
public static Matcher<String> withExceptions() throws Error, IOException, RuntimeException {
195196
return null;
196197
}
197198

@@ -215,14 +216,14 @@ public static class WithJavaDoc {
215216
* @return something
216217
*/
217218
@Factory
218-
public static Matcher documented() {
219+
public static Matcher<String> documented() {
219220
return null;
220221
}
221222

222223
}
223224

224225
public void testCannotReadJavaDoc() {
225-
// JavaDoc informatation is not available through reflection alone.
226+
// JavaDoc information is not available through reflection alone.
226227
FactoryMethod method = readMethod(WithJavaDoc.class, "documented");
227228
assertEquals(null, method.getJavaDoc());
228229
}
@@ -257,7 +258,7 @@ public void testCatchesSubclasses() {
257258
assertNotNull(readMethod(SubclassOfMatcher.class, "subclassMethod"));
258259
}
259260

260-
private FactoryMethod readMethod(Class cls, String methodName) {
261+
private FactoryMethod readMethod(Class<?> cls, String methodName) {
261262
for (FactoryMethod method : new ReflectiveFactoryReader(cls)) {
262263
if (method.getName().equals(methodName)) {
263264
return method;

hamcrest-unit-test/src/main/java/org/hamcrest/generator/config/XmlConfiguratorTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ private InputSource createXml(String xml) {
4848

4949
// Sample Matchers
5050

51+
@SuppressWarnings("unchecked")
5152
public static class SomeMatcher {
5253
@Factory
5354
public static Matcher matcher1() {
@@ -60,6 +61,7 @@ public static Matcher matcher2() {
6061
}
6162
}
6263

64+
@SuppressWarnings("unchecked")
6365
public static class AnotherMatcher {
6466
@Factory
6567
public static Matcher matcher3() {

0 commit comments

Comments
 (0)