Skip to content

Commit 425f095

Browse files
committed
Removed @factory annotations, because we no longer use generate code, and deprecated the annotation interface so that existing third-party code continues to compile.
1 parent 86fcf79 commit 425f095

File tree

106 files changed

+256
-528
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+256
-528
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package org.hamcrest;
22

3-
import static java.lang.annotation.ElementType.METHOD;
43
import java.lang.annotation.Retention;
5-
import static java.lang.annotation.RetentionPolicy.RUNTIME;
64
import java.lang.annotation.Target;
75

6+
import static java.lang.annotation.ElementType.METHOD;
7+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
8+
89
/**
910
* Marks a Hamcrest static factory method so tools recognise them.
1011
* A factory method is an equivalent to a named constructor.
11-
*
12+
*
13+
* @deprecated The code generator is no longer maintained. Write classes of syntactic sugar by hand.
1214
* @author Joe Walnes
1315
*/
1416
@Retention(RUNTIME)
1517
@Target({METHOD})
18+
@Deprecated
1619
public @interface Factory {
1720
}

hamcrest-api/src/test/java/org/hamcrest/NullDescriptionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.hamcrest;
22

3-
import static org.junit.Assert.assertEquals;
4-
53
import org.hamcrest.Description.NullDescription;
64
import org.junit.Test;
75

