Ejemplo n.º 1
0
 public int compareTo(SplitterObject o) {
   return this.guid - o.getGUID();
 }
  /**
   * Creates a new instance of SplitterJavaSource.
   *
   * @param splitObj the SplitterObject for which this splitter java file is be written.
   * @param pptName the name of the Ppt to which splitObj belongs.
   * @param fileName the name of the file that should be written by the new SplitterJavaSource.
   * @param varInfos the varInfos for this the Ppt to which splitObj belongs.
   * @param statementReplacer a statementReplacer for the .spinfo file from which splitObj is being
   *     created from.
   */
  public SplitterJavaSource(
      SplitterObject splitObj,
      String pptName,
      String fileName,
      VarInfo[] varInfos,
      StatementReplacer statementReplacer)
      throws ParseException {
    className = getClassName(pptName);
    this.fileName = fileName;
    this.statementReplacer = statementReplacer;
    varInfos = filterNonVars(varInfos);
    String originalCondition = splitObj.condition();
    String condition = replaceReservedWords(originalCondition);
    condition = this.statementReplacer.makeReplacements(condition);
    condition = convertVariableNames(condition, className, varInfos);
    vars = makeVariableManagerArray(varInfos, condition, className);

    // extra white space at the end of lines used only to increase readability.
    add("import daikon.*; ");
    add("import daikon.inv.*; ");
    add("import daikon.split.*; ");
    skipLine();
    add("public final class " + fileName + " extends Splitter { ");
    skipLine();
    add("  public String condition() { ");
    add("    return \"" + protectQuotations(originalCondition) + "\"; ");
    add("  } ");
    skipLine();
    writeFields();
    skipLine();
    add("  static DummyInvariant dummyInvFactory;");
    add("  DummyInvariant dummyInv;");
    skipLine();
    add("  public " + fileName + "() { } ");
    add("  public " + fileName + "(Ppt ppt) { ");
    writeConstructorBody();
    add("  }");
    skipLine();
    add("  public Splitter instantiate(Ppt ppt) { ");
    add("    return new " + fileName + "(ppt); ");
    add("  } ");
    skipLine();
    add("  public boolean valid() { ");
    writeValidBody();
    add("  } ");
    skipLine();
    add("  public boolean test(ValueTuple vt) { ");
    writeTestBody();
    add("    return(" + NullReplacer.replaceNull(condition) + "); ");
    add("  } ");
    skipLine();
    add("  public String repr() { ");
    writeReprBody();
    add("  } ");
    skipLine();
    add("  public void makeDummyInvariant(DummyInvariant inv) { ");
    add("    dummyInvFactory = inv; ");
    add("  } ");
    skipLine();
    add("  public void instantiateDummy(PptTopLevel ppt) { ");
    add("    dummyInv = null; ");
    writeInstantiateDummyBody();
    add("  } ");
    skipLine();
    add("  public DummyInvariant getDummyInvariant() { ");
    add("    return dummyInv; ");
    add("  } ");
    skipLine();
    add("  public int[] getIntArray(long[] longArray) { ");
    add("    int[] intArray = new int[longArray.length]; ");
    add("    for (int i = 0; i < intArray.length; i++) { ");
    add("      intArray[i] = (int) longArray[i]; ");
    add("    } ");
    add("    return intArray; ");
    add("  } ");
    skipLine();
    add("} ");
  }