Java Code Examples for java.lang.reflect.Constructor#getGenericExceptionTypes()

The following examples show how to use java.lang.reflect.Constructor#getGenericExceptionTypes() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: businessworks   File: TypeLiteral.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the resolved generic exception types thrown by {@code constructor}.
 *
 * @param methodOrConstructor a method or constructor defined by this or any supertype.
 * @since 2.0
 */
public List<TypeLiteral<?>> getExceptionTypes(Member methodOrConstructor) {
  Type[] genericExceptionTypes;

  if (methodOrConstructor instanceof Method) {
    Method method = (Method) methodOrConstructor;
    checkArgument(method.getDeclaringClass().isAssignableFrom(rawType),
        "%s is not defined by a supertype of %s", method, type);
    genericExceptionTypes = method.getGenericExceptionTypes();

  } else if (methodOrConstructor instanceof Constructor) {
    Constructor<?> constructor = (Constructor<?>) methodOrConstructor;
    checkArgument(constructor.getDeclaringClass().isAssignableFrom(rawType),
        "%s does not construct a supertype of %s", constructor, type);
    genericExceptionTypes = constructor.getGenericExceptionTypes();

  } else {
    throw new IllegalArgumentException("Not a method or a constructor: " + methodOrConstructor);
  }

  return resolveAll(genericExceptionTypes);
}
 
Example 2
Source Project: ldp4j   File: ClassDescription.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void processType(Constructor<?> type) {
	super.addTitle("Constructor");
	super.addBlockField("member", wrapElementAs(type,Member.class));
	super.addBlockField("generic declaration", wrapElementAs(type,GenericDeclaration.class));
	super.addBlockField("annotated element", wrapElementAs(type,AnnotatedElement.class));
	super.addField("accessible", type.isAccessible());
	super.addMultiField("parameter types",type.getParameterTypes());
	super.addMultiField("generic parameter types",type.getGenericParameterTypes());
	Annotation[][] parameterAnnotations = type.getParameterAnnotations();
	List<String> annots=new ArrayList<String>();
	for(Annotation[] pa:parameterAnnotations) {
		annots.add(Arrays.toString(pa));
	}
	super.addMultiField("parameter annotations",annots);
	super.addField("var args",type.isVarArgs());
	super.addMultiField("exception types",type.getExceptionTypes());
	super.addMultiField("generic exception types",type.getGenericExceptionTypes());
}
 
Example 3
Source Project: crate   File: TypeLiteral.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the resolved generic exception types thrown by {@code constructor}.
 *
 * @param methodOrConstructor a method or constructor defined by this or any supertype.
 * @since 2.0
 */
public List<TypeLiteral<?>> getExceptionTypes(Member methodOrConstructor) {
    Type[] genericExceptionTypes;

    if (methodOrConstructor instanceof Method) {
        Method method = (Method) methodOrConstructor;
        if (!method.getDeclaringClass().isAssignableFrom(rawType)) {
            throw new IllegalArgumentException(method + " is not defined by a supertype of " + type);
        }

        genericExceptionTypes = method.getGenericExceptionTypes();

    } else if (methodOrConstructor instanceof Constructor) {
        Constructor<?> constructor = (Constructor<?>) methodOrConstructor;
        if (!constructor.getDeclaringClass().isAssignableFrom(rawType)) {
            throw new IllegalArgumentException(constructor + " does not construct a supertype of " + type);
        }
        genericExceptionTypes = constructor.getGenericExceptionTypes();

    } else {
        throw new IllegalArgumentException("Not a method or a constructor: " + methodOrConstructor);
    }

    return resolveAll(genericExceptionTypes);
}