Beispiel #1
0
 protected void dumpScript(RuleScript ruleScript) {
   String file = ruleScript.getFile();
   int line = ruleScript.getLine();
   if (file != null) {
     System.out.println("# " + file + " line " + line);
   }
   System.out.println("RULE " + ruleScript.getName());
   if (ruleScript.isInterface()) {
     System.out.println("INTERFACE " + ruleScript.getTargetClass());
   } else {
     System.out.println("CLASS " + ruleScript.getTargetClass());
   }
   System.out.println("METHOD " + ruleScript.getTargetMethod());
   if (ruleScript.getTargetHelper() != null) {
     System.out.println("HELPER " + ruleScript.getTargetHelper());
   }
   System.out.println(ruleScript.getTargetLocation());
   System.out.println(ruleScript.getRuleText());
   System.out.println("ENDRULE");
 }
Beispiel #2
0
  /**
   * constructor allowing this transformer to be provided with access to the JVM's instrumentation
   * implementation
   *
   * @param inst the instrumentation object used to interface to the JVM
   * @param scriptPaths list of file paths for each input script
   * @param scriptTexts the text of each input script
   * @param isRedefine true if class redefinition is allowed false if not
   * @throws Exception if a script is in error
   */
  public Transformer(
      Instrumentation inst, List<String> scriptPaths, List<String> scriptTexts, boolean isRedefine)
      throws Exception {
    this.inst = inst;
    this.isRedefine = isRedefine;
    scriptRepository = new ScriptRepository(skipOverrideRules);
    loadCache = new LoadCache(inst);
    helperManager = new HelperManager(inst);

    Iterator<String> scriptsIter = scriptTexts.iterator();
    Iterator<String> filesIter = scriptPaths.iterator();
    while (scriptsIter.hasNext()) {
      String scriptText = scriptsIter.next();
      String file = filesIter.next();
      List<RuleScript> ruleScripts = scriptRepository.processScripts(scriptText, file);
      for (RuleScript ruleScript : ruleScripts) {
        String name = ruleScript.getName();
        RuleScript previous = scriptRepository.scriptForRuleName(name);
        if (previous == null) {
          scriptRepository.addScript(ruleScript);
        } else {
          StringBuffer buffer = new StringBuffer();
          buffer.append("Transformer : duplicate script name ");
          buffer.append(name);
          buffer.append("in file ");
          buffer.append(ruleScript.getFile());
          buffer.append("  line ");
          buffer.append(ruleScript.getLine());
          buffer.append("\n previously defined in file ");
          buffer.append(previous.getFile());
          buffer.append("  line ");
          buffer.append(previous.getLine());
          Exception ex = new Exception(buffer.toString());
          throw ex;
        }
      }
    }
  }