private static void handleContextsAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) { Ruby rubyRuntime = rubyClass.getRuntime(); if (processor.isAnnotationPresent(Contexts.class)) { Contexts contexts = processor.getAnnotation(Contexts.class); RubyArray contextList = rubyRuntime.newArray(); for (String value : contexts.value()) { contextList.add(rubyRuntime.newSymbol(value.substring(1))); } rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{ rubyRuntime.newSymbol("contexts"), contextList }); } }
@Name("yell") // <1> @Contexts({Contexts.PARAGRAPH}) // <2> @ContentModel(ContentModel.SIMPLE) // <3> public class YellBlockProcessor extends BlockProcessor { // <4> @Override public Object process( // <5> StructuralNode parent, Reader reader, Map<String, Object> attributes) { String content = reader.read(); String yellContent = content.toUpperCase(); return createBlock(parent, "paragraph", yellContent, attributes); } } //end::include[]
private static void handleContextsAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) { Ruby rubyRuntime = rubyClass.getRuntime(); if (processor.isAnnotationPresent(Contexts.class)) { Contexts contexts = processor.getAnnotation(Contexts.class); RubyArray contextList = rubyRuntime.newArray(); for (String value : contexts.value()) { contextList.add(rubyRuntime.newSymbol(value.substring(1))); } rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{ rubyRuntime.newSymbol("contexts"), contextList }); } }