Search in sources :

Example 86 with Method

use of java.lang.reflect.Method in project blueprints by tinkerpop.

the class Neo4jGraphTest method doTestSuite.

public void doTestSuite(final TestSuite testSuite) throws Exception {
    String directory = this.getWorkingDirectory();
    deleteDirectory(new File(directory));
    for (Method method : testSuite.getClass().getDeclaredMethods()) {
        if (method.getName().startsWith("test")) {
            System.out.println("Testing " + method.getName() + "...");
            method.invoke(testSuite);
            deleteDirectory(new File(directory));
        }
    }
}
Also used : Method(java.lang.reflect.Method) File(java.io.File)

Example 87 with Method

use of java.lang.reflect.Method in project blueprints by tinkerpop.

the class Neo4j2GraphTest method doTestSuite.

public void doTestSuite(final TestSuite testSuite) throws Exception {
    String directory = this.getWorkingDirectory();
    deleteDirectory(new File(directory));
    int total = 0;
    Map<Method, Exception> failures = new LinkedHashMap<Method, Exception>();
    for (Method method : testSuite.getClass().getDeclaredMethods()) {
        if (method.getName().startsWith("test")) {
            System.out.println("Testing " + method.getName() + "...");
            try {
                total++;
                method.invoke(testSuite);
            } catch (Exception e) {
                // report all errors not just the first
                failures.put(method, e);
                System.out.println("Error during " + method.getName() + " " + e.getMessage());
                e.printStackTrace();
            } finally {
                // clean shutdown w/o leaking resources even in case of AssertionErrors
                if (testGraph.get() != null) {
                    testGraph.get().shutdown();
                }
                deleteDirectory(new File(directory));
            }
        }
    }
    // fail the suite
    if (!failures.isEmpty()) {
        throw new AssertionError(testSuite.getName() + " failed, total " + total + " failures: " + failures.size() + "\n" + failures.keySet());
    }
}
Also used : Method(java.lang.reflect.Method) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap)

Example 88 with Method

use of java.lang.reflect.Method in project jetbrick-template-1x by subchen.

the class JetTemplateCodeVisitor method visitTag_directive.

@Override
public Code visitTag_directive(Tag_directiveContext ctx) {
    String text = ctx.getChild(0).getText();
    String name = text.substring(5, text.length() - 1).trim();
    TagCode tagCode = scopeCode.createTagCode();
    tagCode.setTagId(getUid("tag"));
    scopeCode = tagCode.getMethodCode();
    scopeCode.define(Code.CONTEXT_NAME, TypedKlass.JetContext);
    // add body content
    scopeCode.setBodyCode(ctx.block().accept(this));
    scopeCode = scopeCode.pop();
    // finding tag function
    Expression_listContext expression_list = ctx.expression_list();
    SegmentListCode segmentListCode = (expression_list == null) ? SegmentListCode.EMPTY : (SegmentListCode) expression_list.accept(this);
    Class<?>[] parameterTypes = segmentListCode.getParameterTypes(JetTagContext.class);
    Method method = resolver.resolveTagMethod(name, parameterTypes);
    if (method == null) {
        throw reportError("Undefined tag definition: " + getMethodSignature(name, parameterTypes), ctx);
    }
    tagCode.setMethod(method);
    tagCode.setExpressionListCode(segmentListCode);
    return tagCode;
}
Also used : Expression_listContext(jetbrick.template.parser.grammer.JetTemplateParser.Expression_listContext) TagCode(jetbrick.template.parser.code.TagCode) Method(java.lang.reflect.Method) SegmentListCode(jetbrick.template.parser.code.SegmentListCode)

Example 89 with Method

use of java.lang.reflect.Method in project swagger-core by swagger-api.

the class ReflectionUtils method getOverriddenMethod.

/**
     * Returns overridden method from superclass if it exists. If method was not found returns null.
     *
     * @param method is method to find
     * @return overridden method from superclass
     */
public static Method getOverriddenMethod(Method method) {
    Class<?> declaringClass = method.getDeclaringClass();
    Class<?> superClass = declaringClass.getSuperclass();
    Method result = null;
    if (superClass != null && !(superClass.equals(Object.class))) {
        result = findMethod(method, superClass);
    }
    if (result == null) {
        for (Class<?> anInterface : declaringClass.getInterfaces()) {
            result = findMethod(method, anInterface);
            if (result != null) {
                return result;
            }
        }
    }
    return result;
}
Also used : Method(java.lang.reflect.Method)

Example 90 with Method

use of java.lang.reflect.Method in project swagger-core by swagger-api.

the class ReflectionUtils method findMethod.

/**
     * Searches the method methodToFind in given class cls. If the method is found returns it, else return null.
     *
     * @param methodToFind is the method to search
     * @param cls          is the class or interface where to search
     * @return method if it is found
     */
public static Method findMethod(Method methodToFind, Class<?> cls) {
    if (cls == null) {
        return null;
    }
    String methodToSearch = methodToFind.getName();
    Class<?>[] soughtForParameterType = methodToFind.getParameterTypes();
    Type[] soughtForGenericParameterType = methodToFind.getGenericParameterTypes();
    for (Method method : cls.getMethods()) {
        if (method.getName().equals(methodToSearch) && method.getReturnType().isAssignableFrom(methodToFind.getReturnType())) {
            Class<?>[] srcParameterTypes = method.getParameterTypes();
            Type[] srcGenericParameterTypes = method.getGenericParameterTypes();
            if (soughtForParameterType.length == srcParameterTypes.length && soughtForGenericParameterType.length == srcGenericParameterTypes.length) {
                if (hasIdenticalParameters(srcParameterTypes, soughtForParameterType, srcGenericParameterTypes, soughtForGenericParameterType)) {
                    return method;
                }
            }
        }
    }
    return null;
}
Also used : Type(java.lang.reflect.Type) Method(java.lang.reflect.Method)

Aggregations

Method (java.lang.reflect.Method)8797 Test (org.junit.Test)1772 InvocationTargetException (java.lang.reflect.InvocationTargetException)1084 ArrayList (java.util.ArrayList)665 Field (java.lang.reflect.Field)611 IOException (java.io.IOException)549 HashMap (java.util.HashMap)352 Map (java.util.Map)290 List (java.util.List)275 PropertyDescriptor (java.beans.PropertyDescriptor)253 Annotation (java.lang.annotation.Annotation)212 Type (java.lang.reflect.Type)202 HashSet (java.util.HashSet)199 File (java.io.File)173 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)170 BeanInfo (java.beans.BeanInfo)166 ParameterizedType (java.lang.reflect.ParameterizedType)132 Constructor (java.lang.reflect.Constructor)131 SimpleBeanInfo (java.beans.SimpleBeanInfo)128 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)128