Ejemplo n.º 1
0
 public boolean visit(Assignment assignment) throws Exception {
   Expression left = assignment.getVariable();
   if (left instanceof FieldAccess) { // class variable ($this->a = .)
     FieldAccess fieldAccess = (FieldAccess) left;
     Expression dispatcher = fieldAccess.getDispatcher();
     if (dispatcher instanceof VariableReference
         && "$this".equals(((VariableReference) dispatcher).getName())) { // $NON-NLS-1$
       Expression field = fieldAccess.getField();
       if (field instanceof SimpleReference) {
         SimpleReference var = (SimpleReference) field;
         int modifiers = Modifiers.AccPublic;
         int offset = var.sourceStart();
         int length = var.sourceEnd() - offset;
         StringBuilder metadata = new StringBuilder();
         if (fCurrentQualifier != null) {
           metadata.append(fCurrentQualifierCounts.get(fCurrentQualifier));
           metadata.append(";"); // $NON-NLS-1$
         }
         modifyDeclaration(
             assignment,
             new DeclarationInfo(
                 IModelElement.FIELD,
                 modifiers,
                 offset,
                 length,
                 offset,
                 length,
                 '$' + var.getName(),
                 metadata.length() == 0 ? null : metadata.toString(),
                 null,
                 fCurrentQualifier,
                 fCurrentParent));
       }
     }
   } else if (left instanceof VariableReference) {
     int modifiers = Modifiers.AccPublic | Modifiers.AccGlobal;
     if (!declarations.empty()
         && declarations.peek() instanceof MethodDeclaration
         && !methodGlobalVars.peek().contains(((VariableReference) left).getName())) {
       return visitGeneral(assignment);
     }
     int offset = left.sourceStart();
     int length = left.sourceEnd() - offset;
     modifyDeclaration(
         assignment,
         new DeclarationInfo(
             IModelElement.FIELD,
             modifiers,
             offset,
             length,
             offset,
             length,
             ((VariableReference) left).getName(),
             null,
             null,
             null,
             null));
   }
   return visitGeneral(assignment);
 }
  public boolean visit(Assignment assignment) throws Exception {
    Expression left = assignment.getVariable();
    if (left instanceof FieldAccess) { // class variable ($this->a = .)
      FieldAccess fieldAccess = (FieldAccess) left;
      Expression dispatcher = fieldAccess.getDispatcher();
      if (dispatcher instanceof VariableReference
          && "$this" //$NON-NLS-1$
              .equals(((VariableReference) dispatcher).getName())) {
        Expression field = fieldAccess.getField();
        if (field instanceof SimpleReference) {
          SimpleReference ref = (SimpleReference) field;
          ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
          info.modifiers = Modifiers.AccPublic;
          info.name = '$' + ref.getName();
          info.nameSourceEnd = ref.sourceEnd() - 1;
          info.nameSourceStart = ref.sourceStart();
          info.declarationStart = assignment.sourceStart();
          fInfoStack.push(info);
          fRequestor.enterField(info);
          fNodes.push(assignment);
        }
      }
    } else if (left instanceof VariableReference && !(left instanceof ArrayVariableReference)) {
      if (!declarations.empty()) {
        ASTNode parentDeclaration = declarations.peek();
        if (parentDeclaration instanceof MethodDeclaration
                && methodGlobalVars.peek().contains(((VariableReference) left).getName())
            || parentDeclaration == fLastNamespace) {
          deferredDeclarations.add(assignment);
          return false;
        }
      }
      if (!fInfoStack.isEmpty() && fInfoStack.peek() instanceof ISourceElementRequestor.FieldInfo) {
        if (!fDeferredVariables.containsKey(fInfoStack.peek())) {
          fDeferredVariables.put(fInfoStack.peek(), new LinkedList<Assignment>());
        }
        fDeferredVariables.get(fInfoStack.peek()).add(assignment);
        return false;
      }
      ISourceElementRequestor.FieldInfo info = new ISourceElementRequestor.FieldInfo();
      info.modifiers = Modifiers.AccPublic;
      info.name = ((VariableReference) left).getName();
      info.nameSourceEnd = left.sourceEnd() - 1;
      info.nameSourceStart = left.sourceStart();
      info.declarationStart = assignment.sourceStart();

      fInfoStack.push(info);
      if (assignment.getOperatorType() == Assignment.OP_EQUAL) {
        fRequestor.enterField(info);
      } else {
        ISourceElementRequestor sourceElementRequestor = (ISourceElementRequestor) fRequestor;
        sourceElementRequestor.enterFieldCheckDuplicates(info);
      }
      fNodes.push(assignment);
    }
    return true;
  }