SymbolTableImpl implements SymbolTable { public ImmutableList<Symbol> getSymbols() { return ImmutableList.copyOf(symbols); } private  SymbolTableImpl(); static SymbolTableImpl create(CompilationUnitTree compilationUnit); static SymbolTableImpl create(CompilationUnitTree compilationUnit, ProjectSymbolData projectSymbolData, @Nullable PhpFile file); @Override ImmutableSet<Scope> getScopes(); @Nullable @Override Scope getScopeFor(Tree tree); ImmutableList<Symbol> getSymbols(); @Override List<Symbol> getSymbols(Symbol.Kind kind); List<Symbol> getSymbols(String name); @Override @CheckForNull Symbol getSymbol(Tree tree); Collection<ClassSymbolData> classSymbolDatas(); Collection<FunctionSymbolData> functionSymbolDatas();  }
@Test public void symbols_filtering() { assertThat(SYMBOL_MODEL.getSymbols()).hasSize(20); assertThat(SYMBOL_MODEL.getSymbols(Symbol.Kind.FUNCTION)).hasSize(2); assertThat(SYMBOL_MODEL.getSymbols(Symbol.Kind.CLASS)).hasSize(1); assertThat(SYMBOL_MODEL.getSymbols(Symbol.Kind.FIELD)).hasSize(3); assertThat(SYMBOL_MODEL.getSymbols(Symbol.Kind.PARAMETER)).hasSize(1); assertThat(SYMBOL_MODEL.getSymbols(Symbol.Kind.VARIABLE)).hasSize(13); assertThat(SYMBOL_MODEL.getSymbols("$a")).hasSize(3); assertThat(SYMBOL_MODEL.getSymbols("$A")).hasSize(0); assertThat(SYMBOL_MODEL.getSymbols("f")).hasSize(2); assertThat(SYMBOL_MODEL.getSymbols("F")).hasSize(2); }
@Test public void test_class_fields() { Symbol field = SYMBOL_MODEL.getSymbols("$field1").get(0); Symbol constantField = SYMBOL_MODEL.getSymbols("CONSTANT_FIELD").get(0); assertThat(field.hasModifier("public")).isTrue(); assertThat(field.is(Symbol.Kind.FIELD)).isTrue(); assertThat(constantField.hasModifier("const")).isTrue(); assertThat(constantField.is(Symbol.Kind.FIELD)).isTrue(); }
@Test public void test_global_constant() { Symbol constant = SYMBOL_MODEL.getSymbols("CONSTANT").get(0); assertThat(constant.hasModifier("const")).isTrue(); assertThat(constant.is(Symbol.Kind.VARIABLE)).isTrue(); }
@Test public void list_variable() { assertThat(SYMBOL_MODEL.getSymbols("$l1")).hasSize(1); assertThat(SYMBOL_MODEL.getSymbols("$l2")).hasSize(1); }
@Test public void foreach_variable() { assertThat(SYMBOL_MODEL.getSymbols("$key")).hasSize(1); assertThat(SYMBOL_MODEL.getSymbols("$val")).hasSize(1); }
@Test public void static_variable() { List<Symbol> symbols = SYMBOL_MODEL.getSymbols("$static"); assertThat(symbols).hasSize(1); Symbol symbol = symbols.get(0); assertThat(symbol.hasModifier("static")).isTrue(); }
@Test public void test_anonymous_class() { SymbolTableImpl symbolTable = symbolTableFor("<?php namespace N { $x = new class { function foo() {} }; } "); assertThat(symbolTable.getSymbols()).hasSize(2); Symbol fooSymbol = Iterables.getOnlyElement(symbolTable.getSymbols("foo")); assertThat(fooSymbol.qualifiedName().toString()).isEqualTo("n\\foo"); }