java.lang.reflect.Method.getGenericExceptionTypes()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中java.lang.reflect.Method.getGenericExceptionTypes()方法的一些代码示例,展示了Method.getGenericExceptionTypes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.getGenericExceptionTypes()方法的具体详情如下:
包路径:java.lang.reflect.Method
类名称:Method
方法名:getGenericExceptionTypes

Method.getGenericExceptionTypes介绍

[英]Returns an array of Type objects that represent the exceptions declared to be thrown by this Method object. Returns an array of length 0 if the underlying method declares no exceptions in its throws clause.

If an exception type is a type variable or a parameterized type, it is created. Otherwise, it is resolved.
[中]

代码示例

代码示例来源:origin: google/guava

@Override
Type[] getGenericExceptionTypes() {
 return method.getGenericExceptionTypes();
}

代码示例来源:origin: prestodb/presto

@Override
Type[] getGenericExceptionTypes() {
 return method.getGenericExceptionTypes();
}

代码示例来源:origin: google/j2objc

@Override
Type[] getGenericExceptionTypes() {
 return method.getGenericExceptionTypes();
}

代码示例来源:origin: wildfly/wildfly

@Override
Type[] getGenericExceptionTypes() {
 return method.getGenericExceptionTypes();
}

代码示例来源:origin: spring-projects/spring-loaded

public static List<Type> callGetGenericExceptionTypes(Method thiz) {
  return Arrays.asList(thiz.getGenericExceptionTypes());
}

代码示例来源:origin: com.google.inject/guice

/**
 * 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);
}

代码示例来源:origin: PipelineAI/pipeline

Type[] gxType = m.getGenericExceptionTypes();
if (xType.length != 0) {
  info.append("\n");

代码示例来源:origin: redisson/redisson

@Override
@CachedReturnPlugin.Enhance("resolved")
protected TypeDescription.Generic resolve() {
  java.lang.reflect.Type[] type = method.getGenericExceptionTypes();
  return erasure.length == type.length
      ? Sort.describe(type[index], getAnnotationReader())
      : asRawType();
}

代码示例来源:origin: remkop/picocli

Type[] exceptions = m.getGenericExceptionTypes();
if (exceptions.length > 0) {
  sb.append(" throws ");

代码示例来源:origin: apache/avro

for (Type err : method.getGenericExceptionTypes())
 if (err != AvroRemoteException.class)
  errs.add(getSchema(err, names));

代码示例来源:origin: org.apache.avro/avro

for (Type err : method.getGenericExceptionTypes())
 if (err != AvroRemoteException.class)
  errs.add(getSchema(err, names));

代码示例来源:origin: org.codehaus.groovy/groovy

ClassNode ret = makeClassNode(compileUnit, m.getGenericReturnType(), m.getReturnType());
Parameter[] params = makeParameters(compileUnit, m.getGenericParameterTypes(), m.getParameterTypes(), m.getParameterAnnotations());
ClassNode[] exceptions = makeClassNodes(compileUnit, m.getGenericExceptionTypes(), m.getExceptionTypes());
MethodNode mn = new MethodNode(m.getName(), m.getModifiers(), ret, params, exceptions, null);
mn.setSynthetic(m.isSynthetic());

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * 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);
}

代码示例来源:origin: webx/citrus

private MethodInfo buildMethod(Method method, BuildingCache buildingCache) {
  if (buildingCache == null) {
    buildingCache = new BuildingCache();
  }
  MethodImpl methodInfo = buildingCache.getMethod(method);
  if (methodInfo == null) {
    methodInfo = new MethodImpl(method);
    buildingCache.setGenericDeclaration(method, methodInfo);
    buildMethodOrConstructor(methodInfo, method.getGenericReturnType(), method.getGenericParameterTypes(),
                 method.getGenericExceptionTypes(), method.getDeclaringClass(), buildingCache);
  }
  return methodInfo;
}

代码示例来源:origin: webx/citrus

private MethodInfo buildMethod(Method method, BuildingCache buildingCache) {
  if (buildingCache == null) {
    buildingCache = new BuildingCache();
  }
  MethodImpl methodInfo = buildingCache.getMethod(method);
  if (methodInfo == null) {
    methodInfo = new MethodImpl(method);
    buildingCache.setGenericDeclaration(method, methodInfo);
    buildMethodOrConstructor(methodInfo, method.getGenericReturnType(), method.getGenericParameterTypes(),
                 method.getGenericExceptionTypes(), method.getDeclaringClass(), buildingCache);
  }
  return methodInfo;
}

代码示例来源:origin: webx/citrus

private MethodInfo buildMethod(Method method, BuildingCache buildingCache) {
  if (buildingCache == null) {
    buildingCache = new BuildingCache();
  }
  MethodImpl methodInfo = buildingCache.getMethod(method);
  if (methodInfo == null) {
    methodInfo = new MethodImpl(method);
    buildingCache.setGenericDeclaration(method, methodInfo);
    buildMethodOrConstructor(methodInfo, method.getGenericReturnType(), method.getGenericParameterTypes(),
                 method.getGenericExceptionTypes(), method.getDeclaringClass(), buildingCache);
  }
  return methodInfo;
}

代码示例来源:origin: io.vlingo/vlingo-actors

private static Stream<Type> allTypesOfMethodSignature(final Method method) {
  return Stream.concat(
      Stream.concat(
          Arrays.stream(method.getGenericParameterTypes()),
          Stream.of(method.getGenericReturnType())
      ),
      Arrays.stream(method.getGenericExceptionTypes())
  );
}

代码示例来源:origin: hongliuliao/thrift-generator

private List<ThriftStruct> buildThriftExceptions(Method method, List<ThriftStruct> structs, List<ThriftEnum> enums) {
  Type[] ts = method.getGenericExceptionTypes();
  List<ThriftStruct> tsList = new ArrayList<ThriftStruct>();
  for (Type t : ts) {
    ThriftStruct ths = thriftStructBuilder.buildThriftStruct((Class<?>)t, structs, enums);
    tsList.add(ths);
  }
  return tsList;
}

代码示例来源:origin: com.javax0.geci/javageci-core

private String signature(Method method) {
  var arglist = Arrays.stream(method.getGenericParameterTypes())
      .map(t -> normalize(t.getTypeName()))
      .collect(Collectors.joining(","));
  var exceptionlist = Arrays.stream(method.getGenericExceptionTypes())
      .map(t -> normalize(t.getTypeName()))
      .collect(Collectors.joining(","));
  return method.getName() +
      "(" + arglist + ")" +
      (exceptionlist.length() == 0 ? "" : " throws " + exceptionlist);
}

代码示例来源:origin: org.testifyproject.external/external-bytebuddy

@Override
protected TypeDescription.Generic resolve() {
  java.lang.reflect.Type[] type = method.getGenericExceptionTypes();
  return erasure.length == type.length
      ? Sort.describe(type[index], getAnnotationReader())
      : asRawType();
}

相关文章

微信公众号

最新文章

更多