/** * Constructs an annotation object. * * @param cl class loader for obtaining annotation types. * @param clazz the annotation type. * @param cp class pool for containing an annotation * type (or null). * @param anon the annotation. * @return the annotation */ public static Object make(ClassLoader cl, Class clazz, ClassPool cp, Annotation anon) { AnnotationImpl handler = new AnnotationImpl(anon, cp, cl); return Proxy.newProxyInstance(cl, new Class[] { clazz }, handler); }
getAnnotationType(); value = mv.getValue(classLoader, pool, methods[i]); if (value == null) value = getDefault(name, methods[i]); valueHashCode = arrayHashCode(value); else valueHashCode = value.hashCode();
if ("equals".equals(name)) { Object obj = args[0]; return new Boolean(checkEquals(obj)); return new Integer(hashCode()); return getAnnotationType(); return getDefault(name, method); else return mv.getValue(classLoader, pool, method);
if (getAnnotationType().equals(otherAnnotationType) == false) return false; value = mv.getValue(classLoader, pool, methods[i]); if (value == null) value = getDefault(name, methods[i]); otherValue = methods[i].invoke(obj, (Object[])null);
Object getValue(ClassLoader cl, ClassPool cp, Method m) throws ClassNotFoundException { return AnnotationImpl.make(cl, getType(cl), cp, value); }
private String tryExtractFromParamTypeAnnotation(Object[] annotations) { for (Object o : annotations) { AnnotationImpl annotation = (AnnotationImpl) Proxy.getInvocationHandler(o); if (annotation.getTypeName().equals(ParamType.class.getName())) { String value = ((StringMemberValue) annotation.getAnnotation().getMemberValue("value")).getValue(); return value.equals("") ? null : value; } } return null; } }
/** * Get an annotation * * @param method the method * @param annotationClass the annotation class * @return the annotation */ public static Annotation getAnnotation(Method method, Class annotationClass) { if (annotationClass == null) throw new NullPointerException("Null annotation"); String searchName = annotationClass.getName(); for (Object annotation : getAnnotationsInternal(method)) { AnnotationImpl impl = (AnnotationImpl) Proxy.getInvocationHandler(annotation); if (searchName.equals(impl.getTypeName())) return (Annotation)annotation; } return null; }
public static Annotation unwrapAnnotation(Object annotation) { AnnotationImpl annotationImpl = (AnnotationImpl) Proxy.getInvocationHandler(annotation); return annotationImpl.getAnnotation(); }
if (getAnnotationType().equals(otherAnnotationType) == false) return false; value = mv.getValue(classLoader, pool, methods[i]); if (value == null) value = getDefault(name, methods[i]); otherValue = methods[i].invoke(obj);
@Override Object getValue(ClassLoader cl, ClassPool cp, Method m) throws ClassNotFoundException { return AnnotationImpl.make(cl, getType(cl), cp, value); }
private String tryExtractFromParamTypeAnnotation(Object[] annotations) { for (Object o : annotations) { AnnotationImpl annotation = (AnnotationImpl) Proxy.getInvocationHandler(o); if (annotation.getTypeName().equals(ParamType.class.getName())) { String value = ((StringMemberValue) annotation.getAnnotation().getMemberValue("value")).getValue(); return value.equals("") ? null : value; } } return null; } }
/** * Get an annotation * * @param constructor the constructor * @param annotationClass the annotation class * @return the annotation */ public static Annotation getAnnotation(Constructor constructor, Class annotationClass) { if (annotationClass == null) throw new NullPointerException("Null annotation"); String searchName = annotationClass.getName(); for (Object annotation : getAnnotationsInternal(constructor)) { AnnotationImpl impl = (AnnotationImpl) Proxy.getInvocationHandler(annotation); if (searchName.equals(impl.getTypeName())) return (Annotation)annotation; } return null; }
@SuppressWarnings("unchecked") public static <T extends Annotation> javassist.bytecode.annotation.Annotation getAnnotation( CtClass ctClass, Class<T> annotationClass) throws ClassNotFoundException { T proxiedAnnot = (T) ctClass.getAnnotation(annotationClass); if (proxiedAnnot == null) { return null; } else if (!Proxy.isProxyClass(proxiedAnnot.getClass())) { return null; } AnnotationImpl impl = (AnnotationImpl) Proxy.getInvocationHandler(proxiedAnnot); return impl.getAnnotation(); }
/** * Executes a method invocation on a proxy instance. * The implementations of <code>toString()</code>, <code>equals()</code>, * and <code>hashCode()</code> are directly supplied by the * <code>AnnotationImpl</code>. The <code>annotationType()</code> method * is also available on the proxy instance. */ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String name = method.getName(); if (Object.class == method.getDeclaringClass()) { if ("equals".equals(name)) { Object obj = args[0]; return Boolean.valueOf(checkEquals(obj)); } else if ("toString".equals(name)) return annotation.toString(); else if ("hashCode".equals(name)) return Integer.valueOf(hashCode()); } else if ("annotationType".equals(name) && method.getParameterTypes().length == 0) return getAnnotationType(); MemberValue mv = annotation.getMemberValue(name); if (mv == null) return getDefault(name, method); return mv.getValue(classLoader, pool, method); }
getAnnotationType(); value = mv.getValue(classLoader, pool, methods[i]); if (value == null) value = getDefault(name, methods[i]); valueHashCode = arrayHashCode(value); else valueHashCode = value.hashCode();
if (getAnnotationType().equals(otherAnnotationType) == false) return false; value = mv.getValue(classLoader, pool, methods[i]); if (value == null) value = getDefault(name, methods[i]); otherValue = methods[i].invoke(obj, (Object[])null);
/** * Constructs an annotation-type object representing this annotation. * For example, if this annotation represents <code>@Author</code>, * this method returns an <code>Author</code> object. * * @param cl class loader for loading an annotation type. * @param cp class pool for obtaining class files. * @return the annotation * @throws ClassNotFoundException if the class cannot found. * @throws NoSuchClassError if the class linkage fails. */ public Object toAnnotationType(ClassLoader cl, ClassPool cp) throws ClassNotFoundException, NoSuchClassError { return AnnotationImpl.make(cl, MemberValue.loadClass(cl, getTypeName()), cp, this); }
/** * Constructs an annotation object. * * @param cl class loader for obtaining annotation types. * @param clazz the annotation type. * @param cp class pool for containing an annotation * type (or null). * @param anon the annotation. * @return the annotation */ public static Object make(ClassLoader cl, Class<?> clazz, ClassPool cp, Annotation anon) throws IllegalArgumentException { AnnotationImpl handler = new AnnotationImpl(anon, cp, cl); return Proxy.newProxyInstance(cl, new Class[] { clazz }, handler); }
private String getRemoveServiceRelativePath(Class<?> clazz) { CtClass ctClass = GwtClassPool.getCtClass((clazz)); Object[] annotations = ctClass.getAvailableAnnotations(); for (Object o : annotations) { if (Proxy.isProxyClass(o.getClass())) { AnnotationImpl annotation = (AnnotationImpl) Proxy.getInvocationHandler(o); if (annotation.getTypeName().equals(RemoteServiceRelativePath.class.getName())) { return ((StringMemberValue) annotation.getAnnotation().getMemberValue("value")).getValue(); } } } throw new GwtTestRpcException("Cannot find the '@" + RemoteServiceRelativePath.class.getSimpleName() + "' annotation on RemoteService interface '" + clazz.getName() + "'"); }
/** * Get an annotation * * @param clazz the class * @param annotationClass the annotation class * @return the annotation */ public static Annotation getAnnotation(Class clazz, Class annotationClass) { if (annotationClass == null) throw new NullPointerException("Null annotation"); String searchName = annotationClass.getName(); for (Object annotation : getAnnotationsInternal(clazz)) { AnnotationImpl impl = (AnnotationImpl) Proxy.getInvocationHandler(annotation); if (searchName.equals(impl.getTypeName())) return (Annotation)annotation; } return null; }