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 get the name of MethodCallExpr name and FieldAccessExpr from each methods in a class?

I've got the MethodCallExpr and FieldAccessExpr from each method. Here is some code I've done. for (TypeDeclaration typeDec : cu.getTypes()) { for (MethodDeclaration method : typeDec.getMethods()) { …
ardant
  • 23
  • 6
1
vote
0 answers

Exception in thread "main" java.lang.IllegalStateException: No data of this type found. Use containsData to check for this first

i tried to get the inherited methods and fields from java source code but i have this problem : i tried to find inherited methods and fields from each class in my file which contained java code source , the syntax is correct but i have some errors…
1
vote
1 answer

How to replace expression by String in JavaParser AST

Suppose I have expression "(a == b || a == c) && (d == e)". How can I replace subexpression by custom String e.g. how can I replace a == b by a.equals(b)?
matoni
  • 2,479
  • 21
  • 39
1
vote
1 answer

Read XML body element having multiple values based on different requests

I am parsing a XML request using Java. The XML structure is like this:
//Header Details
RahulGo8u
  • 148
  • 2
  • 19
1
vote
0 answers

How to insert statements given in string format in java parser?

Let's say we have a program with a method void foo(int a, int b, int c), and we have a list of statements given in string formats like "System.out.println(a);" or "int q = a+b+c;" or "try{int d = a/b;}catch(Exception e){}". Is there a convenient way…
Yiwei Lyu
  • 23
  • 3
1
vote
2 answers

How to find all assignment statements where string literal is assigned to variable in Java using antlr or javaparser?

I am trying to find hardcoded string assignment statements in Java. I am trying to use antlr or javaparser but am not getting how to find assignment statements? Javaparser seems a good way to go. It has support for declarations etc. I am trying to…
user3565529
  • 1,317
  • 2
  • 14
  • 24
1
vote
1 answer

How to Parse static level variable from the JAVA file?

I'm trying to Parse the static variable value from the JAVA file. But couldn't be able to parse the variable. I've used JavaParser to Parse the code and fetch the value of variable. I got success in fetching all other class level variable and value…
Joshi Yogesh
  • 142
  • 1
  • 12
1
vote
0 answers

Parse Java enum file with a certain annotation

This is what I want to do: Given some enum files, filter out the ones with @someAnnotation in comment or as a class annotation, the grab the names of enum fields from AST. Maybe using Java Parser. But I wasn't sure how to do it exactly.
Nexus2020
  • 538
  • 6
  • 18
1
vote
1 answer

How to get method's parameters' package name by javaparser?

public String do(Person p){} How to get the parameter Person package name?I can only get the paramter type,only get class name.
Crytis
  • 300
  • 3
  • 10
1
vote
1 answer

Using JavaParser to find inheritance using getExtendedType

I need to find if a class is inheriting other class using Javaparser's getExtendedType method. Can someone point the correct syntax for this and also the logic to find it recursively. Suppose class A is extending class B which in turn is extending…
1
vote
0 answers

Importing a library to into Intellij Idea platform sdk

I am developing a plugin using Intellij Idea using platform SDK! I want to import the JavaParser library available at https://github.com/javaparser/javaparser so that I can parse java source code. The importing can be done using gradle and maven…
1
vote
1 answer

Getting the methods called inside main method using JavaParser

I am using the JavaParser library to parse the java code and access the java code tokens. Following is my code import java.util.Vector; import com.github.javaparser.JavaParser; import com.github.javaparser.ast.CompilationUnit; import…
1
vote
1 answer

Change method level String variables with JavaParser

I want to use JavaParser in order to change all String variable values in a Java source code from any value to "". I can change the value of the global variables, but I cannot manage to change the value of the method level variables. Looking around,…
undisp
  • 711
  • 3
  • 11
  • 34
1
vote
1 answer

com.github.javaparser.JavaParser cannot be found

I wanna use javaparser with my plugin in eclipse. I can use/import all of JavaParser-Core classes except one. JavaParser class caused an error. How can i fix this? Here is console output; java.lang.ClassNotFoundException:…
devmaria
  • 27
  • 7
1
vote
1 answer

Extract instance variables referenced in a java method

I have a class like below class A{ private var1, var2; public void methodA(){ sout(var1); } public void methodB(){ sout(var1); sout(var2); } } Here in that code snippet I have class with two instance…