提交 3ebe5cea 编写于 作者: D dlsmith

6990136: Cleanup use of Type.clone()

Summary: Introduced factory methods in class Types which can be used rather than clone().
Reviewed-by: jjg, mcimadamore
上级 26833070
...@@ -270,10 +270,6 @@ public class Type implements PrimitiveType { ...@@ -270,10 +270,6 @@ public class Type implements PrimitiveType {
public Type getUpperBound() { return null; } public Type getUpperBound() { return null; }
public Type getLowerBound() { return null; } public Type getLowerBound() { return null; }
public void setThrown(List<Type> ts) {
throw new AssertionError();
}
/** Navigation methods, these will work for classes, type variables, /** Navigation methods, these will work for classes, type variables,
* foralls, but will return null for arrays and methods. * foralls, but will return null for arrays and methods.
*/ */
...@@ -388,14 +384,6 @@ public class Type implements PrimitiveType { ...@@ -388,14 +384,6 @@ public class Type implements PrimitiveType {
*/ */
public void complete() {} public void complete() {}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError(e);
}
}
public TypeSymbol asElement() { public TypeSymbol asElement() {
return tsym; return tsym;
} }
...@@ -817,8 +805,7 @@ public class Type implements PrimitiveType { ...@@ -817,8 +805,7 @@ public class Type implements PrimitiveType {
} }
} }
public static class MethodType extends Type public static class MethodType extends Type implements ExecutableType {
implements Cloneable, ExecutableType {
public List<Type> argtypes; public List<Type> argtypes;
public Type restype; public Type restype;
...@@ -880,10 +867,6 @@ public class Type implements PrimitiveType { ...@@ -880,10 +867,6 @@ public class Type implements PrimitiveType {
public Type getReturnType() { return restype; } public Type getReturnType() { return restype; }
public List<Type> getThrownTypes() { return thrown; } public List<Type> getThrownTypes() { return thrown; }
public void setThrown(List<Type> t) {
thrown = t;
}
public boolean isErroneous() { public boolean isErroneous() {
return return
isErroneous(argtypes) || isErroneous(argtypes) ||
...@@ -1068,12 +1051,10 @@ public class Type implements PrimitiveType { ...@@ -1068,12 +1051,10 @@ public class Type implements PrimitiveType {
public List<Type> getThrownTypes() { return qtype.getThrownTypes(); } public List<Type> getThrownTypes() { return qtype.getThrownTypes(); }
public List<Type> allparams() { return qtype.allparams(); } public List<Type> allparams() { return qtype.allparams(); }
public Type getUpperBound() { return qtype.getUpperBound(); } public Type getUpperBound() { return qtype.getUpperBound(); }
public Object clone() { DelegatedType t = (DelegatedType)super.clone(); t.qtype = (Type)qtype.clone(); return t; }
public boolean isErroneous() { return qtype.isErroneous(); } public boolean isErroneous() { return qtype.isErroneous(); }
} }
public static class ForAll extends DelegatedType public static class ForAll extends DelegatedType implements ExecutableType {
implements Cloneable, ExecutableType {
public List<Type> tvars; public List<Type> tvars;
public ForAll(List<Type> tvars, Type qtype) { public ForAll(List<Type> tvars, Type qtype) {
...@@ -1092,16 +1073,6 @@ public class Type implements PrimitiveType { ...@@ -1092,16 +1073,6 @@ public class Type implements PrimitiveType {
public List<Type> getTypeArguments() { return tvars; } public List<Type> getTypeArguments() { return tvars; }
public void setThrown(List<Type> t) {
qtype.setThrown(t);
}
public Object clone() {
ForAll result = (ForAll)super.clone();
result.qtype = (Type)result.qtype.clone();
return result;
}
public boolean isErroneous() { public boolean isErroneous() {
return qtype.isErroneous(); return qtype.isErroneous();
} }
......
...@@ -2407,6 +2407,38 @@ public class Types { ...@@ -2407,6 +2407,38 @@ public class Types {
}; };
// </editor-fold> // </editor-fold>
public Type createMethodTypeWithParameters(Type original, List<Type> newParams) {
return original.accept(methodWithParameters, newParams);
}
// where
private final MapVisitor<List<Type>> methodWithParameters = new MapVisitor<List<Type>>() {
public Type visitType(Type t, List<Type> newParams) {
throw new IllegalArgumentException("Not a method type: " + t);
}
public Type visitMethodType(MethodType t, List<Type> newParams) {
return new MethodType(newParams, t.restype, t.thrown, t.tsym);
}
public Type visitForAll(ForAll t, List<Type> newParams) {
return new ForAll(t.tvars, t.qtype.accept(this, newParams));
}
};
public Type createMethodTypeWithThrown(Type original, List<Type> newThrown) {
return original.accept(methodWithThrown, newThrown);
}
// where
private final MapVisitor<List<Type>> methodWithThrown = new MapVisitor<List<Type>>() {
public Type visitType(Type t, List<Type> newThrown) {
throw new IllegalArgumentException("Not a method type: " + t);
}
public Type visitMethodType(MethodType t, List<Type> newThrown) {
return new MethodType(t.argtypes, t.restype, newThrown, t.tsym);
}
public Type visitForAll(ForAll t, List<Type> newThrown) {
return new ForAll(t.tvars, t.qtype.accept(this, newThrown));
}
};
// <editor-fold defaultstate="collapsed" desc="createErrorType"> // <editor-fold defaultstate="collapsed" desc="createErrorType">
public Type createErrorType(Type originalType) { public Type createErrorType(Type originalType) {
return new ErrorType(originalType, syms.errSymbol); return new ErrorType(originalType, syms.errSymbol);
......
...@@ -673,12 +673,15 @@ public class Flow extends TreeScanner { ...@@ -673,12 +673,15 @@ public class Flow extends TreeScanner {
// in an anonymous class, add the set of thrown exceptions to // in an anonymous class, add the set of thrown exceptions to
// the throws clause of the synthetic constructor and propagate // the throws clause of the synthetic constructor and propagate
// outwards. // outwards.
// Changing the throws clause on the fly is okay here because
// the anonymous constructor can't be invoked anywhere else,
// and its type hasn't been cached.
if (tree.name == names.empty) { if (tree.name == names.empty) {
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
if (TreeInfo.isInitialConstructor(l.head)) { if (TreeInfo.isInitialConstructor(l.head)) {
JCMethodDecl mdef = (JCMethodDecl)l.head; JCMethodDecl mdef = (JCMethodDecl)l.head;
mdef.thrown = make.Types(thrown); mdef.thrown = make.Types(thrown);
mdef.sym.type.setThrown(thrown); mdef.sym.type = types.createMethodTypeWithThrown(mdef.sym.type, thrown);
} }
} }
thrownPrev = chk.union(thrown, thrownPrev); thrownPrev = chk.union(thrown, thrownPrev);
......
...@@ -776,10 +776,12 @@ public class Resolve { ...@@ -776,10 +776,12 @@ public class Resolve {
// due to error recovery or mixing incompatible class files // due to error recovery or mixing incompatible class files
return ambiguityError(m1, m2); return ambiguityError(m1, m2);
} }
List<Type> allThrown = chk.intersect(mt1.getThrownTypes(), mt2.getThrownTypes());
Type newSig = types.createMethodTypeWithThrown(mostSpecific.type, allThrown);
MethodSymbol result = new MethodSymbol( MethodSymbol result = new MethodSymbol(
mostSpecific.flags(), mostSpecific.flags(),
mostSpecific.name, mostSpecific.name,
null, newSig,
mostSpecific.owner) { mostSpecific.owner) {
@Override @Override
public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) { public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
...@@ -789,9 +791,6 @@ public class Resolve { ...@@ -789,9 +791,6 @@ public class Resolve {
return super.implementation(origin, types, checkResult); return super.implementation(origin, types, checkResult);
} }
}; };
result.type = (Type)mostSpecific.type.clone();
result.type.setThrown(chk.intersect(mt1.getThrownTypes(),
mt2.getThrownTypes()));
return result; return result;
} }
if (m1SignatureMoreSpecific) return m1; if (m1SignatureMoreSpecific) return m1;
...@@ -852,13 +851,8 @@ public class Resolve { ...@@ -852,13 +851,8 @@ public class Resolve {
} }
//append varargs element type as last synthetic formal //append varargs element type as last synthetic formal
args.append(types.elemtype(varargsTypeTo)); args.append(types.elemtype(varargsTypeTo));
MethodSymbol msym = new MethodSymbol(to.flags_field, Type mtype = types.createMethodTypeWithParameters(to.type, args.toList());
to.name, return new MethodSymbol(to.flags_field, to.name, mtype, to.owner);
(Type)to.type.clone(), //see: 6990136
to.owner);
MethodType mtype = msym.type.asMethodType();
mtype.argtypes = args.toList();
return msym;
} else { } else {
return to; return to;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册