コード例 #1
0
  public boolean visit(MethodDeclaration method) throws Exception {

    methodGlobalVars.add(new HashSet<String>());

    ASTNode parentDeclaration = null;
    if (!declarations.empty()) {
      parentDeclaration = declarations.peek();
    }

    // In case we are entering a nested element - just add to the deferred
    // list
    // and get out of the nested element visiting process
    if (parentDeclaration instanceof MethodDeclaration) {
      if (fLastNamespace == null) {
        deferredDeclarations.add(method);
      } else {
        deferredNamespacedDeclarations.add(method);
      }
      return false;
    }

    if (parentDeclaration instanceof InterfaceDeclaration) {
      method.setModifier(Modifiers.AccAbstract);
    }

    method.setModifiers(markAsDeprecated(method.getModifiers(), method));

    declarations.push(method);

    for (PHPSourceElementRequestorExtension visitor : extensions) {
      visitor.visit(method);
    }

    boolean visit = visitMethodDeclaration(method);

    if (visit) {
      // Process method argument (local variable) declarations:
      List<Argument> arguments = method.getArguments();
      for (Argument arg : arguments) {
        ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
        info.name = arg.getName();
        info.modifiers = Modifiers.AccPublic;
        info.nameSourceStart = arg.getNameStart();
        info.nameSourceEnd = arg.getNameEnd() - 1;
        info.declarationStart = arg.sourceStart();
        fRequestor.enterField(info);
        fRequestor.exitField(arg.sourceEnd() - 1);
      }
    }
    return visit;
  }
コード例 #2
0
  public boolean visit(LambdaFunctionDeclaration lambdaMethod) throws Exception {

    fNodes.push(lambdaMethod);
    methodGlobalVars.add(new HashSet<String>());

    // Declaration parentDeclaration = null;
    // if (!declarations.empty()
    // && declarations.peek() instanceof MethodDeclaration) {
    // parentDeclaration = declarations.peek();
    // // In case we are entering a nested element - just add to the
    // // deferred list and get out of the nested element visiting process
    // deferredDeclarations.add(lambdaMethod);
    // return visitGeneral(lambdaMethod);
    // }

    Collection<FormalParameter> arguments = lambdaMethod.getArguments();
    StringBuilder metadata = new StringBuilder();
    String[] parameters;
    if (arguments != null) {
      parameters = new String[arguments.size()];
      Iterator<FormalParameter> i = arguments.iterator();
      int indx = 0;
      while (i.hasNext()) {
        Argument arg = (Argument) i.next();
        metadata.append(arg.getName());
        parameters[indx] = arg.getName();
        indx++;
        if (i.hasNext()) {
          metadata.append(","); // $NON-NLS-1$
        }
      }
    } else {
      parameters = new String[0];
    }

    // Add method declaration:
    for (PHPSourceElementRequestorExtension visitor : extensions) {
      visitor.visit(lambdaMethod);
    }

    ISourceElementRequestor.MethodInfo mi = new ISourceElementRequestor.MethodInfo();
    mi.parameterNames = parameters;
    mi.name = PHPCoreConstants.ANONYMOUS;
    mi.modifiers = Modifiers.AccPublic;
    if (lambdaMethod.isStatic()) {
      mi.modifiers |= Modifiers.AccStatic;
    }
    mi.nameSourceStart = lambdaMethod.sourceStart();
    mi.nameSourceEnd = lambdaMethod.sourceEnd();
    mi.declarationStart = mi.nameSourceStart;
    mi.isConstructor = false;

    fInfoStack.push(mi);
    this.fRequestor.enterMethod(mi);
    this.fInMethod = true;

    for (Argument arg : arguments) {
      ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
      info.name = arg.getName();
      info.modifiers = Modifiers.AccPublic;
      info.nameSourceStart = arg.getNameStart();
      info.nameSourceEnd = arg.getNameEnd() - 1;
      info.declarationStart = arg.sourceStart();
      fRequestor.enterField(info);
      fRequestor.exitField(arg.sourceEnd() - 1);
    }

    return true;
  }