@Override
    public void process(CompilationUnitDeclaration cud, int i) {
      super.process(cud, i);
      ClassFile[] classFiles = cud.compilationResult().getClassFiles();
      Map<ClassFile, CompiledClass> results = new LinkedHashMap<ClassFile, CompiledClass>();
      for (ClassFile classFile : classFiles) {
        createCompiledClass(classFile, results);
      }
      List<CompiledClass> compiledClasses = new ArrayList<CompiledClass>(results.values());
      addBinaryTypes(compiledClasses);

      ICompilationUnit icu = cud.compilationResult().compilationUnit;
      Adapter adapter = (Adapter) icu;
      CompilationUnitBuilder builder = adapter.getBuilder();

      // TODO this code was added for the arquillian gwt extension
      if (cud.types != null) {
        for (TypeDeclaration type : cud.types) {
          if (type.methods != null) {
            if (isAnnotationPresent(RunWith.class.getSimpleName(), type.annotations)) {
              Set<AbstractMethodDeclaration> filteredMethods =
                  new HashSet<AbstractMethodDeclaration>();
              boolean match = false;
              for (AbstractMethodDeclaration decl : type.methods) {
                if (decl.annotations != null) {
                  // TODO make this configurable
                  if ((isAnnotationPresent(RunAsGwtClient.class.getSimpleName(), decl.annotations)
                          || isAnnotationPresent(
                              RunAsGwtClient.class.getSimpleName(), type.annotations))
                      && !isAnnotationPresent(Deployment.class.getSimpleName(), decl.annotations)) {
                    filteredMethods.add(decl);
                  } else {
                    match = true;
                    System.out.println("Ignoring non-translatable method:\n" + decl.toString());
                  }
                }
              }
              if (match) {
                type.methods =
                    filteredMethods.toArray(new AbstractMethodDeclaration[filteredMethods.size()]);
              }
            }
          }
        }
      }

      processor.process(builder, cud, compiledClasses);
    }
Esempio n. 2
0
  public void printAttributeName(PrintNode row, AttributePath attributePath, Adapter scda)
      throws Exception {
    for (int j = 0; j < attributes.size(); j++) {
      Attribute currentAttribute = (Attribute) attributes.get(j);
      int attributeLength = currentAttribute.name.length() + 2;

      if (currentAttribute.getClass() == DVA.class && attributePath.levelsOfIndirection() <= 0) {
        // If the attribute we want is found or we just want everything, output
        if (attributePath.attribute.equals("*")) {
          PrintCell cell = new PrintCell();
          cell.setOutput(String.format("%s", currentAttribute.name));
          row.addCell(cell);
        } else if (attributePath.attribute.equals(currentAttribute.name)) {
          PrintCell cell = new PrintCell();
          cell.setOutput(String.format("%s", currentAttribute.name));
          row.addCell(cell);
          return;
        }
      }
      if (currentAttribute.getClass() == EVA.class && attributePath.levelsOfIndirection() > 0) {
        String evaName = attributePath.getIndirection(attributePath.levelsOfIndirection() - 1);
        if (evaName.equals(currentAttribute.name)) {
          ClassDef targetClass = scda.getClass(((EVA) currentAttribute).baseClassName);
          attributePath.removeIndirection(attributePath.levelsOfIndirection() - 1);
          targetClass.printAttributeName(row, attributePath, scda);
          attributePath.addIndirection(evaName);
          return;
        }
      }
    }

    // Got here if we didn't get what we need in this class
    int i = 0;
    while (i < superClasses.size()) {
      try {
        ClassDef superClass = scda.getClass(((String) superClasses.get(i)));
        superClass.printAttributeName(row, attributePath, scda);
        i++;
      } catch (NoSuchFieldException nsfe) {
        if (i < superClasses.size()) {
          i++;
        } else {
          throw nsfe;
        }
      }
    }
  }
