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 7769265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:06:59+00:00 2026-06-01T16:06:59+00:00

Can anyone provide me with a code snippet of a simple java annotation processor

  • 0

Can anyone provide me with a code snippet of a simple java annotation processor that just prints “foo” when its process method is called. I’ve been working at this for 2 days and I haven’t been able to get that far

here is my code:


public class ComplexityProcessor extends AbstractProcessor {

    public ComplexityProcessor() {
        super();
    }

    @Override
    public boolean process(Set annotations,
                           RoundEnvironment roundEnv) {
        String message = "annotation found in ";
        processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.NOTE, message);

        try {
            JavaFileObject jfo = processingEnv.getFiler().createSourceFile("Foo");
            BufferedWriter bw = new BufferedWriter(jfo.openWriter());
            bw.append("Bar!!!");
            bw.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        for (Element elem : roundEnv.getElementsAnnotatedWith(Complexity.class)) {
            Complexity complexity = elem.getAnnotation(Complexity.class);
            message = "annotation found in " + elem.getSimpleName()
                           + " with complexity " + complexity.value();
            processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.NOTE, message);
            try {
                JavaFileObject jfo = processingEnv.getFiler().createSourceFile("Foo");
                BufferedWriter bw = new BufferedWriter(jfo.openWriter());
                bw.append("Bar!!!");
                bw.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
        return true; // no further processing of this annotation type
    }
  • 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-01T16:07:00+00:00Added an answer on June 1, 2026 at 4:07 pm

    I have discovered the answer

    So what you need for the future:

    1. A jar with the annotation processor and any mentioned annotations, so that you won’t have a problem with the classpath
    2. A text file in META-INF/services/processor file with the name of the processor class. This also goes in the jar above where my processor is
    3. Compile using the javac -processor argument. This was what I was looking for that was not mentioned on the 3 or 4 tutorials I was initially using
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully this is a simple one, but can anyone provide some simple c# code
Can anyone provide a Code Snippet, Tutorial link or information on how to create
I need to provide a code snippet to my clients that they can add
Can anyone provide some pseudo code for a roulette selection function? How would I
Can anyone please provide me with an example that can help me to understand
Can anyone provide me with a web link that shows a correct approach of
I'm using the code provided below to display time and date. can anyone help
Can anyone provide some real examples as to how best to keep script files
Can anyone provide a clear explanation / example of what these functions do, and
Can anyone provide me with a link to good article about using Firebird.NET with

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.