當前位置: 首頁>>代碼示例>>Java>>正文


Java Method.toString方法代碼示例

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

}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:17,代碼來源:ZipkinSpanAspect.java

示例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());
  }
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:22,代碼來源:ExtensionManifoldTest.java

示例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));
                }
            }
        }
    }
}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:17,代碼來源:ValidateAspectHandel.java

示例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.");
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:20,代碼來源:RpcServiceAdapter.java

示例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;
}
 
開發者ID:gengwg,項目名稱:java_mooc_fi,代碼行數:12,代碼來源:B_CalculatorTest.java

示例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);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:34,代碼來源:MemberName.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:33,代碼來源:ContainerElement.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:LoggerFinderAPITest.java

示例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());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:76,代碼來源:TypedAnnotationWriter.java

示例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);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:59,代碼來源:ActionClassGenerator.java

示例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));
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:61,代碼來源:GeneratedMonitorTest.java

示例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;
}
 
開發者ID:NyaaCat,項目名稱:NyaaCore,代碼行數:51,代碼來源:ColumnStructure.java

示例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);
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:63,代碼來源:TestSynchronization.java

示例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));
}
 
開發者ID:Col-E,項目名稱:Recaf,代碼行數:11,代碼來源:Bus.java

示例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);
}
 
開發者ID:Col-E,項目名稱:Recaf,代碼行數:11,代碼來源:Bus.java


注:本文中的java.lang.reflect.Method.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。