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 OpenBracketIndentRule extends BracketIndentRule 34 { 35 public OpenBracketIndentRule(char openBracket, boolean aligned) 37 { 38 super(openBracket, 39 TextUtilities.getComplementaryBracket(openBracket, 40 new boolean[1])); 41 this.aligned = aligned; 42 } 44 public void apply(JEditBuffer buffer, int thisLineIndex, 46 int prevLineIndex, int prevPrevLineIndex, 47 List <IndentAction> indentActions) 48 { 49 int prevOpenBracketCount = getOpenBracketCount(buffer,prevLineIndex); 50 if(prevOpenBracketCount != 0) 51 { 52 handleCollapse(indentActions); 53 boolean multiple = buffer.getBooleanProperty( 54 "multipleBracketIndent"); 55 IndentAction increase = new IndentAction.Increase( 56 multiple ? prevOpenBracketCount : 1); 57 indentActions.add(increase); 58 } 59 else if(getOpenBracketCount(buffer,thisLineIndex) != 0) 60 { 61 handleCollapse(indentActions); 62 } 63 } 65 private int getOpenBracketCount(JEditBuffer buffer, int line) 67 { 68 if(line == -1) 69 return 0; 70 else 71 return getBrackets(buffer.getLineText(line)).openCount; 72 } 74 private static void handleCollapse(List <IndentAction> indentActions) 76 { 77 if(indentActions.contains(new IndentAction.Collapse())) 78 indentActions.clear(); 79 } 81 private boolean aligned; 82 } 83 | Popular Tags |