use of javax.enterprise.inject.spi.AnnotatedField in project core by weld.
the class Formats method formatAsStackTraceElement.
/**
* See also WELD-1454.
*
* @param ij
* @return the formatted string
*/
public static String formatAsStackTraceElement(InjectionPoint ij) {
Member member;
if (ij.getAnnotated() instanceof AnnotatedField) {
AnnotatedField<?> annotatedField = (AnnotatedField<?>) ij.getAnnotated();
member = annotatedField.getJavaMember();
} else if (ij.getAnnotated() instanceof AnnotatedParameter<?>) {
AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) ij.getAnnotated();
member = annotatedParameter.getDeclaringCallable().getJavaMember();
} else {
// Throwing an exception here would hide the original exception.
return "-";
}
return formatAsStackTraceElement(member);
}
use of javax.enterprise.inject.spi.AnnotatedField in project core by weld.
the class JsonObjectsTest method getFooAnnotatedMethod.
private static AnnotatedMethod<Foo> getFooAnnotatedMethod(String name) {
final Method method = findDeclaredFooMethod(name);
return new AnnotatedMethod<Foo>() {
@Override
public List<AnnotatedParameter<Foo>> getParameters() {
Type[] paramTypes = method.getGenericParameterTypes();
if (paramTypes.length == 0) {
return Collections.emptyList();
}
List<AnnotatedParameter<Foo>> params = new ArrayList<>();
for (int i = 0; i < paramTypes.length; i++) {
final Type baseType = paramTypes[i];
final Annotation[] annotations = method.getParameterAnnotations()[i];
params.add(new AnnotatedParameter<Foo>() {
@Override
public Type getBaseType() {
return baseType;
}
@Override
public Set<Type> getTypeClosure() {
throw new UnsupportedOperationException();
}
@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
throw new UnsupportedOperationException();
}
@Override
public Set<Annotation> getAnnotations() {
return new HashSet<>(Arrays.asList(annotations));
}
@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
throw new UnsupportedOperationException();
}
@Override
public int getPosition() {
throw new UnsupportedOperationException();
}
@Override
public AnnotatedCallable<Foo> getDeclaringCallable() {
throw new UnsupportedOperationException();
}
});
}
return params;
}
@Override
public boolean isStatic() {
throw new UnsupportedOperationException();
}
@Override
public AnnotatedType<Foo> getDeclaringType() {
return new AnnotatedType<Foo>() {
@Override
public Type getBaseType() {
throw new UnsupportedOperationException();
}
@Override
public Set<Type> getTypeClosure() {
throw new UnsupportedOperationException();
}
@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
throw new UnsupportedOperationException();
}
@Override
public Set<Annotation> getAnnotations() {
throw new UnsupportedOperationException();
}
@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
throw new UnsupportedOperationException();
}
@Override
public Class<Foo> getJavaClass() {
return Foo.class;
}
@Override
public Set<AnnotatedConstructor<Foo>> getConstructors() {
throw new UnsupportedOperationException();
}
@Override
public Set<AnnotatedMethod<? super Foo>> getMethods() {
throw new UnsupportedOperationException();
}
@Override
public Set<AnnotatedField<? super Foo>> getFields() {
throw new UnsupportedOperationException();
}
};
}
@Override
public Type getBaseType() {
throw new UnsupportedOperationException();
}
@Override
public Set<Type> getTypeClosure() {
throw new UnsupportedOperationException();
}
@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
throw new UnsupportedOperationException();
}
@Override
public Set<Annotation> getAnnotations() {
return new HashSet<>(Arrays.asList(method.getAnnotations()));
}
@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
throw new UnsupportedOperationException();
}
@Override
public Method getJavaMember() {
return method;
}
};
}
use of javax.enterprise.inject.spi.AnnotatedField in project core by weld.
the class Validator method validateInjectionPointForDefinitionErrors.
/**
* Checks for definition errors associated with a given {@link InjectionPoint}
*/
public void validateInjectionPointForDefinitionErrors(InjectionPoint ij, Bean<?> bean, BeanManagerImpl beanManager) {
if (ij.getAnnotated().getAnnotation(New.class) != null && ij.getQualifiers().size() > 1) {
throw ValidatorLogger.LOG.newWithQualifiers(ij, Formats.formatAsStackTraceElement(ij));
}
if (ij.getType() instanceof TypeVariable<?>) {
throw ValidatorLogger.LOG.injectionPointWithTypeVariable(ij, Formats.formatAsStackTraceElement(ij));
}
// WELD-1739
if (ij.getMember() instanceof Executable && ij.getAnnotated().isAnnotationPresent(Named.class) && ij.getAnnotated().getAnnotation(Named.class).value().equals("")) {
Executable executable = (Executable) ij.getMember();
AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) ij.getAnnotated();
if (!executable.getParameters()[annotatedParameter.getPosition()].isNamePresent()) {
// No parameters info available
throw ValidatorLogger.LOG.nonFieldInjectionPointCannotUseNamed(ij, Formats.formatAsStackTraceElement(ij));
}
}
if (ij.getAnnotated().isAnnotationPresent(Produces.class)) {
if (bean != null) {
throw BeanLogger.LOG.injectedFieldCannotBeProducer(ij.getAnnotated(), bean);
} else {
throw BeanLogger.LOG.injectedFieldCannotBeProducer(ij.getAnnotated(), Reflections.<AnnotatedField<?>>cast(ij.getAnnotated()).getDeclaringType());
}
}
boolean newBean = (bean instanceof NewBean);
if (!newBean) {
checkScopeAnnotations(ij, beanManager.getServices().get(MetaAnnotationStore.class));
}
checkFacadeInjectionPoint(ij, Instance.class);
checkFacadeInjectionPoint(ij, Event.class);
if (InterceptionFactory.class.equals(Reflections.getRawType(ij.getType())) && !(bean instanceof ProducerMethod<?, ?>)) {
throw ValidatorLogger.LOG.invalidInterceptionFactoryInjectionPoint(ij, Formats.formatAsStackTraceElement(ij));
}
for (PlugableValidator validator : plugableValidators) {
validator.validateInjectionPointForDefinitionErrors(ij, bean, beanManager);
}
}
use of javax.enterprise.inject.spi.AnnotatedField in project deltaspike by apache.
the class BeanBuilderTest method assertNonNullInjectionPointsWhenOverriding.
@Test
public void assertNonNullInjectionPointsWhenOverriding() {
final BeanBuilder beanBuilder = new BeanBuilder(beanManager);
final AnnotatedType<?> at = beanManager.createAnnotatedType(WithInjectionPoint.class);
beanBuilder.readFromType(at);
// It's not easy to actually create these in the state we need, so we have to get the InjectionPonits,
// create new ones with the correct info, null out the bean, set them as the new injection points
// then move on.
final Set<InjectionPoint> origInjectionPoints = beanBuilder.getInjectionPoints();
beanBuilder.injectionPoints(beanBuilder.getInjectionPoints());
final Set<InjectionPoint> newInjectionPoints = new HashSet<InjectionPoint>();
for (InjectionPoint ip : origInjectionPoints) {
newInjectionPoints.add(new ImmutableInjectionPoint((AnnotatedField) ip.getAnnotated(), ip.getQualifiers(), null, ip.isTransient(), ip.isDelegate()));
}
beanBuilder.injectionPoints(newInjectionPoints);
final Bean<?> newInjectionBean = beanBuilder.create();
for (final InjectionPoint ip : newInjectionBean.getInjectionPoints()) {
Assert.assertNotNull(ip);
}
}
Aggregations