1 22 23 package org.gjt.sp.jedit.indent; 24 25 import java.util.List ; 26 import org.gjt.sp.jedit.buffer.JEditBuffer; 27 import org.gjt.sp.jedit.TextUtilities; 28 29 33 public class CloseBracketIndentRule extends BracketIndentRule 34 { 35 public CloseBracketIndentRule(char closeBracket, boolean aligned) 37 { 38 super(TextUtilities.getComplementaryBracket(closeBracket, 39 new boolean[1]),closeBracket); 40 this.aligned = aligned; 41 } 43 public void apply(JEditBuffer buffer, int thisLineIndex, 45 int prevLineIndex, int prevPrevLineIndex, 46 List <IndentAction> indentActions) 47 { 48 int index; 49 if(aligned) 50 index = thisLineIndex; 51 else 52 index = prevLineIndex; 53 54 if(index == -1) 55 return; 56 57 String line = buffer.getLineText(index); 58 59 int offset = line.lastIndexOf(closeBracket); 60 if(offset == -1) 61 return; 62 63 int closeCount = getBrackets(line).closeCount; 64 if(closeCount != 0) 65 { 66 IndentAction.AlignBracket alignBracket 67 = new IndentAction.AlignBracket( 68 buffer,index,offset); 69 83 String openLine = alignBracket.getOpenBracketLine(); 84 int column = alignBracket.getOpenBracketColumn(); 85 if(openLine != null) 86 { 87 String leadingBrackets = openLine.substring(0,column); 88 alignBracket.setExtraIndent(getBrackets(leadingBrackets) 89 .openCount); 90 } 91 92 indentActions.add(alignBracket); 93 } 94 } 96 public boolean isMatch(String line) 98 { 99 return getBrackets(line).closeCount != 0; 100 } 102 private boolean aligned; 103 } 104 | Popular Tags |