KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > editor > EditorAnalysisManager


1 package org.antlr.works.editor;
2
3 import org.antlr.works.ate.analysis.ATEAnalysisItem;
4 import org.antlr.works.ate.analysis.ATEAnalysisManager;
5 import org.antlr.works.components.grammar.CEditorGrammar;
6
7 import java.awt.*;
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 EditorAnalysisManager extends ATEAnalysisManager {
42
43     protected static final int ANALYSIS_ITEM_ERROR = 0;
44     protected static final int ANALYSIS_ITEM_WARNING = 1;
45     protected static final int ANALYSIS_ITEM_OTHER = 2;
46
47     protected final Color greenColor = new Color(0f, 0.9f, 0.25f, 1.0f);
48
49     protected CEditorGrammar editor;
50
51     protected int numberOfErrors;
52     protected int numberOfWarnings;
53
54     public EditorAnalysisManager(CEditorGrammar editor) {
55         this.editor = editor;
56     }
57
58     public int[] getAvailableTypes() {
59         return new int[] { ANALYSIS_ITEM_WARNING, ANALYSIS_ITEM_ERROR, ANALYSIS_ITEM_OTHER };
60     }
61
62     public List JavaDoc<ATEAnalysisItem> getItemsForType(int type) {
63         switch(type) {
64             case ANALYSIS_ITEM_ERROR:
65                 return getErrors();
66             case ANALYSIS_ITEM_WARNING:
67                 return getWarnings();
68             case ANALYSIS_ITEM_OTHER:
69                 return getOthers();
70         }
71         return null;
72     }
73
74     public int getLinesCount() {
75         return editor.parserEngine.getMaxLines();
76     }
77
78     public Color getAnalysisColor() {
79         if(numberOfErrors == 0 && numberOfWarnings == 0)
80             return greenColor;
81         else if(numberOfErrors == 0)
82             return Color.yellow;
83         else
84             return Color.red;
85     }
86
87     public String JavaDoc getAnalysisDescription() {
88         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
89         if(numberOfErrors == 0)
90             sb.append("No error");
91         else {
92             sb.append(numberOfErrors);
93             if(numberOfErrors > 1)
94                 sb.append(" errors found");
95             else
96                 sb.append(" error found");
97         }
98         if(numberOfWarnings > 0) {
99             sb.append("\n");
100             sb.append(numberOfWarnings);
101             if(numberOfWarnings > 1)
102                 sb.append(" warnings found");
103             else
104                 sb.append(" warning found");
105         }
106         return sb.toString();
107     }
108
109     public List JavaDoc<ATEAnalysisItem> getErrors() {
110         List JavaDoc<ATEAnalysisItem> errors = new ArrayList JavaDoc<ATEAnalysisItem>();
111         for (EditorInspectorItem item : editor.editorInspector.getErrors()) {
112             errors.add(new ATEAnalysisItem(ANALYSIS_ITEM_ERROR, item.color, item.startLineNumber, item.startIndex, item.description));
113         }
114         numberOfErrors = errors.size();
115         return errors;
116     }
117
118     public List JavaDoc<ATEAnalysisItem> getWarnings() {
119         List JavaDoc<ATEAnalysisItem> warnings = new ArrayList JavaDoc<ATEAnalysisItem>();
120         for (EditorInspectorItem item : editor.editorInspector.getWarnings()) {
121             warnings.add(new ATEAnalysisItem(ANALYSIS_ITEM_WARNING, item.color, item.startLineNumber, item.startIndex, item.description));
122         }
123         numberOfWarnings = warnings.size();
124         return warnings;
125     }
126
127     public List JavaDoc<ATEAnalysisItem> getOthers() {
128         List JavaDoc<ATEAnalysisItem> others = new ArrayList JavaDoc<ATEAnalysisItem>();
129         for (EditorInspectorItem item : editor.editorInspector.getDecisionDFAs()) {
130             others.add(new ATEAnalysisItem(ANALYSIS_ITEM_OTHER, item.color, item.startLineNumber, item.startIndex, item.description));
131         }
132         return others;
133     }
134
135 }
136
Popular Tags