use of org.python.pydev.shared_core.parsing.BaseParser.ParseOutput in project Pydev by fabioz.
the class MatchImportsVisitorTest method testMatchImports2.
public void testMatchImports2() throws Exception {
Document doc = new Document("" + // rename a.b.c
"import a.b.c.d\n" + // rename a.b.c
"import a.b.c\n" + "import a.b\n" + "");
IPythonNature nature = new PythonNatureStub();
ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, nature));
SourceModule module = (SourceModule) AbstractModule.createModule((SimpleNode) obj.ast, null, "z", null);
MatchImportsVisitor visitor = new MatchImportsVisitor(nature, "a.b.c", module, null);
module.getAst().accept(visitor);
assertEquals(visitor.importsMatchingOnAliasPart.size(), 2);
assertEquals(visitor.occurrences.size(), 2);
}
use of org.python.pydev.shared_core.parsing.BaseParser.ParseOutput in project Pydev by fabioz.
the class GenCythonAstImpl method jsonToParseOutput.
private ParseOutput jsonToParseOutput(ParserInfo p, String cythonJson, long modifiedTime) {
JsonValue json = JsonValue.readFrom(cythonJson);
JsonObject asObject = json.asObject();
JsonValue errors = asObject.get("errors");
ParseException exc = null;
for (JsonValue v : errors.asArray()) {
JsonObject objError = v.asObject();
JsonValue lineValue = objError.get("line");
JsonValue colValue = objError.get("col");
JsonValue messageValue = objError.get("message_only");
exc = new ParseException(messageValue.asString(), lineValue.asInt(), colValue.asInt());
}
JsonValue ast = asObject.get("ast");
if (ast == null || !ast.isObject()) {
ParseOutput parseOutput = new ParseOutput(null, exc, modifiedTime);
parseOutput.isCython = true;
return parseOutput;
} else {
JsonValue body = ast.asObject().get("stats");
if (body != null && body.isArray()) {
// System.out.println(body.toPrettyString());
JsonToNodesBuilder builder = new JsonToNodesBuilder(p);
JsonArray asArray = body.asArray();
Iterator<JsonValue> iterator = asArray.iterator();
while (iterator.hasNext()) {
JsonValue node = iterator.next();
try {
builder.addStatement(node);
} catch (Exception e) {
log("Error converting cython json to ast: " + node, e);
}
}
ISimpleNode mod = builder.createModule();
ParseOutput parseOutput = new ParseOutput(mod, null, modifiedTime);
parseOutput.isCython = true;
return parseOutput;
}
}
return null;
}
use of org.python.pydev.shared_core.parsing.BaseParser.ParseOutput in project Pydev by fabioz.
the class GraphView method loadGraph.
private void loadGraph(String fileName) throws FileNotFoundException, IOException, Throwable {
ASTGraph ast = new ASTGraph();
ParseOutput objects = ast.parseFile(fileName);
graph.setGraphLayoutCache(new GraphLayoutCache());
DefaultGraphCell[] cells = ast.generateTree((SimpleNode) objects.ast);
graph.getGraphLayoutCache().insert(cells);
graph.clearSelection();
}
use of org.python.pydev.shared_core.parsing.BaseParser.ParseOutput in project Pydev by fabioz.
the class CodeFoldingVisitorTest method testWith.
public void testWith() throws Exception {
CodeFoldingVisitor visitor = new CodeFoldingVisitor();
String str = "" + "from __future__ import with_statement\n" + "with a:\n" + " print a\n" + "";
ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_2_5, null));
SimpleNode root = (SimpleNode) objects.ast;
root.accept(visitor);
Iterator<ASTEntry> iterator = visitor.getIterator();
check((ASTEntryWithChildren) iterator.next(), "from __future__ import with_statement", 6, 1, 1, 0);
check((ASTEntryWithChildren) iterator.next(), "With", 1, 2, 3, 0);
assertTrue(iterator.hasNext() == false);
}
use of org.python.pydev.shared_core.parsing.BaseParser.ParseOutput in project Pydev by fabioz.
the class CodeFoldingVisitorTest method testTryFinally.
public void testTryFinally() throws Exception {
CodeFoldingVisitor visitor = new CodeFoldingVisitor();
String str = "" + "try:\n" + " print 4\n" + "finally:\n" + " print 5\n" + "\n" + "";
ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_2_5, null));
SimpleNode root = (SimpleNode) objects.ast;
root.accept(visitor);
Iterator<ASTEntry> iterator = visitor.getIterator();
check((ASTEntryWithChildren) iterator.next(), "TryFinally", 1, 1, 4, 0);
assertTrue(iterator.hasNext() == false);
}
Aggregations