Skip to content

Commit 6961b2e

Browse files
Removed dependency on sun.reflect package in GenericsResolverTest
1 parent 92f11bb commit 6961b2e

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

typescript-generator-core/src/test/java/cz/habarta/typescript/generator/GenericsResolverTest.java

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33

44
import cz.habarta.typescript.generator.util.GenericsResolver;
55
import cz.habarta.typescript.generator.util.Utils;
6+
import java.lang.annotation.Annotation;
7+
import java.lang.reflect.AnnotatedType;
68
import java.lang.reflect.GenericDeclaration;
79
import java.lang.reflect.Type;
810
import java.lang.reflect.TypeVariable;
911
import java.util.Arrays;
1012
import java.util.List;
1113
import java.util.Map;
14+
import java.util.Objects;
1215
import org.junit.Assert;
1316
import org.junit.Test;
14-
import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
1517

1618

1719
public class GenericsResolverTest {
@@ -105,8 +107,79 @@ static class R12<U, V> extends R1<V, U> {
105107
static class R123<A, B, C> extends R12<C, List<B>> {
106108
}
107109

110+
// this returns incomplete implementation just for tests
108111
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+
};
110183
}
111184

112185
}

0 commit comments

Comments
 (0)