Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Annotations and add AnnotationBuilder #508

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package jakarta.enterprise.inject.build.compatible.spi;

import jakarta.enterprise.inject.spi.Prioritized;
import jakarta.enterprise.lang.model.declarations.ClassInfo;

import java.lang.annotation.Annotation;

/**
* Service provider interface that supports creating {@link AnnotationBuilder}.
* Should not be called directly by users; the static methods on {@link AnnotationBuilder} are preferred.
*/
public interface AnnotationBuilderFactory extends Prioritized {
/**
* Returns a new {@link AnnotationBuilder} for given annotation type.
*
* @param annotationType the annotation type
* @return a new {@link AnnotationBuilder}
*/
AnnotationBuilder create(Class<? extends Annotation> annotationType);
Ladicek marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns a new {@link AnnotationBuilder} for given annotation type.
*
* @param annotationType the annotation type
* @return a new {@link AnnotationBuilder}
*/
AnnotationBuilder create(ClassInfo<?> annotationType);
Ladicek marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package jakarta.enterprise.inject.build.compatible.spi;

import java.util.Collections;
import java.util.Comparator;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.TreeSet;

final class AnnotationBuilderFactoryResolver {
private static final Object lock = new Object();
private static volatile Set<AnnotationBuilderFactory> discoveredFactories;
private static volatile AnnotationBuilderFactory configuredFactory;

static AnnotationBuilderFactory get() {
if (configuredFactory != null) {
return configuredFactory;
}

if (discoveredFactories == null) {
synchronized (lock) {
if (discoveredFactories == null) {
discoverFactories();
}
}
}

configuredFactory = discoveredFactories.iterator().next();

return configuredFactory;
}

private static void discoverFactories() {
Set<AnnotationBuilderFactory> factories = new TreeSet<>(
Comparator.comparingInt(AnnotationBuilderFactory::getPriority).reversed());

ServiceLoader<AnnotationBuilderFactory> loader = SecurityActions.loadService(
AnnotationBuilderFactory.class, AnnotationBuilderFactoryResolver.class.getClassLoader());

if (!loader.iterator().hasNext()) {
throw new IllegalStateException("Unable to locate AnnotationBuilderFactory implementation");
}

try {
for (AnnotationBuilderFactory factory : loader) {
factories.add(factory);
}
} catch (ServiceConfigurationError e) {
throw new IllegalStateException(e);
}

AnnotationBuilderFactoryResolver.discoveredFactories = Collections.unmodifiableSet(factories);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package jakarta.enterprise.inject.build.compatible.spi;

import jakarta.enterprise.lang.model.AnnotationMember;
import jakarta.enterprise.lang.model.AnnotationInfo;
import jakarta.enterprise.lang.model.declarations.ClassInfo;

import java.lang.annotation.Annotation;
import java.util.function.Predicate;

// TODO better name?
// TODO devise a builder-style API instead (see also Annotations)
public interface AnnotationConfig {
void addAnnotation(Class<? extends Annotation> annotationType, AnnotationMember... attributes);

void addAnnotation(ClassInfo<?> annotationType, AnnotationMember... attributes);
void addAnnotation(Class<? extends Annotation> annotationType); // for marker annotations

void addAnnotation(AnnotationInfo annotation);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
* You can also declare a parameter of type {@link Messages Messages} to produce log messages and validation errors.
* <p>
* If you need to create instances of {@link jakarta.enterprise.lang.model.types.Type Type}, you can also declare
* a parameter of type {@link Types Types}. It provides factory methods for the void type, primitive types,
* a parameter of type {@link Types}. It provides factory methods for the void type, primitive types,
* class types, array types, parameterized types and wildcard types.
* <p>
* If you need to create instances of {@link jakarta.enterprise.lang.model.AnnotationMember AnnotationAttribute} or
* {@link jakarta.enterprise.lang.model.AnnotationMemberValue AnnotationAttributeValue}, you can also declare
* a parameter of type {@link Annotations Annotations}. It provides factory methods for all kinds of annotation attributes.
* If you need to create instances of {@link jakarta.enterprise.lang.model.AnnotationInfo AnnotationInfo},
* use {@link AnnotationBuilder}.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public interface MetaAnnotations {

/**
* Registers custom context as configured by the returned {@link ContextConfig}.
*
* @return custom context configurator, never {@code null}
*/
ContextConfig addContext();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@

public interface ScopeInfo {
/**
* @return declaration of the scope annotation
* Returns the declaration of this scope annotation's type.
*
* @return declaration of this scope annotation's type, never {@code null}
*/
ClassInfo<?> annotation();

/**
* Binary name of this scope annotation's type, as defined by <cite>The Java&trade; Language Specification</cite>;
* in other words, the scope annotation type name as returned by {@link Class#getName()}.
* Equivalent to {@code annotation().name()}.
*
* @return fully qualified name of the annotation
* @return binary name of this scope annotation's type, never {@code null}
*/
default String name() {
return annotation().name();
}

/**
* Returns whether the scope is normal. In other words, returns whether
* the scope annotation type is meta-annotated with {@code @NormalScope}.
* the scope annotation type is meta-annotated {@code @NormalScope}.
*
* @return whether the scope is normal
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2018, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.1-SNAPSHOT (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.1-SNAPSHOT
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package jakarta.enterprise.inject.build.compatible.spi;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ServiceLoader;

/**
* This utility class is used to optimize invocation made through the SecurityManager
*
* @author Antoine Sabot-durand
*/

final class SecurityActions {
private SecurityActions() {
}

static <T> ServiceLoader<T> loadService(Class<T> service, ClassLoader classLoader) {
return AccessController.doPrivileged(
(PrivilegedAction<ServiceLoader<T>>) () -> ServiceLoader.load(service, classLoader)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package jakarta.enterprise.inject.build.compatible.spi;

import jakarta.enterprise.lang.model.AnnotationMember;
import jakarta.enterprise.lang.model.AnnotationInfo;
import jakarta.enterprise.lang.model.declarations.ClassInfo;
import jakarta.enterprise.lang.model.types.Type;

import java.lang.annotation.Annotation;

/**
Expand All @@ -25,11 +25,9 @@ public interface SyntheticBeanBuilder<T> {

// can be called multiple times and is additive
// TODO methods to add multiple qualifiers at once?
SyntheticBeanBuilder<T> qualifier(Class<? extends Annotation> qualifierAnnotation, AnnotationMember... attributes);

SyntheticBeanBuilder<T> qualifier(ClassInfo<?> qualifierAnnotation, AnnotationMember... attributes);
SyntheticBeanBuilder<T> qualifier(Class<? extends Annotation> annotationType); // for marker annotations

SyntheticBeanBuilder<T> qualifier(AnnotationInfo qualifierAnnotation);
SyntheticBeanBuilder<T> qualifier(AnnotationInfo<?> qualifierAnnotation);

SyntheticBeanBuilder<T> qualifier(Annotation qualifierAnnotation);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package jakarta.enterprise.inject.build.compatible.spi;

import jakarta.enterprise.lang.model.AnnotationMember;
import jakarta.enterprise.event.Reception;
import jakarta.enterprise.event.TransactionPhase;
import jakarta.enterprise.lang.model.AnnotationInfo;
import jakarta.enterprise.lang.model.declarations.ClassInfo;
import jakarta.enterprise.lang.model.types.Type;

import java.lang.annotation.Annotation;
import jakarta.enterprise.event.Reception;
import jakarta.enterprise.event.TransactionPhase;

/**
* Instances are not reusable. For each synthetic observer, new instance
Expand Down Expand Up @@ -40,11 +40,9 @@ public interface SyntheticObserverBuilder {

// can be called multiple times and is additive
// TODO methods to add multiple qualifiers at once?
SyntheticObserverBuilder qualifier(Class<? extends Annotation> qualifierAnnotation, AnnotationMember... attributes);

SyntheticObserverBuilder qualifier(ClassInfo<?> qualifierAnnotation, AnnotationMember... attributes);
SyntheticObserverBuilder qualifier(Class<? extends Annotation> annotationType); // for marker annotations

SyntheticObserverBuilder qualifier(AnnotationInfo qualifierAnnotation);
SyntheticObserverBuilder qualifier(AnnotationInfo<?> qualifierAnnotation);

SyntheticObserverBuilder qualifier(Annotation qualifierAnnotation);

Expand Down
Loading