Questions tagged [javapoet]

JavaPoet is a Java API for generating .java source files.

JavaPoet is a Java API for generating .java source files and is the successor to JavaWriter.

It is available on Github: https://github.com/square/javapoet

104 questions
0
votes
1 answer

Android code generation. Get child elements for parent element.

I have two annotations. @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface OmegaExtra { String value() default ""; } @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface OmegaExtraModel…
T. Roman
  • 322
  • 6
  • 14
0
votes
1 answer

JavaPOET - only classes have super classes, not INTERFACE

I am trying to generate code for JPA repository below using JavaPOET library but i am getting "only classes have super classes, not INTERFACE" error. @Repository public interface UserRepository extends PagingAndSortingRepository {…
mrgenco
  • 348
  • 2
  • 9
  • 27
0
votes
1 answer

Initialize a field of an interface in JavaPoet

Is there any way to generate a field which looks like this: public static final TableType NAMESPACE = new TableType() {}; I already generated this code: public static final TableType NAMESPACE;
LaaKii
  • 95
  • 11
0
votes
1 answer

Generate field of an interface by JavaPoet

Is there any way to generate a field like this: public static final TypedKey UM_USR = new TypedKey() {}; I didn't find any way to set the type of UM_USR to a generic interface.
LaaKii
  • 95
  • 11
0
votes
1 answer

How to force Javapoet to create UTF-8 Java source code?

Is there a way to write a com.squareup.javapoet.JavaFile to the file system and make sure the file always is encoded using UTF-8? Currently I am using com.squareup.javapoet.JavaFile#writeTo(java.io.File dir) but this uses the default encoding of the…
saw303
  • 8,051
  • 7
  • 50
  • 90
0
votes
1 answer

JavaPoet - Exception unexpected

So, I'm making a program that takes a Class Diagram and, using JavaPoet, converts it in Java code. The class Diagram is not written in UML, it's already modelled inside the program with java. Here is the code portion giving me problems: (parsing…
user7244619
0
votes
1 answer

In Javapoet, why "ClassName.bestGuess("int")" get error?

Is there a way to resolve the code? - for (FieldInfo fieldInfo : info.getResult()) { result.addField(FieldSpec.builder(ClassName.bestGuess(fieldInfo.getClazz()),fieldInfo.getName()) .addModifiers(Modifier.PRIVATE) .build() …
Jude95
  • 37
  • 3
0
votes
3 answers

Javapoet - TypeName - HashMap>> generation?

I'm studying Javapoet as candidate for some protocol model objects auto-generation. Grat API! question: Can I generate field of complicated type like: TypeName myType = HashMap>>; ? For example, if I want to…
Max
  • 5
  • 6
0
votes
2 answers

Add members to JavaPoet

I tried to create TestSuite in JavaPoet api. I have List with my junit classes in testClasses, so i want to add member annotation but addmember allow us to add only one object at time, so how i can add All…
0
votes
1 answer

Can't resolve method addModifiers in javapoet

I am generating a class using annotation processor in Android. For generating classes, I am using javapoet and it works fine when I use it in java project but in Android I can't access addModifiers method on TypeSpec TypeSpec clz =…
mallaudin
  • 4,744
  • 3
  • 36
  • 68
0
votes
3 answers

java.lang.ClassCastException String to JavaPoet.FieldSpec

I am using JavaPoet api for generating the source code. However, at some point I am fetching the require details from xml that is ready made string for creating fields then I save the string to Object and then I cast object to FieldSpec but it is…
Learner
  • 15
  • 1
  • 7
0
votes
1 answer

Compare JavaPoet ParameterSpec type with Java 8 AnnotatedType

I need to compare the annotated type of a field (or method parameter) with a ParameterSpec instance. The name of the parameter does not matter in this context. The context is somewhat related to the unresolved issue 136. The following tests are…
Sormuras
  • 8,491
  • 1
  • 38
  • 64
-1
votes
1 answer

How can I write Annotation member with using JavaPoet?

I want to generate an annotation with its members. The structure of annotation is public className (@Value("${topics.className.command}") String className){ } Because of $ sign I take error. Pls help me how can I write this structure? The places I…
-1
votes
1 answer

Javapoet: writing the same thing with less line of code (addModifiers)

So, I have this code (using the Javapoet Lib): if (myBeautifulBoolean) <-------------------------- theClass = TypeSpec.classBuilder(classe.getName()) …
user7244619
1 2 3 4 5 6
7