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
votes
2 answers

Javaparser - How to read a method if a condition occurs

I'm using JavaParser library and I would like how to do this: I want to parse a method and If there is a RestTemplate call, I want to get the "url" value. This is my method: public void myMethod() { try { String url =…
Luisao
  • 455
  • 2
  • 9
  • 20
-1
votes
4 answers

Java reflection: How to get comments?

I have faced some difficulties with Java parsing. I need somehow to get comments of class, fields, methods etc. via reflection. I have found JavaParser and it looks like it can elicit comments but I haven't got how to do it as all the examples just…
aspirisen
  • 965
  • 13
  • 29
-1
votes
1 answer

Java parser Adding an new Inner Class

I want use the Java Parser to add an inner class to an existing class. I've tried ClassOrInterfaceDeclaration classOrInterfaceType= cu.addClass("MyInnerClass", Modifier.PUBLIC,Modifier.STATIC); but this adds a new class to the Java class i.e. not…
-1
votes
1 answer

How to import projects (i.e from github) to my application

So I have been working on a project where I need to process some Java code. To do this I decided to use JavaParser. On their website JavaParser, I see a 'Getting Started' guide that explains how to include JavaParser in Maven and Gradle but as I am…
James Webb
  • 167
  • 2
  • 17
-1
votes
1 answer

writing an else if statement using java parser

I have an existing java source code. I am modifying this .java file using java parser (jar name - javaparser-core-2.5.1.jar). I need to add an else if statement block e.g: if(condition1){ //then statement }else if(condition2) { //then…
-1
votes
2 answers

Need to parse JAVA source code

I need to parse MANY JAVA files and save the class names and methods in a word(.docx) file with certain formatting(certain words need to be bolded/indented etc.). Are there any good tools or libraries that I can use for the same? Thanks!
ricky
  • 31
  • 2
-1
votes
4 answers

Parsing JsonArray With JsonObject

I have some JSON with the following structure: { "items":[ { "product":{ "product_id":"some", "price_id":"some", "price":"some", "title_fa":"some", …
masoud p
  • 503
  • 1
  • 7
  • 15
-1
votes
1 answer

Finding everything that affects a variable

I'm trying to make a program that will read in a class file and if you give it a variable for example you give it "i" in the following example: public class Example { public static void main( String[] args) { int i = 1; int j = 5; int…
Steven
  • 93
  • 1
  • 11
-2
votes
1 answer

How to get the value passed to a variable?

I am trying to evaluate a code snippet that has variables initialised to a value. Is there a way to get the field values using java? For the below code: public void testArea(){ int length = 5; int breadth = 6; ... } Suppose this is the…
Rakshita
  • 1
  • 2
-3
votes
1 answer

I want to add a statement. I tried parsing it, java parser exception is thrown. How to overcome it?

I need to insert a statement as int listSize = list.size(); So, I tried inserting that statement as Statement sampleStatement = JavaParser.statement ("int listSize = list.size();"); Java parser exception is thrown. ​ P.s: I'm using java parser…
-3
votes
2 answers

Convert a Date dd/MM/yyyy to dd-MM-yyyy in java

I'm trying to convert a date in dd-MM-yyyy format from YYYY-MM-dd hh:mm:ss.ms in java using the below code but m unable to get the desired value String dob = (new…
Mavericks
  • 283
  • 1
  • 7
  • 20
-3
votes
1 answer

String parser logic in java

I have a string like below which can grow further with few more AND/OR/NOT condition but maintains the syntax. String string = "apple,mango,name( AND( OR( gender[male,female], …
1 2 3
12
13