/** * Properly indents the line that the caret is currently on. Replaces all whitespace characters at * the beginning of the line with the appropriate spacing or characters. Assumes read lock is * already held. * * @param doc AbstractDJDocument containing the line to be indented. * @param reason The reason that the indentation is taking place * @return true if the caller should update the current location itself, false if the indenter has * already handled it */ public void indentLine(AbstractDJDocument doc, Indenter.IndentReason reason) { super.indentLine(doc, reason); // This call does nothing other than record some indent tracing int pos = doc.getCurrentLocation(); // Utilities.show("indentLine in ActionStartStmtOfBracePlus called on doc:\n" + doc.getText() // + "'\nat location " + pos); // Get distance to brace int lineStart = doc._getLineStartPos(pos); if (lineStart < 0) lineStart = 0; BraceInfo info = doc._getLineEnclosingBrace(); int distToLineEnclosingBrace = info.distance(); // System.err.println("dist to brace = " + distToLineEnclosingBrace); // If there is no brace, align to left margin; can't happen when called from rule 19 if (distToLineEnclosingBrace == -1) { doc.setTab(_suffix, pos); return; } // Get the absolute position of (the left edge of) the line enclosing brace final int bracePos = lineStart - distToLineEnclosingBrace; // System.err.println("bracePos = " + bracePos); final int indent = doc._getIndentOfCurrStmt(bracePos) + _suffix; // System.err.println("indent = " + doc._getIndentOfCurrStmt(bracePos)); doc.setTab(indent, pos); }
/** * @param doc The AbstractDJDocument containing the current line. * @param reason The reason the indentation is being done * @return True iff the last block or expression list opened previous to the start of the current * line was opened by one of the characters '(' or '['. */ protected boolean applyRule(AbstractDJDocument doc, Indenter.IndentReason reason) { // PRE: We are not inside a multiline comment. // IndentInfo info = doc.getIndentInformation(); // //// We are using fields on IndentInfo which look at the start of the line, not the current // position! // // return info.lineEnclosingBraceType().equals(IndentInfo.OPEN_PAREN) || // info.lineEnclosingBraceType().equals(IndentInfo.OPEN_BRACKET); BraceInfo info = doc._getLineEnclosingBrace(); String braceType = info.braceType(); return braceType.equals(BraceInfo.OPEN_PAREN) || braceType.equals(BraceInfo.OPEN_BRACKET); }