Ejemplo n.º 1
0
 /** Test for {@link DartFunction#isGlobal()} and {@link DartFunction#isLocal()}. */
 public void test_isGlobal_isLocal() throws Exception {
   TestProject testProject = new TestProject("Test");
   try {
     CompilationUnit unit =
         testProject.setUnitContent(
             "Test.dart",
             Joiner.on("\n")
                 .join(
                     "// filler filler filler filler filler filler filler filler filler filler",
                     "f() {",
                     "  v() {};",
                     "}",
                     ""));
     // global function
     DartFunction globalFunction = (DartFunction) unit.getChildren()[0];
     assertTrue(globalFunction.isGlobal());
     assertFalse(globalFunction.isLocal());
     // local functions
     DartElement[] functions = globalFunction.getChildren();
     assertThat(functions).hasSize(1);
     // v
     {
       DartFunction f = (DartFunction) functions[0];
       assertFalse(f.isGlobal());
       assertTrue(f.isLocal());
     }
   } finally {
     testProject.dispose();
   }
 }
Ejemplo n.º 2
0
 /** Test for {@link DartFunction#getVisibleRange()} for local functions. */
 public void test_getVisibleRange() throws Exception {
   TestProject testProject = new TestProject("Test");
   try {
     CompilationUnit unit =
         testProject.setUnitContent(
             "Test.dart",
             Joiner.on("\n")
                 .join(
                     "// filler filler filler filler filler filler filler filler filler filler",
                     "f() {",
                     "  v1() {};",
                     "  {",
                     "    v2() {};",
                     "  }//marker1",
                     "  v3() {};",
                     "}//marker2",
                     ""));
     String source = unit.getSource();
     DartFunction globalFunction = (DartFunction) unit.getChildren()[0];
     DartElement[] functions = globalFunction.getChildren();
     assertThat(functions).hasSize(3);
     // v1
     {
       DartFunction f = (DartFunction) functions[0];
       SourceRange range = f.getVisibleRange();
       assertEquals("v1", f.getElementName());
       assertEquals(source.indexOf("v1"), range.getOffset());
       assertEquals(source.indexOf("marker2") - 1, range.getOffset() + range.getLength());
     }
     // v2
     {
       DartFunction f = (DartFunction) functions[1];
       SourceRange range = f.getVisibleRange();
       assertEquals("v2", f.getElementName());
       assertEquals(source.indexOf("v2"), range.getOffset());
       assertEquals(source.indexOf("marker1") - 1, range.getOffset() + range.getLength());
     }
     // v3
     {
       DartFunction f = (DartFunction) functions[2];
       SourceRange range = f.getVisibleRange();
       assertEquals("v3", f.getElementName());
       assertEquals(source.indexOf("v3"), range.getOffset());
       assertEquals(source.indexOf("marker2") - 1, range.getOffset() + range.getLength());
     }
   } finally {
     testProject.dispose();
   }
 }