List of usage examples for java.lang.reflect Method getGenericExceptionTypes
@Override
public Type[] getGenericExceptionTypes()
From source file:X.java
public static void main(String[] args) { try {/* w w w .ja v a2 s. co m*/ Class<?> clazz = Class.forName("X"); X x = (X) clazz.newInstance(); Class[] argTypes = { String.class }; Method method = clazz.getMethod("objectMethod", argTypes); Type[] exp = method.getGenericExceptionTypes(); for (Type anno : exp) { System.out.println(anno); } System.out.println(); } catch (Exception e) { System.err.println(e); } }
From source file:org.alfresco.module.org_alfresco_module_rm.api.PublicAPITestUtil.java
/** * Get all types references by the supplied method signature (i.e. the parameters, return type and exceptions). * * @param method The method to analyse./*from ww w . jav a2s.c om*/ * @return The set of types. */ private static Set<Type> getTypesFromMethod(Method method) { Set<Type> methodTypes = new HashSet<>(); methodTypes.addAll(Sets.newHashSet(method.getGenericParameterTypes())); methodTypes.add(method.getGenericReturnType()); methodTypes.addAll(Sets.newHashSet(method.getGenericExceptionTypes())); return methodTypes; }
From source file:org.broadinstitute.gatk.queue.extensions.gatk.GATKExtensionsGenerator.java
/** * Writes the dependents to a scala wrapper that will compile and get picked up by BCEL. * BCEL was missing some classes, such as Enums, when they were defined in the other generated classes. * This generated wrapper makes sure they are explicitly seen by BCEL. * @param dependents Explicit dependencies that need to be packaged. * @throws IOException If the file cannot be written. *//* w w w. j a v a 2s . com*/ private void writeDependencies(SortedSet<Class<?>> dependents) throws IOException { // Include the enclosing classes too. Scala will be looking for them. SortedSet<Class<?>> enclosings = new TreeSet<Class<?>>(classComparator); for (Class<?> dependent : dependents) for (Class<?> enclosing = dependent; enclosing != null; enclosing = enclosing.getEnclosingClass()) enclosings.add(enclosing); dependents = enclosings; // Oh, and include the classes defined on methods too! enclosings = new TreeSet<Class<?>>(classComparator); for (Class<?> dependent : dependents) { for (Method method : dependent.getDeclaredMethods()) { JVMUtils.addGenericTypes(enclosings, method.getGenericReturnType()); for (Type parameterType : method.getGenericParameterTypes()) JVMUtils.addGenericTypes(enclosings, parameterType); for (Type exceptionType : method.getGenericExceptionTypes()) JVMUtils.addGenericTypes(enclosings, exceptionType); } } dependents = enclosings; // Generate the dependents. String className = "GATKClassDependencies"; StringBuilder classes = new StringBuilder(); for (Class<?> dependent : dependents) { if (dependent.isArray()) continue; if (ArgumentField.isBuiltIn(dependent)) continue; if (!Modifier.isPublic(dependent.getModifiers())) continue; if (classes.length() > 0) classes.append(",").append(NEWLINE); String typeParams = getScalaTypeParams(dependent); classes.append("classOf[").append(dependent.getName().replace("$", ".")).append(typeParams).append("]"); } String content = String.format(GATK_DEPENDENCIES_TEMPLATE, GATK_EXTENSIONS_PACKAGE_NAME, className, classes); writeFile(GATK_EXTENSIONS_PACKAGE_NAME + "." + className, content); }