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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:08:00+00:00 2026-05-13T20:08:00+00:00

We have a need to generate Java source code. We do this by modeling

  • 0

We have a need to generate Java source code. We do this by modeling the abstract syntax tree and have a tree walker that generate the actual source code text. This far all good.

Since my AST code is a bit old, it does not have support for annotations and generics. So I’m looking around for open projects to use for future projects with code generation needs. And this is where the actual issue comes. We want to test that the code generated has the correct behavior.

Here is where I got the idea to actually evaluate the AST instead of generating the java source code, compile it, and run tests against that code. An evaluator would speed up the unit tests, and one could evaluate smaller pieces of generated code, such as only a method, making the “units” more reasonable.

So far i have found the com.sun.codemodel project that seems quite nice as for being a modern (support for java5 and 6 features) AST based code-generating solution.

Anyone know if there is another project that would allow me to evaluate pieces of AST directly (such as a single generated method)?

  • 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-13T20:08:00+00:00Added an answer on May 13, 2026 at 8:08 pm

    To evaluate Java, you need all the semantic analysis that goes along with it (“what is the scope of this identifier? What type does it have?”) as well as an interpreter.

    To get that semantic analysis, you need more than just an AST: you need full name resolution (symbol table building) and type resolution (determination of expression types and validation that expressions are valid in the context in which they are found),
    as well as class lookup (which actual method does foo refer to?)

    With that, you can consider building an interpreter by crawling over the trees in execution order. You’ll also need to build a storage manager; you might not need to do a full garbage collector, but you’ll need something. You’ll also need an interpreter
    for .class files if you really want to run something, which means you need a parser
    (and name/type resolution for the class files, too).

    I don’t know if Eclipse has all this (at least the storage manager part you can get for free :). I’d sort of expect it to, given that its original design was to support Java development, but I’ve been sorely disappointed by lots of tools over the years.

    The DMS Software Reengineering Toolkit is a program analysis/transformation too that handles many languages. It has a full Java front end including parsing, AST building, symbol table construction and name resolution, type resolution, builds call graphs (needed to resolve virtual function calls), and has a .class file reader to boot with name resolution. So it would be a good foundation for building an interpreter.

    DMS can construct arbitrary ASTs, too, and then generate source code from them, so it would handle the code generation end, too, just fine.

    [The reason DMS exists is the “sorely disappointed” part].

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

Sidebar

Related Questions

I need a tool to generate a control flow graph from java source code.
Like my question, i need to generate random numbers that have identical pairs between
I have an NSIS based installer that I need to be able generate slightly
I have some Java code that validates XML against an XSD. I am using
I have document source in XML. I need to generate PDF and HTML pages
I have an html file and i need to generate a list of all
I have a situation where I need to generate a few similar anonymous delegates.
I have an WSDL / Web Service and I need to generate an set
I have a dictionary dict1['a'] = [ [1,2], [3,4] ] and need to generate
I have the following requirement: Based on some user input, I need to generate

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.