public void test_argumentResolution_setter_static_propertyAccess() throws Exception {
   Source source =
       addSource(
           createSource( //
               "main() {",
               "  A a = new A();",
               "  a.b.sss = 0;",
               "}",
               "class A {",
               "  B b = new B();",
               "}",
               "class B {",
               "  set sss(x) {}",
               "}"));
   LibraryElement library = resolve(source);
   CompilationUnitElement unit = library.getDefiningCompilationUnit();
   // find "a.b.sss = 0"
   AssignmentExpression assignment;
   {
     FunctionElement mainElement = unit.getFunctions()[0];
     FunctionBody mainBody = mainElement.getNode().getFunctionExpression().getBody();
     Statement statement = ((BlockFunctionBody) mainBody).getBlock().getStatements().get(1);
     ExpressionStatement expressionStatement = (ExpressionStatement) statement;
     assignment = (AssignmentExpression) expressionStatement.getExpression();
   }
   // get parameter
   Expression rhs = assignment.getRightHandSide();
   ParameterElement parameter = rhs.getStaticParameterElement();
   assertNotNull(parameter);
   assertEquals("x", parameter.getDisplayName());
   // validate
   ClassElement classB = unit.getTypes()[1];
   PropertyAccessorElement setter = classB.getAccessors()[0];
   assertSame(parameter, setter.getParameters()[0]);
 }
 public void test_metadata_function() throws Exception {
   Source source =
       addSource(
           createSource( //
               "const A = null;", "@A f() {}"));
   LibraryElement library = resolve(source);
   assertNotNull(library);
   CompilationUnitElement unit = library.getDefiningCompilationUnit();
   assertNotNull(unit);
   FunctionElement[] functions = unit.getFunctions();
   assertLength(1, functions);
   ElementAnnotation[] annotations = functions[0].getMetadata();
   assertLength(1, annotations);
   assertNoErrors(source);
   verify(source);
 }
 public void test_metadata_simpleParameter() throws Exception {
   Source source =
       addSource(
           createSource( //
               "const A = null;", "f(@A p1, @A int p2) {}"));
   LibraryElement library = resolve(source);
   assertNotNull(library);
   CompilationUnitElement unit = library.getDefiningCompilationUnit();
   assertNotNull(unit);
   FunctionElement[] functions = unit.getFunctions();
   assertLength(1, functions);
   ParameterElement[] parameters = functions[0].getParameters();
   assertLength(2, parameters);
   ElementAnnotation[] annotations1 = parameters[0].getMetadata();
   assertLength(1, annotations1);
   ElementAnnotation[] annotations2 = parameters[1].getMetadata();
   assertLength(1, annotations2);
   assertNoErrors(source);
   verify(source);
 }
Esempio n. 4
0
  public void test_empty() throws Exception {
    Source librarySource = addSource("/lib.dart", "library lib;");

    LibraryElement element = buildLibrary(librarySource);
    assertNotNull(element);
    assertEquals("lib", element.getName());
    assertNull(element.getEntryPoint());
    assertLength(0, element.getImportedLibraries());
    assertLength(0, element.getImports());
    assertNull(element.getLibrary());
    assertLength(0, element.getPrefixes());
    assertLength(0, element.getParts());

    CompilationUnitElement unit = element.getDefiningCompilationUnit();
    assertNotNull(unit);
    assertEquals("lib.dart", unit.getName());
    assertEquals(element, unit.getLibrary());
    assertLength(0, unit.getAccessors());
    assertLength(0, unit.getFields());
    assertLength(0, unit.getFunctions());
    assertLength(0, unit.getTypeAliases());
    assertLength(0, unit.getTypes());
  }