@Override
 public void visitMethodInvocation(MethodInvocation methodInvocation) {
   for (ExpressionStatement statement : methodInvocation.getArguments()) {
     statement.accept(this);
   }
   for (FunctionInvocation invocation : methodInvocation.getAnonymousFunctionInvocations()) {
     invocation.accept(this);
   }
 }
    public boolean apply(ASTNode node) {
      // stops when found - that's the reason to use ApplyAll
      if (exists) return false;

      if (node.getType() == ASTNode.SCALAR) {
        final Scalar scalar = (Scalar) node;

        final String stringValue = scalar.getStringValue();
        if (scalar.getScalarType() != Scalar.TYPE_STRING || stringValue == null) {
          return false;
        }

        final int length = stringValue.length() - 1;
        if (stringValue.charAt(0) != '"'
            && stringValue.charAt(length) != '"'
            && stringValue.equals(name)) {
          exists = true;
        }
      } else if (node.getType() == ASTNode.FUNCTION_INVOCATION) {
        FunctionInvocation functionInvocation = (FunctionInvocation) node;
        final Expression functionName = functionInvocation.getFunctionName().getName();
        if (!(functionName instanceof Identifier)) {
          return false;
        }

        final Identifier identifier = (Identifier) functionName;
        final List<Expression> parameters = functionInvocation.parameters();
        if (!"define".equalsIgnoreCase(identifier.getName())
            || parameters == null
            || parameters.size() == 0) { // $NON-NLS-1$
          return false;
        }

        final Expression expression = parameters.get(0);
        if (expression.getType() != ASTNode.SCALAR) {
          return false;
        }

        Scalar scalar = (Scalar) expression;
        final String stringValue = scalar.getStringValue();
        if (stringValue.length() < 2 || stringValue.charAt(0) != '"') {
          return false;
        }
        exists = name.equals(stringValue.substring(1, stringValue.length() - 1));
      }
      return true;
    }
Example #3
0
 @Override
 public void visitMethodInvocation(MethodInvocation methodInvocation) {
   incr();
   space();
   System.out.println(
       "Method invocation: "
           + methodInvocation.getName()
           + ", null safe? -> "
           + methodInvocation.isNullSafeGuarded());
   for (ExpressionStatement argument : methodInvocation.getArguments()) {
     argument.accept(this);
   }
   for (FunctionInvocation invocation : methodInvocation.getAnonymousFunctionInvocations()) {
     invocation.accept(this);
   }
   decr();
 }
Example #4
0
 @Override
 public void visitFunctionInvocation(FunctionInvocation functionInvocation) {
   incr();
   space();
   System.out.println(
       "Function call: "
           + functionInvocation.getName()
           + ", on reference? -> "
           + functionInvocation.isOnReference()
           + ", on module state? -> "
           + functionInvocation.isOnModuleState()
           + ", anonymous? -> "
           + functionInvocation.isAnonymous());
   for (ExpressionStatement argument : functionInvocation.getArguments()) {
     space();
     argument.accept(this);
   }
   for (FunctionInvocation invocation : functionInvocation.getAnonymousFunctionInvocations()) {
     invocation.accept(this);
   }
   decr();
 }
 @Override
 public void visitFunctionInvocation(FunctionInvocation functionInvocation) {
   if (context() != null) {
     Context context = context();
     String name = functionInvocation.getName();
     if (context.allReferences.contains(name)) {
       accessed(name);
       if (context.referenceTableStack.peek().get(name).isModuleState()) {
         functionInvocation.setOnModuleState(true);
       } else {
         functionInvocation.setOnReference(true);
       }
     }
   }
   for (ExpressionStatement statement : functionInvocation.getArguments()) {
     statement.accept(this);
   }
   for (FunctionInvocation invocation : functionInvocation.getAnonymousFunctionInvocations()) {
     invocation.accept(this);
   }
 }
  /**
   * Identifies a constant use
   *
   * @param locateNode
   * @return
   */
  private static boolean isConstant(ASTNode locateNode) {
    assert locateNode != null;
    Scalar scalar = null;
    // check if it is an identifier
    if (locateNode.getType() != ASTNode.SCALAR) {
      ASTNode parent = locateNode.getParent();
      ASTNode node = null;
      // php 5.3, the parent is NamespaceName
      if (parent instanceof NamespaceName) {
        node = parent.getParent().getParent();
      } else { // non-php 5.3
        node = parent.getParent();
      }

      // check if the node is 'define'
      if ((locateNode instanceof Identifier)
          && "define".equals(((Identifier) locateNode).getName()) // $NON-NLS-1$
          && node instanceof FunctionInvocation) {
        FunctionInvocation inv = (FunctionInvocation) node;
        List<Expression> parameters = inv.parameters();
        if (parameters != null && parameters.size() > 0) {
          Expression param = parameters.get(0);
          if (param instanceof Scalar) {
            scalar = (Scalar) param;
          } else {
            return false;
          }
        }
      } else {
        return false;
      }
    } else {
      scalar = (Scalar) locateNode;
    }

    // if it is not a dollared variable - it is not a global one
    if (scalar == null
        || scalar.getScalarType() != Scalar.TYPE_STRING
        || scalar.getStringValue() == null) {
      return false;
    }

    final int length = scalar.getStringValue().length() - 1;
    final char charAtBegining = scalar.getStringValue().charAt(0);
    final char charAtEnd = scalar.getStringValue().charAt(length);
    if (!detectString(charAtEnd) && !detectString(charAtBegining)) {
      return true;
    }

    // check if it is part of define
    ASTNode previous = locateNode.getParent();
    if (previous instanceof NamespaceName) {
      previous = previous.getParent();
    }
    if (previous.getType() == ASTNode.FUNCTION_NAME) {
      previous = previous.getParent();
    }

    if (previous.getType() != ASTNode.FUNCTION_INVOCATION) {
      return false;
    }

    final FunctionInvocation functionInvocation = (FunctionInvocation) previous;
    if (!(functionInvocation.getFunctionName().getName() instanceof Identifier)) {
      return false;
    }

    final Identifier identifier = (Identifier) functionInvocation.getFunctionName().getName();
    return "define".equalsIgnoreCase(identifier.getName())
        || "constant".equalsIgnoreCase(identifier.getName()); // $NON-NLS-1$ //$NON-NLS-2$
  }