Exemple #1
0
 /** Generates Java source code. */
 public void build(CodeWriter source, CodeWriter resource) throws IOException {
   JPackage[] pkgs = packages.values().toArray(new JPackage[packages.size()]);
   // avoid concurrent modification exception
   for (JPackage pkg : pkgs) pkg.build(source, resource);
   source.close();
   resource.close();
 }
Exemple #2
0
  void build(CodeWriter src, CodeWriter res) throws IOException {

    // write classes
    for (JDefinedClass c : classes.values()) {
      if (c.isHidden()) continue; // don't generate this file

      JFormatter f = createJavaSourceFileWriter(src, c.name());
      f.write(c);
      f.close();
    }

    // write package annotations
    if (annotations != null || jdoc != null) {
      JFormatter f = createJavaSourceFileWriter(src, "package-info");

      if (jdoc != null) f.g(jdoc);

      // TODO: think about importing
      if (annotations != null) {
        for (JAnnotationUse a : annotations) f.g(a).nl();
      }
      f.d(this);

      f.close();
    }

    // write resources
    for (JResourceFile rsrc : resources) {
      CodeWriter cw = rsrc.isResource() ? res : src;
      OutputStream os = new BufferedOutputStream(cw.openBinary(this, rsrc.name()));
      rsrc.build(os);
      os.close();
    }
  }
Exemple #3
0
  /** Dumps the AST. */
  public void dump(CodeWriter w) {
    super.dump(w);

    w.allowBreak(4, " ");
    w.begin(0);
    w.write("(value " + value + ")");
    w.end();
  }
Exemple #4
0
 /** Write the expression to an output file. */
 public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
   w.begin(0);
   w.write("(");
   print(castType, w, tr);
   w.write(")");
   w.allowBreak(2, " ");
   printSubExpr(expr, w, tr);
   w.end();
 }
Exemple #5
0
 public void dump(Object o) {
   Set<Object> cache = CollectionFactory.newHashSet();
   w.write("(");
   dumpObject(o, cache);
   w.write(")");
   w.newline(0);
   try {
     w.flush();
   } catch (IOException e) {
   }
 }
  private void writeImports(CodeWriter writer) throws Exception {
    addImport("java.util.Map");
    //        addImport("java.util.HashMap");
    //        addImport("java.util.Collections");
    addImport("static com.sun.faces.util.CollectionsUtils.*");
    addImport("com.sun.faces.util.CollectionsUtils");
    addImport("static com.sun.faces.renderkit.Attribute.*");
    addImport("com.sun.faces.renderkit.Attribute");

    Collections.sort(imports);

    for (Iterator i = imports.iterator(); i.hasNext(); ) {
      writer.writeImport((String) i.next());
    }
    writer.write('\n');
  } // END writeImports
Exemple #7
0
 protected ClassWriter(Context context) {
   super(context);
   context.put(ClassWriter.class, this);
   options = Options.instance(context);
   attrWriter = AttributeWriter.instance(context);
   codeWriter = CodeWriter.instance(context);
   constantWriter = ConstantWriter.instance(context);
 }
