Merge
This commit is contained in:
commit
bedd4eef34
@ -75,6 +75,7 @@ public class Symtab {
|
||||
|
||||
private final Name.Table names;
|
||||
private final ClassReader reader;
|
||||
private final Target target;
|
||||
|
||||
/** A symbol for the root package.
|
||||
*/
|
||||
@ -144,6 +145,7 @@ public class Symtab {
|
||||
public final Type suppressWarningsType;
|
||||
public final Type inheritedType;
|
||||
public final Type proprietaryType;
|
||||
public final Type systemType;
|
||||
|
||||
/** The symbol representing the length field of an array.
|
||||
*/
|
||||
@ -272,6 +274,55 @@ public class Symtab {
|
||||
return reader.enterClass(names.fromString(s)).type;
|
||||
}
|
||||
|
||||
public void synthesizeEmptyInterfaceIfMissing(final Type type) {
|
||||
final Completer completer = type.tsym.completer;
|
||||
if (completer != null) {
|
||||
type.tsym.completer = new Completer() {
|
||||
public void complete(Symbol sym) throws CompletionFailure {
|
||||
try {
|
||||
completer.complete(sym);
|
||||
} catch (CompletionFailure e) {
|
||||
sym.flags_field |= (PUBLIC | INTERFACE);
|
||||
((ClassType) sym.type).supertype_field = objectType;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void synthesizeBoxTypeIfMissing(final Type type) {
|
||||
ClassSymbol sym = reader.enterClass(boxedName[type.tag]);
|
||||
final Completer completer = sym.completer;
|
||||
if (completer != null) {
|
||||
sym.completer = new Completer() {
|
||||
public void complete(Symbol sym) throws CompletionFailure {
|
||||
try {
|
||||
completer.complete(sym);
|
||||
} catch (CompletionFailure e) {
|
||||
sym.flags_field |= PUBLIC;
|
||||
((ClassType) sym.type).supertype_field = objectType;
|
||||
Name n = target.boxWithConstructors() ? names.init : names.valueOf;
|
||||
MethodSymbol boxMethod =
|
||||
new MethodSymbol(PUBLIC | STATIC,
|
||||
n,
|
||||
new MethodType(List.of(type), sym.type,
|
||||
List.<Type>nil(), methodClass),
|
||||
sym);
|
||||
sym.members().enter(boxMethod);
|
||||
MethodSymbol unboxMethod =
|
||||
new MethodSymbol(PUBLIC,
|
||||
type.tsym.name.append(names.Value), // x.intValue()
|
||||
new MethodType(List.<Type>nil(), type,
|
||||
List.<Type>nil(), methodClass),
|
||||
sym);
|
||||
sym.members().enter(unboxMethod);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Constructor; enters all predefined identifiers and operators
|
||||
* into symbol table.
|
||||
*/
|
||||
@ -279,6 +330,7 @@ public class Symtab {
|
||||
context.put(symtabKey, this);
|
||||
|
||||
names = Name.Table.instance(context);
|
||||
target = Target.instance(context);
|
||||
|
||||
// Create the unknown type
|
||||
unknownType = new Type(TypeTags.UNKNOWN, null);
|
||||
@ -373,7 +425,7 @@ public class Symtab {
|
||||
collectionsType = enterClass("java.util.Collections");
|
||||
comparableType = enterClass("java.lang.Comparable");
|
||||
arraysType = enterClass("java.util.Arrays");
|
||||
iterableType = Target.instance(context).hasIterable()
|
||||
iterableType = target.hasIterable()
|
||||
? enterClass("java.lang.Iterable")
|
||||
: enterClass("java.util.Collection");
|
||||
iteratorType = enterClass("java.util.Iterator");
|
||||
@ -383,6 +435,12 @@ public class Symtab {
|
||||
deprecatedType = enterClass("java.lang.Deprecated");
|
||||
suppressWarningsType = enterClass("java.lang.SuppressWarnings");
|
||||
inheritedType = enterClass("java.lang.annotation.Inherited");
|
||||
systemType = enterClass("java.lang.System");
|
||||
|
||||
synthesizeEmptyInterfaceIfMissing(cloneableType);
|
||||
synthesizeEmptyInterfaceIfMissing(serializableType);
|
||||
synthesizeBoxTypeIfMissing(doubleType);
|
||||
synthesizeBoxTypeIfMissing(floatType);
|
||||
|
||||
// Enter a synthetic class that is used to mark Sun
|
||||
// proprietary classes in ct.sym. This class does not have a
|
||||
|
@ -79,6 +79,7 @@ public class Attr extends JCTree.Visitor {
|
||||
final Enter enter;
|
||||
final Target target;
|
||||
final Types types;
|
||||
final JCDiagnostic.Factory diags;
|
||||
final Annotate annotate;
|
||||
|
||||
public static Attr instance(Context context) {
|
||||
@ -102,6 +103,7 @@ public class Attr extends JCTree.Visitor {
|
||||
cfolder = ConstFold.instance(context);
|
||||
target = Target.instance(context);
|
||||
types = Types.instance(context);
|
||||
diags = JCDiagnostic.Factory.instance(context);
|
||||
annotate = Annotate.instance(context);
|
||||
|
||||
Options options = Options.instance(context);
|
||||
@ -2419,7 +2421,7 @@ public class Attr extends JCTree.Visitor {
|
||||
|
||||
if (false) {
|
||||
// TODO: make assertConvertible work
|
||||
chk.typeError(tree.pos(), JCDiagnostic.fragment("incompatible.types"), actual, formal);
|
||||
chk.typeError(tree.pos(), diags.fragment("incompatible.types"), actual, formal);
|
||||
throw new AssertionError("Tree: " + tree
|
||||
+ " actual:" + actual
|
||||
+ " formal: " + formal);
|
||||
|
@ -63,6 +63,7 @@ public class Check {
|
||||
private final Target target;
|
||||
private final Source source;
|
||||
private final Types types;
|
||||
private final JCDiagnostic.Factory diags;
|
||||
private final boolean skipAnnotations;
|
||||
private final TreeInfo treeinfo;
|
||||
|
||||
@ -86,6 +87,7 @@ public class Check {
|
||||
syms = Symtab.instance(context);
|
||||
infer = Infer.instance(context);
|
||||
this.types = Types.instance(context);
|
||||
diags = JCDiagnostic.Factory.instance(context);
|
||||
Options options = Options.instance(context);
|
||||
target = Target.instance(context);
|
||||
source = Source.instance(context);
|
||||
@ -343,7 +345,7 @@ public class Check {
|
||||
if (types.isAssignable(found, req, convertWarner(pos, found, req)))
|
||||
return found;
|
||||
if (found.tag <= DOUBLE && req.tag <= DOUBLE)
|
||||
return typeError(pos, JCDiagnostic.fragment("possible.loss.of.precision"), found, req);
|
||||
return typeError(pos, diags.fragment("possible.loss.of.precision"), found, req);
|
||||
if (found.isSuperBound()) {
|
||||
log.error(pos, "assignment.from.super-bound", found);
|
||||
return syms.errType;
|
||||
@ -352,7 +354,7 @@ public class Check {
|
||||
log.error(pos, "assignment.to.extends-bound", req);
|
||||
return syms.errType;
|
||||
}
|
||||
return typeError(pos, JCDiagnostic.fragment("incompatible.types"), found, req);
|
||||
return typeError(pos, diags.fragment("incompatible.types"), found, req);
|
||||
}
|
||||
|
||||
/** Instantiate polymorphic type to some prototype, unless
|
||||
@ -380,7 +382,7 @@ public class Check {
|
||||
} else {
|
||||
JCDiagnostic d = ex.getDiagnostic();
|
||||
return typeError(pos,
|
||||
JCDiagnostic.fragment("incompatible.types" + (d!=null ? ".1" : ""), d),
|
||||
diags.fragment("incompatible.types" + (d!=null ? ".1" : ""), d),
|
||||
t, pt);
|
||||
}
|
||||
}
|
||||
@ -401,7 +403,7 @@ public class Check {
|
||||
return req;
|
||||
} else {
|
||||
return typeError(pos,
|
||||
JCDiagnostic.fragment("inconvertible.types"),
|
||||
diags.fragment("inconvertible.types"),
|
||||
found, req);
|
||||
}
|
||||
}
|
||||
@ -480,9 +482,9 @@ public class Check {
|
||||
Type checkClassType(DiagnosticPosition pos, Type t) {
|
||||
if (t.tag != CLASS && t.tag != ERROR)
|
||||
return typeTagError(pos,
|
||||
JCDiagnostic.fragment("type.req.class"),
|
||||
diags.fragment("type.req.class"),
|
||||
(t.tag == TYPEVAR)
|
||||
? JCDiagnostic.fragment("type.parameter", t)
|
||||
? diags.fragment("type.parameter", t)
|
||||
: t);
|
||||
else
|
||||
return t;
|
||||
@ -515,7 +517,7 @@ public class Check {
|
||||
Type checkReifiableReferenceType(DiagnosticPosition pos, Type t) {
|
||||
if (t.tag != CLASS && t.tag != ARRAY && t.tag != ERROR) {
|
||||
return typeTagError(pos,
|
||||
JCDiagnostic.fragment("type.req.class.array"),
|
||||
diags.fragment("type.req.class.array"),
|
||||
t);
|
||||
} else if (!types.isReifiable(t)) {
|
||||
log.error(pos, "illegal.generic.type.for.instof");
|
||||
@ -540,7 +542,7 @@ public class Check {
|
||||
return t;
|
||||
default:
|
||||
return typeTagError(pos,
|
||||
JCDiagnostic.fragment("type.req.ref"),
|
||||
diags.fragment("type.req.ref"),
|
||||
t);
|
||||
}
|
||||
}
|
||||
@ -560,7 +562,7 @@ public class Check {
|
||||
return t;
|
||||
default:
|
||||
return typeTagError(pos,
|
||||
JCDiagnostic.fragment("type.req.ref"),
|
||||
diags.fragment("type.req.ref"),
|
||||
t);
|
||||
}
|
||||
}
|
||||
@ -1028,7 +1030,7 @@ public class Check {
|
||||
* @param other The overridden method.
|
||||
* @return An internationalized string.
|
||||
*/
|
||||
static Object cannotOverride(MethodSymbol m, MethodSymbol other) {
|
||||
Object cannotOverride(MethodSymbol m, MethodSymbol other) {
|
||||
String key;
|
||||
if ((other.owner.flags() & INTERFACE) == 0)
|
||||
key = "cant.override";
|
||||
@ -1036,7 +1038,7 @@ public class Check {
|
||||
key = "cant.implement";
|
||||
else
|
||||
key = "clashes.with";
|
||||
return JCDiagnostic.fragment(key, m, m.location(), other, other.location());
|
||||
return diags.fragment(key, m, m.location(), other, other.location());
|
||||
}
|
||||
|
||||
/** A customized "override" warning message.
|
||||
@ -1044,7 +1046,7 @@ public class Check {
|
||||
* @param other The overridden method.
|
||||
* @return An internationalized string.
|
||||
*/
|
||||
static Object uncheckedOverrides(MethodSymbol m, MethodSymbol other) {
|
||||
Object uncheckedOverrides(MethodSymbol m, MethodSymbol other) {
|
||||
String key;
|
||||
if ((other.owner.flags() & INTERFACE) == 0)
|
||||
key = "unchecked.override";
|
||||
@ -1052,7 +1054,7 @@ public class Check {
|
||||
key = "unchecked.implement";
|
||||
else
|
||||
key = "unchecked.clash.with";
|
||||
return JCDiagnostic.fragment(key, m, m.location(), other, other.location());
|
||||
return diags.fragment(key, m, m.location(), other, other.location());
|
||||
}
|
||||
|
||||
/** A customized "override" warning message.
|
||||
@ -1060,7 +1062,7 @@ public class Check {
|
||||
* @param other The overridden method.
|
||||
* @return An internationalized string.
|
||||
*/
|
||||
static Object varargsOverrides(MethodSymbol m, MethodSymbol other) {
|
||||
Object varargsOverrides(MethodSymbol m, MethodSymbol other) {
|
||||
String key;
|
||||
if ((other.owner.flags() & INTERFACE) == 0)
|
||||
key = "varargs.override";
|
||||
@ -1068,7 +1070,7 @@ public class Check {
|
||||
key = "varargs.implement";
|
||||
else
|
||||
key = "varargs.clash.with";
|
||||
return JCDiagnostic.fragment(key, m, m.location(), other, other.location());
|
||||
return diags.fragment(key, m, m.location(), other, other.location());
|
||||
}
|
||||
|
||||
/** Check that this method conforms with overridden method 'other'.
|
||||
@ -1157,7 +1159,7 @@ public class Check {
|
||||
// allow limited interoperability with covariant returns
|
||||
} else {
|
||||
typeError(TreeInfo.diagnosticPositionFor(m, tree),
|
||||
JCDiagnostic.fragment("override.incompatible.ret",
|
||||
diags.fragment("override.incompatible.ret",
|
||||
cannotOverride(m, other)),
|
||||
mtres, otres);
|
||||
return;
|
||||
@ -1165,7 +1167,7 @@ public class Check {
|
||||
} else if (overrideWarner.warned) {
|
||||
warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree),
|
||||
"prob.found.req",
|
||||
JCDiagnostic.fragment("override.unchecked.ret",
|
||||
diags.fragment("override.unchecked.ret",
|
||||
uncheckedOverrides(m, other)),
|
||||
mtres, otres);
|
||||
}
|
||||
@ -2170,7 +2172,7 @@ public class Check {
|
||||
boolean warned = this.warned;
|
||||
super.warnUnchecked();
|
||||
if (warned) return; // suppress redundant diagnostics
|
||||
Object problem = JCDiagnostic.fragment(key);
|
||||
Object problem = diags.fragment(key);
|
||||
Check.this.warnUnchecked(pos(), "prob.found.req", problem, found, expected);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.code.*;
|
||||
import com.sun.tools.javac.code.Type.*;
|
||||
import com.sun.tools.javac.util.JCDiagnostic;
|
||||
|
||||
import static com.sun.tools.javac.code.Flags.*;
|
||||
import static com.sun.tools.javac.code.Kinds.*;
|
||||
@ -50,6 +51,7 @@ public class Infer {
|
||||
|
||||
Symtab syms;
|
||||
Types types;
|
||||
JCDiagnostic.Factory diags;
|
||||
|
||||
public static Infer instance(Context context) {
|
||||
Infer instance = context.get(inferKey);
|
||||
@ -62,6 +64,11 @@ public class Infer {
|
||||
context.put(inferKey, this);
|
||||
syms = Symtab.instance(context);
|
||||
types = Types.instance(context);
|
||||
diags = JCDiagnostic.Factory.instance(context);
|
||||
ambiguousNoInstanceException =
|
||||
new NoInstanceException(true, diags);
|
||||
unambiguousNoInstanceException =
|
||||
new NoInstanceException(false, diags);
|
||||
}
|
||||
|
||||
public static class NoInstanceException extends RuntimeException {
|
||||
@ -70,35 +77,35 @@ public class Infer {
|
||||
boolean isAmbiguous; // exist several incomparable best instances?
|
||||
|
||||
JCDiagnostic diagnostic;
|
||||
JCDiagnostic.Factory diags;
|
||||
|
||||
NoInstanceException(boolean isAmbiguous) {
|
||||
NoInstanceException(boolean isAmbiguous, JCDiagnostic.Factory diags) {
|
||||
this.diagnostic = null;
|
||||
this.isAmbiguous = isAmbiguous;
|
||||
this.diags = diags;
|
||||
}
|
||||
NoInstanceException setMessage(String key) {
|
||||
this.diagnostic = JCDiagnostic.fragment(key);
|
||||
this.diagnostic = diags.fragment(key);
|
||||
return this;
|
||||
}
|
||||
NoInstanceException setMessage(String key, Object arg1) {
|
||||
this.diagnostic = JCDiagnostic.fragment(key, arg1);
|
||||
this.diagnostic = diags.fragment(key, arg1);
|
||||
return this;
|
||||
}
|
||||
NoInstanceException setMessage(String key, Object arg1, Object arg2) {
|
||||
this.diagnostic = JCDiagnostic.fragment(key, arg1, arg2);
|
||||
this.diagnostic = diags.fragment(key, arg1, arg2);
|
||||
return this;
|
||||
}
|
||||
NoInstanceException setMessage(String key, Object arg1, Object arg2, Object arg3) {
|
||||
this.diagnostic = JCDiagnostic.fragment(key, arg1, arg2, arg3);
|
||||
this.diagnostic = diags.fragment(key, arg1, arg2, arg3);
|
||||
return this;
|
||||
}
|
||||
public JCDiagnostic getDiagnostic() {
|
||||
return diagnostic;
|
||||
}
|
||||
}
|
||||
private final NoInstanceException ambiguousNoInstanceException =
|
||||
new NoInstanceException(true);
|
||||
private final NoInstanceException unambiguousNoInstanceException =
|
||||
new NoInstanceException(false);
|
||||
private final NoInstanceException ambiguousNoInstanceException;
|
||||
private final NoInstanceException unambiguousNoInstanceException;
|
||||
|
||||
/***************************************************************************
|
||||
* Auxiliary type values and classes
|
||||
|
@ -2110,16 +2110,64 @@ public class Lower extends TreeTranslator {
|
||||
|
||||
Symbol valuesSym = lookupMethod(tree.pos(), names.values,
|
||||
tree.type, List.<Type>nil());
|
||||
JCTypeCast valuesResult =
|
||||
make.TypeCast(valuesSym.type.getReturnType(),
|
||||
make.App(make.Select(make.Ident(valuesVar),
|
||||
syms.arrayCloneMethod)));
|
||||
List<JCStatement> valuesBody;
|
||||
if (useClone()) {
|
||||
// return (T[]) $VALUES.clone();
|
||||
JCTypeCast valuesResult =
|
||||
make.TypeCast(valuesSym.type.getReturnType(),
|
||||
make.App(make.Select(make.Ident(valuesVar),
|
||||
syms.arrayCloneMethod)));
|
||||
valuesBody = List.<JCStatement>of(make.Return(valuesResult));
|
||||
} else {
|
||||
// template: T[] $result = new T[$values.length];
|
||||
Name resultName = names.fromString(target.syntheticNameChar() + "result");
|
||||
while (tree.sym.members().lookup(resultName).scope != null) // avoid name clash
|
||||
resultName = names.fromString(resultName + "" + target.syntheticNameChar());
|
||||
VarSymbol resultVar = new VarSymbol(FINAL|SYNTHETIC,
|
||||
resultName,
|
||||
arrayType,
|
||||
valuesSym);
|
||||
JCNewArray resultArray = make.NewArray(make.Type(types.erasure(tree.type)),
|
||||
List.of(make.Select(make.Ident(valuesVar), syms.lengthVar)),
|
||||
null);
|
||||
resultArray.type = arrayType;
|
||||
JCVariableDecl decl = make.VarDef(resultVar, resultArray);
|
||||
|
||||
// template: System.arraycopy($VALUES, 0, $result, 0, $VALUES.length);
|
||||
if (systemArraycopyMethod == null) {
|
||||
systemArraycopyMethod =
|
||||
new MethodSymbol(PUBLIC | STATIC,
|
||||
names.fromString("arraycopy"),
|
||||
new MethodType(List.<Type>of(syms.objectType,
|
||||
syms.intType,
|
||||
syms.objectType,
|
||||
syms.intType,
|
||||
syms.intType),
|
||||
syms.voidType,
|
||||
List.<Type>nil(),
|
||||
syms.methodClass),
|
||||
syms.systemType.tsym);
|
||||
}
|
||||
JCStatement copy =
|
||||
make.Exec(make.App(make.Select(make.Ident(syms.systemType.tsym),
|
||||
systemArraycopyMethod),
|
||||
List.of(make.Ident(valuesVar), make.Literal(0),
|
||||
make.Ident(resultVar), make.Literal(0),
|
||||
make.Select(make.Ident(valuesVar), syms.lengthVar))));
|
||||
|
||||
// template: return $result;
|
||||
JCStatement ret = make.Return(make.Ident(resultVar));
|
||||
valuesBody = List.<JCStatement>of(decl, copy, ret);
|
||||
}
|
||||
|
||||
JCMethodDecl valuesDef =
|
||||
make.MethodDef((MethodSymbol)valuesSym,
|
||||
make.Block(0, List.<JCStatement>nil()
|
||||
.prepend(make.Return(valuesResult))));
|
||||
make.MethodDef((MethodSymbol)valuesSym, make.Block(0, valuesBody));
|
||||
|
||||
enumDefs.append(valuesDef);
|
||||
|
||||
if (debugLower)
|
||||
System.err.println(tree.sym + ".valuesDef = " + valuesDef);
|
||||
|
||||
/** The template for the following code is:
|
||||
*
|
||||
* public static E valueOf(String name) {
|
||||
@ -2155,6 +2203,17 @@ public class Lower extends TreeTranslator {
|
||||
addEnumCompatibleMembers(tree);
|
||||
}
|
||||
}
|
||||
// where
|
||||
private MethodSymbol systemArraycopyMethod;
|
||||
private boolean useClone() {
|
||||
try {
|
||||
Scope.Entry e = syms.objectType.tsym.members().lookup(names.clone);
|
||||
return (e.sym != null);
|
||||
}
|
||||
catch (CompletionFailure e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Translate an enumeration constant and its initializer. */
|
||||
private void visitEnumConstantDef(JCVariableDecl var, int ordinal) {
|
||||
|
@ -72,6 +72,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
private final Todo todo;
|
||||
private final Annotate annotate;
|
||||
private final Types types;
|
||||
private final JCDiagnostic.Factory diags;
|
||||
private final Target target;
|
||||
|
||||
private final boolean skipAnnotations;
|
||||
@ -96,6 +97,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
todo = Todo.instance(context);
|
||||
annotate = Annotate.instance(context);
|
||||
types = Types.instance(context);
|
||||
diags = JCDiagnostic.Factory.instance(context);
|
||||
target = Target.instance(context);
|
||||
skipAnnotations =
|
||||
Options.instance(context).get("skipAnnotations") != null;
|
||||
@ -133,7 +135,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
if (tsym.kind == PCK && tsym.members().elems == null && !tsym.exists()) {
|
||||
// If we can't find java.lang, exit immediately.
|
||||
if (((PackageSymbol)tsym).fullname.equals(names.java_lang)) {
|
||||
JCDiagnostic msg = JCDiagnostic.fragment("fatal.err.no.java.lang");
|
||||
JCDiagnostic msg = diags.fragment("fatal.err.no.java.lang");
|
||||
throw new FatalError(msg);
|
||||
} else {
|
||||
log.error(pos, "doesnt.exist", tsym);
|
||||
@ -319,7 +321,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
log.error(pos, "cant.resolve.location",
|
||||
KindName.STATIC,
|
||||
name, List.<Type>nil(), List.<Type>nil(),
|
||||
typeKindName(tsym.type),
|
||||
Kinds.typeKindName(tsym.type),
|
||||
tsym.type);
|
||||
}
|
||||
} finally {
|
||||
|
@ -59,6 +59,7 @@ public class Resolve {
|
||||
ClassReader reader;
|
||||
TreeInfo treeinfo;
|
||||
Types types;
|
||||
JCDiagnostic.Factory diags;
|
||||
public final boolean boxingEnabled; // = source.allowBoxing();
|
||||
public final boolean varargsEnabled; // = source.allowVarargs();
|
||||
private final boolean debugResolve;
|
||||
@ -92,6 +93,7 @@ public class Resolve {
|
||||
reader = ClassReader.instance(context);
|
||||
treeinfo = TreeInfo.instance(context);
|
||||
types = Types.instance(context);
|
||||
diags = JCDiagnostic.Factory.instance(context);
|
||||
Source source = Source.instance(context);
|
||||
boxingEnabled = source.allowBoxing();
|
||||
varargsEnabled = source.allowVarargs();
|
||||
@ -449,7 +451,7 @@ public class Resolve {
|
||||
Symbol sym = findField(env, site, name, site.tsym);
|
||||
if (sym.kind == VAR) return (VarSymbol)sym;
|
||||
else throw new FatalError(
|
||||
JCDiagnostic.fragment("fatal.err.cant.locate.field",
|
||||
diags.fragment("fatal.err.cant.locate.field",
|
||||
name));
|
||||
}
|
||||
|
||||
@ -1248,7 +1250,7 @@ public class Resolve {
|
||||
pos, env, site, name, argtypes, typeargtypes);
|
||||
if (sym.kind == MTH) return (MethodSymbol)sym;
|
||||
else throw new FatalError(
|
||||
JCDiagnostic.fragment("fatal.err.cant.locate.meth",
|
||||
diags.fragment("fatal.err.cant.locate.meth",
|
||||
name));
|
||||
}
|
||||
|
||||
@ -1320,7 +1322,7 @@ public class Resolve {
|
||||
pos, env, site, argtypes, typeargtypes);
|
||||
if (sym.kind == MTH) return (MethodSymbol)sym;
|
||||
else throw new FatalError(
|
||||
JCDiagnostic.fragment("fatal.err.cant.locate.ctor", site));
|
||||
diags.fragment("fatal.err.cant.locate.ctor", site));
|
||||
}
|
||||
|
||||
/** Resolve operator.
|
||||
|
@ -59,20 +59,19 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
return instance;
|
||||
}
|
||||
|
||||
final Messages messages;
|
||||
DiagnosticFormatter<JCDiagnostic> formatter;
|
||||
final String prefix;
|
||||
|
||||
/** Create a new diagnostic factory. */
|
||||
protected Factory(Context context) {
|
||||
this(Messages.instance(context), "compiler");
|
||||
context.put(diagnosticFactoryKey, this);
|
||||
messages = Messages.instance(context);
|
||||
prefix = "compiler";
|
||||
}
|
||||
|
||||
/** Create a new diagnostic factory. */
|
||||
public Factory(Messages messages, String prefix) {
|
||||
this.messages = messages;
|
||||
this.prefix = prefix;
|
||||
this.formatter = new BasicDiagnosticFormatter(messages);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,7 +83,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
*/
|
||||
public JCDiagnostic error(
|
||||
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
|
||||
return new JCDiagnostic(messages, ERROR, true, source, pos, qualify(ERROR, key), args);
|
||||
return new JCDiagnostic(formatter, ERROR, true, source, pos, qualify(ERROR, key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,7 +96,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
*/
|
||||
public JCDiagnostic mandatoryWarning(
|
||||
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
|
||||
return new JCDiagnostic(messages, WARNING, true, source, pos, qualify(WARNING, key), args);
|
||||
return new JCDiagnostic(formatter, WARNING, true, source, pos, qualify(WARNING, key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +108,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
*/
|
||||
public JCDiagnostic warning(
|
||||
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
|
||||
return new JCDiagnostic(messages, WARNING, false, source, pos, qualify(WARNING, key), args);
|
||||
return new JCDiagnostic(formatter, WARNING, false, source, pos, qualify(WARNING, key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,7 +118,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* @see MandatoryWarningHandler
|
||||
*/
|
||||
public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... args) {
|
||||
return new JCDiagnostic(messages, NOTE, true, source, null, qualify(NOTE, key), args);
|
||||
return new JCDiagnostic(formatter, NOTE, true, source, null, qualify(NOTE, key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,7 +139,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
*/
|
||||
public JCDiagnostic note(
|
||||
DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) {
|
||||
return new JCDiagnostic(messages, NOTE, false, source, pos, qualify(NOTE, key), args);
|
||||
return new JCDiagnostic(formatter, NOTE, false, source, pos, qualify(NOTE, key), args);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,7 +148,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* @param args Fields of the error message.
|
||||
*/
|
||||
public JCDiagnostic fragment(String key, Object... args) {
|
||||
return new JCDiagnostic(messages, FRAGMENT, false, null, null, qualify(FRAGMENT, key), args);
|
||||
return new JCDiagnostic(formatter, FRAGMENT, false, null, null, qualify(FRAGMENT, key), args);
|
||||
}
|
||||
|
||||
protected String qualify(DiagnosticType t, String key) {
|
||||
@ -163,10 +162,11 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* Create a fragment diagnostic, for use as an argument in other diagnostics
|
||||
* @param key The key for the localized error message.
|
||||
* @param args Fields of the error message.
|
||||
*
|
||||
*/
|
||||
// should be deprecated
|
||||
@Deprecated
|
||||
public static JCDiagnostic fragment(String key, Object... args) {
|
||||
return new JCDiagnostic(Messages.getDefaultMessages(),
|
||||
return new JCDiagnostic(getFragmentFormatter(),
|
||||
FRAGMENT,
|
||||
false,
|
||||
null,
|
||||
@ -174,6 +174,14 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
"compiler." + FRAGMENT.key + "." + key,
|
||||
args);
|
||||
}
|
||||
//where
|
||||
@Deprecated
|
||||
public static DiagnosticFormatter<JCDiagnostic> getFragmentFormatter() {
|
||||
if (fragmentFormatter == null) {
|
||||
fragmentFormatter = new BasicDiagnosticFormatter(Messages.getDefaultMessages());
|
||||
}
|
||||
return fragmentFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* A DiagnosticType defines the type of the diagnostic.
|
||||
@ -247,7 +255,6 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
private final int pos;
|
||||
}
|
||||
|
||||
private final Messages messages;
|
||||
private final DiagnosticType type;
|
||||
private final DiagnosticSource source;
|
||||
private final DiagnosticPosition position;
|
||||
@ -266,7 +273,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* @param key a resource key to identify the text of the diagnostic
|
||||
* @param args arguments to be included in the text of the diagnostic
|
||||
*/
|
||||
protected JCDiagnostic(Messages messages,
|
||||
protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter,
|
||||
DiagnosticType dt,
|
||||
boolean mandatory,
|
||||
DiagnosticSource source,
|
||||
@ -276,7 +283,7 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
this.messages = messages;
|
||||
this.defaultFormatter = formatter;
|
||||
this.type = dt;
|
||||
this.mandatory = mandatory;
|
||||
this.source = source;
|
||||
@ -398,25 +405,19 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
* @return the prefix string associated with a particular type of diagnostic
|
||||
*/
|
||||
public String getPrefix(DiagnosticType dt) {
|
||||
return getFormatter().formatKind(this, Locale.getDefault());
|
||||
return defaultFormatter.formatKind(this, Locale.getDefault());
|
||||
}
|
||||
|
||||
private DiagnosticFormatter<JCDiagnostic> getFormatter() {
|
||||
if (defaultFormatter == null) {
|
||||
defaultFormatter = new BasicDiagnosticFormatter(messages);
|
||||
}
|
||||
return defaultFormatter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the standard presentation of this diagnostic.
|
||||
*/
|
||||
public String toString() {
|
||||
return getFormatter().format(this,Locale.getDefault());
|
||||
return defaultFormatter.format(this,Locale.getDefault());
|
||||
}
|
||||
|
||||
private static DiagnosticFormatter<JCDiagnostic> defaultFormatter;
|
||||
private DiagnosticFormatter<JCDiagnostic> defaultFormatter;
|
||||
@Deprecated
|
||||
private static DiagnosticFormatter<JCDiagnostic> fragmentFormatter;
|
||||
|
||||
// Methods for javax.tools.Diagnostic
|
||||
|
||||
@ -440,6 +441,6 @@ public class JCDiagnostic implements Diagnostic<JavaFileObject> {
|
||||
|
||||
public String getMessage(Locale locale) {
|
||||
// RFE 6406133: JCDiagnostic.getMessage ignores locale argument
|
||||
return getFormatter().formatMessage(this, locale);
|
||||
return defaultFormatter.formatMessage(this, locale);
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package com.sun.tools.javap;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@ -35,6 +36,7 @@ import com.sun.tools.classfile.ClassFile;
|
||||
import com.sun.tools.classfile.Code_attribute;
|
||||
import com.sun.tools.classfile.ConstantPool;
|
||||
import com.sun.tools.classfile.ConstantPoolException;
|
||||
import com.sun.tools.classfile.ConstantValue_attribute;
|
||||
import com.sun.tools.classfile.Descriptor;
|
||||
import com.sun.tools.classfile.DescriptorException;
|
||||
import com.sun.tools.classfile.Exceptions_attribute;
|
||||
@ -45,6 +47,8 @@ import com.sun.tools.classfile.Signature_attribute;
|
||||
import com.sun.tools.classfile.SourceFile_attribute;
|
||||
import com.sun.tools.classfile.Type;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import static com.sun.tools.classfile.AccessFlags.*;
|
||||
|
||||
/*
|
||||
@ -72,6 +76,23 @@ public class ClassWriter extends BasicWriter {
|
||||
constantWriter = ConstantWriter.instance(context);
|
||||
}
|
||||
|
||||
void setDigest(String name, byte[] digest) {
|
||||
this.digestName = name;
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
void setFile(URI uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
void setFileSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
void setLastModified(long lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
ClassFile getClassFile() {
|
||||
return classFile;
|
||||
}
|
||||
@ -84,6 +105,32 @@ public class ClassWriter extends BasicWriter {
|
||||
classFile = cf;
|
||||
constant_pool = classFile.constant_pool;
|
||||
|
||||
if ((options.sysInfo || options.verbose) && !options.compat) {
|
||||
if (uri != null) {
|
||||
if (uri.getScheme().equals("file"))
|
||||
println("Classfile " + uri.getPath());
|
||||
else
|
||||
println("Classfile " + uri);
|
||||
}
|
||||
if (lastModified != -1) {
|
||||
Date lm = new Date(lastModified);
|
||||
DateFormat df = DateFormat.getDateInstance();
|
||||
if (size > 0) {
|
||||
println("Last modified " + df.format(lm) + "; size " + size + " bytes");
|
||||
} else {
|
||||
println("Last modified " + df.format(lm));
|
||||
}
|
||||
} else if (size > 0) {
|
||||
println("Size " + size + " bytes");
|
||||
}
|
||||
if (digestName != null && digest != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b: digest)
|
||||
sb.append(String.format("%02x", b));
|
||||
println(digestName + " checksum " + sb);
|
||||
}
|
||||
}
|
||||
|
||||
Attribute sfa = cf.getAttribute(Attribute.SourceFile);
|
||||
if (sfa instanceof SourceFile_attribute) {
|
||||
println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\"");
|
||||
@ -185,6 +232,14 @@ public class ClassWriter extends BasicWriter {
|
||||
}
|
||||
print(" ");
|
||||
print(getFieldName(f));
|
||||
if (options.showConstants && !options.compat) { // BUG 4111861 print static final field contents
|
||||
Attribute a = f.attributes.get(Attribute.ConstantValue);
|
||||
if (a instanceof ConstantValue_attribute) {
|
||||
print(" = ");
|
||||
ConstantValue_attribute cv = (ConstantValue_attribute) a;
|
||||
print(getConstantValue(f.descriptor, cv.constantvalue_index));
|
||||
}
|
||||
}
|
||||
print(";");
|
||||
println();
|
||||
|
||||
@ -481,11 +536,91 @@ public class ClassWriter extends BasicWriter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of an entry in the constant pool as a Java constant.
|
||||
* Characters and booleans are represented by CONSTANT_Intgere entries.
|
||||
* Character and string values are processed to escape characters outside
|
||||
* the basic printable ASCII set.
|
||||
* @param d the descriptor, giving the expected type of the constant
|
||||
* @param index the index of the value in the constant pool
|
||||
* @return a printable string containing the value of the constant.
|
||||
*/
|
||||
String getConstantValue(Descriptor d, int index) {
|
||||
try {
|
||||
ConstantPool.CPInfo cpInfo = constant_pool.get(index);
|
||||
|
||||
switch (cpInfo.getTag()) {
|
||||
case ConstantPool.CONSTANT_Integer: {
|
||||
ConstantPool.CONSTANT_Integer_info info =
|
||||
(ConstantPool.CONSTANT_Integer_info) cpInfo;
|
||||
String t = d.getValue(constant_pool);
|
||||
if (t.equals("C")) { // character
|
||||
return getConstantCharValue((char) info.value);
|
||||
} else if (t.equals("Z")) { // boolean
|
||||
return String.valueOf(info.value == 1);
|
||||
} else { // other: assume integer
|
||||
return String.valueOf(info.value);
|
||||
}
|
||||
}
|
||||
|
||||
case ConstantPool.CONSTANT_String: {
|
||||
ConstantPool.CONSTANT_String_info info =
|
||||
(ConstantPool.CONSTANT_String_info) cpInfo;
|
||||
return getConstantStringValue(info.getString());
|
||||
}
|
||||
|
||||
default:
|
||||
return constantWriter.stringValue(cpInfo);
|
||||
}
|
||||
} catch (ConstantPoolException e) {
|
||||
return "#" + index;
|
||||
}
|
||||
}
|
||||
|
||||
private String getConstantCharValue(char c) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('\'');
|
||||
sb.append(esc(c, '\''));
|
||||
sb.append('\'');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getConstantStringValue(String s) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("\"");
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
sb.append(esc(s.charAt(i), '"'));
|
||||
}
|
||||
sb.append("\"");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String esc(char c, char quote) {
|
||||
if (32 <= c && c <= 126 && c != quote)
|
||||
return String.valueOf(c);
|
||||
else switch (c) {
|
||||
case '\b': return "\\b";
|
||||
case '\n': return "\\n";
|
||||
case '\t': return "\\t";
|
||||
case '\f': return "\\f";
|
||||
case '\r': return "\\r";
|
||||
case '\\': return "\\\\";
|
||||
case '\'': return "\\'";
|
||||
case '\"': return "\\\"";
|
||||
default: return String.format("\\u%04x", (int) c);
|
||||
}
|
||||
}
|
||||
|
||||
private Options options;
|
||||
private AttributeWriter attrWriter;
|
||||
private CodeWriter codeWriter;
|
||||
private ConstantWriter constantWriter;
|
||||
private ClassFile classFile;
|
||||
private URI uri;
|
||||
private long lastModified;
|
||||
private String digestName;
|
||||
private byte[] digest;
|
||||
private int size;
|
||||
private ConstantPool constant_pool;
|
||||
private Method method;
|
||||
private static final String NEWLINE = System.getProperty("line.separator", "\n");
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* 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-15301 USA.
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
@ -27,11 +27,15 @@ package com.sun.tools.javap;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -199,6 +203,12 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask {
|
||||
}
|
||||
},
|
||||
|
||||
new Option(false, "-sysinfo") {
|
||||
void process(JavapTask task, String opt, String arg) {
|
||||
task.options.sysInfo = true;
|
||||
}
|
||||
},
|
||||
|
||||
new Option(false, "-Xold") {
|
||||
void process(JavapTask task, String opt, String arg) throws BadArgs {
|
||||
// -Xold is only supported as first arg when invoked from
|
||||
@ -229,6 +239,12 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask {
|
||||
void process(JavapTask task, String opt, String arg) {
|
||||
task.options.ignoreSymbolFile = true;
|
||||
}
|
||||
},
|
||||
|
||||
new Option(false, "-constants") {
|
||||
void process(JavapTask task, String opt, String arg) {
|
||||
task.options.showConstants = true;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@ -488,8 +504,27 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask {
|
||||
Attribute.Factory attributeFactory = new Attribute.Factory();
|
||||
attributeFactory.setCompat(options.compat);
|
||||
attributeFactory.setJSR277(options.jsr277);
|
||||
ClassFile cf = ClassFile.read(fo.openInputStream(), attributeFactory);
|
||||
|
||||
InputStream in = fo.openInputStream();
|
||||
SizeInputStream sizeIn = null;
|
||||
MessageDigest md = null;
|
||||
if (options.sysInfo || options.verbose) {
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
in = new DigestInputStream(in, md);
|
||||
in = sizeIn = new SizeInputStream(in);
|
||||
}
|
||||
|
||||
ClassFile cf = ClassFile.read(in, attributeFactory);
|
||||
|
||||
if (options.sysInfo || options.verbose) {
|
||||
classWriter.setFile(fo.toUri());
|
||||
classWriter.setLastModified(fo.getLastModified());
|
||||
classWriter.setDigest("MD5", md.digest());
|
||||
classWriter.setFileSize(sizeIn.size());
|
||||
}
|
||||
|
||||
classWriter.write(cf);
|
||||
|
||||
} catch (ConstantPoolException e) {
|
||||
diagnosticListener.report(createDiagnostic("err.bad.constant.pool", className, e.getLocalizedMessage()));
|
||||
ok = false;
|
||||
@ -659,4 +694,31 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask {
|
||||
Map<Locale, ResourceBundle> bundles;
|
||||
|
||||
private static final String progname = "javap";
|
||||
|
||||
private static class SizeInputStream extends FilterInputStream {
|
||||
SizeInputStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] buf, int offset, int length) throws IOException {
|
||||
int n = super.read(buf, offset, length);
|
||||
if (n > 0)
|
||||
size += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int b = super.read();
|
||||
size += 1;
|
||||
return b;
|
||||
}
|
||||
|
||||
private int size;
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ public class Options {
|
||||
public boolean showDisassembled;
|
||||
public boolean showInternalSignatures;
|
||||
public boolean showAllAttrs;
|
||||
public boolean showConstants;
|
||||
public boolean sysInfo;
|
||||
|
||||
public boolean compat; // bug-for-bug compatibility mode with old javap
|
||||
public boolean jsr277;
|
||||
|
@ -63,5 +63,10 @@ main.opt.classpath=\
|
||||
main.opt.bootclasspath=\
|
||||
\ -bootclasspath <path> Override location of bootstrap class files
|
||||
|
||||
main.opt.constants=\
|
||||
\ -constants Show static final constants
|
||||
|
||||
|
||||
main.opt.sysinfo=\
|
||||
\ -sysinfo Show system info (path, size, date, MD5 hash)\n\
|
||||
\ of class being processed
|
||||
|
@ -1,13 +1,36 @@
|
||||
/**
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 5045412
|
||||
* @compile/fail/ref=out -XDstdout -XDrawDiagnostics -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java
|
||||
/*
|
||||
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 5045412
|
||||
* @compile/fail/ref=out -XDstdout -XDrawDiagnostics -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java Foo.java
|
||||
* @test
|
||||
* @bug 5045412 6627366
|
||||
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 5045412 6627366
|
||||
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Bar.java Foo.java
|
||||
*/
|
||||
|
||||
class Bar implements java.io.Serializable { }
|
||||
|
@ -23,14 +23,14 @@
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 5045412
|
||||
* @bug 5045412 6627366
|
||||
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 5045412
|
||||
* @compile/fail/ref=out -XDstdout -XDrawDiagnostics -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java Bar.java
|
||||
* @bug 5045412 6627366
|
||||
* @compile -Xlint:serial -XDfailcomplete=java.io.Serializable Foo.java Bar.java
|
||||
*/
|
||||
|
||||
class Foo { }
|
||||
|
@ -1,2 +0,0 @@
|
||||
Bar.java:13:29: compiler.err.cant.resolve.location: kindname.class, Serializable, , , kindname.package, java.io
|
||||
1 error
|
133
langtools/test/tools/javac/6627362/T6627362.java
Normal file
133
langtools/test/tools/javac/6627362/T6627362.java
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6627362
|
||||
* @summary javac generates code that uses array.clone,
|
||||
* which is not available on JavaCard
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
public class T6627362 {
|
||||
static String testSrc = System.getProperty("test.src", ".");
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
new T6627362().run();
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
testStandard();
|
||||
testNoClone();
|
||||
if (errors > 0)
|
||||
throw new Error(errors + " test cases failed");
|
||||
}
|
||||
|
||||
void testStandard() throws Exception {
|
||||
// compile and disassemble E.java, check for reference to Object.clone()
|
||||
File x = new File(testSrc, "x");
|
||||
String[] jcArgs = { "-d", ".",
|
||||
new File(x, "E.java").getPath() };
|
||||
compile(jcArgs);
|
||||
|
||||
String[] jpArgs = { "-classpath", ".", "-c", "E" };
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
javap(new PrintWriter(sw, true), jpArgs);
|
||||
check(sw.toString(), "Method \"[LE;\".clone:()Ljava/lang/Object;");
|
||||
callValues();
|
||||
}
|
||||
|
||||
void testNoClone() throws Exception {
|
||||
// compile and disassemble E.java, using modified Object.java,
|
||||
// check for reference to System.arraycopy
|
||||
File x = new File(testSrc, "x");
|
||||
String[] jcArgs = { "-d", ".",
|
||||
new File(x, "E.java").getPath(),
|
||||
new File(x, "Object.java").getPath()};
|
||||
compile(jcArgs);
|
||||
|
||||
String[] jpArgs = { "-classpath", ".", "-c", "E" };
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
javap(new PrintWriter(sw, true), jpArgs);
|
||||
check(sw.toString(), "//Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V");
|
||||
callValues();
|
||||
}
|
||||
|
||||
void compile(String... args) {
|
||||
int rc = com.sun.tools.javac.Main.compile(args);
|
||||
if (rc != 0)
|
||||
throw new Error("javac failed: " + Arrays.asList(args) + ": " + rc);
|
||||
}
|
||||
|
||||
void javap(PrintWriter out, String... args) throws Exception {
|
||||
// for now, we have to exec javap
|
||||
File javaHome = new File(System.getProperty("java.home"));
|
||||
if (javaHome.getName().equals("jre"))
|
||||
javaHome = javaHome.getParentFile();
|
||||
File javap = new File(new File(javaHome, "bin"), "javap");
|
||||
String[] cmd = new String[args.length + 1];
|
||||
cmd[0] = javap.getPath();
|
||||
System.arraycopy(args, 0, cmd, 1, args.length);
|
||||
Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start();
|
||||
p.getOutputStream().close();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null)
|
||||
out.println(line);
|
||||
int rc = p.waitFor();
|
||||
if (rc != 0)
|
||||
throw new Error("javap failed: " + Arrays.asList(args) + ": " + rc);
|
||||
}
|
||||
|
||||
void check(String s, String require) {
|
||||
if (s.indexOf(require) == -1) {
|
||||
System.err.println("Can't find " + require);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
||||
void callValues() {
|
||||
try {
|
||||
File dot = new File(System.getProperty("user.dir"));
|
||||
ClassLoader cl = new URLClassLoader(new URL[] { dot.toURL() });
|
||||
Class<?> e_class = cl.loadClass("E");
|
||||
Method m = e_class.getMethod("values", new Class[] { });
|
||||
//System.err.println(m);
|
||||
Object o = m.invoke(null, (Object[]) null);
|
||||
List<Object> v = Arrays.asList((Object[]) o);
|
||||
if (!v.toString().equals("[a, b, c]"))
|
||||
throw new Error("unexpected result for E.values(): " + v);
|
||||
} catch (Exception e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
int errors;
|
||||
}
|
||||
|
26
langtools/test/tools/javac/6627362/x/E.java
Normal file
26
langtools/test/tools/javac/6627362/x/E.java
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
public enum E {
|
||||
a, b, c
|
||||
}
|
30
langtools/test/tools/javac/6627362/x/Object.java
Normal file
30
langtools/test/tools/javac/6627362/x/Object.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
/*
|
||||
* Object, without clone()
|
||||
*/
|
||||
public class Object {
|
||||
}
|
41
langtools/test/tools/javac/synthesize/Boolean.java
Normal file
41
langtools/test/tools/javac/synthesize/Boolean.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public class Boolean
|
||||
{
|
||||
public static Boolean valueOf(boolean v) {
|
||||
return new Boolean(v);
|
||||
}
|
||||
|
||||
public Boolean(boolean v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public boolean booleanValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private boolean value;
|
||||
}
|
41
langtools/test/tools/javac/synthesize/Byte.java
Normal file
41
langtools/test/tools/javac/synthesize/Byte.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public class Byte
|
||||
{
|
||||
public static Byte valueOf(byte v) {
|
||||
return new Byte(v);
|
||||
}
|
||||
|
||||
public Byte(byte v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public byte byteValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private byte value;
|
||||
}
|
41
langtools/test/tools/javac/synthesize/Character.java
Normal file
41
langtools/test/tools/javac/synthesize/Character.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public class Character
|
||||
{
|
||||
public static Character valueOf(char v) {
|
||||
return new Character(v);
|
||||
}
|
||||
|
||||
public Character(char v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public char characterValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private char value;
|
||||
}
|
27
langtools/test/tools/javac/synthesize/Cloneable.java
Normal file
27
langtools/test/tools/javac/synthesize/Cloneable.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public interface Cloneable {
|
||||
}
|
18
langtools/test/tools/javac/synthesize/Double.java
Normal file
18
langtools/test/tools/javac/synthesize/Double.java
Normal file
@ -0,0 +1,18 @@
|
||||
package java.lang;
|
||||
|
||||
public class Double extends Number
|
||||
{
|
||||
public static Double valueOf(double v) {
|
||||
return new Double(v);
|
||||
}
|
||||
|
||||
public Double(double v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public double doubleValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private double value;
|
||||
}
|
18
langtools/test/tools/javac/synthesize/Float.java
Normal file
18
langtools/test/tools/javac/synthesize/Float.java
Normal file
@ -0,0 +1,18 @@
|
||||
package java.lang;
|
||||
|
||||
public class Float extends Number
|
||||
{
|
||||
public static Float valueOf(float v) {
|
||||
return new Float(v);
|
||||
}
|
||||
|
||||
public Float(float v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public float floatValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private float value;
|
||||
}
|
41
langtools/test/tools/javac/synthesize/Integer.java
Normal file
41
langtools/test/tools/javac/synthesize/Integer.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public class Integer extends Number
|
||||
{
|
||||
public static Integer valueOf(int v) {
|
||||
return new Integer(v);
|
||||
}
|
||||
|
||||
public Integer(int v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public int integerValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private int value;
|
||||
}
|
41
langtools/test/tools/javac/synthesize/Long.java
Normal file
41
langtools/test/tools/javac/synthesize/Long.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public class Long extends Number
|
||||
{
|
||||
public static Long valueOf(long v) {
|
||||
return new Long(v);
|
||||
}
|
||||
|
||||
public Long(long v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public long longValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private long value;
|
||||
}
|
122
langtools/test/tools/javac/synthesize/Main.java
Normal file
122
langtools/test/tools/javac/synthesize/Main.java
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6627364 6627366
|
||||
* @summary Synthesize important classes if they are missing from the (boot)classpath
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Main
|
||||
{
|
||||
File testSrc = new File(System.getProperty("test.src"));
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new Main().run();
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
|
||||
// compile with standard bootclasspath
|
||||
compile(true, "Test.java");
|
||||
|
||||
// compile with various missing system classes
|
||||
|
||||
List<String> base_files = Arrays.asList(
|
||||
"Boolean.java",
|
||||
"Byte.java",
|
||||
"Character.java",
|
||||
"Integer.java",
|
||||
"Long.java",
|
||||
"Number.java",
|
||||
"Object.java",
|
||||
"Short.java",
|
||||
"Void.java"
|
||||
);
|
||||
|
||||
List<String> extra_files = Arrays.asList(
|
||||
"Double.java",
|
||||
"Float.java",
|
||||
"Cloneable.java",
|
||||
"Serializable.java"
|
||||
);
|
||||
|
||||
List<String> files = new ArrayList<String>();
|
||||
files.addAll(base_files);
|
||||
files.add("Test.java");
|
||||
|
||||
compile(false, files);
|
||||
|
||||
for (String f: extra_files) {
|
||||
files = new ArrayList<String>();
|
||||
files.addAll(base_files);
|
||||
files.addAll(extra_files);
|
||||
files.remove(f);
|
||||
files.add("Test.java");
|
||||
compile(false, files);
|
||||
}
|
||||
|
||||
if (errors > 0)
|
||||
throw new Exception(errors + " errors occurred");
|
||||
}
|
||||
|
||||
void compile(boolean stdBootClassPath, String... files) {
|
||||
compile(stdBootClassPath, Arrays.asList(files));
|
||||
}
|
||||
|
||||
void compile(boolean stdBootClassPath, List<String> files) {
|
||||
File empty = new File("empty");
|
||||
empty.mkdirs();
|
||||
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add("-classpath");
|
||||
args.add("empty");
|
||||
|
||||
if (!stdBootClassPath) {
|
||||
args.add("-bootclasspath");
|
||||
args.add("empty");
|
||||
}
|
||||
args.add("-d");
|
||||
args.add(".");
|
||||
for (String f: files)
|
||||
args.add(new File(testSrc, f).getPath());
|
||||
|
||||
System.out.println("Compile: " + args);
|
||||
StringWriter out = new StringWriter();
|
||||
int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]),
|
||||
new PrintWriter(out));
|
||||
System.out.println(out.toString());
|
||||
System.out.println("result: " + rc);
|
||||
System.out.println();
|
||||
|
||||
if (rc != 0)
|
||||
errors++;
|
||||
}
|
||||
|
||||
private int errors;
|
||||
}
|
||||
|
||||
|
29
langtools/test/tools/javac/synthesize/Number.java
Normal file
29
langtools/test/tools/javac/synthesize/Number.java
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public class Number
|
||||
{
|
||||
|
||||
}
|
28
langtools/test/tools/javac/synthesize/Object.java
Normal file
28
langtools/test/tools/javac/synthesize/Object.java
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public class Object
|
||||
{
|
||||
}
|
27
langtools/test/tools/javac/synthesize/Serializable.java
Normal file
27
langtools/test/tools/javac/synthesize/Serializable.java
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.io;
|
||||
|
||||
public interface Serializable {
|
||||
}
|
41
langtools/test/tools/javac/synthesize/Short.java
Normal file
41
langtools/test/tools/javac/synthesize/Short.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public class Short extends Number
|
||||
{
|
||||
public static Short valueOf(short v) {
|
||||
return new Short(v);
|
||||
}
|
||||
|
||||
public Short(short v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public short shortValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private short value;
|
||||
}
|
32
langtools/test/tools/javac/synthesize/Test.java
Normal file
32
langtools/test/tools/javac/synthesize/Test.java
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
// This code (indirectly) requires the presence of
|
||||
// Cloneable and Serializable (supertypes for Java arrays)
|
||||
// Double and Float (for boxing/unboxing)
|
||||
public class Test
|
||||
{
|
||||
Object f(boolean b, int[] array) {
|
||||
return b ? array : 2;
|
||||
}
|
||||
}
|
29
langtools/test/tools/javac/synthesize/Void.java
Normal file
29
langtools/test/tools/javac/synthesize/Void.java
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package java.lang;
|
||||
|
||||
public class Void
|
||||
{
|
||||
|
||||
}
|
14
langtools/test/tools/javap/4111861/A.java
Normal file
14
langtools/test/tools/javap/4111861/A.java
Normal file
@ -0,0 +1,14 @@
|
||||
class A {
|
||||
public static final int i = 42;
|
||||
public static final boolean b = true;
|
||||
public static final float f = 1.0f;
|
||||
public static final double d = 1.0d;
|
||||
public static final short s = 1;
|
||||
public static final long l = 1l;
|
||||
public static final char cA = 'A';
|
||||
public static final char c0 = '\u0000';
|
||||
public static final char cn = '\n';
|
||||
public static final char cq1 = '\'';
|
||||
public static final char cq2 = '"';
|
||||
public static final java.lang.String t1 = "abc \u0000 \f\n\r\t'\"";
|
||||
}
|
101
langtools/test/tools/javap/4111861/T4111861.java
Normal file
101
langtools/test/tools/javap/4111861/T4111861.java
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4111861
|
||||
* @summary static final field contents are not displayed
|
||||
*/
|
||||
public class T4111861 {
|
||||
public static void main(String... args) throws Exception {
|
||||
new T4111861().run();
|
||||
}
|
||||
|
||||
void run() throws Exception {
|
||||
File testSrc = new File(System.getProperty("test.src", "."));
|
||||
File a_java = new File(testSrc, "A.java");
|
||||
javac("-d", ".", a_java.getPath());
|
||||
|
||||
String out = javap("-classpath", ".", "-constants", "A");
|
||||
|
||||
String a = read(a_java);
|
||||
|
||||
if (!filter(out).equals(filter(read(a_java)))) {
|
||||
System.out.println(out);
|
||||
throw new Exception("unexpected output");
|
||||
}
|
||||
}
|
||||
|
||||
String javac(String... args) throws Exception {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
int rc = com.sun.tools.javac.Main.compile(args, pw);
|
||||
if (rc != 0)
|
||||
throw new Exception("javac failed, rc=" + rc);
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
String javap(String... args) throws Exception {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
int rc = com.sun.tools.javap.Main.run(args, pw);
|
||||
if (rc != 0)
|
||||
throw new Exception("javap failed, rc=" + rc);
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
String read(File f) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
BufferedReader in = new BufferedReader(new FileReader(f));
|
||||
try {
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
sb.append(line);
|
||||
sb.append('\n');
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// return those lines beginning "public static final"
|
||||
String filter(String s) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
BufferedReader in = new BufferedReader(new StringReader(s));
|
||||
try {
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
if (line.indexOf("public static final") > 0) {
|
||||
sb.append(line);
|
||||
sb.append('\n');
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
56
langtools/test/tools/javap/T4884240.java
Normal file
56
langtools/test/tools/javap/T4884240.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Sun designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Sun in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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-15301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4884240
|
||||
* @summary additional option required for javap
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class T4884240 {
|
||||
public static void main(String... args) throws Exception {
|
||||
new T4884240().run();
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
String[] args = { "-sysinfo", "java.lang.Object" };
|
||||
int rc = com.sun.tools.javap.Main.run(args, pw);
|
||||
if (rc != 0)
|
||||
throw new Exception("unexpected return code: " + rc);
|
||||
pw.close();
|
||||
String[] lines = sw.toString().split("\n");
|
||||
if (lines.length < 3
|
||||
|| !lines[0].startsWith("Classfile")
|
||||
|| !lines[1].startsWith("Last modified")
|
||||
|| !lines[2].startsWith("MD5")) {
|
||||
System.out.println(sw);
|
||||
throw new Exception("unexpected output");
|
||||
}
|
||||
}
|
||||
}
|
@ -189,6 +189,10 @@ public class T6622260 {
|
||||
|
||||
void verify(String output) {
|
||||
System.out.println(output);
|
||||
if (output.startsWith("Classfile")) {
|
||||
// make sure to ignore filename
|
||||
output = output.substring(output.indexOf('\n'));
|
||||
}
|
||||
if (output.indexOf("-") >= 0)
|
||||
throw new Error("- found in output");
|
||||
if (output.indexOf("FFFFFF") >= 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user