SymbolHighlighter { public void highlight(SymbolTable symbolTable, NewSymbolTable newSymbolTable) { for (Symbol symbol : ((SymbolTableImpl) symbolTable).getSymbols()) { SyntaxToken token = symbol.declaration().token(); NewSymbol newSymbol = newSymbolTable.newSymbol(token.line(), token.column(), token.endLine(), token.endColumn()); for (SyntaxToken usageToken : symbol.usages()) { newSymbol.newReference(usageToken.line(), usageToken.column(), usageToken.endLine(), usageToken.endColumn()); } } }  void highlight(SymbolTable symbolTable, NewSymbolTable newSymbolTable);  }
@Test public void test_empty_input() throws Exception { highlight("<?php "); checkNoSymbolExists(1, 1); }
@Test public void test_no_usages() throws Exception { highlight("<?php $a = 1; "); checkNoSymbolExists(1, 7); checkSymbolExistence(1, 8); checkSymbolExistence(1, 9); checkNoSymbolExists(1, 10); checkSymbolReferences(1, 8, new LinkedList<>()); }
@Test public void test_usages() throws Exception { highlight("<?php $a = 1; echo $a; $a = 4; "); checkSymbolReferences(1, 8, ImmutableList.of( textRange(1, 21, 1, 23), textRange(1, 25, 1, 27))); }
@Test public void test_compound_variable() throws Exception { highlight("<?php $a = 1; echo \"${a}\"; echo \"$a\";"); checkSymbolReferences(1, 8, ImmutableList.of(textRange(1, 24, 1, 25), textRange(1, 35, 1, 37))); }
@Test public void test_use_clause() throws Exception { highlight("<?php $b = 42; $f = function() use($b) { echo $b; };"); checkSymbolExistence(1, 15); checkSymbolReferences(1, 6, ImmutableList.of(textRange(1, 35, 1, 37))); checkSymbolReferences(1, 35, ImmutableList.of(textRange(1, 46, 1, 48))); }
@Test public void test_arrow_function() throws Exception { highlight("<?php $a = 1; $b = 2; $f = fn($b) => $a + $b; foo($a); foo($b);"); checkSymbolReferences(1, 6, ImmutableList.of( textRange(1, 37, 1, 39), textRange(1, 50, 1, 52) )); checkSymbolReferences(1, 14, ImmutableList.of( textRange(1, 59, 1, 61) )); checkSymbolReferences(1, 30, ImmutableList.of( textRange(1, 42, 1, 44) )); }