question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with AST Output for Java

See original GitHub issue

The Node Types in the AST Output for Java are not very specific. As can be seen below, “SimpleName” type is applicable for variables, methods as well as class names; which reduces its value.

image

Is there anything that can be done to improve upon this?

PFB the input source code I was using, for quick reference:

`public class sample_java_2{

public static void main(String[] args){
	int x = 10; 
	int y = 15;
	int z;
	if (x < y) {
		z = 2*x;
	}
	else {
		z = 5*x;
	}

}

}`

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jsanket9578commented, May 25, 2021

You can specify java parser by passing a special key

--java-parser antlr

(I was wrong, the alternative to the GumTree parser that we currently support is ANTLR parser).

Hi @SpirinEgor thanks for the reply. I forgot replying, the ANTLR parser has been really helpful. I couldn’t find it in the documentation, it might be a good idea to add this in there.

1reaction
vovakcommented, May 13, 2021

Hi @jsanket9578, thanks for reaching out.

You can use the type label of the parent node(s) to get context information for each SimpleName.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Abstract Syntax Tree (AST) in Java - GeeksforGeeks
AST's are mainly used in compilers to check code for their accuracy. If the generated tree has errors, the compiler prints an error...
Read more >
How to fix error while installing AST-View on Eclipse
I'm trying to install AST-view plugin on Eclipse. It visualizes the AST (abstract syntax tree) of a Java file open in the editor....
Read more >
Eclipse JDT - Abstract Syntax Tree (AST) and the Java Model
The AST is a detailed tree representation of the Java source code. The AST defines an API to modify, create, read and delete...
Read more >
CSE 401/M501 22sp - Project II - Parser+AST - Washington
The output of the new AST Visitor should be a readable representation of the abstract tree, not a "de-compiled" version of the program,...
Read more >
ast — Abstract Syntax Trees — Python 3.11.1 documentation
Source code: Lib/ast.py The ast module helps Python applications to process ... optional in the grammar (using a question mark), the value might...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found