Exemple #8
0
  /**
   * Writes and compresses a single byte to the underlying output stream.
   *
   * @param b byte to write
   * @throws IOException if anything goes wrong
   */
  @Override
  public void write(int b) throws IOException {
    if (prefixCode == -1) {
      prefixCode = b;
    } else {
      int newPrefixCode = table.codeValue(prefixCode, (byte) b);
      if (newPrefixCode != -1) {
        prefixCode = newPrefixCode;
      } else {
        writer.write(prefixCode);
        boolean added = table.add(prefixCode, (byte) b);

        if (added && codeWidthNeedsToBeIncreased()) {
          writer.increaseCodeWidth();
          codeWidth++;
        }

        prefixCode = b;
      }
    }
  }
 private void writeClassEnd(CodeWriter writer) throws Exception {
   writer.outdent();
   writer.fwrite("}\n");
   writer.flush();
   writer.close();
 }
  private void writeClassBody(CodeWriter writer, FacesConfigBean bean) throws Exception {
    writer.indent();
    writer.fwrite(
        "private static Map<String,Attribute[]> ATTRIBUTE_LOOKUP=CollectionsUtils.<String,Attribute[]>map()\n");
    writer.indent();

    ComponentBean[] components = bean.getComponents();
    List<String> keys = new ArrayList<String>();
    for (int i = 0, len = components.length; i < len; i++) {
      ComponentBean comp = components[i];
      if (!comp.getComponentClass().contains("Html")) {
        continue;
      }
      String type = comp.getRendererType();
      if (type != null) {
        String family = comp.getBaseComponentType();
        type = type.substring(type.lastIndexOf('.') + 1);
        family = family.substring(family.lastIndexOf('.') + 1);
        String key = family + type;
        PropertyBean[] props = comp.getProperties();
        boolean attributeWritten = false;
        for (int ii = 0, llen = props.length; ii < llen; ii++) {
          PropertyBean aBean = props[ii];
          if (aBean.isPassThrough()) {
            if ((key.contains("Radio") || "SelectManyCheckbox".equals(key))
                && ("style".equals(aBean.getPropertyName())
                    || ("border".equals(aBean.getPropertyName())))) {
              continue;
            }
            if (attributeWritten) {
              writer.fwrite(",attr(\"");
            } else {
              keys.add(key);
              writer.fwrite(".add(\"");
              writer.write(key);
              writer.write("\",ar(\n");
              writer.indent();
              writer.fwrite("attr(\"");
            }
            writer.write(aBean.getPropertyName());
            writer.write("\"");
            if (aBean.getBehaviors() != null && !aBean.getBehaviors().isEmpty()) {
              for (String behavior : aBean.getBehaviors()) {
                writer.write(",\"");
                String behaviorName;
                if (0 == behavior.length()) {
                  behaviorName = aBean.getPropertyName();
                  // Strip leading "on" preffix.
                  if (behaviorName.length() > 2 && behaviorName.startsWith("on")) {
                    StringBuilder buffer =
                        new StringBuilder(behaviorName.substring(2, 3).toLowerCase());
                    buffer.append(behaviorName.substring(3));
                    behaviorName = buffer.toString();
                  }
                } else {
                  behaviorName = behavior;
                }
                writer.write(behaviorName);
                writer.write("\"");
              }
            }
            writer.write(")\n");
            attributeWritten = true;
          }
          if (key.contains("Button") && "onclick".equals(aBean.getPropertyName())) {
            // reset to the original state
            aBean.setPassThrough(false);
          }
        }
        if (attributeWritten) {
          writer.outdent();
          writer.fwrite("))\n");
        }
      }
    }
    writer.fwrite(".fix();\n");

    //        writer.fwrite("ATTRIBUTE_LOOKUP = Collections.unmodifiableMap(map);\n");
    //        writer.outdent();
    //        writer.fwrite("}\n\n");
    writer.outdent();
    writer.fwrite("public enum Key {\n");
    writer.indent();
    for (int i = 0, len = keys.size(); i < len; i++) {
      String key = keys.get(i);
      writer.fwrite(key.toUpperCase() + "(\"" + key + "\")");
      if (i == (len - 1)) {
        writer.write(";\n");
      } else {
        writer.write(",\n");
      }
    }
    writer.fwrite("private String key;\n");
    writer.fwrite("Key(String key) {\n");
    writer.indent();
    writer.fwrite("this.key = key;\n");
    writer.outdent();
    writer.fwrite("}\n");
    writer.fwrite("public String value() {\n");
    writer.indent();
    writer.fwrite("return this.key;\n");
    writer.outdent();
    writer.fwrite("}\n");
    writer.outdent();
    writer.fwrite("}\n");
    writer.write("\n\n");
    writer.fwrite("public static Attribute[] getAttributes(Key key) {\n");
    writer.indent();
    writer.fwrite("return ATTRIBUTE_LOOKUP.get(key.value());\n");
    writer.outdent();
    writer.fwrite("}\n");
  }
  private void writeClassDeclaration(CodeWriter writer) throws Exception {

    // Generate the class declaration
    writer.writePublicClassDeclaration(TARGET_CLASSNAME, null, null, false, false);
  } // END writeClassDeclaration
  private void writeClassDocumentation(CodeWriter writer) throws Exception {

    writer.writeJavadocComment(
        "This class contains mappings between the standard components\n"
            + "and the passthrough attributes associated with them.");
  } // END writeClassDocumentation
  private void writePackage(CodeWriter writer) throws Exception {

    // Generate the package declaration
    writer.writePackage(TARGET_PACKAGE);
    writer.write('\n');
  } // END writePackage
  private void writeCopyright(CodeWriter writer) throws Exception {

    writer.writeBlockComment(manager.getProperty(PropertyManager.COPYRIGHT));
    writer.write('\n');
  } // END writeCopyright