6+
import static org.junit.Assert.assertEquals;
7+
88
public final class NullDescriptionTest {
99

1010
private final NullDescription nullDescription = new Description.NullDescription();

hamcrest-core/src/main/java/org/hamcrest/BaseDescription.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package org.hamcrest;
22

3-
import static java.lang.String.valueOf;
3+
import org.hamcrest.internal.ArrayIterator;
4+
import org.hamcrest.internal.SelfDescribingValueIterator;
45

56
import java.util.Arrays;
67
import java.util.Iterator;
78

8-
import org.hamcrest.internal.ArrayIterator;
9-
import org.hamcrest.internal.SelfDescribingValueIterator;
9+
import static java.lang.String.valueOf;
1010

1111
/**
1212
* A {@link Description} that is stored as a string.

hamcrest-core/src/main/java/org/hamcrest/core/AllOf.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.hamcrest.Description;
44
import org.hamcrest.DiagnosingMatcher;
5-
import org.hamcrest.Factory;
65
import org.hamcrest.Matcher;
76

87
import java.util.ArrayList;
@@ -43,7 +42,6 @@ public void describeTo(Description description) {
4342
* For example:
4443
* <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
4544
*/
46-
@Factory
4745
public static <T> Matcher<T> allOf(Iterable<Matcher<? super T>> matchers) {
4846
return new AllOf<T>(matchers);
4947
}
@@ -53,7 +51,6 @@ public static <T> Matcher<T> allOf(Iterable<Matcher<? super T>> matchers) {
5351
* For example:
5452
* <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
5553
*/
56-
@Factory
5754
public static <T> Matcher<T> allOf(Matcher<? super T>... matchers) {
5855
return allOf(Arrays.asList(matchers));
5956
}
@@ -63,7 +60,6 @@ public static <T> Matcher<T> allOf(Matcher<? super T>... matchers) {
6360
* For example:
6461
* <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
6562
*/
66-
@Factory
6763
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second) {
6864
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(2);
6965
matchers.add(first);
@@ -76,7 +72,6 @@ public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T>
7672
* For example:
7773
* <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
7874
*/
79-
@Factory
8075
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third) {
8176
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(3);
8277
matchers.add(first);
@@ -90,7 +85,6 @@ public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T>
9085
* For example:
9186
* <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
9287
*/
93-
@Factory
9488
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth) {
9589
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(4);
9690
matchers.add(first);
@@ -105,7 +99,6 @@ public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T>
10599
* For example:
106100
* <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
107101
*/
108-
@Factory
109102
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth) {
110103
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(5);
111104
matchers.add(first);
@@ -121,7 +114,6 @@ public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T>
121114
* For example:
122115
* <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
123116
*/
124-
@Factory
125117
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth) {
126118
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(6);
127119
matchers.add(first);

hamcrest-core/src/main/java/org/hamcrest/core/AnyOf.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package org.hamcrest.core;
22

3+
import org.hamcrest.Description;
4+
import org.hamcrest.Matcher;
5+
36
import java.util.ArrayList;
47
import java.util.Arrays;
58
import java.util.List;
69

7-
import org.hamcrest.Description;
8-
import org.hamcrest.Factory;
9-
import org.hamcrest.Matcher;
10-
1110
/**
1211
* Calculates the logical disjunction of multiple matchers. Evaluation is shortcut, so
1312
* subsequent matchers are not called if an earlier matcher returns <code>true</code>.
@@ -33,7 +32,6 @@ public void describeTo(Description description) {
3332
* For example:
3433
* <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>
3534
*/
36-
@Factory
3735
public static <T> AnyOf<T> anyOf(Iterable<Matcher<? super T>> matchers) {
3836
return new AnyOf<T>(matchers);
3937
}
@@ -43,7 +41,6 @@ public static <T> AnyOf<T> anyOf(Iterable<Matcher<? super T>> matchers) {
4341
* For example:
4442
* <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>
4543
*/
46-
@Factory
4744
public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers) {
4845
return anyOf(Arrays.asList(matchers));
4946
}
@@ -53,7 +50,6 @@ public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers) {
5350
* For example:
5451
* <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>
5552
*/
56-
@Factory
5753
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second) {
5854
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
5955
matchers.add(first);
@@ -66,7 +62,6 @@ public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second) {
6662
* For example:
6763
* <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>
6864
*/
69-
@Factory
7065
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third) {
7166
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
7267
matchers.add(first);
@@ -80,7 +75,6 @@ public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Ma
8075
* For example:
8176
* <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>
8277
*/
83-
@Factory
8478
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth) {
8579
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
8680
matchers.add(first);
@@ -95,7 +89,6 @@ public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Ma
9589
* For example:
9690
* <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>
9791
*/
98-
@Factory
9992
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth) {
10093
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
10194
matchers.add(first);
@@ -111,7 +104,6 @@ public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Ma
111104
* For example:
112105
* <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>
113106
*/
114-
@Factory
115107
public static <T> AnyOf<T> anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth) {
116108
List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>();
117109
matchers.add(first);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.hamcrest.core;
22

3-
import org.hamcrest.*;
3+
import org.hamcrest.Description;
4+
import org.hamcrest.Matcher;
5+
import org.hamcrest.TypeSafeDiagnosingMatcher;
46

57
import java.util.ArrayList;
68

@@ -45,7 +47,6 @@ private ArrayList<Matcher<? super T>> templatedListWith(Matcher<? super T> other
4547
* For example:
4648
* <pre>assertThat("fab", both(containsString("a")).and(containsString("b")))</pre>
4749
*/
48-
@Factory
4950
public static <LHS> CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher) {
5051
return new CombinableBothMatcher<LHS>(matcher);
5152
}
@@ -65,7 +66,6 @@ public CombinableMatcher<X> and(Matcher<? super X> other) {
6566
* For example:
6667
* <pre>assertThat("fan", either(containsString("a")).or(containsString("b")))</pre>
6768
*/
68-
@Factory
6969
public static <LHS> CombinableEitherMatcher<LHS> either(Matcher<? super LHS> matcher) {
7070
return new CombinableEitherMatcher<LHS>(matcher);
7171
}

hamcrest-core/src/main/java/org/hamcrest/core/DescribedAs.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import org.hamcrest.BaseMatcher;
66
import org.hamcrest.Description;
7-
import org.hamcrest.Factory;
87
import org.hamcrest.Matcher;
98

109
import java.util.regex.Pattern;
@@ -66,7 +65,6 @@ public void describeMismatch(Object item, Description description) {
6665
* @param values
6766
* optional values to insert into the tokenised description
6867
*/
69-
@Factory
7068
public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) {
7169
return new DescribedAs<T>(description, matcher, values);
7270
}

hamcrest-core/src/main/java/org/hamcrest/core/Every.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.hamcrest.core;
22

33
import org.hamcrest.Description;
4-
import org.hamcrest.Factory;
54
import org.hamcrest.Matcher;
65
import org.hamcrest.TypeSafeDiagnosingMatcher;
76

@@ -39,7 +38,6 @@ public void describeTo(Description description) {
3938
* @param itemMatcher
4039
* the matcher to apply to every item provided by the examined {@link Iterable}
4140
*/
42-
@Factory
4341
public static <U> Matcher<Iterable<? extends U>> everyItem(final Matcher<U> itemMatcher) {
4442
return new Every<U>(itemMatcher);
4543
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.hamcrest.BaseMatcher;
44
import org.hamcrest.Description;
5-
import org.hamcrest.Factory;
65
import org.hamcrest.Matcher;
76

87
import static org.hamcrest.core.IsEqual.equalTo;
@@ -46,7 +45,6 @@ public void describeMismatch(Object item, Description mismatchDescription) {
4645
* <pre>assertThat(cheese, equalTo(smelly))</pre>
4746
*
4847
*/
49-
@Factory
5048
public static <T> Matcher<T> is(Matcher<T> matcher) {
5149
return new Is<T>(matcher);
5250
}
@@ -59,7 +57,6 @@ public static <T> Matcher<T> is(Matcher<T> matcher) {
5957
* <pre>assertThat(cheese, is(equalTo(smelly)))</pre>
6058
*
6159
*/
62-
@Factory
6360
public static <T> Matcher<T> is(T value) {
6461
return is(equalTo(value));
6562
}
@@ -72,7 +69,6 @@ public static <T> Matcher<T> is(T value) {
7269
* <pre>assertThat(cheese, is(instanceOf(Cheddar.class)))</pre>
7370
*
7471
*/
75-
@Factory
7672
public static <T> Matcher<T> isA(Class<T> type) {
7773
final Matcher<T> typeMatcher = instanceOf(type);
7874
return is(typeMatcher);

hamcrest-core/src/main/java/org/hamcrest/core/IsAnything.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
*/
33
package org.hamcrest.core;
44

5+
import org.hamcrest.BaseMatcher;
56
import org.hamcrest.Description;
67
import org.hamcrest.Matcher;
7-
import org.hamcrest.Factory;
8-
import org.hamcrest.BaseMatcher;
98

109

1110
/**
@@ -36,7 +35,6 @@ public void describeTo(Description description) {
3635
/**
3736
* Creates a matcher that always matches, regardless of the examined object.
3837
*/
39-
@Factory
4038
public static Matcher<Object> anything() {
4139
return new IsAnything<Object>();
4240
}
@@ -48,7 +46,6 @@ public static Matcher<Object> anything() {
4846
* @param description
4947
* a meaningful {@link String} used when describing itself
5048
*/
51-
@Factory
5249
public static Matcher<Object> anything(String description) {
5350
return new IsAnything<Object>(description);
5451
}

hamcrest-core/src/main/java/org/hamcrest/core/IsCollectionContaining.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.hamcrest.core;
22

33
import org.hamcrest.Description;
4-
import org.hamcrest.Factory;
54
import org.hamcrest.Matcher;
65
import org.hamcrest.TypeSafeDiagnosingMatcher;
76

@@ -67,7 +66,6 @@ public void describeTo(Description description) {
6766
* @param itemMatcher
6867
* the matcher to apply to items provided by the examined {@link Iterable}
6968
*/
70-
@Factory
7169
public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher) {
7270
return new IsCollectionContaining<T>(itemMatcher);
7371
}
@@ -83,7 +81,6 @@ public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> itemMa
8381
* @param item
8482
* the item to compare against the items provided by the examined {@link Iterable}
8583
*/
86-
@Factory
8784
public static <T> Matcher<Iterable<? super T>> hasItem(T item) {
8885
// Doesn't forward to hasItem() method so compiler can sort out generics.
8986
return new IsCollectionContaining<T>(equalTo(item));
@@ -100,7 +97,6 @@ public static <T> Matcher<Iterable<? super T>> hasItem(T item) {
10097
* @param itemMatchers
10198
* the matchers to apply to items provided by the examined {@link Iterable}
10299
*/
103-
@Factory
104100
public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... itemMatchers) {
105101
List<Matcher<? super Iterable<T>>> all = new ArrayList<Matcher<? super Iterable<T>>>(itemMatchers.length);
106102

@@ -123,7 +119,6 @@ public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... itemMatche
123119
* @param items
124120
* the items to compare against the items provided by the examined {@link Iterable}
125121
*/
126-
@Factory
127122
public static <T> Matcher<Iterable<T>> hasItems(T... items) {
128123
List<Matcher<? super Iterable<T>>> all = new ArrayList<Matcher<? super Iterable<T>>>(items.length);
129124
for (T item : items) {

hamcrest-core/src/main/java/org/hamcrest/core/IsEqual.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import org.hamcrest.BaseMatcher;
66
import org.hamcrest.Description;
7-
import org.hamcrest.Factory;
87
import org.hamcrest.Matcher;
98

109
import java.lang.reflect.Array;
@@ -86,7 +85,6 @@ private static boolean isArray(Object o) {
8685
* </pre>
8786
*
8887
*/
89-
@Factory
9088
public static <T> Matcher<T> equalTo(T operand) {
9189
return new IsEqual<T>(operand);
9290
}
@@ -95,7 +93,6 @@ public static <T> Matcher<T> equalTo(T operand) {
9593
* Creates an {@link org.hamcrest.core.IsEqual} matcher that does not enforce the values being
9694
* compared to be of the same static type.
9795
*/
98-
@Factory
9996
public static Matcher<Object> equalToObject(Object operand) {
10097
return new IsEqual<Object>(operand);
10198
}

hamcrest-core/src/main/java/org/hamcrest/core/IsInstanceOf.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import org.hamcrest.Description;
66
import org.hamcrest.DiagnosingMatcher;
7-
import org.hamcrest.Factory;
87
import org.hamcrest.Matcher;
98

109

@@ -70,7 +69,6 @@ public void describeTo(Description description) {
7069
*
7170
*/
7271
@SuppressWarnings("unchecked")
73-
@Factory
7472
public static <T> Matcher<T> instanceOf(Class<?> type) {
7573
return (Matcher<T>) new IsInstanceOf(type);
7674
}
@@ -88,7 +86,6 @@ public static <T> Matcher<T> instanceOf(Class<?> type) {
8886
*
8987
*/
9088
@SuppressWarnings("unchecked")
91-
@Factory
9289
public static <T> Matcher<T> any(Class<T> type) {
9390
return (Matcher<T>) new IsInstanceOf(type);
9491
}

0 commit comments

Comments
 (0)