/** * Obtains the name of the annotation type. * * @return the type name */ public String getTypeName() { return annotation.getTypeName(); }
/** * Obtains the name of the annotation type. * * @return the type name */ public String getTypeName() { return annotation.getTypeName(); }
private List<String> getAnnotationNames(final Annotation[] annotations) { List<String> result = Lists.newArrayList(); for (Annotation annotation : annotations) { result.add(annotation.getTypeName()); } return result; }
private List<String> getAnnotationNames(final Annotation[] annotations) { List<String> result = Lists.newArrayList(); for (Annotation annotation : annotations) { result.add(annotation.getTypeName()); } return result; }
@Override public int hashCode() { return getTypeName().hashCode() + (members == null ? 0 : members.hashCode()); }
Class getType(ClassLoader cl) throws ClassNotFoundException { if (value == null) throw new ClassNotFoundException("no type specified"); else return loadClass(cl, value.getTypeName()); }
protected boolean containsTypeLevelPersistenceAnnotation(Annotation[] annotations) { for (Annotation annotation : annotations) { if (annotation.getTypeName().equals(Entity.class.getName()) || annotation.getTypeName().equals(Embeddable.class.getName()) || annotation.getTypeName().equals(MappedSuperclass.class.getName())) { return true; } } return false; } }
/** * Returns true if the given object represents the same annotation * as this object. The equality test checks the member values. */ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj instanceof Annotation == false) return false; Annotation other = (Annotation) obj; if (getTypeName().equals(other.getTypeName()) == false) return false; LinkedHashMap otherMembers = other.members; if (members == otherMembers) return true; else if (members == null) return otherMembers == null; else if (otherMembers == null) return false; else return members.equals(otherMembers); } }
/** * Parses the annotations and returns a data structure representing * the annotation with the specified type. See also * <code>getAnnotations()</code> as to the returned data structure. * * @param type the annotation type. * @return null if the specified annotation type is not included. * @see #getAnnotations() */ public Annotation getAnnotation(String type) { Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) return annotations[i]; } return null; }
/** * Returns a string representation of the annotation. */ public String toString() { StringBuffer buf = new StringBuffer("@"); buf.append(getTypeName()); if (members != null) { buf.append("("); Iterator mit = members.keySet().iterator(); while (mit.hasNext()) { String name = (String)mit.next(); buf.append(name).append("=").append(getMemberValue(name)); if (mit.hasNext()) buf.append(", "); } buf.append(")"); } return buf.toString(); }
private List<String> getAnnotationNames(final AnnotationsAttribute... annotationsAttributes) { List<String> result = Lists.newArrayList(); if (annotationsAttributes != null) { for (AnnotationsAttribute annotationsAttribute : annotationsAttributes) { if (annotationsAttribute != null) { for (Annotation annotation : annotationsAttribute.getAnnotations()) { result.add(annotation.getTypeName()); } } } } return result; }
@Override Class<?> getType(ClassLoader cl) throws ClassNotFoundException { if (value == null) throw new ClassNotFoundException("no type specified"); return loadClass(cl, value.getTypeName()); }
private List<String> getAnnotationNames(final AnnotationsAttribute... annotationsAttributes) { List<String> result = Lists.newArrayList(); if (annotationsAttributes != null) { for (AnnotationsAttribute annotationsAttribute : annotationsAttributes) { if (annotationsAttribute != null) { for (Annotation annotation : annotationsAttribute.getAnnotations()) { result.add(annotation.getTypeName()); } } } } return result; }
/** * Adds an annotation. If there is an annotation with the same type, * it is removed before the new annotation is added. * * @param annotation the added annotation. */ public void addAnnotation(Annotation annotation) { String type = annotation.getTypeName(); Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) { annotations[i] = annotation; setAnnotations(annotations); return; } } Annotation[] newlist = new Annotation[annotations.length + 1]; System.arraycopy(annotations, 0, newlist, 0, annotations.length); newlist[annotations.length] = annotation; setAnnotations(newlist); }
static boolean hasAnnotationType(String annotationTypeName, ClassPool cp, AnnotationsAttribute a1, AnnotationsAttribute a2) { Annotation[] anno1, anno2; if (a1 == null) anno1 = null; else anno1 = a1.getAnnotations(); if (a2 == null) anno2 = null; else anno2 = a2.getAnnotations(); if (anno1 != null) for (int i = 0; i < anno1.length; i++) if (anno1[i].getTypeName().equals(annotationTypeName)) return true; if (anno2 != null) for (int i = 0; i < anno2.length; i++) if (anno2[i].getTypeName().equals(annotationTypeName)) return true; return false; }
/** * Get the annotation type * * @return the annotation class * @throws NoClassDefFoundError when the class could not loaded */ private Class getAnnotationType() { if (annotationType == null) { String typeName = annotation.getTypeName(); try { annotationType = classLoader.loadClass(typeName); } catch (ClassNotFoundException e) { NoClassDefFoundError error = new NoClassDefFoundError("Error loading annotation class: " + typeName); error.setStackTrace(e.getStackTrace()); throw error; } } return annotationType; }
/** * Removes an annotation by type. * After removing an annotation, if {@link #numAnnotations()} returns 0, * this annotations attribute has to be removed. * * @param type of annotation to remove * @return whether an annotation with the given type has been removed * @since 3.21 */ public boolean removeAnnotation(String type) { Annotation[] annotations = getAnnotations(); for (int i = 0; i < annotations.length; i++) { if (annotations[i].getTypeName().equals(type)) { Annotation[] newlist = new Annotation[annotations.length - 1]; System.arraycopy(annotations, 0, newlist, 0, i); if (i < annotations.length - 1) { System.arraycopy(annotations, i + 1, newlist, i, annotations.length - i - 1); } setAnnotations(newlist); return true; } } return false; }
static Object getAnnotationType(Class clz, ClassPool cp, AnnotationsAttribute a1, AnnotationsAttribute a2) throws ClassNotFoundException { Annotation[] anno1, anno2; if (a1 == null) anno1 = null; else anno1 = a1.getAnnotations(); if (a2 == null) anno2 = null; else anno2 = a2.getAnnotations(); String typeName = clz.getName(); if (anno1 != null) for (int i = 0; i < anno1.length; i++) if (anno1[i].getTypeName().equals(typeName)) return toAnnoType(anno1[i], cp); if (anno2 != null) for (int i = 0; i < anno2.length; i++) if (anno2[i].getTypeName().equals(typeName)) return toAnnoType(anno2[i], cp); return 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); }
private static Object toAnnoType(Annotation anno, ClassPool cp) throws ClassNotFoundException { try { ClassLoader cl = cp.getClassLoader(); return anno.toAnnotationType(cl, cp); } catch (ClassNotFoundException e) { ClassLoader cl2 = cp.getClass().getClassLoader(); try { return anno.toAnnotationType(cl2, cp); } catch (ClassNotFoundException e2){ try { Class clazz = cp.get(anno.getTypeName()).toClass(); return javassist.bytecode.annotation.AnnotationImpl.make( clazz.getClassLoader(), clazz, cp, anno); } catch (Throwable e3) { throw new ClassNotFoundException(anno.getTypeName()); } } } }