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 locateNode
   * @return true if the given path indicates a function
   */
  private static boolean isFunction(ASTNode locateNode) {
    assert locateNode != null;
    ASTNode parent = null;
    Identifier targetIdentifier = null;

    if (locateNode.getType() == ASTNode.FUNCTION_DECLARATION) {
      parent = ((FunctionDeclaration) locateNode);
      targetIdentifier = ((FunctionDeclaration) locateNode).getFunctionName();
    } else if (locateNode instanceof Identifier
        && !"define".equals(((Identifier) locateNode).getName())) { // $NON-NLS-1$
      targetIdentifier = (Identifier) locateNode;
      parent = targetIdentifier.getParent();
      if (parent != null && parent.getType() == ASTNode.NAMESPACE_NAME) {
        parent = targetIdentifier.getParent().getParent();
      }
    } else {
      return false;
    }

    // check if it is a function
    if (parent == null
        || parent.getType() != ASTNode.FUNCTION_DECLARATION
            && parent.getType() != ASTNode.FUNCTION_NAME
        || parent.getParent().getType() == ASTNode.METHOD_DECLARATION
        || parent.getType() == ASTNode.FULLY_QUALIFIED_TRAIT_METHOD_REFERENCE) {
      return false;
    }

    if (parent instanceof TraitAlias) {
      return false;
    }
    // check if it is a method
    final int type = parent.getParent().getType();
    if (type == ASTNode.FUNCTION_INVOCATION) {
      final int parentParentType = parent.getParent().getParent().getType();
      if (parentParentType == ASTNode.METHOD_DECLARATION
          || parentParentType == ASTNode.STATIC_METHOD_INVOCATION) {
        return false;
      }
    } else if (type == ASTNode.METHOD_DECLARATION) {
      return false;
    }

    return true;
  }
Ejemplo n.º 3
0
    public boolean apply(ASTNode node) {
      // stops when found - that's the reason to use ApplyAll
      if (exists) return false;

      if (node instanceof Identifier) {
        final Identifier id = (Identifier) node;
        if (name.equals(id.getName()) && id.getParent().getType() == type) {
          exists = true;
        }
      }

      return true;
    }