[stringtemplate-interest] What compiles to : Bytecode.INSTR_LOAD_ATTR ?
Collin Fagan
collin.fagan at gmail.com
Sat Sep 3 05:30:28 PDT 2011
Hi Everyone,
In my (probably misguided) quest to inject attributes into the scope of a
template I've overridden the getAttribute method on Interpreter. This method
call gets invoked when the Interpreter runs into Bytecode.INSTR_LOAD_ATTR.
My problem is that my simple test never generates this bytecode. It only
generates Bytecode.INSTR_LOAD_LOCAL.
Does anyone know what I have to do to generate Bytecode.INSTR_LOAD_ATTR?
Thanks,
Collin
Here is my experimental code:
/**
*
* @author collin
*/
public class Exp {
private class ExtInterpreter extends Interpreter {
public ExtInterpreter(STGroup group, Locale locale,
ErrorManager errMgr, boolean debug) {
super(group, locale, errMgr, debug);
// TODO Auto-generated constructor stub
}
@Override
public Object getAttribute(ST self, String name) {
System.out.println(name);
return super.getAttribute(self, name);
}
}
@Test
public void testStaticMethodAddForString() {
STGroup group = new STGroup();
group.defineTemplate("main", "string", "{<string.q>}");
ST mainTemplate = group.getInstanceOf("main");
// mainTemplate.add("string", "this is my test string");
Interpreter interp = new
ExtInterpreter(group,Locale.getDefault(),group.errMgr,false);
StringWriter stringWriter = new StringWriter();
STWriter wr = new AutoIndentWriter(stringWriter);
wr.setLineWidth(STWriter.NO_WRAP);
interp.exec(wr, mainTemplate);
System.out.print(stringWriter.toString());
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110903/f47dbdb3/attachment.html
More information about the stringtemplate-interest
mailing list