public static Object createAnnotation(ASTAnnotation node, Class annotation) throws Exception { return createAnnotation(node, annotation, null); }
/** * 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); }
@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; }
/** * 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); }
/** * 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 static Object createAnnotation(final String annotationExpr, final Class annotation) throws Exception { return createAnnotation(getRootExpr(annotationExpr), annotation, null); }
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; }
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 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); }
/** * 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 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); }
/** * Create annotation. * * @param annotationExpr the annotation expression * @param cl the classloader to use * @param replace should we replace possible properties in expression * @return new annotation instance * @throws Exception for any error */ public static Object createAnnotation(String annotationExpr, ClassLoader cl, boolean replace) throws Exception { return createAnnotation(getRootExpr(annotationExpr, null, replace), null, cl); }
/** * 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); } }
/** * 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); } }
public Annotation getAnnotationInstance(ClassLoader cl) { try { String annString = annotation; if (replace) { annString = StringPropertyReplacer.replaceProperties(annString); } if (cl == null) { cl = Thread.currentThread().getContextClassLoader(); } ann = (Annotation)AnnotationCreator.createAnnotation(annString, cl); } catch (Exception e) { throw new RuntimeException("Error creating annotation for " + annotation, e); } catch(TokenMgrError e) { throw new RuntimeException("Error creating annotation for " + annotation, e); } return ann; }
public Annotation getAnnotationInstance(ClassLoader cl) { try { String annString = annotation; if (replace) { annString = StringPropertyReplacer.replaceProperties(annString); } if (cl == null) { cl = Thread.currentThread().getContextClassLoader(); } ann = (Annotation)AnnotationCreator.createAnnotation(annString, cl); } catch (Exception e) { throw new RuntimeException("Error creating annotation for " + annotation, e); } catch(TokenMgrError e) { throw new RuntimeException("Error creating annotation for " + annotation, e); } return ann; }
public Annotation getAnnotationInstance(ClassLoader cl) { if (ann != null) return ann; String annString = getAnnotation(); try { if (replace) { annString = StringPropertyReplacer.replaceProperties(annString); } if (cl == null) { cl = Thread.currentThread().getContextClassLoader(); } ann = (Annotation)AnnotationCreator.createAnnotation(annString, cl); flushJBossObjectCache(); } catch(TokenMgrError e) { throw new RuntimeException("Error creating annotation for " + annotation, e); } catch (Throwable e) { throw new RuntimeException("Error creating annotation for " + annotation, e); } return ann; }
@SuppressWarnings("unchecked") public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable { if (scope != null) { Annotation annotation = (Annotation)AnnotationCreator.createAnnotation(scope, cl); ScopeFactoryLookup scopeFactoryLookup = annotation.getClass().getAnnotation(ScopeFactoryLookup.class); if (scopeFactoryLookup != null) { // TODO do we really want to create a new factory for every annotation we look at? // We could use some kind of soft reference map here (per classloader) // Class<?> clazz = scopeFactoryLookup.value(); // WeakHashMap.put(clazz.getClassLoader(), new SoftMap()) // SoftValueHashMap.put(clazz.getName(), instance) // If this is done, it should be moved to a common helper class // that does generic construction from a factory given on the meta annotations ScopeFactory scopeFactory = scopeFactoryLookup.value().newInstance(); return scopeFactory.create(annotation); } else { // todo - annotation.value(); return createScopeKey(annotation.getClass().getSimpleName(), annotation.toString()); } } else { return createScopeKey(level, qualifier); } }