KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > syntax > element > ElementAction


1 package org.antlr.works.syntax.element;
2
3 import org.antlr.works.ate.folding.ATEFoldingEntity;
4 import org.antlr.works.ate.syntax.misc.ATEToken;
5 import org.antlr.works.editor.EditorPersistentObject;
6 import org.antlr.works.syntax.GrammarSyntaxParser;
7
8 import java.util.ArrayList JavaDoc;
9 import java.util.List JavaDoc;
10 /*
11
12 [The "BSD licence"]
13 Copyright (c) 2005 Jean Bovet
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
18 are met:
19
20 1. Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
22 2. Redistributions in binary form must reproduce the above copyright
23 notice, this list of conditions and the following disclaimer in the
24 documentation and/or other materials provided with the distribution.
25 3. The name of the author may not be used to endorse or promote products
26 derived from this software without specific prior written permission.
27
28 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
32 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39 */

40
41 public class ElementAction extends ElementScopable implements EditorPersistentObject, ATEFoldingEntity {
42
43     public ElementRule rule;
44     public ATEToken start;
45     public ATEToken end;
46     public int actionNum;
47     private boolean expanded = true;
48     private GrammarSyntaxParser parser;
49
50     public ElementAction(GrammarSyntaxParser parser, ElementRule rule, ATEToken start) {
51         this.parser = parser;
52         this.rule = rule;
53         this.start = start;
54     }
55
56     public boolean containsIndex(int index) {
57         return index >= start.getStartIndex() && index <= end.getEndIndex();
58     }
59
60     public boolean equals(Object JavaDoc other) {
61         if(other == null) return false;
62
63         if(other instanceof ElementAction) {
64             return getUniqueIdentifier() == ((ElementAction)other).getUniqueIdentifier();
65         } else {
66             return false;
67         }
68     }
69
70     public List JavaDoc<ATEToken> getTokens() {
71         List JavaDoc<ATEToken> t = new ArrayList JavaDoc<ATEToken>();
72         for(int index=start.index; index<end.index; index++) {
73             t.add(parser.getTokens().get(index));
74         }
75         return t;
76     }
77
78     public int getUniqueIdentifier() {
79         String JavaDoc actionText = start.getText().substring(start.start, end.end);
80         return (rule.name+actionText+actionNum).hashCode();
81     }
82
83     public void foldingEntitySetExpanded(boolean expanded) {
84         this.expanded = expanded;
85     }
86
87     public boolean foldingEntityIsExpanded() {
88         return expanded;
89     }
90
91     public boolean foldingEntityCanBeCollapsed() {
92         return true;
93     }
94
95     public int foldingEntityGetStartParagraphIndex() {
96         return start.getStartIndex();
97     }
98
99     public int foldingEntityGetStartIndex() {
100         return start.getStartIndex();
101     }
102
103     public int foldingEntityGetEndIndex() {
104         return end.getEndIndex();
105     }
106
107     public int foldingEntityGetStartLine() {
108         return start.startLineNumber;
109     }
110
111     public int foldingEntityGetEndLine() {
112         return end.endLineNumber;
113     }
114
115     public String JavaDoc foldingEntityPlaceholderString() {
116         return "{ ... }";
117     }
118
119     public String JavaDoc foldingEntityID() {
120         return String.valueOf(getUniqueIdentifier());
121     }
122
123     public int foldingEntityLevel() {
124         return 1;
125     }
126
127     public Object JavaDoc getPersistentID() {
128         return getUniqueIdentifier();
129     }
130
131     public void persistentAssign(EditorPersistentObject otherObject) {
132         ElementAction otherAction = (ElementAction)otherObject;
133         this.expanded = otherAction.expanded;
134     }
135 }
136
Popular Tags