예제 #1
0
 @Override
 public void visit(Tree.Body that) {
   if (hasParameter && that.getScope() == declaration.getContainer()) {
     hasParameter = false;
   }
   for (Tree.Statement st : that.getStatements()) {
     if (st instanceof Tree.AttributeDeclaration) {
       Tree.AttributeDeclaration ad = (Tree.AttributeDeclaration) st;
       withinAttributeInitializer =
           ad.getDeclarationModel() == declaration
               && !(ad.getSpecifierOrInitializerExpression()
                   instanceof Tree.LazySpecifierExpression);
     } else {
       withinAttributeInitializer = false;
     }
     st.visit(this);
     withinAttributeInitializer = false;
   }
 }
예제 #2
0
  @Override
  public void visit(Tree.Block that) {
    Scope scope = that.getScope();
    if (scope instanceof Constructor) {
      if (definitelyInitedBy.contains(delegatedConstructor)) {
        specified.definitely = true;
      }
      if (possiblyInitedBy.contains(delegatedConstructor)) {
        specified.possibly = true;
      }
      delegatedConstructor = null;
    }

    boolean oe = endsInBreakReturnThrow;
    Tree.Continue olc = lastContinue;
    Tree.Statement olcs = lastContinueStatement;
    // rather nasty way of detecting that the continue
    // occurs in another conditional branch of the
    // statement containing this block, even though we
    // did not find it in _this_ branch
    boolean continueInSomeBranchOfCurrentConditional =
        lastContinue != null && lastContinueStatement == null;
    boolean blockEndsInBreakReturnThrow = blockEndsInBreakReturnThrow(that);
    endsInBreakReturnThrow = endsInBreakReturnThrow || blockEndsInBreakReturnThrow;
    Tree.Continue last = null;
    Tree.Statement lastStatement = null;
    for (Tree.Statement st : that.getStatements()) {
      ContinueVisitor cv = new ContinueVisitor(olc);
      st.visit(cv);
      if (cv.node != null) {
        last = cv.node;
        lastStatement = st;
      }
      if (cv.found) {
        olc = null;
        olcs = null;
      }
    }
    if (blockEndsInBreakReturnThrow || continueInSomeBranchOfCurrentConditional) {
      lastContinue = last;
      lastContinueStatement = lastStatement;
    }
    super.visit(that);
    endsInBreakReturnThrow = oe;
    lastContinue = olc;
    lastContinueStatement = olcs;

    if (scope instanceof Constructor) {
      Constructor c = (Constructor) scope;
      if (specified.definitely) {
        definitelyInitedBy.add(c);
      }
      if (specified.possibly) {
        possiblyInitedBy.add(c);
      }
    }
    if (isNonPartialConstructor(scope) && declaration.getContainer() == scope.getContainer()) {
      if (!specified.definitely) {
        initedByEveryConstructor = false;
      }
    }
  }