Package gov.nasa.jpf.conformanceChecker

Source Code of gov.nasa.jpf.conformanceChecker.Inconsistency

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

import gov.nasa.jpf.conformanceChecker.util.MaybeVersion;
import gov.nasa.jpf.jvm.ClassInfo;
import gov.nasa.jpf.jvm.FieldInfo;
import gov.nasa.jpf.jvm.InfoObject;
import gov.nasa.jpf.jvm.MethodInfo;

import java.lang.reflect.Modifier;

/**
* Class that gathers informations about a detected inconsistency.
*
* @author Matteo Ceccarello <matteo.ceccarello AT gmail.com>
*
*/
public class Inconsistency {
 
  /**
   * This enum represents the supported inconsistency
   * types.
   */
  public enum InconsistencyType {
    /**
     * Inconsistency due to a method present in the standard
     * version of the class, but not in the model.
     */
    MISSING_METHOD,
    /**
     * Inconsistency due to a field present in the standard
     * version of the class, but not in the model.
     */
    MISSING_FIELD,
    /**
     * Inconsistency due to a native method in the model class
     * missing its native peer.
     */
    MISSING_NATIVE_PEER,
    /**
     * Inconsistency due to a method present in the model
     * of the class, but not in the standard version.
     */
    ORPHAN_METHOD,
    /**
     * Inconsistency due to a field present in the model
     * of the class, but not in the standard version.
     */
    ORPHAN_FIELD,
    /**
     * Inconsistency due to a native peer missing the corresponding
     * method in the model class.
     */
    ORPHAN_NATIVE_PEER,
    /**
     * Represent a member that has the name corresponding to the library
     * version, but different modifiers.
     */
    INCONSISTENT_MODIFIERS,
    /**
     * The state of a class is determined by its static fields. This
     * inconsistency represents the situation in which the model class
     * has a different state from the library version.
     */
    INCONSISTENT_CLASS_STATE,
    /**
     * The state of a object is made up by its instance fields. This
     * inconsistency represents the situation in which an instance
     * of a model class has a different state from an instance of the
     * library version.
     */
    INCONSISTENT_OBJECT_STATE
  }
  private MaybeVersion javaVersion;
 
  /**
   * The type of inconsistency represented by this object.
   */
  private InconsistencyType type;
 
  /**
   * The class to which the member belongs to.
   */
  private ClassInfo memberClass;
 
  /**
   * The name of the member on which he inconsistency was detected.
   */
  private InfoObject member;
 
  /**
   * General purpose description for this inconsistency.
   */
  private String description;

  public Inconsistency(InconsistencyType type, MaybeVersion javaVersion,
      ClassInfo memberClass,
      InfoObject member, String description) {
    super();
    this.javaVersion = javaVersion;
    this.type = type;
    this.memberClass = memberClass;
    this.member = member;
    this.description = description;
  }

  public ClassInfo getMemberClass() {
    return memberClass;
  }



  public void setMemberClass(ClassInfo memberClass) {
    this.memberClass = memberClass;
  }

  public InfoObject getMember() {
    return member;
  }



  public void setMember(InfoObject member) {
    this.member = member;
  }

  public MaybeVersion getJavaVersion() {
    return javaVersion;
  }

  public void setJavaVersion(MaybeVersion javaVersion) {
    this.javaVersion = javaVersion;
  }

  public InconsistencyType getType() {
    return type;
  }

  public void setType(InconsistencyType type) {
    this.type = type;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }
 
  public String getMemberName() {
    if(member instanceof MethodInfo) {
      MethodInfo mi = ((MethodInfo) member);
      if("<init>".equals(mi.getName())) // constructors
        return memberClass.getSimpleName() + " " + mi.getLongName();
                  //Arrays.toString(mi.getArgumentTypeNames()).replace('[','(').replace(']', ')');
      return mi.getReturnTypeName() + " " + mi.getLongName();
    }
    if(member instanceof FieldInfo) {
      FieldInfo fi = ((FieldInfo) member);
      return fi.getType() + " " + fi.getName();
    }
    throw new RuntimeException("Member " + member + " is not a " +
        "field nor a method");
  }
 
  public String getMemberModifiers() {
    if(member instanceof MethodInfo) {
      return Modifier.toString(((MethodInfo) member).getModifiers());
    }
    if(member instanceof FieldInfo) {
      return Modifier.toString(((FieldInfo) member).getModifiers());
    }
    throw new RuntimeException("Member " + member + " is not a " +
        "field nor a method");
  }

  @Override
  public String toString() {
    return "Inconsistency [type=" + type + ", javaVersion=" + javaVersion
        + ", memberClass= " + memberClass
        + ", member=" + member + ", description=" + description + "]";
  }

}
TOP

Related Classes of gov.nasa.jpf.conformanceChecker.Inconsistency

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.