Пример #1
0
  public static void leadFlow(BytecodeContext bc, Statement stat, int flowType, String label)
      throws BytecodeException {
    List<FlowControlFinal> finallyLabels = new ArrayList<FlowControlFinal>();

    FlowControl fc;
    String name;
    if (FlowControl.BREAK == flowType) {
      fc = ASMUtil.getAncestorBreakFCStatement(stat, finallyLabels, label);
      name = "break";
    } else if (FlowControl.CONTINUE == flowType) {
      fc = ASMUtil.getAncestorContinueFCStatement(stat, finallyLabels, label);
      name = "continue";
    } else {
      fc = ASMUtil.getAncestorRetryFCStatement(stat, finallyLabels, label);
      name = "retry";
    }

    if (fc == null)
      throw new BytecodeException(
          name + " must be inside a loop (for,while,do-while,<cfloop>,<cfwhile> ...)",
          stat.getStart());

    GeneratorAdapter adapter = bc.getAdapter();

    Label end;
    if (FlowControl.BREAK == flowType) end = ((FlowControlBreak) fc).getBreakLabel();
    else if (FlowControl.CONTINUE == flowType) end = ((FlowControlContinue) fc).getContinueLabel();
    else end = ((FlowControlRetry) fc).getRetryLabel();

    // first jump to all final labels
    FlowControlFinal[] arr = finallyLabels.toArray(new FlowControlFinal[finallyLabels.size()]);
    if (arr.length > 0) {
      FlowControlFinal fcf;
      for (int i = 0; i < arr.length; i++) {
        fcf = arr[i];

        // first
        if (i == 0) {
          adapter.visitJumpInsn(Opcodes.GOTO, fcf.getFinalEntryLabel());
        }

        // last
        if (arr.length == i + 1) fcf.setAfterFinalGOTOLabel(end);
        else fcf.setAfterFinalGOTOLabel(arr[i + 1].getFinalEntryLabel());
      }

    } else bc.getAdapter().visitJumpInsn(Opcodes.GOTO, end);
  }
Пример #2
0
  @Override
  public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {

    // check parent
    Body body = null;

    String compName = Property.getComponentName(tag);

    boolean isCompChild = false;
    Tag p = ASMUtil.getParentTag(tag);

    if (p != null && (p instanceof TagComponent || getFullname(p, "").equalsIgnoreCase(compName))) {
      isCompChild = true;
      body = p.getBody();
    }

    Tag pp = p != null ? ASMUtil.getParentTag(p) : null;
    if (!isCompChild
        && pp != null
        && (p instanceof TagComponent || getFullname(pp, "").equalsIgnoreCase(compName))) {
      isCompChild = true;
      body = pp.getBody();
    }

    if (!isCompChild) {
      throw new EvaluatorException(
          "Wrong Context for the the static constructor, "
              + "a static constructor must inside a component body.");
    }

    // Body body=(Body) tag.getParent();
    List<Statement> children = tag.getBody().getStatements();

    // remove that tag from parent
    ASMUtil.remove(tag);

    StaticBody sb = getStaticBody(body);
    ASMUtil.addStatements(sb, children);
  }
Пример #3
0
  public static byte[] createPojo(
      String className, ASMProperty[] properties, Class parent, Class[] interfaces, String srcName)
      throws PageException {
    className = className.replace('.', '/');
    className = className.replace('\\', '/');
    className = ListUtil.trim(className, "/");
    String[] inter = null;
    if (interfaces != null) {
      inter = new String[interfaces.length];
      for (int i = 0; i < inter.length; i++) {
        inter[i] = interfaces[i].getName().replace('.', '/');
      }
    }
    // CREATE CLASS
    ClassWriter cw = ASMUtil.getClassWriter();
    cw.visit(
        Opcodes.V1_6,
        Opcodes.ACC_PUBLIC,
        className,
        null,
        parent.getName().replace('.', '/'),
        inter);
    String md5;
    try {
      md5 = createMD5(properties);
    } catch (Throwable t) {
      md5 = "";
      t.printStackTrace();
    }

    FieldVisitor fv =
        cw.visitField(
            Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
            "_md5_",
            "Ljava/lang/String;",
            null,
            md5);
    fv.visitEnd();

    // Constructor
    GeneratorAdapter adapter =
        new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_OBJECT, null, null, cw);
    adapter.loadThis();
    adapter.invokeConstructor(toType(parent, true), CONSTRUCTOR_OBJECT);
    adapter.returnValue();
    adapter.endMethod();

    // properties
    for (int i = 0; i < properties.length; i++) {
      createProperty(cw, className, properties[i]);
    }

    // complexType src
    if (!StringUtil.isEmpty(srcName)) {
      GeneratorAdapter _adapter =
          new GeneratorAdapter(
              Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
              _SRC_NAME,
              null,
              null,
              cw);
      _adapter.push(srcName);
      _adapter.returnValue();
      _adapter.endMethod();
    }

    cw.visitEnd();
    return cw.toByteArray();
  }