List of usage examples for java.lang.reflect Method getExceptionTypes
@Override
public Class<?>[] getExceptionTypes()
From source file:org.solmix.datax.support.InvokerObject.java
private static String getFormattedMethodSignature(Method method) { if (method == null) return null; String result = (new StringBuilder()).append(method.getReturnType().getName()).append(" ") .append(method.getDeclaringClass().getName()).append(".").append(method.getName()).append("(") .toString();//from ww w. j a v a2 s. c om Class<?> paramTypes[] = method.getParameterTypes(); for (int ii = 0; ii < paramTypes.length; ii++) { result = (new StringBuilder()).append(result).append(paramTypes[ii].getName()).toString(); if (ii + 1 < paramTypes.length) result = (new StringBuilder()).append(result).append(", ").toString(); } result = (new StringBuilder()).append(result).append(")").toString(); Class<?> exceptionTypes[] = method.getExceptionTypes(); if (exceptionTypes.length > 0) { result = (new StringBuilder()).append(result).append(" throws ").toString(); for (int ii = 0; ii < exceptionTypes.length; ii++) { result = (new StringBuilder()).append(result).append(exceptionTypes[ii].getName()).toString(); if (ii + 1 < exceptionTypes.length) result = (new StringBuilder()).append(result).append(", ").toString(); } } return result; }
From source file:org.structr.core.entity.SchemaMethod.java
private boolean getSignature(final Class type, final String methodName, final ActionEntry entry) { // superclass is AbstractNode for (final Method method : type.getMethods()) { if (methodName.equals(method.getName()) && (method.getModifiers() & Modifier.STATIC) == 0) { final Type[] parameterTypes = method.getGenericParameterTypes(); final Type returnType = method.getGenericReturnType(); final List<Type> types = new LinkedList<>(); // compile list of types to check for generic type parameter types.addAll(Arrays.asList(parameterTypes)); types.add(returnType);//from w ww . j av a 2 s. c om final String genericTypeParameter = getGenericMethodParameter(types, method); // check for generic return type, and if the method defines its own generic type if (returnType instanceof TypeVariable && ((TypeVariable) returnType).getGenericDeclaration().equals(method)) { // method defines its own generic type entry.setReturnType(genericTypeParameter + returnType.getTypeName()); } else { // non-generic return type final Class returnClass = method.getReturnType(); if (returnClass.isArray()) { entry.setReturnType(genericTypeParameter + returnClass.getComponentType().getName() + "[]"); } else { entry.setReturnType(genericTypeParameter + method.getReturnType().getName()); } } for (final Parameter parameter : method.getParameters()) { String typeName = parameter.getParameterizedType().getTypeName(); String name = parameter.getType().getSimpleName(); if (typeName.contains("$")) { typeName = typeName.replace("$", "."); } entry.addParameter(typeName, parameter.getName()); } for (final Class exception : method.getExceptionTypes()) { entry.addException(exception.getName()); } entry.setOverrides(getProperty(overridesExisting)); entry.setCallSuper(getProperty(callSuper)); // success return true; } } return false; }
From source file:org.wso2.msf4j.swagger.ExtendedSwaggerReader.java
private Operation parseMethod(Class<?> cls, Method method, List<Parameter> globalParameters, List<ApiResponse> classApiResponses) { Operation operation = new Operation(); ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); ApiResponses responseAnnotation = ReflectionUtils.getAnnotation(method, ApiResponses.class); String operationId = method.getName(); String responseContainer = null; Type responseType = null;/*from w w w . j ava2s . com*/ Map<String, Property> defaultResponseHeaders = new HashMap<>(); if (apiOperation != null) { if (apiOperation.hidden()) { return null; } if (!"".equals(apiOperation.nickname())) { operationId = apiOperation.nickname(); } defaultResponseHeaders = parseResponseHeaders(apiOperation.responseHeaders()); operation.summary(apiOperation.value()).description(apiOperation.notes()); if (apiOperation.response() != null && !isVoid(apiOperation.response())) { responseType = apiOperation.response(); } if (!"".equals(apiOperation.responseContainer())) { responseContainer = apiOperation.responseContainer(); } if (apiOperation.authorizations() != null) { List<SecurityRequirement> securities = new ArrayList<>(); for (Authorization auth : apiOperation.authorizations()) { if (auth.value() != null && !"".equals(auth.value())) { SecurityRequirement security = new SecurityRequirement(); security.setName(auth.value()); AuthorizationScope[] scopes = auth.scopes(); for (AuthorizationScope scope : scopes) { if (scope.scope() != null && !"".equals(scope.scope())) { security.addScope(scope.scope()); } } securities.add(security); } } if (securities.size() > 0) { securities.forEach(operation::security); } } if (apiOperation.consumes() != null && !apiOperation.consumes().isEmpty()) { String[] consumesAr = ReaderUtils.splitContentValues(new String[] { apiOperation.consumes() }); for (String consume : consumesAr) { operation.consumes(consume); } } if (apiOperation.produces() != null && !apiOperation.produces().isEmpty()) { String[] producesAr = ReaderUtils.splitContentValues(new String[] { apiOperation.produces() }); for (String produce : producesAr) { operation.produces(produce); } } } if (apiOperation != null && StringUtils.isNotEmpty(apiOperation.responseReference())) { Response response = new Response().description(SUCCESSFUL_OPERATION); response.schema(new RefProperty(apiOperation.responseReference())); operation.addResponse(String.valueOf(apiOperation.code()), response); } else if (responseType == null) { // pick out response from method declaration LOGGER.debug("picking up response class from method " + method); responseType = method.getGenericReturnType(); } if (isValidResponse(responseType)) { final Property property = ModelConverters.getInstance().readAsProperty(responseType); if (property != null) { final Property responseProperty = ContainerWrapper.wrapContainer(responseContainer, property); final int responseCode = apiOperation == null ? 200 : apiOperation.code(); operation.response(responseCode, new Response().description(SUCCESSFUL_OPERATION) .schema(responseProperty).headers(defaultResponseHeaders)); appendModels(responseType); } } operation.operationId(operationId); if (operation.getConsumes() == null || operation.getConsumes().isEmpty()) { final Consumes consumes = ReflectionUtils.getAnnotation(method, Consumes.class); if (consumes != null) { for (String mediaType : ReaderUtils.splitContentValues(consumes.value())) { operation.consumes(mediaType); } } } if (operation.getProduces() == null || operation.getProduces().isEmpty()) { final Produces produces = ReflectionUtils.getAnnotation(method, Produces.class); if (produces != null) { for (String mediaType : ReaderUtils.splitContentValues(produces.value())) { operation.produces(mediaType); } } } List<ApiResponse> apiResponses = new ArrayList<>(); if (responseAnnotation != null) { apiResponses.addAll(Arrays.asList(responseAnnotation.value())); } Class<?>[] exceptionTypes = method.getExceptionTypes(); for (Class<?> exceptionType : exceptionTypes) { ApiResponses exceptionResponses = ReflectionUtils.getAnnotation(exceptionType, ApiResponses.class); if (exceptionResponses != null) { apiResponses.addAll(Arrays.asList(exceptionResponses.value())); } } for (ApiResponse apiResponse : apiResponses) { addResponse(operation, apiResponse); } // merge class level @ApiResponse for (ApiResponse apiResponse : classApiResponses) { String key = apiResponse.code() == 0 ? "default" : String.valueOf(apiResponse.code()); if (operation.getResponses().containsKey(key)) { continue; } addResponse(operation, apiResponse); } if (ReflectionUtils.getAnnotation(method, Deprecated.class) != null) { operation.setDeprecated(true); } // process parameters globalParameters.forEach(operation::parameter); Type[] genericParameterTypes = method.getGenericParameterTypes(); Annotation[][] paramAnnotations = method.getParameterAnnotations(); for (int i = 0; i < genericParameterTypes.length; i++) { final Type type = TypeFactory.defaultInstance().constructType(genericParameterTypes[i], cls); List<Parameter> parameters = getParameters(type, Arrays.asList(paramAnnotations[i])); parameters.forEach(operation::parameter); } if (operation.getResponses() == null) { Response response = new Response().description(SUCCESSFUL_OPERATION); operation.defaultResponse(response); } return operation; }