mjc

org.multijava.util
Class Utils

java.lang.Object
  extended byorg.multijava.util.Utils
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
CAbstractMethodSet, CAugmentationMap, CContext, CFieldTable, CGFCollectionMap, CMember, CModifier, CodeSequence, Compiler, CSpecializedType, CStdType, CThrowableInfo, CTopLevel, CType, MemberAccess, MjcPrettyPrinter, Phylum, TypeLoader

public abstract class Utils
extends java.lang.Object
implements java.lang.Cloneable

This class defines severals utilities methods used in source code


Field Summary
private static boolean caseInsensitiveFS
           
private static java.lang.String CURRENT
           
static int DBG_LEVEL_HIGH
           
static int DBG_LEVEL_LOW
           
static int DBG_LEVEL_NO
           
private static boolean DEBUG_ENABLED
           
private static int debugLevel
           
private static java.lang.String FILE_SEP
           
private static java.lang.String UP
           
 
Constructor Summary
Utils()
           
 
Method Summary
static void assertTrue(boolean b)
          Check if an assertion is valid
static void assertTrue(boolean b, java.lang.String message)
          Check if an assertion is valid
static java.lang.Object[] combineArrays(java.lang.Object[] x, java.lang.Object[] y)
          Combines two reference arrays of into one; the result has the same dynamic type as the first argument.
static java.lang.String escapeString(java.lang.String val)
          Returns a String formed by translating Unicode characters for the standard Java escape sequences into the corresponding escape sequences from JLS2, 3.10.6.
static java.lang.String escapeString(java.lang.String val, boolean escapeApostrophes)
          Returns a String formed by translating Unicode characters for the standard Java escape sequences into the corresponding escape sequences from JLS2, 3.10.6.
static void fail()
          Throws an error.
static void fail(java.lang.String message)
          Throws an error.
static java.lang.String getFilePath(java.io.File f)
          Returns the canonical path of the given File, or the absolute path if an exception is thrown by the underlying file system when constructing the canonical path.
static boolean hasFlag(long modifiers, long flags)
          Returns true if any of the bits set in flags are are also enabled in modifiers.
static boolean hasOtherFlags(long modifiers, long flags)
          Returns true if modifiers has any bits set other than those in flags.
static java.util.List parsePathParts(java.io.File path)
          Returns a list of Strings representing the parts of the given path, assembled by repeatedly invoking getName() on getParentFile() of the given path until no parent path parts remain.
static java.lang.String relativePathTo(java.io.File file)
          Returns a String representing the relative path from the current user directory, user.dir, to the given file.
static java.lang.String[] splitQualifiedName(java.lang.String name)
          Splits a string like: "java/lang/System/out" into two strings: "java/lang/System" and "out"
static java.lang.String[] splitQualifiedName(java.lang.String name, char separator)
          Splits a string like: "java/lang/System/out" into two strings: "java/lang/System" and "out"
static long stripJavaModifiers(long modifiers)
          Returns the modifiers with the Java bit masks stripped.
static long stripNonJavaModifiers(long modifiers)
          Returns the modifiers with the non-Java bit masks stripped.
static long stripPrivateModifier(long modifiers)
          Returns the modifiers with the Private modifier stripped.
static java.lang.String unescapeString(java.lang.String val)
          Returns a String formed by translating Java escape sequences in the given String into single Unicode characters.
static java.lang.Object[] vectorToArray(java.util.Vector vect, java.lang.Class type)
          Creates a typed array from a vector.
static int[] vectorToIntArray(java.util.Vector vect)
          Creates a int array from a vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DBG_LEVEL_NO

public static final int DBG_LEVEL_NO

DBG_LEVEL_LOW

public static final int DBG_LEVEL_LOW

DBG_LEVEL_HIGH

public static final int DBG_LEVEL_HIGH

CURRENT

private static java.lang.String CURRENT

UP

private static java.lang.String UP

FILE_SEP

private static java.lang.String FILE_SEP

caseInsensitiveFS

private static boolean caseInsensitiveFS

DEBUG_ENABLED

private static final boolean DEBUG_ENABLED

debugLevel

private static int debugLevel
Constructor Detail

Utils

public Utils()
Method Detail

assertTrue

public static final void assertTrue(boolean b,
                                    java.lang.String message)
Check if an assertion is valid

