KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infozone > tools > janalyzer > ConstantsManager


1 // You can redistribute this software and/or modify it under the terms of
2
// the Infozone Software License version 2 published by the Infozone Group
3
// (http://www.infozone-group.org).
4
//
5
// Copyright (C) @year@ by The Infozone Group. All rights reserved.
6
//
7
// $Id: ConstantsManager.java,v 1.1 2002/05/10 08:59:12 per_nyfelt Exp $
8

9 package org.infozone.tools.janalyzer;
10
11 /** All available Expressions and Nodes of the syntax tree */
12 import koala.dynamicjava.tree.*;
13
14 /** For all available Modifier strings. */
15 import java.lang.reflect.Modifier JavaDoc;
16
17
18 /**
19  * This class returns String Constants for Binary Expressions,
20  * Access Modifier and so on.
21  * It's used by the JavaCodeAnalyzer class in this package.
22  *
23  * @version $Revision: 1.1 $ $Date: 2002/05/10 08:59:12 $
24  * @author <a HREF="http://www.softwarebuero.de">SMB</a>
25  * @see org.infozone.tools.janalyzer.JavaCodeAnalyzer for details
26  */

27 public final class ConstantsManager extends java.lang.Object JavaDoc {
28     
29     
30     public static String JavaDoc getBinaryExpressionString( Expression aExp ) {
31         if (aExp instanceof AddExpression) {
32             return "+";
33         }
34         if (aExp instanceof AddAssignExpression) {
35             return "+=";
36         }
37         if (aExp instanceof BitAndAssignExpression) {
38             return "&=";
39         }
40         if (aExp instanceof BitOrAssignExpression) {
41             return "|=";
42         }
43         if (aExp instanceof DivideAssignExpression) {
44             return "/=";
45         }
46         if (aExp instanceof ExclusiveOrAssignExpression) {
47             return "^=";
48         }
49         if (aExp instanceof MultiplyAssignExpression) {
50             return "*=";
51         }
52         if (aExp instanceof RemainderExpression) {
53             return "%";
54         }
55         if (aExp instanceof RemainderAssignExpression) {
56             return "%=";
57         }
58         if (aExp instanceof ShiftLeftAssignExpression) {
59             return ">>=";
60         }
61         if (aExp instanceof ShiftRightAssignExpression) {
62             return "<<=";
63         }
64         if (aExp instanceof SimpleAssignExpression) {
65             return "=";
66         }
67         if (aExp instanceof SubtractAssignExpression) {
68             return "-=";
69         }
70         if (aExp instanceof UnsignedShiftRightAssignExpression) {
71             return ">>>=";
72         }
73         if (aExp instanceof AndExpression) {
74             return "&&";
75         }
76         if (aExp instanceof BitAndExpression) {
77             return "&";
78         }
79         if (aExp instanceof BitOrExpression) {
80             return "|";
81         }
82         if (aExp instanceof DivideExpression) {
83             return "/";
84         }
85         if (aExp instanceof EqualExpression) {
86             return "==";
87         }
88         if (aExp instanceof ExclusiveOrExpression) {
89             return "^";
90         }
91         if (aExp instanceof GreaterExpression) {
92             return ">";
93         }
94         if (aExp instanceof GreaterOrEqualExpression) {
95             return ">=";
96         }
97         if (aExp instanceof LessExpression) {
98             return "<";
99         }
100         if (aExp instanceof LessOrEqualExpression) {
101             return "<=";
102         }
103         if (aExp instanceof MultiplyExpression) {
104             return "*";
105         }
106         if (aExp instanceof NotEqualExpression) {
107             return "!=";
108         }
109         if (aExp instanceof OrExpression) {
110             return "||";
111         }
112         if (aExp instanceof ShiftLeftExpression) {
113             return "<<";
114         }
115         if (aExp instanceof ShiftRightExpression) {
116             return ">>";
117         }
118         if (aExp instanceof SimpleAssignExpression) {
119             return "=";
120         }
121         if (aExp instanceof SubtractExpression) {
122             return "-";
123         }
124         if (aExp instanceof UnsignedShiftRightExpression) {
125             return ">>>";
126         }
127         return "Constants Manager: unknown BinaryExpressionString " + aExp;
128     }
129     
130     
131     /**
132      * The right operator Precedence of all conditional operators in binary expressions.
133      * @see package koala.dynamicjava.tree
134      * @return A int value of the level.
135      *
136      */

137     public static int getExpressionLevel( Expression aExp ) {
138         if (aExp instanceof AddAssignExpression || aExp instanceof BitAndAssignExpression
139                 || aExp instanceof BitOrAssignExpression || aExp instanceof DivideAssignExpression
140                 || aExp instanceof ExclusiveOrAssignExpression || aExp instanceof MultiplyAssignExpression
141                 || aExp instanceof RemainderAssignExpression || aExp instanceof ShiftLeftAssignExpression
142                 || aExp instanceof ShiftRightAssignExpression || aExp instanceof SimpleAssignExpression
143                 || aExp instanceof SubtractAssignExpression || aExp instanceof UnsignedShiftRightAssignExpression) {
144             return 1;
145         }
146         if (aExp instanceof ConditionalExpression) {
147             return 2;
148         }
149         if (aExp instanceof OrExpression) {
150             return 3;
151         }
152         if (aExp instanceof AndExpression) {
153             return 4;
154         }
155         if (aExp instanceof BitOrExpression) {
156             return 5;
157         }
158         if (aExp instanceof ExclusiveOrExpression) {
159             return 6;
160         }
161         if (aExp instanceof BitAndExpression) {
162             return 7;
163         }
164         if (aExp instanceof EqualExpression || aExp instanceof NotEqualExpression) {
165             return 8;
166         }
167         if (aExp instanceof GreaterExpression || aExp instanceof GreaterOrEqualExpression
168                 || aExp instanceof LessExpression || aExp instanceof LessOrEqualExpression
169                 || aExp instanceof InstanceOfExpression) {
170             return 9;
171         }
172         if (aExp instanceof ShiftLeftExpression || aExp instanceof ShiftRightExpression
173                 || aExp instanceof UnsignedShiftRightExpression) {
174             return 10;
175         }
176         if (aExp instanceof AddExpression || aExp instanceof SubtractExpression) {
177             return 11;
178         }
179         if (aExp instanceof DivideExpression || aExp instanceof RemainderExpression
180                 || aExp instanceof MultiplyExpression) {
181             return 12;
182         }
183         if (aExp instanceof CastExpression) {
184             return 13;
185         }
186         if (aExp instanceof NotExpression || aExp instanceof PreDecrement || aExp instanceof PreIncrement
187                 || aExp instanceof PlusExpression || aExp instanceof MinusExpression) {
188             return 14;
189         }
190         if (aExp instanceof PostDecrement || aExp instanceof PostIncrement || aExp instanceof ObjectMethodCall
191                 || aExp instanceof ObjectFieldAccess || aExp instanceof ArrayAccess || aExp instanceof CastExpression) {
192             return 15;
193         }
194         // literals should not be in parenthesis
195
//printDB("ConstantsManager Expression " + aExp
196
// + " not found return level 16");
197
return 16;
198     }
199     
200     
201     /**
202      * All avaliable modifiers of the JAVA Language.
203      * @see java.lang.reflect.Modifier
204      * @return A String representation of all suitable modifier or
205      * an empty string.
206      *
207      */

208     public static String JavaDoc getModifierString( int access ) {
209         String JavaDoc ret = "";
210         if ((Modifier.PRIVATE & access) == Modifier.PRIVATE) {
211             ret += "private ";
212         }
213         if ((Modifier.PROTECTED & access) == Modifier.PROTECTED) {
214             ret += "protected ";
215         }
216         if ((Modifier.PUBLIC & access) == Modifier.PUBLIC) {
217             ret += "public ";
218         }
219         if ((Modifier.SYNCHRONIZED & access) == Modifier.SYNCHRONIZED) {
220             ret += "synchronized ";
221         }
222         if ((Modifier.ABSTRACT & access) == Modifier.ABSTRACT) {
223             ret += "abstract ";
224         }
225         if ((Modifier.FINAL & access) == Modifier.FINAL) {
226             ret += "final ";
227         }
228         if ((Modifier.INTERFACE & access) == Modifier.INTERFACE) {
229             ret += "interface ";
230         }
231         if ((Modifier.NATIVE & access) == Modifier.NATIVE) {
232             ret += "native ";
233         }
234         if ((Modifier.STATIC & access) == Modifier.STATIC) {
235             ret += "static ";
236         }
237         if ((Modifier.STRICT & access) == Modifier.STRICT) {
238             ret += "strict ";
239         }
240         if ((Modifier.TRANSIENT & access) == Modifier.TRANSIENT) {
241             ret += "transient ";
242         }
243         if ((Modifier.VOLATILE & access) == Modifier.VOLATILE) {
244             ret += "volatile ";
245         }
246         /*
247         if (ret.length()>1) {
248             return ret.substring(0, ret.length()-1);
249          }
250          */

251         return ret;
252     }
253     
254     
255     public static void printDB( String JavaDoc aLine ) {
256         System.err.println( aLine );
257         getBinaryExpressionString( null ).length();
258     }
259 }
260
Popular Tags