TypeHarness.java revision 791
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Test harness whose goal is to simplify the task of writing type-system
* regression test. It provides functionalities to build custom types as well
* as to access the underlying javac's symbol table in order to retrieve
* predefined types. Among the features supported by the harness are: type
* substitution, type containment, subtyping, cast-conversion, assigment
* conversion.
*
* This class is meant to be a common super class for all concrete type test
* classes. A subclass can access the type-factory and the test methods so as
* to write compact tests. An example is reported below:
*
* <pre>
* Type X = fac.TypeVariable();
* Type Y = fac.TypeVariable();
* Type A_X_Y = fac.Class(0, X, Y);
* Type A_Obj_Obj = fac.Class(0,
* predef.objectType,
* predef.objectType);
* checkSameType(A_Obj_Obj, subst(A_X_Y,
* Mapping(X, predef.objectType),
* Mapping(Y, predef.objectType)));
* </pre>
*
* The above code is used to create two class types, namely {@code A<X,Y>} and
* {@code A<Object,Object>} where both {@code X} and {@code Y} are type-variables.
* The code then verifies that {@code [X:=Object,Y:=Object]A<X,Y> == A<Object,Object>}.
*
* @author mcimadamore
*/
public class TypeHarness {
protected TypeHarness() {
}
// <editor-fold defaultstate="collapsed" desc="type assertions">
/** assert that 's' is a subtype of 't' */
assertSubtype(s, t, true);
}
" is not a subtype of " :
" is a subtype of ";
}
}
/** assert that 's' is the same type as 't' */
assertSameType(s, t, true);
}
" is not the same type as " :
" is the same type as ";
}
}
/** assert that 's' is castable to 't' */
assertCastable(s, t, true);
}
" is not castable to " :
" is castable to ";
}
}
/** assert that 's' is convertible (method invocation conversion) to 't' */
assertCastable(s, t, true);
}
" is not convertible to " :
" is convertible to ";
}
}
/** assert that 's' is assignable to 't' */
assertCastable(s, t, true);
}
" is not assignable to " :
" is assignable to ";
}
}
// </editor-fold>
}
// <editor-fold defaultstate="collapsed" desc="type functions">
/** compute the erasure of a type 't' */
}
/** compute the capture of a type 't' */
}
/** compute the boxed type associated with 't' */
if (!t.isPrimitive()) {
throw new AssertionError("Cannot box non-primitive type: " + t);
}
}
/** compute the unboxed type associated with 't' */
if (t == null) {
throw new AssertionError("Cannot unbox reference type: " + t);
} else {
return u;
}
}
/** compute a type substitution on 't' given a list of type mappings */
}
}
/** create a fresh type mapping from a type to another */
}
public static class Mapping {
}
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="type factory">
/**
* This class is used to create Java types in a simple way. All main
* kinds of type are supported: primitive, reference, non-denotable. The
* factory also supports creation of constant types (used by the compiler
* to represent the type of a literal).
*/
public class Factory {
private int synthNameCount = 0;
private Name syntheticName() {
}
}
}
}
}
}
}
}
}
}
}
}
}
public TypeVar TypeVariable() {
}
}
}
}
return ct;
}
}
// </editor-fold>
}