Esempio n. 3
0
  public void padAttribute(PrintNode row, AttributePath attributePath, Adapter scda)
      throws Exception {
    for (int j = 0; j < attributes.size(); j++) {
      Attribute currentAttribute = (Attribute) attributes.get(j);
      int attributeLength = currentAttribute.name.length();

      if (currentAttribute.getClass() == DVA.class && attributePath.levelsOfIndirection() <= 0) {
        // If the attribute we want is found or we just want everything, output
        if (attributePath.attribute.equals("*")) {
          PrintCell cell = new PrintCell();
          cell.setOutput(String.format(""));
          row.addCell(cell);
        } else if (attributePath.attribute.equals(currentAttribute.name)) {
          PrintCell cell = new PrintCell();
          cell.setOutput(String.format(""));
          row.addCell(cell);
          return;
        }
      }
      if (currentAttribute.getClass() == EVA.class && attributePath.levelsOfIndirection() > 0) {
        String evaName = attributePath.getIndirection(attributePath.levelsOfIndirection() - 1);
        if (evaName.equals(currentAttribute.name)) {
          ClassDef targetClass = scda.getClass(((EVA) currentAttribute).baseClassName);
          attributePath.removeIndirection(attributePath.levelsOfIndirection() - 1);
          targetClass.padAttribute(row, attributePath, scda);
          attributePath.addIndirection(evaName);
          return;
        }
      }
    }

    if (!(attributePath.attribute.equals("*") && attributePath.levelsOfIndirection() <= 0)) {
      // If we got here and we weren't trying to output all the attributes, we didn't find the
      // requested attribute.

      if (this.getClass() == SubclassDef.class) {
        for (int i = 0; i < ((SubclassDef) this).numberOfSuperClasses(); i++) {
          ClassDef parentClass = scda.getClass(((SubclassDef) this).getSuperClass(i));
          parentClass.padAttribute(row, attributePath, scda);
        }
      } else {
        throw new NoSuchFieldException(
            "Attribute \"" + attributePath.attribute + "\" is not a valid DVA");
      }
    }
  }
Esempio n. 4
0
 public static void main(String[] args) {
   // Adapt a Collection:
   List<Coffee> carrier = new ArrayList<Coffee>();
   Fill2.fill(new AddableCollectionAdapter<Coffee>(carrier), Coffee.class, 3);
   // Helper method captures the type:
   Fill2.fill(Adapter.collectionAdapter(carrier), Latte.class, 2);
   for (Coffee c : carrier) print(c);
   print("----------------------");
   // Use an adapted class:
   AddableSimpleQueue<Coffee> coffeeQueue = new AddableSimpleQueue<Coffee>();
   Fill2.fill(coffeeQueue, Mocha.class, 4);
   Fill2.fill(coffeeQueue, Latte.class, 1);
   for (Coffee c : coffeeQueue) print(c);
 }
Esempio n. 5
0
 public boolean isSubclassOf(String superClassName, Adapter scda) throws Exception {
   // See if its one of my immediate superclasses.
   if (superClasses.contains(superClassName)) {
     return true;
   }
   // Not immediate superclass of me. Check my parents.
   ClassDef superClass;
   for (int i = 0; i < superClasses.size(); i++) {
     superClass = scda.getClass(((String) superClasses.get(i)));
     if (superClass.isSubclassOf(superClassName, scda)) {
       return true;
     }
   }
   // Not any superClass of mine!
   return false;
 }
Esempio n. 6
0
  public WDBObject newInstance(WDBObject baseParent, Adapter scda) throws Exception {
    Integer newUid = new Integer(Math.abs((new UID()).hashCode()));
    WDBObject newObject =
        new WDBObject(
            new Hashtable<String, Integer>(),
            new Hashtable<String, Integer>(),
            new Hashtable<String, Object>(),
            new Hashtable<String, Object>(),
            this.name,
            newUid);

    for (int i = 0; i < this.superClasses.size(); i++) {
      ClassDef superClass = scda.getClass((String) this.superClasses.get(i));
      WDBObject parent;
      if (baseParent == null || !superClass.name.equals(baseParent.getClassName())) {
        if (superClass.getClass() == SubclassDef.class) {
          // If this super class is another subclass, then create a new instance of one of those
          // with this object as the child and the parent we want to attach to
          parent = superClass.newInstance(baseParent, scda);
        } else {
          // If this super class is a base class, then create a new isntance but don't pass the
          // parent we want to attach since its a base class
          parent = superClass.newInstance(null, scda);
        }
      } else {
        // The base parent is my immediate parent
        parent = baseParent;
      }

      WDBObject childObject = parent.getChildObject(this.name, scda);

      if (childObject != null) {
        // Parent alreadly extended to this class, just return the child instance
        return childObject;
      }

      parent.addChildObject(newObject);
      parent.commit(scda);
      newObject.addParentObject(parent);
    }

    this.addInstance(newUid);
    this.commit(scda);

    return newObject;
  }
Esempio n. 7
0
 public WDBObject getInstance(int index, Adapter da) throws Exception {
   return da.getObject(this.name, (Integer) instances.get(index));
 }
Esempio n. 8
0
 public void commit(Adapter scda) throws Exception {
   scda.putClass(this);
 }
Esempio n. 9
0
 public ClassDef getBaseClass(Adapter scda) throws Exception {
   // Assume all of our superclasses go back to the same base class alreadly
   ClassDef superClass;
   superClass = scda.getClass(((String) superClasses.get(0)));
   return superClass.getBaseClass(scda);
 }