SymbolModelImpl implements SymbolModel, SymbolModelBuilder { @Override public Set<Symbol> getSymbols() { return Collections.unmodifiableSet(symbols); }  static void build(TreeVisitorContext context, @Nullable Configuration configuration); @Override Scope globalScope(); @Override void addScope(Scope scope); @Override Set<Scope> getScopes(); @Override Symbol declareSymbol(String name, Symbol.Kind kind, Scope scope); @Override Symbol declareExternalSymbol(String name, Symbol.Kind kind, Scope scope); @Override Set<Symbol> getSymbols(); @Override Set<Symbol> getSymbols(Symbol.Kind kind); @Override Set<Symbol> getSymbols(String name); @Nullable @Override Scope getScope(Tree tree);  }
@Test public void symbols_filtering() { assertThat(SYMBOL_MODEL.getSymbols(Symbol.Kind.FUNCTION)).extracting("name").containsOnly("f", "func", "flowGenerics"); assertThat(SYMBOL_MODEL.getSymbols(Symbol.Kind.PARAMETER)).extracting("name").containsOnly("p1", "p2", "p3"); assertThat(SYMBOL_MODEL.getSymbols(Symbol.Kind.FLOW_GENERIC_TYPE)).extracting("name").containsOnly("T"); assertThat(SYMBOL_MODEL.getSymbols("a")).hasSize(3); assertThat(SYMBOL_MODEL.getSymbols("arguments")).hasSize(3); assertThat(SYMBOL_MODEL.getSymbols("this")).hasSize(4); assertThat(SYMBOL_MODEL.getSymbols("Object")).hasSize(1); assertThat(SYMBOL_MODEL.getSymbols("window")).hasSize(1); }
@Test public void symbols_scope() { Symbol f = (Symbol) SYMBOL_MODEL.getSymbols("f").toArray()[0]; Symbol e = (Symbol) SYMBOL_MODEL.getSymbols("e").toArray()[0]; assertThat(f.scope().tree().is(Tree.Kind.SCRIPT)).isTrue(); assertThat(e.scope().tree().is(Tree.Kind.CATCH_BLOCK)).isTrue(); }
@Test public void for_object_loops() throws Exception { Symbol i = (Symbol) SYMBOL_MODEL.getSymbols("i").toArray()[0]; assertThat(i.usages()).hasSize(2); }
@Test public void override_symbol_kind() throws Exception { Symbol func = (Symbol) SYMBOL_MODEL.getSymbols("func").toArray()[0]; assertThat(func.is(Kind.FUNCTION)).isTrue(); }
@Test public void environment() throws Exception { assertThat(symbolModel(INPUT_FILE, config("", "")).getSymbols("document")).hasSize(0); assertThat(symbolModel(INPUT_FILE, config("xxx", "")).getSymbols("document")).hasSize(0); assertThat(symbolModel(INPUT_FILE, config("browser", "")).getSymbols("document")).hasSize(1); }
@Test public void global_variable() throws Exception { assertThat(symbolModel(INPUT_FILE, config("", "")).getSymbols("global1")).hasSize(0); assertThat(symbolModel(INPUT_FILE, config("", "global1")).getSymbols("global1")).hasSize(1); }
@Test public void flowed_let() throws Exception { assertThat(SYMBOL_MODEL.getSymbols("flowed")).hasSize(1); }
@Test public void destructuring_let() throws Exception { assertThat(SYMBOL_MODEL.getSymbols("arra")).hasSize(1); assertThat(SYMBOL_MODEL.getSymbols("arrb")).hasSize(1); }
@Test public void flow_interface() { Symbol flowInterface = Iterables.getOnlyElement(SYMBOL_MODEL.getSymbols("FlowInterface")); assertThat(flowInterface.kind()).isEqualTo(Kind.FLOW_TYPE); }