コード例 #1
0
 protected void checkAnnotations(String clazz, String member, AnnotationsAttribute aa, int line) {
   if (aa != null) {
     for (Map.Entry<String, Boolean> entry : annotations.entrySet()) {
       String annotation = entry.getKey();
       Annotation ann = aa.getAnnotation(annotation);
       if (ann != null) {
         checkAnnotation(clazz, member, line, entry.getValue(), annotation, ann);
       }
     }
   }
 }
コード例 #2
0
  /**
   * Retrieve the String value of an annotation which is not available at runtime.
   *
   * @param clazz The annotated class
   * @param annotation The annotation which is not visible at runtime
   * @param name The name of the String property of the annotation to retrieve
   * @return The String value of the annotation or null if the annotation or its property is not
   *     present
   */
  public static String getInvisibleAnnotationStringValue(
      Class<?> clazz, Class<? extends Annotation> annotation, String name) {
    CtClass ctClass = GwtClassPool.getCtClass(clazz);
    ctClass.defrost();

    AnnotationsAttribute attr =
        (AnnotationsAttribute)
            ctClass.getClassFile().getAttribute(AnnotationsAttribute.invisibleTag);
    if (attr == null) {
      return null;
    }
    javassist.bytecode.annotation.Annotation an = attr.getAnnotation(annotation.getName());

    ctClass.freeze();

    return an != null ? ((StringMemberValue) an.getMemberValue(name)).getValue() : null;
  }
コード例 #3
0
      private URL computeResourceURL(Method method) throws NotFoundException, URISyntaxException {
        List<ResourceFileEntry> filesSimpleNames = new ArrayList<ResourceFileEntry>();
        boolean computeExtensions = false;
        CtMethod m = ctClass.getMethod(method.getName(), getDescriptor(method));
        MethodInfo minfo = m.getMethodInfo2();
        AnnotationsAttribute attr =
            (AnnotationsAttribute) minfo.getAttribute(AnnotationsAttribute.invisibleTag);
        if (attr != null) {
          Annotation an = attr.getAnnotation(Source.class.getName());
          if (an != null) {
            MemberValue[] mvArray = ((ArrayMemberValue) an.getMemberValue("value")).getValue();
            if (mvArray != null) {
              for (MemberValue mv : mvArray) {
                StringMemberValue smv = (StringMemberValue) mv;
                filesSimpleNames.add(new ResourceFileEntry(smv.getValue(), m));
              }
            }
          }
        }

        if (filesSimpleNames.isEmpty()) {
          // no @Source annotation detected
          filesSimpleNames.add(new ResourceFileEntry(method.getName(), m));
          computeExtensions = true;
        }

        List<URL> existingFiles = new ArrayList<URL>();

        for (ResourceFileEntry resourceEntry : filesSimpleNames) {
          String resourceName = resourceEntry.resourceName;
          CtClass declaringClass = resourceEntry.resourceMethod.getDeclaringClass();
          String baseDir = declaringClass.getPackageName().replaceAll("\\.", "/") + "/";
          String fileName =
              (resourceName.startsWith(baseDir)) ? resourceName : baseDir + resourceName;

          if (computeExtensions) {
            String[] extensions = getResourceDefaultExtensions(method);

            for (String extension : extensions) {
              String possibleFile = fileName + extension;
              URL url = GwtPatcher.class.getClassLoader().getResource(possibleFile);
              if (url != null) {
                existingFiles.add(url);
              }
            }
          } else {
            URL url = GwtPatcher.class.getClassLoader().getResource(fileName);
            if (url != null) {
              existingFiles.add(url);
            }
          }
        }

        if (existingFiles.isEmpty()) {
          throw new RuntimeException(
              "No resource file found for method "
                  + ctClass.getSimpleName()
                  + "."
                  + method.getName()
                  + "()");
        } else if (existingFiles.size() > 1) {
          throw new RuntimeException(
              "Too many resource files found for method "
                  + ctClass.getSimpleName()
                  + "."
                  + method.getName()
                  + "()");
        }

        return existingFiles.get(0);
      }