Coder Social home page Coder Social logo

roaster's Introduction

Roaster - The only Java source parser library you’ll ever need

Actions Status License Maven Central Supported JVM Versions

Roaster (formerly known as java-parser) is a library that allows easy parsing and formatting of java source files. Roaster introduces a fluent interface to manipulate Java source files, like adding fields, methods, annotations and so on.

Installation

  • If you are using Maven, add the following dependencies to your project:

<properties>
  <version.roaster>2.29.0.Final</version.roaster>
</properties>

<dependency>
  <groupId>org.jboss.forge.roaster</groupId>
  <artifactId>roaster-api</artifactId>
  <version>${version.roaster}</version>
</dependency>
<dependency>
  <groupId>org.jboss.forge.roaster</groupId>
  <artifactId>roaster-jdt</artifactId>
  <version>${version.roaster}</version>
  <scope>runtime</scope>
</dependency>
  • Otherwise, download and extract (or build from sources) the most recent distribution containing the Roaster distribution and command line tools

Usage

CLI

Execute roaster by running the following script (add these to your $PATH for convenience):

bin/roaster     (Unix/Linux/OSX)
bin/roaster.bat (Windows)

Options described here:

$ roaster -h

Usage: roaster [OPTION]... FILES ...
The fastest way to build applications, share your software, and enjoy doing it.

-c, --config [CONFIG_FILE]
	 specify the path to the Eclipse code format profile (usually found at '$PROJECT/.settings/org.eclipse.jdt.core.prefs')

-r, --recursive
	 format files in found sub-directories recursively

FILES...
	 specify one or more space-separated files or directories to format

-h, --help
	 display this help and exit

Java Parser API

Example:

Roaster.parse(JavaClassSource.class, "public class HelloWorld {}");

Java Source Code Generation API

Roaster provides a fluent API to generate java classes. Here an example:

final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
javaClass.setPackage("com.company.example").setName("Person");

javaClass.addInterface(Serializable.class);
javaClass.addField()
  .setName("serialVersionUID")
  .setType("long")
  .setLiteralInitializer("1L")
  .setPrivate()
  .setStatic(true)
  .setFinal(true);

javaClass.addProperty(Integer.class, "id").setMutable(false);
javaClass.addProperty(String.class, "firstName");
javaClass.addProperty("String", "lastName");

javaClass.addMethod()
  .setConstructor(true)
  .setPublic()
  .setBody("this.id = id;")
  .addParameter(Integer.class, "id");

Will produce:

package com.company.example;

import java.io.Serializable;

public class Person implements Serializable {

   private static final long serialVersionUID = 1L;
   private final Integer id;
   private String firstName;
   private String lastName;

   public Integer getId() {
      return id;
   }

   public String getFirstName() {
      return firstName;
   }

   public void setFirstName(String firstName) {
      this.firstName = firstName;
   }

   public String getLastName() {
      return lastName;
   }

   public void setLastName(String lastName) {
      this.lastName = lastName;
   }

   public Person(Integer id) {
      this.id = id;
   }
}

Java Source Code Modification API

Of course it is possible to mix both approaches (parser and writer) to modify Java code programmatically:

JavaClassSource javaClass =
  Roaster.parse(JavaClassSource.class, "public class SomeClass {}");
javaClass.addMethod()
  .setPublic()
  .setStatic(true)
  .setName("main")
  .setReturnTypeVoid()
  .setBody("System.out.println(\"Hello World\");")
  .addParameter("java.lang.String[]", "args");
System.out.println(javaClass);

JavaDoc creation and parsing

Here is an example on how to add JavaDoc to a class:

JavaClassSource javaClass =
  Roaster.parse(JavaClassSource.class, "public class SomeClass {}");
JavaDocSource javaDoc = javaClass.getJavaDoc();

javaDoc.setFullText("Full class documentation");
// or
javaDoc.setText("Class documentation text");
javaDoc.addTagValue("@author","George Gastaldi");

