introduce @Suppress annotation to disable processor

This commit is contained in:
Gavin King 2024-03-22 11:56:23 +01:00 committed by Christian Beikov
parent 8bc09c976a
commit 50af2eef15
4 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,29 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.annotations.processing;
import org.hibernate.Incubating;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;
/**
* Indicates that a package or top-level type should be ignored
* by the Hibernate annotation processor.
*
* @author Gavin King
* @since 6.5
*/
@Target({PACKAGE, TYPE})
@Retention(CLASS)
@Incubating
public @interface Suppress {
}

View File

@ -10,10 +10,12 @@ package org.hibernate.orm.test.annotations.onetoone;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;
import org.hibernate.annotations.processing.Suppress;
/**
* @author Emmanuel Bernard
*/
@Suppress
@Entity
public class ShowDescription {
@Id

View File

@ -279,7 +279,11 @@ public class HibernateProcessor extends AbstractProcessor {
for ( Element element : roundEnvironment.getRootElements() ) {
try {
if ( isEntityOrEmbeddable( element ) ) {
if ( hasAnnotation( element, SUPPRESS)
|| hasAnnotation( context.getElementUtils().getPackageOf(element), SUPPRESS ) ) {
// skip it completely
}
else if ( isEntityOrEmbeddable( element ) ) {
context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated entity class '" + element + "'" );
handleRootElementAnnotationMirrors( element );
}

View File

@ -61,6 +61,7 @@ public final class Constants {
public static final String SQL = "org.hibernate.annotations.processing.SQL";
public static final String FIND = "org.hibernate.annotations.processing.Find";
public static final String PATTERN = "org.hibernate.annotations.processing.Pattern";
public static final String SUPPRESS = "org.hibernate.annotations.processing.Suppress";
public static final String JD_REPOSITORY = "jakarta.data.repository.Repository";
public static final String JD_QUERY = "jakarta.data.repository.Query";