private JDeclarationStatement makeDeclaration(SourceInfo info, JLocal local, JExpression value) { return new JDeclarationStatement(info, new JLocalRef(info, local), value); }
private JExpression makeLocalRef(SourceInfo info, LocalVariableBinding b) { JVariable variable = curMethod.locals.get(b); assert variable != null; if (variable instanceof JLocal) { return new JLocalRef(info, (JLocal) variable); } else { return new JParameterRef(info, (JParameter) variable); } }
@Override public void endVisit(LocalDeclaration x, BlockScope scope) { try { SourceInfo info = makeSourceInfo(x); JLocal local = (JLocal) curMethod.locals.get(x.binding); assert local != null; JLocalRef localRef = new JLocalRef(info, local); JExpression initialization = pop(x.initialization); push(new JDeclarationStatement(info, localRef, initialization)); } catch (Throwable e) { throw translateException(x, e); } }
@Override public void endVisit(TryStatement x, BlockScope scope) { try { SourceInfo info = makeSourceInfo(x); JBlock finallyBlock = pop(x.finallyBlock); List<JBlock> catchBlocks = pop(x.catchBlocks); JBlock tryBlock = pop(x.tryBlock); List<JLocalRef> catchArgs = new ArrayList<JLocalRef>(); if (x.catchBlocks != null) { for (Argument argument : x.catchArguments) { JLocal local = (JLocal) curMethod.locals.get(argument.binding); catchArgs.add(new JLocalRef(info, local)); } } push(new JTryStatement(info, tryBlock, catchArgs, catchBlocks, finallyBlock)); } catch (Throwable e) { throw translateException(x, e); } }
initializers.add(makeDeclaration(info, maxVar, new JArrayLength(info, new JLocalRef(info, arrayVar)))); new JBinaryOperation(info, JPrimitiveType.BOOLEAN, JBinaryOperator.LT, new JLocalRef( info, indexVar), new JLocalRef(info, maxVar)); increments.add(new JPrefixOperation(info, JUnaryOperator.INC, new JLocalRef(info, indexVar)).makeStatement()); new JArrayRef(info, new JLocalRef(info, arrayVar), new JLocalRef(info, indexVar)); body.addStmt(0, elementDecl); new JMethodCall(info, new JLocalRef(info, iteratorVar), typeMap.get(hasNext)); new JMethodCall(info, new JLocalRef(info, iteratorVar), typeMap.get(next));