io.micronaut.inject.ast.Element Maven / Gradle / Ivy
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (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.0
*
* 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 io.micronaut.inject.ast;
import io.micronaut.core.annotation.AnnotatedElement;
import io.micronaut.core.annotation.AnnotationMetadataDelegate;
import io.micronaut.core.annotation.AnnotationValueBuilder;
import io.micronaut.core.util.ArgumentUtils;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.lang.annotation.Annotation;
import java.util.Optional;
import java.util.function.Consumer;
/**
* Stores data about a compile time element. The underlying object can be a class, field, or method.
*
* @author James Kleeh
* @since 1.0
*/
public interface Element extends AnnotationMetadataDelegate, AnnotatedElement {
/**
* @return The name of the element.
*/
@Override
@NonNull String getName();
/**
* @return True if the element is protected.
*/
boolean isProtected();
/**
* @return True if the element is public.
*/
boolean isPublic();
/**
* Returns the native underlying type. This API is extended by all of the inject language implementations.
* The object returned by this method will be the language native type the information is being retrieved from.
*
* @return The native type
*/
@NonNull Object getNativeType();
/**
* Annotate this element with the given annotation type. If the annotation is already present then
* any values populated by the builder will be merged/overridden with the existing values.
*
* @param annotationType The annotation type
* @param consumer A function that receives the {@link AnnotationValueBuilder}
* @param The annotation generic type
* @return This element
*/
@NonNull
default Element annotate(@NonNull String annotationType, @NonNull Consumer> consumer) {
throw new UnsupportedOperationException("Element of type [" + getClass() + "] does not support adding annotations at compilation time");
}
/**
* Annotate this element with the given annotation type. If the annotation is already present then
* any values populated by the builder will be merged/overridden with the existing values.
*
* @param annotationType The annotation type
* @param The annotation generic type
* @return This element
*/
@NonNull
default Element annotate(@NonNull String annotationType) {
return annotate(annotationType, (Consumer>) annotationValueBuilder -> { });
}
/**
* Annotate this element with the given annotation type. If the annotation is already present then
* any values populated by the builder will be merged/overridden with the existing values.
*
* @param annotationType The annotation type
* @param consumer A function that receives the {@link AnnotationValueBuilder}
* @param The annotation generic type
* @return The {@link AnnotationValueBuilder}
*/
@NonNull
default Element annotate(@NonNull Class annotationType, @NonNull Consumer> consumer) {
ArgumentUtils.requireNonNull("annotationType", annotationType);
ArgumentUtils.requireNonNull("consumer", consumer);
return annotate(annotationType.getName(), consumer);
}
/**
* Annotate this element with the given annotation type. If the annotation is already present then
* any values populated by the builder will be merged/overridden with the existing values.
*
* @param annotationType The annotation type
* @param The annotation generic type
* @return The {@link AnnotationValueBuilder}
*/
@NonNull
default Element annotate(@NonNull Class annotationType) {
ArgumentUtils.requireNonNull("annotationType", annotationType);
return annotate(annotationType.getName(), annotationValueBuilder -> { });
}
/**
* The simple name of the element. For a class this will be the name without the package.
*
* @return The simple name
*/
default @NonNull String getSimpleName() {
return getName();
}
/**
* @return True if the element is abstract.
*/
default boolean isAbstract() {
return false;
}
/**
* @return True if the element is static.
*/
default boolean isStatic() {
return false;
}
/**
* @return The documentation, if any.
*/
default Optional getDocumentation() {
return Optional.empty();
}
/**
* @return True if the element is private.
*/
default boolean isPrivate() {
return !isPublic();
}
/**
* @return True if the element is final.
*/
default boolean isFinal() {
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy