1 33 34 package edu.rice.cs.drjava.model.definitions.indent; 35 36 import edu.rice.cs.drjava.model.AbstractDJDocument; 37 import edu.rice.cs.drjava.model.definitions.reducedmodel.IndentInfo; 38 39 43 public class ActionBracePlus extends IndentRuleAction { 44 45 private String _suffix; 46 47 48 public ActionBracePlus(String suffix) { _suffix = suffix; } 49 50 56 public boolean indentLine(AbstractDJDocument doc, int reason) { 57 boolean supResult = super.indentLine(doc, reason); 58 int here = doc.getCurrentLocation(); 59 int startLine = doc.getLineStartPos(here); 60 doc.setCurrentLocation(startLine); 61 IndentInfo ii = doc.getIndentInformation(); 62 63 if ((ii.braceType.equals("")) || 65 (ii.distToBrace < 0)) { 66 return supResult; 68 } 69 70 int bracePos = startLine - ii.distToBrace; 72 int braceNewLine = 0; 73 if (ii.distToNewline >=0) { 74 braceNewLine = startLine - ii.distToNewline; 75 } 76 int braceLen = bracePos - braceNewLine; 77 78 final StringBuilder tab = new StringBuilder (_suffix.length() + braceLen); 80 for (int i=0; i < braceLen; i++) { 81 tab.append(" "); 82 } 83 tab.append(_suffix); 84 85 if (here > doc.getLength()) { 86 here = doc.getLength() - 1; 87 } 88 doc.setCurrentLocation(here); 89 90 doc.setTab(tab.toString(), here); 91 92 return supResult; 93 } 94 } 95 | Popular Tags |