Exemple #15
0
 public void generateCode(SymbolTable table, CodeWriter writer) throws IOException {
   writer.writeInstr("NOCODE " + toString());
 }
Exemple #16
0
  protected void dumpObject(Object obj, Set<Object> cache) {
    if (obj == null) {
      w.write("null");
      return;
    }

    w.write(StringUtil.getShortNameComponent(obj.getClass().getName()));

    //        w.allowBreak(0, " ");
    //        w.write(obj.toString());

    if (cache.contains(obj)) {
      return;
    }
    cache.add(obj);

    w.allowBreak(1, " ");
    w.begin(0);

    try {
      Field[] fields = obj.getClass().getDeclaredFields();
      java.lang.reflect.AccessibleObject.setAccessible(fields, true);
      for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        if ((field.getModifiers() & modifiersMask) != 0) continue;
        w.write("(");
        w.write(field.getName());
        w.allowBreak(1, " ");
        try {
          Object o = field.get(obj);
          dumpObject(o, cache);
        } catch (IllegalAccessException exn) {
          w.write("##[" + exn.getMessage() + "]");
        }
        w.write(")");
        w.newline(0);
      }
    } catch (SecurityException exn) {
    }

    w.end();
  }
Exemple #17
0
 /** Write the expression to an output file. */
 public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
   w.write(String.valueOf(value));
 }
Exemple #18
0
 private JFormatter createJavaSourceFileWriter(CodeWriter src, String className)
     throws IOException {
   Writer bw = new BufferedWriter(src.openSource(this, className + ".java"));
   return new JFormatter(new PrintWriter(bw));
 }
Exemple #19
0
 /**
  * Finishes the compression by writing out stop code and by flushing anything that haven't been
  * written yet.
  *
  * @throws IOException if anything goes wrong
  */
 public void finish() throws IOException {
   writer.write(prefixCode);
   writer.write(StringTable.STOP_CODE);
   writer.flush();
 }
 public void generateCode(SymbolTable table, CodeWriter writer) throws IOException {
   getLeft().generateCode(table, writer);
   getRight().generateCode(table, writer);
   writer.writeInstr("neq");
 }
 public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
   w.write("adviceexecution()");
 }
Exemple #22
0
  /** Write the statement to an output file. */
  public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
    w.write("for (");
    w.begin(0);

    if (inits != null) {
      boolean first = true;
      for (Iterator i = inits.iterator(); i.hasNext(); ) {
        ForInit s = (ForInit) i.next();
        printForInit(s, w, tr, first);
        first = false;

        if (i.hasNext()) {
          w.write(",");
          w.allowBreak(2, " ");
        }
      }
    }

    w.write(";");
    w.allowBreak(0);

    if (cond != null) {
      printBlock(cond, w, tr);
    }

    w.write(";");
    w.allowBreak(0);

    if (iters != null) {
      for (Iterator i = iters.iterator(); i.hasNext(); ) {
        ForUpdate s = (ForUpdate) i.next();
        printForUpdate(s, w, tr);

        if (i.hasNext()) {
          w.write(",");
          w.allowBreak(2, " ");
        }
      }
    }

    w.end();
    w.write(")");

    printSubStmt(body, w, tr);
  }