In Project Annotation Proccessor

very short: Some classes are required by my annotation proccessor which when run first compiles the whole project to run which fails because of the classes that its generating missing in some other classes because they are loaded at the same time causing a chikcen egg problem. Running in different sub projects causes either a dependency loop or missing dependencies for some classes with dependencies. full explenation: I recently stumbled across annotation Proccessing and wrote one that works for my purposes as long as its in a different gradle project. However If I want to add something that utilises Classes from my main Code I need to change the location to that other class including that classes dependencies which is quite annoying. However I cant put it in the same project since parts of my code are generated using that annotation Proccessor. That means that the compilation which is needed before the processing fails since the imports to those auto generated classes fail since they are deleted on regeneration. meaning a chicken and egg problem. However the classes that use that generated code are not required by my processor. Meaning I basically would have to only compile the annotation processor first and then the classes as it needs them. After that the rest can be compiled. Question is how could I do that? any other way is also fine by me.
167 Replies
JavaBot
JavaBot3mo ago
This post has been reserved for your question.
Hey @Hype_the_Time! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st3mo ago
Split it into two modules you create one module containing the annotation processor and one module with the actual code using the annotation processor then the annotation processor doesn't run on itself
Hype_the_Time (PING ON REPLY)
problem is that i need some of the classes and i get a dependency loop if i implement import them in gradle. for some classes i can use a simple string refernce but for some i actually need to check the class. mainly to check whther a class extends a other one.
dan1st
dan1st3mo ago
Just only put the annotation processor code in the annotation processor module and make sure nothing in there needs the annotation processor and that the annotation processor doesn't need the other module annotation processors should ideally not run application code
Hype_the_Time (PING ON REPLY)
my code doesnt run it but it uses it for some generation logic. mainly it checks for fields of the annotated class and whether they extend a specific class. there are some reasons for checking the class rn. not aware for a fix of that (without class being defined)
dan1st
dan1st3mo ago
the annotation processor doesn't need to be dependent on these classes you can implement it without the class being present
dan1st
dan1st3mo ago
Why would you need it for compiling the annotation processor? the annotation processor can just use javax.processing APIs for accessing all the information it needs about application classes
Hype_the_Time (PING ON REPLY)
i dont need it to compile the proccessor. i need it for logic that is generated by the proccessor
dan1st
dan1st3mo ago
then what's the problem there? Do you want to process generated classes? You can do that it would just happen in a later round
Hype_the_Time (PING ON REPLY)
mainly was missing a way to access the classes. (right now) i was using com. squareup. javapoet and i got a type nullpointer due to it being unable to reference the class type due too it not being accessible for it. one sec i am changing it to be in a different project again and coppying the exact error
dan1st
dan1st3mo ago
yeah I think you can only access generated classes in consecutive rounds
Hype_the_Time (PING ON REPLY)
how do consecutive rounds work?
dan1st
dan1st3mo ago
javac performs multiple rounds of compilation. In each round, it calls process giving you information about what happened in the current round etc
Hype_the_Time (PING ON REPLY)
basically i need to wait until a certain level and skip till then?
dan1st
dan1st3mo ago
What do you need JDA's Button import for? what are you waiting for? if one generated class depends on another, you need to make sure you are generating the required class in the same round or before What in there needs another class?
Hype_the_Time (PING ON REPLY)
i made a own button class and i generate some code based on it for conevniency. I was reworking it because my handler had like 2k lines. a bit long.
dan1st
dan1st3mo ago
so what's the problem with generating code based on your button class? Does your custom button class need the annotation processor for anything?
Hype_the_Time (PING ON REPLY)
List<VariableElement> buttonOptions = typeElement.getEnclosedElements().stream()
.filter(e -> e.getKind() == ElementKind.FIELD)
.filter(e -> processingEnv.getTypeUtils()
.isAssignable(e.asType(), processingEnv.getElementUtils()
.getTypeElement("de.hype.bbsentials.server.discord.options.AbstractButtonOption")
.asType())) // Match subclasses of AbstractButtonOption<T>
.map(e -> (VariableElement) e)
.filter(e -> processingEnv.getTypeUtils()
.isAssignable(e.asType(), processingEnv.getElementUtils()
.getTypeElement("de.hype.bbsentials.server.discord.options.AbstractButtonOption")
.asType())) // Match subclasses of AbstractButtonOption<T>
.map(e -> (VariableElement) e)
.toList();
List<VariableElement> buttonOptions = typeElement.getEnclosedElements().stream()
.filter(e -> e.getKind() == ElementKind.FIELD)
.filter(e -> processingEnv.getTypeUtils()
.isAssignable(e.asType(), processingEnv.getElementUtils()
.getTypeElement("de.hype.bbsentials.server.discord.options.AbstractButtonOption")
.asType())) // Match subclasses of AbstractButtonOption<T>
.map(e -> (VariableElement) e)
.filter(e -> processingEnv.getTypeUtils()
.isAssignable(e.asType(), processingEnv.getElementUtils()
.getTypeElement("de.hype.bbsentials.server.discord.options.AbstractButtonOption")
.asType())) // Match subclasses of AbstractButtonOption<T>
.map(e -> (VariableElement) e)
.toList();
abstract button option assignable
dan1st
dan1st3mo ago
Is that what's failing?
stechy1
stechy13mo ago
Hi, if you have some code used in a production code and also in annotations processor, you can extract it to a separated module...
Hype_the_Time (PING ON REPLY)
not 100% sure since i dont have line of error in my stacktrace cause i am not able to debug it etc but i am pretty sure that it is this. happened after i added it. recursive dependencies (code in it requiring dependecy which then requires a different class....) gets pretty annoying but yes. daniels rounds seems very promising so far from what i cought up which is saying nothing tbh.
dan1st
dan1st3mo ago
From the Javadoc:
To be robust when running in different tool implementations, an annotation processor should have the following properties: The result of processing a given input is not a function of the presence or absence of other inputs (orthogonality). Processing the same input produces the same output (consistency). Processing input A followed by processing input B is equivalent to processing B then A (commutativity) Processing an input does not rely on the presence of the output of other annotation processors (independence)
https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/annotation/processing/Processor.html
Processor (Java SE 21 & JDK 21)
declaration: module: java.compiler, package: javax.annotation.processing, interface: Processor
dan1st
dan1st3mo ago
When does it crash? Why can't you debug it? Does the annotation processor/compilation crash or does running the application crash? you might want to follow that since not doing so may be annoying/cause unexpected things to happen and if you need some things to be processed before others, you could also ensure that they are in different modules with the one that should be processed later being dependent on the one that should be processed earlier If you want to debug the annotation processor itself, that should be possible in Maven, you can just run mvnDebug instead of mvn and attach a debugger it probably works similar with Gradle
Hype_the_Time (PING ON REPLY)
i tried bootjar (due too spring) with debug in intelij but it never hit a breakpoiint even at the start of process etc
dan1st
dan1st3mo ago
you need to attach a debugger to the compilation in Maven, you'd need to run mvnDebug
dan1st
dan1st3mo ago
Stack Overflow
how do you debug java annotation processors using intellij?
How do you debug java annotation processors using intellij? Preferably using IDEA IntelliJ. I tried setting a breakpoint inside the processor and running but it did not break.
dan1st
dan1st3mo ago
Stack Overflow
how do you debug java annotation processors using intellij?
How do you debug java annotation processors using intellij? Preferably using IDEA IntelliJ. I tried setting a breakpoint inside the processor and running but it did not break.
dan1st
dan1st3mo ago
and also others
Hype_the_Time (PING ON REPLY)
got debugging to work. Cannot invoke "javax.lang.model.element.TypeElement.asType()" because the return value of "javax.lang.model.util.Elements.getTypeElement(java.lang.CharSequence)" is null
List<VariableElement> buttonOptions = typeElement.getEnclosedElements().stream()
.filter(e -> e.getKind() == ElementKind.FIELD)
.filter(e -> processingEnv.getTypeUtils()
.isAssignable(e.asType(), processingEnv.getElementUtils()
.getTypeElement("de.hype.bbsentials.server.discord.options.AbstractButtonOption")
.asType())) // Match subclasses of AbstractButtonOption<T>
.map(e -> (VariableElement) e)
.filter(e -> processingEnv.getTypeUtils()
.isAssignable(e.asType(), processingEnv.getElementUtils()
.getTypeElement("de.hype.bbsentials.server.discord.options.AbstractButtonOption")
.asType())) // Match subclasses of AbstractButtonOption<T>
- .toList();
List<VariableElement> buttonOptions = typeElement.getEnclosedElements().stream()
.filter(e -> e.getKind() == ElementKind.FIELD)
.filter(e -> processingEnv.getTypeUtils()
.isAssignable(e.asType(), processingEnv.getElementUtils()
.getTypeElement("de.hype.bbsentials.server.discord.options.AbstractButtonOption")
.asType())) // Match subclasses of AbstractButtonOption<T>
.map(e -> (VariableElement) e)
.filter(e -> processingEnv.getTypeUtils()
.isAssignable(e.asType(), processingEnv.getElementUtils()
.getTypeElement("de.hype.bbsentials.server.discord.options.AbstractButtonOption")
.asType())) // Match subclasses of AbstractButtonOption<T>
- .toList();
fails when i continue after toList()
dan1st
dan1st3mo ago
seems like de.hype.bbsentials.server.discord.options.AbstractButtonOption is not available Is that class generated?
Hype_the_Time (PING ON REPLY)
hm package seemed to be wrong probably happened during a refecactor
dan1st
dan1st3mo ago
well that explains it lol
Hype_the_Time (PING ON REPLY)
while compilation didnt work again i expect these errors that i see right now. those are from other places which i still need to fix. some due too outcommented stuff. maybe there is one hiding some where in those error but for now seems to be done tyvm @dan1st | Daniel
dan1st
dan1st3mo ago
ok if you have more questions about annotation processors, you can continue asking here or create a new post and ping me (you can ping me for other annotation processing related questions, please not necessarily for other questions)
Hype_the_Time (PING ON REPLY)
yeah was ware. i would close it but i want to keep it open until ik its done. if i remeber by then ill close it
dan1st
dan1st3mo ago
if you don't, it isn't much of an issue
Hype_the_Time (PING ON REPLY)
very much aware
JavaBot
JavaBot3mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Hype_the_Time (PING ON REPLY)
@dan1st | Daniel Sorry for the german error message but thats what the compiler gives out to me. otherwise would have used english. normally i know what the problem is due too the stacktrace but I didnt find any code in it thats by me. I am also confused since my log is basically telling me its happeneing after me proccessing. cutted log. last round: Hinweis: Generating start Hinweis: Generating done Hinweis: Modal Processing start Hinweis: Modal Processing done
Im Compiler (21.0.3) ist eine Ausnahme aufgetreten. Erstellen Sie auf der Java-Seite zum Melden von Bugs (https://bugreport.java.com) einen Bugbericht, nachdem Sie die Bugdatenbank (https://bugs.java.com) auf Duplikate geprüft haben. Geben Sie in Ihrem Bericht Ihr Programm, die folgende Diagnose und die Parameter an, die Sie dem Java-Compiler übergeben haben. Vielen Dank.
java.lang.StackOverflowError
at jdk.compiler/com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4980)
at jdk.compiler/com.sun.tools.javac.code.Types$Rewriter.visitClassType(Types.java:4739)
at jdk.compiler/com.sun.tools.javac.code.Types$Rewriter.visitClassType(Types.java:4724)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1050)
at jdk.compiler/com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4980)
at jdk.compiler/com.sun.tools.javac.code.Types$Rewriter.visitTypeVar(Types.java:4771)
at jdk.compiler/com.sun.tools.javac.code.Types$Rewriter.visitTypeVar(Types.java:4724)
at jdk.compiler/com.sun.tools.javac.code.Type$TypeVar.accept(Type.java:1705)
Im Compiler (21.0.3) ist eine Ausnahme aufgetreten. Erstellen Sie auf der Java-Seite zum Melden von Bugs (https://bugreport.java.com) einen Bugbericht, nachdem Sie die Bugdatenbank (https://bugs.java.com) auf Duplikate geprüft haben. Geben Sie in Ihrem Bericht Ihr Programm, die folgende Diagnose und die Parameter an, die Sie dem Java-Compiler übergeben haben. Vielen Dank.
java.lang.StackOverflowError
at jdk.compiler/com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4980)
at jdk.compiler/com.sun.tools.javac.code.Types$Rewriter.visitClassType(Types.java:4739)
at jdk.compiler/com.sun.tools.javac.code.Types$Rewriter.visitClassType(Types.java:4724)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1050)
at jdk.compiler/com.sun.tools.javac.code.Types$UnaryVisitor.visit(Types.java:4980)
at jdk.compiler/com.sun.tools.javac.code.Types$Rewriter.visitTypeVar(Types.java:4771)
at jdk.compiler/com.sun.tools.javac.code.Types$Rewriter.visitTypeVar(Types.java:4724)
at jdk.compiler/com.sun.tools.javac.code.Type$TypeVar.accept(Type.java:1705)
I expect the button annotation porccessor to generate bad code rn. but commenting out the last change that is causing bad code isnt fixing this error seemingly. I tried gradle reload and clean.
Hype_the_Time (PING ON REPLY)
I did find something which is causing a suspicion though:
public abstract class AbstractDiscordInteractionImplementation<Event extends BBDiscordInteractionEvent<?, EphemeralPolicy>, EphemeralPolicy extends IEphemeralPolicy<Event>> {
public abstract class AbstractDiscordInteractionImplementation<Event extends BBDiscordInteractionEvent<?, EphemeralPolicy>, EphemeralPolicy extends IEphemeralPolicy<Event>> {
thats linking between each other. its a first idea i will try to have a look at
dan1st
dan1st3mo ago
looks like either something within the annotation processor overflows or it generates code for generated code from generated code etc so you'd be stuck in an "infinite" loop of generating code until it overflows
Hype_the_Time (PING ON REPLY)
can you tell whether this is deffenetley not it then?
dan1st
dan1st3mo ago
Did you attach a debugger to the compilation process?
Hype_the_Time (PING ON REPLY)
i attached ones at the try catches in both of the processors. they did not activate but were attached
dan1st
dan1st3mo ago
Is there maybe generated code using it? Is EphemeralPolicy or IEphemeralPolicy using it? Were you able to step through?
Hype_the_Time (PING ON REPLY)
it paused if i set it withing the code
dan1st
dan1st3mo ago
Is there any generated code using that class? ok so it happens after all the process() calls, right?
Hype_the_Time (PING ON REPLY)
in the log i provided there is some logging that for me looks like its after the proccessing of the annotation processors full-log.txt
dan1st
dan1st3mo ago
Can you verify that with the debugger? You can use roundEnv.processingOver()
Hype_the_Time (PING ON REPLY)
dont know in which way you mean. will need it more specific for what to test
dan1st
dan1st3mo ago
Does that return true in a round before the exception? Does process() finish before it?
dan1st
dan1st3mo ago
the compiler calls process() any number of times. The last time, processingOver() should return true
Hype_the_Time (PING ON REPLY)
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generating done");
if (roundEnv.processingOver()){
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Processing over");
}
return true;
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generating done");
if (roundEnv.processingOver()){
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Processing over");
}
return true;
like this?
dan1st
dan1st3mo ago
yes
dan1st
dan1st3mo ago
Is that printed?
Hype_the_Time (PING ON REPLY)
it activates
dan1st
dan1st3mo ago
My guess is that you are generating invalid code in some way yeah I see looks like something is referencing itself maybe if you think it's that, maybe skip generating that class if that resolves the issue, generate it but without any methods (assuming you are currently generating it with methods)
Hype_the_Time (PING ON REPLY)
I dont know of how to descirbve it very well but simply all classes annoated in some way extend that class. i will have to search for a solution to test for it.
dan1st
dan1st3mo ago
Can you change it to public class ...<Event, EphemeralPolicy> without any bounds? for testing? but yeah idk whether generating a superclass is possible interfaces might work though
Hype_the_Time (PING ON REPLY)
no they always extend that class. that class itself never gets generated. no class extends this one directley but they usually have another class in between I dont think so since its more complicated. i have to find a actual soltuion bercause theres quite a lot of usages. working on it
dan1st
dan1st3mo ago
that doesn't make it better whatever you do: make sure there are absolutely no circles/circular dependencies at compile time
Hype_the_Time (PING ON REPLY)
oh so this would be a issue that only comes if a annotation processor is used?
dan1st
dan1st3mo ago
maybe unlikely but possible maybe you also have a case of something like A extends B extends A which is never allowed Do you have any generated class with more than 100 members?
Hype_the_Time (PING ON REPLY)
would have been surprised too. when i was making it i was like oh intelij isnt sayin g no? strange. wouldnt expect that this is possible lets do it if its possible tho 100 members? wdym
dan1st
dan1st3mo ago
Do you have any generated method (including constructors and initializers) with more than 100 method calls (e.g. a().b().c() - this is known to cause StackOverflowErrors during compilation) methods, fields, inner classes, etc you can view the generated code somewhere in the build directory
Hype_the_Time (PING ON REPLY)
I doubt it. I got a fix for the type refernce loop idea i had and now its throwing other errors but ones that I can work iwth.
dan1st
dan1st3mo ago
also you can enable more detailed logging within javac - that should give you information on what type it was compiling that caused the issue that may be useful in general when you get weird errors in javac
Hype_the_Time (PING ON REPLY)
uhhhhhh a) what argument b) will take time to find in intelij because i doubt that its easily possible for me outside due too dependencies that are handled by gradle etc
dan1st
dan1st3mo ago
a) if you get a weird error from javac, you can enable that logging for inside javac - I think that should tell you what javac is compiling and when b) I think you can tell Gradle what to CLI options to pass to javac
dan1st
dan1st3mo ago
Does your annotation processor run before or after the Klasse ... wird geprüft logs? seems like the error occurs after compiling you could try using a different compiler instead of javac - for example EJC maybe that gives you a better error message
Hype_the_Time (PING ON REPLY)
no clue on how to check. also its ~ 11pm rn so I should probably cool down for today and go sleep and continue tomorrow.
dan1st
dan1st3mo ago
I think Gradle can be configured to use EJC if you want to try that might not work well though - just for testing and for it being 11pm: I'm in CEST as well
Hype_the_Time (PING ON REPLY)
I mean we all know staying up till like 2 or 3 am but was programming a lot today so kinda exhausted as well. Also gn.
dan1st
dan1st3mo ago
xd
JavaBot
JavaBot3mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Hype_the_Time (PING ON REPLY)
+ import org.gradle.api.tasks.compile.JavaCompile
...
+ tasks.withType<JavaCompile> {
+ options.compilerArgs.addAll(listOf("-Xlint:all", "-verbose"))
+ options.forkOptions.executable = "ecj"
+ }
+ import org.gradle.api.tasks.compile.JavaCompile
...
+ tasks.withType<JavaCompile> {
+ options.compilerArgs.addAll(listOf("-Xlint:all", "-verbose"))
+ options.forkOptions.executable = "ecj"
+ }
Hype_the_Time (PING ON REPLY)
will have a look now you might be onto something there. but will need a clearer instruction on how to check.
dan1st
dan1st3mo ago
that's not actually using EJC
Hype_the_Time (PING ON REPLY)
what do i need to change?
dan1st
dan1st3mo ago
you might need to tell gradle to fork the conpiler
dan1st
dan1st3mo ago
Stack Overflow
Gradle: How to compile Java by eclipse ECJ (JDT core) by running Gr...
I have a project that can be build well by eclipse (ECJ) But Oracle javac can't build it (some reasons like in link: the different of ecj and javac). I would like moving from eclipse to build by G...
dan1st
dan1st3mo ago
Are you compiling Kotlin code? if you want to use EJC, you'd need to do something like that I think
compileJava {
options.fork = true
options.forkOptions.with {
executable = 'java'
jvmArgs = ['-classpath', project.configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main', '-nowarn']
}
}
compileJava {
options.fork = true
options.forkOptions.with {
executable = 'java'
jvmArgs = ['-classpath', project.configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main', '-nowarn']
}
}
but it's fine if it doesn't work
Hype_the_Time (PING ON REPLY)
i use gradle dsl aka kotlin gradle. uses other ways to reference stuff. under that assumption I assume it can be converted to:
tasks.named<JavaCompile>("compileJava") {
options.isFork = true
options.forkOptions.apply {
executable = "java"
jvmArgs = listOf("-classpath", project.configurations.getByName("ecj").asPath, "org.eclipse.jdt.internal.compiler.batch.Main", "-nowarn")
}
}
tasks.named<JavaCompile>("compileJava") {
options.isFork = true
options.forkOptions.apply {
executable = "java"
jvmArgs = listOf("-classpath", project.configurations.getByName("ecj").asPath, "org.eclipse.jdt.internal.compiler.batch.Main", "-nowarn")
}
}
however The configured executable does not exist (/home/spieler/.gradle/daemon/8.5/java)
dan1st
dan1st3mo ago
hm, interesting yeah idk that much about gradle
Hype_the_Time (PING ON REPLY)
same the executeable java is casuing the problem i assume it would be fine if i just say nothing so it uses default aka whatever it needs?
dan1st
dan1st3mo ago
you can maybe set executable = "java" to executable = "/usr/lib/jvm/YOUR_JDK/bin/java" or similar for testing or don't do the tests with EJC
Hype_the_Time (PING ON REPLY)
what then?
dan1st
dan1st3mo ago
you could create a copy of the project and remove everything you don't need for reproducing the issue (you can use git to save your state) until you have a truly minimal reproducer
Suika
Suika3mo ago
2024-12-24T16:24:50.060+0100 [ERROR] [system.err] Unrecognized option : -Dfile.encoding=UTF-8
tasks.named<JavaCompile>("compileJava") {
options.isFork = true
options.forkOptions.apply {
jvmArgs = listOf("-classpath", project.configurations.getByName("ecj").asPath, "org.eclipse.jdt.internal.compiler.batch.Main", "-nowarn")
}
}
tasks.named<JavaCompile>("compileJava") {
options.isFork = true
options.forkOptions.apply {
jvmArgs = listOf("-classpath", project.configurations.getByName("ecj").asPath, "org.eclipse.jdt.internal.compiler.batch.Main", "-nowarn")
}
}
This message has been formatted automatically. You can disable this using /preferences.
dan1st
dan1st3mo ago
that's interesting
Hype_the_Time (PING ON REPLY)
i mean lets say it this way i did find something
dan1st
dan1st3mo ago
Did you remove the executable = "java" completely?
Hype_the_Time (PING ON REPLY)
wait how is this done? yes
dan1st
dan1st3mo ago
the bot detected that you posted some code and used a codeblock
Hype_the_Time (PING ON REPLY)
no but that its a app with same name and icon
dan1st
dan1st3mo ago
it's a new message sent with a webhook
Hype_the_Time (PING ON REPLY)
like webhooks have limits etc how do you handle the limitations from discord side regarding count tho
dan1st
dan1st3mo ago
What limits are you talking about specifically?
Hype_the_Time (PING ON REPLY)
like max ones to exist or sth
dan1st
dan1st3mo ago
it's only one per channel you can set the name for every message within the message same for the profile picture
Hype_the_Time (PING ON REPLY)
wait you can set those with webhooks?
dan1st
dan1st3mo ago
yes
JavaBot
JavaBot3mo ago
WebhookMessageBuilder message = new WebhookMessageBuilder().setContent(newMessageContent)
.setAllowedMentions(AllowedMentions.none())
.setAvatarUrl(transformOrNull(member, Member::getEffectiveAvatarUrl))
.setUsername(transformOrNull(member, Member::getEffectiveName));
WebhookMessageBuilder message = new WebhookMessageBuilder().setContent(newMessageContent)
.setAllowedMentions(AllowedMentions.none())
.setAvatarUrl(transformOrNull(member, Member::getEffectiveAvatarUrl))
.setUsername(transformOrNull(member, Member::getEffectiveName));
Hype_the_Time (PING ON REPLY)
welp i will for sure have a look at that i was looking for something like that
dan1st
dan1st3mo ago
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
No description
Hype_the_Time (PING ON REPLY)
do you know whether jda has this supported?
dan1st
dan1st3mo ago
we also do a bit of fun with it - for example if you post a message containing "fuck"
Hype_the_Time (PING ON REPLY)
or will i need to use a library / self programm test fuck fuck
dan1st
dan1st3mo ago
What?
Hype_the_Time (PING ON REPLY)
lets try again fuck
dan1st
dan1st3mo ago
maybe that one doesn't like threads nothing weird in the logs and also not overloaded - idk I'd need to check this is what happens: https://canary.discord.com/channels/648956210850299986/653633234898255943/1321138299951251549
Suika
Suika3mo ago
hugging test
Hype_the_Time (PING ON REPLY)
ic good to know will work on it also back to topic
dan1st
dan1st3mo ago
anyway when I create a minimal reproducer like that, you can do the following: - Create a new local branch (or a copy of the project and git init) - Make sure everything is committed - Remove parts of the project where you think the issue would still occur (you can remove like half of the project at once) - If the issue still occurs, commit - If it doesn't, checkout/revert to the previous state - repeat that's what I typically do I did that with bugs where it fails during a native-image compilation which takes like 30min to compile on a somewhat decently-sized project
Hype_the_Time (PING ON REPLY)
btw i was able to find something sus related already yestrday. maybe you missed me saying it. due to git and it "only" being 2 commits i went back those 2 and it worked again. during that the type loop was noticied by me. when i went in and changed it to sth different which isnt as great but still decent i do not get that javacompiler error anymore
dan1st
dan1st3mo ago
Do you know what exactly is the loop? you could also create a new project with only the type loop and check whether you can reproduce it
Hype_the_Time (PING ON REPLY)
<Event extends BBDiscordInteractionEvent<?, EphemeralPolicy>, EphemeralPolicy extends IEphemeralPolicy<Event> event requires ephermeral but ephermeral requeires event
dan1st
dan1st3mo ago
that compiles for me
No description
Hype_the_Time (PING ON REPLY)
could it help if we go into a vc or sth so i can screenshare? wait will need to wait tho forgot about something but option later. maybe in an hour or 2 does it work with a annotation processor?
dan1st
dan1st3mo ago
didn't test it
Hype_the_Time (PING ON REPLY)
might be important
dan1st
dan1st3mo ago
yeah
Hype_the_Time (PING ON REPLY)
hm is this important maybe? public enum ActionEphemeralPolicy implements IEphemeralPolicy<BBDiscordInteractionEvent<?, ?>> { public interface IEphemeralPolicy<Event extends BBDiscordInteractionEvent<?, ?>> { might be important of how they work togeter basically my goal was to say hey this event will use yourself as this type
dan1st
dan1st3mo ago
Can you show the signature of an implementation?
dan1st
dan1st3mo ago
Something extending the generated class
Hype_the_Time (PING ON REPLY)
check your dms
dan1st
dan1st3mo ago
i don't even have any JetBrains IDE installed
dan1st
dan1st3mo ago
I can try reproducing it later with an annotation processor
Hype_the_Time (PING ON REPLY)
i dont knwo of how to describe it very well its a complex construct i would say
dan1st
dan1st3mo ago
but it may be useful to have one of the classes extending the generated abstract class
Suika
Suika3mo ago
public abstract class AbstractDiscordInteractionImplementation<Event extends BBDiscordInteractionEvent<?, EphemeralPolicy>, EphemeralPolicy extends IEphemeralPolicy<BBDiscordInteractionEvent<?, ?>>> {

public abstract class AbstractButtonImplementation extends AbstractDiscordInteractionImplementation<BBButtonInteractionEvent, BBActionInteractionEvent.ActionEphemeralPolicy> {

@DiscordButtonImplementation(id = "ticket-accept-role", name = "Accept", buttonStyle = net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle.SUCCESS)
public abstract class AcceptTicketButtonImplementation extends AbstractButtonImplementation {

generated:

public class AcceptTicketButton extends AbstractButtonImplementation.ButtonInstance {
public AcceptTicketButton(String name, ButtonStyle style) {
super(Button.of(style, "ticket-accept-role", name));
}

public AcceptTicketButton() {
this("Accept", ButtonStyle.SUCCESS);
}

public static class AcceptTicketExecutor extends AcceptTicketButtonImplementation {
@Override
protected void execute(BBButtonInteractionEvent event, Core core) throws OnCooldownException,
SQLException, NoDiscordAvailable, ExternalAPIError, ExecutionException,
InterruptedException, ProfileDoesNotExistException, NoBingoDataException, IOException,
InvalidInputException {
super.execute(event, core);
}
}
}
public abstract class AbstractDiscordInteractionImplementation<Event extends BBDiscordInteractionEvent<?, EphemeralPolicy>, EphemeralPolicy extends IEphemeralPolicy<BBDiscordInteractionEvent<?, ?>>> {

public abstract class AbstractButtonImplementation extends AbstractDiscordInteractionImplementation<BBButtonInteractionEvent, BBActionInteractionEvent.ActionEphemeralPolicy> {

@DiscordButtonImplementation(id = "ticket-accept-role", name = "Accept", buttonStyle = net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle.SUCCESS)
public abstract class AcceptTicketButtonImplementation extends AbstractButtonImplementation {

generated:

public class AcceptTicketButton extends AbstractButtonImplementation.ButtonInstance {
public AcceptTicketButton(String name, ButtonStyle style) {
super(Button.of(style, "ticket-accept-role", name));
}

public AcceptTicketButton() {
this("Accept", ButtonStyle.SUCCESS);
}

public static class AcceptTicketExecutor extends AcceptTicketButtonImplementation {
@Override
protected void execute(BBButtonInteractionEvent event, Core core) throws OnCooldownException,
SQLException, NoDiscordAvailable, ExternalAPIError, ExecutionException,
InterruptedException, ProfileDoesNotExistException, NoBingoDataException, IOException,
InvalidInputException {
super.execute(event, core);
}
}
}
This message has been formatted automatically. You can disable this using /preferences.
Hype_the_Time (PING ON REPLY)
+ public interface IEphemeralPolicy<Event extends BBDiscordInteractionEvent<?, ?>> {
dan1st
dan1st3mo ago
What exactly is the signature of BBDiscordInteractionEvent?
Hype_the_Time (PING ON REPLY)
public abstract class BBDiscordInteractionEvent<T extends GenericInteractionCreateEvent & IReplyCallback, EphemeralPolicy> extends GenericInteractionCreateEvent implements IReplyCallback { the events etc come from discord jda
dan1st
dan1st3mo ago
for reproducing later
class GenericInteractionCreateEvent{}
interface IReplyCallback{}

//BBDiscordInteractionEvent is forward declared
public interface IEphemeralPolicy<Event extends BBDiscordInteractionEvent<?, ?>> {}

//generated
public abstract class BBDiscordInteractionEvent<T extends GenericInteractionCreateEvent & IReplyCallback, EphemeralPolicy> extends GenericInteractionCreateEvent implements IReplyCallback {}
class GenericInteractionCreateEvent{}
interface IReplyCallback{}

//BBDiscordInteractionEvent is forward declared
public interface IEphemeralPolicy<Event extends BBDiscordInteractionEvent<?, ?>> {}

//generated
public abstract class BBDiscordInteractionEvent<T extends GenericInteractionCreateEvent & IReplyCallback, EphemeralPolicy> extends GenericInteractionCreateEvent implements IReplyCallback {}
public abstract class AbstractDiscordInteractionImplementation<Event extends BBDiscordInteractionEvent<?, EphemeralPolicy>, EphemeralPolicy extends IEphemeralPolicy<BBDiscordInteractionEvent<?, ?>>> {//THIS IS QUESTIONABLE - should probably be IEphemeralPolicy<? extends BBDiscordInteractionEvent<?, ?>> or IEphemeralPolicy<Event>
public class ButtonInstance{}
}

class DEvt extends GenericInteractionCreateEvent implements IReplyCallback{}
class BBActionInteractionEvent extends BBDiscordInteractionEvent<DEvt, BBActionInteractionEvent.ActionEphemeralPolicy>{
interface ActionEphemeralPolicy extends IEphemeralPolicy<BBDiscordInteractionEvent<?,?>>{}
}

class BBButtonInteractionEvent extends BBDiscordInteractionEvent<DEvt, BBActionInteractionEvent.ActionEphemeralPolicy>{}
public abstract class AbstractButtonImplementation extends AbstractDiscordInteractionImplementation<BBButtonInteractionEvent, BBActionInteractionEvent.ActionEphemeralPolicy> {
static class ButtonInstance{}
}

public abstract class AcceptTicketButtonImplementation extends AbstractButtonImplementation {}

//generated
public class AcceptTicketButton extends AbstractButtonImplementation.ButtonInstance {
public AcceptTicketButton() {
}

public static class AcceptTicketExecutor extends AcceptTicketButtonImplementation {
}
}
public abstract class AbstractDiscordInteractionImplementation<Event extends BBDiscordInteractionEvent<?, EphemeralPolicy>, EphemeralPolicy extends IEphemeralPolicy<BBDiscordInteractionEvent<?, ?>>> {//THIS IS QUESTIONABLE - should probably be IEphemeralPolicy<? extends BBDiscordInteractionEvent<?, ?>> or IEphemeralPolicy<Event>
public class ButtonInstance{}
}

class DEvt extends GenericInteractionCreateEvent implements IReplyCallback{}
class BBActionInteractionEvent extends BBDiscordInteractionEvent<DEvt, BBActionInteractionEvent.ActionEphemeralPolicy>{
interface ActionEphemeralPolicy extends IEphemeralPolicy<BBDiscordInteractionEvent<?,?>>{}
}

class BBButtonInteractionEvent extends BBDiscordInteractionEvent<DEvt, BBActionInteractionEvent.ActionEphemeralPolicy>{}
public abstract class AbstractButtonImplementation extends AbstractDiscordInteractionImplementation<BBButtonInteractionEvent, BBActionInteractionEvent.ActionEphemeralPolicy> {
static class ButtonInstance{}
}

public abstract class AcceptTicketButtonImplementation extends AbstractButtonImplementation {}

//generated
public class AcceptTicketButton extends AbstractButtonImplementation.ButtonInstance {
public AcceptTicketButton() {
}

public static class AcceptTicketExecutor extends AcceptTicketButtonImplementation {
}
}
JavaBot
JavaBot3mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
dan1st
dan1st3mo ago
bot, this is active - I'm testing
Hype_the_Time (PING ON REPLY)
how did THAT happen
dan1st
dan1st3mo ago
I reopened the post without sending a message and there was no message within 300min
Hype_the_Time (PING ON REPLY)
i sent messages in here previously tho and insta deleted and it stayed open for a while at least
dan1st
dan1st3mo ago
yeah I didn't
Hype_the_Time (PING ON REPLY)
strange. whatever
dan1st
dan1st3mo ago
anyways that compiles without an annotation processor but note the comment here:
public abstract class AbstractDiscordInteractionImplementation<Event extends BBDiscordInteractionEvent<?, EphemeralPolicy>, EphemeralPolicy extends IEphemeralPolicy<BBDiscordInteractionEvent<?, ?>>> {//THIS IS QUESTIONABLE - should probably be IEphemeralPolicy<? extends BBDiscordInteractionEvent<?, ?>> or IEphemeralPolicy<Event>
public class ButtonInstance{}
}
public abstract class AbstractDiscordInteractionImplementation<Event extends BBDiscordInteractionEvent<?, EphemeralPolicy>, EphemeralPolicy extends IEphemeralPolicy<BBDiscordInteractionEvent<?, ?>>> {//THIS IS QUESTIONABLE - should probably be IEphemeralPolicy<? extends BBDiscordInteractionEvent<?, ?>> or IEphemeralPolicy<Event>
public class ButtonInstance{}
}
I took that code from you it doesn't even care about deleted messages it checks every 10min and if there are no recent messages, it marks it as "dormant"
Hype_the_Time (PING ON REPLY)
i am not an expert but my goal was to tell it you can exoect this event. but one of my classes also needs to know which ephermeral policy to use so i needed to tell it that, but the epeehermreal policy also needs to know that it can expct itself for equal and which event it can expect which is kinda cusing a loop if done like it. instance of can work as a replacement but i dont like it as much
dan1st
dan1st3mo ago
Does it expect an IEphemeralPolicy<BBDiscordInteractionEvent<?, ?>> but does not allow IEphemeralPolicy<SomeSubclassOfBBDiscordInteractionEvent<?, ?>>? IEphemeralPolicy<BBDiscordInteractionEvent<?, ?>> means that the type parameter must be exactly BBDiscordInteractionEvent - not any subclass and not any superclass
dan1st
dan1st3mo ago
Stack Overflow
Is List a subclass of List? Why are Java generics not implicitly po...
I'm a bit confused about how Java generics handle inheritance / polymorphism. Assume the following hierarchy - Animal (Parent) Dog - Cat (Children) So suppose I have a method doSomething(List<
Hype_the_Time (PING ON REPLY)
hm might be important
dan1st
dan1st3mo ago
yeah - I'm telling you because I noticed that there
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
dan1st
dan1st2mo ago
Alternatively you could try the following: - The compilation that fails still generates the source files from the annotation processor. - You can try running javac with -proc:none (no annotation processor) and compile both the sources and the generated sources together I was able to compile that using an annotation processor generating the marked parts without issues
dan1st
dan1st2mo ago
so I guess it's something else
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Hype_the_Time (PING ON REPLY)
i found a easy work around that is way simpler. it called: Simply use a abstract method that returns a boolean and let the super class define the rest. when you then use a extend class architecture you define it once and it works everywhere else anyway. worked on sth else for a bit but are resuming now on this part. anyway ty for your time. was very much appreciated.
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?