Ejemplo n.º 1
0
 protected <A extends Annotation> A getAnnotation(Class<A> annoType, Symbol annotated) {
   if (!annoType.isAnnotation()) {
     throw new IllegalArgumentException("Not an annotation type: " + annoType);
   }
   String name = annoType.getName();
   for (Attribute.Compound attr : annotated.getAnnotationMirrors()) {
     if (name.equals(attr.type.tsym.flatName().toString())) {
       return AnnotationProxyMaker.generateAnnotation(env, attr, annoType);
     }
   }
   return null;
 }
Ejemplo n.º 2
0
 public void close() {
   if (jusl) {
     try {
       // Call java.util.ServiceLoader.reload
       Method reloadMethod = loaderClass.getMethod("reload");
       reloadMethod.invoke(loader);
     } catch (Exception e) {; // Ignore problems during a call to reload.
     }
   }
 }
Ejemplo n.º 3
0
    ServiceIterator(ClassLoader classLoader, Log log) {
      String loadMethodName;

      this.log = log;
      try {
        try {
          loaderClass = Class.forName("java.util.ServiceLoader");
          loadMethodName = "load";
          jusl = true;
        } catch (ClassNotFoundException cnfe) {
          try {
            loaderClass = Class.forName("sun.misc.Service");
            loadMethodName = "providers";
            jusl = false;
          } catch (ClassNotFoundException cnfe2) {
            // Fail softly if a loader is not actually needed.
            this.iterator = handleServiceLoaderUnavailability("proc.no.service", null);
            return;
          }
        }

        // java.util.ServiceLoader.load or sun.misc.Service.providers
        Method loadMethod = loaderClass.getMethod(loadMethodName, Class.class, ClassLoader.class);

        Object result = loadMethod.invoke(null, Processor.class, classLoader);

        // For java.util.ServiceLoader, we have to call another
        // method to get the iterator.
        if (jusl) {
          loader = result; // Store ServiceLoader to call reload later
          Method m = loaderClass.getMethod("iterator");
          result = m.invoke(result); // serviceLoader.iterator();
        }

        // The result should now be an iterator.
        this.iterator = (Iterator<?>) result;
      } catch (Throwable t) {
        log.error("proc.service.problem");
        throw new Abort(t);
      }
    }