コード例 #1
0
ファイル: InitChecker.java プロジェクト: tianhuat/polyglot
  /** Perform necessary actions upon seeing the ConstructorDecl <code>cd</code>. */
  protected void finishConstructorDecl(
      FlowGraph graph, ConstructorDecl cd, DataFlowItem dfIn, DataFlowItem dfOut) {
    ConstructorInstance ci = cd.constructorInstance();

    // we need to set currCBI.fieldsConstructorInitializes correctly.
    // It is meant to contain the non-static final fields that the
    // constructor ci initializes.
    //
    // Note that dfOut.initStatus contains only the MinMaxInitCounts
    // for _normal_ termination of the constructor (see the
    // method confluence). This means that if dfOut says the min
    // count of the initialization for a final non-static field
    // is one, and that is different from what is recoreded in
    // currCBI.currClassFinalFieldInitCounts (which is the counts
    // of the initializations performed by initializers), then
    // the constructor does indeed initialize the field.

    Set s = new HashSet();

    // go through every final non-static field in dfOut.initStatus
    Iterator iter = dfOut.initStatus.entrySet().iterator();
    while (iter.hasNext()) {
      Entry e = (Entry) iter.next();
      if (e.getKey() instanceof FieldInstance
          && ((FieldInstance) e.getKey()).flags().isFinal()
          && !((FieldInstance) e.getKey()).flags().isStatic()) {
        // we have a final non-static field
        FieldInstance fi = (FieldInstance) e.getKey();
        MinMaxInitCount initCount = (MinMaxInitCount) e.getValue();
        MinMaxInitCount origInitCount =
            (MinMaxInitCount) currCBI.currClassFinalFieldInitCounts.get(fi);
        if (initCount.getMin() == InitCount.ONE
            && (origInitCount == null || origInitCount.getMin() == InitCount.ZERO)) {
          // the constructor initialized this field
          s.add(fi);
        }
      }
    }
    if (!s.isEmpty()) {
      currCBI.fieldsConstructorInitializes.put(ci, s);
    }
  }