mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 19:14:38 +02:00
7187104: Inference cleanup: remove redundant exception classes in Infer.java
Remove unused exception classes in Infer.java Reviewed-by: jjg
This commit is contained in:
parent
a39622326e
commit
b1457fe814
1 changed files with 13 additions and 39 deletions
|
@ -75,12 +75,7 @@ public class Infer {
|
||||||
log = Log.instance(context);
|
log = Log.instance(context);
|
||||||
chk = Check.instance(context);
|
chk = Check.instance(context);
|
||||||
diags = JCDiagnostic.Factory.instance(context);
|
diags = JCDiagnostic.Factory.instance(context);
|
||||||
ambiguousNoInstanceException =
|
inferenceException = new InferenceException(diags);
|
||||||
new NoInstanceException(true, diags);
|
|
||||||
unambiguousNoInstanceException =
|
|
||||||
new NoInstanceException(false, diags);
|
|
||||||
invalidInstanceException =
|
|
||||||
new InvalidInstanceException(diags);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,28 +87,7 @@ public class Infer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NoInstanceException extends InferenceException {
|
private final InferenceException inferenceException;
|
||||||
private static final long serialVersionUID = 1;
|
|
||||||
|
|
||||||
boolean isAmbiguous; // exist several incomparable best instances?
|
|
||||||
|
|
||||||
NoInstanceException(boolean isAmbiguous, JCDiagnostic.Factory diags) {
|
|
||||||
super(diags);
|
|
||||||
this.isAmbiguous = isAmbiguous;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class InvalidInstanceException extends InferenceException {
|
|
||||||
private static final long serialVersionUID = 2;
|
|
||||||
|
|
||||||
InvalidInstanceException(JCDiagnostic.Factory diags) {
|
|
||||||
super(diags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final NoInstanceException ambiguousNoInstanceException;
|
|
||||||
private final NoInstanceException unambiguousNoInstanceException;
|
|
||||||
private final InvalidInstanceException invalidInstanceException;
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Auxiliary type values and classes
|
* Auxiliary type values and classes
|
||||||
|
@ -144,7 +118,7 @@ public class Infer {
|
||||||
/** Instantiate undetermined type variable to its minimal upper bound.
|
/** Instantiate undetermined type variable to its minimal upper bound.
|
||||||
* Throw a NoInstanceException if this not possible.
|
* Throw a NoInstanceException if this not possible.
|
||||||
*/
|
*/
|
||||||
void maximizeInst(UndetVar that, Warner warn) throws NoInstanceException {
|
void maximizeInst(UndetVar that, Warner warn) throws InferenceException {
|
||||||
List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
|
List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
|
||||||
if (that.eq.isEmpty()) {
|
if (that.eq.isEmpty()) {
|
||||||
if (hibounds.isEmpty())
|
if (hibounds.isEmpty())
|
||||||
|
@ -158,7 +132,7 @@ public class Infer {
|
||||||
}
|
}
|
||||||
if (that.inst == null ||
|
if (that.inst == null ||
|
||||||
that.inst.isErroneous())
|
that.inst.isErroneous())
|
||||||
throw ambiguousNoInstanceException
|
throw inferenceException
|
||||||
.setMessage("no.unique.maximal.instance.exists",
|
.setMessage("no.unique.maximal.instance.exists",
|
||||||
that.qtype, hibounds);
|
that.qtype, hibounds);
|
||||||
}
|
}
|
||||||
|
@ -173,7 +147,7 @@ public class Infer {
|
||||||
/** Instantiate undetermined type variable to the lub of all its lower bounds.
|
/** Instantiate undetermined type variable to the lub of all its lower bounds.
|
||||||
* Throw a NoInstanceException if this not possible.
|
* Throw a NoInstanceException if this not possible.
|
||||||
*/
|
*/
|
||||||
void minimizeInst(UndetVar that, Warner warn) throws NoInstanceException {
|
void minimizeInst(UndetVar that, Warner warn) throws InferenceException {
|
||||||
List<Type> lobounds = Type.filter(that.lobounds, errorFilter);
|
List<Type> lobounds = Type.filter(that.lobounds, errorFilter);
|
||||||
if (that.eq.isEmpty()) {
|
if (that.eq.isEmpty()) {
|
||||||
if (lobounds.isEmpty())
|
if (lobounds.isEmpty())
|
||||||
|
@ -184,7 +158,7 @@ public class Infer {
|
||||||
that.inst = types.lub(lobounds);
|
that.inst = types.lub(lobounds);
|
||||||
}
|
}
|
||||||
if (that.inst == null || that.inst.tag == ERROR)
|
if (that.inst == null || that.inst.tag == ERROR)
|
||||||
throw ambiguousNoInstanceException
|
throw inferenceException
|
||||||
.setMessage("no.unique.minimal.instance.exists",
|
.setMessage("no.unique.minimal.instance.exists",
|
||||||
that.qtype, lobounds);
|
that.qtype, lobounds);
|
||||||
} else {
|
} else {
|
||||||
|
@ -228,7 +202,7 @@ public class Infer {
|
||||||
Type qtype1 = types.subst(mtype.getReturnType(), tvars, undetvars);
|
Type qtype1 = types.subst(mtype.getReturnType(), tvars, undetvars);
|
||||||
if (!types.isSubtype(qtype1,
|
if (!types.isSubtype(qtype1,
|
||||||
qtype1.tag == UNDETVAR ? types.boxedTypeOrType(to) : to)) {
|
qtype1.tag == UNDETVAR ? types.boxedTypeOrType(to) : to)) {
|
||||||
throw unambiguousNoInstanceException
|
throw inferenceException
|
||||||
.setMessage("infer.no.conforming.instance.exists",
|
.setMessage("infer.no.conforming.instance.exists",
|
||||||
tvars, mtype.getReturnType(), to);
|
tvars, mtype.getReturnType(), to);
|
||||||
}
|
}
|
||||||
|
@ -382,17 +356,17 @@ public class Infer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public InapplicableMethodException arityMismatch() {
|
public InapplicableMethodException arityMismatch() {
|
||||||
return unambiguousNoInstanceException.setMessage("infer.arg.length.mismatch", inferenceVars(undetvars));
|
return inferenceException.setMessage("infer.arg.length.mismatch", inferenceVars(undetvars));
|
||||||
}
|
}
|
||||||
public InapplicableMethodException argumentMismatch(boolean varargs, JCDiagnostic details) {
|
public InapplicableMethodException argumentMismatch(boolean varargs, JCDiagnostic details) {
|
||||||
String key = varargs ?
|
String key = varargs ?
|
||||||
"infer.varargs.argument.mismatch" :
|
"infer.varargs.argument.mismatch" :
|
||||||
"infer.no.conforming.assignment.exists";
|
"infer.no.conforming.assignment.exists";
|
||||||
return unambiguousNoInstanceException.setMessage(key,
|
return inferenceException.setMessage(key,
|
||||||
inferenceVars(undetvars), details);
|
inferenceVars(undetvars), details);
|
||||||
}
|
}
|
||||||
public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) {
|
public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) {
|
||||||
return unambiguousNoInstanceException.setMessage("inaccessible.varargs.type",
|
return inferenceException.setMessage("inaccessible.varargs.type",
|
||||||
expected, Kinds.kindName(location), location);
|
expected, Kinds.kindName(location), location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -405,7 +379,7 @@ public class Infer {
|
||||||
}
|
}
|
||||||
catch (InapplicableMethodException ex) {
|
catch (InapplicableMethodException ex) {
|
||||||
// inferred method is not applicable
|
// inferred method is not applicable
|
||||||
throw invalidInstanceException.setMessage(ex.getDiagnostic());
|
throw inferenceException.setMessage(ex.getDiagnostic());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,7 +389,7 @@ public class Infer {
|
||||||
List<Type> undetvars,
|
List<Type> undetvars,
|
||||||
List<Type> arguments,
|
List<Type> arguments,
|
||||||
Warner warn)
|
Warner warn)
|
||||||
throws InvalidInstanceException {
|
throws InferenceException {
|
||||||
List<Type> args = arguments;
|
List<Type> args = arguments;
|
||||||
for (Type t : undetvars) {
|
for (Type t : undetvars) {
|
||||||
UndetVar uv = (UndetVar)t;
|
UndetVar uv = (UndetVar)t;
|
||||||
|
@ -496,7 +470,7 @@ public class Infer {
|
||||||
}
|
}
|
||||||
//where
|
//where
|
||||||
void reportBoundError(UndetVar uv, BoundErrorKind bk) {
|
void reportBoundError(UndetVar uv, BoundErrorKind bk) {
|
||||||
throw bk.setMessage(uv.inst == null ? ambiguousNoInstanceException : invalidInstanceException, uv);
|
throw bk.setMessage(inferenceException, uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue