Tabnine Logo
ReflectionUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
ReflectionUtils
in
io.swagger.v3.core.util

Best Java code snippets using io.swagger.v3.core.util.ReflectionUtils (Showing top 20 results out of 315)

origin: swagger-api/swagger-core

annotation = getAnnotation(superClass, annotationClass);
annotation = getAnnotation(anInterface, annotationClass);
if (annotation != null) {
  return annotation;
origin: swagger-api/swagger-core

/**
 * Returns an annotation by type from a method.
 *
 * @param method          is the method to find
 * @param annotationClass is the type of annotation
 * @param <A>             is the type of annotation
 * @return annotation if it is found
 */
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationClass) {
  A annotation = method.getAnnotation(annotationClass);
  if (annotation == null) {
    for (Annotation metaAnnotation : method.getAnnotations()) {
      annotation = metaAnnotation.annotationType().getAnnotation(annotationClass);
      if (annotation != null) {
        return annotation;
      }
    }
    Method superclassMethod = getOverriddenMethod(method);
    if (superclassMethod != null) {
      annotation = getAnnotation(superclassMethod, annotationClass);
    }
  }
  return annotation;
}
origin: swagger-api/swagger-core

public static <A extends Annotation> List<A> getRepeatableAnnotations(Class<?> cls, Class<A> annotationClass) {
  A[] annotations = getRepeatableAnnotationsArray(cls, annotationClass);
  if (annotations == null || annotations.length == 0) {
    return null;
  }
  return Arrays.asList(annotations);
}
origin: swagger-api/swagger-core

/**
 * Returns a List of repeatable annotations by type from a method.
 *
 * @param method          is the method to find
 * @param annotationClass is the type of annotation
 * @param <A>             is the type of annotation
 * @return List of repeatable annotations if it is found
 */
public static <A extends Annotation> List<A> getRepeatableAnnotations(Method method, Class<A> annotationClass) {
  A[] annotations = method.getAnnotationsByType(annotationClass);
  if (annotations == null || annotations.length == 0) {
    for (Annotation metaAnnotation : method.getAnnotations()) {
      annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass);
      if (annotations != null && annotations.length > 0) {
        return Arrays.asList(annotations);
      }
    }
    Method superclassMethod = getOverriddenMethod(method);
    if (superclassMethod != null) {
      return getRepeatableAnnotations(superclassMethod, annotationClass);
    }
  }
  if (annotations == null) {
    return null;
  }
  return Arrays.asList(annotations);
}
origin: swagger-api/swagger-core

if (!ReflectionUtils.isConstructorCompatible(constructor)
    && !ReflectionUtils.isInject(Arrays.asList(constructor.getDeclaredAnnotations()))) {
  continue;
origin: swagger-api/swagger-core

final javax.ws.rs.Path apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class);
io.swagger.v3.oas.annotations.responses.ApiResponse[] classResponses = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.responses.ApiResponse.class);
List<io.swagger.v3.oas.annotations.security.SecurityScheme> apiSecurityScheme = ReflectionUtils.getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityScheme.class);
List<io.swagger.v3.oas.annotations.security.SecurityRequirement> apiSecurityRequirements = ReflectionUtils.getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityRequirement.class);
ExternalDocumentation apiExternalDocs = ReflectionUtils.getAnnotation(cls, ExternalDocumentation.class);
io.swagger.v3.oas.annotations.tags.Tag[] apiTags = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.tags.Tag.class);
io.swagger.v3.oas.annotations.servers.Server[] apiServers = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.servers.Server.class);
javax.ws.rs.Consumes classConsumes = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Consumes.class);
javax.ws.rs.Produces classProduces = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Produces.class);
OpenAPIDefinition openAPIDefinition = ReflectionUtils.getAnnotation(cls, OpenAPIDefinition.class);
  javax.ws.rs.Produces methodProduces = ReflectionUtils.getAnnotation(method, javax.ws.rs.Produces.class);
  javax.ws.rs.Consumes methodConsumes = ReflectionUtils.getAnnotation(method, javax.ws.rs.Consumes.class);
  if (ReflectionUtils.isOverriddenMethod(method, cls)) {
    continue;
  javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class);
    io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class);
    JsonView jsonViewAnnotation;
    JsonView jsonViewAnnotationForRequestBody;
      jsonViewAnnotationForRequestBody = null;
origin: swagger-api/swagger-core

