Package gov.nasa.jpf.conformanceChecker.checkers

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

//
// 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.JPF;
import gov.nasa.jpf.conformanceChecker.Inconsistency;
import gov.nasa.jpf.conformanceChecker.Inconsistency.InconsistencyType;
import gov.nasa.jpf.conformanceChecker.comparators.MangledMethodInfoComparator;
import gov.nasa.jpf.conformanceChecker.comparators.MethodInfoComparator;
import gov.nasa.jpf.conformanceChecker.providers.ModelClassProvider;
import gov.nasa.jpf.conformanceChecker.providers.NativePeerProvider;
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.reporters.SimpleCmdLineReporter;
import gov.nasa.jpf.conformanceChecker.util.MaybeVersion;
import gov.nasa.jpf.jvm.ClassInfo;
import gov.nasa.jpf.jvm.MethodInfo;

import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* This class looks for native methods that do not have a corresponding
* native peer.
*
* @see InconsistencyType#ORPHAN_NATIVE_PEER
*
* @author Matteo Ceccarello <matteo.ceccarello AT gmail.com>
*
*/
public class OrphanNativePeerChecker extends NativePeerChecker {
 
  private static Logger logger = JPF.getLogger(OrphanNativePeerChecker.class.getName());

  NativePeerProvider provider;

  private MethodInfoComparator comparator = new MethodInfoComparator()
 
  public OrphanNativePeerChecker(
      List<Reporter> reporters, MemberLevel level) {
    super(reporters, level);
    this.provider = ProviderFactory.getNativePeerProvider();
  }

  public OrphanNativePeerChecker(List<Reporter> reporters) {
    super(reporters);
    this.provider = ProviderFactory.getNativePeerProvider();
  }
 
  public OrphanNativePeerChecker() {
    super();
    this.provider = ProviderFactory.getNativePeerProvider();
  }
 
  @Override
  public boolean check(ClassInfo cls) {
    boolean noInconsistencies = true;
   
    ClassInfo peer = provider.loadNativePeerClass(cls);
    if (peer == null) // the class has no native peer
      return noInconsistencies; // nothing to do
   
    MethodInfo[] peerMethods = getPeerMethods(peer);
    MethodInfo[] modelMethods = cls.getDeclaredMethodInfos();
    Arrays.sort(modelMethods, comparator);
   
    MangledMethodInfoComparator comp = new MangledMethodInfoComparator(true);
   
    for (MethodInfo peerMth : peerMethods) {
      if (Arrays.binarySearch(modelMethods, peerMth, comp) < 0) {
        signal(new Inconsistency(
            InconsistencyType.MISSING_NATIVE_PEER,
            MaybeVersion.nothing(),
            peer,
            peerMth,
            "This native peer is missing a corresponding method in the " +
            "model class."));
      }
    }
   
   
    return noInconsistencies;
   
  }
 
  public static void main(String[] args) {
    ProviderFactory.init(JPF.createConfig(args));
    logger.setLevel(Level.ALL);
    ClassInfo cls = new ModelClassProvider().loadClassInfo("java.lang.System");
    OrphanNativePeerChecker onpc = new OrphanNativePeerChecker();
    SimpleCmdLineReporter reporter = new SimpleCmdLineReporter(JPF.createConfig(args));
    onpc.registerReporter(reporter);
    System.out.println(onpc.check(cls));
  }

}
TOP

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

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.