@Test public void test() throws Exception { GlobalStatementTree tree = parse("global $a, $b;", PHPLexicalGrammar.GLOBAL_STATEMENT); assertThat(tree.is(Kind.GLOBAL_STATEMENT)).isTrue(); assertThat(tree.globalToken().text()).isEqualTo("global"); assertThat(tree.variables()).hasSize(2); assertThat(tree.eosToken().text()).isEqualTo(";"); }
@Override public void visitGlobalStatement(GlobalStatementTree tree) { for (VariableTree variable : tree.variables()) { // Other cases are not supported if (variable.is(Tree.Kind.VARIABLE_IDENTIFIER)) { IdentifierTree identifier = (IdentifierTree) variable.variableExpression(); Symbol symbol = globalScope.getSymbol(identifier.text(), Symbol.Kind.VARIABLE); if (symbol != null) { // actually this identifier in global statement is not usage, but we do this for the symbol highlighting associateSymbol(identifier, symbol); currentScope.addSymbol(symbol); } else { symbol = createSymbol(identifier, Symbol.Kind.VARIABLE); } // consider 'global' has being a modifier for the variable symbol.addModifiers(Collections.singletonList(tree.globalToken())); } } }
@Override public void visitGlobalStatement(GlobalStatementTree tree) { for (VariableTree variableTree : tree.variables()) { Symbol symbol = context().symbolTable().getSymbol(variableTree); if (variableTree.is(Tree.Kind.VARIABLE_IDENTIFIER) && symbol != null) { Scope scope = symbol.scope(); String variable = ((VariableIdentifierTree) variableTree).text(); variableSetAsGlobalInScopes .computeIfAbsent(scope, key -> new ArrayList<>()) .add(variable); } } super.visitGlobalStatement(tree); }
@Override public void visitGlobalStatement(GlobalStatementTree tree) { for (VariableTree variable : tree.variables()) { // Other cases are not supported if (variable.is(Tree.Kind.VARIABLE_IDENTIFIER)) { IdentifierTree identifier = (IdentifierTree) variable.variableExpression(); Symbol symbol = globalScope.getSymbol(identifier.text(), Symbol.Kind.VARIABLE); if (symbol != null) { // actually this identifier in global statement is not usage, but we do this for the symbol highlighting associateSymbol(identifier, symbol); currentScope.addSymbol(symbol); } else { symbol = createSymbol(identifier, Symbol.Kind.VARIABLE); } // consider 'global' has being a modifier for the variable symbol.addModifiers(Collections.singletonList(tree.globalToken())); } } }
@Override public void visitGlobalStatement(GlobalStatementTree tree) { for (VariableTree variableTree : tree.variables()) { Symbol symbol = context().symbolTable().getSymbol(variableTree); if (variableTree.is(Tree.Kind.VARIABLE_IDENTIFIER) && symbol != null) { Scope scope = symbol.scope(); String variable = ((VariableIdentifierTree) variableTree).text(); variableSetAsGlobalInScopes .computeIfAbsent(scope, key -> new ArrayList<>()) .add(variable); } } super.visitGlobalStatement(tree); }