public static Annotation[][] getParameterAnnotations(Method method) {
  Annotation[][] methodAnnotations = method.getParameterAnnotations();
  Method overriddenmethod = getOverriddenMethod(method);
  if (overriddenmethod != null) {
    Annotation[][] overriddenAnnotations = overriddenmethod
        .getParameterAnnotations();
    for (int i = 0; i < methodAnnotations.length; i++) {
      List<Type> types = new ArrayList<>();
      for (int j = 0; j < methodAnnotations[i].length; j++) {
        types.add(methodAnnotations[i][j].annotationType());
      }
      for (int j = 0; j < overriddenAnnotations[i].length; j++) {
        if (!types.contains(overriddenAnnotations[i][j]
            .annotationType())) {
          methodAnnotations[i] = ArrayUtils.add(
              methodAnnotations[i],
              overriddenAnnotations[i][j]);
        }
      }
    }
  }
  return methodAnnotations;
}
origin: com.atlassian.swagger/atlassian-swagger-doclet

if (methodOpt.isDefined()) {
  Method method = methodOpt.get();
  Annotation[][] paramAnnotations = ReflectionUtils.getParameterAnnotations(method);
  Consumes methodConsumes = ReflectionUtils.getAnnotation(method, Consumes.class);
  Consumes classConsumes = ReflectionUtils.getAnnotation(method.getDeclaringClass(), Consumes.class);
  JsonView jsonViewAnnotation = ReflectionUtils.getAnnotation(method, JsonView.class);
origin: swagger-api/swagger-core

/**
 * Checks if the method methodToFind is the overridden method from the superclass or superinterface.
 *
 * @param methodToFind is method to check
 * @param cls          is method class
 * @return true if the method is overridden method
 */
public static boolean isOverriddenMethod(Method methodToFind, Class<?> cls) {
  Set<Class<?>> superClasses = new HashSet<>();
  for (Class c : cls.getInterfaces()) {
    superClasses.add(c);
  }
  if (cls.getSuperclass() != null) {
    superClasses.add(cls.getSuperclass());
  }
  for (Class<?> superClass : superClasses) {
    if (superClass != null && !(superClass.equals(Object.class))) {
      for (Method method : superClass.getMethods()) {
        if (method.getName().equals(methodToFind.getName()) && method.getReturnType().isAssignableFrom(methodToFind.getReturnType())
            && Arrays.equals(method.getParameterTypes(), methodToFind.getParameterTypes()) && !Arrays.equals(method.getGenericParameterTypes(), methodToFind.getGenericParameterTypes())) {
          return true;
        }
      }
      if (isOverriddenMethod(methodToFind, superClass)) {
        return true;
      }
    }
  }
  return false;
}
origin: swagger-api/swagger-core

/**
 * Collects field-level parameters from class.
 *
 * @param cls        is a class for collecting
 * @param components
 * @return the collection of supported parameters
 */
public static List<Parameter> collectFieldParameters(Class<?> cls, Components components, javax.ws.rs.Consumes classConsumes, JsonView jsonViewAnnotation) {
  final List<Parameter> parameters = new ArrayList<Parameter>();
  for (Field field : ReflectionUtils.getDeclaredFields(cls)) {
    final List<Annotation> annotations = Arrays.asList(field.getAnnotations());
    final Type genericType = field.getGenericType();
    parameters.addAll(collectParameters(genericType, annotations, components, classConsumes, jsonViewAnnotation));
  }
  return parameters;
}
origin: swagger-api/swagger-core

/**
 * Returns overridden method from superclass if it exists. If method was not found returns null.
 *
 * @param method is method to find
 * @return overridden method from superclass
 */
public static Method getOverriddenMethod(Method method) {
  Class<?> declaringClass = method.getDeclaringClass();
  Class<?> superClass = declaringClass.getSuperclass();
  Method result = null;
  if (superClass != null && !(superClass.equals(Object.class))) {
    result = findMethod(method, superClass);
  }
  if (result == null) {
    for (Class<?> anInterface : declaringClass.getInterfaces()) {
      result = findMethod(method, anInterface);
      if (result != null) {
        return result;
      }
    }
  }
  return result;
}
origin: swagger-api/swagger-core

@Test
public void isConstructorCompatibleTest() throws NoSuchMethodException {
  Assert.assertFalse(ReflectionUtils.isConstructorCompatible(Child.class.getDeclaredConstructor()));
  Assert.assertTrue(ReflectionUtils.isConstructorCompatible(Child.class.getDeclaredConstructor(String.class)));
}
origin: swagger-api/swagger-core

@Test
public void isInjectTest() throws NoSuchMethodException {
  final Method injectableMethod = Child.class.getMethod("injectableMethod");
  Assert.assertTrue(ReflectionUtils.isInject(Arrays.asList(injectableMethod.getDeclaredAnnotations())));
  final Method methodToFind = Child.class.getMethod("parametrizedMethod1", Integer.class);
  Assert.assertFalse(ReflectionUtils.isInject(Arrays.asList(methodToFind.getDeclaredAnnotations())));
}
origin: io.swagger.core.v3/swagger-jaxrs2

final javax.ws.rs.Path apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class);
io.swagger.v3.oas.annotations.responses.ApiResponse[] classResponses = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.responses.ApiResponse.class);
List<io.swagger.v3.oas.annotations.security.SecurityScheme> apiSecurityScheme = ReflectionUtils.getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityScheme.class);
List<io.swagger.v3.oas.annotations.security.SecurityRequirement> apiSecurityRequirements = ReflectionUtils.getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityRequirement.class);
ExternalDocumentation apiExternalDocs = ReflectionUtils.getAnnotation(cls, ExternalDocumentation.class);
io.swagger.v3.oas.annotations.tags.Tag[] apiTags = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.tags.Tag.class);
io.swagger.v3.oas.annotations.servers.Server[] apiServers = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.servers.Server.class);
javax.ws.rs.Consumes classConsumes = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Consumes.class);
javax.ws.rs.Produces classProduces = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Produces.class);
OpenAPIDefinition openAPIDefinition = ReflectionUtils.getAnnotation(cls, OpenAPIDefinition.class);
  javax.ws.rs.Produces methodProduces = ReflectionUtils.getAnnotation(method, javax.ws.rs.Produces.class);
  javax.ws.rs.Consumes methodConsumes = ReflectionUtils.getAnnotation(method, javax.ws.rs.Consumes.class);
  if (ReflectionUtils.isOverriddenMethod(method, cls)) {
    continue;
  javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class);
    io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class);
    JsonView jsonViewAnnotation;
    JsonView jsonViewAnnotationForRequestBody;
      jsonViewAnnotationForRequestBody = null;
