org.jutil.java.reflect
Class Classes

java.lang.Object
  |
  +--org.jutil.java.reflect.Classes

public class Classes
extends java.lang.Object

Utility methods for class reflection.


Field Summary
static java.lang.String CVS_REVISION
           
static Filter PACKAGE_ACCESS_FILTER
           
static Filter PRIVATE_ACCESS_FILTER
           
static Filter PROTECTED_ACCESS_FILTER
           
static Filter PUBLIC_ACCESS_FILTER
           
 
Constructor Summary
Classes()
           
 
Method Summary
static boolean areInSamePackage(java.lang.Class t1, java.lang.Class t2)
          Check whether and are defined in the same package.
static java.util.Set getImmediateSuperTypes(java.lang.Class clazz)
          All immediate syper types of .
static java.util.SortedSet getSuperClasses(java.lang.Class clazz)
          All super classes of , including and Object. If is an interface, the set is empty.
static java.util.Set getSuperTypes(java.lang.Class clazz)
          All syper types of .
static java.lang.String packageName(java.lang.Class t)
          The fully qualified package name of type .
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION

PUBLIC_ACCESS_FILTER

public static final Filter PUBLIC_ACCESS_FILTER

PROTECTED_ACCESS_FILTER

public static final Filter PROTECTED_ACCESS_FILTER

PACKAGE_ACCESS_FILTER

public static final Filter PACKAGE_ACCESS_FILTER

PRIVATE_ACCESS_FILTER

public static final Filter PRIVATE_ACCESS_FILTER
Constructor Detail

Classes

public Classes()
Method Detail

getImmediateSuperTypes

public static java.util.Set getImmediateSuperTypes(java.lang.Class clazz)

All immediate syper types of . These are the interfaces and classes mentioned in the implements and extends clauses, or Object when there is no extends.

If the this method is applied to class Class, the result is the empty set.

Parameters:
clazz - The class to get all immediate super types for.

Specifications:
requires clazz != null;
ensures ( \forall Object o; \result .contains(o); o instanceof Class);
ensures ( \forall Object o; \result .contains(o); o != null);
ensures ( \forall Class c; \result .contains(c); c == clazz.getSuperclass()||Arrays.asList(clazz.getInterfaces()).contains(c));
ensures (clazz == Class.class) ==> \result .isEmpty();

getSuperTypes

public static java.util.Set getSuperTypes(java.lang.Class clazz)

All syper types of . This is the transitive closure of the immediate super types of .

Parameters:
clazz - The class to get all super types for.

Specifications:
requires clazz != null;
ensures ( \forall Object o; \result .contains(o); o instanceof Class);
ensures ( \forall Class c; \result .contains(c); c != null);
ensures ( \forall Class c; \result .contains(c); c.isAssignableFrom(clazz));
ensures \result .contains(clazz);
ensures (clazz == Object.class) ==> (\result .contains(Object.class))&&(\result .size() == 1);

getSuperClasses

public static java.util.SortedSet getSuperClasses(java.lang.Class clazz)

All super classes of , including and Object.

If is an interface, the set is empty.

Parameters:
clazz - The class to get all super classes for. //MvDMvDMvD : The following 2 postconditions are not required I think.

Specifications:
requires clazz != null;
ensures ( \forall Object o; \result .contains(o); o instanceof Class);
ensures ( \forall Class c; \result .contains(c); c != null);
ensures ( \forall Class c; \result .contains(c); !c.isInterface());
ensures ( \forall Class c; \result .contains(c); c.isAssignableFrom(clazz));
ensures ( \forall Class c; (c.isAssignableFrom(clazz))&&(!c.isInterface()); \result .contains(c));
ensures (clazz.isInterface()) ==> \result .size() == 0;
ensures (* The order of the result set is that subclasses are smaller than superclasses.*);

areInSamePackage

public static boolean areInSamePackage(java.lang.Class t1,
                                       java.lang.Class t2)
Check whether and are defined in the same package.

Parameters:
t1 - The first type to compare.
t2 - The second type to compare.

Specifications:
requires (t1 != null)&&(t2 != null);
ensures \result == (t1.getPackage().getName().equals(t2.getPackage().getName()));
ensures (t1.getPackage() == null||t2.getPackage() == null) ==> (\result == false);

packageName

public static java.lang.String packageName(java.lang.Class t)
The fully qualified package name of type . The empty string represents the unnamed package.

Parameters:
t - The type to get the fully qualified package name for. //MvDMvDMvD : for JDK 1.2+ this can be specified in terms of getPackage().getName()
Returns:
The fully qualified package name of . The empty string represents the unnamed package.

Specifications:
requires t != null;
ensures \result != null;
ensures Character.isJavaIdentifierStart(\result .charAt(1));
ensures ( \forall int i; (i > 0)&&(i < \result .length()); Character.isJavaIdentifierPart(\result .charAt(i)));