本文整理匯總了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();
}