001: // You can redistribute this software and/or modify it under the terms of
002: // the Infozone Software License version 2 published by the Infozone Group
003: // (http://www.infozone-group.org).
004: //
005: // Copyright (C) @year@ by The Infozone Group. All rights reserved.
006: //
007: // $Id: ConstantsManager.java,v 1.1 2002/05/10 08:59:12 per_nyfelt Exp $
008:
009: package org.infozone.tools.janalyzer;
010:
011: /** All available Expressions and Nodes of the syntax tree */
012: import koala.dynamicjava.tree.*;
013:
014: /** For all available Modifier strings. */
015: import java.lang.reflect.Modifier;
016:
017: /**
018: * This class returns String Constants for Binary Expressions,
019: * Access Modifier and so on.
020: * It's used by the JavaCodeAnalyzer class in this package.
021: *
022: * @version $Revision: 1.1 $ $Date: 2002/05/10 08:59:12 $
023: * @author <a href="http://www.softwarebuero.de">SMB</a>
024: * @see org.infozone.janalyzer.JavaCodeAnalyzer for details
025: */
026: public final class ConstantsManager extends java.lang.Object {
027:
028: public static String getBinaryExpressionString(Expression aExp) {
029: if (aExp instanceof AddExpression) {
030: return "+";
031: }
032: if (aExp instanceof AddAssignExpression) {
033: return "+=";
034: }
035: if (aExp instanceof BitAndAssignExpression) {
036: return "&=";
037: }
038: if (aExp instanceof BitOrAssignExpression) {
039: return "|=";
040: }
041: if (aExp instanceof DivideAssignExpression) {
042: return "/=";
043: }
044: if (aExp instanceof ExclusiveOrAssignExpression) {
045: return "^=";
046: }
047: if (aExp instanceof MultiplyAssignExpression) {
048: return "*=";
049: }
050: if (aExp instanceof RemainderExpression) {
051: return "%";
052: }
053: if (aExp instanceof RemainderAssignExpression) {
054: return "%=";
055: }
056: if (aExp instanceof ShiftLeftAssignExpression) {
057: return ">>=";
058: }
059: if (aExp instanceof ShiftRightAssignExpression) {
060: return "<<=";
061: }
062: if (aExp instanceof SimpleAssignExpression) {
063: return "=";
064: }
065: if (aExp instanceof SubtractAssignExpression) {
066: return "-=";
067: }
068: if (aExp instanceof UnsignedShiftRightAssignExpression) {
069: return ">>>=";
070: }
071: if (aExp instanceof AndExpression) {
072: return "&&";
073: }
074: if (aExp instanceof BitAndExpression) {
075: return "&";
076: }
077: if (aExp instanceof BitOrExpression) {
078: return "|";
079: }
080: if (aExp instanceof DivideExpression) {
081: return "/";
082: }
083: if (aExp instanceof EqualExpression) {
084: return "==";
085: }
086: if (aExp instanceof ExclusiveOrExpression) {
087: return "^";
088: }
089: if (aExp instanceof GreaterExpression) {
090: return ">";
091: }
092: if (aExp instanceof GreaterOrEqualExpression) {
093: return ">=";
094: }
095: if (aExp instanceof LessExpression) {
096: return "<";
097: }
098: if (aExp instanceof LessOrEqualExpression) {
099: return "<=";
100: }
101: if (aExp instanceof MultiplyExpression) {
102: return "*";
103: }
104: if (aExp instanceof NotEqualExpression) {
105: return "!=";
106: }
107: if (aExp instanceof OrExpression) {
108: return "||";
109: }
110: if (aExp instanceof ShiftLeftExpression) {
111: return "<<";
112: }
113: if (aExp instanceof ShiftRightExpression) {
114: return ">>";
115: }
116: if (aExp instanceof SimpleAssignExpression) {
117: return "=";
118: }
119: if (aExp instanceof SubtractExpression) {
120: return "-";
121: }
122: if (aExp instanceof UnsignedShiftRightExpression) {
123: return ">>>";
124: }
125: return "Constants Manager: unknown BinaryExpressionString "
126: + aExp;
127: }
128:
129: /**
130: * The right operator Precedence of all conditional operators in binary expressions.
131: * @see package koala.dynamicjava.tree
132: * @return A int value of the level.
133: *
134: */
135: public static int getExpressionLevel(Expression aExp) {
136: if (aExp instanceof AddAssignExpression
137: || aExp instanceof BitAndAssignExpression
138: || aExp instanceof BitOrAssignExpression
139: || aExp instanceof DivideAssignExpression
140: || aExp instanceof ExclusiveOrAssignExpression
141: || aExp instanceof MultiplyAssignExpression
142: || aExp instanceof RemainderAssignExpression
143: || aExp instanceof ShiftLeftAssignExpression
144: || aExp instanceof ShiftRightAssignExpression
145: || aExp instanceof SimpleAssignExpression
146: || aExp instanceof SubtractAssignExpression
147: || aExp instanceof UnsignedShiftRightAssignExpression) {
148: return 1;
149: }
150: if (aExp instanceof ConditionalExpression) {
151: return 2;
152: }
153: if (aExp instanceof OrExpression) {
154: return 3;
155: }
156: if (aExp instanceof AndExpression) {
157: return 4;
158: }
159: if (aExp instanceof BitOrExpression) {
160: return 5;
161: }
162: if (aExp instanceof ExclusiveOrExpression) {
163: return 6;
164: }
165: if (aExp instanceof BitAndExpression) {
166: return 7;
167: }
168: if (aExp instanceof EqualExpression
169: || aExp instanceof NotEqualExpression) {
170: return 8;
171: }
172: if (aExp instanceof GreaterExpression
173: || aExp instanceof GreaterOrEqualExpression
174: || aExp instanceof LessExpression
175: || aExp instanceof LessOrEqualExpression
176: || aExp instanceof InstanceOfExpression) {
177: return 9;
178: }
179: if (aExp instanceof ShiftLeftExpression
180: || aExp instanceof ShiftRightExpression
181: || aExp instanceof UnsignedShiftRightExpression) {
182: return 10;
183: }
184: if (aExp instanceof AddExpression
185: || aExp instanceof SubtractExpression) {
186: return 11;
187: }
188: if (aExp instanceof DivideExpression
189: || aExp instanceof RemainderExpression
190: || aExp instanceof MultiplyExpression) {
191: return 12;
192: }
193: if (aExp instanceof CastExpression) {
194: return 13;
195: }
196: if (aExp instanceof NotExpression
197: || aExp instanceof PreDecrement
198: || aExp instanceof PreIncrement
199: || aExp instanceof PlusExpression
200: || aExp instanceof MinusExpression) {
201: return 14;
202: }
203: if (aExp instanceof PostDecrement
204: || aExp instanceof PostIncrement
205: || aExp instanceof ObjectMethodCall
206: || aExp instanceof ObjectFieldAccess
207: || aExp instanceof ArrayAccess
208: || aExp instanceof CastExpression) {
209: return 15;
210: }
211: // literals should not be in parenthesis
212: //printDB("ConstantsManager Expression " + aExp
213: // + " not found return level 16");
214: return 16;
215: }
216:
217: /**
218: * All avaliable modifiers of the JAVA Language.
219: * @see java.lang.reflect.Modifier
220: * @return A String representation of all suitable modifier or
221: * an empty string.
222: *
223: */
224: public static String getModifierString(int access) {
225: String ret = "";
226: if ((Modifier.PRIVATE & access) == Modifier.PRIVATE) {
227: ret += "private ";
228: }
229: if ((Modifier.PROTECTED & access) == Modifier.PROTECTED) {
230: ret += "protected ";
231: }
232: if ((Modifier.PUBLIC & access) == Modifier.PUBLIC) {
233: ret += "public ";
234: }
235: if ((Modifier.SYNCHRONIZED & access) == Modifier.SYNCHRONIZED) {
236: ret += "synchronized ";
237: }
238: if ((Modifier.ABSTRACT & access) == Modifier.ABSTRACT) {
239: ret += "abstract ";
240: }
241: if ((Modifier.FINAL & access) == Modifier.FINAL) {
242: ret += "final ";
243: }
244: if ((Modifier.INTERFACE & access) == Modifier.INTERFACE) {
245: ret += "interface ";
246: }
247: if ((Modifier.NATIVE & access) == Modifier.NATIVE) {
248: ret += "native ";
249: }
250: if ((Modifier.STATIC & access) == Modifier.STATIC) {
251: ret += "static ";
252: }
253: if ((Modifier.STRICT & access) == Modifier.STRICT) {
254: ret += "strict ";
255: }
256: if ((Modifier.TRANSIENT & access) == Modifier.TRANSIENT) {
257: ret += "transient ";
258: }
259: if ((Modifier.VOLATILE & access) == Modifier.VOLATILE) {
260: ret += "volatile ";
261: }
262: /*
263: if (ret.length()>1) {
264: return ret.substring(0, ret.length()-1);
265: }
266: */
267: return ret;
268: }
269:
270: public static void printDB(String aLine) {
271: System.err.println(aLine);
272: getBinaryExpressionString(null).length();
273: }
274: }
|