Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:23:38+00:00 2026-06-13T10:23:38+00:00

I have built an annotation processor that is triggered with the com.foo.FooEntity annotation. There

  • 0

I have built an annotation processor that is triggered with the com.foo.FooEntity annotation. There is a need to be able to create more stereotypes that would trigger that annotation processor as well.

For instance, a controller should also trigger this annotation processor. I am wondering if there is a way to place the @FooEntity annotation on it. Something like:

@FooEntity
@Target(TYPE)
@Retention(RUNTIME)
public @interface Controller {}

And use this so that this class triggers annotation processing

@Controller
public class MyController { ... }

Of course, the idea here is that I want to add new stereotypes without having to touch the annotation processor itself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:23:39+00:00Added an answer on June 13, 2026 at 10:23 am

    I don’t think there is a way to configure a processor to process @FooEntity as well as annotations meta-annotated with @FooEntity (@Controller in this case). What you could do instead is have a processor that supports any annotation (@SupportedAnnotationTypes("*")) and then implement some further logic within the processor itself in order to decide which annotations you do want to process. Here is such an implementation based on my understanding of the problem:

    package acme.annotation.processing;
    
    import java.util.HashSet;
    import java.util.Set;
    
    import javax.annotation.processing.AbstractProcessor;
    import javax.annotation.processing.RoundEnvironment;
    import javax.annotation.processing.SupportedAnnotationTypes;
    import javax.lang.model.element.TypeElement;
    
    import acme.annotation.FooEntity;
    
    @SupportedAnnotationTypes("*")
    public class FooEntityExtendedProcessor extends AbstractProcessor {
    
        private void log(String msg) {
            System.out.println(msg);
        }
    
        @Override
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
            log("Initially I was asked to process:" + annotations.toString());
    
            Set<TypeElement> fooAnnotations = new HashSet<>();
            for (TypeElement elem : annotations) {
                if (isFoo(elem)) fooAnnotations.add(elem);
            }
    
            if (fooAnnotations.size() > 0) {
                log("... but I am now going to process:" + fooAnnotations.toString());
                processInternal(fooAnnotations, roundEnv);
            } else {
                log("... but none of those was my business!");
            }
    
            // always return false so that other processors get a chance to process the annotations not consumed here
            return false;
        }
    
        private void processInternal(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
            // TODO: do your foo processing here
        }
    
        private boolean isFoo(TypeElement elem) {
            if (elem.getQualifiedName().toString().equals("acme.annotation.FooEntity")
                    || elem.getAnnotation(FooEntity.class) != null) {
                return true;            
            } else {
                return false;
            }
        }
    
    }
    

    A sample run would give you:

    Initially I was asked to process:[acme.annotation.FooEntity, skriptor.annotation.ScriptArg, java.lang.Override, skriptor.annotation.ScriptCodeRT, skriptor.annotation.ScriptCode, skriptor.annotation.ScriptObject, javax.ws.rs.Path, javax.ws.rs.GET, acme.annotation.Controller, com.sun.jersey.spi.resource.Singleton, skriptor.annotation.ScriptImport, javax.ws.rs.ext.Provider, javax.ws.rs.Produces, javax.annotation.PostConstruct]
    ... but I am now going to process:[acme.annotation.Controller, acme.annotation.FooEntity]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the scenario: I have a program that contains an annotation that I built
I have built so far an application that allows the user to drag and
I have a REST web service built with Spring MVC, with annotation-based configuration and
I have a web service (built using jaxb/jaxws) that invokes a stateless EJB to
We have test classes which are built on Spring 2.0.8's AbstractTransactionalDataSourceSpringContextTests. There are a
I have some automatically generated Ant build scripts that I need to use to
I have a maven project generating a new class from an annotation processor during
I have a maven project in eclipse and have maven goals that run annotation
I have a custom annotation and it's processor & processorFactory. How do I configure
I have a Java project that is built using Maven , thus my build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.