Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Meta({
- @Do(
- // Possible values: ModifyStatements.Type.{
- // REMOVE_STATEMENT, ADD_METHOD, REMOVE_METHOD, ADD_FIELD, REMOVE_FIELD, GENERATE_CLASS
- // }
- // Note that there is no task for manipulating subclasses because subclasses are not actually "sub"classes
- type = ModifyStatements.Type.APPEND_STATEMENT,
- // These fields are (mostly) specific to ModifyStatements.Type.APPEND
- to = @SelectEntity("<staticInit>"), // <staticInit> is a special way to refer to it created by JMeta
- // All sequences contain entities
- statements = @Statements(
- source = @SelectEntity(value = MetaEntities.FIELDS, target = Block.class),
- operations = {
- // `expr` and `clazz` are specific to some types as well
- @Op(type = Op.Type.FILTER_INSTANCEOF, expr = @InstanceOf(expr = @TypeOfEntity, clazz = Block.class)),
- },
- // Finalize refers to a @MetaStatement method in the current class. The method must recieve the results' type
- // from previous processing steps (field -> MetaField<T>, method -> MetaMethod)
- finalize = "addBlockStatement"
- )
- )
- })
- class MetaProgrammingExample {
- static {} // For @SelectEntity("<staticInit>"), technically not needed because java compiler auto-generates them
- public static final List<Block> BLOCKS = new ArrayList<>();
- // Excludes this method in the final output
- // All usages of @MetaStatement require the method have `void` return type and
- @MetaStatement
- private static void addBlockStatement(MetaField<Block> field) {
- BLOCKS.add(field.getValue(null));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement