|
3 | 3 |
|
4 | 4 | import cz.habarta.typescript.generator.util.GenericsResolver; |
5 | 5 | import cz.habarta.typescript.generator.util.Utils; |
| 6 | +import java.lang.annotation.Annotation; |
| 7 | +import java.lang.reflect.AnnotatedType; |
6 | 8 | import java.lang.reflect.GenericDeclaration; |
7 | 9 | import java.lang.reflect.Type; |
8 | 10 | import java.lang.reflect.TypeVariable; |
9 | 11 | import java.util.Arrays; |
10 | 12 | import java.util.List; |
11 | 13 | import java.util.Map; |
| 14 | +import java.util.Objects; |
12 | 15 | import org.junit.Assert; |
13 | 16 | import org.junit.Test; |
14 | | -import sun.reflect.generics.reflectiveObjects.TypeVariableImpl; |
15 | 17 |
|
16 | 18 |
|
17 | 19 | public class GenericsResolverTest { |
@@ -105,8 +107,79 @@ static class R12<U, V> extends R1<V, U> { |
105 | 107 | static class R123<A, B, C> extends R12<C, List<B>> { |
106 | 108 | } |
107 | 109 |
|
| 110 | + // this returns incomplete implementation just for tests |
108 | 111 | private static <D extends GenericDeclaration> TypeVariable<D> createTypeVariable(D genericDeclaration, String name) { |
109 | | - return TypeVariableImpl.make(genericDeclaration, name, null, null); |
| 112 | + final Type[] bounds = new Type[0]; |
| 113 | + final AnnotatedType[] annotatedBounds = new AnnotatedType[0]; |
| 114 | + final Annotation[] annotations = new Annotation[0]; |
| 115 | + return new TypeVariable<D>() { |
| 116 | + @Override |
| 117 | + public Type[] getBounds() { |
| 118 | + return bounds; |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public D getGenericDeclaration() { |
| 123 | + return genericDeclaration; |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public String getName() { |
| 128 | + return name; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public AnnotatedType[] getAnnotatedBounds() { |
| 133 | + return annotatedBounds; |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + @SuppressWarnings("unchecked") |
| 138 | + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
| 139 | + for (Annotation annotation : getAnnotations()) { |
| 140 | + if (annotationClass.isInstance(annotation)) { |
| 141 | + return (T) annotation; |
| 142 | + } |
| 143 | + } |
| 144 | + return null; |
| 145 | + } |
| 146 | + |
| 147 | + @Override |
| 148 | + public Annotation[] getAnnotations() { |
| 149 | + return annotations; |
| 150 | + } |
| 151 | + |
| 152 | + @Override |
| 153 | + public Annotation[] getDeclaredAnnotations() { |
| 154 | + return getAnnotations(); |
| 155 | + } |
| 156 | + |
| 157 | + @Override |
| 158 | + public boolean equals(Object obj) { |
| 159 | + if (this == obj) { |
| 160 | + return true; |
| 161 | + } |
| 162 | + if (obj instanceof TypeVariable) { |
| 163 | + final TypeVariable<?> that = (TypeVariable<?>) obj; |
| 164 | + return |
| 165 | + Objects.equals(genericDeclaration, that.getGenericDeclaration()) && |
| 166 | + Objects.equals(name, that.getName()); |
| 167 | + } else { |
| 168 | + return false; |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + @Override |
| 173 | + public int hashCode() { |
| 174 | + return genericDeclaration.hashCode() ^ name.hashCode(); |
| 175 | + } |
| 176 | + |
| 177 | + @Override |
| 178 | + public String toString() { |
| 179 | + return getName(); |
| 180 | + } |
| 181 | + |
| 182 | + }; |
110 | 183 | } |
111 | 184 |
|
112 | 185 | } |
0 commit comments