Javalangannotationretention Example

Java Code Examples for java.lang.annotation.RetentionPolicy

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project openwebbeans, under directory /webbeans-impl/src/main/java/org/apache/webbeans/event/.

Source file: EventUtil.java

26

vote

public static void checkEventBindings(WebBeansContext webBeansContext,Annotation... annotations){   for (  Annotation ann : annotations) {     Retention retention=ann.annotationType().getAnnotation(Retention.class);     RetentionPolicy policy=retention.value();     if (!policy.equals(RetentionPolicy.RUNTIME)) {       throw new IllegalArgumentException("Event qualifiere RetentionPolicy must be RUNTIME for qualifier : " + ann);     }   }   webBeansContext.getAnnotationManager().checkQualifierConditions(annotations); }            

Example 2

From project crash, under directory /cmdline/src/test/java/org/crsh/cmdline/matcher/.

Source file: CompleteTestCase.java

23

vote

public void testEnum() throws Exception { class A {     @Command void foo(    @Option(names="a") RetentionPolicy a){     }     @Command void bar(    @Argument RetentionPolicy a){     }   }   ClassDescriptor<A> desc=CommandFactory.create(A.class);   Matcher<A> matcher=Matcher.createMatcher(desc);   CommandCompletion a=new CommandCompletion(Delimiter.EMPTY,ValueCompletion.create("SOURCE",true).put("CLASS",true).put("RUNTIME",true));   CommandCompletion b=new CommandCompletion(Delimiter.DOUBLE_QUOTE,ValueCompletion.create("SOURCE",true).put("CLASS",true).put("RUNTIME",true));   CommandCompletion c=new CommandCompletion(Delimiter.SINGLE_QUOTE,ValueCompletion.create("SOURCE",true).put("CLASS",true).put("RUNTIME",true));   CommandCompletion d=new CommandCompletion(Delimiter.EMPTY,ValueCompletion.create("RCE",true));   CommandCompletion e=new CommandCompletion(Delimiter.DOUBLE_QUOTE,ValueCompletion.create("RCE",true));   CommandCompletion f=new CommandCompletion(Delimiter.SINGLE_QUOTE,ValueCompletion.create("RCE",true));   CommandCompletion g=new CommandCompletion(Delimiter.EMPTY,ValueCompletion.create("",true));   CommandCompletion h=new CommandCompletion(Delimiter.EMPTY,ValueCompletion.create("",true));   for (  String m : Arrays.asList("foo -a","bar")) {     assertEquals("testing " + m,a,matcher.complete(m + " "));     assertEquals("testing " + m,b,matcher.complete(m + " \""));     assertEquals("testing " + m,c,matcher.complete(m + " '"));     assertEquals("testing " + m,d,matcher.complete(m + " SOU"));     assertEquals("testing " + m,e,matcher.complete(m + " \"SOU"));     assertEquals("testing " + m,f,matcher.complete(m + " 'SOU"));     assertEquals("testing " + m,g,matcher.complete(m + " SOURCE"));     assertEquals("testing " + m,h,matcher.complete(m + " \"SOURCE\""));   } }            

Example 3

From project crash, under directory /cmdline/src/test/java/org/crsh/cmdline/.

Source file: OptionTestCase.java

23

vote

public void testOptionEnumType() throws IntrospectionException { class A {     @Option(names="o") RetentionPolicy o;   }   CommandDescriptor<A,?> c=CommandFactory.create(A.class);   OptionDescriptor i=c.getOption("-o");   assertEquals(Multiplicity.SINGLE,i.getMultiplicity());   assertEquals(false,i.isRequired());   assertEquals(SimpleValueType.ENUM,i.getType()); }            

Example 4

From project griffon, under directory /subprojects/griffon-cli/src/main/groovy/org/codehaus/griffon/compiler/.

Source file: ResolveVisitor.java

23

vote

public void visitAnnotations(AnnotatedNode node){   List<AnnotationNode> annotations=node.getAnnotations();   if (annotations.isEmpty())   return;   Map<String,AnnotationNode> tmpAnnotations=new HashMap<String,AnnotationNode>();   ClassNode annType;   for (  AnnotationNode an : annotations) {     if (an.isBuiltIn())     continue;     annType=an.getClassNode();     resolveOrFail(annType,",  unable to find class for annotation",an);     for (    Map.Entry<String,Expression> member : an.getMembers().entrySet()) {       Expression newValue=transform(member.getValue());       newValue=transformInlineConstants(newValue);       member.setValue(newValue);       checkAnnotationMemberValue(newValue);     }     if (annType.isResolved()) {       Class annTypeClass=annType.getTypeClass();       Retention retAnn=(Retention)annTypeClass.getAnnotation(Retention.class);       if (retAnn != null && retAnn.value().equals(RetentionPolicy.RUNTIME)) {         AnnotationNode anyPrevAnnNode=tmpAnnotations.put(annTypeClass.getName(),an);         if (anyPrevAnnNode != null) {           addError("Cannot specify duplicate annotation on the same member : " + annType.getName(),an);         }       }     }   } }            

