Пример #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;
    }
Пример #2
0
          public boolean apply(ASTNode node) {
            if (offset != end) {
              return false;
            }

            if (node.getType() == ASTNode.GLOBAL_STATEMENT) {
              GlobalStatement globalStatement = (GlobalStatement) node;
              if (checkGlobal(targetIdentifier, globalStatement)) {
                offset = globalStatement.getStart();
              }
            }

            return true;
          }
Пример #3
0
 public boolean visit(GlobalStatement s) throws Exception {
   if (!declarations.empty() && declarations.peek() instanceof MethodDeclaration) {
     for (Expression var : s.getVariables()) {
       if (var instanceof ReferenceExpression) {
         var = ((ReferenceExpression) var).getVariable();
       }
       if (var instanceof SimpleReference) {
         methodGlobalVars.peek().add(((SimpleReference) var).getName());
       }
     }
   }
   return visitGeneral(s);
 }
Пример #4
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;
  }