Java Code Examples for java.lang.reflect.Method.toString()

The following are Jave code examples for showing how to use toString() of the java.lang.reflect.Method class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-servicecomb-java-chassis   File: ZipkinSpanAspect.java   View Source Code Vote up 7 votes
@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);

}
 
Example 2
Project: manifold   File: ExtensionManifoldTest.java   View Source Code Vote up 7 votes
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());
  }
}
 
Example 3
Project: dooo   File: ValidateAspectHandel.java   View Source Code Vote up 6 votes
@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));
                }
            }
        }
    }
}
 
Example 4
Project: hashsdn-controller   File: RpcServiceAdapter.java   View Source Code Vote up 6 votes
@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.");
}
 
Example 5
Project: java_mooc_fi   File: B_CalculatorTest.java   View Source Code Vote up 5 votes
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;
}
 
Example 6
Project: OpenJSharp   File: MemberName.java   View Source Code Vote up 5 votes
@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);
    }
}
 
Example 7
Project: OpenJSharp   File: ContainerElement.java   View Source Code Vote up 5 votes
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);
}
 
Example 8
Project: jdk8u-jdk   File: MemberName.java   View Source Code Vote up 5 votes
@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);
    }
}
 
Example 9
Project: openjdk-jdk10   File: LoggerFinderAPITest.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 10
Project: openjdk-jdk10   File: TypedAnnotationWriter.java   View Source Code Vote up 5 votes
@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());
}
 
Example 11
Project: openjdk-jdk10   File: ContainerElement.java   View Source Code Vote up 5 votes
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);
}
 
Example 12
Project: ats-framework   File: ActionClassGenerator.java   View Source Code Vote up 4 votes
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);
    }
}
 
Example 13
Project: guava-mock   File: GeneratedMonitorTest.java   View Source Code Vote up 4 votes
/**
 * 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));
  }
}
 
Example 14
Project: NyaaCore   File: ColumnStructure.java   View Source Code Vote up 4 votes
/**
 * 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;
}
 
Example 15
Project: OpenJSharp   File: TypedAnnotationWriter.java   View Source Code Vote up 4 votes
@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());
}
 
Example 16
Project: jdk8u-jdk   File: TestSynchronization.java   View Source Code Vote up 4 votes
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);
        }
    }
}
 
Example 17
Project: openjdk-jdk10   File: TestSynchronization.java   View Source Code Vote up 4 votes
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);
        }
    }
}
 
Example 18
Project: googles-monorepo-demo   File: GeneratedMonitorTest.java   View Source Code Vote up 4 votes
/**
 * 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));
  }
}
 
Example 19
Project: Recaf   File: Bus.java   View Source Code Vote up 2 votes
/**
 * 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));
}
 
Example 20
Project: Recaf   File: Bus.java   View Source Code Vote up 2 votes
/**
 * Remove method from map.
 * 
 * @param instance
 * @param method
 */
public void unsubscribe(Object instance, Method method) {
	String key = instance.toString() + method.toString();
	invokers.remove(key);
}