List of usage examples for java.lang.reflect Constructor getExceptionTypes
@Override
public Class<?>[] getExceptionTypes()
From source file:Main.java
public static void print_method_or_constructor(Member member) { Constructor c = (Constructor) member; Class[] parameters = c.getParameterTypes(); Class[] exceptions = c.getExceptionTypes(); System.out.println(c.getDeclaringClass()); for (int i = 0; i < parameters.length; i++) { System.out.println(parameters[i]); }// www . ja v a 2 s . c om for (int i = 0; i < exceptions.length; i++) { System.out.println(exceptions[i]); } }
From source file:ShowClass.java
public static void printMethodOrConstructor(Member member) { Class returntype = null, parameters[], exceptions[]; if (member instanceof Method) { Method m = (Method) member; returntype = m.getReturnType();//w w w. j a va 2 s .c o m parameters = m.getParameterTypes(); exceptions = m.getExceptionTypes(); System.out.print( " " + modifiers(member.getModifiers()) + typeName(returntype) + " " + member.getName() + "("); } else { Constructor c = (Constructor) member; parameters = c.getParameterTypes(); exceptions = c.getExceptionTypes(); System.out.print(" " + modifiers(member.getModifiers()) + typeName(c.getDeclaringClass()) + "("); } for (int i = 0; i < parameters.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typeName(parameters[i])); } System.out.print(")"); if (exceptions.length > 0) System.out.print(" throws "); for (int i = 0; i < exceptions.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typeName(exceptions[i])); } System.out.println(";"); }
From source file:Main.java
public static void print_method_or_constructor(Member member) { Class returntype = null, parameters[], exceptions[]; if (member instanceof Method) { Method m = (Method) member; returntype = m.getReturnType();// ww w . ja va2 s. c om parameters = m.getParameterTypes(); exceptions = m.getExceptionTypes(); System.out.print( " " + modifiers(member.getModifiers()) + typename(returntype) + " " + member.getName() + "("); } else { Constructor c = (Constructor) member; parameters = c.getParameterTypes(); exceptions = c.getExceptionTypes(); System.out.print(" " + modifiers(member.getModifiers()) + typename(c.getDeclaringClass()) + "("); } for (int i = 0; i < parameters.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(parameters[i])); } System.out.print(")"); if (exceptions.length > 0) System.out.print(" throws "); for (int i = 0; i < exceptions.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(exceptions[i])); } System.out.println(";"); }
From source file:ShowClass.java
/** * Print the modifiers, return type, name, parameter types and exception type * of a method or constructor. Note the use of the Member interface to allow * this method to work with both Method and Constructor objects *//*from w ww .j av a 2s.co m*/ public static void print_method_or_constructor(Member member) { Class returntype = null, parameters[], exceptions[]; if (member instanceof Method) { Method m = (Method) member; returntype = m.getReturnType(); parameters = m.getParameterTypes(); exceptions = m.getExceptionTypes(); System.out.print( " " + modifiers(member.getModifiers()) + typename(returntype) + " " + member.getName() + "("); } else { Constructor c = (Constructor) member; parameters = c.getParameterTypes(); exceptions = c.getExceptionTypes(); System.out.print(" " + modifiers(member.getModifiers()) + typename(c.getDeclaringClass()) + "("); } for (int i = 0; i < parameters.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(parameters[i])); } System.out.print(")"); if (exceptions.length > 0) System.out.print(" throws "); for (int i = 0; i < exceptions.length; i++) { if (i > 0) System.out.print(", "); System.out.print(typename(exceptions[i])); } System.out.println(";"); }
From source file:Mopex.java
/** * Returns a String that represents the header suffix for a constructor. The * term "header suffix" is not a standard Java term. We use it to mean the * Java header without the modifiers.//from w w w .j a va2s . c o m * * @return String * @param c * java.lang.Constructor */ //start extract constructorHeaderToString public static String headerSuffixToString(Constructor c) { String header = signatureToString(c); Class[] eTypes = c.getExceptionTypes(); if (eTypes.length != 0) header += " throws " + classArrayToString(eTypes); return header; }
From source file:Mopex.java
/** * Creates constructor with the signature of c and a new name. It adds some * code after generating a super statement to call c. This method is used * when generating a subclass of class that declared c. * //from w ww. j av a 2 s . com * @return String * @param c * java.lang.Constructor * @param name * String * @param code * String */ //start extract createRenamedConstructor public static String createRenamedConstructor(Constructor c, String name, String code) { Class[] pta = c.getParameterTypes(); String fpl = formalParametersToString(pta); String apl = actualParametersToString(pta); Class[] eTypes = c.getExceptionTypes(); String result = name + "(" + fpl + ")\n"; if (eTypes.length != 0) result += " throws " + classArrayToString(eTypes) + "\n"; result += "{\n super(" + apl + ");\n" + code + "}\n"; return result; }
From source file:org.batoo.common.reflect.ReflectHelper.java
private static ConstructorAccessor createConstructorImpl(Constructor<?> constructor) { try {/* ww w . j a v a 2 s .c o m*/ final Class<?> magClass = Class.forName("sun.reflect.MethodAccessorGenerator"); final Constructor<?> c = magClass.getDeclaredConstructors()[0]; final Method generateMethod = magClass.getMethod("generateConstructor", Class.class, Class[].class, Class[].class, Integer.TYPE); ReflectHelper.setAccessible(c, true); ReflectHelper.setAccessible(generateMethod, true); try { final Object mag = c.newInstance(); return new SunConstructorAccessor( generateMethod.invoke(mag, constructor.getDeclaringClass(), constructor.getParameterTypes(), constructor.getExceptionTypes(), constructor.getModifiers())); } finally { ReflectHelper.setAccessible(c, false); ReflectHelper.setAccessible(generateMethod, false); } } catch (final Exception e) { throw new RuntimeException("Constructor generation failed", e); } }
From source file:org.obsidian.test.TestAbstract.java
public <T> String buildConstructionStringFromType(Class<T> type, Constructor[] visitedConstructors) { //initialize construction String String constructionString;/*from w w w .ja v a 2 s . co m*/ //append equality method types appendEqualityMethodTypes(type); //append the type to the getterTest's dynamic imports appendDynamicImports(type); //if class is abstract, replace with concrete substitution if (Modifier.isAbstract(type.getModifiers()) || type.isInterface()) { type = Helpers.getConcreteSubstitution(type); } //type's simple name String name = type.getSimpleName(); //append the type to the getterTest's dynamic imports appendDynamicImports(type); if (Helpers.PRIMITIVE_CONSTRUCTIONS.get(name) != null) { //get construction from PRIMITIVE_CONSTRUCTIONS constructionString = Helpers.PRIMITIVE_CONSTRUCTIONS.get(name); } else if (type.isArray()) { int numberOfDimensions = StringUtils.countMatches(name, "[]"); constructionString = name.replace("[]", ""); for (int i = 0; i < numberOfDimensions; i++) { constructionString = constructionString + "[0]"; } constructionString = "new " + constructionString; } else if (Modifier.isAbstract(type.getModifiers()) || type.isInterface()) { constructionString = "null"; } else if (type.getConstructors().length == 0) { constructionString = "null"; } else { //not visited constructors ArrayList<Constructor> NVC = Helpers.notVisitedConstructors(type.getConstructors(), visitedConstructors); Constructor constructor = Helpers.getConstructorWithLeastParametersFromList(NVC); if (NVC.isEmpty()) { constructionString = "null"; } else if (constructor.getExceptionTypes().length > 0) { constructionString = "null"; } else { visitedConstructors = Helpers.addConstructor(visitedConstructors, constructor); constructionString = "new " + name + "("; Class[] parameters = constructor.getParameterTypes(); for (int i = 0; i < parameters.length; i++) { constructionString = constructionString + buildConstructionStringFromType(parameters[i], visitedConstructors) + ","; } if (parameters.length != 0) { constructionString = constructionString.substring(0, constructionString.length() - 1); } constructionString = constructionString + ")"; } } //this will prevent ambiguity in constructors with parmeter that //cannot be constructed if (constructionString.contains("null")) { constructionString = "null"; } return constructionString; }