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 do I use Java Compiler Tree API (com.sun.source.util) to reconstruct source code

I am currently analysing Java source code. I have done AST analysis by using Compiler Tree API to parser source code. But I have a problem to add new AST node(insert a expression or statement for example) to compilation unit which can be compiled by…
Saddy
  • 313
  • 4
  • 22
1
vote
1 answer

How can I map java source code constructs to imports?

The wider context is that I am writing a tool which tries to rough-estimate the consultancy potential of a java developer with respect to various java libraries/technologies across projects in an organization. The version history of a file gives me…
Abhijith Madhav
  • 2,748
  • 5
  • 33
  • 44
1
vote
1 answer

BCEL - Get Class name,element names ,and method names

how to using bcel classparaser to get class names ,element names and method names ? ive already find a way to get class names but element and method names give me something wrong . Anyone can help me with that ? here is my code (with some errors…
YDev
  • 61
  • 1
  • 9
1
vote
3 answers

How to modularize a JavaCC grammar file (.jj)?

I am learning compiler construction and want to implement the JavaScript grammar using JavaCC. (I have already written my own JavaScript CodeModel which allows programmatic construction of the JavaScript code, now I want to write a JavaCC-based…
lexicore
  • 42,748
  • 17
  • 132
  • 221
1
vote
2 answers

How to get class level variable declarations using javaparser ?

I want to get only the class level variable declarations. How can i get the declarations using javaparser? public class Login { private Keyword browser; private String pageTitle = "Login"; } Using javaparser have to get the details of…
user3181223
1
vote
1 answer

Halstead Science Metrics

I am working in building halstead Metrics in java and I am using javaparser library and I am confusing about how I can find all java reserved words in the java imported file which will be parsing to find the operator (n1) ?
JavaTrainner
  • 37
  • 1
  • 5
1
vote
1 answer

How to parse a method or any other valid expression using JavaParser

JavaParser is a java source code parsing tool. I read the documents but found it only able to parse source of a full java class, like: public class X { public void show(String id) { Question q = Quesiton.findById(id); …
Freewind
  • 193,756
  • 157
  • 432
  • 708
0
votes
0 answers

Is it possible to get the return type contained in a MethodCallExpr using JavaParser?

Suppose I have the following snippet of code class Main { public static void main(String[] args) { System.out.println("Hello world!"); if (yes(1) == true) { System.out.println("yep"); //do something …
Aditi
  • 157
  • 6
0
votes
1 answer

How to add maven type solver in JavaParser

I have an AEM maven project with dependencies being injected by maven. I am using the Java Parser library to do some analysis of the code. Till now, we were manually injecting the typesolvers using the paths of the jars in the m2 repository like…
Rohit
  • 21
  • 1
  • 4
0
votes
0 answers

Determining if a parsed method parameter is an enum

I am using javaparser to parse and analyse some classes and to generate an adequate response. I have a problem detecting if a method's argument is an enum. A class is parsed and list of methods is fetched. When I iterate through this list I also…
Saša
  • 4,416
  • 1
  • 27
  • 41
0
votes
0 answers

How to prepend to move a line comment to the middle of field declaration with JavaParser

What I want to do I am trying to add a comment on the generated field declaration by Lombok like this: @lombok.Generated private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SomeController.class); To tell Parasoft Jtest to…
SATO Yusuke
  • 1,600
  • 15
  • 39
0
votes
0 answers

Find the actual scope of a variable declared multiple times in Java

I have a program that is like this : class A { String abc; public void f1(){ String abc = 'test'; System.out.println(abc); if (true){ String abc = 'something else'; System.out.println(abc); } } public void…
Aditi
  • 157
  • 6
0
votes
1 answer

Weird behavior with FQ type names

I'm trying to extract all class/interface type references from a class declarations. I'm getting a weird behavior with FQ names. Here is a simple example: CompilationUnit cu = StaticJavaParser.parse( "public class foo extends java.lang.String…
0
votes
1 answer

How could I insert a statement before try statement in method using github.parser

I am using Com.GitHub.java parser for generating java code. i am facing a problem . problem is : I have need bellow output . This line "String result = null;" need to show before try statement . But it is showing inside of try statement. My Source…
0
votes
1 answer

How to make a Java object of generic type, in Clojure?

Clojure empty changes types of Java collections. For example a JavaParser MethodCallExpr object mce, (type (.getArguments mce)) ;; => com.github.javaparser.ast.NodeList (type (emtpy (.getArguments mce))) ;; => nil (type (into (empty (.getArguments…
cmal
  • 2,062
  • 1
  • 18
  • 35