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));
}
}
}
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());
}
}
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;
}
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;
}
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;
}
Aggregations