Here are the examples of the java api class java.lang.reflect.AnnotatedType taken from open source projects.
1. RedefineAnnotations#verifyArrayFieldTypeAnnotations()
Project: openjdk
File: RedefineAnnotations.java
File: RedefineAnnotations.java
private void verifyArrayFieldTypeAnnotations(Class c) throws NoSuchFieldException, NoSuchMethodException { Annotation anno; AnnotatedType at; at = c.getDeclaredField("typeAnnotatedArray").getAnnotatedType(); anno = at.getAnnotations()[0]; verifyTestAnn(arrayTA[0], anno, "array1"); arrayTA[0] = anno; for (int i = 1; i <= 3; i++) { at = ((AnnotatedArrayType) at).getAnnotatedGenericComponentType(); anno = at.getAnnotations()[0]; verifyTestAnn(arrayTA[i], anno, "array" + (i + 1)); arrayTA[i] = anno; } }
2. TypeAnnotationAwareMetaDataProvider#findTypeAnnotationConstraintsForMember()
Project: hibernate-validator
File: TypeAnnotationAwareMetaDataProvider.java
File: TypeAnnotationAwareMetaDataProvider.java
@Override protected Set<MetaConstraint<?>> findTypeAnnotationConstraintsForMember(Member member) { AnnotatedType annotatedType = null; if (member instanceof Field) { annotatedType = ((Field) member).getAnnotatedType(); } if (member instanceof Method) { annotatedType = ((Method) member).getAnnotatedReturnType(); } return findTypeArgumentsConstraints(member, annotatedType, ((AccessibleObject) member).isAnnotationPresent(Valid.class)); }
3. RedefineAnnotations#verifyMapFieldTypeAnnotations()
Project: openjdk
File: RedefineAnnotations.java
File: RedefineAnnotations.java
private void verifyMapFieldTypeAnnotations(Class c) throws NoSuchFieldException, NoSuchMethodException { Annotation anno; AnnotatedType atBase; AnnotatedType atParameter; atBase = c.getDeclaredField("typeAnnotatedMap").getAnnotatedType(); anno = atBase.getAnnotations()[0]; verifyTestAnn(mapTA[0], anno, "map1"); mapTA[0] = anno; atParameter = ((AnnotatedParameterizedType) atBase).getAnnotatedActualTypeArguments()[0]; anno = ((AnnotatedWildcardType) atParameter).getAnnotations()[0]; verifyTestAnn(mapTA[1], anno, "map2"); mapTA[1] = anno; anno = ((AnnotatedWildcardType) atParameter).getAnnotatedUpperBounds()[0].getAnnotations()[0]; verifyTestAnn(mapTA[2], anno, "map3"); mapTA[2] = anno; atParameter = ((AnnotatedParameterizedType) atBase).getAnnotatedActualTypeArguments()[1]; anno = ((AnnotatedParameterizedType) atParameter).getAnnotations()[0]; verifyTestAnn(mapTA[3], anno, "map4"); mapTA[3] = anno; anno = ((AnnotatedParameterizedType) atParameter).getAnnotatedActualTypeArguments()[0].getAnnotations()[0]; verifyTestAnn(mapTA[4], anno, "map5"); mapTA[4] = anno; }
4. TestBed#main()
Project: titan
File: TestBed.java
File: TestBed.java
/** * @param args * @throws java.io.IOException */ public static void main(String[] args) throws Exception { Method method = TestBed.class.getMethod("getInt", int.class, int.class); AnnotatedType rt = method.getAnnotatedReturnType(); System.out.println(rt.getType()); System.out.println(rt.getAnnotations().length); System.out.println(method.getAnnotations().length); for (int i = 0; i < method.getAnnotations().length; i++) { System.out.println(method.getAnnotations()[i]); } // String[] s = {"a","b","c","d","e","f","g","h","i","x","u"}; // int len = s.length; // Random random = new Random(); // // Context c = new Context(new ObserverManager(),Observer.NO_OP); // //Warmup // for (int i = 0; i < 1000000000; i++) { // c.observe(s[1],s[2]); // } // long before = System.nanoTime(); // for (int i = 0; i < 1000000000; i++) { // c.observe(s[1],s[2]); // } // long total = System.nanoTime()-before; // System.out.println("Total time: " + total/1000000); System.exit(0); final ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(1, new RejectedExecutionHandler() { @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { r.run(); } }); ScheduledFuture future = exe.scheduleWithFixedDelay(new Runnable() { AtomicInteger atomicInt = new AtomicInteger(0); @Override public void run() { try { for (int i = 0; i < 10; i++) { exe.submit(new Runnable() { private final int number = atomicInt.incrementAndGet(); @Override public void run() { try { Thread.sleep(150); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(number); } }); System.out.println("Submitted: " + i); // doSomethingExpensive(20); } } catch (Exception e) { e.printStackTrace(); } } }, 0, 1, TimeUnit.SECONDS); Thread.sleep(10000); // future.get(1,TimeUnit.SECONDS); System.out.println("Cancel: " + future.cancel(false)); System.out.println("Done: " + future.isDone()); exe.shutdown(); // Thread.sleep(2000); System.out.println("Terminate: " + exe.awaitTermination(5, TimeUnit.SECONDS)); System.out.println("DONE"); NonBlockingHashMapLong<String> id1 = new NonBlockingHashMapLong<String>(128); ConcurrentHashMap<Long, String> id2 = new ConcurrentHashMap<Long, String>(128, 0.75f, 2); }
5. RedefineAnnotations#verifyInnerFieldTypeAnnotations()
Project: openjdk
File: RedefineAnnotations.java
File: RedefineAnnotations.java
private void verifyInnerFieldTypeAnnotations(Class c) throws NoSuchFieldException, NoSuchMethodException { AnnotatedType at = c.getDeclaredField("typeAnnotatedInner").getAnnotatedType(); Annotation anno = at.getAnnotations()[0]; verifyTestAnn(innerTA, anno, "inner"); innerTA = anno; }
6. ValuesTest#java8TypeAnnotation()
Project: immutables
File: ValuesTest.java
File: ValuesTest.java
@Test public void java8TypeAnnotation() throws Exception { Method method = ImmutableHasTypeAnnotation.class.getMethod("str"); AnnotatedType returnType = method.getAnnotatedReturnType(); check(returnType.getAnnotation(TypeA.class)).notNull(); check(returnType.getAnnotation(TypeB.class)).notNull(); }
7. TypeAnnotationAwareMetaDataProvider#getTypeParameter()
Project: hibernate-validator
File: TypeAnnotationAwareMetaDataProvider.java
File: TypeAnnotationAwareMetaDataProvider.java
/** * Returns the type argument of a parameterized type. If the type is a {@code Map}, the method returns the value * type argument. If the type has more than one type argument and is not a Map, the method returns an empty {@code * Optional}. */ private Optional<AnnotatedType> getTypeParameter(AnnotatedType annotatedType) { if (annotatedType == null) { return Optional.empty(); } if (!TypeHelper.isAssignable(AnnotatedParameterizedType.class, annotatedType.getClass())) { return Optional.empty(); } AnnotatedType[] annotatedArguments = ((AnnotatedParameterizedType) annotatedType).getAnnotatedActualTypeArguments(); // One type argument, return it if (annotatedArguments.length == 1) { return Optional.of(annotatedArguments[0]); } // More than one type argument if (annotatedArguments.length > 1) { // If it is a Map, return the value type argument if (ReflectionHelper.isMap(annotatedType.getType())) { return Optional.of(annotatedArguments[1]); } // If it is not a Map, log a message and ignore log.parameterizedTypeWithMoreThanOneTypeArgumentIsNotSupported(annotatedType.getType().getTypeName()); } return Optional.empty(); }