示例#1
0
  protected void addAllPackages(Package pkg) {
    Gwtc gwtc = pkg.getAnnotation(Gwtc.class);
    if (gwtc != null && addPackage(pkg)) {
      addGwtcPackage(gwtc, pkg, false);
    }
    String parentName = pkg.getName();
    int ind = parentName.lastIndexOf('.');
    while (ind > -1) {
      parentName = parentName.substring(0, ind);
      ind = parentName.lastIndexOf('.');
      pkg = GwtReflect.getPackage(parentName);
      X_Log.debug(getClass(), "Checking parent package", "'" + parentName + "'", pkg != null);

      if (pkg != null) {
        gwtc = pkg.getAnnotation(Gwtc.class);
        if (gwtc != null && addPackage(pkg)) {
          addGwtcPackage(gwtc, pkg, false);
        }
      }
    }
    pkg = GwtReflect.getPackage("");
    if (pkg != null) {
      gwtc = pkg.getAnnotation(Gwtc.class);
      if (gwtc != null && addPackage(pkg)) {
        addGwtcPackage(gwtc, pkg, false);
      }
    }
  }
示例#2
0
 private Object findAncestor(Package p) {
   String name = p.getName();
   int ind = name.lastIndexOf('.');
   while (ind > -1) {
     name = name.substring(0, ind);
     p = GwtReflect.getPackage(name);
     if (p != null && p.isAnnotationPresent(Gwtc.class)) {
       return p;
     }
     ind = name.lastIndexOf('.');
   }
   p = GwtReflect.getPackage("");
   return p == null || !p.isAnnotationPresent(Gwtc.class) ? null : p;
 }
示例#3
0
 public void addPackages(Package pkg, GwtcServiceImpl gwtc, boolean recursive) {
   Iterable<ClassFile> iter;
   if (recursive) {
     iter = classpath.get().findClassesBelowPackage(pkg.getName());
   } else {
     iter = classpath.get().findClassesInPackage(pkg.getName());
   }
   for (ClassFile file : iter) {
     X_Log.info(getClass(), "Scanning file ", file);
     if ("package-info".equals(file.getEnclosedName())) {
       Package p = GwtReflect.getPackage(file.getPackage());
       if (!finishedPackages.contains(p)) {
         gwtcService.addPackage(p, false);
       }
     } else {
       try {
         Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(file.getName());
         if (!finishedClasses.contains(cls)) {
           gwtc.addClass(cls);
         }
       } catch (ClassNotFoundException e) {
         X_Log.warn(getClass(), "Unable to load class ", file);
       }
     }
   }
 }
示例#4
0
  private void scanClass(Class<?> clazz) {
    GwtcUnit data = nodes.get(clazz);
    if (data == null) {
      Object ancestor = findAncestor(clazz);
      return;
    }
    if (data.gwtc == null) {
      return;
    }
    gwtcService.addClass(clazz);
    Object parent;
    if (data.isFindParent()) {
      parent = findAncestor(data.source);
      if (parent != null) {
        GwtcUnit parentNode = nodes.get(parent);
        data.setParent(parentNode);
        if (data.isFindAllParents()) {
          while (parent != null) {
            Object ancestor = findAncestor(parent);
            if (ancestor == null) {
              break;
            } else {
              GwtcUnit ancestorNode = nodes.get(ancestor);
              parentNode.setParent(ancestorNode);
              parent = ancestor;
              parentNode = ancestorNode;
            }
          }
        }
      }
    }

    Gwtc gwtc = clazz.getAnnotation(Gwtc.class);
    Class<?> c;
    parent = c = clazz;
    if (gwtc == null) {
      while (c != Object.class) {
        gwtc = c.getAnnotation(Gwtc.class);
        if (gwtc != null) {
          parent = c;
          maybeAddAncestors(gwtc, c);
          break;
        }
        c = c.getSuperclass();
      }
      Package pkg;
      parent = pkg = clazz.getPackage();
      if (gwtc == null) {
        gwtc = pkg.getAnnotation(Gwtc.class);
        String parentName = pkg.getName();
        search:
        while (gwtc == null) {
          int ind = parentName.lastIndexOf('.');
          if (ind == -1) {
            break;
          }
          parentName = parentName.substring(0, ind);
          pkg = GwtReflect.getPackage(parentName);
          while (pkg == null) {
            ind = parentName.lastIndexOf('.');
            if (ind == -1) {
              X_Log.warn("No package found for ", clazz.getPackage(), "; aborting @Gwtc search");
              break search;
            }
            parentName = parentName.substring(0, ind);
            pkg = GwtReflect.getPackage(parentName);
          }
          gwtc = pkg.getAnnotation(Gwtc.class);
        }
        if (gwtc != null) {
          parent = pkg;
          maybeAddAncestors(gwtc, pkg);
        }
      } else {
        maybeAddAncestors(gwtc, pkg);
      }
    } else {
      maybeAddAncestors(gwtc, c);
      inherit(data);
    }
    if (parent != null) {
      X_Log.trace(getClass(), "Next annotated parent of ", c, "is", parent);
    }
  }
示例#5
0
 /**
  * Finds the next parent element annotated with @Gwtc. <br>
  * This method should NOT be used to recurse parent hierarchy; instead use {@link #getParents()}
  *
  * @return the next parent with @Gwtc, if there is one.
  */
 public Object getParent() {
   if (!isFindParent()) {
     return null;
   }
   final boolean findAll = isFindAllParents();
   Object o = source;
   Class<?> c;
   switch (type) {
     case Method:
       if (!isFindEnclosingClasses()) {
         return null;
       }
       o = c = ((Method) o).getDeclaringClass();
       if (c.isAnnotationPresent(Gwtc.class)) {
         return c;
       } else if (!findAll) {
         return null;
       }
       // fallthrough
     case Class:
       c = (Class<?>) o;
       if (isFindEnclosingClasses()) {
         Class<?> search = c;
         while (!isObjectOrNull(search.getDeclaringClass())) {
           search = search.getDeclaringClass();
           if (search.isAnnotationPresent(Gwtc.class)) {
             return search;
           }
           if (!findAll) {
             break;
           }
         }
       }
       if (isFindSuperClasses()) {
         Class<?> search = c;
         while (!isObjectOrNull(search.getSuperclass())) {
           search = search.getSuperclass();
           if (search.isAnnotationPresent(Gwtc.class)) {
             return search;
           }
           if (!findAll) {
             break;
           }
         }
       }
       o = c.getPackage();
       // fallthrough
     case Package:
       Package p = (Package) o;
       String pkg = p.getName();
       if ("".equals(pkg)) {
         return null;
       }
       do {
         pkg = X_String.chopOrReturnEmpty(pkg, ".");
         p = GwtReflect.getPackage(pkg);
         if (p != null) {
           if (p.isAnnotationPresent(Gwtc.class)) {
             return p;
           }
           if (!findAll) {
             return null;
           }
         }
       } while (pkg.length() > 0);
   }
   return null;
 }