origin: io.swagger.core.v3/swagger-core

/**
 * Returns a List of repeatable annotations by type from a method.
 *
 * @param method          is the method to find
 * @param annotationClass is the type of annotation
 * @param <A>             is the type of annotation
 * @return List of repeatable annotations if it is found
 */
public static <A extends Annotation> List<A> getRepeatableAnnotations(Method method, Class<A> annotationClass) {
  A[] annotations = method.getAnnotationsByType(annotationClass);
  if (annotations == null || annotations.length == 0) {
    for (Annotation metaAnnotation : method.getAnnotations()) {
      annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass);
      if (annotations != null && annotations.length > 0) {
        return Arrays.asList(annotations);
      }
    }
    Method superclassMethod = getOverriddenMethod(method);
    if (superclassMethod != null) {
      return getRepeatableAnnotations(superclassMethod, annotationClass);
    }
  }
  if (annotations == null) {
    return null;
  }
  return Arrays.asList(annotations);
}
origin: swagger-api/swagger-core

public static String extractOperationMethod(Method method, Iterator<OpenAPIExtension> chain) {
  if (method.getAnnotation(javax.ws.rs.GET.class) != null) {
    return GET_METHOD;
  } else if (method.getAnnotation(javax.ws.rs.PUT.class) != null) {
    return PUT_METHOD;
  } else if (method.getAnnotation(javax.ws.rs.POST.class) != null) {
    return POST_METHOD;
  } else if (method.getAnnotation(javax.ws.rs.DELETE.class) != null) {
    return DELETE_METHOD;
  } else if (method.getAnnotation(javax.ws.rs.OPTIONS.class) != null) {
    return OPTIONS_METHOD;
  } else if (method.getAnnotation(javax.ws.rs.HEAD.class) != null) {
    return HEAD_METHOD;
  } else if (method.getAnnotation(DELETE.class) != null) {
    return DELETE_METHOD;
  } else if (method.getAnnotation(HttpMethod.class) != null) {
    HttpMethod httpMethod = method.getAnnotation(HttpMethod.class);
    return httpMethod.value().toLowerCase();
  } else if (!StringUtils.isEmpty(getHttpMethodFromCustomAnnotations(method))) {
    return getHttpMethodFromCustomAnnotations(method);
  } else if ((ReflectionUtils.getOverriddenMethod(method)) != null) {
    return extractOperationMethod(ReflectionUtils.getOverriddenMethod(method), chain);
  } else if (chain != null && chain.hasNext()) {
    return chain.next().extractOperationMethod(method, chain);
  } else {
    return null;
  }
}
origin: swagger-api/swagger-core

@Test
public void isOverriddenMethodTest() throws NoSuchMethodException {
  for (Method method : Child.class.getMethods()) {
    if ("parametrizedMethod1".equals(method.getName())) {
      final boolean result = ReflectionUtils.isOverriddenMethod(method, Child.class);
      final Class<?> first = method.getParameterTypes()[0];
      if (Number.class.equals(first)) {
        Assert.assertTrue(result);
      } else if (Integer.class.equals(first)) {
        Assert.assertFalse(result);
      }
    } else if ("parametrizedMethod3".equals(method.getName())) {
      Assert.assertFalse(ReflectionUtils.isOverriddenMethod(method, Child.class));
    }
  }
  for (Method method : Object.class.getMethods()) {
    if ("equals".equals(method.getName())) {
      Assert.assertFalse(ReflectionUtils.isOverriddenMethod(method, Object.class));
    }
  }
  for (Method method : IParent.class.getMethods()) {
    if ("parametrizedMethod5".equals(method.getName())) {
      Assert.assertTrue(ReflectionUtils.isOverriddenMethod(method, IParent.class));
    } else if ("parametrizedMethod2".equals(method.getName())) {
      Assert.assertFalse(ReflectionUtils.isOverriddenMethod(method, IParent.class));
    } else {
      Assert.fail("Method not expected");
    }
  }
}
origin: swagger-api/swagger-core

/**
 * Returns the list of declared fields from the class <code>cls</code> and its superclasses
 * excluding <code>Object</code> class. If the field from child class hides the field from superclass,
 * the field from superclass won't be added to the result list.
 *
 * @param cls is the processing class
 * @return list of Fields
 */
public static List<Field> getDeclaredFields(Class<?> cls) {
  if (cls == null || Object.class.equals(cls)) {
    return Collections.emptyList();
  }
  final List<Field> fields = new ArrayList<Field>();
  final Set<String> fieldNames = new HashSet<String>();
  for (Field field : cls.getDeclaredFields()) {
    fields.add(field);
    fieldNames.add(field.getName());
  }
  for (Field field : getDeclaredFields(cls.getSuperclass())) {
    if (!fieldNames.contains(field.getName())) {
      fields.add(field);
    }
  }
  return fields;
}
origin: io.swagger.core.v3/swagger-jaxrs2

if (!ReflectionUtils.isConstructorCompatible(constructor)
    && !ReflectionUtils.isInject(Arrays.asList(constructor.getDeclaredAnnotations()))) {
  continue;
origin: swagger-api/swagger-core

@Test
public void testFindMethodForNullClass() throws Exception {
  Method method = ReflectionUtilsTest.class.getMethod("testFindMethodForNullClass", (Class<?>[]) null);
  assertNull(ReflectionUtils.findMethod(method, null));
}
io.swagger.v3.core.utilReflectionUtils

Most used methods

  • getAnnotation
    Returns an annotation by type from a method.
  • getOverriddenMethod
    Returns overridden method from superclass if it exists. If method was not found returns null.
  • getRepeatableAnnotationsArray
  • isOverriddenMethod
    Checks if the method methodToFind is the overridden method from the superclass or superinterface.
  • getDeclaredFields
    Returns the list of declared fields from the class cls and its superclasses excluding Object class.
  • getRepeatableAnnotations
    Returns a List of repeatable annotations by type from a method.
  • findMethod
    Searches the method methodToFind in given class cls. If the method is found returns it, else return
  • getParameterAnnotations
  • isConstructorCompatible
  • isInject
  • hasIdenticalParameters
  • isSystemType
  • hasIdenticalParameters,
  • isSystemType,
  • isVoid,
  • loadClassByName,
  • typeFromString

Popular in Java

  • Finding current android device location
  • getSharedPreferences (Context)
  • getSupportFragmentManager (FragmentActivity)
  • putExtra (Intent)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Reference (javax.naming)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now