hnOsmium0001

JMeta usage example v1

May 6th, 2020
890
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Meta({
  2.     @Do(
  3.         // Possible values: ModifyStatements.Type.{
  4.         //     REMOVE_STATEMENT, ADD_METHOD, REMOVE_METHOD, ADD_FIELD, REMOVE_FIELD, GENERATE_CLASS
  5.         // }
  6.         // Note that there is no task for manipulating subclasses because subclasses are not actually "sub"classes
  7.         type = ModifyStatements.Type.APPEND_STATEMENT,
  8.         // These fields are (mostly) specific to ModifyStatements.Type.APPEND
  9.         to = @SelectEntity("<staticInit>"), // <staticInit> is a special way to refer to it created by JMeta
  10.         // All sequences contain entities
  11.         statements = @Statements(
  12.             source = @SelectEntity(value = MetaEntities.FIELDS, target = Block.class),
  13.             operations = {
  14.                 // `expr` and `clazz` are specific to some types as well
  15.                 @Op(type = Op.Type.FILTER_INSTANCEOF, expr = @InstanceOf(expr = @TypeOfEntity, clazz = Block.class)),
  16.             },
  17.             // Finalize refers to a @MetaStatement method in the current class. The method must recieve the results' type
  18.             // from previous processing steps (field -> MetaField<T>, method -> MetaMethod)
  19.             finalize = "addBlockStatement"
  20.         )
  21.     )
  22. })
  23. class MetaProgrammingExample {
  24.     static {} // For @SelectEntity("<staticInit>"), technically not needed because java compiler auto-generates them
  25.  
  26.     public static final List<Block> BLOCKS = new ArrayList<>();
  27.  
  28.     // Excludes this method in the final output
  29.     // All usages of @MetaStatement require the method have `void` return type and
  30.     @MetaStatement
  31.     private static void addBlockStatement(MetaField<Block> field) {
  32.         BLOCKS.add(field.getValue(null));
  33.     }
  34. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×