Java source code parsers/generators [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I need tools to:
Conveniently parse Java source code and easily access given elements.
Easily generate source code files, to easily transform data structures into code
Any good tips, libraries, frameworks, tools? Thank you for help.

If you need to parse existing source code, use JavaParser. It gives you visitor-based access to the AST. You can write new code, but many things are a pain (e.g. referencing other classes)
If you need to generate source code use CodeModel. It lets you programmatically create classes, packages, methods etc, and it's very easy to use. However, I don't think it can import existing code.
Both are pretty awesome in their respective domains.

Since Java 6, the compiler has an API included in the JDK. Through it you can access the results of the Java parser through the javax.lang.model APIs. The same functionality was present with JDK5 in the form of the Mirror API. There's a good introductory article here.
The best code generation tool I've seen is CodeModel. It has a very simple API and can generate multiple Java source files at once.

Our DMS Software Reengineering Toolkit and its Java Front End can do this. They are designed to enable the construction of custom analyzers and code generators.
DMS provides generic parsing, abstract-syntax tree (with comments) and symbol table building, tree navigation/inspection/modification facilities, and the ability to regenerate the complete source code from the modified tree. Additional facilities includes source-to-source transformation rules ("if you see this syntax, replace it with that syntax"), and patterns (used to build or recognize subtree), attribute grammar evaluators, control and data flow analysis, and call-graph construction. The Java Front End specializes DMS to do all of this for Java 1.4-1.6 with 1.7 nearby.
(EDIT May 2016: Now handles Java 1.8)
DMS is also designed to handle scale: it is often used to process many compilation-units (source files) at the same time, enabling analysis and transformations that cross file boundaries. It can also handle multiple languages at the same time; DMS has front ends for a wide variety of languages.

Check out Antlr. One of its examples is a Java grammar.

Related

Is there a Java API that creates BPMN? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Is there a way to programmatically create BPMN 2.0 via a Java API?
I'm aware that I can use a graphical modeling tool or create the BPMN XML by hand but I'm looking for a way to create it dynamically at run-time.
In my case, the BPMN will be executed through jBPM. The jBPM docs say you can use their API to define processes but they don't recommend its use "to shield yourself from internal APIs". It would be great if there were an API that wasn't tied to a specific vendor.
EasyBPMN is one option. There is no "vendor neutral" way in that Java doesn't have a standard API for the concept (unlike, say generic XML manipulation), but this would be an option which would be more portable between workflow engines and modeling tools.
the whole idea about the BPMN2 spec is to be vendor neutral, inside jBPM5 you have the fluent API that in some way allow you to create BPMN2 models that you can export. I'm not sure if it's up-to-date with the latest features that are supported in the XML but I'm pretty sure that you can create your own processes with it.
Cheers
BPMN2 model is based on EMF model (org.eclipse.bpmn2 project, model folder, BPMN20.ecore file). You can use EMF Java Api to create, read or modify BPMN2 models.
You can use the library from activiti.
here there's a blog post of one of the people behind activiti.
I did a compiler that modifies a process based on this and it works.

Single page Web App in Java framework or examples? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Has anyone seen an example or done the following in Java:
http://duganchen.ca/single-page-web-app-architecture-done-right/
That is a design a single page web app that will work with Google SEO with out massive violation of DRY using Java technologies?
It doesn't seem terrible hard to do this on my own but I was curious (and lazy) to see if someone had already done it with either Spring or JAX-RS.
I have built quite a large "single-page" javascript website, that generats all HTML on the client. Server provides JSON only responses. I used Google Closure tools for the following reasons:
Google Closure Templates allows designing templates in high level templating language (named soy) which is compiled either to pure javascript functions to run on the client or java code to run on the server site.
Google Closure Compiler, which allows separating javascript code to modules and provides autmatic dependency injection for uncompiled mode. Good program structure and modularisation is necessary for any project exceeding simple html decoration. This is hard to achieve with frameworks like jQuery or dojo. In advanced compiled mode it transforms your javascript to shorter an more efficient equivalent, eliminates dead code and do dramatic reduction in size, which can shrink the original codebase to few % of the original size.
Google Stylesheets is meta css language which works great with closure compiler.
Google Closure Library is huge and well tested javascript library and with closure compiler, you only take what is needed.
To streamline the development, I'm using plovr, written by Michale Bolin, a former googler, one of the members of the original Closure Compiler Team.
I can recommend reading Michale's book: Closure, the Definitive Guide.
I must but warn, the initial leraning curve might be quite steep, but it is well worth the pain. Google used this tools to write almost all their web projects.
Just one more thing
If you feel really adventurous, and want to peep in to the future, I recomend upgrading the former strategy with Clojure/ClojureScript. For the start, watch this very persuasive talk of Rich Hickey and make sure to check Clojurescript one project.
I recommend AribaWEB for its advanced AJAX usage.
http://aribaweb.org/
Take a look to ItsNat, is a Java framework focused on Single Page Interface SEO compatible websites.

Tools to detect duplicated code (Java) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am in a project where previous programmers have been copy-pasting codes all over the place. These codes are actually identical (or very similar) and they could have been refactored into one.
I have spent countless hours refactoring these codes manually but I think there must be a better way. Some are very trivial static methods that could have been moved into an ancestor class (but instead was copy pasted all over by previous junior programmers).
Is there a code analysis tool that can detect this and provide reports/recommendations? I prefer free/open source tool if possible.
I use the following tools:
PMD/CPD (BSD-style License).
Checkstyle (LGPL License) - support was removed, see details.
Both tools have code duplication detection support. But both of them lack the ability to advise you how to refactor your code.
JetBrains IntelliJ IDEA Ultimate has good static code analysis with code duplication support, but it is not free.
Most of the tools listed on the Wikipedia article on Duplicate Code Tools will detect duplicates in many different languages, including Java.
SonarQube can detect duplicated codes but does not give recommendation on eliminating them. It is free and - although with the default setup it can only detect lexically identical clones
Either Simian or PMD's CPD. The former supports a wider set of languages but is non free for commercial projects.
http://checkstyle.sourceforge.net/ has support for finding duplicates
See our SD Java CloneDR, a tool for detecting exact and near-miss duplicate code in large Java systems.
The CloneDR will find code clones in spite of whitespace changes, line breaks, comment insertions deletions, modification of constants or identifiers, and in a number of cases, even replacement of one statement by another or a block of statements.
It shows where each set of clones is found, each individual clone, an abstraction of the clones having their shared commonality and parameterization of the abstraction to show how each clone instance can be derived from the abstraction.
It finds 10-20% clones in most Java systems.

Where can I find a Java library for code highlighting? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm trying to find a Java library to highlight code. I don't want to highlight Java code. I want a library that will easily allow me to highlight a macro language of my own, in a code editor of my own written in Java.
JSyntaxPane is decent. Advanced and decent IDEs use either Lexer/Parsers such as Antlr and Javacc or regular expressions. Implementing it correctly is not a trivial task.
As you mentioned "a macro language of my own", I suggest taking a look at Lexer/Parser generators for Java and maybe JEdit syntax package source code(google it, reached the maximum hyperlinks) for lexing strategies.
GesHi is pretty good. There is a list of highlighters here.
UPDATE: missed that you wanted a java lib. Try jedit syntax package.
You might look at the Java port of GeSHi named JaSHi. It looks like it is a complete rewrite of the popular PHP package, with Java bindings.
JSyntaxPane may be the way to go. It will highlight a number of languages and is extensible to handle others.
You may want to take a look at xtext - it does a lot more than syntax highlighting; in fact, you only have to define a grammar, and it will generate an eclipse editor plugin with outline, syntax highlighting, syntax checking and autocompletion automatically. It could save you a lot of work if an eclipse editor plugin is an acceptable end result for you.

Tools for converting non-Java into Java source [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Are there any good tools out there for automatically converting non-Java source code into Java source?
I'm not expecting something perfect, just to get the worst of the grunt work out of the way.
I guess there is a sliding scale of difficulty. C# should be relatively easy (so long as you ignore all the libraries). (well written) C++ not so bad. C requires making a little OO. (Statically type) functional languages may be easy to grok. Dynamic OO languages may require non-local analysis.
One thing you can try is find a Java bytecode compiler for the language you're talking about (there are JVM compilers for all kinds of languages) and then decompile the bytecode back into Java using a decompiler like Jad.
This is fraught with peril. The regenerated code will suck and will probably be unreadable.
Source-to-source migrations fall under the umbrella of Program Transformation. Program-Transformation.org tracks a bunch of tools that are useful for language recognition, analysis, and transformation. Here are few that are capable of source-to-source migrations:
ASF+SDF Meta-Environment - As noted, there is no new development on this tool. Instead, the developers are focusing on Rascal.
Rascal Meta Programming Language
Stratego /XT
TXL
DMSĀ® Software Reengineering Toolkit (commercial)
If you spend any time with one of the open source tools, you'll notice that even though they include source-to-source migration as a feature, it's hard to find working examples. I imagine this is because there's no such thing as a one-size-fits-all migration. Each project/team makes unique use of a language and can vary by libraries used, type complexity, idioms, style, etc. It makes sense to define some transformations per migration. This means a project must reach some critical mass before automatic migration is worth the effort.
A few related documents:
An introduction to Rascal - includes a migration between the toy language Pico and Assembly starting at page 94.
Cracking the 500 Language Problem
An Experiment in Automatic Conversion of Legacy Java Programs to C# (gated) - uses TXL
Google: ANTLR
The language conversion is fairly simple, but you will find the libraries are different.
This is likely to be most of your work.
If you just want to use some legacy C/Pascal code, you could also use JNI to call it from Java.
If you want to run it in a Java applet or similar constrained environment, and it does not have to be very efficient, you can use NestedVM (which is a MIPS to Java bytecode converter) in conjunction with a gcc cross-compiler that compiles to MIPS). But don't expect to get readably Java code from that.
Any of those tools might help only if your non java code is not huge enough.
If its huge non java code and if you want to seriously translate it to java, then few things need to be thought of, its not just hundreds of lines of code, there is a design beneath it, there are few decisions taken by people beneath the code due to which certain problems might have been solved and few things have been working there. and investing time on any good translator won't be worth as it won't exist, it's not just syntax translation from one language to another.
If its not so huge code, its better to re write in java, as it has so many APIs packages out of box, it might not be big deal, hiring few interns for this also might help.
ADA to Java can be done with a find-and-replace!

Categories

Resources