31614

Java Generic Context Type of super Class

The compliation of the CORE of fluent-builders-generator project failed with the compilation error

The method endParameter() is undefined for the type JavaSourceBuilderBase.MethodParameterBuilderBase

<img src="https://i.stack.imgur.com/VmgXY.jpg" alt="enter image description here">

The target line is

.withParameter().withType(..).withName("aInstance").endParameter()

the withParameter() return a Class witch effectivly contains the endParameter() but not his super Class

public class ParameterMethodParameterBuilder extends MethodParameterBuilderBase<ParameterMethodParameterBuilder> { public ParameterMethodParameterBuilder(com.sabre.buildergenerator.sourcegenerator.java.MethodParameter aInstance) { super(aInstance); } public GeneratorT endParameter() { return (GeneratorT) MethodBuilderBase.this; } }

Now the super Class

public static class MethodParameterBuilderBase<GeneratorT extends MethodParameterBuilderBase> { private final com.sabre.buildergenerator.sourcegenerator.java.MethodParameter instance; protected MethodParameterBuilderBase(com.sabre.buildergenerator.sourcegenerator.java.MethodParameter aInstance) { instance = aInstance; } protected com.sabre.buildergenerator.sourcegenerator.java.MethodParameter getInstance() { return instance; } public GeneratorT withType(java.lang.String aValue) { instance.setType(aValue); return (GeneratorT) this; } public GeneratorT withName(java.lang.String aValue) { instance.setName(aValue); return (GeneratorT) this; } }

So the problem is that the withName() and withType() return the super Class that didn't contains the endParameter.

i think that this had a relation ship with compiler version or parameters.

About the context of GeneratorT

public class JavaSourceBuilder extends JavaSourceBuilderBase<JavaSourceBuilder> { public static JavaSourceBuilder javaSource() { return new JavaSourceBuilder(); } public JavaSourceBuilder() { super(new com.sabre.buildergenerator.sourcegenerator.java.JavaSource()); } public com.sabre.buildergenerator.sourcegenerator.java.JavaSource build() { return getInstance(); } } @SuppressWarnings("unchecked") class JavaSourceBuilderBase<GeneratorT extends JavaSourceBuilderBase> { ...

}

The complete class source code : JavaSourceBuilder.java

Answer1:

I also had a look at the fluent-builders-generator but came to the same result. The generator part of the library is unfinished in sense that it won't compile. And even if you fix the JavaSourceBuilder problem using @Nassim MOUALEK's answer, you will fail later because the basic ReflectionUtiland SignatureUtil methods throw UnsupportedException. They are not implemented.

Anyways, this generator would have never worked. That's because you need the Builder on compile time, but the generator itself needs the compiled sources for introspection. If you are thinking about the maven build phases, this generator would be located at the generate-sources phase, in which the source code is not yet compiled. But the whole generator can only operate on already compiled classes.

Since the builders builder is an eclipse plugin, and is operating on source level, this concept works nicely with eclipse. That's most probably why the generator is unfinished.

If you are looking for a builder generator that actually works hava a look at pojobuilder. It uses the javax.annotation.processing.Processor to generate the builders on compile time.

Answer2:

After some manipulations, its looks that the project is not finished yet, but i succeed to run it whith some changes like:

p s class MethodParameterBuilderBase<GeneratorT extends MethodParameterBuilderBase> { ... }

to

p s class MethodParameterBuilderBase<GeneratorT extends ParameterMethodParameterBuilder> { .... }

this remove the compile exception

Recommend

  • How to run code sequentially with parse, in Android?
  • Why have a private constructor [duplicate]
  • Populatate the spinner from Firebase database
  • Efficient User-Agent Regex to find Safari in Python
  • Get Currently Active User in Android
  • What is the correct way to synchronize a shared, static object in Java?
  • Two Tables Serving as one Model in Rails
  • Find Previous month name using Calender or any classes that in java
  • Laravel: Getting Session ID oddly truncates when using foreach
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • how does System.Web.HttpRequest::PathInfo work?
  • Element.tagName for python not working
  • Bypass multiple inheritance in Java
  • Spring Cloud Microservice Architecture Confusion
  • presentShareDialogWithParams posts to FB wall, but callback handler results say error
  • gspread or such: help me get cell coordinates (not value)
  • How can I set a binding to a Combox in a UserControl?
  • SplFileObject error failed to open stream: No such file or directory
  • print() is showing quotation marks in results
  • Play WS (2.2.1): post/put large request
  • Refering to the class itself from within a class mehod in Objective C
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • how to adjust image in a panel in Java swing?
  • Highlight one bar in a series in highcharts?
  • Recording logins for password protected directories
  • how to do an event when i swipe from fragment to the other
  • req.body is undefined - nodejs
  • Possible to stop flickering java tooltip in heavyweight mode?
  • output of program is not same as passed argument
  • sending/ receiving email in Java
  • Javascript + PHP Encryption with pidCrypt
  • Calling of Constructors in a Java
  • PHP: When would you need the self:: keyword?
  • How to delete a row from a dynamic generate table using jquery?
  • Proper way to use connect-multiparty with express.js?
  • JTable with a ScrollPane misbehaving
  • Getting Messege Twice Using IMvxMessenger
  • Checking variable from a different class in C#
  • How can i traverse a binary tree from right to left in java?
  • How can I use threading to 'tick' a timer to be accessed by other threads?