本文整理汇总了Java中java.lang.reflect.Method.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Method.toString方法的具体用法?Java Method.toString怎么用?Java Method.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Method
的用法示例。
在下文中一共展示了Method.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: advise
import java.lang.reflect.Method; //导入方法依赖的package包/类
@Around("execution(@org.apache.servicecomb.tracing.Span * *(..)) && @annotation(spanAnnotation)")
public Object advise(ProceedingJoinPoint joinPoint, Span spanAnnotation) throws Throwable {
String spanName = spanAnnotation.spanName();
String callPath = spanAnnotation.callPath();
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
LOG.debug("Generating zipkin span for method {}", method.toString());
if ("".equals(spanName)) {
spanName = method.getName();
}
if ("".equals(callPath)) {
callPath = method.toString();
}
return adviser.invoke(spanName, callPath, joinPoint::proceed);
}
示例2: testCoverage
import java.lang.reflect.Method; //导入方法依赖的package包/类
protected void testCoverage( Class extensionClass ) {
Method[] methods = extensionClass.getMethods();
ArrayList<String> untested = new ArrayList<>();
for (Method m : methods) {
if (Modifier.isStatic(m.getModifiers()) && !Modifier.isPrivate(m.getModifiers())) {
try {
String name = m.getName();
getClass().getMethod("test" + Character.toUpperCase(name.charAt(0)) + name.substring(1));
} catch (Exception e) {
String fullDesc = m.toString();
untested.add( "Untested: " + fullDesc.substring( fullDesc.indexOf( '.' + m.getName() + '(' ) + 1 ) );
}
}
}
if (!untested.isEmpty()) {
StringBuilder msg = new StringBuilder();
untested.stream().sorted().forEach(e -> msg.append(e).append("\n"));
msg.append("Expecting at least one test method per extension method of the form: testXxx().\n");
TestCase.fail( msg.toString());
}
}
示例3: init
import java.lang.reflect.Method; //导入方法依赖的package包/类
@PostConstruct
public void init() {
List<Class<?>> classList = ClassUtil.getClasses(ArcticleService.class.getPackage().getName());
for (Class<?> aClass : classList) {
if (aClass.isAnnotationPresent(Service.class)) {
for (Method method : aClass.getDeclaredMethods()) {
if (method.isAnnotationPresent(ValidateGroup.class)) {
String key = method.toString();
LOGGER.info("init validators of method {}", key);
validateConcurrentMap.put(key, getFiledValidators(key, method));
}
}
}
}
}
示例4: invoke
import java.lang.reflect.Method; //导入方法依赖的package包/类
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final RpcInvocationStrategy rpc = rpcNames.get(method);
if (rpc != null) {
if (method.getParameterTypes().length == 0) {
return rpc.invokeEmpty();
}
if (args.length != 1) {
throw new IllegalArgumentException("Input must be provided.");
}
return rpc.invoke((DataObject) args[0]);
}
if (isObjectMethod(method)) {
return callObjectMethod(proxy, method, args);
}
throw new UnsupportedOperationException("Method " + method.toString() + "is unsupported.");
}
示例5: haeMetodi
import java.lang.reflect.Method; //导入方法依赖的package包/类
private Method haeMetodi(Class c, String nimi) {
for (Method m : c.getDeclaredMethods()) {
if (m.getName().equals(nimi)) {
String mj = m.toString();
if (mj.contains("()") && mj.contains("void")) {
return m;
}
}
}
return null;
}
示例6: MemberName
import java.lang.reflect.Method; //导入方法依赖的package包/类
@SuppressWarnings("LeakingThisInConstructor")
public MemberName(Method m, boolean wantSpecial) {
m.getClass(); // NPE check
// fill in vmtarget, vmindex while we have m in hand:
MethodHandleNatives.init(this, m);
if (clazz == null) { // MHN.init failed
if (m.getDeclaringClass() == MethodHandle.class &&
isMethodHandleInvokeName(m.getName())) {
// The JVM did not reify this signature-polymorphic instance.
// Need a special case here.
// See comments on MethodHandleNatives.linkMethod.
MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes());
int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual);
init(MethodHandle.class, m.getName(), type, flags);
if (isMethodHandleInvoke())
return;
}
throw new LinkageError(m.toString());
}
assert(isResolved() && this.clazz != null);
this.name = m.getName();
if (this.type == null)
this.type = new Object[] { m.getReturnType(), m.getParameterTypes() };
if (wantSpecial) {
if (isAbstract())
throw new AbstractMethodError(this.toString());
if (getReferenceKind() == REF_invokeVirtual)
changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual);
else if (getReferenceKind() == REF_invokeInterface)
// invokeSpecial on a default method
changeReferenceKind(REF_invokeSpecial, REF_invokeInterface);
}
}
示例7: invoke
import java.lang.reflect.Method; //导入方法依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if(method.getDeclaringClass()==TypedXmlWriter.class || method.getDeclaringClass()==Object.class) {
// forward to myself
try {
return method.invoke(this,args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
XmlAttribute xa = method.getAnnotation(XmlAttribute.class);
XmlValue xv = method.getAnnotation(XmlValue.class);
XmlElement xe = method.getAnnotation(XmlElement.class);
if(xa!=null) {
if(xv!=null || xe!=null)
throw new IllegalAnnotationException(method.toString());
addAttribute(xa,method,args);
return proxy; // allow method chaining
}
if(xv!=null) {
if(xe!=null)
throw new IllegalAnnotationException(method.toString());
_pcdata(args);
return proxy; // allow method chaining
}
return addElement(xe,method,args);
}
示例8: invokeOn
import java.lang.reflect.Method; //导入方法依赖的package包/类
public void invokeOn(java.lang.System.Logger logger, Method m) {
Object[] p = getParamsFor(m);
try {
m.invoke(logger, p);
} catch (Exception e) {
throw new RuntimeException("Failed to invoke "+m.toString(), e);
}
}
示例9: invoke
import java.lang.reflect.Method; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if(method.getDeclaringClass()==JAnnotationWriter.class) {
try {
return method.invoke(this,args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
String name = method.getName();
Object arg=null;
if(args!=null && args.length>0)
arg = args[0];
// check how it's defined on the annotation
Method m = annotation.getDeclaredMethod(name);
Class<?> rt = m.getReturnType();
// array value
if(rt.isArray()) {
return addArrayValue(proxy,name,rt.getComponentType(),method.getReturnType(),arg);
}
// sub annotation
if(Annotation.class.isAssignableFrom(rt)) {
Class<? extends Annotation> r = (Class<? extends Annotation>)rt;
return new TypedAnnotationWriter(
r,method.getReturnType(),use.annotationParam(name,r)).createProxy();
}
// scalar value
if(arg instanceof JType) {
JType targ = (JType) arg;
checkType(Class.class,rt);
if(m.getDefaultValue()!=null) {
// check the default
if(targ.equals(targ.owner().ref((Class)m.getDefaultValue())))
return proxy; // defaulted
}
use.param(name,targ);
return proxy;
}
// other Java built-in types
checkType(arg.getClass(),rt);
if(m.getDefaultValue()!=null && m.getDefaultValue().equals(arg))
// defaulted. no need to write out.
return proxy;
if(arg instanceof String) {
use.param(name,(String)arg);
return proxy;
}
if(arg instanceof Boolean) {
use.param(name,(Boolean)arg);
return proxy;
}
if(arg instanceof Integer) {
use.param(name,(Integer)arg);
return proxy;
}
if(arg instanceof Class) {
use.param(name,(Class)arg);
return proxy;
}
if(arg instanceof Enum) {
use.param(name,(Enum)arg);
return proxy;
}
throw new IllegalArgumentException("Unable to handle this method call "+method.toString());
}
示例10: generateActionDefinition
import java.lang.reflect.Method; //导入方法依赖的package包/类
private String generateActionDefinition( String actionName,
Method actionImplementation,
String transferUnit,
boolean registerAction ) {
log.info("Generating method implementation for action '" + actionName + "'");
String[] paramNames = new String[actionImplementation.getParameterTypes().length];
String[] paramTypes = new String[actionImplementation.getParameterTypes().length];
Annotation[][] parameterAnnotations = actionImplementation.getParameterAnnotations();
for (int i = 0; i < parameterAnnotations.length; i++) {
Class<?> paramType = actionImplementation.getParameterTypes()[i];
Annotation[] currentParamAnnotations = parameterAnnotations[i];
Parameter paramAnnotation = null;
for (int j = 0; j < currentParamAnnotations.length; j++) {
if (currentParamAnnotations[j] instanceof Parameter) {
paramAnnotation = (Parameter) currentParamAnnotations[j];
break;
}
}
if (paramAnnotation == null) {
throw new BuildException("No @Parameter annotation for one of the parameters of action method "
+ actionImplementation.toString());
}
paramNames[i] = paramAnnotation.name();
if (paramType.isArray() && paramType.getComponentType().isEnum()) {
//array of enums should be represented by array of String in the generated stub
paramTypes[i] = "String[]";
} else if (paramType.isEnum()) {
//enums should be represented by Strings in the generated stub
paramTypes[i] = "String";
} else {
paramTypes[i] = paramType.getSimpleName();
}
}
//parameters and arguments
if (paramNames.length != paramTypes.length) {
throw new BuildException("Parameter names count different than parameter types count for action method "
+ actionImplementation.toString());
}
Annotation deprecatedAnnotation = actionImplementation.getAnnotation(Deprecated.class);
boolean isDeprecated = (deprecatedAnnotation != null);
try {
return new MethodTemplateProcessor(actionImplementation, actionName, paramNames, registerAction,
paramTypes, transferUnit, isDeprecated).processTemplate();
} catch (IOException ioe) {
throw new BuildException(ioe);
}
}
示例11: validateMethod
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Validates that the given method's signature meets all of our assumptions.
*/
private static void validateMethod(Method method) {
String desc = method.toString();
assertTrue(desc, isAnyEnter(method) || isWaitFor(method));
switch (method.getParameterTypes().length) {
case 0:
assertFalse(desc, isGuarded(method));
assertFalse(desc, isTimed(method));
break;
case 1:
assertTrue(desc, isGuarded(method));
assertFalse(desc, isTimed(method));
break;
case 2:
assertFalse(desc, isGuarded(method));
assertTrue(desc, isTimed(method));
break;
case 3:
assertTrue(desc, isGuarded(method));
assertTrue(desc, isTimed(method));
break;
default:
fail(desc);
}
if (method.getReturnType() == void.class) {
assertFalse(desc, isBoolean(method));
} else {
assertTrue(desc, isBoolean(method));
}
switch (method.getExceptionTypes().length) {
case 0:
assertFalse(desc, isInterruptible(method));
break;
case 1:
assertTrue(desc, isInterruptible(method));
break;
default:
fail(desc);
}
if (isEnterIf(method)) {
assertTrue(desc, isGuarded(method));
assertTrue(desc, isBoolean(method));
} else if (isTryEnter(method)) {
assertFalse(desc, isTimed(method));
assertTrue(desc, isBoolean(method));
assertFalse(desc, isInterruptible(method));
} else if (isWaitFor(method)) {
assertTrue(desc, isGuarded(method));
assertEquals(desc, isTimed(method), isBoolean(method));
} else { // any other enterXxx method
assertEquals(desc, isTimed(method), isBoolean(method));
}
}
示例12: ColumnStructure
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Constructor for method based table columns
*/
public ColumnStructure(TableStructure table, Method dataMethod, DataColumn anno) {
if (anno == null) throw new IllegalArgumentException();
this.table = table;
String methodName = dataMethod.getName();
if (!methodName.startsWith("get") && !methodName.startsWith("set"))
throw new IllegalArgumentException("Method is neither a setter nor a getter: " + dataMethod.toString());
String methodSuffix = methodName.substring(3);
String name = ("".equals(anno.value())) ? methodSuffix : anno.value();
Class methodType;
if (methodName.startsWith("get")) {
methodType = dataMethod.getReturnType();
} else {
methodType = dataMethod.getParameterCount() == 1 ? dataMethod.getParameterTypes()[0] : null;
}
if (methodType == null || methodType == Void.class || methodType == Void.TYPE)
throw new IllegalArgumentException("Cannot determine getter/setter type: " + dataMethod.toString());
//if (methodType != String.class && methodType != Long.class && methodType != Double.class)
// throw new IllegalArgumentException("Only three types are supported for getter/setter columns: String/Long/Double");
Method getter, setter;
try {
getter = dataMethod.getDeclaringClass().getDeclaredMethod("get" + methodSuffix);
setter = dataMethod.getDeclaringClass().getDeclaredMethod("set" + methodSuffix, methodType);
if (getter.getParameterCount() != 0 || getter.getReturnType() != methodType || Modifier.isStatic(getter.getModifiers()))
throw new RuntimeException("getter signature mismatch");
if (setter.getParameterCount() != 1 || setter.getParameterTypes()[0] != methodType ||
(setter.getReturnType() != Void.class && setter.getReturnType() != Void.TYPE) ||
Modifier.isStatic(setter.getModifiers()))
throw new RuntimeException("setter signature mismatch");
boolean primary = getter.getDeclaredAnnotation(PrimaryKey.class) != null;
primary |= setter.getDeclaredAnnotation(PrimaryKey.class) != null;
getter.setAccessible(true);
setter.setAccessible(true);
this.isPrimary = primary;
} catch (ReflectiveOperationException ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
this.columnType = ColumnType.getType(ColumnAccessMethod.METHOD, methodType);
this.accessMethod = ColumnAccessMethod.METHOD;
this.getter = getter;
this.setter = setter;
this.field = null;
this.fieldParser = null;
this.fieldType = methodType;
this.name = name;
}
示例13: testMethod
import java.lang.reflect.Method; //导入方法依赖的package包/类
private static void testMethod(Class<?> aClass, Method m) throws
Exception {
/*
* Construct call with arguments of the correct type. Note that the
* values are somewhat irrelevant. If the call actually succeeds, it
* means we aren't synchronized and the test has failed.
*/
Class<?>[] pTypes = m.getParameterTypes();
List<Integer> charSequenceArgs = new ArrayList<>();
Object[] args = new Object[pTypes.length];
for (int i = 0; i < pTypes.length; i++) {
// determine the type and create the corresponding actual argument
Class<?> pType = pTypes[i];
if (pType.equals(boolean.class)) {
args[i] = BOOLEAN_VAL;
} else if (pType.equals(char.class)) {
args[i] = CHAR_VAL;
} else if (pType.equals(int.class)) {
args[i] = INT_VAL;
} else if (pType.equals(double.class)) {
args[i] = DOUBLE_VAL;
} else if (pType.equals(float.class)) {
args[i] = FLOAT_VAL;
} else if (pType.equals(long.class)) {
args[i] = LONG_VAL;
} else if (pType.equals(Object.class)) {
args[i] = OBJECT_VAL;
} else if (pType.equals(StringBuilder.class)) {
args[i] = STRING_BUILDER_VAL;
} else if (pType.equals(StringBuffer.class)) {
args[i] = STRING_BUFFER_VAL;
} else if (pType.equals(String.class)) {
args[i] = STRING_VAL;
} else if (pType.isArray() && pType.getComponentType().equals(char.class)) {
args[i] = CHAR_ARRAY_VAL;
} else if (pType.equals(CharSequence.class)) {
charSequenceArgs.add(new Integer(i));
} else {
throw new RuntimeException("Test Failed: not accounting for method call with parameter type of " + pType.getName() + " You must update the test.");
}
}
/*
* If there are no CharSequence args, we can simply invoke our method
* and test it
*/
if (charSequenceArgs.isEmpty()) {
invokeMethod(aClass, m, args);
} else {
/*
* Iterate through the different CharSequence types and invoke the
* method for each type.
*/
if (charSequenceArgs.size() > 1) {
throw new RuntimeException("Test Failed: the test cannot handle a method with multiple CharSequence arguments. You must update the test to handle the method "
+ m.toString());
}
for (int j = 0; j < CHAR_SEQUENCE_VAL.length; j++) {
args[charSequenceArgs.get(0)] = CHAR_SEQUENCE_VAL[j];
invokeMethod(aClass, m, args);
}
}
}
示例14: subscribe
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Add method to map.
*
* @param instance
* @param method
*/
public void subscribe(Object instance, Method method) {
String key = instance.toString() + method.toString();
invokers.put(key, new InvokeWrapper(instance, method));
}
示例15: unsubscribe
import java.lang.reflect.Method; //导入方法依赖的package包/类
/**
* Remove method from map.
*
* @param instance
* @param method
*/
public void unsubscribe(Object instance, Method method) {
String key = instance.toString() + method.toString();
invokers.remove(key);
}