JML

org.multijava.util
Class Utils

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

public abstract class Utils
extends Object
implements Cloneable

This class defines severals utilities methods used in source code


Field Summary
private static boolean caseInsensitiveFS
           
private static 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 String FILE_SEP
           
private static String UP
           
 
Constructor Summary
Utils()
           
 
Method Summary
static void assertTrue(boolean b)
          Check if an assertion is valid
static void assertTrue(boolean b, String message)
          Check if an assertion is valid
static Object[] combineArrays(Object[] x, Object[] y)
          Combines two reference arrays of into one; the result has the same dynamic type as the first argument.
static String escapeString(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 String escapeString(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(String message)
          Throws an error.
static String getFilePath(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 List parsePathParts(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 String relativePathTo(File file)
          Returns a String representing the relative path from the current user directory, user.dir, to the given file.
static String[] splitQualifiedName(String name)
          Splits a string like: "java/lang/System/out" into two strings: "java/lang/System" and "out"
static String[] splitQualifiedName(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 String unescapeString(String val)
          Returns a String formed by translating Java escape sequences in the given String into single Unicode characters.
static Object[] vectorToArray(Vector vect, Class type)
          Creates a typed array from a vector.
static int[] vectorToIntArray(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 String CURRENT

UP

private static String UP

FILE_SEP

private static 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,
                                    String message)
Check if an assertion is valid

Throws:
RuntimeException - the entire token reference

fail

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

Throws:
RuntimeException - the entire token reference

assertTrue

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

Throws:
RuntimeException - the entire token reference

fail

public static final void fail()
Throws an error.

Throws:
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 Object[] vectorToArray(Vector vect,
                                     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(Vector vect)
Creates a int array from a vector.

Parameters:
vect - the vector containing the elements

combineArrays

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


splitQualifiedName

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


splitQualifiedName

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


unescapeString

public static final String unescapeString(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 String escapeString(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 String escapeString(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 String relativePathTo(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 List parsePathParts(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 String getFilePath(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.


JML

JML is Copyright (C) 1998-2002 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. This release depends on code from the MultiJava project and is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.