예제 #1
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;
 }
 private List<String> dependenciesOf(Package source) {
   List<String> result = new ArrayList<>();
   if (source.isAnnotationPresent(DependsUpon.class))
     for (Class<?> target : source.getAnnotation(DependsUpon.class).packagesOf())
       result.add(target.getPackage().getName());
   return result;
 }
예제 #3
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;
 }