GH-522 - Support for package info types.

Introduce @PackageInfo annotation to allow marking a types as alternative to Java's native package-info.java so that annotation lookups on a JavaPackage will also find annotations placed on that type. Useful to declare package scoped metadata like @ApplicationModule and @NamedInterface for languages that do not support packages well enough (read: Kotlin).
This commit is contained in:
Oliver Drotbohm
2024-03-05 08:35:45 +01:00
parent f3c111f769
commit 5f7e6a2479
21 changed files with 461 additions and 66 deletions

View File

@@ -25,7 +25,8 @@ import java.lang.annotation.Target;
*
* @author Oliver Drotbohm
*/
@Target({ ElementType.PACKAGE, ElementType.ANNOTATION_TYPE })
@PackageInfo
@Target({ ElementType.PACKAGE, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface ApplicationModule {

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2024 the original author or 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
*
* https://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 org.springframework.modulith;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to mark a type as an alternative to Java's native {@code package-info.java}. Classes annotated like
* this will be considered, too, when looking up annotations on a package.
*
* @author Oliver Drotbohm
* @since 1.2
*/
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface PackageInfo {}