Constructor.getAnnotation
Code IndexAdd Codota to your IDE (free)

Best Java code snippets using java.lang.reflect.Constructor.getAnnotation (Showing top 20 results out of 2,889)

  • Common ways to obtain Constructor
private void myMethod () {
Constructor c =
  • Class clazz;Class[] parameterTypes;clazz.getConstructor(parameterTypes)
  • Class clazz;clazz.getConstructor()
  • Class clazz;Class[] parameterTypes;clazz.getDeclaredConstructor(parameterTypes)
  • Smart code suggestions by Codota
}
origin: spring-projects/spring-loaded

public Annotation callConstructorGetAnnotation(Constructor<?> m, Class<? extends Annotation> annotClass) {
  return m.getAnnotation(annotClass);
}
public List<List<Annotation>> callConstructorGetParameterAnnotations(Constructor<?> m) {
origin: spring-projects/spring-framework

  @Nullable
  public static String[] evaluate(Constructor<?> candidate, int paramCount) {
    ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class);
    if (cp != null) {
      String[] names = cp.value();
      if (names.length != paramCount) {
        throw new IllegalStateException("Constructor annotated with @ConstructorProperties but not " +
            "corresponding to actual number of parameters (" + paramCount + "): " + candidate);
      }
      return names;
    }
    else {
      return null;
    }
  }
}
origin: MorphiaOrg/morphia

@SuppressWarnings("unchecked")
private boolean injectOnConstructor(final Class clazz) {
  final Constructor[] cs = clazz.getDeclaredConstructors();
  for (final Constructor constructor : cs) {
    if (constructor.getAnnotation(Inject.class) != null) {
      return true;
    }
  }
  return false;
}
origin: jooby-project/jooby

 private boolean shouldInject(final Class<?> clazz) {
  for(Constructor<?> constructor : clazz.getDeclaredConstructors()) {
   if (constructor.getAnnotation(Inject.class) != null) {
    return true;
   }
  }
  return false;
 }
}
origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public Instantiator replaceBy(Resolved instantiator) {
  Priority left = constructor.getAnnotation(Priority.class), right = instantiator.constructor.getAnnotation(Priority.class);
  int leftPriority = left == null ? Priority.DEFAULT : left.value(), rightPriority = right == null ? Priority.DEFAULT : right.value();
  if (leftPriority > rightPriority) {
    return this;
  } else if (leftPriority < rightPriority) {
    return instantiator;
  } else {
    throw new IllegalStateException("Ambiguous constructors " + constructor + " and " + instantiator.constructor);
  }
}
origin: jenkinsci/configuration-as-code-plugin

@CheckForNull
public static Constructor getDataBoundConstructor(@Nonnull Class type) {
  for (Constructor c : type.getConstructors()) {
    if (c.getAnnotation(DataBoundConstructor.class) != null) return c;
  }
  return null;
}
origin: org.testng/testng

@Override
public <A extends IAnnotation> A findAnnotation(Constructor<?> cons, Class<A> annotationClass) {
 final Class<? extends Annotation> a = m_annotationMap.get(annotationClass);
 if (a == null) {
  throw new IllegalArgumentException("Java @Annotation class for '"
    + annotationClass + "' not found.");
 }
 Annotation annotation = cons.getAnnotation(a);
 return findAnnotation(cons.getDeclaringClass(), annotation, annotationClass, null, cons, null,
   new Pair<>(annotation, cons));
}
origin: org.springframework/spring-beans

  @Nullable
  public static String[] evaluate(Constructor<?> candidate, int paramCount) {
    ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class);
    if (cp != null) {
      String[] names = cp.value();
      if (names.length != paramCount) {
        throw new IllegalStateException("Constructor annotated with @ConstructorProperties but not " +
            "corresponding to actual number of parameters (" + paramCount + "): " + candidate);
      }
      return names;
    }
    else {
      return null;
    }
  }
}
origin: apache/incubator-gobblin

