本文整理汇总了Java中org.codehaus.groovy.runtime.MetaClassHelper类的典型用法代码示例。如果您正苦于以下问题:Java MetaClassHelper类的具体用法?Java MetaClassHelper怎么用?Java MetaClassHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetaClassHelper类属于org.codehaus.groovy.runtime包,在下文中一共展示了MetaClassHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: correctArguments
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
public Object[] correctArguments(Object[] argumentArray) {
// correct argumentArray's length
if (argumentArray == null) {
return MetaClassHelper.EMPTY_ARRAY;
}
final CachedClass[] pt = getParameterTypes();
if (pt.length == 1 && argumentArray.length == 0) {
if (isVargsMethod)
return new Object[]{Array.newInstance(pt[0].getTheClass().getComponentType(), 0)};
else
return MetaClassHelper.ARRAY_WITH_NULL;
}
if (isVargsMethod && isVargsMethod(argumentArray)) {
return fitToVargs(argumentArray, pt);
}
return argumentArray;
}
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:ParameterTypes.java
示例2: isValidVarargsMethod
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private static boolean isValidVarargsMethod(Class[] arguments, int size, CachedClass[] pt, int paramMinus1) {
// first check normal number of parameters
for (int i = 0; i < paramMinus1; i++) {
if (pt[i].isAssignableFrom(arguments[i])) continue;
return false;
}
// check direct match
CachedClass varg = pt[paramMinus1];
Class clazz = varg.getTheClass().getComponentType();
if (size == pt.length &&
(varg.isAssignableFrom(arguments[paramMinus1]) ||
testComponentAssignable(clazz, arguments[paramMinus1]))) {
return true;
}
// check varged
for (int i = paramMinus1; i < size; i++) {
if (MetaClassHelper.isAssignableFrom(clazz, arguments[i])) continue;
return false;
}
return true;
}
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:ParameterTypes.java
示例3: checkDuplicateProperties
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private void checkDuplicateProperties(PropertyNode node) {
ClassNode cn = node.getDeclaringClass();
String name = node.getName();
String getterName = "get" + MetaClassHelper.capitalize(name);
if (Character.isUpperCase(name.charAt(0))) {
for (PropertyNode propNode : cn.getProperties()) {
String otherName = propNode.getField().getName();
String otherGetterName = "get" + MetaClassHelper.capitalize(otherName);
if (node != propNode && getterName.equals(otherGetterName)) {
String msg = "The field " + name + " and " + otherName + " on the class " +
cn.getName() + " will result in duplicate JavaBean properties, which is not allowed";
addError(msg, node);
}
}
}
}
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:ClassCompletionVerifier.java
示例4: createListenerSetter
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private void createListenerSetter(SourceUnit source, boolean bindable, ClassNode declaringClass, PropertyNode propertyNode) {
if (bindable && needsPropertyChangeSupport(declaringClass, source)) {
addPropertyChangeSupport(declaringClass);
}
if (needsVetoableChangeSupport(declaringClass, source)) {
addVetoableChangeSupport(declaringClass);
}
String setterName = "set" + MetaClassHelper.capitalize(propertyNode.getName());
if (declaringClass.getMethods(setterName).isEmpty()) {
Expression fieldExpression = fieldX(propertyNode.getField());
BlockStatement setterBlock = new BlockStatement();
setterBlock.addStatement(createConstrainedStatement(propertyNode, fieldExpression));
if (bindable) {
setterBlock.addStatement(createBindableStatement(propertyNode, fieldExpression));
} else {
setterBlock.addStatement(createSetStatement(fieldExpression));
}
// create method void <setter>(<type> fieldName)
createSetterMethod(declaringClass, propertyNode, setterName, setterBlock);
} else {
wrapSetterMethod(declaringClass, bindable, propertyNode.getName());
}
}
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:VetoableASTTransformation.java
示例5: getNormalMethodWithCaching
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private MetaMethod getNormalMethodWithCaching(Object[] arguments, MetaMethodIndex.Entry e) {
MetaMethodIndex.CacheEntry cacheEntry;
final Object methods = e.methods;
if (methods == null)
return null;
cacheEntry = e.cachedMethod;
if (cacheEntry != null &&
MetaClassHelper.sameClasses(cacheEntry.params, arguments, methods instanceof MetaMethod))
{
MetaMethod method = cacheEntry.method;
if (method!=null) return method;
}
final Class[] classes = MetaClassHelper.convertToTypeArray(arguments);
cacheEntry = new MetaMethodIndex.CacheEntry (classes, (MetaMethod) chooseMethod(e.name, methods, classes));
e.cachedMethod = cacheEntry;
return cacheEntry.method;
}
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:MetaClassImpl.java
示例6: retrieveStaticMethod
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
public MetaMethod retrieveStaticMethod(String methodName, Object[] arguments) {
final MetaMethodIndex.Entry e = metaMethodIndex.getMethods(theClass, methodName);
MetaMethodIndex.CacheEntry cacheEntry;
if (e != null) {
cacheEntry = e.cachedStaticMethod;
if (cacheEntry != null &&
MetaClassHelper.sameClasses(cacheEntry.params, arguments, e.staticMethods instanceof MetaMethod))
{
return cacheEntry.method;
}
final Class[] classes = MetaClassHelper.convertToTypeArray(arguments);
cacheEntry = new MetaMethodIndex.CacheEntry (classes, pickStaticMethod(methodName, classes));
e.cachedStaticMethod = cacheEntry;
return cacheEntry.method;
}
else
return pickStaticMethod(methodName, MetaClassHelper.convertToTypeArray(arguments));
}
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:MetaClassImpl.java
示例7: pickStaticMethod
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private MetaMethod pickStaticMethod(String methodName, Class[] arguments) {
MetaMethod method = null;
MethodSelectionException mse = null;
Object methods = getStaticMethods(theClass, methodName);
if (!(methods instanceof FastArray) || !((FastArray)methods).isEmpty()) {
try {
method = (MetaMethod) chooseMethod(methodName, methods, arguments);
} catch(MethodSelectionException msex) {
mse = msex;
}
}
if (method == null && theClass != Class.class) {
MetaClass classMetaClass = registry.getMetaClass(Class.class);
method = classMetaClass.pickMethod(methodName, arguments);
}
if (method == null) {
method = (MetaMethod) chooseMethod(methodName, methods, MetaClassHelper.convertToTypeArray(arguments));
}
if (method == null && mse != null) {
throw mse;
} else {
return method;
}
}
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:MetaClassImpl.java
示例8: createCachedConstructor
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private CachedConstructor createCachedConstructor(Object[] arguments) {
if (arguments == null) arguments = EMPTY_ARGUMENTS;
Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
MetaClassHelper.unwrap(arguments);
CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses);
if (constructor == null) {
constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses);
}
if (constructor == null) {
throw new GroovyRuntimeException(
"Could not find matching constructor for: "
+ theClass.getName()
+ "(" + InvokerHelper.toTypeString(arguments) + ")");
}
return constructor;
}
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:MetaClassImpl.java
示例9: retrieveConstructor
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
/**
* This is a helper method added in Groovy 2.1.0, which is used only by indy.
* This method is for internal use only.
* @since Groovy 2.1.0
*/
public MetaMethod retrieveConstructor(Object[] arguments) {
checkInitalised();
if (arguments == null) arguments = EMPTY_ARGUMENTS;
Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
MetaClassHelper.unwrap(arguments);
Object res = chooseMethod("<init>", constructors, argClasses);
if (res instanceof MetaMethod) return (MetaMethod) res;
CachedConstructor constructor = (CachedConstructor) res;
if (constructor != null) return new MetaConstructor(constructor, false);
if (arguments.length == 1 && arguments[0] instanceof Map) {
res = chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY);
} else if (
arguments.length == 2 && arguments[1] instanceof Map &&
theClass.getEnclosingClass()!=null &&
theClass.getEnclosingClass().isAssignableFrom(argClasses[0]))
{
res = chooseMethod("<init>", constructors, new Class[]{argClasses[0]});
}
if (res instanceof MetaMethod) return (MetaMethod) res;
constructor = (CachedConstructor) res;
if (constructor != null) return new MetaConstructor(constructor, true);
return null;
}
开发者ID:apache,项目名称:groovy,代码行数:30,代码来源:MetaClassImpl.java
示例10: invokeConstructor
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private Object invokeConstructor(Class at, Object[] arguments) {
checkInitalised();
if (arguments == null) arguments = EMPTY_ARGUMENTS;
Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments);
MetaClassHelper.unwrap(arguments);
CachedConstructor constructor = (CachedConstructor) chooseMethod("<init>", constructors, argClasses);
if (constructor != null) {
return constructor.doConstructorInvoke(arguments);
}
if (arguments.length == 1) {
Object firstArgument = arguments[0];
if (firstArgument instanceof Map) {
constructor = (CachedConstructor) chooseMethod("<init>", constructors, MetaClassHelper.EMPTY_TYPE_ARRAY);
if (constructor != null) {
Object bean = constructor.doConstructorInvoke(MetaClassHelper.EMPTY_ARRAY);
setProperties(bean, ((Map) firstArgument));
return bean;
}
}
}
throw new GroovyRuntimeException(
"Could not find matching constructor for: "
+ theClass.getName()
+ "(" + InvokerHelper.toTypeString(arguments) + ")");
}
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:MetaClassImpl.java
示例11: doChooseMostSpecificParams
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
protected static Object doChooseMostSpecificParams(String theClassName, String name, List matchingMethods, Class[] arguments, boolean checkParametersCompatible) {
long matchesDistance = -1;
LinkedList matches = new LinkedList();
for (Object method : matchingMethods) {
final ParameterTypes parameterTypes = (ParameterTypes) method;
if (checkParametersCompatible && !MetaClassHelper.parametersAreCompatible(arguments, parameterTypes.getNativeParameterTypes())) continue;
long dist = MetaClassHelper.calculateParameterDistance(arguments, parameterTypes);
if (dist == 0) return method;
matchesDistance = handleMatches(matchesDistance, matches, method, dist);
}
int size = matches.size();
if (1 == size) {
return matches.getFirst();
}
if (0 == size) {
return null;
}
//more than one matching method found --> ambiguous!
throw new GroovyRuntimeException(createErrorMessageForAmbiguity(theClassName, name, arguments, matches));
}
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:MetaClassImpl.java
示例12: createPogoCallSite
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
/**
* Create a CallSite
*/
public CallSite createPogoCallSite(CallSite site, Object[] args) {
if (!GroovyCategorySupport.hasCategoryInCurrentThread() && !(this instanceof AdaptingMetaClass)) {
Class [] params = MetaClassHelper.convertToTypeArray(args);
CallSite tempSite = site;
if (site.getName().equals("call") && GeneratedClosure.class.isAssignableFrom(theClass)) {
// here, we want to point to a method named "doCall" instead of "call"
// but we don't want to replace the original call site name, otherwise
// we loose the fact that the original method name was "call" so instead
// we will point to a metamethod called "doCall"
// see GROOVY-5806 for details
tempSite = new AbstractCallSite(site.getArray(),site.getIndex(),"doCall");
}
MetaMethod metaMethod = getMethodWithCachingInternal(theClass, tempSite, params);
if (metaMethod != null)
return PogoMetaMethodSite.createPogoMetaMethodSite(site, this, metaMethod, params, args);
}
return new PogoMetaClassSite(site, this);
}
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:MetaClassImpl.java
示例13: processDoMethodInvokeException
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
/**
* This method is called when an exception occurs while invoking this method.
*/
public final RuntimeException processDoMethodInvokeException (Exception e, Object object, Object [] argumentArray) {
// if (e instanceof IllegalArgumentException) {
// //TODO: test if this is OK with new MOP, should be changed!
// // we don't want the exception being unwrapped if it is a IllegalArgumentException
// // but in the case it is for example a IllegalThreadStateException, we want the unwrapping
// // from the runtime
// //Note: the reason we want unwrapping sometimes and sometimes not is that the method
// // invocation tries to invoke the method with and then reacts with type transformation
// // if the invocation failed here. This is OK for IllegalArgumentException, but it is
// // possible that a Reflector will be used to execute the call and then an Exception from inside
// // the method is not wrapped in a InvocationTargetException and we will end here.
// boolean setReason = e.getClass() != IllegalArgumentException.class || this instanceof org.codehaus.groovy.reflection.GeneratedMetaMethod;
// return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, setReason);
// }
if (e instanceof RuntimeException)
return (RuntimeException) e;
return MetaClassHelper.createExceptionText("failed to invoke method: ", this, object, argumentArray, e, true);
}
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:MetaMethod.java
示例14: addReadOnlyProperty
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
public static void addReadOnlyProperty(ClassNode classNode, String propertyName, ClassNode propertyClass, Object value) {
final boolean hasProperty = hasOrInheritsProperty(classNode, propertyName);
if (!hasProperty) {
int visibility = Modifier.PRIVATE | Modifier.FINAL;
Expression initialValue = value != null && !(value instanceof Expression) ? new ConstantExpression(value) : (Expression) value;
classNode.addField(propertyName, visibility, propertyClass, initialValue);
addMethod(classNode, new MethodNode(
"get" + MetaClassHelper.capitalize(propertyName),
Modifier.PUBLIC,
propertyClass,
Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY,
new ReturnStatement(
new ExpressionStatement(
new FieldExpression(classNode.getField(propertyName))))));
}
}
开发者ID:aalmiray,项目名称:griffon2,代码行数:19,代码来源:GriffonASTUtils.java
示例15: inferTypes
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private Class[] inferTypes(Object... arguments) {
if (arguments == null || arguments.length == 0) {
return MetaClassHelper.EMPTY_CLASS_ARRAY;
}
Class[] classes = new Class[arguments.length];
for (int i = 0; i < arguments.length; i++) {
Object argType = arguments[i];
if (argType == null) {
classes[i] = null;
} else {
classes[i] = argType.getClass();
}
}
return classes;
}
开发者ID:lxxlxx888,项目名称:Reer,代码行数:16,代码来源:BeanDynamicObject.java
示例16: addMethod
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private static void addMethod(FieldNode fieldNode, BlockStatement body, ClassNode type) {
int visibility = ACC_PUBLIC;
if (fieldNode.isStatic()) visibility |= ACC_STATIC;
String propName = MetaClassHelper.capitalize(fieldNode.getName().substring(1));
fieldNode.getDeclaringClass().addMethod("get" + propName, visibility, type, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, body);
if (ClassHelper.boolean_TYPE.equals(type)) {
fieldNode.getDeclaringClass().addMethod("is" + propName, visibility, type,
Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, stmt(callThisX("get" + propName)));
}
}
开发者ID:apache,项目名称:groovy,代码行数:11,代码来源:LazyASTTransformation.java
示例17: createSoftSetter
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
private static void createSoftSetter(FieldNode fieldNode, ClassNode type) {
final BlockStatement body = new BlockStatement();
final Expression fieldExpr = varX(fieldNode);
final String name = "set" + MetaClassHelper.capitalize(fieldNode.getName().substring(1));
final Parameter parameter = param(type, "value");
final Expression paramExpr = varX(parameter);
body.addStatement(ifElseS(
notNullX(paramExpr),
assignS(fieldExpr, ctorX(SOFT_REF, paramExpr)),
assignS(fieldExpr, NULL_EXPR)
));
int visibility = ACC_PUBLIC;
if (fieldNode.isStatic()) visibility |= ACC_STATIC;
fieldNode.getDeclaringClass().addMethod(name, visibility, ClassHelper.VOID_TYPE, params(parameter), ClassNode.EMPTY_ARRAY, body);
}
开发者ID:apache,项目名称:groovy,代码行数:16,代码来源:LazyASTTransformation.java
示例18: checkGroovyConstructorMap
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
protected void checkGroovyConstructorMap(final Expression receiver, final ClassNode receiverType, final MapExpression mapExpression) {
// workaround for map-style checks putting setter info on wrong AST nodes
typeCheckingContext.pushEnclosingBinaryExpression(null);
for (MapEntryExpression entryExpression : mapExpression.getMapEntryExpressions()) {
Expression keyExpr = entryExpression.getKeyExpression();
if (!(keyExpr instanceof ConstantExpression)) {
addStaticTypeError("Dynamic keys in map-style constructors are unsupported in static type checking", keyExpr);
} else {
AtomicReference<ClassNode> lookup = new AtomicReference<ClassNode>();
PropertyExpression pexp = new PropertyExpression(varX("_", receiverType), keyExpr.getText());
boolean hasProperty = existsProperty(pexp, false, new PropertyLookupVisitor(lookup));
if (!hasProperty) {
addStaticTypeError("No such property: " + keyExpr.getText() +
" for class: " + receiverType.getName(), receiver);
} else {
ClassNode valueType = getType(entryExpression.getValueExpression());
MethodNode setter = receiverType.getSetterMethod("set" + MetaClassHelper.capitalize(pexp.getPropertyAsString()), false);
ClassNode toBeAssignedTo = setter == null ? lookup.get() : setter.getParameters()[0].getType();
if (!isAssignableTo(valueType, toBeAssignedTo)
&& !extension.handleIncompatibleAssignment(toBeAssignedTo, valueType, entryExpression)) {
addAssignmentError(toBeAssignedTo, valueType, entryExpression);
}
}
}
}
typeCheckingContext.popEnclosingBinaryExpression();
}
开发者ID:apache,项目名称:groovy,代码行数:28,代码来源:StaticTypeCheckingVisitor.java
示例19: hasSetter
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
@Deprecated
protected SetterInfo hasSetter(final PropertyExpression pexp) {
String propertyName = pexp.getPropertyAsString();
if (propertyName == null) return null;
Expression objectExpression = pexp.getObjectExpression();
List<Receiver<String>> receivers = new LinkedList<Receiver<String>>();
List<Receiver<String>> owners = makeOwnerList(objectExpression);
addReceivers(receivers, owners, pexp.isImplicitThis());
String capName = MetaClassHelper.capitalize(propertyName);
boolean isAttributeExpression = pexp instanceof AttributeExpression;
for (Receiver<String> receiver: receivers) {
ClassNode testClass = receiver.getType();
LinkedList<ClassNode> queue = new LinkedList<ClassNode>();
queue.add(testClass);
if (testClass.isInterface()) {
queue.addAll(testClass.getAllInterfaces());
}
while (!queue.isEmpty()) {
ClassNode current = queue.removeFirst();
current = current.redirect();
// check that a setter also exists
String setterName = "set" + capName;
List<MethodNode> setterMethods = findSetters(current, setterName, false);
if (!setterMethods.isEmpty()) {
// storeType(pexp, setterMethod.getParameters()[0].getType());
return new SetterInfo(current, setterName, setterMethods);
}
if (!isAttributeExpression && current.getSuperClass() != null) {
queue.add(current.getSuperClass());
}
}
}
return null;
}
开发者ID:apache,项目名称:groovy,代码行数:38,代码来源:StaticTypeCheckingVisitor.java
示例20: extractPropertyNameFromMethodName
import org.codehaus.groovy.runtime.MetaClassHelper; //导入依赖的package包/类
/**
* Given a method name and a prefix, returns the name of the property that should be looked up,
* following the java beans rules. For example, "getName" would return "name", while
* "getFullName" would return "fullName".
* If the prefix is not found, returns null.
* @param prefix the method name prefix ("get", "is", "set", ...)
* @param methodName the method name
* @return a property name if the prefix is found and the method matches the java beans rules, null otherwise
*/
public static String extractPropertyNameFromMethodName(String prefix, String methodName) {
if (prefix==null || methodName==null) return null;
if (methodName.startsWith(prefix) && prefix.length()<methodName.length()) {
String result = methodName.substring(prefix.length());
String propertyName = java.beans.Introspector.decapitalize(result);
if (result.equals(MetaClassHelper.capitalize(propertyName))) return propertyName;
}
return null;
}
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:StaticTypeCheckingVisitor.java
注:本文中的org.codehaus.groovy.runtime.MetaClassHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论