@Override public Statement getValue() { return ref.getValue(); }
public static VariableReferenceContextualStatementBuilder loadVariable(final VariableReference reference) { return loadVariable(reference.getName(), reference.getIndexes()); }
@Test public void testAddVariableWithStringTypeInference() { Context ctx = ContextBuilder.create().addVariable("n", "10").getContext(); VariableReference n = ctx.getVariable("n"); assertEquals("Wrong variable name", "n", n.getName()); Assert.assertEquals("Wrong variable type", MetaClassFactory.get(String.class), n.getType()); Assert.assertEquals("Wrong variable value", LiteralFactory.getLiteral("10"), n.getValue()); }
@Override public String generate(final Context context) { return getName(); }
@Override public String generate(final Context context) { MetaClass referenceType = reference.getType(); final Statement[] indexes = reference.getIndexes(); if (indexes!=null) { for (final Statement index : indexes) { if (!referenceType.isArray()) throw new InvalidTypeException("Variable is not a " + indexes.length + "-dimensional array!"); referenceType = referenceType.getComponentType(); } } operator.assertCanBeApplied(referenceType); operator.assertCanBeApplied(statement.getType()); return reference.generate(context) + generateIndexes(context, indexes) + " " + operator.getCanonicalString() + " " + statement.generate(context); }
@Override public MetaClass getType() { return reference.getType(); } }
@Override public String generate(Context context) { StringBuilder buf = new StringBuilder(); try { buf.append("throw "); if (throwableType != null) { buf.append(ObjectBuilder.newInstanceOf(throwableType).withParameters(parameters).generate(context)); } else { VariableReference exceptionVar = context.getVariable(exceptionVariableName); if (!exceptionVar.getType().isAssignableTo(Throwable.class)) { throw new InvalidTypeException("Variable " + exceptionVariableName + " is not a Throwable"); } buf.append(exceptionVar.generate(context)); } } catch (GenerationException e) { blameAndRethrow(e); } return buf.toString(); } };
if (!ref.getType().isArray()) { throw new InvalidTypeException("attempt to use indexed accessor on non-array type: " + ref); ref.setIndexes(idx); nextOrReturn(writer, context, stmt);
@Test public void testAddVariableWithExactTypeProvided() { Context ctx = ContextBuilder.create().addVariable("n", Integer.class, 10).getContext(); VariableReference n = ctx.getVariable("n"); assertEquals("Wrong variable name", "n", n.getName()); Assert.assertEquals("Wrong variable type", MetaClassFactory.get(Integer.class), n.getType()); Assert.assertEquals("Wrong variable value", LiteralFactory.getLiteral(10), n.getValue()); }
@Override public String getName() { return ref.getName(); }
@Override public String generate(final Context context) { MetaClass referenceType = reference.getType(); final Statement[] indexes = reference.getIndexes(); if (indexes!=null) { for (final Statement index : indexes) { if (!referenceType.isArray()) throw new InvalidTypeException("Variable is not a " + indexes.length + "-dimensional array!"); referenceType = referenceType.getComponentType(); } } operator.assertCanBeApplied(referenceType); operator.assertCanBeApplied(statement.getType()); return reference.generate(context) + generateIndexes(context, indexes) + " " + operator.getCanonicalString() + " " + statement.generate(context); }
@Override public MetaClass getType() { return reference.getType(); } }
@Override public String generate(Context context) { StringBuilder buf = new StringBuilder(); try { buf.append("throw "); if (throwableType != null) { buf.append(ObjectBuilder.newInstanceOf(throwableType).withParameters(parameters).generate(context)); } else { VariableReference exceptionVar = context.getVariable(exceptionVariableName); if (!exceptionVar.getType().isAssignableTo(Throwable.class)) { throw new InvalidTypeException("Variable " + exceptionVariableName + " is not a Throwable"); } buf.append(exceptionVar.generate(context)); } } catch (GenerationException e) { blameAndRethrow(e); } return buf.toString(); } };
if (!ref.getType().isArray()) { throw new InvalidTypeException("attempt to use indexed accessor on non-array type: " + ref); ref.setIndexes(idx); nextOrReturn(writer, context, stmt);
@Test public void testAddVariableWithIntegerTypeInference() { Context ctx = ContextBuilder.create().addVariable("n", 10).getContext(); VariableReference n = ctx.getVariable("n"); assertEquals("Wrong variable name", "n", n.getName()); Assert.assertEquals("Wrong variable type", MetaClassFactory.get(Integer.class), n.getType()); Assert.assertEquals("Wrong variable value", LiteralFactory.getLiteral(10), n.getValue()); }
@Override public String generate(final Context context) { return getName(); }
@Override public String generate(Context context) { type = context.getVariable(name).getType(); return name; }
public static VariableReferenceContextualStatementBuilder loadVariable(final VariableReference reference) { return loadVariable(reference.getName(), reference.getIndexes()); }