PageRenderTime 63ms CodeModel.GetById 55ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/indent/OpenBracketIndentRule.java

#
Java | 91 lines | 54 code | 8 blank | 29 comment | 10 complexity | aceba5c0a285f8b5791bc86c1686e312 MD5 | raw file
 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
23package org.gjt.sp.jedit.indent;
24
25import java.util.List;
26import org.gjt.sp.jedit.buffer.JEditBuffer;
27import org.gjt.sp.jedit.TextUtilities;
28
29/**
30 * @author Slava Pestov
31 * @version $Id: OpenBracketIndentRule.java 12504 2008-04-22 23:12:43Z ezust $
32 */
33public class OpenBracketIndentRule extends BracketIndentRule
34{
35	//{{{ OpenBracketIndentRule constructor
36	public OpenBracketIndentRule(char openBracket, boolean aligned)
37	{
38		super(openBracket,
39			TextUtilities.getComplementaryBracket(openBracket,null));
40		this.aligned = aligned;
41	} //}}}
42
43	//{{{ apply() method
44	public void apply(JEditBuffer buffer, int thisLineIndex,
45		int prevLineIndex, int prevPrevLineIndex,
46		List<IndentAction> indentActions)
47	{
48		int prevOpenBracketCount = getOpenBracketCount(buffer,prevLineIndex);
49		if(prevOpenBracketCount != 0)
50		{
51			handleCollapse(indentActions, true);
52			boolean multiple = buffer.getBooleanProperty(
53				"multipleBracketIndent");
54			IndentAction increase = new IndentAction.Increase(
55				multiple ? prevOpenBracketCount : 1);
56			indentActions.add(increase);
57		}
58		else if(getOpenBracketCount(buffer,thisLineIndex) != 0)
59		{
60			handleCollapse(indentActions, false);
61		}
62	} //}}}
63
64	//{{{ getOpenBracketCount() method
65	private int getOpenBracketCount(JEditBuffer buffer, int line)
66	{
67		if(line == -1)
68			return 0;
69		else
70			return getBrackets(buffer, line).openCount;
71	} //}}}
72
73	//{{{ handleCollapse() method
74	private static void handleCollapse(List<IndentAction> indentActions,
75					   boolean delPrevPrevCollapse)
76	{
77		if (indentActions.contains(IndentAction.PrevCollapse))
78		{
79			indentActions.clear();
80			return;
81		}
82
83		if (delPrevPrevCollapse && indentActions.contains(IndentAction.PrevPrevCollapse))
84		{
85			indentActions.clear();
86			return;
87		}
88	} //}}}
89
90	private boolean aligned;
91}