Java Code Examples for java.lang.annotation.Annotation

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 androidannotations, under directory /AndroidAnnotations/androidannotations/src/main/java/com/googlecode/androidannotations/helper/.

Source file: AnnotationHelper.java

  18 
vote

@SuppressWarnings("unchecked") public <T>T extractAnnotationParameter(Element element,Class<? extends Annotation> target,String methodName){
  Annotation annotation=element.getAnnotation(target);
  Method method;
  try {
    method=annotation.getClass().getMethod(methodName);
    return (T)method.invoke(annotation);
  }
 catch (  InvocationTargetException e) {
    if (e.getCause() instanceof MirroredTypeException) {
      MirroredTypeException cause=(MirroredTypeException)e.getCause();
      return (T)cause.getTypeMirror();
    }
 else {
      throw new RuntimeException(e);
    }
  }
catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 2

From project arquillian-core, under directory /test/impl-base/src/test/java/org/jboss/arquillian/test/impl/enricher/resource/.

Source file: ArquillianResourceTestEnricherTestCase.java

  18 
vote

@Test public void shouldBeAbleToInjectBaseContextOnMethod() throws Exception {
  Method resourceMethod=ObjectClass.class.getMethod("test",Object.class);
  Annotation resourceAnnotation=resourceMethod.getParameterAnnotations()[0][0];
  Mockito.when(resourceProvider.lookup((ArquillianResource)resourceAnnotation)).thenReturn(resource);
  TestEnricher enricher=new ArquillianResourceTestEnricher();
  injector.get().inject(enricher);
  Object[] result=enricher.resolve(resourceMethod);
  Assert.assertEquals(resource,result[0]);
}
 

Example 3

From project arquillian-extension-persistence, under directory /int-tests/src/test/java/org/jboss/arquillian/integration/persistence/testextension/event/.

Source file: EventHandlingVerifier.java

  18 
vote

private TestExecutionPhase extractPhase(Method method){
  final Annotation annotation=method.getAnnotation(eventExpectedToBeTriggeredAnnotation);
  try {
    return (TestExecutionPhase)annotation.annotationType().getMethod("value").invoke(annotation);
  }
 catch (  Exception e) {
    throw new RuntimeException("Unable to fetch test execution phase for " + annotation,e);
  }
}
 

Example 4

From project arquillian-extension-warp, under directory /impl/src/main/java/org/jboss/arquillian/warp/impl/server/test/.

Source file: LifecycleTestDriver.java

  18 
vote

public void fireTest(@Observes LifecycleEvent event){
  for (  final Object assertionObject : registry().getAssertions()) {
    final Annotation annotation=event.getAnnotation();
    List<Method> methods=SecurityActions.getMethodsWithAnnotation(assertionObject.getClass(),annotation);
    for (    final Method testMethod : methods) {
      executeTest(assertionObject,testMethod);
    }
  }
}
 

Example 5

From project agraph-java-client, under directory /src/test/.

Source file: TestRunner.java

  17 
vote

static List<Method> methodsAnnotated(Class clazz,Class<? extends Annotation> annotationClass){
  List<Method> r=new ArrayList<Method>();
  List<Class> classes=getSupers(clazz);
  for (  Class c : classes) {
    Method[] methods=c.getDeclaredMethods();
    for (int i=0; i < methods.length; i++) {
      Method m=methods[i];
      Annotation anno=m.getAnnotation(annotationClass);
      if (anno != null) {
        r.add(m);
      }
    }
  }
  return r;
}
 

Example 6

From project amplafi-sworddance, under directory /src/main/java/com/sworddance/beans/.

Source file: BaseProxyLoaderImpl.java

  17 
vote

/** 
 * @param clazz
 */
@SuppressWarnings("unchecked") private <I>Class<? extends I> getProxyClassFromJustClass(Class<? extends I> clazz){
  Proxy proxyInfo=clazz.getAnnotation(Proxy.class);
  if (proxyInfo != null && proxyInfo.proxyClass() != void.class) {
    return (Class<? extends I>)proxyInfo.proxyClass();
  }
  if (hibernateProxyAnnotationClazz != null) {
    Annotation hibernateProxyInfo=clazz.getAnnotation(hibernateProxyAnnotationClazz);
    if (hibernateProxyInfo != null) {
      try {
        Class<?> c=(Class<?>)hibernateProxyAnnotationMethod.invoke(hibernateProxyInfo);
        if (c != null && c != void.class) {
          return (Class<? extends I>)c;
        }
      }
 catch (      Exception e) {
      }
    }
  }
  return null;
}
 

Example 7

From project agorava-core, under directory /agorava-core-impl-cdi/src/main/java/org/agorava/core/cdi/.

Source file: AgoravaExtension.java

  15 
vote

private void internalProcessApiHub(Annotated annotated){
  log.infof("Found services hub %s",annotated.getBaseType());
  Set<Annotation> qualifiers=AnnotationInspector.getAnnotations(annotated,ServiceRelated.class);
  servicesQualifiersAvailable.addAll(qualifiers);
  if (annotated.isAnnotationPresent(OAuthApplication.class)) {
    log.debug("Bean is configured");
    servicesQualifiersConfigured.addAll(qualifiers);
  }
}
 

Example 8

From project airlift, under directory /bootstrap/src/main/java/io/airlift/bootstrap/.

Source file: LifeCycleMethods.java

  15 
vote

private void processMethod(Method method,Class<? extends Annotation> annotationClass,Set<String> usedSet){
  if (method.isAnnotationPresent(annotationClass)) {
    if (!usedSet.contains(method.getName())) {
      if (method.getParameterTypes().length != 0) {
        throw new UnsupportedOperationException(String.format("@PostConstruct/@PreDestroy methods cannot have arguments: %s",method.getDeclaringClass().getName() + "." + method.getName()+ "(...)"));
      }
      method.setAccessible(true);
      usedSet.add(method.getName());
      methodMap.put(annotationClass,method);
    }
  }
}
 

Example 9

From project android_8, under directory /src/com/google/gson/.

Source file: CamelCaseSeparatorNamingPolicy.java

  15 
vote

@Override protected String translateName(String target,Type fieldType,Collection<Annotation> annnotations){
  StringBuilder translation=new StringBuilder();
  for (int i=0; i < target.length(); i++) {
    char character=target.charAt(i);
    if (Character.isUpperCase(character) && translation.length() != 0) {
      translation.append(separatorString);
    }
    translation.append(character);
  }
  return translation.toString();
}
 

Example 10

From project ANNIS, under directory /annis-interfaces/src/main/java/annis/provider/.

Source file: SaltProjectProvider.java

  15 
vote

@Override public void writeTo(SaltProject project,Class<?> type,Type genericType,Annotation[] annotations,MediaType mediaType,MultivaluedMap<String,Object> httpHeaders,OutputStream entityStream) throws IOException, WebApplicationException {
  Resource resource=new XMIResourceImpl();
  resource.getContents().add(project);
  for (  SCorpusGraph corpusGraph : project.getSCorpusGraphs()) {
    for (    SDocument doc : corpusGraph.getSDocuments()) {
      if (doc.getSDocumentGraph() != null) {
        resource.getContents().add(doc.getSDocumentGraph());
      }
    }
  }
  try {
    resource.save(entityStream,null);
  }
 catch (  Exception ex) {
    log.error("exception when serializing SaltProject",ex);
  }
}
 

Example 11

From project Arecibo, under directory /aggregator/src/main/java/com/ning/arecibo/aggregator/rest/.

Source file: AggregatorRenderer.java

  15 
vote

@Override public void writeTo(AggregatorImpl impl,Class<?> type,Type genericType,Annotation[] annotations,MediaType mediaType,MultivaluedMap<String,Object> httpHeaders,OutputStream entityStream) throws IOException, WebApplicationException {
  PrintWriter pw=new PrintWriter(entityStream);
  StringTemplate st=StringTemplates.getTemplate("htmlOpen");
  st.setAttribute("header","Aggregator Details");
  st.setAttribute("msg","");
  pw.println(st.toString());
  pw.println(StringTemplates.getTemplate("tableOpen"));
  StringTemplate th=StringTemplates.getTemplate("tableHeader");
  th.setAttribute("headers",Arrays.asList("Aggregator","InputEvent","OutputEvent","Esper Statement"));
  pw.println(th);
  impl.renderHtml(pw,0);
  pw.println(StringTemplates.getTemplate("tableClose"));
  pw.println(StringTemplates.getTemplate("htmlClose"));
}
 

Example 12

From project arquillian-container-osgi, under directory /container-common/src/main/java/org/jboss/arquillian/container/osgi/.

Source file: AbstractOSGiApplicationArchiveProcessor.java

  15 
vote

private void addImportsForClass(OSGiManifestBuilder builder,Class<?> javaClass){
  for (  Class<?> interf : javaClass.getInterfaces()) {
    addImportPackage(builder,interf);
  }
  for (  Annotation anno : javaClass.getDeclaredAnnotations()) {
    addImportPackage(builder,anno.annotationType());
  }
  for (  Field field : javaClass.getDeclaredFields()) {
    Class<?> type=field.getType();
    addImportPackage(builder,type);
  }
  for (  Method method : javaClass.getDeclaredMethods()) {
    Class<?> returnType=method.getReturnType();
    if (returnType != Void.TYPE)     addImportPackage(builder,returnType);
    for (    Class<?> paramType : method.getParameterTypes())     addImportPackage(builder,paramType);
  }
  for (  Class<?> declaredClass : javaClass.getDeclaredClasses()) {
    addImportsForClass(builder,declaredClass);
  }
}
 

Example 13

From project arquillian-extension-android, under directory /android-configuration/src/main/java/org/jboss/arquillian/android/configuration/.

Source file: SecurityActions.java

  15 
vote

static List<Field> getFieldsWithAnnotation(final Class<?> source,final Class<? extends Annotation> annotationClass){
  List<Field> declaredAccessableFields=AccessController.doPrivileged(new PrivilegedAction<List<Field>>(){
    public List<Field> run(){
      List<Field> foundFields=new ArrayList<Field>();
      Class<?> nextSource=source;
      while (nextSource != Object.class) {
        for (        Field field : nextSource.getDeclaredFields()) {
          if (field.isAnnotationPresent(annotationClass)) {
            if (!field.isAccessible()) {
              field.setAccessible(true);
            }
            foundFields.add(field);
          }
        }
        nextSource=nextSource.getSuperclass();
      }
      return foundFields;
    }
  }
);
  return declaredAccessableFields;
}
 

Example 14

From project arquillian-extension-drone, under directory /drone-configuration/src/main/java/org/jboss/arquillian/drone/configuration/.

Source file: ConfigurationMapper.java

  15 
vote

/** 
 * Maps a configuration using Arquillian Descriptor file
 * @param < T > Type of the configuration
 * @param descriptor Arquillian Descriptor
 * @param configuration Configuration object
 * @param qualifier Qualifier annotation
 * @return Configured configuration
 */
public static <T extends DroneConfiguration<T>>T fromArquillianDescriptor(ArquillianDescriptor descriptor,T configuration,Class<? extends Annotation> qualifier){
  Validate.notNull(descriptor,"Descriptor must not be null");
  Validate.notNull(configuration,"Configuration object must not be null");
  Validate.notNull(qualifier,"Qualifier object must not be null");
  String descriptorQualifier=configuration.getConfigurationName();
  String qualifierName=qualifier.getSimpleName().toLowerCase();
  Map<String,String> nameValuePairs=loadNameValuePairs(descriptor,descriptorQualifier,qualifierName);
  return mapFromNameValuePairs(configuration,nameValuePairs);
}
 

Example 15

From project arquillian-extension-seam2, under directory /src/main/java/org/jboss/arquillian/seam2/.

Source file: ReflectionHelper.java

  15 
vote

public static List<Field> getFieldsWithAnnotation(final Class<?> source,final Class<? extends Annotation> annotationClass){
  List<Field> declaredAccessableFields=AccessController.doPrivileged(new PrivilegedAction<List<Field>>(){
    public List<Field> run(){
      List<Field> foundFields=new ArrayList<Field>();
      Class<?> nextSource=source;
      while (nextSource != Object.class) {
        for (        Field field : nextSource.getDeclaredFields()) {
          if (field.isAnnotationPresent(annotationClass)) {
            if (!field.isAccessible()) {
              field.setAccessible(true);
            }
            foundFields.add(field);
          }
        }
        nextSource=nextSource.getSuperclass();
      }
      return foundFields;
    }
  }
);
  return declaredAccessableFields;
}
 

Example 16

From project arquillian-extension-spring, under directory /arquillian-warp-spring/src/main/java/org/jboss/arquillian/warp/extension/spring/container/.

Source file: SecurityActions.java

  15 
vote

/** 
 * <p>Retrieves the list of annotated fields for the given type.</p>
 * @param source          the type that will be scanned for fields annotated with given type
 * @param annotationClass the annotation type
 * @return list of fields of the given glass that are annotated with specific annotation, may be empty
 */
static List<Field> getFieldsWithAnnotation(final Class<?> source,final Class<? extends Annotation> annotationClass){
  List<Field> declaredAccessableFields=AccessController.doPrivileged(new PrivilegedAction<List<Field>>(){
    public List<Field> run(){
      List<Field> foundFields=new ArrayList<Field>();
      Class<?> nextSource=source;
      while (nextSource != Object.class) {
        for (        Field field : nextSource.getDeclaredFields()) {
          if (field.isAnnotationPresent(annotationClass)) {
            if (!field.isAccessible()) {
              field.setAccessible(true);
            }
            foundFields.add(field);
          }
        }
        nextSource=nextSource.getSuperclass();
      }
      return foundFields;
    }
  }
);
  return declaredAccessableFields;
}
 

Example 17

From project arquillian-graphene, under directory /graphene-selenium/graphene-selenium-drone/src/main/java/org/jboss/arquillian/ajocado/drone/factory/.

Source file: AjocadoFactory.java

  15 
vote

@Override public ArquillianGrapheneConfiguration createConfiguration(ArquillianDescriptor descriptor,Class<? extends Annotation> qualifier){
  ArquillianGrapheneConfiguration configuration=new ArquillianGrapheneConfiguration();
  configuration.configure(descriptor,qualifier);
  GrapheneConfigurationContext.set(configuration);
  return configuration;
}
 

Example 18

From project arquillian-rusheye, under directory /rusheye-impl/src/main/java/org/jboss/rusheye/suite/utils/.

Source file: NullingProxy.java

  15 
vote

public static <T>T handle(T instance,Class<? extends Annotation> nullified) throws InstantiationException, IllegalAccessException {
  Class<?> originalClass=(Class<?>)instance.getClass();
  if (instance instanceof ProxyObject) {
    originalClass=(Class<?>)originalClass.getSuperclass();
  }
  ProxyFactory proxyFactory=new ProxyFactory();
  proxyFactory.setSuperclass(originalClass);
  Class<?> proxyClass=proxyFactory.createClass();
  MethodHandler handler=new NullingHandler(instance,nullified);
  @SuppressWarnings("unchecked") T proxyInstance=(T)proxyClass.newInstance();
  ((ProxyObject)proxyInstance).setHandler(handler);
  return proxyInstance;
}
 

Example 19

From project arquillian-showcase, under directory /extensions/autodiscover/src/main/java/org/jboss/arquillian/showcase/extension/autodiscover/.

Source file: ReflectionHelper.java

  15 
vote

public static List<Field> getFieldsWithAnnotation(final Class<?> source,final Class<? extends Annotation> annotationClass){
  List<Field> declaredAccessableFields=AccessController.doPrivileged(new PrivilegedAction<List<Field>>(){
    public List<Field> run(){
      List<Field> foundFields=new ArrayList<Field>();
      Class<?> nextSource=source;
      while (nextSource != Object.class) {
        for (        Field field : nextSource.getDeclaredFields()) {
          if (field.isAnnotationPresent(annotationClass)) {
            if (!field.isAccessible()) {
              field.setAccessible(true);
            }
            foundFields.add(field);
          }
        }
        nextSource=nextSource.getSuperclass();
      }
      return foundFields;
    }
  }
);
  return declaredAccessableFields;
}
 

Example 20

From project arquillian_deprecated, under directory /containers/openejb-embedded-3.1/src/main/java/org/jboss/arquillian/container/openejb/embedded_3_1/.

Source file: OpenEJBTestEnricher.java

  15 
vote

/** 
 * {@inheritDoc}
 * @see org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher#enrich(org.jboss.arquillian.spi.Context,java.lang.Object)
 */
@Override public void enrich(Object testCase){
  super.enrich(testCase);
  final Class<? extends Annotation> inject=(Class<? extends Annotation>)Inject.class;
  List<Field> fieldsWithInject=this.getFieldsWithAnnotation(testCase.getClass(),inject);
  for (  final Field field : fieldsWithInject) {
    if (!field.isAccessible()) {
      AccessController.doPrivileged(new PrivilegedAction<Void>(){
        public Void run(){
          field.setAccessible(true);
          return null;
        }
      }
);
    }
    try {
      final Object resolvedVaue;
      final ArquillianContext arquillianContext=this.getArquillianContext();
      final Class<?> type=field.getType();
      if (field.isAnnotationPresent(Properties.class)) {
        final Properties properties=field.getAnnotation(Properties.class);
        resolvedVaue=arquillianContext.get(type,properties);
      }
 else       if (field.isAnnotationPresent(Property.class)) {
        final Property property=field.getAnnotation(Property.class);
        final Properties properties=new PropertiesImpl(new Property[]{property});
        resolvedVaue=arquillianContext.get(type,properties);
      }
 else {
        resolvedVaue=arquillianContext.get(type);
      }
      field.set(testCase,resolvedVaue);
    }
 catch (    final IllegalAccessException e) {
      throw new RuntimeException("Could not inject into " + field.getName() + " of test case: "+ testCase,e);
    }
  }
}