System.out.println(javaClass);

Formatting the Java Source Code

Roaster formats the Java Source Code by calling the format() method:

String javaCode = "public class MyClass{ private String field;}";
String formattedCode = Roaster.format(javaCode);
System.out.println(formattedCode);

Parsing the java unit

The Java Language Specification allows you to define multiple classes in the same .java file. Roaster supports parsing the entire unit by calling the parseUnit() method:

String javaCode = "public class MyClass{ private String field;} public class AnotherClass {}";

JavaUnit unit = Roaster.parseUnit(javaCode);

JavaClassSource myClass = unit.getGoverningType();
JavaClassSource anotherClass = (JavaClassSource) unit.getTopLevelTypes().get(1);

Validate Code Snippets

Roaster validates Java snippets and reports as Problem objects by calling the validateSnippet() method:

Example:

List<Problem> problem = Roaster.validateSnippet("public class HelloWorld {}");
// problem.size() == 0

List<Problem> problem = Roaster.validateSnippet("public class MyClass {");
// problem.size() == 1 containing a new Problem("Syntax error, insert \"}\" to complete ClassBody", 21, 21, 1)

Building from sources

Just run mvn clean install to build the sources

Issue tracker

File an issue in our GitHub Issue Tracker

Get in touch

Roaster uses the same forum and mailing lists as the JBoss Forge project. See the JBoss Forge Community page.

Related / Similar projects

For the writer part:

License

roaster's People

Contributors

asaf-wizzdi avatar bukodi avatar candiru avatar danielsoro avatar davecahill avatar davsclaus avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar evanchooly avatar forge-bot avatar gastaldi avatar georgekankava avatar jmini avatar kasium avatar lincolnthree avatar mbenson avatar meijuh avatar mrizzi avatar myannou avatar nbauma109 avatar nchal avatar plamen5kov avatar radai-rosenblatt avatar selrahal avatar sotty avatar vineetreynolds avatar windmueller avatar wmedvede avatar woodcoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

roaster's Issues

metadata.xml is not up-to-date in central repository

