org.fuin.srcgen4javassist
Class SgUtils

java.lang.Object
  extended by org.fuin.srcgen4javassist.SgUtils

public final class SgUtils
extends Object

Some helper for the package.


Method Summary
static void addToStringMethod(SgClassPool pool, SgClass clasz, List<SgField> fields)
          Creates an toString() method with all fields.
static void checkClassModifiers(int modifiers, boolean isInterface, boolean isInnerClass)
          Checks if the modifiers are valid for a class.
static void checkConstructorModifiers(int modifiers)
          Checks if the modifiers are valid for a constructor.
static void checkFieldModifiers(int modifiers)
          Checks if the modifiers are valid for a field.
static void checkMethodModifiers(int modifiers)
          Checks if the modifiers are valid for a method.
static String concatPackages(String package1, String package2)
          Merge two packages into one.
static List<SgAnnotation> createAnnotations(Annotation[] ann)
          Create a list of annotations.
static String createTypeSignature(String methodName, Class<?>[] paramTypes)
          Returns the "type" signature of the method.
static String firstCharUpper(String str)
          Converts the first character into upper case.
static boolean isEmpty(String str)
           Checks if a String is empty ("") or null.
static String modifierMatrixToHtml()
          Create a simple HTML table for the modifier matrix.
static String replace(String text, String searchString, String replacement, int max)
           Replaces a String with another String inside a larger String, for the first max values of the search String.
static int toModifiers(String modifiers)
          Returns a Java "Modifier" value for a list of modifier names.
static String uppercaseToUnderscore(String str)
          Inserts an underscore before every upper case character and returns an all lower case string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

checkClassModifiers

public static void checkClassModifiers(int modifiers,
                                       boolean isInterface,
                                       boolean isInnerClass)
Checks if the modifiers are valid for a class. If any of the modifiers is not valid an IllegalArgumentException is thrown.

Parameters:
modifiers - Modifiers.
isInterface - Are the modifiers from an interface?
isInnerClass - Is it an inner class?

checkFieldModifiers

public static void checkFieldModifiers(int modifiers)
Checks if the modifiers are valid for a field. If any of the modifiers is not valid an IllegalArgumentException is thrown.

Parameters:
modifiers - Modifiers.

checkMethodModifiers

public static void checkMethodModifiers(int modifiers)
Checks if the modifiers are valid for a method. If any of the modifiers is not valid an IllegalArgumentException is thrown.

Parameters:
modifiers - Modifiers.

checkConstructorModifiers

public static void checkConstructorModifiers(int modifiers)
Checks if the modifiers are valid for a constructor. If any of the modifiers is not valid an IllegalArgumentException is thrown.

Parameters:
modifiers - Modifiers.

uppercaseToUnderscore

public static String uppercaseToUnderscore(String str)
Inserts an underscore before every upper case character and returns an all lower case string. If the first character is upper case an underscore will not be inserted.

Parameters:
str - String to convert.
Returns:
Lower case + underscored text.

firstCharUpper

public static String firstCharUpper(String str)
Converts the first character into upper case.

Parameters:
str - String to convert - Can be null or empty string (In both cases the unchanged value will be returned).
Returns:
Same string but first character upper case-

concatPackages

public static String concatPackages(String package1,
                                    String package2)
Merge two packages into one. If any package is null or empty no "." will be added. If both packages are null an empty string will be returned.

Parameters:
package1 - First package - Can also be null or empty.
package2 - Second package - Can also be null or empty.
Returns:
Both packages added with ".".

addToStringMethod

public static void addToStringMethod(SgClassPool pool,
                                     SgClass clasz,
                                     List<SgField> fields)
Creates an toString() method with all fields.

Parameters:
pool - Pool to use.
clasz - Class to add the new method to.
fields - List of fields to output.

modifierMatrixToHtml

public static String modifierMatrixToHtml()
Create a simple HTML table for the modifier matrix. This is helpful to check if the matrix is valid.

Returns:
Modifier matrix HTML table.

toModifiers

public static int toModifiers(String modifiers)
Returns a Java "Modifier" value for a list of modifier names.

Parameters:
modifiers - Modifier names separated by spaces.
Returns:
Modifiers.

replace

public static String replace(String text,
                             String searchString,
                             String replacement,
                             int max)

Replaces a String with another String inside a larger String, for the first max values of the search String.

A null reference passed to this method is a no-op.

 StringUtils.replace(null, *, *, *)         = null
 StringUtils.replace("", *, *, *)           = ""
 StringUtils.replace("any", null, *, *)     = "any"
 StringUtils.replace("any", *, null, *)     = "any"
 StringUtils.replace("any", "", *, *)       = "any"
 StringUtils.replace("any", *, *, 0)        = "any"
 StringUtils.replace("abaa", "a", null, -1) = "abaa"
 StringUtils.replace("abaa", "a", "", -1)   = "b"
 StringUtils.replace("abaa", "a", "z", 0)   = "abaa"
 StringUtils.replace("abaa", "a", "z", 1)   = "zbaa"
 StringUtils.replace("abaa", "a", "z", 2)   = "zbza"
 StringUtils.replace("abaa", "a", "z", -1)  = "zbzz"
 

Parameters:
text - text to search and replace in, may be null
searchString - the String to search for, may be null
replacement - the String to replace it with, may be null
max - maximum number of values to replace, or -1 if no maximum
Returns:
the text with any replacements processed, null if null String input

isEmpty

public static boolean isEmpty(String str)

Checks if a String is empty ("") or null.

 StringUtils.isEmpty(null)      = true
 StringUtils.isEmpty("")        = true
 StringUtils.isEmpty(" ")       = false
 StringUtils.isEmpty("bob")     = false
 StringUtils.isEmpty("  bob  ") = false
 

NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().

Parameters:
str - the String to check, may be null
Returns:
true if the String is empty or null

createTypeSignature

public static String createTypeSignature(String methodName,
                                         Class<?>[] paramTypes)
Returns the "type" signature of the method.

Parameters:
methodName - Name of the method.
paramTypes - Argument types.
Returns:
Method name and argument types (like "methodXY(String, int, boolean)").

createAnnotations

public static List<SgAnnotation> createAnnotations(Annotation[] ann)
Create a list of annotations.

Parameters:
ann - Java annotation array.
Returns:
List of annotations.


Copyright © 2011 Future Invent Informationsmanagement GmbH. All Rights Reserved.