JAC project
AOPSYS
CEDRIC & LIP6 labs

org.objectweb.jac.core.rtti
Class NamingConventions

java.lang.Object
  |
  +--org.objectweb.jac.core.rtti.NamingConventions

public class NamingConventions
extends Object

This class provides some useful methods to get some information regarding the naming conventions.

Author:
Renaud Pawlak, Laurent Martelli

Field Summary
static int ADDER
          Constant to represent collection adders.
static String[] adderPrefixes
          Store default collection adder prefixes (add..., put...).
static int GETTER
          Constant to represent field getters.
static String[] getterPrefixes
          Store default field getter prefixes (get...).
static int MODIFIER
          Constant to represent field modifiers.
static int REMOVER
          Constant to represent collection removers.
static String[] removerPrefixes
          Store default collection remover prefixes (rmv..., del..., remove...).
static int SETTER
          Constant to represent field setters.
static String[] setterPrefixes
          Store default field setter prefixes (set...).
 
Constructor Summary
NamingConventions()
           
 
Method Summary
static String capitalize(String str)
          Takes a string and returns a new capitalized one.
static String fieldForMethod(Class cl, String method)
          Returns the field name for a given method (modifier or getter).
static Method getDeclaredMethodByName(Class c, String name)
          Returns a declared method of a class c only by knowing its name.
static String getNormalizedAspectClassName(String programName, String aspectName)
          Returns the normalized class name of an aspect regarding its normalized name and the program it belongs to.
static String getNormalizedAspectName(String name)
          Returns the normalized name of an aspect regarding its class name.
static String getNormalizedString(String string)
          Returns the normalized name for a string.
static String getPackageName(Class cl)
          Returns the package name of the given class.
static String getPlural(String name)
          Returns the plural of a name
static String getPrintableParameterTypes(AbstractMethodItem method)
          Returns a printable representation of the argument types of a method (or a constructor if needed).
static String getPrintableParameterTypes(AccessibleObject method)
          Returns a printable representation of the argument types of a method (or a constructor if needed).
static String getShortClassName(Class cl)
          Returns the short name of a class.
static String getShortClassName(ClassItem cli)
          Returns the short name of a class.
static String getShortConstructorName(Constructor constructor)
          Returns the short name of a given constructor.
static String getShortConstructorName(ConstructorItem constructor)
          Returns the short name of a given constructor.
static String getSingular(String name)
          Return the singular of a name.
static String getStandardClassName(Class cl)
           
static String getUnderscoredString(String string)
          Returns the underscored name for a normalized string.
static String getUnprefixedString(String string)
          Get an unprefixed string from a prefixed string.
