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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:57:58+00:00 2026-06-02T05:57:58+00:00

I am currently working with eclipse AST to generate source code. Other than in

  • 0

I am currently working with eclipse AST to generate source code. Other than in most examples, I am generating the source code from scratch and in a stand-alone application, as opposed to an eclipse plug-in.

When read in from an ASTParser, you can activate modifications by calling recordModifications(), but this doesn’t work when the AST is created from scratch, e.g. by calling newCompilationUnit().

Consequently, writing the source to file via a Document and TextEdit is not possible – there is an exception saying that modification recording hasn’t been enabled.
Any experiences in generating AST from scratch and writing to file?
Thanks!

  • 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-02T05:58:00+00:00Added an answer on June 2, 2026 at 5:58 am

    Why not create the file first, then generate an AST from it, like this:

    ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setResolveBindings(true);
    parser.setSource(unit);
    // Parse the source code and generate an AST.
    CompilationUnit ast = (CompilationUnit) parser.createAST(null);
    

    If the file is newly created and blank, then presumably the AST will be empty, You can then replace the root of the ast object and write it to the file. Also, if you are not tied to Eclipse, you could just do the same thing using the JSR199 standard and write that AST to a file in the normal way. See here for an introduction.

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

Sidebar

Related Questions

I'm currently working on a plug-in for Eclipse that translates some custom Java code
I'm currently experiencing a problem with 'hot code replace' not working on Eclipse Galileo
I'm currently working on a project that contains many different Eclipse projects referencing each
Currently, I have a machine on which I am working in Eclipse, it says
I reference another eclipse project from the current project I am working on. Everything
i'm currently working on a Eclipse RCP Project. I have a Plugin Fragment where
I'm currently working on a school project in Eclipse (We have just started using
I'm currently working on some concurrent code that would appear to have a few
I am currently working in a .Net project but from university I have also
I am running Eclipse Galileo with Tomcat 6.0.18. Currently, I have a working application

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.