Example #1
0
 private void parseExtends(Clazz clazz) {
   TypeRef[] inherits = clazz.getInterfaces();
   if (inherits != null) {
     if (analyzed == null) {
       analyzed = new HashSet<TypeRef>();
     }
     for (TypeRef typeRef : inherits) {
       if (!typeRef.isJava() && analyzed.add(typeRef)) {
         try {
           Clazz inherit = analyzer.findClass(typeRef);
           if (inherit != null) {
             inherit.parseClassFileWithCollector(this);
             parseExtends(inherit);
           } else {
             analyzer.error(
                 "Could not obtain super class %s of class %s",
                 typeRef.getFQN(), clazz.getClassName().getFQN());
           }
         } catch (Exception e) {
           analyzer.error(
               "Could not obtain super class %s of class %s; exception %s",
               typeRef.getFQN(), clazz.getClassName().getFQN(), e.getMessage());
         }
       }
     }
   }
 }
Example #2
0
 private DesignateDef getDef() throws Exception {
   clazz.parseClassFileWithCollector(this);
   if (pid != null && designate != null) {
     if (pids != null && pids.length > 1) {
       analyzer.error(
           "DS Component %s specifies multiple pids %s, and a Designate which requires exactly one pid",
           clazz.getClassName().getFQN(), Arrays.asList(pids));
       return null;
     }
     TypeRef ocdClass = designate.get("ocd");
     // ocdClass = ocdClass.substring(1, ocdClass.length() - 1);
     OCDDef ocd = classToOCDMap.get(ocdClass);
     if (ocd == null) {
       analyzer.error(
           "DS Component %s specifies ocd class %s which cannot be found; known classes %s",
           clazz.getClassName().getFQN(), ocdClass, classToOCDMap.keySet());
       return null;
     }
     String id = ocd.id;
     boolean factoryPid = Boolean.TRUE == designate.get("factory");
     if (def == null) def = new DesignateDef(finder);
     def.ocdRef = id;
     def.pid = pid;
     def.factory = factoryPid;
     ocd.designates.add(def);
     return def;
   }
   return null;
 }
Example #3
0
  private static Map<MethodDef, List<MethodDef>> buildCatalog(Collection<Clazz> sources)
      throws Exception {
    final Map<MethodDef, List<MethodDef>> catalog =
        new TreeMap<MethodDef, List<MethodDef>>(
            new Comparator<MethodDef>() {
              public int compare(MethodDef a, MethodDef b) {
                return a.getName().compareTo(b.getName());
              }
            });
    for (final Clazz clazz : sources) {
      clazz.parseClassFileWithCollector(
          new ClassDataCollector() {

            @Override
            public boolean classStart(int access, TypeRef name) {
              return clazz.isPublic();
            }

            @Override
            public void method(MethodDef source) {
              if (source.isPublic() || source.isProtected())
                catalog.put(source, new ArrayList<MethodDef>());
            }
          });
    }
    return catalog;
  }
Example #4
0
  private OCDDef getDef() throws Exception {
    clazz.parseClassFileWithCollector(this);
    if (ocd != null) {
      topLevel = false;
      parseExtends(clazz);

      doMethods();
    }
    return ocd;
  }
Example #5
0
  private void parseOptionValues(Clazz c, final List<OptionDef> options) throws Exception {

    c.parseClassFileWithCollector(
        new ClassDataCollector() {
          @Override
          public void field(Clazz.FieldDef def) {
            if (def.isEnum()) {
              OptionDef o = new OptionDef(def.getName(), def.getName());
              options.add(o);
            }
          }
        });
  }
Example #6
0
  private static void crossRef(
      Collection<Clazz> source, final Map<MethodDef, List<MethodDef>> catalog) throws Exception {
    for (final Clazz clazz : source) {
      clazz.parseClassFileWithCollector(
          new ClassDataCollector() {
            //				MethodDef	source;

            @Override
            public void implementsInterfaces(TypeRef names[]) {
              MethodDef def = clazz.getMethodDef(0, "<implements>", "()V");
              // TODO
              for (TypeRef interfaceName : names) {
                for (Map.Entry<MethodDef, List<MethodDef>> entry : catalog.entrySet()) {
                  String catalogClass = entry.getKey().getContainingClass().getFQN();
                  List<MethodDef> references = entry.getValue();

                  if (catalogClass.equals(interfaceName.getFQN())) {
                    references.add(def);
                  }
                }
              }
            }

            // Method definitions
            @Override
            public void method(MethodDef source) {
              //					this.source = source;
            }

            // TODO need to use different reference method
            //				public void reference(MethodDef reference) {
            //					List<MethodDef> references = catalog.get(reference);
            //					if (references != null) {
            //						references.add(source);
            //					}
            //				}
          });
    }
  }