private boolean canUseConstructor(Constructor<?> constructor) {
 if (!Modifier.isPublic(constructor.getModifiers())) {
  return false;
 }
 if (!constructor.isAnnotationPresent(CliObjectSupport.class)) {
  return false;
 }
 for (Class<?> param : constructor.getParameterTypes()) {
  if (param != String.class) {
   return false;
  }
 }
 return constructor.getParameterTypes().length ==
   constructor.getAnnotation(CliObjectSupport.class).argumentNames().length;
}
origin: fabioCollini/DaggerMock

public void checkOverriddenInjectAnnotatedClass(List<Object> modules) {
  Set<String> errors = new HashSet<>();
  for (Map.Entry<ObjectId, Provider> entry : fields.entrySet()) {
    ObjectId objectId = entry.getKey();
    Constructor[] constructors = objectId.objectClass.getConstructors();
    for (Constructor constructor : constructors) {
      if (constructor.getAnnotation(Inject.class) != null && !existProvidesMethodInModule(objectId, modules)) {
        errors.add(objectId.objectClass.getName());
      }
    }
  }
  ErrorsFormatter.throwExceptionOnErrors(
      "Error while trying to override objects",
      errors,
      "You must define overridden objects using a @Provides annotated method instead of using @Inject annotation");
}
origin: alibaba/fastjson

JSONCreator annotation = constructor.getAnnotation(JSONCreator.class);
if (annotation != null) {
  if (creatorConstructor != null) {
origin: jersey/jersey

@SuppressWarnings("MagicConstant")
private boolean isCompatible(final Constructor<?> constructor) {
  if (constructor.getAnnotation(Inject.class) != null) {
    // JSR-330 applicable
    return true;
  }
  final int paramSize = constructor.getParameterTypes().length;
  if (paramSize != 0 && resolverAnnotations.get().isEmpty()) {
    return false;
  }
  if (!Modifier.isPublic(constructor.getModifiers())) {
    // return true for a default constructor, return false otherwise.
    return paramSize == 0
        && (constructor.getDeclaringClass().getModifiers()
              & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE)) == constructor.getModifiers();
  }
  for (final Annotation[] paramAnnotations : constructor.getParameterAnnotations()) {
    boolean found = false;
    for (final Annotation paramAnnotation : paramAnnotations) {
      if (resolverAnnotations.get().contains(paramAnnotation.annotationType())) {
        found = true;
        break;
      }
    }
    if (!found) {
      return false;
    }
  }
  return true;
}
origin: cbeust/testng

@Override
public <A extends IAnnotation> A findAnnotation(Constructor<?> cons, Class<A> annotationClass) {
 final Class<? extends Annotation> a = m_annotationMap.get(annotationClass);
 if (a == null) {
  throw new IllegalArgumentException(
    "Java @Annotation class for '" + annotationClass + "' not found.");
 }
 Annotation annotation = cons.getAnnotation(a);
 return findAnnotation(
   cons.getDeclaringClass(),
   annotation,
   annotationClass,
   null,
   cons,
   null,
   new Pair<>(annotation, cons),
   null);
}
origin: spring-projects/spring-framework

ConstructorProperties cp = ctor.getAnnotation(ConstructorProperties.class);
String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor));
Assert.state(paramNames != null, () -> "Cannot resolve parameter names for constructor " + ctor);
origin: cbeust/testng

@DataProvider(name = "dp")
public static Object[][] createData(Constructor c) {
 Assert.assertEquals(c.getDeclaringClass(), ConstructorSample.class);
 Assert.assertNotNull(c.getAnnotation(Factory.class));
 Assert.assertEquals(c.getParameterTypes().length, 1);
 Assert.assertEquals(c.getParameterTypes()[0], String.class);
 return new Object[][] {{"Cedric"}, {"Alois"}};
}
origin: spring-projects/spring-framework

