#How to mark a class as warning / unstable using a custom annotation

1 messages · Page 1 of 1 (latest)

hasty coyote
#

Hey đź‘‹ i basically want to make a custom annotation @NotFinished to mark a class as not finished
i was able to just make a marker annotation but i dont know how to make it have a warning on it

worn spokeBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
Hey đź‘‹ i basically want to make a custom annotation @NotFinished to mark a class as not finished i was able to just make a marker annotation but i dont know how to make it have a warning on it

interface as follows:

public @interface NotFinished {
    String value() default "";
}

Then you can simply apply this annotation to any class like this:

@NotFinished("This class is not fully implemented yet")
public class ExampleClass {
    // class implementation here
}

You can also check for this annotation at runtime using reflection if needed. Remember that annotations do not affect the behavior of your code, they are just metadata that you can use for documentation or custom processing. Also, make sure to communicate clearly with your team about the meaning of your custom annotations so everyone understands their purpose.

hasty coyote
#

that wont apply a warningn right..

plush seal
#

uh what exactly do you want to do
what is the goal? log some message if an unfinished class is used? or prevent using it completely?

formal seal
#

Do you want a warning during compilation or?

hasty coyote
#

you know like when u use deprecated methods it becomes yellow in intellij and shows a warning when u hover over them

#

i just want to make a warning like that

plush seal
#

ah well IDE integration is more effort

hasty coyote
#

o

#

can u not just mark a class as unstable?

plush seal
#

this might be helpful

#

you can probably match for your custom marker annotation

hasty coyote
#

thanks :3

torn spoke
#

I think something like checkerframework can be configured

#

or you could write an annotation processor

#

which would work as a plugin to javac and be able to emit warnings/errors

#

actually - this feels like a crazy fun project

hasty coyote
#

i cant lie i didnt thought it would be soo deep

#

i just wanted to add a fancy thing to my class

torn spoke
#

not too hard, but gotta learn stuff

torn spoke
#

let me make sure im right about that

hasty coyote
#
package io.github.unjoinable.skyblock.item.items;

import io.github.unjoinable.skyblock.annotations.NotFinished;

@NotFinished("A class purely for development purposes must not be used in production.")
public class TestSword {
}``` the class name speaks for it but ykk we gotta be out here being fancyy
#

ok lemme google chehckerframework

torn spoke
#

i might be wrong? idk

#

but this is a decent guide to the annotation processor thing

hasty coyote
#

ty

#

one thing i could figure out was using documented

#
@Documented
public @interface NotFinished {
    String value() default "";

}```
it would look like this then^
#

but i believe this is where i would be stopping for now since it was just a fancy tool i wanted

#

🤣

#
import java.lang.annotation.Documented;
@NotFinished("Unfinished class being unfinished be like...u get it?")
@Documented
public @interface NotFinished {
    String value() default "";

}```
formal seal
#

Out of curiousity, will you use this a lot more than the built in warnings for TODO and FIXME?

hasty coyote
hasty coyote
#

thanks :3

#

i guess they are what i need but i would still like to have a IDE warning which i will look into

pale steeple
#

Generally any form of the word 'todo' will get picked up by the IDE and if you have it set as a warning in the settings, it can be quite annoying.