Package net.sf.cglib.core
Class DefaultNamingPolicy
- java.lang.Object
-
- net.sf.cglib.core.DefaultNamingPolicy
-
- All Implemented Interfaces:
NamingPolicy
public class DefaultNamingPolicy extends java.lang.Object implements NamingPolicy
The default policy used byAbstractClassGenerator
. Generates names such asnet.sf.cglib.Foo$$EnhancerByCGLIB$$38272841
This is composed of a prefix based on the name of the superclass, a fixed string incorporating the CGLIB class responsible for generation, and a hashcode derived from the parameters used to create the object. If the same name has been previously been used in the same
ClassLoader
, a suffix is added to ensure uniqueness.
-
-
Field Summary
Fields Modifier and Type Field Description static DefaultNamingPolicy
INSTANCE
private static boolean
STRESS_HASH_CODE
This allows to test collisions ofkey.hashCode()
.
-
Constructor Summary
Constructors Constructor Description DefaultNamingPolicy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
TheNamingPolicy
in use does not currently, but may in the future, affect the caching of classes generated byAbstractClassGenerator
, so this is a reminder that you should correctly implementequals
andhashCode
to avoid generating too many classes.java.lang.String
getClassName(java.lang.String prefix, java.lang.String source, java.lang.Object key, Predicate names)
Choose a name for a generated class.protected java.lang.String
getTag()
Returns a string which is incorporated into every generated class name.int
hashCode()
-
-
-
Field Detail
-
INSTANCE
public static final DefaultNamingPolicy INSTANCE
-
STRESS_HASH_CODE
private static final boolean STRESS_HASH_CODE
This allows to test collisions ofkey.hashCode()
.
-
-
Method Detail
-
getClassName
public java.lang.String getClassName(java.lang.String prefix, java.lang.String source, java.lang.Object key, Predicate names)
Description copied from interface:NamingPolicy
Choose a name for a generated class.- Specified by:
getClassName
in interfaceNamingPolicy
- Parameters:
prefix
- a dotted-name chosen by the generating class (possibly to put the generated class in a particular package)source
- the fully-qualified class name of the generating class (for example "net.sf.cglib.Enhancer")key
- A key object representing the state of the parameters; for caching to work properly, equal keys should result in the same generated class name. The default policy incorporateskey.hashCode()
into the class name.names
- a predicate that returns true if the given classname has already been used in the same ClassLoader.- Returns:
- the fully-qualified class name
-
getTag
protected java.lang.String getTag()
Returns a string which is incorporated into every generated class name. By default returns "ByCGLIB"
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:NamingPolicy
TheNamingPolicy
in use does not currently, but may in the future, affect the caching of classes generated byAbstractClassGenerator
, so this is a reminder that you should correctly implementequals
andhashCode
to avoid generating too many classes.- Specified by:
equals
in interfaceNamingPolicy
- Overrides:
equals
in classjava.lang.Object
-
-