本文整理汇总了Java中java.lang.reflect.Parameter.isVarArgs方法的典型用法代码示例。如果您正苦于以下问题:Java Parameter.isVarArgs方法的具体用法?Java Parameter.isVarArgs怎么用?Java Parameter.isVarArgs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Parameter
的用法示例。
在下文中一共展示了Parameter.isVarArgs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkViewOnShowOrLeaveMethod
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
/**
* Check given method has a valid signature for {@link OnShow} or {@link OnLeave} view method
* @param viewClass View class
* @param method Method to check
* @param message Error message annotation description
* @throws ViewConfigurationException Method is not valid
*/
private static void checkViewOnShowOrLeaveMethod(Class<?> viewClass, Method method, String message)
throws ViewConfigurationException {
if (method.getReturnType() != Void.class && method.getReturnType() != Void.TYPE) {
throw new ViewConfigurationException("Invalid " + message + " method in view class " + viewClass.getName()
+ ": method must be a void return method");
}
int params = method.getParameterCount();
if (params > 1) {
throw new ViewConfigurationException("Invalid " + message + " method in view class " + viewClass.getName()
+ ": method must have no parameters or only one parameter of type ViewChangeEvent");
}
if (params == 1) {
Parameter param = method.getParameters()[0];
if (param.isVarArgs() || !(ViewChangeEvent.class.isAssignableFrom(param.getType())
|| ViewNavigatorChangeEvent.class.isAssignableFrom(param.getType()))) {
throw new ViewConfigurationException(
"Invalid " + message + " method in view class " + viewClass.getName()
+ ": method must have no parameters or only one parameter of type ViewChangeEvent");
}
}
}
示例2: getGroovyImplementation0
import java.lang.reflect.Parameter; //导入方法依赖的package包/类
@Override
protected String getGroovyImplementation0(MethodInvoker method, ConfigPropertyTemplate<?> propertyTemplate, ConfigPropertyActionInstance actionInstance)
{
// language=groovy
StringBuilder methodBuilder = new StringBuilder(500);
methodBuilder.append("$rawType v = $rawValue\n")
.append("if ($value == null) return $nullOrNothing\n");
Parameter parameter = method.getParameters()[0];
if (Collection.class.isAssignableFrom(propertyTemplate.getRawType()))
{
// language=groovy
if (method.isVarArgs())
{
methodBuilder.append("$returnOrNothing v.removeAll(Arrays.asList(var1))\n");
}
else
{
methodBuilder.append("$returnOrNothing v.remove(var1)\n");
}
}
else if (Map.class.isAssignableFrom(propertyTemplate.getRawType()))
{
// language=groovy
if (parameter.isVarArgs())
{
methodBuilder.append("if (var1.length == 0) $returnOrNothing Collections.emptyList()\n");
methodBuilder.append("List removed = new ArrayList() \n" +
"for (Object anArg : var1)\n" +
"{\n" +
" removed.add(v.remove(anArg)) \n" +
"}\n" +
"$returnOrNothing ($returnType) removed");
}
else
{
methodBuilder.append("$returnOrNothing ($returnType) v.remove(var1)");
}
}
else
{
throw new IllegalStateException("Unsupported type of property: " + propertyTemplate.getGenericType());
}
return methodBuilder.toString();
}