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

  • Home
  • SEARCH
  • 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 505477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:36:10+00:00 2026-05-13T06:36:10+00:00

I experiment with java annotation processors and try to understand the usage of the

  • 0

I experiment with java annotation processors and try to understand the usage of the classes in “javax.lang.model”. For what I have read I think the ElementVisitor is to be intended as the primary way to work with the model. But I don’t understand how to use it properly.

I knew the visitor pattern. Up to now I’ve used it to avoid iterating over the children of an element (and the children of the children …) and avoiding ugly “instanceof” tests. But this visitor seems to be different. If I call “accept” on an model element it doesn’t visit the children but only the element itself.

Could someone provide assistance on how to make use of the API?

I’ve found the following link: http://www.cs.bgu.ac.il/~gwiener/programming/visitors-galore/#more-113 . But using one visitor inside the other inside the other … just feel not right!?

Edit: To make it easier to understand the question I copy the code from the link above. The following code doesn’t seem to be “right”. I can’t believe that an official java API is designed in this way. But how to use the ElementVisitor properly?

tElem.accept(new SimpleElementVisitor6<Void, ...>() {
  public Void visitType(TypeElement e, ...) {
    for (Element tSubElem : e.getEnclosedElements()) {
      tSubElem.accept(new SimpleElementVisitor6<AssocEndSpec, ...>() {
        public AssocEndSpec visitExecutable(ExecutableElement ex, ...) {
          TypeMirror tRetTypeMirror = ex.getReturnType();
          tRetTypeMirror.accept(new SimpleTypeVisitor6<TypeElement, TypeElement>() {
            public TypeElement visitDeclared(DeclaredType t, TypeElement enclose) {
              for (TypeMirror tTypeArgMirror : t.getTypeArguments()) {
                tTypeArgMirror.accept(new SimpleTypeVisitor6<TypeElement, ...>() {
                  public TypeElement visitDeclared(DeclaredType t, TypeElement self) {
                    TypeElement tArgTypeElem = (TypeElement) t.asElement();
                    if (!self.equals(tArgTypeElem)) {
                      // found the little bugger!
                    }
                  }
                }, ...);
              }
            }
          }, ...);
        }
    }, ...);
  }
}, ...);
  • 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-05-13T06:36:10+00:00Added an answer on May 13, 2026 at 6:36 am

    This code is bollocks.

    Take a look at javax.lang.model.util.ElementKindVisitor6 or javax.lang.model.util.ElementScanner6, they might do what. In any case, you should be able to take their sources and adapt them to your needs.

     

    NB: that being said, yes I’d say too that ElementVisitor is a rather strange implementation of a visitor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 249k
  • Answers 249k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Completely reset? Delete the .git directory locally. Recreate the git… May 13, 2026 at 9:03 am
  • Editorial Team
    Editorial Team added an answer Alignment helps the CPU fetch data from memory in an… May 13, 2026 at 9:03 am
  • Editorial Team
    Editorial Team added an answer From the root threadgroup, you can have the Thread class… May 13, 2026 at 9:03 am

Related Questions

I am designing a psychology experiment with java applets. I have to make my
I have been researching and playing with functional programming lately, solely to broaden my
I am writing code in Java where I branch off based on whether a
I'd like to set up a cheap Linux box as a web server to
I'm trying to experiment with OracleHelp for Java on my Windows Vista server. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.