Package gov.nasa.jpf.conformanceChecker.checkers

Source Code of gov.nasa.jpf.conformanceChecker.checkers.OrphanInstanceFieldChecker

//
// Copyright (C) 2012 United States Government as represented by the
// Administrator of the National Aeronautics and Space Administration
// (NASA).  All Rights Reserved.
//
// This software is distributed under the NASA Open Source Agreement
// (NOSA), version 1.3.  The NOSA has been approved by the Open Source
// Initiative.  See the file NOSA-1.3-JPF at the top of the distribution
// directory tree for the complete NOSA document.
//
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
//
package gov.nasa.jpf.conformanceChecker.checkers;

import gov.nasa.jpf.conformanceChecker.Inconsistency;
import gov.nasa.jpf.conformanceChecker.Inconsistency.InconsistencyType;
import gov.nasa.jpf.conformanceChecker.comparators.FieldInfoComparator;
import gov.nasa.jpf.conformanceChecker.providers.ProviderFactory;
import gov.nasa.jpf.conformanceChecker.providers.StandardClassProvider;
import gov.nasa.jpf.conformanceChecker.reporters.Reporter;
import gov.nasa.jpf.conformanceChecker.util.MaybeVersion;
import gov.nasa.jpf.jvm.ClassInfo;
import gov.nasa.jpf.jvm.FieldInfo;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
* This checker looks for orphan instance fields
*
* @see InconsistencyType#ORPHAN_FIELD
*
* @author Matteo Ceccarello <matteo.ceccarello AT gmail.com>
*
*/
public class OrphanInstanceFieldChecker extends Checker {
 
  private FieldInfoComparator comparator = new FieldInfoComparator();
 
  StandardClassProvider provider;

  public OrphanInstanceFieldChecker(List<Reporter> reporters, MemberLevel level) {
    super(reporters, level);
    this.provider = ProviderFactory.getStandardProvider();
  }

  public OrphanInstanceFieldChecker(List<Reporter> reporters) {
    super(reporters);
    this.provider = ProviderFactory.getStandardProvider();
  }

  public OrphanInstanceFieldChecker() {
    super();
    this.provider = ProviderFactory.getStandardProvider();
  }
 
  @Override
  public boolean check(ClassInfo cls) {
    boolean noInconsistencies = true;
    Map<MaybeVersion, ClassInfo> versions = provider.loadClassInfo(cls.getName());
    FieldInfo[] modelFields = cls.getDeclaredInstanceFields();
    for(MaybeVersion ver : versions.keySet()) {
      ClassInfo std = versions.get(ver);
      FieldInfo[] stdFields = std.getDeclaredInstanceFields();
      Arrays.sort(stdFields, comparator);
      for (FieldInfo f : modelFields) {
        if(MemberLevel.getMemberLevel(f).compareTo(this.level) >= 0) {
          if (Arrays.binarySearch(stdFields, f, comparator) < 0) {
            signal(new Inconsistency(
                InconsistencyType.ORPHAN_FIELD, ver, cls, f,
                "This field is present in the model, but not in " +
                "the library version."));
            noInconsistencies = false;
          }
        }
      }
    }
    return noInconsistencies;
  }

}
TOP

Related Classes of gov.nasa.jpf.conformanceChecker.checkers.OrphanInstanceFieldChecker

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.