本文整理汇总了Java中org.codehaus.groovy.reflection.ReflectionCache类的典型用法代码示例。如果您正苦于以下问题:Java ReflectionCache类的具体用法?Java ReflectionCache怎么用?Java ReflectionCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReflectionCache类属于org.codehaus.groovy.reflection包,在下文中一共展示了ReflectionCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MetaClassImpl
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
/**
* Constructor
*
* @param theClass The class this is the metaclass dor
* @param add The methods for this class
*/
public MetaClassImpl(final Class theClass, MetaMethod[] add) {
this.theClass = theClass;
theCachedClass = ReflectionCache.getCachedClass(theClass);
this.isGroovyObject = GroovyObject.class.isAssignableFrom(theClass);
this.isMap = Map.class.isAssignableFrom(theClass);
this.registry = GroovySystem.getMetaClassRegistry();
metaMethodIndex = new MetaMethodIndex(theCachedClass);
final MetaMethod[] metaMethods = theCachedClass.getNewMetaMethods();
if (add != null && !(add.length == 0)) {
List<MetaMethod> arr = new ArrayList<MetaMethod>();
arr.addAll(Arrays.asList(metaMethods));
arr.addAll(Arrays.asList(add));
myNewMetaMethods = arr.toArray(new MetaMethod[arr.size()]);
additionalMetaMethods = metaMethods;
}
else {
myNewMetaMethods = metaMethods;
additionalMetaMethods = EMPTY;
}
}
示例2: getMetaProperty
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
/**
* @see MetaObjectProtocol#getMetaProperty(String)
*/
public MetaProperty getMetaProperty(String name) {
SingleKeyHashMap propertyMap = classPropertyIndex.getNotNull(theCachedClass);
if (propertyMap.containsKey(name)) {
return (MetaProperty) propertyMap.get(name);
} else if (staticPropertyIndex.containsKey(name)) {
return (MetaProperty) staticPropertyIndex.get(name);
} else {
propertyMap = classPropertyIndexForSuper.getNotNull(theCachedClass);
if (propertyMap.containsKey(name))
return (MetaProperty) propertyMap.get(name);
else {
CachedClass superClass = theCachedClass;
while (superClass != null && superClass != ReflectionCache.OBJECT_CLASS) {
final MetaBeanProperty property = findPropertyInClassHierarchy(name, superClass);
if (property != null) {
onSuperPropertyFoundInHierarchy(property);
return property;
}
superClass = superClass.getCachedSuperClass();
}
return null;
}
}
}
示例3: findPropertyInClassHierarchy
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
protected MetaBeanProperty findPropertyInClassHierarchy(String propertyName, CachedClass theClass) {
MetaBeanProperty property= null;
if (theClass == null)
return null;
final CachedClass superClass = theClass.getCachedSuperClass();
if (superClass == null)
return null;
MetaClass metaClass = this.registry.getMetaClass(superClass.getTheClass());
if(metaClass instanceof MutableMetaClass) {
property = getMetaPropertyFromMutableMetaClass(propertyName,metaClass);
if(property == null) {
if(superClass != ReflectionCache.OBJECT_CLASS) {
property = findPropertyInClassHierarchy(propertyName, superClass);
}
if(property == null) {
final Class[] interfaces = theClass.getTheClass().getInterfaces();
property = searchInterfacesForMetaProperty(propertyName, interfaces);
}
}
}
return property;
}
示例4: createMetaMethods
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
private static void createMetaMethods(final Class extensionClass, final List<MetaMethod> metaMethods, final boolean isStatic) {
CachedClass cachedClass = ReflectionCache.getCachedClass(extensionClass);
CachedMethod[] methods = cachedClass.getMethods();
for (CachedMethod method : methods) {
if (method.isStatic() && method.isPublic() && method.getParamsCount() > 0) {
// an extension method is found
metaMethods.add(isStatic?new NewStaticMetaMethod(method) : new NewInstanceMetaMethod(method));
}
}
}
示例5: box
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
/**
* Generates the bytecode to autobox the current value on the stack
*/
@Deprecated
public static boolean box(MethodVisitor mv, Class type) {
if (ReflectionCache.getCachedClass(type).isPrimitive && type != void.class) {
String returnString = "(" + BytecodeHelper.getTypeDescription(type) + ")Ljava/lang/Object;";
mv.visitMethodInsn(INVOKESTATIC, DTT_CLASSNAME, "box", returnString, false);
return true;
}
return false;
}
示例6: use
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
private void use(Class categoryClass) {
CachedClass cachedClass = ReflectionCache.getCachedClass(categoryClass);
LinkedList<CachedClass> classStack = new LinkedList<CachedClass>();
for (CachedClass superClass = cachedClass; superClass.getTheClass()!=Object.class; superClass = superClass.getCachedSuperClass()) {
classStack.add(superClass);
}
while (!classStack.isEmpty()) {
CachedClass klazz = classStack.removeLast();
applyUse(klazz);
}
}
示例7: castToType
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
public static Object castToType(Object object, Class type) {
if (object == null) return null;
if (type == Object.class) return object;
final Class aClass = object.getClass();
if (type == aClass) return object;
if (type.isAssignableFrom(aClass)) return object;
if (ReflectionCache.isArray(type)) return asArray(object, type);
if (type.isEnum()) {
return ShortTypeHandling.castToEnum(object, type);
} else if (Collection.class.isAssignableFrom(type)) {
return continueCastOnCollection(object, type);
} else if (type == String.class) {
return InvokerHelper.toString(object);
} else if (type == Character.class) {
return ShortTypeHandling.castToChar(object);
} else if (type == Boolean.class) {
return castToBoolean(object);
} else if (type == Class.class) {
return ShortTypeHandling.castToClass(object);
} else if (type.isPrimitive()) {
return castToPrimitive(object, type);
}
return continueCastOnNumber(object, type);
}
示例8: primitiveArrayBox
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
public static Object[] primitiveArrayBox(Object array) {
int size = Array.getLength(array);
Object[] ret = (Object[]) Array.newInstance(ReflectionCache.autoboxType(array.getClass().getComponentType()), size);
for (int i = 0; i < size; i++) {
ret[i] = Array.get(array, i);
}
return ret;
}
示例9: ClosureMetaMethod
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
public ClosureMetaMethod(String name, Class declaringClass, Closure c, CachedMethod doCall) {
super (doCall.getNativeParameterTypes());
this.name = name;
callable = c;
this.doCall = doCall;
this.declaringClass = ReflectionCache.getCachedClass(declaringClass);
}
示例10: createSetter
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
private static MetaMethod createSetter(final MetaProperty property, final MixinInMetaClass mixinInMetaClass) {
return new MetaMethod() {
final String name = getSetterName(property.getName());
{
setParametersTypes (new CachedClass [] {ReflectionCache.getCachedClass(property.getType())} );
}
public int getModifiers() {
return Modifier.PUBLIC;
}
public String getName() {
return name;
}
public Class getReturnType() {
return property.getType();
}
public CachedClass getDeclaringClass() {
return mixinInMetaClass.getInstanceClass();
}
public Object invoke(Object object, Object[] arguments) {
property.setProperty(mixinInMetaClass.getMixinInstance(object), arguments[0]);
return null;
}
};
}
示例11: getSuperClasses
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
protected LinkedList<CachedClass> getSuperClasses() {
LinkedList<CachedClass> superClasses = new LinkedList<CachedClass>();
if (theClass.isInterface()) {
superClasses.addFirst(ReflectionCache.OBJECT_CLASS);
} else {
for (CachedClass c = theCachedClass; c != null; c = c.getCachedSuperClass()) {
superClasses.addFirst(c);
}
if (theCachedClass.isArray && theClass != Object[].class && !theClass.getComponentType().isPrimitive()) {
superClasses.addFirst(ReflectionCache.OBJECT_ARRAY_CLASS);
}
}
return superClasses;
}
示例12: Closure
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
public Closure(Object owner, Object thisObject) {
this.owner = owner;
this.delegate = owner;
this.thisObject = thisObject;
final CachedClosureClass cachedClass = (CachedClosureClass) ReflectionCache.getCachedClass(getClass());
parameterTypes = cachedClass.getParameterTypes();
maximumNumberOfParameters = cachedClass.getMaximumNumberOfParameters();
}
示例13: isAssignableFrom
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
public static boolean isAssignableFrom(Class classToTransformTo, Class classToTransformFrom) {
if (classToTransformTo == classToTransformFrom
|| classToTransformFrom == null
|| classToTransformTo == Object.class) {
return true;
}
classToTransformTo = ReflectionCache.autoboxType(classToTransformTo);
classToTransformFrom = ReflectionCache.autoboxType(classToTransformFrom);
if (classToTransformTo == classToTransformFrom) return true;
// note: there is no coercion for boolean and char. Range matters, precision doesn't
if (classToTransformTo == Integer.class) {
if (classToTransformFrom == Short.class
|| classToTransformFrom == Byte.class
|| classToTransformFrom == BigInteger.class)
return true;
} else if (classToTransformTo == Double.class) {
if (classToTransformFrom == Integer.class
|| classToTransformFrom == Long.class
|| classToTransformFrom == Short.class
|| classToTransformFrom == Byte.class
|| classToTransformFrom == Float.class
|| classToTransformFrom == BigDecimal.class
|| classToTransformFrom == BigInteger.class)
return true;
} else if (classToTransformTo == BigDecimal.class) {
if (classToTransformFrom == Double.class
|| classToTransformFrom == Integer.class
|| classToTransformFrom == Long.class
|| classToTransformFrom == Short.class
|| classToTransformFrom == Byte.class
|| classToTransformFrom == Float.class
|| classToTransformFrom == BigInteger.class)
return true;
} else if (classToTransformTo == BigInteger.class) {
if (classToTransformFrom == Integer.class
|| classToTransformFrom == Long.class
|| classToTransformFrom == Short.class
|| classToTransformFrom == Byte.class)
return true;
} else if (classToTransformTo == Long.class) {
if (classToTransformFrom == Integer.class
|| classToTransformFrom == Short.class
|| classToTransformFrom == Byte.class)
return true;
} else if (classToTransformTo == Float.class) {
if (classToTransformFrom == Integer.class
|| classToTransformFrom == Long.class
|| classToTransformFrom == Short.class
|| classToTransformFrom == Byte.class)
return true;
} else if (classToTransformTo == Short.class) {
if (classToTransformFrom == Byte.class)
return true;
} else if (classToTransformTo == String.class) {
if (GString.class.isAssignableFrom(classToTransformFrom)) {
return true;
}
}
return ReflectionCache.isAssignableFrom(classToTransformTo, classToTransformFrom);
}
示例14: isAssignableFrom
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
public boolean isAssignableFrom(Class classToTransformFrom) {
return classToTransformFrom == null
|| classToTransformFrom == STRING_CLASS
|| ReflectionCache.isAssignableFrom(GSTRING_CLASS,classToTransformFrom);
}
示例15: isAssignableFrom
import org.codehaus.groovy.reflection.ReflectionCache; //导入依赖的package包/类
@Override
public boolean isAssignableFrom(Class argument) {
return argument == null ||
Closure.class.isAssignableFrom(argument) ||
ReflectionCache.isAssignableFrom(getTheClass(), argument);
}