Skip to content

MDSD-Tools/JaMoPP

Repository files navigation

JaMoPP: Java Model Parser and Printer

JaMoPP is an EMF-based tool that can parse and print Java source and byte code into EMF models and vice versa. It preserves source formatting and can be used for code analysis, refactoring, and code generation. JaMoPP is based on the original version by DevBoost GmbH and the Software Technology Group of the Technical University of Dresden. It has been forked by the Institute of Information Security and Dependability (KASTEL) at the Karlsruhe Institute of Technology (KIT). This repository is not supported by or affiliated with DevBoost GmbH or TU Dresden (TUD).

JaMoPP defines a complete metamodel and textual syntax specification for Java, covering Java versions up to 15. It also provides a parser and printer that can convert between text and models in both directions. This allows Java code to be treated like any other model. JaMoPP can also parse and print byte code (.class files) using the Eclipse Java Development Tools (JDT).

For more information read the original publications: JaMoPP publications

Getting Started

Currently, JaMoPP only supports a direct inclusion of its sources into Eclipse. For stand-alone usage, use the code in jamopp.standalone.JaMoPPStandalone.java as a starting point.

Prerequisites

  • Eclipse Modeling Tools 2022-09 with UTF-8 encoding and (optionally) install Xtext from the Marketplace
  • Java 17
  • Maven 3.8.7

Installation

JaMoPP can be installed from its update site (latest build from master), or the plugins can be imported directly into Eclipse:

  1. Clone this repository.
  2. Import all existing plugins from this repository (In Eclipse click File -> Import and select General -> Existing Projects into Workspace).
  3. Set releng/org.palladiosimulator.jdt.targetplatform/org.palladiosimulator.jdt.targetplatform.target as the active target platform.
  4. Run the generate.mwe2 file in releng/org.palladiosimulator.jdt.workflow/workflow/ (if Xtext is installed). Alternatively, run a build (e.g. mvn clean verify) that also generates the model code.
  5. Now you should be able to use JaMoPP. Note: The file encoding must be set to UTF-8. Otherwise compilation errors may occur.
  6. To test the setup, open the console in root folder and build project with mvn clean verify. All tests will be run with the build.

Usage

In Eclipse, after installing JaMoPP, you can load Java files (.java and .class files) with any EMF-based tool similar to how you load other EMF models.

For stand-alone usage, use the code in JaMoPPStandalone.java as a starting point. The JaMoPPStandalone class is a standalone utility for parsing Java source code and generating XMI models. It can be used to parse any URI (absolute or relative file path/ Directory/ Archive) and output the corresponding XMI model. The class takes two input parameters:

  • INPUT: The URI of the Java source code to parse.
  • ENABLE_OUTPUT_OF_LIBRARY_FILES: A Boolean flag that determines whether to output XMI models for library files. The class generates XMI models for the Java source code and saves them to the ./standalone_output directory. The directory structure of the output files mirrors the package hierarchy of the Java source code.

Built With

  • Eclipse Tycho
  • Maven
  • Google Guice - Used for the bundles /tools.mdsd.jamopp.printer and /tools.mdsd.jamopp.parser. The code responsible for the dependency injection are in the injection packages.

Codestyle

For styling and coding conventions the Eclipse internal compiler, Eclipse-PMD, SpotBugs and Teamscale are used.

  • The PMD ruleset is JaMoPP\codestyle\jamopp-ruleset.xml.
  • The Teamscale analysis profile is JaMoPP\codestyle\Jamopp-Profile.tsanalysisprofile.
  • The Spotbugs exclude file is JaMoPP\codestyle\jamopp-exclude-filter.xml.

The settings for the plugins and for the internal compiler are all saved as project settings and should be imported when the repository is opened in Eclipse. Spotbugs and PMD must be downloaded from the Eclipse Marketplace.

Case Studies

We tested JaMoPP with the following evaluation scenarios:

Contributing

We welcome contributions to JaMoPP. Please submit pull requests to the GitHub repository.

License

JaMoPP is released under the Eclipse Public License - v 1.0. For more information, please refer to the LICENSE file.