PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 85 lines | 49 code | 9 blank | 27 comment | 10 complexity | 5ea291280013af1639839be69c1bf26e 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. * BracketIndentRule.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 org.gjt.sp.jedit.Buffer;
  24. public abstract class BracketIndentRule implements IndentRule
  25. {
  26. //{{{ BracketIndentRule constructor
  27. public BracketIndentRule(char openBracket, char closeBracket)
  28. {
  29. this.openBracket = openBracket;
  30. this.closeBracket = closeBracket;
  31. } //}}}
  32. //{{{ Brackets class
  33. public static class Brackets
  34. {
  35. int openCount;
  36. int closeCount;
  37. } //}}}
  38. //{{{ getBrackets() method
  39. public Brackets getBrackets(String line)
  40. {
  41. Brackets brackets = new Brackets();
  42. for(int i = 0; i < line.length(); i++)
  43. {
  44. char ch = line.charAt(i);
  45. if(ch == openBracket)
  46. {
  47. /* Don't increase indent when we see
  48. an explicit fold. */
  49. if(line.length() - i >= 3)
  50. {
  51. if(line.substring(i,i+3).equals("{{{")) /* }}} */
  52. {
  53. i += 2;
  54. continue;
  55. }
  56. }
  57. brackets.openCount++;
  58. }
  59. else if(ch == closeBracket)
  60. {
  61. if(brackets.openCount != 0)
  62. brackets.openCount--;
  63. else
  64. brackets.closeCount++;
  65. }
  66. }
  67. return brackets;
  68. } //}}}
  69. //{{{ toString() method
  70. public String toString()
  71. {
  72. return getClass().getName() + "[" + openBracket + ","
  73. + closeBracket + "]";
  74. } //}}}
  75. protected char openBracket, closeBracket;
  76. }