ConstantsManager.java :  » Database-DBMS » Ozone-1.1 » org » infozone » tools » janalyzer » Java Open Source

Java Open Source » Database DBMS » Ozone 1.1 
Ozone 1.1 » org » infozone » tools » janalyzer » ConstantsManager.java
// You can redistribute this software and/or modify it under the terms of
// the Infozone Software License version 2 published by the Infozone Group
// (http://www.infozone-group.org).
//
// Copyright (C) @year@ by The Infozone Group. All rights reserved.
//
// $Id: ConstantsManager.java,v 1.1 2002/05/10 08:59:12 per_nyfelt Exp $

package org.infozone.tools.janalyzer;

/** All available Expressions and Nodes of the syntax tree */
import koala.dynamicjava.tree.*;

/** For all available Modifier strings. */
import java.lang.reflect.Modifier;


/**
 * This class returns String Constants for Binary Expressions,
 * Access Modifier and so on.
 * It's used by the JavaCodeAnalyzer class in this package.
 *
 * @version $Revision: 1.1 $ $Date: 2002/05/10 08:59:12 $
 * @author <a href="http://www.softwarebuero.de">SMB</a>
 * @see org.infozone.janalyzer.JavaCodeAnalyzer for details
 */
public final class ConstantsManager extends java.lang.Object {
    
    
    public static String getBinaryExpressionString( Expression aExp ) {
        if (aExp instanceof AddExpression) {
            return "+";
        } 
        if (aExp instanceof AddAssignExpression) {
            return "+=";
        } 
        if (aExp instanceof BitAndAssignExpression) {
            return "&=";
        } 
        if (aExp instanceof BitOrAssignExpression) {
            return "|=";
        } 
        if (aExp instanceof DivideAssignExpression) {
            return "/=";
        } 
        if (aExp instanceof ExclusiveOrAssignExpression) {
            return "^=";
        } 
        if (aExp instanceof MultiplyAssignExpression) {
            return "*=";
        } 
        if (aExp instanceof RemainderExpression) {
            return "%";
        } 
        if (aExp instanceof RemainderAssignExpression) {
            return "%=";
        } 
        if (aExp instanceof ShiftLeftAssignExpression) {
            return ">>=";
        } 
        if (aExp instanceof ShiftRightAssignExpression) {
            return "<<=";
        } 
        if (aExp instanceof SimpleAssignExpression) {
            return "=";
        } 
        if (aExp instanceof SubtractAssignExpression) {
            return "-=";
        } 
        if (aExp instanceof UnsignedShiftRightAssignExpression) {
            return ">>>=";
        } 
        if (aExp instanceof AndExpression) {
            return "&&";
        } 
        if (aExp instanceof BitAndExpression) {
            return "&";
        } 
        if (aExp instanceof BitOrExpression) {
            return "|";
        } 
        if (aExp instanceof DivideExpression) {
            return "/";
        } 
        if (aExp instanceof EqualExpression) {
            return "==";
        } 
        if (aExp instanceof ExclusiveOrExpression) {
            return "^";
        } 
        if (aExp instanceof GreaterExpression) {
            return ">";
        } 
        if (aExp instanceof GreaterOrEqualExpression) {
            return ">=";
        } 
        if (aExp instanceof LessExpression) {
            return "<";
        } 
        if (aExp instanceof LessOrEqualExpression) {
            return "<=";
        } 
        if (aExp instanceof MultiplyExpression) {
            return "*";
        } 
        if (aExp instanceof NotEqualExpression) {
            return "!=";
        } 
        if (aExp instanceof OrExpression) {
            return "||";
        } 
        if (aExp instanceof ShiftLeftExpression) {
            return "<<";
        } 
        if (aExp instanceof ShiftRightExpression) {
            return ">>";
        } 
        if (aExp instanceof SimpleAssignExpression) {
            return "=";
        } 
        if (aExp instanceof SubtractExpression) {
            return "-";
        } 
        if (aExp instanceof UnsignedShiftRightExpression) {
            return ">>>";
        } 
        return "Constants Manager: unknown BinaryExpressionString " + aExp;
    } 
    
    
    /**
     * The right operator Precedence of all conditional operators in binary expressions.
     * @see package koala.dynamicjava.tree
     * @return A int value of the level.
     *
     */
    public static int getExpressionLevel( Expression aExp ) {
        if (aExp instanceof AddAssignExpression || aExp instanceof BitAndAssignExpression 
                || aExp instanceof BitOrAssignExpression || aExp instanceof DivideAssignExpression 
                || aExp instanceof ExclusiveOrAssignExpression || aExp instanceof MultiplyAssignExpression 
                || aExp instanceof RemainderAssignExpression || aExp instanceof ShiftLeftAssignExpression 
                || aExp instanceof ShiftRightAssignExpression || aExp instanceof SimpleAssignExpression 
                || aExp instanceof SubtractAssignExpression || aExp instanceof UnsignedShiftRightAssignExpression) {
            return 1;
        } 
        if (aExp instanceof ConditionalExpression) {
            return 2;
        } 
        if (aExp instanceof OrExpression) {
            return 3;
        } 
        if (aExp instanceof AndExpression) {
            return 4;
        } 
        if (aExp instanceof BitOrExpression) {
            return 5;
        } 
        if (aExp instanceof ExclusiveOrExpression) {
            return 6;
        } 
        if (aExp instanceof BitAndExpression) {
            return 7;
        } 
        if (aExp instanceof EqualExpression || aExp instanceof NotEqualExpression) {
            return 8;
        } 
        if (aExp instanceof GreaterExpression || aExp instanceof GreaterOrEqualExpression 
                || aExp instanceof LessExpression || aExp instanceof LessOrEqualExpression 
                || aExp instanceof InstanceOfExpression) {
            return 9;
        } 
        if (aExp instanceof ShiftLeftExpression || aExp instanceof ShiftRightExpression 
                || aExp instanceof UnsignedShiftRightExpression) {
            return 10;
        } 
        if (aExp instanceof AddExpression || aExp instanceof SubtractExpression) {
            return 11;
        } 
        if (aExp instanceof DivideExpression || aExp instanceof RemainderExpression 
                || aExp instanceof MultiplyExpression) {
            return 12;
        } 
        if (aExp instanceof CastExpression) {
            return 13;
        } 
        if (aExp instanceof NotExpression || aExp instanceof PreDecrement || aExp instanceof PreIncrement 
                || aExp instanceof PlusExpression || aExp instanceof MinusExpression) {
            return 14;
        } 
        if (aExp instanceof PostDecrement || aExp instanceof PostIncrement || aExp instanceof ObjectMethodCall 
                || aExp instanceof ObjectFieldAccess || aExp instanceof ArrayAccess || aExp instanceof CastExpression) {
            return 15;
        } 
        // literals should not be in parenthesis
        //printDB("ConstantsManager Expression " + aExp
        //        + " not found return level 16");
        return 16;
    } 
    
    
    /**
     * All avaliable modifiers of the JAVA Language.
     * @see java.lang.reflect.Modifier
     * @return A String representation of all suitable modifier or
     *                  an empty string.
     *
     */
    public static String getModifierString( int access ) {
        String ret = "";
        if ((Modifier.PRIVATE & access) == Modifier.PRIVATE) {
            ret += "private ";
        } 
        if ((Modifier.PROTECTED & access) == Modifier.PROTECTED) {
            ret += "protected ";
        } 
        if ((Modifier.PUBLIC & access) == Modifier.PUBLIC) {
            ret += "public ";
        } 
        if ((Modifier.SYNCHRONIZED & access) == Modifier.SYNCHRONIZED) {
            ret += "synchronized ";
        } 
        if ((Modifier.ABSTRACT & access) == Modifier.ABSTRACT) {
            ret += "abstract ";
        } 
        if ((Modifier.FINAL & access) == Modifier.FINAL) {
            ret += "final ";
        } 
        if ((Modifier.INTERFACE & access) == Modifier.INTERFACE) {
            ret += "interface ";
        } 
        if ((Modifier.NATIVE & access) == Modifier.NATIVE) {
            ret += "native ";
        } 
        if ((Modifier.STATIC & access) == Modifier.STATIC) {
            ret += "static ";
        } 
        if ((Modifier.STRICT & access) == Modifier.STRICT) {
            ret += "strict ";
        } 
        if ((Modifier.TRANSIENT & access) == Modifier.TRANSIENT) {
            ret += "transient ";
        } 
        if ((Modifier.VOLATILE & access) == Modifier.VOLATILE) {
            ret += "volatile ";
        } 
        /*
    if (ret.length()>1) {
      return ret.substring(0, ret.length()-1);
     }    
         */
        return ret;
    } 
    
    
    public static void printDB( String aLine ) {
        System.err.println( aLine );
        getBinaryExpressionString( null ).length();
    } 
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.