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

Copy nodes in AST

I am using javaparser to construct an AST from Java source code. Is there a way to safely copy AST nodes? For example, if I want to duplicate a BinaryExpr to insert somewhere else in the tree, is there a built-in way to copy the node?
jem
  • 130
  • 8
0
votes
1 answer

How to get binary subexpressions with javaparser

I am using javaparser to parse the AST for Java source files. I would like to get all binary subexpressions in the source code as individual nodes. Here is the source code I am parsing: class MyClass { public MyClass() { double x = (4 / 10.0)…
jem
  • 130
  • 8
0
votes
2 answers

Adding data in a text file between already existing data in Java

I need to add this is a class or this is a method in a text/java file before class name or method name (line no is available through japa). I have tried all possible cases I can, try to edit text/Java file with file reader/writer (but it always…
shrikant.sharma
  • 203
  • 1
  • 17
  • 37
0
votes
2 answers

JAVA parser for asana json data "Error:JSONObject cannot be converted to JSONArray"

I am working on java parser that parse asana json data. Now I am executing request using curl and curl use cygwin tool(Used to execute UNIX commands on windows). Now I am getting single project details in json format(that contain all tasks in…
0
votes
1 answer

JavaParser - ArrayList Doesn't Recognized Properly

Im using https://code.google.com/p/javaparser Java parser to get data from file. Problem is parser can't recognize arraylist, hashmap, map etc. When I use arraylist in file like this; public static ArrayList classList; There is no any…
Nerzid
  • 457
  • 5
  • 15
0
votes
1 answer

Unsure why this LOOKAHEAD is needed in these contexts

Here is my token table: TOKEN : { < A : "A" > | < B : "B" > | < C : "C" > } I have this code that contains 2 choice conflicts. void Start() : {} { < A> [ Bs() ] "-" < A> } void Bs() : {} { ( "-" < B> )+ } In order to remove the choice…
Ogen
  • 6,499
  • 7
  • 58
  • 124
0
votes
1 answer

Accessing Javadoc with Javaparser returns null

I'm parsing Java source files with Javaparser (javaparser-core 2.0.0) to get Javadoc comments from methods. However, I always get null When I call MethodDeclaration.getJavaDoc(). Looking at the source of MethodDeclaration, I can see why: public…
David Carboni
  • 1,556
  • 23
  • 24
0
votes
2 answers

javaparser generic method

Can I parse generic method with javaparser ?? If its possible so how? For example this is my method: public static < E > void printArray( E[] inputArray ) { // Display array elements for ( E element : inputArray ){ …
user1951618
  • 131
  • 12
0
votes
1 answer

Finding methods in a ClassOrInterface Declaration

Is there any way I can find the methods in a ClassOrInterface Declaration? I'm using javaparser to read in source code which but when I read in multiple classes I have the problem of trying to attach which methods are attached to which…
Steven
  • 93
  • 1
  • 11
0
votes
1 answer

Is it possible to preserve whitespace?

Using the javaparser library: Is there a way to print out a compilation unit and preserve whitespace? I tried the toString() method on compilationUnit but that throws away newlines. Seeing as how each ASTNode stores line and column number…
cciollaro
  • 354
  • 4
  • 10
0
votes
1 answer

How to Display the list of methods with signature in a java file using javaparser

I need to display the list of methods along with signature for a java class using javaparser. I know how to display the list of methods with out signature but not along with signature. Can any one provide some examples to get methods along with…
user3181223
0
votes
2 answers

Handling exception in Javaparser

I am trying to handle the exception produced by Javaparser library due to token error. I used the following code. String content=getTheSource(); ByteArrayInputStream bin=new ByteArrayInputStream(content.getBytes()); try { …
Masud Rahman
  • 1,064
  • 4
  • 14
  • 28
0
votes
1 answer

Google javaparser IfStmt not counting consequent

I am using Google javaparser to parse the java file, when I try to count the "If" statement, it seems like I can not get the number of "else-if" statement. For example, I want to parse the following code: if(i>1){ i++; }else if(i>2){ …
Xiansong
  • 91
  • 2
  • 8
-1
votes
0 answers

Parsing part of Java code without executing it, is there a way other then statically analysing it

I have a large scale non-compiled project developed using Java and its frameworks like Spring and Spring Boot. This project has database interaction point like JDBC's connection.prepareStatement(sql). SQL passing to .prepareStatement() can be a…
-1
votes
1 answer

Parsing methods with JavaParser

I want to parse the method check() using java parser. With getStatements() method in MethodDeclaration I can get the method. But I want to traverse the code inside the method. Is there any way to do this. I need to count the number of return…
1 2 3
12
13