I'm currently beginning an automated software analysis project of which I am the research phase. I'm quite new to parsing and struggling to find info on resources regarding comparisons between the main java parsing options. I understand JavaParser was created using JavaCC, what functionalities does it contain that JavaCC does not? Are there any primary differences I should be aware of when making a decision as to which parser to use. Similarly, are there features that the Eclipse JDT contains compared to these two which may be of use to me? Thank you for any answers in advance.
Understanding JavaParser compared to JavaCC and Eclipse JDT
729 Views Asked by neversnow1 At
1
There are 1 best solutions below
Related Questions in JAVA
- I need the BIRT.war that is compatible with Java 17 and Tomcat 10
- Creating global Class holder
- No method found for class java.lang.String in Kafka
- Issue edit a jtable with a pictures
- getting error when trying to launch kotlin jar file that use supabase "java.lang.NoClassDefFoundError"
- Does the && (logical AND) operator have a higher precedence than || (logical OR) operator in Java?
- Mixed color rendering in a JTable
- HTTPS configuration in Spring Boot, server returning timeout
- How to use Layout to create textfields which dont increase in size?
- Function for making the code wait in javafx
- How to create beans of the same class for multiple template parameters in Spring
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
- Accessing Secret Variables in Classic Pipelines through Java app in Azure DevOps
- Postgres && statement Error in Mybatis Mapper?
Related Questions in ECLIPSE
- I need the BIRT.war that is compatible with Java 17 and Tomcat 10
- GUI window is not appearing
- I am trying to run java application in Eclipse, When I try to do Run > Run as > Java Application it starts to show little processing but nothing happe
- Migrating Google App Engine - Eclipse Java 8
- Unable to compile the class for JSP in tomcat 8.5.95
- Eclipse + CMake: Eclipse index unable to resolve header files
- Commit Each Change from Eclipse to GitHub as a different Branch
- Using Eclipse Maven project, import new version of a class from a jar file created from another Maven project
- Is the Eclipse RCP "Window > Show View" menu predefined somewhere
- To enable syntax highlighting with color for JBehave stories in Eclipse
- Eclipse: "package...does not exist" when building a Maven package that references a class in another project
- TestNG update related issue
- How to print a value by comparing 2 fields inside JSON - RestAssured
- How to build using Eclipse Tycho
- "Cannot be resolved as a type" problem with Java
Related Questions in ECLIPSE-JDT
- How to get ITypeBinding of HashMap in JDT without parsing code
- Class-File-Editor.Source-not-found Source Attachment Doesn't Have Source-File ReflectionUtils.class
- debug unexported java packages of JDK modules in Eclipse
- eclipse.jdt.ls Support for Kotlin
- Ways to access class structure/adding or removing highlighting via eclipse.jdt.ls Plugin API
- Neovim jdtls config can't persist
- JDT resolveBinding not returning null even when environment is set
- Trying to workspace setup in Eclips for existing maven project build error occurs
- Tycho does not find JUnit5 tests since Eclipse 2022-09
- implementing extract method refactoring using jdt and ltk
- Eclipse jdt formatter configuration to force braces for if else
- How to debug Java SE 6 using Eclipse 2022-12?
- Neovim setting up jdtls with lsp-zero/mason
- Understanding JavaParser compared to JavaCC and Eclipse JDT
- How to discover all dependencies (aka. "imports") from an IType?
Related Questions in JAVACC
- Java Project Analysis with Infer that Contains .jj Files
- Read in and parse a file to be able to set variables
- JAVA CC Pattern Throws an Error on an Expected Token
- difference between ParseException and TokenManagerError (javaCC)
- JAVACC - Switching Lexical States Based on Context
- How to test a token in JavaCC
- JavaCC generates code that fails while parsing UTF-8 strings
- Does the JavaCC (.jj) format support comments?
- Javacc left recursion
- JavaCC conditionals implement given a grammar
- Understanding JavaParser compared to JavaCC and Eclipse JDT
- use JavaCC to format my input file; how to handle comments?
- How to match any string between paranthesis that can contain paranthesis?
- Distinguish between object($.book) and array ($.book[0]) in JavaCC jj file
- Testing JavaCC on a File?
Related Questions in JAVAPARSER
- Javaparser: Curly braces for one-line blocks?
- Javaparser: Visit all node types with one method
- JavaParser extracting annotation parameter value
- Convert a Date dd/MM/yyyy to dd-MM-yyyy in java
- How to infer the types of all the parameters of a function using java-parser and java-symbol-solver?
- How to include JavaParser Dependencies with Maven?
- Handling exception in Javaparser
- Creating an invalid AST in JavaParser
- javaparser generic method
- How to check if a Java source file is valid (has no errors)?
- Minimal java file
- Javaparser: get generic class of a method return type like List<MyClass>
- How to add a new statement on the same line using JavaParser
- Track line number changes in JavaParser
- JavaParser how to get classname in CompilationUnit
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
That's by no means an exhaustive answer, just a bit of clarification on the specific part of your questions and my 5 cents on the more general one. I assume, that you want to analyze Java code.
I also assume that it is sort of exercise in using code-as-data and grammars/parsers. Otherwise the field of code analysis itself is huge with very specific niches like finding bugs or checking code for thread safety, say.
In general, there's a huge amount of tools available for the purpose, but if we limit them to those written in Java the biggest fish in the open source space seem to be covered here. For a more complete list see this blog from some of the authors of JavaParser and this for a general introduction to the topic. It may also be worth it to have a look at their material on the somewhat overlapping topic of language development in general.
In an ex post view those question were lurking in the background of this response:
Let's go from the specific to the general:
com.github.javaparser parses a static piece of java code (note: only java, only static) and gives you an AST. The package also has SymbolResolver, which tries to determine the Java type of symbols. Its called JavaParser, but it isn't just a parser, it supports Java streams for querying and comes with AST manipulation and code generation capabilities. A main backer is an Italian company btw.
Eclipse jdt is comparably huge, with org.eclipse.jdt.core.dom.ASTParser giving you an AST. But as opposed to JavaParser everything is geared towards handling Java (only) in an interactive development situation. Since Eclipse can perform refactorings, it must be able to analyze and manipulate the AST, here's an example for that (as part of this post) and here are comprehensive examples for the refactoring api. If you're building some Eclipse integrated functionality to support writing of code, that will be your first option anyway. Eclipse Jdt supports incremental compilation in some form which you need if you want some compile-on-the-fly-and-give-feedback-as-the-code-gets-typed functionality.
I also worked a bit with the spoon library (developed by a university in France) which has the same focus as JavaParser, also does symbol resolution but has different querying mechanisms. It builds on org.eclipse.jdt.core. Each of those tools will give you a different AST for the same java code reflecting their intended use case, spoon describes it like this:
The most stark difference is between the more domain specific tools and the parser generators' generated parsers. While having some difference even between them, JavaParser/Spoon ASTs mirror the code on a conceptual level, you get methods, parameter lists, parameters and so on while the generated parsers give you every detail in the grammar down to semicolons, commas and braces as elements in the AST. I think, Eclipse has an Ast View where you can see JDT's parser output perhaps, but I'm not aware of a comprehensive tool that can show you differences between different parser for java like AstExplorer does it in the javascript world.
Which framework suits your need will depend very much on your use case. E.g. if you need symbol resolution, you're probably bound to those options that provide it anyway. I tried to get my feet wet with a Java transpiler and found the JavaParser metamodel more suitable than spoon's model and liked its small number of dependencies.
A general (though non-incremental) way to get a handle at an AST would be a parser generator like JavaCC (read: compiler compiler (aka compiler generator) written in Java that can create parsers for anything you have a grammar for) or ANTLR. If you want to parse SQL, you feed them a sql grammar, if you want to parse Java code, you feed them this one (ANTLR-format) or this one (JavaCC-format). The result will be a parser which can give you an AST for a given piece of code and a visitor class perhaps.
This approach gives you all possible control over the processing and the possibility to define or tweak a grammar depending on your needs, e.g. to introduce additional non-terminal nodes, trim it down to class/method-level only or pick out comments only without confusing them with string constants, if that's all you care about. You could also get at the structure of embedded non-Java code fragments, e.g. SQL query strings.
Btw. ANTLR can handle direct left recursion in the grammar, while JavaCC can't, e.g. for arithmetic expressions for binary operators like in
exp := exp + expIf your goal is to support developer activities as they write the code you'll have to deal with broken or incomplete code. Eclipse is build for the purpose and while I didn't use its jdt I'd expect it to handle such cases gracefully with reasonable feedback. Also ANTLR will recover from syntax errors if possible allowing you to define some error handling. I don't remember what spoon and JavaParser did in case of errors, I think, they expect syntactically correct code upfront.