use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.
the class PyParser25Test method testNewWithStmt2.
public void testNewWithStmt2() {
setDefaultVersion(IPythonNature.GRAMMAR_PYTHON_VERSION_2_5);
String str = "" + "from __future__ import with_statement\n" + "with foo as x:\n" + " print 'bla'\n" + "";
// we'll actually treat this as a try..finally with a body with try..except..else
Module mod = (Module) parseLegalDocStr(str);
assertEquals(2, mod.body.length);
assertTrue(mod.body[1] instanceof With);
With w = (With) mod.body[1];
assertTrue(((WithItem) w.with_item[0]).optional_vars != null);
}
use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.
the class PyParser25Test method testNewWithStmt.
public void testNewWithStmt() {
setDefaultVersion(IPythonNature.GRAMMAR_PYTHON_VERSION_2_5);
String str = "" + "from __future__ import with_statement\n" + "with foo:\n" + " print 'bla'\n" + "";
// we'll actually treat this as a try..finally with a body with try..except..else
Module mod = (Module) parseLegalDocStr(str);
assertEquals(2, mod.body.length);
assertTrue(mod.body[1] instanceof With);
With w = (With) mod.body[1];
assertTrue(((WithItem) w.with_item[0]).optional_vars == null);
}
use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.
the class AbstractTreeBuilder method makeWithItem.
protected final SimpleNode makeWithItem(int arity) throws Exception {
// expr
exprType expr = (exprType) stack.popNode();
arity--;
exprType asExpr = null;
if (arity > 0) {
asExpr = expr;
expr = (exprType) stack.popNode();
ctx.setStore(asExpr);
}
return new WithItem(expr, asExpr);
}
use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.
the class AbstractTreeBuilder method makeWithStmt.
protected final SimpleNode makeWithStmt(int arity) {
Suite suite = (Suite) stack.popNode();
arity--;
WithItem[] items = new WithItem[arity];
while (arity > 0) {
items[arity - 1] = (WithItem) stack.popNode();
arity--;
}
suiteType s = new Suite(suite.body);
addSpecialsAndClearOriginal(suite, s);
return new With(items, s, stack.getGrammar().getInsideAsync());
}
use of org.python.pydev.parser.jython.ast.WithItem in project Pydev by fabioz.
the class PrettyPrinterVisitorV2 method visitWith.
@Override
public Object visitWith(With node) throws Exception {
startStatementPart();
beforeNode(node);
if (node.async) {
doc.addRequire("async ", node);
}
doc.addRequire("with", node);
if (node.with_item != null) {
for (int i = 0; i < node.with_item.length; i++) {
if (i > 0) {
doc.addRequire(",", lastNode);
}
WithItem withItem = (WithItem) node.with_item[i];
withItem.accept(this);
}
}
doc.addRequire(":", lastNode);
this.doc.addRequireIndent(":", lastNode);
endStatementPart(node);
if (node.body != null) {
node.body.accept(this);
}
dedent();
afterNode(node);
return null;
}
Aggregations