Class ClassInfo
- All Implemented Interfaces:
Finalizable
public class ClassInfo extends java.lang.Object implements Finalizable
This class handles caching internally and its advisable to not store
references directly to objects of this class. The static factory method
getClassInfo(Class) should be used to retrieve an instance
from the cache. Internally the Class associated with a ClassInfo
instance is kept as WeakReference, so it not safe to reference
and instance without the Class being either strongly or softly reachable.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceClassInfo.ClassInfoAction -
Field Summary
Fields Modifier and Type Field Description inthash -
Method Summary
Modifier and Type Method Description static voidclearModifiedExpandos()voidfinalizeReference()static intfullSize()static java.util.Collection<ClassInfo>getAllClassInfo()ClassLoaderForClassArtifactsgetArtifactClassLoader()CachedClassgetCachedClass()static ClassInfogetClassInfo(java.lang.Class cls)MetaClassgetMetaClass()Returns theMetaClassfor theClassassociated with thisClassInfo.MetaClassgetMetaClass(java.lang.Object obj)MetaClassgetMetaClassForClass()ExpandoMetaClassgetModifiedExpando()MetaClassgetPerInstanceMetaClass(java.lang.Object obj)MetaClassgetStrongMetaClass()java.lang.Class<?>getTheClass()Returns theClassassociated with thisClassInfo.intgetVersion()MetaClassgetWeakMetaClass()booleanhasPerInstanceMetaClasses()voidincVersion()voidlock()static voidonAllClassInfo(ClassInfo.ClassInfoAction action)static voidremove(java.lang.Class<?> cls)Removes aClassInfofrom the cache.voidsetPerInstanceMetaClass(java.lang.Object obj, MetaClass metaClass)voidsetStrongMetaClass(MetaClass answer)voidsetWeakMetaClass(MetaClass answer)static intsize()voidunlock()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
hash
public final int hash- See Also:
- Constant Field Values
-
-
Method Details
-
getVersion
public int getVersion() -
incVersion
public void incVersion() -
getModifiedExpando
-
clearModifiedExpandos
public static void clearModifiedExpandos() -
getTheClass
public final java.lang.Class<?> getTheClass()Returns theClassassociated with thisClassInfo.This method can return
nullif theClassis no longer reachable through any strong or soft references. A non-null return value indicates that thisClassInfois valid.- Returns:
- the
Classassociated with thisClassInfo, elsenull
-
getCachedClass
-
getArtifactClassLoader
-
getClassInfo
-
remove
public static void remove(java.lang.Class<?> cls)Removes aClassInfofrom the cache. This is useful in cases where the Class is parsed from a script, such as when using GroovyClassLoader#parseClass, and is executed for its result but the Class is not retained or cached. Removing theClassInfoassociated with the Class will make the Class and its ClassLoader eligible for garbage collection sooner that it would otherwise.- Parameters:
cls- the Class associated with the ClassInfo to remove from cache
-
getAllClassInfo
-
onAllClassInfo
-
getStrongMetaClass
-
setStrongMetaClass
-
getWeakMetaClass
-
setWeakMetaClass
-
getMetaClassForClass
-
getMetaClass
Returns theMetaClassfor theClassassociated with thisClassInfo. If noMetaClassexists one will be created.It is not safe to call this method without a
Classassociated with thisClassInfo. It is advisable to aways retrieve a ClassInfo instance from the cache by using the static factory methodgetClassInfo(Class)to ensure the referenced Class is strongly reachable.- Returns:
- a
MetaClassinstance
-
getMetaClass
-
size
public static int size() -
fullSize
public static int fullSize() -
lock
public void lock() -
unlock
public void unlock() -
getPerInstanceMetaClass
-
setPerInstanceMetaClass
-
hasPerInstanceMetaClasses
public boolean hasPerInstanceMetaClasses() -
finalizeReference
public void finalizeReference()- Specified by:
finalizeReferencein interfaceFinalizable
-