org.stringtemplate.v4.Interpreter Java Examples
The following examples show how to use
org.stringtemplate.v4.Interpreter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompilationState.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
public void refAttr(Token templateToken, CommonTree id) { String name = id.getText(); if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) { FormalArgument arg = impl.formalArguments.get(name); int index = arg.index; emit1(id, Bytecode.INSTR_LOAD_LOCAL, index); } else { if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) { errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token); emit(id, Bytecode.INSTR_NULL); } else { emit1(id, Bytecode.INSTR_LOAD_ATTR, name); } } }
Example #2
Source File: MapModelAdaptor.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException { Object value; Map<?, ?> map = (Map<?, ?>)o; if ( property==null ) value = map.get(STGroup.DEFAULT_KEY); else if ( property.equals("keys") ) value = map.keySet(); else if ( property.equals("values") ) value = map.values(); else if ( map.containsKey(property) ) value = map.get(property); else if ( map.containsKey(propertyName) ) { // if can't find the key, try toString version value = map.get(propertyName); } else value = map.get(STGroup.DEFAULT_KEY); // not found, use default if ( value==STGroup.DICT_KEY ) { value = property; } return value; }
Example #3
Source File: CompilationState.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
public void refAttr(Token templateToken, CommonTree id) { String name = id.getText(); if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) { FormalArgument arg = impl.formalArguments.get(name); int index = arg.index; emit1(id, Bytecode.INSTR_LOAD_LOCAL, index); } else { if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) { errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token); emit(id, Bytecode.INSTR_NULL); } else { emit1(id, Bytecode.INSTR_LOAD_ATTR, name); } } }
Example #4
Source File: ObjectModelAdaptor.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public synchronized Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException { if ( o==null ) { throw new NullPointerException("o"); } Class<?> c = o.getClass(); if ( property==null ) { return throwNoSuchProperty(c, propertyName, null); } Member member = findMember(c, propertyName); if ( member!=null ) { try { if ( member instanceof Method ) { return ((Method)member).invoke(o); } else if ( member instanceof Field ) { return ((Field)member).get(o); } } catch (Exception e) { throwNoSuchProperty(c, propertyName, e); } } return throwNoSuchProperty(c, propertyName, null); }
Example #5
Source File: CompilationState.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
public void refAttr(Token templateToken, CommonTree id) { String name = id.getText(); if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) { FormalArgument arg = impl.formalArguments.get(name); int index = arg.index; emit1(id, Bytecode.INSTR_LOAD_LOCAL, index); } else { if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) { errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token); emit(id, Bytecode.INSTR_NULL); } else { emit1(id, Bytecode.INSTR_LOAD_ATTR, name); } } }
Example #6
Source File: ObjectModelAdaptor.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public synchronized Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException { if ( o==null ) { throw new NullPointerException("o"); } Class<?> c = o.getClass(); if ( property==null ) { return throwNoSuchProperty(c, propertyName, null); } Member member = findMember(c, propertyName); if ( member!=null ) { try { if ( member instanceof Method ) { return ((Method)member).invoke(o); } else if ( member instanceof Field ) { return ((Field)member).get(o); } } catch (Exception e) { throwNoSuchProperty(c, propertyName, e); } } return throwNoSuchProperty(c, propertyName, null); }
Example #7
Source File: STRuntimeMessage.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(); String loc = null; if ( self!=null ) { loc = getSourceLocation(); buf.append("context ["); if ( interp!=null ) { buf.append(Interpreter.getEnclosingInstanceStackString(scope)); } buf.append("]"); } if ( loc!=null ) buf.append(" "+loc); buf.append(" "+super.toString()); return buf.toString(); }
Example #8
Source File: STRuntimeMessage.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(); String loc = null; if ( self!=null ) { loc = getSourceLocation(); buf.append("context ["); if ( interp!=null ) { buf.append(Interpreter.getEnclosingInstanceStackString(scope)); } buf.append("]"); } if ( loc!=null ) buf.append(" "+loc); buf.append(" "+super.toString()); return buf.toString(); }
Example #9
Source File: STRuntimeMessage.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(); String loc = null; if ( self!=null ) { loc = getSourceLocation(); buf.append("context ["); if ( interp!=null ) { buf.append(Interpreter.getEnclosingInstanceStackString(scope)); } buf.append("]"); } if ( loc!=null ) buf.append(" "+loc); buf.append(" "+super.toString()); return buf.toString(); }
Example #10
Source File: STRuntimeMessage.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(); String loc = null; if ( self!=null ) { loc = getSourceLocation(); buf.append("context ["); if ( interp!=null ) { buf.append( Interpreter.getEnclosingInstanceStackString(scope) ); } buf.append("]"); } if ( loc!=null ) buf.append(" "+loc); buf.append(" "+super.toString()); return buf.toString(); }
Example #11
Source File: ObjectModelAdaptor.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public synchronized Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException { if ( o==null ) { throw new NullPointerException("o"); } Class<?> c = o.getClass(); if ( property==null ) { return throwNoSuchProperty(c, propertyName, null); } Member member = findMember(c, propertyName); if ( member!=null ) { try { if ( member instanceof Method ) { return ((Method)member).invoke(o); } else if ( member instanceof Field ) { return ((Field)member).get(o); } } catch (Exception e) { throwNoSuchProperty(c, propertyName, e); } } return throwNoSuchProperty(c, propertyName, null); }
Example #12
Source File: CompilationState.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
public void refAttr(Token templateToken, CommonTree id) { String name = id.getText(); if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) { FormalArgument arg = impl.formalArguments.get(name); int index = arg.index; emit1(id, Bytecode.INSTR_LOAD_LOCAL, index); } else { if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) { errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token); emit(id, Bytecode.INSTR_NULL); } else { emit1(id, Bytecode.INSTR_LOAD_ATTR, name); } } }
Example #13
Source File: MapModelAdaptor.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException { Object value; Map<?, ?> map = (Map<?, ?>)o; if ( property==null ) value = map.get(STGroup.DEFAULT_KEY); else if ( property.equals("keys") ) value = map.keySet(); else if ( property.equals("values") ) value = map.values(); else if ( map.containsKey(property) ) value = map.get(property); else if ( map.containsKey(propertyName) ) { // if can't find the key, try toString version value = map.get(propertyName); } else value = map.get(STGroup.DEFAULT_KEY); // not found, use default if ( value==STGroup.DICT_KEY ) { value = property; } return value; }
Example #14
Source File: STViz.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
public STViz(ErrorManager errMgr, EvalTemplateEvent root, String output, Interpreter interp, List<String> trace, List<STMessage> errors) { this.errMgr = errMgr; this.currentEvent = root; this.currentScope = root.scope; this.output = output; this.interp = interp; this.allEvents = interp.getEvents(); this.trace = trace; this.errors = errors; }
Example #15
Source File: ErrorManager.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public void runTimeError(Interpreter interp, InstanceScope scope, ErrorType error, Object arg, Object arg2, Object arg3) { listener.runTimeError(new STRuntimeMessage(interp, error, scope!=null ? scope.ip : 0, scope, null, arg, arg2, arg3)); }
Example #16
Source File: STModelAdaptor.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException { ST st = (ST)o; return st.getAttribute(propertyName); }
Example #17
Source File: JTreeScopeStackModel.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public JTreeScopeStackModel(InstanceScope scope) { root = new StringTree("Scope stack:"); Set<String> names = new HashSet<String>(); List<InstanceScope> stack = Interpreter.getScopeStack(scope, false); for (InstanceScope s : stack) { StringTree templateNode = new StringTree(s.st.getName()); root.insertChild(0, templateNode); addAttributeDescriptions(s.st, templateNode, names); } //System.out.println(root.toStringTree()); }
Example #18
Source File: STViz.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public STViz(ErrorManager errMgr, EvalTemplateEvent root, String output, Interpreter interp, List<String> trace, List<STMessage> errors) { this.errMgr = errMgr; this.currentEvent = root; this.currentScope = root.scope; this.output = output; this.interp = interp; this.allEvents = interp.getEvents(); this.trace = trace; this.errors = errors; }
Example #19
Source File: ErrorManager.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public void runTimeError(Interpreter interp, InstanceScope scope, ErrorType error, Object arg, Object arg2, Object arg3) { listener.runTimeError(new STRuntimeMessage(interp, error, scope!=null ? scope.ip : 0, scope, null, arg, arg2, arg3)); }
Example #20
Source File: STRuntimeMessage.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public STRuntimeMessage(Interpreter interp, ErrorType error, int ip, InstanceScope scope, Throwable e, Object arg, Object arg2) { this(interp, error, ip, scope, e, arg, arg2, null); }
Example #21
Source File: JTreeScopeStackModel.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public JTreeScopeStackModel(InstanceScope scope) { root = new StringTree("Scope stack:"); Set<String> names = new HashSet<String>(); List<InstanceScope> stack = Interpreter.getScopeStack(scope, false); for (InstanceScope s : stack) { StringTree templateNode = new StringTree(s.st.getName()); root.insertChild(0, templateNode); addAttributeDescriptions(s.st, templateNode, names); } //System.out.println(root.toStringTree()); }
Example #22
Source File: STRuntimeMessage.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public STRuntimeMessage(Interpreter interp, ErrorType error, int ip, InstanceScope scope, Throwable e, Object arg) { this(interp, error, ip, scope, e, arg, null); }
Example #23
Source File: STViz.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public STViz(ErrorManager errMgr, EvalTemplateEvent root, String output, Interpreter interp, List<String> trace, List<STMessage> errors) { this.errMgr = errMgr; this.currentEvent = root; this.currentScope = root.scope; this.output = output; this.interp = interp; this.allEvents = interp.getEvents(); this.trace = trace; this.errors = errors; }
Example #24
Source File: JTreeScopeStackModel.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public JTreeScopeStackModel(InstanceScope scope) { root = new StringTree("Scope stack:"); Set<String> names = new HashSet<String>(); List<InstanceScope> stack = Interpreter.getScopeStack(scope, false); for (InstanceScope s : stack) { StringTree templateNode = new StringTree(s.st.getName()); root.insertChild(0, templateNode); addAttributeDescriptions(s.st, templateNode, names); } //System.out.println(root.toStringTree()); }
Example #25
Source File: ErrorManager.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public void runTimeError(Interpreter interp, InstanceScope scope, ErrorType error, Object arg, Object arg2, Object arg3) { listener.runTimeError(new STRuntimeMessage(interp, error, scope!=null ? scope.ip :0, scope, null, arg, arg2, arg3)); }
Example #26
Source File: STRuntimeMessage.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public STRuntimeMessage(Interpreter interp, ErrorType error, int ip, InstanceScope scope, Throwable e, Object arg) { this(interp, error, ip, scope, e, arg, null); }
Example #27
Source File: JTreeScopeStackModel.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public JTreeScopeStackModel(InstanceScope scope) { root = new StringTree("Scope stack:"); Set<String> names = new HashSet<String>(); List<InstanceScope> stack = Interpreter.getScopeStack(scope, false); for (InstanceScope s : stack) { StringTree templateNode = new StringTree(s.st.getName()); root.insertChild(0, templateNode); addAttributeDescriptions(s.st, templateNode, names); } //System.out.println(root.toStringTree()); }
Example #28
Source File: STRuntimeMessage.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public STRuntimeMessage(Interpreter interp, ErrorType error, int ip, InstanceScope scope, Throwable e, Object arg) { this(interp, error, ip, scope, e, arg, null); }
Example #29
Source File: ErrorManager.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public void runTimeError(Interpreter interp, InstanceScope scope, ErrorType error, Object arg, Object arg2, Object arg3) { listener.runTimeError(new STRuntimeMessage(interp, error, scope!=null ? scope.ip : 0, scope, null, arg, arg2, arg3)); }
Example #30
Source File: STRuntimeMessage.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
public STRuntimeMessage(Interpreter interp, ErrorType error, int ip, InstanceScope scope, Throwable e, Object arg, Object arg2) { this(interp, error, ip, scope, e, arg, arg2, null); }