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
2
votes
1 answer

JavaParser: Detect if FieldDeclaration is Interface Type

I am gathering class metadata using JavaParser to store in a JSON object. For each compilation unit I collect, I also collect a list of the FieldDeclarations. For each FieldDeclaration, I would like to see if the type is an interface type. In the…
omri
  • 352
  • 2
  • 18
2
votes
0 answers

JavaParser - analyze and generate code for whole spring boot maven project

I am trying to accomplish code generation and analysis of my entire spring boot maven application. What I want to achieve is Just like IDEA analyzes the whole project and find dependencies for a class in the editor ie if a class is using: class…
user1539343
  • 1,569
  • 6
  • 28
  • 45
2
votes
1 answer

JavaParser: parsing and generating Java code

I have read the JavaParser manual and started to build my own examples. What I intend to achieve, is to read Java code and insert new lines of code on it. Specifically, I want to initialise a counter before every if and while statement, and inside…
John Stef
  • 585
  • 1
  • 4
  • 16
2
votes
1 answer

JavaParser: get field name from FieldDeclaration

I've built up a list of FieldDeclarations and need to find out what the name of each field is: List fields = classDeclaration.getFields(); for (FieldDeclaration field : fields) { String fieldName = field.get...? } I can't…
algorhythm
  • 3,304
  • 6
  • 36
  • 56
2
votes
0 answers

Unsolved method call expression reference in case of enum statements

I'm facing a problem when trying to solve a method call expression which reference a declaration in a enum statement. Following, I leave a detail of my code. public enum EscapeMode { ... some code ... EscapeMode(String file, int size) { …
2
votes
1 answer

JavaParser: How to retrieve all ParentNode names from MethodDeclaration?

I am using JavaParser library (https://github.com/javaparser/javaparser) for parsing Java method declarations. I want to identify different method declarations from different packages, classes, scopes, etc. so that I can precisely identify every…
arnobpl
  • 1,126
  • 4
  • 16
  • 32
2
votes
1 answer

JavaSymbolSolver: get field's fully qualified name

I use JavaParser (from javaparser.org) and javasymbolsolver to parse Java. I have a simple Java source that accesses File.separator (see the multi-line string in the source); I want my program to print java.io.File.fileseparator. Instead, it prints…
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
2
votes
1 answer

How to differentiate between two methods in MethodCallExpr in a method?

public class A{ void methodA(){ add(1, 2); add(1.2, 2.5); } void add(int a, int b){ // add two integers } void add(double a, double b){ // add two double numbers } } Now I have used below…
2
votes
2 answers

How to include JavaParser Dependencies with Maven?

I read the official http://javaparser.org/ page but I don't know how to install it. I saw this answer https://stackoverflow.com/a/32215185/7643663 that told me to easily create a project using Maven and including among the dependencies…
AIpeter
  • 868
  • 1
  • 7
  • 17
2
votes
1 answer

javaparser UnsolvedSymbolException - Class used on the class being parsed, uses another class that is unresolved

I'm not sure if I described the issue well in the title, but here is the background: I want to parse a java source code, say TestClassOne.java. TestClassOne uses another class "TestClassTwo" declared as instance variable. Now, TestClassTwo has a…
H Kopec
  • 21
  • 3
2
votes
1 answer

How to figure out depth of inheritance tree of java class?

I'm making an analyser that figures out the depth of inheritance tree of a java class. I'm using javaparser to exact this info from a java file. How would I be able to calculate the DIT? I'm aware of .getSuperClass() but that's not useful when…
srysry
  • 173
  • 1
  • 1
  • 10
2
votes
1 answer

JavaParser doesn't update source file

I'm using JavaParser and following its Wiki. Problem is even though I change the method's name and add a parameter to it, the file doesn't update. In other words, changes are not saved. When I System.out.println the changed CompilationUnit, it…
2
votes
2 answers

Modfying methods variable using java parser in java file

i am using java parser to read a java file. then i have problem with how to access variable in each method, then modifying the variable name and type in each method. public static void main(String[] args) throws Exception { // creates an input…
Samsul Arifin
  • 247
  • 1
  • 6
  • 24
2
votes
1 answer

Java MethodDeclaration ClassOrInterfaceDeclaration finding class names

I'm using the MethodDeclaration for a java parser that reads in source code but I'm having some problems. I can't see any methods which give me the class that this belongs to. Does a method exist for this or do I need to look in the java parser to…
Steven
  • 93
  • 1
  • 11
2
votes
1 answer

Counting Methods declaration + Methods Calls in a class using JavaParser

I'm trying to code rfc metric (Response for a Class), it counts the Method declarations + Method Calls. Method declarations works fine, but I got a problem at counting method calls using JavaParser API. Here is my code: public class MethodPrinter…
GSDa
  • 193
  • 2
  • 4
  • 21
1 2
3
12 13