protected ArrayList createListCompletions(Package setOfCompletions) { ArrayList listOfCompletions = new ArrayList(); for (Item i : setOfCompletions) { try { try { if (i instanceof ClassName) { String fullName = getFullName(setOfCompletions.getName(), ((ClassName) i).getName()); Class clazz = getClass().getClassLoader().loadClass(fullName); Constructor[] ctor = clazz.getConstructors(); for (Constructor c : ctor) { String cotrCompletion = createConstructorCompletion(c.toString()); listOfCompletions.add(new BasicCompletion(defaultProvider, cotrCompletion)); } listOfCompletions.add(new BasicCompletion(defaultProvider, i.getName() + ".")); } } catch (NoClassDefFoundError e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } listOfCompletions.add(new BasicCompletion(defaultProvider, i.getName())); } return listOfCompletions; }
private static RetryPolicy instantiateRetryPolicy( String policyClassName, Object[] args, String raw) throws Exception { Class<?> policyClass = Class.forName(policyClassName); for (Constructor<?> con : policyClass.getConstructors()) { Class<?>[] parameterClasses = con.getParameterTypes(); if (args.length == parameterClasses.length) { boolean allInts = true; for (Class<?> pc : parameterClasses) { if (!pc.equals(int.class)) { allInts = false; break; } } if (!allInts) { break; } log.debug("About to instantiate class {} with {} arguments", con.toString(), args.length); return (RetryPolicy) con.newInstance(args); } } throw new Exception( "Failed to identify a class matching the Astyanax Retry Policy config string \"" + raw + "\""); }
public static void main(String[] args) { if (args.length < 1) { print(usage); System.exit(0); } int lines = 0; try { Class<?> c = Class.forName(args[0]); Method[] methods = c.getMethods(); Constructor[] ctors = c.getConstructors(); if (args.length == 1) { for (Method method : methods) print(p.matcher(method.toString()).replaceAll("")); for (Constructor ctor : ctors) print(p.matcher(ctor.toString()).replaceAll("")); lines = methods.length + ctors.length; } else { for (Method method : methods) if (method.toString().indexOf(args[1]) != -1) { print(p.matcher(method.toString()).replaceAll("")); lines++; } for (Constructor ctor : ctors) if (ctor.toString().indexOf(args[1]) != -1) { print(p.matcher(ctor.toString()).replaceAll("")); lines++; } } } catch (ClassNotFoundException e) { print("No such class: " + e); } }
@SuppressWarnings("unchecked") public final T createItem(String name, String prefix, AttributeSet attrs) throws ClassNotFoundException, InflateException { if (prefix != null) { name = prefix + name; } Constructor<?> constructor = GenericInflater.sConstructorMap.get(name); try { if (constructor == null) { if (mClassLoader == null) { mClassLoader = getClassLoader(); if (mClassLoader == null) { mClassLoader = mContext.getClassLoader(); } } Class<?> clazz = mClassLoader.loadClass(name); constructor = findConstructor(clazz); GenericInflater.sConstructorMap.put(clazz, constructor); } return (T) constructor.newInstance(obtainConstructorArgs(name, attrs, constructor)); } catch (NoSuchMethodException e) { InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + name); ie.initCause(e); throw ie; } catch (Exception e) { InflateException ie = new InflateException( attrs.getPositionDescription() + ": Error inflating class " + constructor.toString()); ie.initCause(e); throw ie; } }
/** * Runs the test using the specified harness. * * @param harness the test harness (<code>null</code> not permitted). */ public void test(TestHarness harness) { // map of declared constructors which should exists Map<String, String> testedDeclaredConstructors = null; // map of declared constructors for (Open)JDK6 Map<String, String> testedDeclaredConstructors_jdk6 = new HashMap<String, String>(); // map of declared constructors for (Open)JDK7 Map<String, String> testedDeclaredConstructors_jdk7 = new HashMap<String, String>(); // map for constructors declared in (Open)JDK6 testedDeclaredConstructors_jdk6.put( "public java.lang.TypeNotPresentException(java.lang.String,java.lang.Throwable)", "java.lang.TypeNotPresentException"); // map for constructors declared in (Open)JDK7 testedDeclaredConstructors_jdk7.put( "public java.lang.TypeNotPresentException(java.lang.String,java.lang.Throwable)", "java.lang.TypeNotPresentException"); // create instance of a class TypeNotPresentException final Object o = new TypeNotPresentException("TypeNotPresentException", new Throwable()); // get a runtime class of an object "o" final Class c = o.getClass(); // get the right map containing constructor signatures testedDeclaredConstructors = getJavaVersion() < 7 ? testedDeclaredConstructors_jdk6 : testedDeclaredConstructors_jdk7; // get all declared constructors for this class java.lang.reflect.Constructor[] declaredConstructors = c.getDeclaredConstructors(); // expected number of constructors final int expectedNumberOfConstructors = testedDeclaredConstructors.size(); // basic check for a number of constructors harness.check(declaredConstructors.length, expectedNumberOfConstructors); // check if all declared constructors exist for (java.lang.reflect.Constructor declaredConstructor : declaredConstructors) { // constructor name should consists of package name + class name String constructorName = declaredConstructor.getName(); // modifiers + package + class name + parameter types String constructorString = declaredConstructor.toString().replaceAll(" native ", " "); harness.check(testedDeclaredConstructors.containsKey(constructorString)); harness.check(testedDeclaredConstructors.get(constructorString), constructorName); } }
/** * Creates the parameters needed for constructing a test class instance. * * @param finder TODO */ public static Object[] createInstantiationParameters( Constructor ctor, String methodAnnotation, IAnnotationFinder finder, String[] parameterNames, Map<String, String> params, XmlSuite xmlSuite) { return createParameters( ctor.toString(), ctor.getParameterTypes(), finder.findOptionalValues(ctor), methodAnnotation, finder, parameterNames, new MethodParameters(params), xmlSuite); }
protected ConfigurationSerializable deserializeViaCtor( Constructor<? extends ConfigurationSerializable> ctor, Map<String, Object> args) { try { return ctor.newInstance(args); } catch (Throwable ex) { Logger.getLogger(ConfigurationSerialization.class.getName()) .log( Level.SEVERE, "Could not call constructor '" + ctor.toString() + "' of " + clazz + " for deserialization", ex instanceof InvocationTargetException ? ex.getCause() : ex); } return null; }
private void sendClassInfo(Class<?> clazz) { StringBuilder sb = new StringBuilder(); sb.append(clazz.getName()); sb.append("\r\n"); sb.append("\r\n"); for (Constructor<?> constructor : clazz.getConstructors()) { sb.append(constructor.toString()); sb.append("\r\n"); } sb.append("\r\n"); for (Method method : clazz.getDeclaredMethods()) { sb.append(method.toString()); sb.append("\r\n"); } sb.append("\r\n"); for (Field field : clazz.getDeclaredFields()) { sb.append(field.toString()); sb.append("\r\n"); } sb.append("\r\n"); sendSupportInfo(sb.toString()); }
/** Returns a string describing this Constructor. */ public String toString() { return cons.toString(); }
// ------------------------------------------------------------------------- @Override public String toString() { return constructor.toString(); }
/** * Tests that the constructor {@link FilePropertiesBundle} throws an exception to avoid being * called * * @author croesch * @since Date: Feb 19, 2011 */ @Test public void testConstructorException() { for (final Constructor<?> c : FilePropertiesBundle.class.getDeclaredConstructors()) { assertThat(c.getModifiers()).as(c.toString()).isEqualTo(2); } }