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.DrJava; 38 import edu.rice.cs.drjava.config.OptionConstants; 39 40 43 public class Indenter { 44 45 public Indenter(int indentLevel) { buildTree(indentLevel); } 46 47 48 49 52 public static final int ENTER_KEY_PRESS = 1; 53 54 57 public static final int OTHER = 0; 58 59 60 protected IndentRule _topRule; 61 62 65 public void buildTree(int indentLevel) { 66 char[] indent = new char[indentLevel]; 67 java.util.Arrays.fill(indent,' '); 68 final String oneLevel = new String (indent); 69 70 boolean autoCloseComments = DrJava.getConfig().getSetting(OptionConstants.AUTO_CLOSE_COMMENTS).booleanValue(); 71 72 IndentRule 73 rule37 = new ActionStartCurrStmtPlus(oneLevel), 75 rule36 = new ActionStartStmtOfBracePlus(oneLevel), 76 rule35 = rule37, 77 rule34 = new QuestionExistsCharInStmt('?', ':', rule35, rule36), 78 rule33 = new QuestionLineContains(':', rule34, rule37), 79 rule32 = new ActionStartCurrStmtPlus(""), 80 rule31 = new QuestionCurrLineStartsWithSkipComments("{", rule32, rule33), 81 rule39 = new ActionStartPrevStmtPlus("", true), 82 rule29 = rule36, 83 rule28 = new ActionStartPrevStmtPlus("", false), 84 rule40 = rule28, 85 rule30 = new QuestionExistsCharInPrevStmt('?', rule40, rule39), 86 rule27 = new QuestionExistsCharInStmt('?', ':', rule28, rule29), 87 rule26 = new QuestionLineContains(':', rule27, rule30), 88 rule25 = new QuestionStartingNewStmt(rule26, rule31), rule24 = rule25, 90 rule23 = rule36, 91 rule22 = new QuestionHasCharPrecedingOpenBrace(new char[] {'=',',','{'},rule23,rule24), 92 rule21 = rule36, 93 rule20 = new QuestionStartAfterOpenBrace(rule21, rule22), 94 rule19 = new ActionStartStmtOfBracePlus(""), 95 rule18 = new QuestionCurrLineStartsWithSkipComments("}", rule19, rule20), rule17 = new QuestionBraceIsCurly(rule18, rule25), rule16 = new ActionBracePlus(" " + oneLevel), 98 rule15 = new ActionBracePlus(" "), 99 rule38 = new QuestionCurrLineStartsWith(")", rule30, rule15), rule14 = new QuestionNewParenPhrase(rule38, rule16), rule13 = new QuestionBraceIsParenOrBracket(rule14, rule17), 103 rule12 = new ActionStartPrevLinePlus(""), 105 rule11 = rule12, 106 rule10 = new ActionStartPrevLinePlus("* "), 107 rule09 = new QuestionCurrLineEmptyOrEnterPress(rule10, rule11), 108 rule08 = rule12, 109 rule07 = new QuestionCurrLineStartsWith("*", rule08, rule09), 110 rule06 = new QuestionPrevLineStartsWith("*", rule07, rule12), 111 rule05 = new ActionStartPrevLinePlus(" "), rule04 = new ActionStartPrevLinePlus(" * "), rule46 = new ActionStartPrevLinePlus(" * "), rule47 = new ActionStartPrevLinePlus(" "), rule45 = new QuestionPrevLineStartsJavaDocWithText(rule46, rule04), rule48 = new QuestionPrevLineStartsJavaDocWithText(rule47, rule05), rule41 = new ActionStartPrevLinePlusMultilinePreserve(new String [] { " * \n", " */" }, 0, 3, 0, 3), 118 rule49 = new ActionStartPrevLinePlusMultilinePreserve(new String [] { " * \n", " */"}, 0, 4, 0, 4), 119 rule50 = new QuestionPrevLineStartsJavaDocWithText(rule49, rule41), 120 121 rule03 = new QuestionCurrLineEmptyOrEnterPress(rule45, rule48), 122 rule42 = new QuestionFollowedByStar(rule04, rule41), 123 rule51 = new QuestionCurrLineEmpty(rule50, rule03), rule02 = new QuestionPrevLineStartsComment(autoCloseComments ? rule51 : rule03, rule06), 128 rule43 = new ActionDoNothing(), 129 rule44 = new QuestionCurrLineIsWingComment(rule43, rule13), 130 rule01 = new QuestionInsideComment(rule02, rule44); 131 132 _topRule = rule01; 133 } 134 135 139 public boolean indent(AbstractDJDocument doc, int reason) { 140 return _topRule.indentLine(doc, reason); 142 } 143 } 144 145 146 147 | Popular Tags |