/** * Create annotation. * * @param annotationExpr the annotation expression * @param cl the classloader to use * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(String annotationExpr, ClassLoader cl) throws Exception { return createAnnotation(getRootExpr(annotationExpr), null, cl); }
public static Object createAnnotation(ASTAnnotation node, Class annotation) throws Exception { return createAnnotation(node, annotation, null); }
if (contained instanceof ASTSingleMemberValue) Class type = getMemberType(annotation, "value"); AnnotationCreator creator = new AnnotationCreator(annotation, type); contained.jjtAccept(creator, "value"); map.put("value", creator.typeValue); Class type = getMemberType(annotation, member.getIdentifier().getValue()); AnnotationCreator creator = new AnnotationCreator(annotation, type); member.jjtAccept(creator, null); map.put(member.getIdentifier().getValue(), creator.typeValue);
public Object visit(ASTMemberValueArrayInitializer node, Object data) { if (!type.isArray()) throw new RuntimeException(annotation.getName() + "." + data + " is not an array"); Class<?> baseType = type.getComponentType(); int size = node.jjtGetNumChildren(); typeValue = Array.newInstance(baseType, size); for (int i = 0; i < size; i++) { AnnotationCreator creator = new AnnotationCreator(annotation, baseType, loader); node.jjtGetChild(i).jjtAccept(creator, null); Array.set(typeValue, i, creator.typeValue); } return null; }
private static ASTAnnotation getRootExpr(final String annotationExpr) throws Exception { return getRootExpr(annotationExpr, null, false); }
/** * Create annotation. * * @param node the ast annotation node * @param annotation the annotation class * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(ASTAnnotation node, Class<?> annotation) throws Exception { return createAnnotation(node, annotation, null); }
if (contained instanceof ASTSingleMemberValue) Class<?> type = getMemberType(annotation, "value"); AnnotationCreator creator = new AnnotationCreator(annotation, type, loader); contained.jjtAccept(creator, "value"); map.put("value", creator.typeValue); Class<?> type = getMemberType(annotation, member.getIdentifier().getValue()); AnnotationCreator creator = new AnnotationCreator(annotation, type, loader); member.jjtAccept(creator, null); map.put(member.getIdentifier().getValue(), creator.typeValue);
public Object visit(ASTMemberValueArrayInitializer node, Object data) { if (!type.isArray()) throw new RuntimeException(annotation.getName() + "." + data + " is not an array"); Class baseType = type.getComponentType(); int size = node.jjtGetNumChildren(); typeValue = Array.newInstance(baseType, size); for (int i = 0; i < size; i++) { AnnotationCreator creator = new AnnotationCreator(annotation, baseType); node.jjtGetChild(i).jjtAccept(creator, null); Array.set(typeValue, i, creator.typeValue); } return null; }
private static ASTAnnotation getRootExpr(final String annotationExpr, final Properties properties, final Boolean replace) throws Exception { try { return AccessController.doPrivileged(new PrivilegedExceptionAction<ASTAnnotation>() { public ASTAnnotation run() throws Exception { String expr; if (properties != null && properties.isEmpty() == false) expr = StringPropertyReplacer.replaceProperties(annotationExpr, properties); else if (replace != null && replace) expr = StringPropertyReplacer.replaceProperties(annotationExpr); else expr = annotationExpr; AnnotationParser parser = new AnnotationParser(new StringReader(expr)); ASTStart start = parser.Start(); return (ASTAnnotation)start.jjtGetChild(0); } }); } catch (PrivilegedActionException e) { throw new RuntimeException("Error getting root expression " + annotationExpr, e.getException()); } }
public static Object createAnnotation(final String annotationExpr, final Class annotation) throws Exception { return createAnnotation(getRootExpr(annotationExpr), annotation, null); }
@SuppressWarnings("unchecked") protected Object extractAnnotation(Object value, Class annotation) { if (value == null) return null; if (value instanceof String) { String expr = (String) value; try { return AnnotationCreator.createAnnotation(expr, annotation); } catch (Exception e) { throw new RuntimeException("Bad annotation expression " + expr, e); } } return value; }
public static Object createAnnotation(String annotationExpr, ClassLoader cl) throws Exception { return createAnnotation(getRootExpr(annotationExpr), null, cl); }
public Object visit(ASTAnnotation node, Object data) { try { Class subAnnotation = Thread.currentThread().getContextClassLoader().loadClass(node.getIdentifier()); typeValue = createAnnotation(node, subAnnotation); } catch (Exception e) { throw new RuntimeException(e); } return null; }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param annotation the annotation class * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(final String annotationExpr, final Class<?> annotation) throws Exception { return createAnnotation(getRootExpr(annotationExpr), annotation, null); }
public Object visit(ASTAnnotation node, Object data) { try { Class<?> subAnnotation = loader.loadClass(node.getIdentifier()); typeValue = createAnnotation(node, subAnnotation); } catch (Exception e) { throw new RuntimeException(e); } return null; }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param cl the classloader to use * @param properties the properties to use for replacement * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(String annotationExpr, ClassLoader cl, Properties properties) throws Exception { return createAnnotation(getRootExpr(annotationExpr, properties), null, cl); } }
protected Annotation initAnnotation(Object annotation) { if (annotation == null) throw new IllegalArgumentException("Null annotation"); if (annotation instanceof Annotation) return (Annotation) annotation; if (annotation instanceof String == false) throw new IllegalArgumentException("Not an annotation: " + annotation); try { return (Annotation) AnnotationCreator.createAnnotation((String) annotation, classLoader); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Error creating annotation: " + annotation, e); } }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param annotation the annotation class * @param properties the properties to use for replacement * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(final String annotationExpr, final Class<?> annotation, Properties properties) throws Exception { return createAnnotation(getRootExpr(annotationExpr, properties), annotation, null); }
/** * Initialise an annotation * * @param annotation the annotation or a string * @return the annotation */ protected Annotation initAnnotation(Object annotation) { if (annotation == null) throw new IllegalArgumentException("Null annotation"); if (annotation instanceof Annotation) return (Annotation) annotation; if (annotation instanceof String == false) throw new IllegalArgumentException("Not an annotation: " + annotation); try { return (Annotation) AnnotationCreator.createAnnotation((String) annotation, classLoader); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Error creating annotation: " + annotation, e); } }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param annotation the annotation class * @param replace should we replace possible properties in expression * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(final String annotationExpr, final Class<?> annotation, boolean replace) throws Exception { return createAnnotation(getRootExpr(annotationExpr, null, replace), annotation, null); }