Package gov.nasa.jpf.conformanceChecker.checkers

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

//
// 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;

/**
* Checker that looks if there are missing static fields
*
* @see InconsistencyType#MISSING_FIELD
*
* @author Matteo Ceccarello <matteo.ceccarello AT gmail.com>
*
*/
public class MissingStaticFieldChecker extends Checker{
 
  FieldInfoComparator comparator = new FieldInfoComparator();
  StandardClassProvider provider;

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

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

  public MissingStaticFieldChecker() {
    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.getDeclaredStaticFields();
    Arrays.sort(modelFields, comparator);
    for(MaybeVersion ver : versions.keySet()) {
      ClassInfo std = versions.get(ver);
      FieldInfo[] stdFields = std.getDeclaredStaticFields();
      for (FieldInfo f : stdFields) {
        if(MemberLevel.getMemberLevel(f).compareTo(this.level) >= 0) {
          if (Arrays.binarySearch(modelFields, f, comparator) < 0) {
            signal(new Inconsistency(
                InconsistencyType.MISSING_FIELD, ver, cls, f,
                "This field is present in the library class, but " +
                "missing in the library version."));
            noInconsistencies = false;
          }
        }
      }
    }
    return noInconsistencies;
  }

}
TOP

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

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.