static boolean isAdder(String name)
          Return true if the name matches a adder profile (i.e.
static boolean isGetter(String name)
          Return true if the name matches a getter profile (i.e.
static boolean isInPrefixes(String candidate, String[] prefixes)
          Tells if the the method name is equal to one of the given prefixes.
static boolean isModifier(String name)
          Returns true if the name matches a modifier profile (i.e.
static int isPrefixedWith(String candidate, String[] prefixes)
          Tell if the string is prefixed with one of the given prefixes.
static boolean isRemover(String name)
          Return true if the name matches a remover profile (i.e.
static boolean isSetter(String name)
          Return true if the name matches a setter profile (i.e.
static String lowerFirst(String string)
          Lower case the first character of a string.
static String maybeLowerFirst(String string)
          Lower case the first character of a string unless it starts with at least two upper case letters.
static String removePrefixFrom(String string)
          Removes the prefix from a prefixed string.
static String textForName(String name)
          Returns the printable textual representation of a field or method name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODIFIER

public static final int MODIFIER
Constant to represent field modifiers.

See Also:
Constant Field Values

GETTER

public static final int GETTER
Constant to represent field getters.

See Also:
Constant Field Values

SETTER

public static final int SETTER
Constant to represent field setters.

See Also:
Constant Field Values

ADDER

public static final int ADDER
Constant to represent collection adders.

See Also:
Constant Field Values

REMOVER

public static final int REMOVER
Constant to represent collection removers.

See Also:
Constant Field Values

getterPrefixes

public static final String[] getterPrefixes
Store default field getter prefixes (get...).


setterPrefixes

public static final String[] setterPrefixes
Store default field setter prefixes (set...).


adderPrefixes

public static final String[] adderPrefixes
Store default collection adder prefixes (add..., put...).


removerPrefixes

public static final String[] removerPrefixes
Store default collection remover prefixes (rmv..., del..., remove...).

Constructor Detail

NamingConventions

public NamingConventions()
Method Detail

getShortClassName

public static String getShortClassName(ClassItem cli)
Returns the short name of a class.

If it is a well-known java class or a well-known JAC class, truncates the packages to give only the class name. It is is an array, add [] after the primitive type.


getShortClassName

public static String getShortClassName(Class cl)
Returns the short name of a class.

If it is a well-known java class or a well-known JAC class, truncates the packages to give only the class name. It is is an array, add [] after the primitive type.

Parameters:
cl - the class

getStandardClassName

public static String getStandardClassName(Class cl)

getShortConstructorName

public static String getShortConstructorName(Constructor constructor)
Returns the short name of a given constructor.

By default, the name of a constructor contains the full path name of the constructor class. Thus, this method is equivalent to get the short name of the constructor class.

Parameters:
constructor - a constructor
Returns:
its short name
See Also:
getShortClassName(Class)

getShortConstructorName

public static String getShortConstructorName(ConstructorItem constructor)
Returns the short name of a given constructor.

By default, the name of a constructor contains the full path name of the constructor class. Thus, this method is equivalent to get the short name of the constructor class.

Parameters:
constructor - a constructor
Returns:
its short name
See Also:
getShortClassName(ClassItem)

getPackageName

public static String getPackageName(Class cl)
Returns the package name of the given class.

Parameters:
cl - the class to get the package of
Returns:
the name of the package where cl is defined

getPrintableParameterTypes

public static String getPrintableParameterTypes(AccessibleObject method)
Returns a printable representation of the argument types of a method (or a constructor if needed).

For instance, for a method that takes one object, one string, and one string array, the result will look like "Object, String, String[]".

Parameters:
method - the involved method
Returns:
a printable string
See Also:
getPrintableParameterTypes(AbstractMethodItem)

getPrintableParameterTypes

public static String getPrintableParameterTypes(AbstractMethodItem method)
Returns a printable representation of the argument types of a method (or a constructor if needed).

Same as its homonym but uing RTTI meta item.

Parameters:
method - the involved method
Returns:
a printable string
See Also:
getPrintableParameterTypes(AccessibleObject)

getDeclaredMethodByName

public static Method getDeclaredMethodByName(Class c,
                                             String name)
Returns a declared method of a class c only by knowing its name. Returns null if not found (to be modified to raise an exception.

Parameters:
c - the class.
name - the name of the method to find.
Returns:
the method (null if not found).

isPrefixedWith

public static int isPrefixedWith(String candidate,
                                 String[] prefixes)
Tell if the string is prefixed with one of the given prefixes.

Returns 0 if the candidate is not prefixed by any of the given prefixes and also if the candidate exactly equals one of the prefixes.

Parameters:
candidate - the string to test
prefixes - the tested prefixes
Returns:
the length of the matching prefix, 0 if not prefixed

isInPrefixes

public static boolean isInPrefixes(String candidate,
                                   String[] prefixes)
Tells if the the method name is equal to one of the given prefixes.

Returns:
true if equals

isSetter

public static boolean isSetter(String name)
Return true if the name matches a setter profile (i.e. set...).

Parameters:
name - the string to test
Returns:
true if setter profile

isGetter

public static boolean isGetter(String name)
Return true if the name matches a getter profile (i.e. get...).

Parameters:
name - the string to test
Returns:
true if getter profile

isAdder

public static boolean isAdder(String name)
Return true if the name matches a adder profile (i.e. add...).

Parameters:
name - the string to test
Returns:
true if adder profile

isRemover

public static boolean isRemover(String name)
Return true if the name matches a remover profile (i.e. rmv..., del..., remove...).

Parameters:
name - the string to test
Returns:
true if remover profile

isModifier

public static boolean isModifier(String name)
Returns true if the name matches a modifier profile (i.e. setter, adder, or remover profile).

Parameters:
name - the string to test
Returns:
true if modifier profile

capitalize

public static String capitalize(String str)
Takes a string and returns a new capitalized one.

Parameters:
str - the original string
Returns:
a new capitalized version of str

getNormalizedString

public static String getNormalizedString(String string)
Returns the normalized name for a string.

A normalized string is a blank-free word where each relevant substring starts with an upcase character.

For instance:

Parameters:
string - the string to normalize
Returns:
the normalized string

getUnderscoredString

public static String getUnderscoredString(String string)
Returns the underscored name for a normalized string.

A normalized string is a blank-free word where each relevant substring starts with an upcase character.

For instance:

Parameters:
string - a normalized string
Returns:
the underscored string

lowerFirst

public static String lowerFirst(String string)
Lower case the first character of a string.

Parameters:
string - the string to transform
Returns:
the same string but with the first character lowered

maybeLowerFirst

public static String maybeLowerFirst(String string)
Lower case the first character of a string unless it starts with at least two upper case letters.

Parameters:
string - the string to transform
Returns:
the same string but with the first character lowered

getUnprefixedString

public static String getUnprefixedString(String string)
Get an unprefixed string from a prefixed string.

NOTE: this method is not semantically indentical to removePrefixFrom.

For instance:

Parameters:
string - a prefixed string
Returns:
the corresponding unprefixed string
See Also:
removePrefixFrom(String)

getPlural

public static String getPlural(String name)
Returns the plural of a name

Parameters:
name - the name
Returns:
the plural of name

getSingular

public static String getSingular(String name)
Return the singular of a name. Handles english -ies plurals, and -s. If no plural is recognized, returns name.


removePrefixFrom

public static String removePrefixFrom(String string)
Removes the prefix from a prefixed string.

NOTE: this method is not semantically indentical to getUnprefixedString.

For instance:

Parameters:
string - a prefixed string
Returns:
the corresponding unprefixed string
See Also:
getUnprefixedString(String)

fieldForMethod

public static String fieldForMethod(Class cl,
                                    String method)
Returns the field name for a given method (modifier or getter).

Parameters:
cl - the class where the method is supposed to be
method - the name of the method
Returns:
the field for this method if exist

textForName

public static String textForName(String name)
Returns the printable textual representation of a field or method name.

Parameters:
name - the field or method name
Returns:
a "natural-language-like" textual representation

getNormalizedAspectName

public static String getNormalizedAspectName(String name)
Returns the normalized name of an aspect regarding its class name.

E.g.:


getNormalizedAspectClassName

public static String getNormalizedAspectClassName(String programName,
                                                  String aspectName)
Returns the normalized class name of an aspect regarding its normalized name and the program it belongs to.


Contact JAC development team:
Renaud Pawlak
Lionel Seinturier
Laurent Martelli