| 1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import edu.rice.cs.drjava.model.AbstractDJDocument; 37 38 import java.util.Vector ; 40 import java.io.PrintStream ; 41 42 48 public abstract class IndentRuleWithTrace implements IndentRule{ 49 50 private static Vector <String > trace = null; 51 private static boolean startOver = true; 52 private static boolean ruleTraceEnabled = false; 53 54 public static final String YES = "Yes"; 55 public static final String NO = "No"; 56 public static final String TERMINUS_RULE = ""; 57 58 59 public static void printLastIndentTrace(PrintStream ps) { 60 if (trace == null) { 61 ps.println("No trace to print"); 62 } else { 63 for (int x = 0; x < trace.size(); x++) { 64 ps.println(trace.get(x)); 65 } 66 ps.println("******************************"); 67 } 68 } 69 70 public static void setRuleTraceEnabled(boolean ruleTraceEnabled) { 71 IndentRuleWithTrace.ruleTraceEnabled = ruleTraceEnabled; 72 } 73 74 static Vector <String > getTrace() { 75 return trace; 76 } 77 78 81 protected static void _addToIndentTrace(String ruleName, String direction, boolean terminus) { 82 if (ruleTraceEnabled) { 83 if (startOver) { 84 trace = new Vector <String >(); 85 } 86 startOver = terminus; 87 trace.add(ruleName + " " + direction); 88 } 89 } 90 91 92 101 public boolean indentLine(AbstractDJDocument doc, int pos, int reason) { 102 int oldPos = doc.getCurrentLocation(); 103 doc.setCurrentLocation(pos); 104 indentLine(doc, reason); 105 if (oldPos > doc.getLength()) oldPos = doc.getLength(); 106 doc.setCurrentLocation(oldPos); 107 return false; 108 } 109 110 public boolean indentLine(AbstractDJDocument doc, int reason) { 111 _addToIndentTrace(getRuleName(), TERMINUS_RULE, true); 112 113 return true; 116 } 117 118 119 public String getRuleName() { return this.getClass().getName(); } 120 } 121 | Popular Tags |