Ejemplo n.º 1
0
    public boolean apply(ASTNode node) {

      // stops when found - that's the reason to use ApplyAll
      if (exists) return false;

      if (node.getType() == ASTNode.CLASS_DECLARATION
          || node.getType() == ASTNode.FUNCTION_DECLARATION) {
        isGlobalScope = false;
        node.childrenAccept(this);
        isGlobalScope = true;
        return false;
      } else if (node instanceof Identifier) {
        Identifier identifier = (Identifier) node;
        if (identifier.getParent().getType() == ASTNode.VARIABLE) {
          Variable variable = (Variable) identifier.getParent();
          if (variable.isDollared() && isGlobalScope && name.equals(identifier.getName())) {
            exists = true;
          }
        }
      } else if (node.getType() == ASTNode.GLOBAL_STATEMENT) {
        GlobalStatement globalStatement = (GlobalStatement) node;
        final List<Variable> variables = globalStatement.variables();
        for (final Variable variable : variables) {
          final Expression variableName = variable.getName();
          if (variable.isDollared() && variableName instanceof Identifier) {
            Identifier identifier = (Identifier) variableName;
            if (name.equals(identifier.getName())) {
              exists = true;
            }
          }
        }
      }

      return true;
    }
Ejemplo n.º 2
0
  /**
   * @param targetIdentifier
   * @param variable
   * @param isGlobal
   * @param globalStatement
   * @return true is the
   */
  private static boolean checkGlobal(
      Identifier targetIdentifier, final GlobalStatement globalStatement) {
    final List<Variable> variables = globalStatement.variables();
    for (final Variable current : variables) {
      // if the variable is reflection (eg. global $$var) skip
      if (current.getName().getType() == ASTNode.IDENTIFIER) {
        Identifier id = (Identifier) current.getName();

        // variables are case sensative
        if (id.getName().equals(targetIdentifier.getName())) {
          return true;
        }
      }
    }
    return false;
  }