Throws:
java.lang.RuntimeException - the entire token reference

fail

public static final void fail(java.lang.String message)
Throws an error.

Throws:
java.lang.RuntimeException - the entire token reference

assertTrue

public static final void assertTrue(boolean b)
Check if an assertion is valid

Throws:
java.lang.RuntimeException - the entire token reference

fail

public static final void fail()
Throws an error.

Throws:
java.lang.RuntimeException - the entire token reference

hasFlag

public static boolean hasFlag(long modifiers,
                              long flags)
Returns true if any of the bits set in flags are are also enabled in modifiers. This method is usually used to check for a single flag.

Parameters:
modifiers - the modifiers bit mask
flags - the flags to be checked
Returns:
(modifiers & flags) != 0

hasOtherFlags

public static boolean hasOtherFlags(long modifiers,
                                    long flags)
Returns true if modifiers has any bits set other than those in flags.

Parameters:
modifiers - the modifiers bit mask
flags - the flags that are supposed to be in modifiers
Returns:
(modifiers & flags) != modifiers

stripNonJavaModifiers

public static long stripNonJavaModifiers(long modifiers)
Returns the modifiers with the non-Java bit masks stripped.

Parameters:
modifiers - the modifiers bit mask
Returns:
modifiers & 0x0000FFFF

stripJavaModifiers

public static long stripJavaModifiers(long modifiers)
Returns the modifiers with the Java bit masks stripped.

Parameters:
modifiers - the modifiers bit mask
Returns:
modifiers & 0xFFFFFFFFFFFF0000L

stripPrivateModifier

public static long stripPrivateModifier(long modifiers)
Returns the modifiers with the Private modifier stripped.

Parameters:
modifiers - the modifiers bit mask
Returns:
modifiers & 0xFFFFFFFFFFFFFFFDL

vectorToArray

public static java.lang.Object[] vectorToArray(java.util.Vector vect,
                                               java.lang.Class type)
Creates a typed array from a vector.

Parameters:
vect - the vector containing the elements
type - the type of the elements

vectorToIntArray

public static int[] vectorToIntArray(java.util.Vector vect)
Creates a int array from a vector.

Parameters:
vect - the vector containing the elements

combineArrays

public static java.lang.Object[] combineArrays(java.lang.Object[] x,
                                               java.lang.Object[] y)
Combines two reference arrays of into one; the result has the same dynamic type as the first argument.


splitQualifiedName

public static java.lang.String[] splitQualifiedName(java.lang.String name,
                                                    char separator)
Splits a string like: "java/lang/System/out" into two strings: "java/lang/System" and "out"


splitQualifiedName

public static java.lang.String[] splitQualifiedName(java.lang.String name)
Splits a string like: "java/lang/System/out" into two strings: "java/lang/System" and "out"


unescapeString

public static final java.lang.String unescapeString(java.lang.String val)
Returns a String formed by translating Java escape sequences in the given String into single Unicode characters. The escape sequences are those of JLS2, 3.10.6 with the addition of Unicode escapes.

See Also:
escapeString(String)

escapeString

public static final java.lang.String escapeString(java.lang.String val)
Returns a String formed by translating Unicode characters for the standard Java escape sequences into the corresponding escape sequences from JLS2, 3.10.6. Octal and unicode escapes are not generated.

See Also:
escapeString(String,boolean), unescapeString(String)

escapeString

public static final java.lang.String escapeString(java.lang.String val,
                                                  boolean escapeApostrophes)
Returns a String formed by translating Unicode characters for the standard Java escape sequences into the corresponding escape sequences from JLS2, 3.10.6. Octal and unicode escapes are not generated.

See Also:
unescapeString(String)

relativePathTo

public static final java.lang.String relativePathTo(java.io.File file)
Returns a String representing the relative path from the current user directory, user.dir, to the given file.

 requires file != null;
 


parsePathParts

public static final java.util.List parsePathParts(java.io.File path)
Returns a list of Strings representing the parts of the given path, assembled by repeatedly invoking getName() on getParentFile() of the given path until no parent path parts remain.


getFilePath

public static java.lang.String getFilePath(java.io.File f)
Returns the canonical path of the given File, or the absolute path if an exception is thrown by the underlying file system when constructing the canonical path.


mjc

mjc is Copyright (C) 2000-2004 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. mjc is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.