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;
  }
    public boolean visit(Expression e) throws Exception {
      if (typeDeclaration.sourceStart() < e.sourceStart()
          && typeDeclaration.sourceEnd() > e.sourceEnd()) {
        if (e instanceof Assignment) {
          if (e.sourceStart() == offset && e.sourceEnd() - e.sourceStart() == length) {
            result = ((Assignment) e).getValue();
            context = contextStack.peek();
          } else if (variableName != null) {
            Assignment assignment = (Assignment) e;
            Expression left = assignment.getVariable();
            Expression right = assignment.getValue();

            if (left instanceof StaticFieldAccess) {
              StaticFieldAccess fieldAccess = (StaticFieldAccess) left;
              Expression dispatcher = fieldAccess.getDispatcher();
              if (dispatcher instanceof TypeReference
                  && "self".equals(((TypeReference) dispatcher).getName())) { // $NON-NLS-1$
                Expression field = fieldAccess.getField();
                if (field instanceof VariableReference
                    && variableName.equals(((VariableReference) field).getName())) {
                  staticDeclarations.put(right, contextStack.peek());
                }
              }
            } else if (left instanceof FieldAccess) {
              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
                    && variableName.equals('$' + ((SimpleReference) field).getName())) {
                  staticDeclarations.put(right, contextStack.peek());
                }
              }
            }
          }
        }
      }
      return visitGeneral(e);
    }
Ejemplo n.º 4
0
  public boolean visit(FieldAccess access) throws Exception {
    // This is variable field access:
    if (access.getField() instanceof SimpleReference) {
      SimpleReference simpleReference = (SimpleReference) access.getField();

      String name = simpleReference.getName();
      if (!name.startsWith(DOLOR)) {
        name = DOLOR + name;
      }
      modifyReference(
          access,
          new ReferenceInfo(
              IModelElement.FIELD,
              simpleReference.sourceStart(),
              simpleReference.sourceEnd() - simpleReference.sourceStart(),
              name,
              null,
              null));
    }

    return visitGeneral(access);
  }