Example 5

From project hibernate-validator, under directory /annotation-processor/src/main/java/org/hibernate/validator/ap/checks/.

Source file: RetentionPolicyCheck.java

23

vote

@Override public Set<ConstraintCheckError> checkAnnotationType(TypeElement element,AnnotationMirror annotation){   Retention retention=element.getAnnotation(Retention.class);   if (retention == null) {     return CollectionHelper.asSet(new ConstraintCheckError(element,null,"CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION"));   }   if (!retention.value().equals(RetentionPolicy.RUNTIME)) {     return CollectionHelper.asSet(new ConstraintCheckError(element,annotationApiHelper.getMirror(element.getAnnotationMirrors(),Retention.class),"CONSTRAINT_TYPE_WITH_MISSING_OR_WRONG_RETENTION"));   }   return Collections.emptySet(); }            

Example 6

public void testImmutables() throws Throwable {   final ObjectCloner objectCloner=ObjectCloners.getSerializingObjectClonerFactory().createCloner(new ClonerConfiguration());   final Object[] objects={TimeUnit.NANOSECONDS,"Bananananana",Boolean.TRUE,Integer.valueOf(12),new String("Something else"),new Integer(1234),Enum.class,Object.class,new Object[0],RetentionPolicy.RUNTIME};   for (  Object orig : objects) {     final Object clone=objectCloner.clone(orig);     assertSame(clone,orig);   } }            

Example 7

From project myfaces-extcdi, under directory /core/impl/src/test/java/org/apache/myfaces/extensions/cdi/core/test/impl/utils/.

Source file: CodiUtilsTest.java

23

vote

@Test public void test_isQualifierEqual_AnnotationLiteral_Different_Enum(){   TestQualifier q1=new TestQualifierAnnotationLiteral();   TestQualifierAnnotationLiteral q2=new TestQualifierAnnotationLiteral();   q2.setEnumValue(RetentionPolicy.SOURCE);   Assert.assertFalse(CodiUtils.isQualifierEqual(q1,q2)); }            

Example 8

From project openwebbeans, under directory /webbeans-impl/src/test/java/org/apache/webbeans/newtests/util/.

Source file: AnnotationUtilTest.java

23

vote

@Test public void test_isQualifierEqual_AnnotationLiteral_Different_Enum(){   TestQualifier q1=new TestQualifierAnnotationLiteral();   TestQualifierAnnotationLiteral q2=new TestQualifierAnnotationLiteral();   q2.setEnumValue(RetentionPolicy.SOURCE);   Assert.assertFalse(AnnotationUtil.isQualifierEqual(q1,q2)); }            

Example 9

From project rewrite, under directory /integration-cdi/src/main/java/org/ocpsoft/rewrite/cdi/util/.

Source file: Reflections.java

23

vote

/**   * Checks the bindingType to make sure the annotation was declared properly as a binding type (annotated with @BindingType) and that it has a runtime retention policy.  * @param binding The binding type to check  * @return true only if the annotation is really a binding type  */ @Deprecated public static boolean isBindings(Annotation binding){   boolean isBindingAnnotation=false;   if (binding.annotationType().isAnnotationPresent(Qualifier.class) && binding.annotationType().isAnnotationPresent(Retention.class) && binding.annotationType().getAnnotation(Retention.class).value().equals(RetentionPolicy.RUNTIME)) {     isBindingAnnotation=true;   }   return isBindingAnnotation; }            

Example 10

From project solder, under directory /api/src/main/java/org/jboss/solder/reflection/.

Source file: Reflections.java

23

vote

/**   * Checks the bindingType to make sure the annotation was declared properly as a binding type (annotated with @BindingType) and that it has a runtime retention policy.  * @param binding The binding type to check  * @return true only if the annotation is really a binding type  */ @Deprecated public static boolean isBindings(Annotation binding){   boolean isBindingAnnotation=false;   if (binding.annotationType().isAnnotationPresent(Qualifier.class) && binding.annotationType().isAnnotationPresent(Retention.class) && binding.annotationType().getAnnotation(Retention.class).value().equals(RetentionPolicy.RUNTIME)) {     isBindingAnnotation=true;   }   return isBindingAnnotation; }            

mainorshormilt.blogspot.com

Source: http://www.javased.com/index.php?api=java.lang.annotation.RetentionPolicy

0 Response to "Javalangannotationretention Example"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel