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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:10:49+00:00 2026-06-14T22:10:49+00:00

JavaParser is a java source code parsing tool. I read the documents but found

  • 0

JavaParser is a java source code parsing tool. I read the documents but found it only able to parse source of a full java class, like:

public class X {
    public void show(String id) {
        Question q = Quesiton.findById(id);
        aaa.BBB.render(q);
    }
}

But I want to parse only part of it, e.g. the method declaration:

public void show(String id) {
    Question q = Quesiton.findById(id);
    aaa.BBB.render(q);
}

How to do it or is it possible? If not, is there any other tool can do this?


Update

Actually I want to parse any valid expression in java, so I can do this easily with JavaParser:

CompilationUnit unit = JavaParser.parse(codeInputStream);

addField(unit, parseField("public String name"));  // not possible now
  • 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-14T22:10:51+00:00Added an answer on June 14, 2026 at 10:10 pm

    I see you can include the method in a dummy class and parse it as usual. For the example you provided, enclose it inside:

    public class DUMMY_CLASS_FOO {
    
        // The string you're trying to parse (method or whatever)
    
    }
    

    Then you parse it as usual and neglect your dummy class while parsing.

    UPDATE:

    For the update you provided, you may try and catch

    If the previous enclosure didn’t do it, so enclose it into:

    public class DUMMY_CLASS_FOO {
    
        public void DUMMY_METHOD_FOO {
    
            // Anything here
    
        }
    }
    

    You might also search for Access Level Modifiers (public, private, …etc), and if found, do the 1st solution. If not found, do the other one.

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

Sidebar

Related Questions

I am looking for a Java source code parser and came across JavaParser, however
I'm parsing a lot of .java-files with the latest JavaParser . Files are parsed
I'm parsing Java source files and I need to extract type information to guess
I'm trying to analyze Java source files with Clojure but I couldn't find a
I want to parse java code using java. problem is , when I pass
The scalac Java parser is taking objection to my Java code imported `Entity' is
I am using Java Parser to get information about the method in a source
ANTLR generates java source from the grammar file. Generated source has dependency to ANTLR
I am writing a java code analyzing snippet which will find out the use
I am trying to parse a giant (> 1GB) xml file using Java's XMLStreamReader.

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.