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.util.UnexpectedException; 38 39 import javax.swing.text.BadLocationException ; 40 41 48 public class ActionStartPrevStmtPlus extends IndentRuleAction { 49 private String _suffix; 50 private boolean _useColon; 51 52 57 public ActionStartPrevStmtPlus(String suffix, boolean colonIsDelim) { 58 super(); 59 _suffix = suffix; 60 _useColon = colonIsDelim; 61 } 62 63 72 public boolean indentLine(AbstractDJDocument doc, int reason) { 73 boolean supResult = super.indentLine(doc, reason); 74 String indent = ""; 75 int here = doc.getCurrentLocation(); 76 77 char[] delims = {';', '{', '}'}; 79 int lineStart = doc.getLineStartPos(here); 80 int prevDelimiterPos; 81 try { 82 prevDelimiterPos = doc.findPrevDelimiter(lineStart, delims); 83 } catch (BadLocationException e) { 84 throw new UnexpectedException(e); 86 } 87 88 if (prevDelimiterPos <= AbstractDJDocument.DOCSTART) { 90 doc.setTab(_suffix, here); 91 return supResult; 92 } 93 94 try { 95 char delim = doc.getText(prevDelimiterPos, 1).charAt(0); 96 char[] ws = {' ', '\t', '\n', ';'}; 97 if (delim == ';') { 98 int testPos = doc.findPrevCharPos(prevDelimiterPos, ws); 99 if (doc.getText(testPos,1).charAt(0) == '}') { 100 prevDelimiterPos = testPos; 101 } 102 } 103 } catch (BadLocationException e) { 104 } 106 107 try { 108 char delim = doc.getText(prevDelimiterPos, 1).charAt(0); 110 111 if (delim == '}') { 112 doc.resetReducedModelLocation(); 115 116 int dist = prevDelimiterPos - here + 1; 117 118 doc.move(dist); 119 prevDelimiterPos -= doc.balanceBackward() - 1; 120 doc.move(-dist); 121 122 } 123 } 124 catch (BadLocationException e) { throw new UnexpectedException(e); } 125 126 127 try { 129 char[] indentDelims; 131 char[] indentDelimsWithColon = {';', '{', '}', ':'}; 132 char[] indentDelimsWithoutColon = {';', '{', '}'}; 133 if (_useColon) indentDelims = indentDelimsWithColon; 134 else indentDelims = indentDelimsWithoutColon; 135 136 indent = doc.getIndentOfCurrStmt(prevDelimiterPos, indentDelims); 137 138 } catch (BadLocationException e) { 139 throw new UnexpectedException(e); 140 } 141 142 indent = indent + _suffix; 143 doc.setTab(indent, here); 144 return supResult; 145 } 146 147 } 158 159 | Popular Tags |