View Javadoc
Minimize
Table

Bug Overview

linebug prioritybugbug descriptionexisting sinceauthor
70mediumExcessiveMethodLengthDiese Methode ist sehr lang, ein Indiz dafür das diese Methode zu viel tut, es sollten Hilfsmethoden genutzt und Copy/Paste-Code entfernt werden. Falls dies beabsichtigt ist und der Fehler soll ignoriert werden, dann //NOBUG verwenden.  Details zum Fehler...18.06.2012-10:31Unbekannt

1   /*
2    * Copyright 2003-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.groovy.antlr.treewalker;
17  
18  import java.io.PrintStream;
19  import java.util.Stack;
20  
21  import org.codehaus.groovy.antlr.GroovySourceAST;
22  import org.codehaus.groovy.antlr.parser.GroovyTokenTypes;
23  
24  /**
25   * A visitor that prints a html tags of each node to the supplied PrintStream
26   *
27   * @author <a href="mailto:groovy@ross-rayner.com">Jeremy Rayner</a>
28   * @version $Revision: 20442 $
29   */
30  
31  public class NodeAsHTMLPrinter extends VisitorAdapter {
32      private final String[] tokenNames;
33      private final PrintStream out;
34      private final Stack stack;
35  
36      /**
37       * A visitor that prints a html tags, for each node, to the supplied PrintStream.
38       * @param out supplied PrintStream to output nodes to
39       * @param tokenNames an array of token names to use
40       */
41      public NodeAsHTMLPrinter(PrintStream out,String[] tokenNames) {
42          this.tokenNames = tokenNames;
43          this.out = out;
44          this.stack = new Stack();
45      }
46  
47      public void setUp() {
48          out.println("<html><head></head><body><pre>");
49      }
50  
51      public void visitDefault(GroovySourceAST t,int visit) {
52          if (visit == OPENING_VISIT) {
53              out.print("<code title=" + quote(tokenNames[t.getType()]) + "><font color='#" + colour(t) + "'>");
54          } else if (visit == CLOSING_VISIT) {
55              out.print("</font></code>");
56          }
57      }
58  
59      private String quote(String tokenName) {
60          if (tokenName.length() > 0 && tokenName.charAt(0) != '\'')
61              return "'" + tokenName + "'";
62          else
63              return "\"" + tokenName + "\"";
64      }
65  
66      public void tearDown() {
67          out.println("</pre></body></html>");
68      }
69  
70 bug overview        private String colour(GroovySourceAST t) {  HEALTH4J >>  :  ExcessiveMethodLength 
71          String black = "000000";
72          String blue = "17178B";
73          String green = "008000";
74          //String purple = "7C308D";
75          String colour = black;
76          switch (t.getType()) {
77              case GroovyTokenTypes.ABSTRACT                      :
78              case GroovyTokenTypes.ANNOTATION                    :
79              case GroovyTokenTypes.ANNOTATIONS                   :
80              case GroovyTokenTypes.ANNOTATION_ARRAY_INIT         :
81              case GroovyTokenTypes.ANNOTATION_DEF                :
82              case GroovyTokenTypes.ANNOTATION_FIELD_DEF          :
83              case GroovyTokenTypes.ANNOTATION_MEMBER_VALUE_PAIR  :
84              case GroovyTokenTypes.ARRAY_DECLARATOR              :
85              case GroovyTokenTypes.ASSIGN                        :
86              case GroovyTokenTypes.AT                            :
87              case GroovyTokenTypes.BAND                          :
88              case GroovyTokenTypes.BAND_ASSIGN                   :
89              case GroovyTokenTypes.BIG_SUFFIX                    :
90              case GroovyTokenTypes.BLOCK                         :
91              case GroovyTokenTypes.BNOT                          :
92              case GroovyTokenTypes.BOR                           :
93              case GroovyTokenTypes.BOR_ASSIGN                    :
94              case GroovyTokenTypes.BSR                           :
95              case GroovyTokenTypes.BSR_ASSIGN                    :
96              case GroovyTokenTypes.BXOR                          :
97              case GroovyTokenTypes.BXOR_ASSIGN                   :
98              case GroovyTokenTypes.CASE_GROUP                    :
99              case GroovyTokenTypes.CLOSABLE_BLOCK                :
100             case GroovyTokenTypes.CLOSABLE_BLOCK_OP             :
101             case GroovyTokenTypes.COLON                         :
102             case GroovyTokenTypes.COMMA                         :
103             case GroovyTokenTypes.COMPARE_TO                    :
104             case GroovyTokenTypes.CTOR_CALL                     :
105             case GroovyTokenTypes.CTOR_IDENT                    :
106             case GroovyTokenTypes.DEC                           :
107             case GroovyTokenTypes.DIGIT                         :
108             case GroovyTokenTypes.DIV                           :
109             case GroovyTokenTypes.DIV_ASSIGN                    :
110             case GroovyTokenTypes.DOLLAR                        :
111             case GroovyTokenTypes.DOT                           :
112             case GroovyTokenTypes.DYNAMIC_MEMBER                :
113             case GroovyTokenTypes.ELIST                         :
114             case GroovyTokenTypes.EMPTY_STAT                    :
115             case GroovyTokenTypes.ENUM_CONSTANT_DEF             :
116             case GroovyTokenTypes.ENUM_DEF                      :
117             case GroovyTokenTypes.EOF                           :
118             case GroovyTokenTypes.EQUAL                         :
119             case GroovyTokenTypes.ESC                           :
120             case GroovyTokenTypes.EXPONENT                      :
121             case GroovyTokenTypes.EXPR                          :
122             case GroovyTokenTypes.FINAL                         :
123             case GroovyTokenTypes.FLOAT_SUFFIX                  :
124             case GroovyTokenTypes.FOR_CONDITION                 :
125             case GroovyTokenTypes.FOR_EACH_CLAUSE               :
126             case GroovyTokenTypes.FOR_INIT                      :
127             case GroovyTokenTypes.FOR_IN_ITERABLE               :
128             case GroovyTokenTypes.FOR_ITERATOR                  :
129             case GroovyTokenTypes.GE                            :
130             case GroovyTokenTypes.GT                            :
131             case GroovyTokenTypes.HEX_DIGIT                     :
132             case GroovyTokenTypes.IDENT                         :
133             case GroovyTokenTypes.IMPLICIT_PARAMETERS           :
134             case GroovyTokenTypes.INC                           :
135             case GroovyTokenTypes.INDEX_OP                      :
136             case GroovyTokenTypes.INSTANCE_INIT                 :
137             case GroovyTokenTypes.INTERFACE_DEF                 :
138             case GroovyTokenTypes.LABELED_ARG                   :
139             case GroovyTokenTypes.LABELED_STAT                  :
140             case GroovyTokenTypes.LAND                          :
141             case GroovyTokenTypes.LBRACK                        :
142             case GroovyTokenTypes.LCURLY                        :
143             case GroovyTokenTypes.LE                            :
144             case GroovyTokenTypes.LETTER                        :
145             case GroovyTokenTypes.LIST_CONSTRUCTOR              :
146             case GroovyTokenTypes.LNOT                          :
147             case GroovyTokenTypes.LOR                           :
148             case GroovyTokenTypes.LPAREN                        :
149             case GroovyTokenTypes.LT                            :
150             case GroovyTokenTypes.MAP_CONSTRUCTOR               :
151             case GroovyTokenTypes.MEMBER_POINTER                :
152             case GroovyTokenTypes.METHOD_CALL                   :
153             case GroovyTokenTypes.METHOD_DEF                    :
154             case GroovyTokenTypes.MINUS                         :
155             case GroovyTokenTypes.MINUS_ASSIGN                  :
156             case GroovyTokenTypes.ML_COMMENT                    :
157             case GroovyTokenTypes.MOD                           :
158             case GroovyTokenTypes.MODIFIERS                     :
159             case GroovyTokenTypes.MOD_ASSIGN                    :
160             case GroovyTokenTypes.NLS                           :
161             case GroovyTokenTypes.NOT_EQUAL                     :
162             case GroovyTokenTypes.NULL_TREE_LOOKAHEAD           :
163             case GroovyTokenTypes.NUM_BIG_DECIMAL               :
164             case GroovyTokenTypes.NUM_BIG_INT                   :
165             case GroovyTokenTypes.NUM_DOUBLE                    :
166             case GroovyTokenTypes.NUM_FLOAT                     :
167             case GroovyTokenTypes.NUM_INT                       :
168             case GroovyTokenTypes.NUM_LONG                      :
169             case GroovyTokenTypes.OBJBLOCK                      :
170             case GroovyTokenTypes.ONE_NL                        :
171             case GroovyTokenTypes.OPTIONAL_DOT                  :
172             case GroovyTokenTypes.PARAMETERS                    :
173             case GroovyTokenTypes.PARAMETER_DEF                 :
174             case GroovyTokenTypes.PLUS                          :
175             case GroovyTokenTypes.PLUS_ASSIGN                   :
176             case GroovyTokenTypes.POST_DEC                      :
177             case GroovyTokenTypes.POST_INC                      :
178             case GroovyTokenTypes.QUESTION                      :
179             case GroovyTokenTypes.RANGE_EXCLUSIVE               :
180             case GroovyTokenTypes.RANGE_INCLUSIVE               :
181             case GroovyTokenTypes.RBRACK                        :
182             case GroovyTokenTypes.RCURLY                        :
183             case GroovyTokenTypes.REGEXP_CTOR_END               :
184             case GroovyTokenTypes.REGEXP_SYMBOL                 :
185             case GroovyTokenTypes.REGEX_FIND                    :
186             case GroovyTokenTypes.REGEX_MATCH                   :
187             case GroovyTokenTypes.RPAREN                        :
188             case GroovyTokenTypes.SELECT_SLOT                   :
189             case GroovyTokenTypes.SEMI                          :
190             case GroovyTokenTypes.SH_COMMENT                    :
191             case GroovyTokenTypes.SL                            :
192             case GroovyTokenTypes.SLIST                         :
193             case GroovyTokenTypes.SL_ASSIGN                     :
194             case GroovyTokenTypes.SL_COMMENT                    :
195             case GroovyTokenTypes.SPREAD_ARG                    :
196             case GroovyTokenTypes.SPREAD_DOT                    :
197             case GroovyTokenTypes.SPREAD_MAP_ARG                :
198             case GroovyTokenTypes.SR                            :
199             case GroovyTokenTypes.SR_ASSIGN                     :
200             case GroovyTokenTypes.STAR                          :
201             case GroovyTokenTypes.STAR_ASSIGN                   :
202             case GroovyTokenTypes.STAR_STAR                     :
203             case GroovyTokenTypes.STAR_STAR_ASSIGN              :
204             case GroovyTokenTypes.STATIC_IMPORT                 :
205             case GroovyTokenTypes.STATIC_INIT                   :
206             case GroovyTokenTypes.STRICTFP                      :
207             case GroovyTokenTypes.STRING_CH                     :
208             case GroovyTokenTypes.STRING_CONSTRUCTOR            :
209             case GroovyTokenTypes.STRING_CTOR_END               :
210             case GroovyTokenTypes.STRING_CTOR_MIDDLE            :
211             case GroovyTokenTypes.STRING_CTOR_START             :
212             case GroovyTokenTypes.STRING_NL                     :
213             case GroovyTokenTypes.SUPER_CTOR_CALL               :
214             case GroovyTokenTypes.TRIPLE_DOT                    :
215             case GroovyTokenTypes.TYPECAST                      :
216             case GroovyTokenTypes.TYPE_ARGUMENT                 :
217             case GroovyTokenTypes.TYPE_ARGUMENTS                :
218             case GroovyTokenTypes.TYPE_LOWER_BOUNDS             :
219             case GroovyTokenTypes.TYPE_PARAMETER                :
220             case GroovyTokenTypes.TYPE_PARAMETERS               :
221             case GroovyTokenTypes.TYPE_UPPER_BOUNDS             :
222             case GroovyTokenTypes.UNARY_MINUS                   :
223             case GroovyTokenTypes.UNARY_PLUS                    :
224             case GroovyTokenTypes.UNUSED_CONST                  :
225             case GroovyTokenTypes.UNUSED_DO                     :
226             case GroovyTokenTypes.UNUSED_GOTO                   :
227             case GroovyTokenTypes.VARIABLE_DEF                  :
228             case GroovyTokenTypes.VARIABLE_PARAMETER_DEF        :
229             case GroovyTokenTypes.VOCAB                         :
230             case GroovyTokenTypes.WILDCARD_TYPE                 :
231             case GroovyTokenTypes.WS                            :
232                 colour = black;
233                 break;
234 
235             case GroovyTokenTypes.STRING_LITERAL                :
236             case GroovyTokenTypes.REGEXP_LITERAL                :
237             case GroovyTokenTypes.DOLLAR_REGEXP_LITERAL         :
238                 colour = green;
239                 break;
240 
241             case GroovyTokenTypes.CLASS_DEF                     :
242             case GroovyTokenTypes.EXTENDS_CLAUSE                :
243             case GroovyTokenTypes.IMPLEMENTS_CLAUSE             :
244             case GroovyTokenTypes.IMPORT                        :
245             case GroovyTokenTypes.LITERAL_as                    :
246             case GroovyTokenTypes.LITERAL_assert                :
247             case GroovyTokenTypes.LITERAL_boolean               :
248             case GroovyTokenTypes.LITERAL_break                 :
249             case GroovyTokenTypes.LITERAL_byte                  :
250             case GroovyTokenTypes.LITERAL_case                  :
251             case GroovyTokenTypes.LITERAL_catch                 :
252             case GroovyTokenTypes.LITERAL_char                  :
253             case GroovyTokenTypes.LITERAL_class                 :
254             case GroovyTokenTypes.LITERAL_continue              :
255             case GroovyTokenTypes.LITERAL_def                   :
256             case GroovyTokenTypes.LITERAL_default               :
257             case GroovyTokenTypes.LITERAL_double                :
258             case GroovyTokenTypes.LITERAL_else                  :
259             case GroovyTokenTypes.LITERAL_enum                  :
260             case GroovyTokenTypes.LITERAL_extends               :
261             case GroovyTokenTypes.LITERAL_false                 :
262             case GroovyTokenTypes.LITERAL_finally               :
263             case GroovyTokenTypes.LITERAL_float                 :
264             case GroovyTokenTypes.LITERAL_for                   :
265             case GroovyTokenTypes.LITERAL_if                    :
266             case GroovyTokenTypes.LITERAL_implements            :
267             case GroovyTokenTypes.LITERAL_import                :
268             case GroovyTokenTypes.LITERAL_in                    :
269             case GroovyTokenTypes.LITERAL_instanceof            :
270             case GroovyTokenTypes.LITERAL_int                   :
271             case GroovyTokenTypes.LITERAL_interface             :
272             case GroovyTokenTypes.LITERAL_long                  :
273             case GroovyTokenTypes.LITERAL_native                :
274             case GroovyTokenTypes.LITERAL_new                   :
275             case GroovyTokenTypes.LITERAL_null                  :
276             case GroovyTokenTypes.LITERAL_package               :
277             case GroovyTokenTypes.LITERAL_private               :
278             case GroovyTokenTypes.LITERAL_protected             :
279             case GroovyTokenTypes.LITERAL_public                :
280             case GroovyTokenTypes.LITERAL_return                :
281             case GroovyTokenTypes.LITERAL_short                 :
282             case GroovyTokenTypes.LITERAL_static                :
283             case GroovyTokenTypes.LITERAL_super                 :
284             case GroovyTokenTypes.LITERAL_switch                :
285             case GroovyTokenTypes.LITERAL_synchronized          :
286             case GroovyTokenTypes.LITERAL_this                  :
287             case GroovyTokenTypes.LITERAL_threadsafe            :
288             case GroovyTokenTypes.LITERAL_throw                 :
289             case GroovyTokenTypes.LITERAL_throws                :
290             case GroovyTokenTypes.LITERAL_transient             :
291             case GroovyTokenTypes.LITERAL_true                  :
292             case GroovyTokenTypes.LITERAL_try                   :
293             case GroovyTokenTypes.LITERAL_void                  :
294             case GroovyTokenTypes.LITERAL_volatile              :
295             case GroovyTokenTypes.LITERAL_while                 :
296             case GroovyTokenTypes.PACKAGE_DEF                   :
297             case GroovyTokenTypes.TYPE                          :
298                 colour = blue;
299                 break;
300 
301             default:
302                 colour = black;
303                 break;
304         }
305         return colour;
306     }
307 
308     public void push(GroovySourceAST t) {
309         stack.push(t);
310     }
311     public GroovySourceAST pop() {
312         if (!stack.empty()) {
313             return (GroovySourceAST) stack.pop();
314         }
315         return null;
316     }
317 }