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
1
vote
1 answer

How to change Object Type in JavaParser

I'm using JavaParser. For example, I'm having below method void checkCall() { Blabla.test(); } Blabla.test(); is a static call. I want to change Blabla.test() to ABCD.test() without changing any other. I got Blabla from…
RAM NATHAN
  • 19
  • 3
1
vote
1 answer

How to parse java method body?

I want to parse java source files (.java) in order to identify methods, in a class, that contain calls to a specific method. In the below example, I need to know which methods contain a call to xyz(). So, the parser should return method01 and…
Tony P
  • 211
  • 5
  • 12
1
vote
2 answers

Getting names of inherited classes in JavaParser

In my example I have something like this: public class Example extends Random, Math {...} Using JavaParser I want to get the names of classes that are after 'extends' keyword. How can I do it? On the site of JavaParser I have found something…
mexicoman
  • 23
  • 6
1
vote
2 answers

Combine Java parser in custom parser for expressions

I'm trying to create a custom domain specific language for creating HTML templates using java expressions statements. For instance it should parse tags combined with java statements:
if (someValue == true) { "someValue was…
Tim
  • 5,521
  • 8
  • 36
  • 69
1
vote
1 answer

How to infer the types of all the parameters of a function using java-parser and java-symbol-solver?

Suppose I have the following Class A in pkg1 and a Class B in pkg2 and function calculate() is defined in pkg2 class B as follows: B.calculate(A a1, A a2); I want to identify the the type of parameters a1 and a2. For instance, here it will be…
AmeyaKetkar
  • 117
  • 1
  • 9
1
vote
1 answer

How to create a new object as an AST node using JavaParser?

I would like to add the following statement to my AST using JavaParser. I already read the manual and I know how to do simple examples. However, I could not find anything related to creating new objects. I am wondering if anyone could help me with…
media
  • 433
  • 5
  • 19
1
vote
1 answer

Identify Variables used in a Statement/Line

Given a method I would like to identify unused variables. The format that I am currently looking at guarantees that there's an assert statement as the very last line of every method. I am using JavaParser to parse each method, list the statements…
waylonion
  • 6,866
  • 8
  • 51
  • 92
1
vote
1 answer

javaparser - Lexical error Encountered: after : ""

I am using this javaparser https://github.com/javaparser/javaparser to parse a lot of java source codes of some github users to make some statistics from them (this is for a university project). Everything seems to work fine, but at some point, a…
user6199298
1
vote
2 answers

Java parser library for NetBeans

I want to make a java application that takes java source codes as input to create and visit their Abstract Syntax Trees, so I can make some statistics out of them. I found this java parser: https://github.com/javaparser/javaparser My questions…
user6199298
1
vote
1 answer

Parse String to get grouped parameters

My String looks like this http://localhost:8080/HospitalServer/files/file?id=34&firstname=alex&lastname=ozouf&age=33&firstname=kevin&lastname=gerfild&age=27 I use this code to parse the parameters final Map> query_pairs = new…
user3235881
  • 487
  • 2
  • 9
  • 24
1
vote
1 answer

Javaparser AST variable declaration

How to get all static final declaration information with line number inside a class using JavaParser. Example public class demo { private static final int x; private static final int y; private static final int z; // some code } Ouput…
rahul b
  • 21
  • 3
1
vote
1 answer

Check duplicate variable in a method scope Java

I read java file using FileReader that contains some method. How i can read method scope (method area inside) to find duplicate variable? For example, this is a java file that i read: public double[] copyArray(double[] data) { int _nn =…
Samsul Arifin
  • 247
  • 1
  • 6
  • 24
1
vote
0 answers

How can I find all for-loops in a Java file using javaparser?

I am using javaparser to parse a Java file and I would like to find all occurrences of for loops (forEach & normal for loops). This is my approach so far, but it only finds some, not all occurrences. public class AstElementTraverser extends…
Daniel Schmidt
  • 11,605
  • 5
  • 38
  • 70
1
vote
1 answer

JavaParser - Get typed AST

I want to get typed AST from JavaParser or another parser of Java code. It means I would be able to get the type for a specific variable or parameters+returning type of a method. I googled a lot about this feature of JavaParser, but didn't find…
ivan
  • 287
  • 3
  • 14
1
vote
1 answer

Javaparser add new field to class

I would like to add a new field of type List to every existing field in a class. I would also like it to be initialized with an empty ArrayList. How can I create the appropriate FieldDeclaration object to add to list of BodyDeclaration in the…
Bite
  • 23
  • 4