Skip to content

Commit f26c0e8

Browse files
author
smgfreeman
committed
Broken check-in to cope with GWT commit
1 parent 2dcab6f commit f26c0e8

27 files changed

Lines changed: 203 additions & 74 deletions

‎hamcrest-core/src/main/java/org/hamcrest/core/CombinableMatcher.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private ArrayList<Matcher<? super T>> templatedListWith(Matcher<? super T> other
4444
* </pre>
4545
*/
4646
@Factory
47-
public static <LHS> CombinableMatcher<LHS> both(Matcher<LHS> matcher) {
47+
public static <LHS> CombinableMatcher<LHS> both(Matcher<? super LHS> matcher) {
4848
return new CombinableMatcher<LHS>(matcher);
4949
}
5050

@@ -55,7 +55,7 @@ public static <LHS> CombinableMatcher<LHS> both(Matcher<LHS> matcher) {
5555
* </pre>
5656
*/
5757
@Factory
58-
public static <LHS> CombinableMatcher<LHS> either(Matcher<LHS> matcher) {
58+
public static <LHS> CombinableMatcher<LHS> either(Matcher<? super LHS> matcher) {
5959
return new CombinableMatcher<LHS>(matcher);
6060
}
6161

‎hamcrest-core/src/main/java/org/hamcrest/core/Is.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static <T> Matcher<T> is(Matcher<T> matcher) {
5555
* vs. assertThat(cheese, is(smelly))
5656
*/
5757
@Factory
58-
public static <T> Matcher<T> is(T value) {
58+
public static <T> Matcher<? super T> is(T value) {
5959
return is(equalTo(value));
6060
}
6161

‎hamcrest-core/src/main/java/org/hamcrest/core/IsNot.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static <T> Matcher<T> not(Matcher<T> matcher) {
4444
* vs. assertThat(cheese, is(not(smelly)))
4545
*/
4646
@Factory
47-
public static <T> Matcher<T> not(T value) {
47+
public static <T> Matcher<? super T> not(T value) {
4848
return not(equalTo(value));
4949
}
5050
}

‎hamcrest-generator/src/main/java/org/hamcrest/generator/HamcrestFactoryWriter.java‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.io.PrintWriter;
55
import java.io.Writer;
6+
import java.util.StringTokenizer;
67

78
/**
89
* {@link FactoryWriter} that outputs Java code which simply delegates all
@@ -88,7 +89,30 @@ private void writeGenericTypeParameters(FactoryMethod factoryMethod) {
8889
private void writeMethodBody(FactoryMethod factoryMethod) {
8990
indent();
9091
output.append("return ").append(factoryMethod.getMatcherClass());
91-
output.append('.').append(factoryMethod.getName());
92+
output.append('.');
93+
94+
// lets write the generic types
95+
if (!factoryMethod.getGenericTypeParameters().isEmpty()) {
96+
output.append('<');
97+
boolean seenFirst = false;
98+
for (String type : factoryMethod.getGenericTypeParameters()) {
99+
if (seenFirst) {
100+
output.append(",");
101+
} else {
102+
seenFirst = true;
103+
}
104+
// lets only print the first word of the type
105+
// so if its 'T extends Cheese' we just print T
106+
//output.append(type);
107+
108+
StringTokenizer iter = new StringTokenizer(type);
109+
iter.hasMoreElements();
110+
output.append(iter.nextToken());
111+
}
112+
output.append(">");
113+
}
114+
115+
output.append(factoryMethod.getName());
92116
output.append('(');
93117
boolean seenFirst = false;
94118
for (FactoryMethod.Parameter parameter : factoryMethod.getParameters()) {

‎hamcrest-integration/src/main/java/org/hamcrest/MatcherAssert.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55

66
public class MatcherAssert {
7-
public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
7+
8+
public static <T,K extends T,V extends T> void assertThat(K actual, Matcher<V> matcher) {
89
assertThat("", actual, matcher);
910
}
10-
11-
public static <T> void assertThat(String reason, T actual, Matcher<? super T> matcher) {
11+
12+
public static<T,K extends T,V extends T> void assertThat(String reason, K actual, Matcher<V> matcher) {
1213
if (!matcher.matches(actual)) {
1314
Description description = new StringDescription();
1415
description.appendText(reason)

‎hamcrest-library/src/main/java/org/hamcrest/collection/IsArray.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44

55
import org.hamcrest.Description;
66
import org.hamcrest.Matcher;
7+
import org.hamcrest.TypeSafeMatcher;
78

89
/**
910
* Matcher for array whose elements satisfy a sequence of matchers.
1011
* The array size must equal the number of element matchers.
1112
*/
12-
public class IsArray<T> extends ArrayMatcher<T> {
13+
public class IsArray<T> extends TypeSafeMatcher<T[]> {
1314
private final Matcher<T>[] elementMatchers;
1415

15-
@SuppressWarnings("unchecked")
1616
public IsArray(Matcher<T>[] elementMatchers) {
17-
this.elementMatchers = new Matcher[elementMatchers.length];
18-
System.arraycopy(elementMatchers, 0, this.elementMatchers, 0, elementMatchers.length);
17+
this.elementMatchers = elementMatchers.clone();
1918
}
2019

2120
@Override

‎hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContaining.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Matches if an array contains an item satisfying a nested matcher.
1010
*/
1111
public class IsArrayContaining<T> extends ArrayMatcher<T> {
12-
private final Matcher<T> elementMatcher;
12+
private final Matcher<? super T> elementMatcher;
1313

14-
public IsArrayContaining(Matcher<T> elementMatcher) {
14+
public IsArrayContaining(Matcher<? super T> elementMatcher) {
1515
this.elementMatcher = elementMatcher;
1616
}
1717

@@ -35,7 +35,7 @@ public void describeTo(Description description) {
3535
* Evaluates to true if any item in an array satisfies the given matcher.
3636
*/
3737
@Factory
38-
public static <T> Matcher<T[]> hasItemInArray(Matcher<T> elementMatcher) {
38+
public static <T> Matcher<T[]> hasItemInArray(Matcher<? super T> elementMatcher) {
3939
return new IsArrayContaining<T>(elementMatcher);
4040
}
4141

@@ -47,6 +47,7 @@ public static <T> Matcher<T[]> hasItemInArray(Matcher<T> elementMatcher) {
4747
*/
4848
@Factory
4949
public static <T> Matcher<T[]> hasItemInArray(T element) {
50-
return hasItemInArray(equalTo(element));
50+
Matcher<? super T> matcher = equalTo(element);
51+
return IsArrayContaining.<T>hasItemInArray(matcher);
5152
}
5253
}

‎hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayWithSize.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* Matches if array size satisfies a nested matcher.
1212
*/
1313
public class IsArrayWithSize<E> extends ArrayMatcher<E> {
14-
private final Matcher<Integer> sizeMatcher;
14+
private final Matcher<? super Integer> sizeMatcher;
1515

16-
public IsArrayWithSize(Matcher<Integer> sizeMatcher) {
16+
public IsArrayWithSize(Matcher<? super Integer> sizeMatcher) {
1717
this.sizeMatcher = sizeMatcher;
1818
}
1919

@@ -31,7 +31,7 @@ public void describeTo(Description description) {
3131
* Does array size satisfy a given matcher?
3232
*/
3333
@Factory
34-
public static <E> Matcher<E[]> arrayWithSize(Matcher<Integer> sizeMatcher) {
34+
public static <E> Matcher<E[]> arrayWithSize(Matcher<? super Integer> sizeMatcher) {
3535
return new IsArrayWithSize<E>(sizeMatcher);
3636
}
3737

‎hamcrest-library/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
import org.hamcrest.Description;
88
import org.hamcrest.Factory;
99
import org.hamcrest.Matcher;
10+
import org.hamcrest.TypeSafeMatcher;
1011

1112
/**
1213
* Matches if collection size satisfies a nested matcher.
1314
*/
14-
public class IsCollectionWithSize<E> extends CollectionMatcher<E> {
15-
private final Matcher<Integer> sizeMatcher;
15+
public class IsCollectionWithSize<E> extends TypeSafeMatcher<Collection<? extends E>> {
16+
private final Matcher<? super Integer> sizeMatcher;
1617

17-
public IsCollectionWithSize(Matcher<Integer> sizeMatcher) {
18+
public IsCollectionWithSize(Matcher<? super Integer> sizeMatcher) {
1819
this.sizeMatcher = sizeMatcher;
1920
}
2021

2122
@Override
22-
public boolean matchesSafely(Collection<E> item) {
23+
public boolean matchesSafely(Collection<? extends E> item) {
2324
return sizeMatcher.matches(item.size());
2425
}
2526

@@ -32,18 +33,20 @@ public void describeTo(Description description) {
3233
* Does collection size satisfy a given matcher?
3334
*/
3435
@Factory
35-
public static <E> Matcher<Collection<E>> hasSize(Matcher<Integer> size) {
36+
public static <E> Matcher<? super Collection<? extends E>> hasSize(Matcher<? super Integer> size) {
3637
return new IsCollectionWithSize<E>(size);
3738
}
3839

40+
3941
/**
4042
* This is a shortcut to the frequently used hasSize(equalTo(x)).
4143
*
4244
* For example, assertThat(hasSize(equal_to(x)))
4345
* vs. assertThat(hasSize(x))
4446
*/
4547
@Factory
46-
public static <E> Matcher<Collection<E>> hasSize(int size) {
47-
return hasSize(equalTo(size));
48+
public static <E> Matcher<? super Collection<? extends E>> hasSize(int size) {
49+
Matcher<? super Integer> matcher = equalTo(size);
50+
return IsCollectionWithSize.<E>hasSize(matcher);
4851
}
4952
}

‎hamcrest-library/src/main/java/org/hamcrest/collection/IsIterableWithSize.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import org.hamcrest.core.DiagnosingIterableMatcher;
1111

1212
public class IsIterableWithSize<E> extends DiagnosingIterableMatcher<E> {
13-
private final Matcher<Integer> sizeMatcher;
13+
private final Matcher<? super Integer> sizeMatcher;
1414

15-
public IsIterableWithSize(Matcher<Integer> sizeMatcher) {
15+
public IsIterableWithSize(Matcher<? super Integer> sizeMatcher) {
1616
this.sizeMatcher = sizeMatcher;
1717
}
1818

@@ -35,7 +35,7 @@ public void describeTo(Description description) {
3535
}
3636

3737
@Factory
38-
public static <E> Matcher<Iterable<E>> iterableWithSize(Matcher<Integer> sizeMatcher) {
38+
public static <E> Matcher<Iterable<E>> iterableWithSize(Matcher<? super Integer> sizeMatcher) {
3939
return new IsIterableWithSize<E>(sizeMatcher);
4040
}
4141

0 commit comments

Comments
 (0)