An IFileNode is the root of the AST (abstract syntax tree) produced for a file.
IFileNode
If the file includes other files, a single IFileNode is produced.
The shape of this node is
IFileNode IASNode <-- getChild(0) IASNode <-- getChild(1) ...
270271272273274275276277278279280
@Override @Test public void testVisit() { // TODO (erikdebruin) check if resulting 'goog' JS is valid IFileNode node = (IFileNode) getNode( "try { a; } catch (e:Error) { if (a) { if (b) { if (c) b; else if (f) a; else e; }} } finally { }" + "if (d) for (var i:int = 0; i < len; i++) break;" + "if (a) { with (ab) { c(); } " + "do {a++;do a++; while(a > b);} while(c > d); }" + "if (b) { try { a; throw new Error('foo'); } catch (e:Error) { "
150151152153154155156157158159160
@Override public void visitCompilationUnit(ICompilationUnit unit) { debug("visitCompilationUnit()"); IFileNode node = null; try { node = (IFileNode) unit.getSyntaxTreeRequest().get().getAST(); } catch (InterruptedException e)
207208209210211212213214215216
} protected IClassNode getClassNode(String code) { String source = "package {" + code + "}"; IFileNode node = getFileNode(source); IClassNode child = (IClassNode) findFirstDescendantOfType(node, IClassNode.class); return child; }
353637383940414243
//-------------------------------------------------------------------------- @Test public void testPackage_Simple() { IFileNode node = getFileNode("package{}"); visitor.visitFile(node); assertOut("package {\n}"); }
434445464748495051
} @Test public void testPackage_Name() { IFileNode node = getFileNode("package foo.bar.baz {}"); visitor.visitFile(node); assertOut("package foo.bar.baz {\n}"); }
515253545556575859
} @Test public void testPackageSimple_Class() { IFileNode node = getFileNode("package {public class A{}}"); visitor.visitFile(node); assertOut("package {\n\tpublic class A {\n\t}\n}"); }
596061626364656667
} @Test public void testPackageQualified_Class() { IFileNode node = getFileNode("package foo.bar.baz {public class A{}}"); visitor.visitFile(node); assertOut("package foo.bar.baz {\n\tpublic class A {\n\t}\n}"); }
676869707172737475
} @Test public void testPackageQualified_ClassBody() { IFileNode node = getFileNode("package foo.bar.baz {public class A{public function A(){}}}"); visitor.visitFile(node); assertOut("package foo.bar.baz {\n\tpublic class A {\n\t\tpublic function A() {\n\t\t}\n\t}\n}"); }
75767778798081828384
} @Test public void testPackageQualified_ClassBodyMethodContents() { IFileNode node = getFileNode("package foo.bar.baz {public class A{public function A(){if (a){for each(var i:Object in obj){doit();}}}}}"); visitor.visitFile(node); assertOut("package foo.bar.baz {\n\tpublic class A {\n\t\tpublic function A() {\n\t\t\t" + "if (a) {\n\t\t\t\tfor each (var i:Object in obj) {\n\t\t\t\t\tdoit();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}"); }
194195196197198199200201202203
} protected INamespaceNode getNamespace(String code) { String source = "package {public class A {" + code + "}}"; IFileNode node = getFileNode(source); INamespaceNode child = (INamespaceNode) findFirstDescendantOfType(node, INamespaceNode.class); return child; }