Skip to content

Latest commit

 

History

History
101 lines (81 loc) · 2.58 KB

README.asciidoc

File metadata and controls

101 lines (81 loc) · 2.58 KB

parser-java

This addon exports services for use in other addons. The Java parser addon provides APIs and services for parsing Java types including classes, enums, interfaces, annotations, and package-info types.

Depends on

Addon Exported Optional

resources

no

yes

projects

no

yes

ui-spi

no

yes

org.jboss.forge.furnace:container-cdi

no

no

Setup

This Addon requires the following installation steps.

Add configuration to pom.xml

To use this addon, you must add it as a dependency in the pom.xml of your forge-addon classified artifact:

<dependency>
   <groupId>org.jboss.forge.addon</groupId>
   <artifactId>parser-java</artifactId>
   <classifier>forge-addon</classifier>
   <version>${version}</version>
</dependency>

Features

JavaSourceFactory for java source parsing and generation

The JavaSourceFactory allows for parsing and generation of Java sources via a type-safe and fluent API.

@Inject
private JavaSourceFactory factory;
...
JavaClass myClass = factory.parse(JavaClass.class, "public class MyClass{}");
Tip

If your addon uses a container that does not support "@Inject" annotations, services such as the JavaSourceFactory may also be accessed via the AddonRegistry:

AddonRegistry registry = ...
Imported<JavaSourceFactory> imported = registry.getServices(JavaSourceFactory.class);
JavaSourceFactory factory = imported.get();
(Optional) projects addon integration

When the projects addon is installed, several ProjectFacet implementations will be retrievable from appropriately configured projects that include java source code.

  • JavaCompilerFacet - used to control the project Java compiler version.

  • JavaSourceFacet - used to manipulate project Java source files.

    Project project = ...
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
(Optional) resources addon integration

When the resources addon is installed, additional resources types for dealing with java types, methods and fields will be available for use via the ResourceFactory.

ResourceFactory factory = ...
JavaResource resource = (JavaResource) factory.create(new File(".../MyJavaClass.java"));

JavaResource types also expose JavaFieldResource and JavaMethodResource via JavaResource.listResources().

(Optional) ui-spi addon integration

When the ui-spi addon is installed, the InputType.JAVA_CLASS_PICKER input type hint will be registered for UIInput<JavaResource> instances.