Ejemplo n.º 1
0
  public byte[] generateClass(Context context, IStrategoTerm file) {
    if (isTermAppl(file)) {
      IStrategoAppl appl = (IStrategoAppl) file;

      if (hasConstructor(appl, FILE_CONS, FILE_ARITY)) {
        IStrategoTerm header = Tools.termAt(appl, 0);
        IStrategoTerm fields = Tools.termAt(appl, 1);
        IStrategoTerm methods = Tools.termAt(appl, 2);

        return generateClass(context, header, fields, methods);
      } else {
        return null;
      }
    } else {
      return null;
    }
  }
Ejemplo n.º 2
0
  public void visitFields(ClassWriter cw, Context context, IStrategoTerm fields) {
    if (Tools.isTermList(fields)) {
      IStrategoList list = (IStrategoList) fields;

      for (IStrategoTerm field : list) {
        visitField(cw, context, field);
      }
    } else {
      throw new IllegalArgumentException("Invalid FieldSpecs, not a list.");
    }
  }
Ejemplo n.º 3
0
  public void visitField(ClassWriter cw, Context context, IStrategoTerm field) {
    if (Tools.isTermAppl(field)) {
      IStrategoAppl appl = (IStrategoAppl) field;

      if (hasConstructor(appl, "JBCField", 5)) {
        IStrategoTerm flags = termAt(appl, 0);
        IStrategoTerm name = termAt(appl, 1);
        IStrategoTerm desc = termAt(appl, 2);
        IStrategoTerm sig = termAt(appl, 3);
        IStrategoTerm initial = termAt(appl, 4);

        visitField(cw, context, flags, name, desc, sig, initial);
      } else {
        throw new IllegalArgumentException("Invalid FieldSpec.");
      }
    } else {
      throw new IllegalArgumentException("Invalid FieldSpec.");
    }
  }