Standard Libraries

/** Classes to represent standard classes and methods from the JDK. */

import Member

/** The class java.lang.Object */
class TypeObject extends Class {
  TypeObject() {
    this.hasQualifiedName("java.lang", "Object")
  }
}

/** The interface java.lang.Cloneable */
class TypeCloneable extends Interface {
  TypeCloneable() {
    this.hasQualifiedName("java.lang", "Cloneable")
  }
}

/** The interface java.io.Serializable */
class TypeSerializable extends Interface {
  TypeSerializable() {
    this.hasQualifiedName("java.io", "Serializable")
  }
}

/** The type java.lang.String */
class TypeString extends Class {
  TypeString() {
    this.hasQualifiedName("java.lang", "String")
  }
}

/** A method with the same signature as java.lang.Object.equals */
class EqualsMethod extends Method {
  EqualsMethod() {
    this.hasName("equals") and
    this.getNumberOfParameters() = 1 and
    ((RefType)this.getParameter(0).getType()).hasQualifiedName("java.lang", "Object")
  }

  /** gets the single parameter of this method */
  Parameter getParameter() {
    result = this.getAParameter()
  }
}

/** A method with the same signature as java.lang.Object.hashCode */
class HashCodeMethod extends Method {
  HashCodeMethod() {
    this.hasName("hashCode") and
    this.getNumberOfParameters() = 0
  }
}

/** A method with the same signature as java.lang.Object.clone */
class CloneMethod extends Method {
  CloneMethod() {
    this.hasName("clone") and
    this.hasNoParameters()
  }
}

/** A main method. */
class MainMethod extends Method {
  MainMethod() {
    this.hasModifier("public") and 
    this.hasModifier("static") and
    this.getType().hasName("void") and
    this.hasName("main") and
    this.getNumberOfParameters() = 1 and 
    exists(Array a | a = this.getAParameter().getType() and
                     a.getDimension() = 1 and
                     a.getElementType() instanceof TypeString)
  }
}