private VariableReference getVariable(final String name, final boolean mustBeClassMember) { checkThread(); Variable found = null; Context ctx = this; do { if (ctx.variables != null) { final Variable var = ctx.variables.get(name); found = (mustBeClassMember && var != null && !variables.containsKey(var.getName())) ? null : var; } } while (found == null && (ctx = ctx.parent) != null); if (found == null) { missingSymbols.add(name); if (GenUtil.isPermissiveMode()) { return Variable.create(name, Object.class).getReference(); } else { throw new OutOfScopeException((mustBeClassMember) ? "this." + name : name + " not found.\nScope:\n" + this); } } return found.getReference(); }
private VariableReference getVariable(final String name, final boolean mustBeClassMember) { checkThread(); Variable found = null; Context ctx = this; do { if (ctx.variables != null) { final Variable var = ctx.variables.get(name); found = (mustBeClassMember && var != null && !variables.containsKey(var.getName())) ? null : var; } } while (found == null && (ctx = ctx.parent) != null); if (found == null) { missingSymbols.add(name); if (GenUtil.isPermissiveMode()) { return Variable.create(name, Object.class).getReference(); } else { throw new OutOfScopeException((mustBeClassMember) ? "this." + name : name + " not found.\nScope:\n" + this); } } return found.getReference(); }
@Override public String generate(final Context context) { if (generatedCache != null) return generatedCache; if (initialization != null) { this.type = (type == null) ? inferType(context, initialization) : type; this.value = GenUtil.convert(context, initialization, type); } return generatedCache = new DeclareAssignmentBuilder(isFinal, getReference(), value).generate(context); } }
@Override public String generate(final Context context) { if (generatedCache != null) return generatedCache; if (initialization != null) { this.type = (type == null) ? inferType(context, initialization) : type; this.value = GenUtil.convert(context, initialization, type); } return generatedCache = new DeclareAssignmentBuilder(isFinal, getReference(), value).generate(context); } }
public static Statement generate(final Context context, final Object o) { if (o instanceof VariableReference) { return context.getVariable(((VariableReference) o).getName()); } else if (o instanceof Variable) { final Variable v = (Variable) o; if (context.isScoped(v)) { return v.getReference(); } else { if (context.isPermissiveMode()) { return v.getReference(); } else { throw new OutOfScopeException("variable cannot be referenced from this scope: " + v.getName()); } } } else if (o instanceof Statement) { ((Statement) o).generate(context); return (Statement) o; } else { return LiteralFactory.getLiteral(context, o); } }
public static Statement generate(final Context context, final Object o) { if (o instanceof VariableReference) { return context.getVariable(((VariableReference) o).getName()); } else if (o instanceof Variable) { final Variable v = (Variable) o; if (context.isScoped(v)) { return v.getReference(); } else { if (context.isPermissiveMode()) { return v.getReference(); } else { throw new OutOfScopeException("variable cannot be referenced from this scope: " + v.getName()); } } } else if (o instanceof Statement) { ((Statement) o).generate(context); return (Statement) o; } else { return LiteralFactory.getLiteral(context, o); } }