@Test
public void javaLangAnnotationTypeViaFindMergedAnnotation() throws Exception {
  Constructor<?> deprecatedCtor = Date.class.getConstructor(String.class);
  assertEquals(deprecatedCtor.getAnnotation(Deprecated.class), findMergedAnnotation(deprecatedCtor, Deprecated.class));
  assertEquals(Date.class.getAnnotation(Deprecated.class), findMergedAnnotation(Date.class, Deprecated.class));
}
origin: cbeust/testng

@DataProvider(name = "dp1")
public static Object[][] createData1(ConstructorOrMethod cOrM) {
 Assert.assertEquals(cOrM.getDeclaringClass(), ConstructorOrMethodSample.class);
 Assert.assertNull(cOrM.getMethod());
 Assert.assertNotNull(cOrM.getConstructor());
 Constructor c = cOrM.getConstructor();
 Assert.assertNotNull(c.getAnnotation(Factory.class));
 Assert.assertEquals(c.getParameterTypes().length, 1);
 Assert.assertEquals(c.getParameterTypes()[0], String.class);
 return new Object[][] {{"0"}, {"1"}};
}
origin: immutables/immutables

 @Test
 public void constructorPass() throws Exception {
  check(ImmutableValForPass.class.getConstructor(int.class).getAnnotation(B1.class)).notNull();
  check(ImmutableValForPass.class.getConstructor(int.class).getAnnotation(C1.class)).notNull();
 }
}
origin: spring-projects/spring-framework

ConstructorProperties cp = ctor.getAnnotation(ConstructorProperties.class);
String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor));
Assert.state(paramNames != null, () -> "Cannot resolve parameter names for constructor " + ctor);
origin: cbeust/testng

 @DataProvider(name = "cookie-master")
 public static Object[][] cookies(ConstructorOrMethod method) {
  TestInfo value;
  if (method.getConstructor() != null) {
   value = (TestInfo) method.getConstructor().getAnnotation(TestInfo.class);
  } else {
   value = method.getMethod().getAnnotation(TestInfo.class);
  }
  String name = value.name();
  if ("glutton".equalsIgnoreCase(name)) {
   return new Object[][] {{"oreo", 200}};
  }
  if ("nibbler".equalsIgnoreCase(name)) {
   return new Object[][] {{"marie-gold", 10}};
  }
  return new Object[][] {
   {"oreo", 200},
   {"marie-gold", 10}
  };
 }
}
java.lang.reflectConstructorgetAnnotation

Popular methods of Constructor

  • newInstance
    Uses the constructor represented by this Constructor object to create and initialize a new instance
  • getParameterTypes
  • setAccessible
  • getDeclaringClass
    Returns the Class object representing the class that declares the constructor represented by this Co
  • getModifiers
    Returns the Java language modifiers for the constructor represented by this Constructor object, as
  • getParameterAnnotations
    Returns an array of arrays that represent the annotations of the formal parameters of this construct
  • getGenericParameterTypes
    Returns the generic parameter types as an array of Typeinstances, in declaration order. If this cons
  • isAccessible
  • getName
    Returns the name of this constructor, as a string. This is always the same as the simple name of the
  • isVarArgs
    Indicates whether or not this constructor takes a variable number of arguments.
  • getExceptionTypes
  • getParameterCount
  • getExceptionTypes,
  • getParameterCount,
  • isAnnotationPresent,
  • toString,
  • getParameters,
  • getGenericExceptionTypes,
  • getTypeParameters,
  • getDeclaredAnnotations,
  • equals

Popular in Java

  • Creating JSON documents from java classes using gson
  • notifyDataSetChanged (ArrayAdapter)
  • findViewById (Activity)
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base

For IntelliJ IDEA,
Android Studio or Eclipse

  • Search for JavaScript code betaCodota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutBlogContact Us
  • Plugin user guideTerms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)