/** Returns the scoping annotation, or null if there isn't one. */ public static Class<? extends Annotation> findScopeAnnotation( Errors errors, Annotation[] annotations) { Class<? extends Annotation> found = null; for (Annotation annotation : annotations) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (isScopeAnnotation(annotationType)) { if (found != null) { errors.duplicateScopeAnnotations(found, annotationType); } else { found = annotationType; } } } return found; }
@Override public Boolean visit(ScopeBinding command) { Scope scope = checkNotNull(command.getScope(), "scope"); Class<? extends Annotation> annotationType = checkNotNull(command.getAnnotationType(), "annotation type"); if (!Annotations.isScopeAnnotation(annotationType)) { errors.missingScopeAnnotation(annotationType); // Go ahead and bind anyway so we don't get collateral errors. } if (!Annotations.isRetainedAtRuntime(annotationType)) { errors.missingRuntimeRetention(annotationType); // Go ahead and bind anyway so we don't get collateral errors. } ScopeBinding existing = injector.state.getScopeBinding(annotationType); if (existing != null) { if (!scope.equals(existing.getScope())) { errors.duplicateScopes(existing, annotationType, scope); } } else { injector.state.putScopeBinding(annotationType, command); } return true; } }
/** Returns the scoping annotation, or null if there isn't one. */ public static Class<? extends Annotation> findScopeAnnotation(Errors errors, Annotation[] annotations) { Class<? extends Annotation> found = null; for (Annotation annotation : annotations) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (isScopeAnnotation(annotationType)) { if (found != null) { errors.duplicateScopeAnnotations(found, annotationType); } else { found = annotationType; } } } return found; }
/** Returns the scoping annotation, or null if there isn't one. */ public static Class<? extends Annotation> findScopeAnnotation(Errors errors, Annotation[] annotations) { Class<? extends Annotation> found = null; for (Annotation annotation : annotations) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (isScopeAnnotation(annotationType)) { if (found != null) { errors.duplicateScopeAnnotations(found, annotationType); } else { found = annotationType; } } } return found; }
/** Returns the scoping annotation, or null if there isn't one. */ public static Class<? extends Annotation> findScopeAnnotation(Errors errors, Annotation[] annotations) { Class<? extends Annotation> found = null; for (Annotation annotation : annotations) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (isScopeAnnotation(annotationType)) { if (found != null) { errors.duplicateScopeAnnotations(found, annotationType); } else { found = annotationType; } } } return found; }
/** Returns the scoping annotation, or null if there isn't one. */ public static Class<? extends Annotation> findScopeAnnotation( Errors errors, Annotation[] annotations) { Class<? extends Annotation> found = null; for (Annotation annotation : annotations) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (isScopeAnnotation(annotationType)) { if (found != null) { errors.duplicateScopeAnnotations(found, annotationType); } else { found = annotationType; } } } return found; }
/** Returns the scoping annotation, or null if there isn't one. */ public static Class<? extends Annotation> findScopeAnnotation( Errors errors, Annotation[] annotations) { Class<? extends Annotation> found = null; for (Annotation annotation : annotations) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (isScopeAnnotation(annotationType)) { if (found != null) { errors.duplicateScopeAnnotations(found, annotationType); } else { found = annotationType; } } } return found; }
/** * Returns the scoping annotation, or null if there isn't one. */ public static Class<? extends Annotation> findScopeAnnotation(Errors errors, Annotation[] annotations) { Class<? extends Annotation> found = null; for (Annotation annotation : annotations) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (isScopeAnnotation(annotationType)) { if (found != null) { errors.duplicateScopeAnnotations(found, annotationType); } else { found = annotationType; } } } return found; }
@SuppressWarnings("PMD.UnusedPrivateMethod") private static void applyScopeAnnotation(final ClassPool classPool, final AnnotationsAttribute annotations, final AnnotatedElement source, final Class<? extends java.lang.annotation.Annotation> scope) throws Exception { if (scope != null) { Preconditions.checkState(Annotations.isScopeAnnotation(scope), "Provided annotation %s is not scope annotation", scope.getSimpleName()); for (java.lang.annotation.Annotation ann : source.getAnnotations()) { Preconditions.checkArgument(!(ann instanceof ScopeAnnotation), "Duplicate scope definition: scope is specified as %s and also defined " + "in @ScopeAnnotation.", scope.getSimpleName()); } annotations.addAnnotation(new Annotation(annotations.getConstPool(), classPool.get(scope.getName()))); } }
private static Annotation processAnnotation(final ClassPool classPool, final ConstPool constPool, final java.lang.annotation.Annotation ann) throws Exception { Annotation res = null; // if we copy these annotation guice will go to infinite loop if (!(ann instanceof ProvidedBy || ann instanceof ImplementedBy)) { Preconditions.checkState(!Annotations.isScopeAnnotation(ann.annotationType()), "Don't use scope annotations directly - use @ScopeAnnotation(TargetScope) wrapper, " + "because guice doesn't allow scope annotations on abstract types"); if (ann instanceof ScopeAnnotation) { res = new Annotation(constPool, classPool.get(((ScopeAnnotation) ann).value().getName())); } else { res = JavassistUtils.copyAnnotation(classPool, constPool, ann); } } return res; }
@Override public Boolean visit(ScopeBinding command) { Scope scope = checkNotNull(command.getScope(), "scope"); Class<? extends Annotation> annotationType = checkNotNull(command.getAnnotationType(), "annotation type"); if (!Annotations.isScopeAnnotation(annotationType)) { errors.missingScopeAnnotation(annotationType); // Go ahead and bind anyway so we don't get collateral errors. } if (!Annotations.isRetainedAtRuntime(annotationType)) { errors.missingRuntimeRetention(annotationType); // Go ahead and bind anyway so we don't get collateral errors. } ScopeBinding existing = injector.state.getScopeBinding(annotationType); if (existing != null) { if (!scope.equals(existing.getScope())) { errors.duplicateScopes(existing, annotationType, scope); } } else { injector.state.putScopeBinding(annotationType, command); } return true; } }
@Override public Boolean visit(ScopeBinding command) { Scope scope = checkNotNull(command.getScope(), "scope"); Class<? extends Annotation> annotationType = checkNotNull(command.getAnnotationType(), "annotation type"); if (!Annotations.isScopeAnnotation(annotationType)) { errors.missingScopeAnnotation(annotationType); // Go ahead and bind anyway so we don't get collateral errors. } if (!Annotations.isRetainedAtRuntime(annotationType)) { errors.missingRuntimeRetention(annotationType); // Go ahead and bind anyway so we don't get collateral errors. } ScopeBinding existing = injector.state.getScopeBinding(annotationType); if (existing != null) { if (!scope.equals(existing.getScope())) { errors.duplicateScopes(existing, annotationType, scope); } } else { injector.state.putScopeBinding(annotationType, command); } return true; } }
@Override public Boolean visit(ScopeBinding command) { Scope scope = checkNotNull(command.getScope(), "scope"); Class<? extends Annotation> annotationType = checkNotNull(command.getAnnotationType(), "annotation type"); if (!Annotations.isScopeAnnotation(annotationType)) { errors.missingScopeAnnotation(annotationType); // Go ahead and bind anyway so we don't get collateral errors. } if (!Annotations.isRetainedAtRuntime(annotationType)) { errors.missingRuntimeRetention(annotationType); // Go ahead and bind anyway so we don't get collateral errors. } ScopeBinding existing = injector.state.getScopeBinding(annotationType); if (existing != null) { if (!scope.equals(existing.getScope())) { errors.duplicateScopes(existing, annotationType, scope); } } else { injector.state.putScopeBinding(annotationType, command); } return true; } }
@Override public Boolean visit(ScopeBinding command) { Scope scope = command.getScope(); Class<? extends Annotation> annotationType = command.getAnnotationType(); if (!Annotations.isScopeAnnotation(annotationType)) { errors.withSource(annotationType).missingScopeAnnotation(); // Go ahead and bind anyway so we don't get collateral errors. } if (!Annotations.isRetainedAtRuntime(annotationType)) { errors.withSource(annotationType) .missingRuntimeRetention(command.getSource()); // Go ahead and bind anyway so we don't get collateral errors. } Scope existing = injector.state.getScope(checkNotNull(annotationType, "annotation type")); if (existing != null) { errors.duplicateScopes(existing, annotationType, scope); } else { injector.state.putAnnotation(annotationType, checkNotNull(scope, "scope")); } return true; } }
@Override public Boolean visit(ScopeBinding command) { Scope scope = command.getScope(); Class<? extends Annotation> annotationType = command.getAnnotationType(); if (!Annotations.isScopeAnnotation(annotationType)) { errors.withSource(annotationType).missingScopeAnnotation(); // Go ahead and bind anyway so we don't get collateral errors. } if (!Annotations.isRetainedAtRuntime(annotationType)) { errors.withSource(annotationType) .missingRuntimeRetention(command.getSource()); // Go ahead and bind anyway so we don't get collateral errors. } Scope existing = injector.state.getScope(checkNotNull(annotationType, "annotation type")); if (existing != null) { errors.duplicateScopes(existing, annotationType, scope); } else { injector.state.putAnnotation(annotationType, checkNotNull(scope, "scope")); } return true; } }
@Override public Boolean visit(ScopeBinding command) { Scope scope = command.getScope(); Class<? extends Annotation> annotationType = command.getAnnotationType(); if (!Annotations.isScopeAnnotation(annotationType)) { errors.withSource(annotationType).missingScopeAnnotation(); // Go ahead and bind anyway so we don't get collateral errors. } if (!Annotations.isRetainedAtRuntime(annotationType)) { errors.withSource(annotationType) .missingRuntimeRetention(command.getSource()); // Go ahead and bind anyway so we don't get collateral errors. } Scope existing = injector.state.getScope(checkNotNull(annotationType, "annotation type")); if (existing != null) { errors.duplicateScopes(existing, annotationType, scope); } else { injector.state.putAnnotation(annotationType, checkNotNull(scope, "scope")); } return true; } }