@@ -86,26 +86,18 @@ private boolean outsideArrayBounds() {
8686 * <p>To use another set of rules, override this method.
8787 */
8888 protected boolean isFactoryMethod (Method javaMethod ) {
89- // We dynamically load these classes, to avoid a compile time
90- // dependency on org.hamcrest.{Factory,Matcher}. This gets around
91- // a circular bootstrap issue (because generator is required to
92- // compile core).
9389 return isStatic (javaMethod .getModifiers ())
9490 && isPublic (javaMethod .getModifiers ())
9591 && hasFactoryAnnotation (javaMethod )
96- && matcherClass ().isAssignableFrom (javaMethod .getReturnType ());
97- }
98-
99- private Class <?> matcherClass () {
100- try {
101- return classLoader .loadClass ("org.hamcrest.Matcher" );
102- } catch (ClassNotFoundException e ) {
103- throw new RuntimeException ("Cannot load hamcrest core" , e );
104- }
92+ && !Void .TYPE .equals (javaMethod .getReturnType ());
10593 }
10694
10795 @ SuppressWarnings ("unchecked" )
10896 private boolean hasFactoryAnnotation (Method javaMethod ) {
97+ // We dynamically load the Factory class, to avoid a compile time
98+ // dependency on org.hamcrest.Factory. This gets around
99+ // a circular bootstrap issue (because generator is required to
100+ // compile core).
109101 try {
110102 final Class <?> factoryClass = classLoader .loadClass ("org.hamcrest.Factory" );
111103 if (!Annotation .class .isAssignableFrom (factoryClass )) {
@@ -119,9 +111,9 @@ private boolean hasFactoryAnnotation(Method javaMethod) {
119111
120112 private static FactoryMethod buildFactoryMethod (Method javaMethod ) {
121113 FactoryMethod result = new FactoryMethod (
122- javaMethod .getDeclaringClass (). getName ( ),
114+ classToString ( javaMethod .getDeclaringClass ()),
123115 javaMethod .getName (),
124- javaMethod .getReturnType (). getName ( ));
116+ classToString ( javaMethod .getReturnType ()));
125117
126118 for (TypeVariable <Method > typeVariable : javaMethod .getTypeParameters ()) {
127119 boolean hasBound = false ;
@@ -175,7 +167,8 @@ private static String typeToString(Type type) {
175167 }
176168
177169 private static String classToString (Class <?> cls ) {
178- return cls .isArray () ? cls .getComponentType ().getName () + "[]" : cls .getName ();
170+ final String name = cls .isArray () ? cls .getComponentType ().getName () + "[]" : cls .getName ();
171+ return name .replace ('$' , '.' );
179172 }
180173
181- }
174+ }
0 commit comments