Questions tagged [javaparser]

A Java Parser with AST (abstract syntax tree) generation and visitor support.

Javaparser is a Java 1.0..9 Parser with AST (abstract syntax tree) generation and visitor support. The AST records the source code structure, javadoc and comments. It is also possible to change the AST nodes or create new ones to modify the source code.

Main features

  • lightweight
  • good performance
  • easy to use
  • lexical preservation
  • AST can be modified
  • AST can be created from scratch
  • comments support
192 questions
0
votes
1 answer

Serialize Javaparser objects with Jackson Json

I'm trying to serialize Javaparser objects with Jackson JSON, but it's pretty complicated as it is a third party library (I can't change/annotate the code) and there are circular dependencies within it. My project is structured as such : An object…
Lodart
  • 23
  • 5
0
votes
1 answer

Calculate total number of if-else clauses(including nested)

Need to calculate the number of if-else clauses. I'm using java parser to do it. What I've done till now: I've obtained the count of all if and else-if clauses by using the function node.getChildNodesByType(IfStmt.class)) Problem: How do I count…
xmacz
  • 394
  • 1
  • 5
  • 14
0
votes
0 answers

Can JavaParser recognize the feed to BufferedReader?

After calling the JavaParser, I want to visit/select all the BufferedReader objects that reads from Sockets or ServerSocket. The problem is that the object of BufferedReader is not defined directly from it, instead the declaration of…
S. Nabil
  • 319
  • 1
  • 10
0
votes
1 answer

java source parsing, finding method signatures with complete types

I am using javaparser (https://github.com/javaparser/javaparser) and javasymbolsolver (https://github.com/javaparser/javasymbolsolver). to parse java source code. I am looking to create a basic report from a .java file to list the method…
Steve Renyolds
  • 1,341
  • 2
  • 9
  • 10
0
votes
1 answer

JavaParser extracting annotation parameter value

I'm working on a project to parse jersey based annotations to build an request interaction graph between projects from java source code. It's easy to parse and get info when everythink like that @GET @Path("/parameter/{param}") public Response…
Tugrul
  • 1,760
  • 4
  • 24
  • 39
0
votes
2 answers

How to extract the boolean value of the branch decision?

I am currently working on a project in which I need to run JUnit test cases and then extract information from the Target Class (class being tested). To extract the statements covered I have used eclEmma, but using this tool I am only able to extract…
0
votes
1 answer

Javaparser method editing

Let's say I have a method: void method() { int i = 5; } I want to insert a statement at the very beginning of that method, between { and int i = 5;. How do I do that with javaparser? When visiting methods, ASTHelper.addStmt(..) inserts the…
tomwyn
  • 65
  • 1
  • 7
0
votes
1 answer

JavaParser comparison

I am playing with JavaParser and I am looking for a way to filter all System.out.println(); I am able to do it with the following methods public class SystemOutFilter extends ModifierVisitorAdapter{ @Override public Node…
0
votes
1 answer

Adding a String field to a new compilationUnit with JavaParser

This might be a stupid question, but i want to acchive what the subject states. I want to add a new String field to a newly declared classOrInterfaceobject in a new new compilationUnit. But from what i can tell from the sourcefiles, that option is…
SwissArmyKnife
  • 200
  • 1
  • 12
0
votes
1 answer

JavaParser: Where is the Java grammar definition?

Where can I get the BNF-style Java 1.8 grammar that JavaParser is actually using to parse Java code? There's a java_1_8.jj file in JavaParser's codebase automatically generated by javacc, but no sight of the grammar file used to generate this .jj…
Harry
  • 3,684
  • 6
  • 39
  • 48
0
votes
2 answers

JavaParser: Constructor ParseException(String) is undefined

in another thread about JavaParser you wrote: "it should not have any dependency". But JavaParser has a dependency to a special ParseException: In JavaParser, line 205: throw new ParseException(ioe.getMessage()) The constructor…
Fifi
  • 13
  • 6
0
votes
0 answers

File Parsing in java SQLite

I want to parse a file and store reference of each bible verse. file format is: 1:1 In the beginning God created the heaven and the earth. 1:2 And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of…
Abdus Salam
  • 11
  • 10
0
votes
1 answer

Javaparser AST pattern match

I need to do some operations on the AST produced by the java parser. My problem is I want to check a class initialization cycle problem is there or not. One example is, class mark1 { public static final int x = mark2.p * 5; //Do some operations…
0
votes
2 answers

JavaParser only showing comment, not JavaDoc

Disclaimer: I am only a lowly trainee, so please forgive me if I made elementary mistakes :( I am writing an automatic API generator, and the classes need JavaDoc as well as comments because some of the values the API contains shouldn't be written…
Alex Eggers
  • 328
  • 3
  • 16
0
votes
1 answer

Javaparser: Curly braces for one-line blocks?

I am using Javaparser to parse/write source code. I noticed that if I create an IfStmt with a one-line thenStmt, then the toString method does not use curly braces to enclose the block. This makes the output source code hard to read because…
jem
  • 130
  • 8