PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/indent/OpenBracketIndentRule.java

#
Java | 78 lines | 46 code | 7 blank | 25 comment | 8 complexity | 84b4f88f8ce4c08abd68d97e7fa87836 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * OpenBracketIndentRule.java
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2005 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.indent;
  23. import java.util.List;
  24. import org.gjt.sp.jedit.buffer.JEditBuffer;
  25. import org.gjt.sp.jedit.TextUtilities;
  26. public class OpenBracketIndentRule extends BracketIndentRule
  27. {
  28. //{{{ OpenBracketIndentRule constructor
  29. public OpenBracketIndentRule(char openBracket, boolean aligned)
  30. {
  31. super(openBracket,
  32. TextUtilities.getComplementaryBracket(openBracket,
  33. new boolean[1]));
  34. this.aligned = aligned;
  35. } //}}}
  36. //{{{ apply() method
  37. public void apply(JEditBuffer buffer, int thisLineIndex,
  38. int prevLineIndex, int prevPrevLineIndex,
  39. List indentActions)
  40. {
  41. int prevOpenBracketCount = getOpenBracketCount(buffer,prevLineIndex);
  42. if(prevOpenBracketCount != 0)
  43. {
  44. handleCollapse(indentActions);
  45. boolean multiple = buffer.getBooleanProperty(
  46. "multipleBracketIndent");
  47. IndentAction increase = new IndentAction.Increase(
  48. multiple ? prevOpenBracketCount : 1);
  49. indentActions.add(increase);
  50. }
  51. else if(getOpenBracketCount(buffer,thisLineIndex) != 0)
  52. {
  53. handleCollapse(indentActions);
  54. }
  55. } //}}}
  56. //{{{ getOpenBracketCount() method
  57. private int getOpenBracketCount(JEditBuffer buffer, int line)
  58. {
  59. if(line == -1)
  60. return 0;
  61. else
  62. return getBrackets(buffer.getLineText(line)).openCount;
  63. } //}}}
  64. //{{{ handleCollapse() method
  65. private void handleCollapse(List indentActions)
  66. {
  67. if(indentActions.contains(new IndentAction.Collapse()))
  68. indentActions.clear();
  69. } //}}}
  70. private boolean aligned;
  71. }