as we use multiple plugins to detect newer versions of used libraries we figured out that updates were not suggested for the roaster libraries. by digging a little bit deeper into that we noticed that the metadata.xml file in the central repository (https://repo1.maven.org/maven2/org/jboss/forge/roaster/roaster-api/maven-metadata.xml) lists as the last version 2.17.4.Final and was last updated December 2015.

can this pls be fixed when a new release is uploaded to the central repository to also update the metadata.xml file?

Qualified name of inner classes missing the enclosing type

If you reference an inner class (or interface) in the extends clause / implements clause / field / return type of method / parameter of method, the parent types are missing. I provided a small example:

import org.jboss.forge.roaster.Roaster;
import org.jboss.forge.roaster.model.source.JavaClassSource;
import org.jboss.forge.roaster.model.source.JavaInterfaceSource;
import org.jboss.forge.roaster.model.source.JavaSource;
import org.junit.jupiter.api.Test;

public class InnerClassesTest {

	private String testClass = """
			package alpha.beta.gamma;

				public class Foo {

					public class Bar extends Bar2 implements BarInterface {
						
						private Huu h;
					
						public Huu getHuu(Huu huu) throws BarException {return null;}

						public class Huu {

						}
					}
					
					public class Bar2 {}
					
					public interface BarInterface {}
					
				}

			""";

	@Test
	public void test() {
		JavaClassSource foo = (JavaClassSource) Roaster.parse(JavaSource.class, testClass);
		JavaClassSource bar = (JavaClassSource) foo.getNestedTypes().get(0);
		JavaClassSource bar2 = (JavaClassSource) foo.getNestedTypes().get(1);
		JavaInterfaceSource bar2Interface = (JavaInterfaceSource) foo.getNestedTypes().get(2);	
		JavaClassSource huu = (JavaClassSource) bar.getNestedTypes().get(0);
		
		System.out.println(bar.getSuperType()+" should be "+bar2.getQualifiedName());		
		System.out.println(bar.getInterfaces().get(0)+" should be "+bar2Interface.getQualifiedName());	
		System.out.println(bar.getFields().get(0).getType().getQualifiedNameWithGenerics() +" should be "+huu.getQualifiedName());
		System.out.println(bar.getMethods().get(0).getReturnType().getQualifiedNameWithGenerics()+" should be "+huu.getQualifiedName());
		System.out.println(bar.getMethods().get(0).getParameters().get(0).getType().getQualifiedNameWithGenerics()+" should be "+huu.getQualifiedName());
		System.out.println(bar.getMethods().get(0).getParameters().get(0).getType().getQualifiedNameWithGenerics()+" should be "+huu.getQualifiedName());
	}
}

Produced output:

alpha.beta.gamma.Bar2 should be alpha.beta.gamma.Foo$Bar2
alpha.beta.gamma.BarInterface should be alpha.beta.gamma.Foo$BarInterface
alpha.beta.gamma.Huu should be alpha.beta.gamma.Foo$Bar$Huu
alpha.beta.gamma.Huu should be alpha.beta.gamma.Foo$Bar$Huu
alpha.beta.gamma.Huu should be alpha.beta.gamma.Foo$Bar$Huu
alpha.beta.gamma.Huu should be alpha.beta.gamma.Foo$Bar$Huu

How to Utilize generics while keeping typecasting minimum

currently if you have a java class and if you want to parse it(or obtain it) recursively.we need to do.

for(org.jboss.forge.roaster.model.JavaType jtypes:javaClass.getNestedTypes()){
			org.jboss.forge.roaster.model.source.JavaClassSource assumetypeiscls=(org.jboss.forge.roaster.model.source.JavaClassSource)jtypes;
.........

is there any way to just not cast it into a classsource?or maybe cast to a more genric type? that may include interface.

All user code input should be validated

You should not be able to pass in invalid code and get obscure errors like "index out of range" exceptions. I found one place for this but the code should be audited for it everywhere. Better to run slower and have excellent errors.

wildcard resolved first instead of current package

when looking for super type of a type we try to resolve the canonical name of that type.
the issue is that we are trying to resolve wildcard imports before checking in the current package first.
example of the issue:

package org.jboss.forge.grammar.java;

import java.net.http.*;
import java.util.*;

public class MockWildcardClass {

    public List<String> getList(){
        return new ArrayList<>();
    }
    public HttpRequest getHttpRequest(){
        return new HttpRequest();
    }
}

and in the same package:

package org.jboss.forge.grammar.java;


public class HttpRequest {

   private String fakeField;


    public String getFakeField() {
        return fakeField;
    }

    public <T extends HttpRequest> T setFakeField(String fakeField) {
        this.fakeField = fakeField;
        return (T) this;
    }
}

roaster resolves HttpRequest as java.net.http.HttpRequest even though it should be org.jboss.forge.grammar.java.HttpRequest

How to use roaster in modularized project ?

Hi, I'm trying to use roaster in a modularized project

<properties>
  <version.roaster>2.29.0.Final</version.roaster>
</properties>

<dependency>
  <groupId>org.jboss.forge.roaster</groupId>
  <artifactId>roaster-api</artifactId>
  <version>${version.roaster}</version>
</dependency>
<dependency>
  <groupId>org.jboss.forge.roaster</groupId>
  <artifactId>roaster-jdt</artifactId>
  <version>${version.roaster}</version>
  <scope>runtime</scope>
</dependency>

If roaster-jdt is used in scope runtime it cannot be added in module-info.java
In scope compile, add in module-info.java

requires roaster.api;
requires roaster.jdt;

The result will be:

[WARNING] Can't extract module name from roaster-jdt-2.29.0.Final.jar: Provider class org.jboss.forge.roaster._shade.org.eclipse.osgi.launch.EquinoxFactory not in JAR file roaster-jdt-2.29.0.Final.jar
[WARNING] ****************************************************************************************************************************************************
[WARNING] * Required filename-based automodules detected: [roaster-api-2.29.0.Final.jar]. Please don't publish this project to a public artifact repository! *
[WARNING] ****************************************************************************************************************************************************

Did I missed something?
Maybe the project could be modularized for a futur version.

Cannot add an import with a class name of "Error"

The framework won't let you add a class import with the class name "Error". The test below fails.

@Test
  public void addImportWithNameErrorExpectsNoErrors() {
    String className = "SomeClass";
    JavaClassSource originalClass =
        Roaster.parse(JavaClassSource.class, "public class " + className + " {}");

    String importName = "foo.Error";
    originalClass.addImport(importName);
    Import addedImport = originalClass.getImport(importName);
    assertNotNull(addedImport, "Expected to successfully add the import");
  }

ClassLoaderWildcardImportResolver does not look for the correct class

looking at the code of ClassLoaderWildcardImportResolver and running a debugger seems that it does not remove the asterisks at the end of the import statement thus if we have a class:

package com.test.service.service;
import java.util.*;
public class PersonService {
public List<Person> listAllPeople(){/*implementation discarded*/}
}

it will attempt to load the class java.util.*.List instead of java.util.List
this will result in the default implementation of method.getReturnType().getQualifiedName() returning com.test.service.service.List in this case

org.jboss.forge.roaster.model.impl.JavaSourceImpl is not thread safe

This is the issue: private static List<WildcardImportResolver> resolvers;
is used like a poor man's singleton so, when concurrent calls stat hitting getImportResolvers, sooner or later a concurrent modification exception is thrown.
The simpler solutions is to wrap the body of getImportResolvers in synchronized (JavaSourceImpl.class) {} block but I'm sure there are also more elegant fixes.

Wrong code generated when extending interface with another that has the same name

When extending an interface with another one that has the same name but comes from a different package, Roaster should add a fully qualified reference to the extending interface.
Here is a reproducer that can be run using jbang:

///usr/bin/env jbang "$0" "$@" ; exit $?

//DEPS org.jboss.forge.roaster:roaster-api:2.26.0.Final
//DEPS org.jboss.forge.roaster:roaster-jdt:2.26.0.Final

import org.jboss.forge.roaster.Roaster;
import org.jboss.forge.roaster.model.source.JavaInterfaceSource;

import static java.lang.System.out;

class Bug {

	public static void main(String[] args) {

		JavaInterfaceSource outer = Roaster.create(JavaInterfaceSource.class)
				.setPackage("outer")
				.setName("Buggy")
				.setPublic();

		JavaInterfaceSource inner = Roaster.create(JavaInterfaceSource.class)
				.setPackage("outer.inner")
				.setName("Buggy")
				.setPublic();

		inner.addInterface(outer);

		out.println("Expected:\n" +
				"package outer.inner;\n" +
				"public interface Buggy extends outer.Buggy {\n" +
				"}");

		out.println("Actual:");
		out.println(inner.toString());
	}
}

Is there a workaround (other than changing the name)? Thanks for any help!

How to create method: public <T> List<T> apiGet(String url, Class<T> clazz)

Hello,

We're trying to create the following method:

public <T> List<T> apiGet(String url, Class<T> clazz)

but am unable to generate the first "" marker. Is this possible?

Here's the code I'm using:

    public static void main(final String[] args) {

        final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
        javaClass.setName("TestClass");

        final MethodSource<?> methodSource = javaClass.addMethod();
        methodSource.setName("apiGet").setPublic().setBody("return null;");
        methodSource.addParameter("String", "url");
        methodSource.addParameter("Class<T>", "clazz");
        methodSource.setReturnType("List<T>");
        //methodSource.setReturnType("<T> List<T>");  // does not work: throws StringIndexOutOfBoundsException

        log.info("\n\n" + javaClass.toString() + "\n");
    }

Thanks for any help you can offer!

Switch using "->" handled incorrectly as switch expression

I can write the following method in Java:

enum Direction {LEFT, RIGHT}

void displayDirection(Direction direction) {
  switch(direction) {
    case LEFT -> System.out.println("Turn Left");
    case RIGHT -> System.out.println("Turn Right");
  }
}

This is the correct java code. When I create method with this body though, it gets replaced with something like:

void displayDirection(Direction direction) {
  switch(direction) {
    case LEFT: 
      System.out.println("Turn Left");
      yield;
    case RIGHT:
      System.out.println("Turn Right");
      yield;
  };
}

It seems as if I use "->" in standard switch, library automatically treats it as switch expression

all user string input should be validated

java.lang.IllegalArgumentException
	at org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.AST.newName(AST.java:2420)
	at org.jboss.forge.roaster.model.impl.JavaSourceImpl.setPackage(JavaSourceImpl.java:625)
	at org.jboss.forge.roaster.model.impl.JavaSourceImpl.setPackage(JavaSourceImpl.java:53)

setPackage should do a notBlank check on user input and throw contextual exception (same for all user input methods)

Support comments in method bodies

Discussed in #267

Originally posted by panderior November 6, 2022
When I try to add a line comment to a Java class code I am trying to generate, the roaster library removes the comment and gives just the code.

My intention is to generate a code like this:

public class A {
    public void helper () {
         // this is a comment
         System.out.println("Success");
}}

What have I tried:

  • I have tried class and method level JavaDoc, which is a nice feature. But I also want to use line comment.
  • I have tried getting the "toUnformattedString" on the JavaClassSource, but the line comments just won't appear.

Your help is very appreciated. Thank you.

JavaDocImpl#getFullText misses adding a space when tag is @see #methodName

As the fragment doesn't resolve to a SimpleName, adding a space is skipped.

input:

result of MethodImpl.getJavaDoc().toString:

/** 
 * Convenience entry point for {@link IdCard} assertions when being mixed with other "assertThat" assertion libraries.
 * @see #assertThat
 */

result of MethodImpl.getJavaDoc().getFullText():

Convenience entry point for {@link IdCard} assertions when being mixed with other "assertThat" assertion libraries.
@see#assertThat

workaround for my use:

            String fullText = impl.getJavaDoc().getFullText();
            String replace = StringUtils.replace(fullText, "@see#", "@see #");
            copy.getJavaDoc().setText(replace);

Support Compact Constructors in Records

Library could support compact constructors in java records:

record Foo(String name, int x, int y) {
  Foo {
    Objects.requireNonNull(name);
  }
}

Currently, as a workaround you can ovveride the whole default constructor:

record Foo(String name, int x, int y) {
    Foo(String name, int x, int y) {
        this.name = Objects.requireNonNull(name);
        this.x = x;
        this.y = y;
    }
}

NPE in TypeImpl with anonymous inner classes - getSimpleName returns ""

java.lang.NullPointerException: Cannot invoke "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Type.toString()" because "this.type" is null
	at org.jboss.forge.roaster.model.impl.TypeImpl.getQualifiedName(TypeImpl.java:178)
	at org.jboss.forge.roaster.model.impl.JavaSourceImpl.addImport(JavaSourceImpl.java:285)
	at org.jboss.forge.roaster.model.impl.FieldImpl.setType(FieldImpl.java:341)
	at org.jboss.forge.roaster.model.impl.FieldImpl.setType(FieldImpl.java:327)
	at com.google.common.truth.extension.generator.TruthGenerator.addActualField(TruthGenerator.java:382)

getSimpleName():

Returns the simple name of the underlying class as given in the source code. Returns an empty string if the underlying class is anonymous.

Support nested types in Records

It would be useful if JavaRecordSource could have addNestedType method.
Such method is already present in JavaClassSource

java.lang.ClassCastException SingleMemberAnnotation to NormalAnnotation

Error adding a annotation value to @generated

java.lang.ClassCastException: class org.eclipse.jdt.core.dom.SingleMemberAnnotation cannot be cast to class
org.eclipse.jdt.core.dom.NormalAnnotation (org.eclipse.jdt.core.dom.SingleMemberAnnotation and
org.eclipse.jdt.core.dom.NormalAnnotation are in unnamed module of loader 'app')
	at org.jboss.forge.roaster.model.impl.AnnotationImpl.setAnnotationValue(AnnotationImpl.java:615)
	at org.jboss.forge.roaster.model.impl.AnnotationImpl.addAnnotationValue(AnnotationImpl.java:731)
	at com.google.common.truth.extension.generator.TruthGenerator.generate(TruthGenerator.java:44)
	at com.google.common.truth.TruthGeneratorTest.poc(TruthGeneratorTest.java:21)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

Support JavaDoc comment to an annotation element

Discussed in #270

Originally posted by rob-stoecklein November 8, 2022
When creating an annotation type, how do we set the JavaDoc for an element?
In the example below, it's the JAVADOC TEXT.

    /**
     * Trying to build the following annotation:
     * 
     * public @interface MyAnnotation {
     *
     *     /**
     *      * JAVADOC TEXT
     *      */
     *     String element;
     * }
     */
    public static void main(final String[] args) {
        final JavaAnnotationSource output = Roaster.create(JavaAnnotationSource.class);
        output.setName("MyAnnotation");

        final AnnotationElementSource annotationElementSource = output.addAnnotationElement();
        annotationElementSource.setName("element");
        annotationElementSource.setType("String");
        //annotationElementSource.getJavaDoc().setFullText("JAVADOC TEXT");  // <== Expecting a call like this

        final String outputStr = Roaster.format(output.toString());
        System.out.println(outputStr);
    }

How can we get this to work?
Thanks!

cannot generate record source ?

///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS org.jboss.forge.roaster:roaster-api:RELEASE
//DEPS org.jboss.forge.roaster:roaster-jdt:RELEASE
//JAVA 17

import org.jboss.forge.roaster.Roaster;
import org.jboss.forge.roaster.model.source.JavaRecordSource;

public class j2son2java {

    public static void main(String... args) {

        final JavaRecordSource javaClass = Roaster.create(JavaRecordSource.class);
        javaClass.setDefaultPackage();
        javaClass.addAnnotation();

    }
}

gives me:

Exception in thread "main" org.jboss.forge.roaster.ParserException: Cannot find JavaParserProvider capable of producing JavaSource of type JavaRecordSource
	at org.jboss.forge.roaster.Roaster.create(Roaster.java:103)
	at j2son2java.main(j2son2java.java:13)
Caused by: java.lang.IllegalArgumentException: org.jboss.forge.roaster.model.source.JavaRecordSource
	... 2 more

what is needed to generate Records ?

also seem that JavaRecordSource has no way to set/define fields/properties to have in a record?

IllegalArgumentException: Invalid identifier : >ConfigAware<T><

Running:

output.addInterface("com.blah.blah.blah.ConfigAware<T>"); // output is of type InterfaceCapableSource<?>

gives the following exception stack trace:

java.lang.IllegalArgumentException: Invalid identifier : >ConfigAware<T><
	at org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.SimpleName.setIdentifier(SimpleName.java:247)
	at org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.AST.newSimpleName(AST.java:2793)
	at org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.AST.newName(AST.java:2443)
	at org.jboss.forge.roaster.model.impl.AbstractInterfaceCapableJavaSource.addInterface(AbstractInterfaceCapableJavaSource.java:94)
	at com.tccc.kos.sdk.generator.builder.TypeBase.copyInterfaces(TypeBase.java:320)
	at com.tccc.kos.sdk.generator.builder.TypeClass.parse(TypeClass.java:34)

It happens because the target class implements the ConfigAware<T> interface, which contains the <T> generic.

Any ideas?
Was there a recent change to this code? (It works as expected in version 2.26.0.Final)

Originally posted by @rob-stoecklein in #272 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.