Replace and remove JavaException(s).

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org/2326813002 .
This commit is contained in:
Konstantin Shcheglov 2016-09-08 15:56:33 -07:00
parent 6137d020b9
commit e976e692be
28 changed files with 179 additions and 367 deletions

View file

@ -151,18 +151,18 @@ class LocationSpec {
modifiedSource.substring(index + n);
}
if (modifiedSource == originalSource) {
throw new IllegalStateException("No tests in source: " + originalSource);
throw new StateError("No tests in source: " + originalSource);
}
for (String result in validationStrings) {
if (result.length < 3) {
throw new IllegalStateException("Invalid location result: " + result);
throw new StateError("Invalid location result: " + result);
}
String id = result.substring(0, 1);
String sign = result.substring(1, 2);
String value = result.substring(2);
LocationSpec test = tests[id];
if (test == null) {
throw new IllegalStateException(
throw new StateError(
"Invalid location result id: $id for: $result");
}
test.source = modifiedSource;
@ -172,7 +172,7 @@ class LocationSpec {
test.negativeResults.add(value);
} else {
String err = "Invalid location result sign: $sign for: $result";
throw new IllegalStateException(err);
throw new StateError(err);
}
}
List<String> badPoints = <String>[];
@ -200,7 +200,7 @@ class LocationSpec {
err..write(' ')..write(ch);
}
}
throw new IllegalStateException(err.toString());
throw new StateError(err.toString());
}
return tests.values.toList();
}

View file

@ -473,7 +473,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
if (identical(_sourceFactory, factory)) {
return;
} else if (factory.context != null) {
throw new IllegalStateException(
throw new StateError(
"Source factories cannot be shared between contexts");
}
if (_sourceFactory != null) {
@ -2307,7 +2307,7 @@ class SdkAnalysisContext extends AnalysisContextImpl {
}
DartSdk sdk = factory.dartSdk;
if (sdk == null) {
throw new IllegalArgumentException(
throw new ArgumentError(
"The source factory for an SDK analysis context must have a DartUriResolver");
}
return new AnalysisCache(

View file

@ -143,8 +143,7 @@ class SourceFactoryImpl implements SourceFactory {
Source fromEncoding(String encoding) {
Source source = forUri(encoding);
if (source == null) {
throw new IllegalArgumentException(
"Invalid source encoding: '$encoding'");
throw new ArgumentError("Invalid source encoding: '$encoding'");
}
return source;
}

View file

@ -399,7 +399,7 @@ class ArgumentListImpl extends AstNodeImpl implements ArgumentList {
void set correspondingPropagatedParameters(
List<ParameterElement> parameters) {
if (parameters != null && parameters.length != _arguments.length) {
throw new IllegalArgumentException(
throw new ArgumentError(
"Expected ${_arguments.length} parameters, not ${parameters.length}");
}
_correspondingPropagatedParameters = parameters;
@ -411,7 +411,7 @@ class ArgumentListImpl extends AstNodeImpl implements ArgumentList {
@override
void set correspondingStaticParameters(List<ParameterElement> parameters) {
if (parameters != null && parameters.length != _arguments.length) {
throw new IllegalArgumentException(
throw new ArgumentError(
"Expected ${_arguments.length} parameters, not ${parameters.length}");
}
_correspondingStaticParameters = parameters;
@ -5177,7 +5177,7 @@ class FunctionExpressionImpl extends ExpressionImpl
}
// This should never be reached because external functions must be named,
// hence either the body or the name should be non-null.
throw new IllegalStateException("Non-external functions must have a body");
throw new StateError("Non-external functions must have a body");
}
@override
@ -5201,7 +5201,7 @@ class FunctionExpressionImpl extends ExpressionImpl
}
// This should never be reached because external functions must be named,
// hence either the body or the name should be non-null.
throw new IllegalStateException("Non-external functions must have a body");
throw new StateError("Non-external functions must have a body");
}
@override
@ -9297,7 +9297,7 @@ class StringInterpolationImpl extends SingleStringLiteralImpl
@override
void _appendStringValue(StringBuffer buffer) {
throw new IllegalArgumentException();
throw new ArgumentError();
}
}
@ -9410,7 +9410,7 @@ abstract class StringLiteralImpl extends LiteralImpl implements StringLiteral {
StringBuffer buffer = new StringBuffer();
try {
_appendStringValue(buffer);
} on IllegalArgumentException {
} on ArgumentError {
return null;
}
return buffer.toString();
@ -9418,8 +9418,8 @@ abstract class StringLiteralImpl extends LiteralImpl implements StringLiteral {
/**
* Append the value of this string literal to the given [buffer]. Throw an
* [IllegalArgumentException] if the string is not a constant string without
* any string interpolation.
* [ArgumentError] if the string is not a constant string without any
* string interpolation.
*/
void _appendStringValue(StringBuffer buffer);
}

View file

@ -71,8 +71,7 @@ class AstCloner implements AstVisitor<AstNode> {
* Return a list containing cloned versions of the nodes in the given list of
* [nodes].
*/
List<AstNode/*=E*/ > cloneNodeList/*<E extends AstNode>*/(
List/*<E>*/ nodes) {
List<AstNode/*=E*/ > cloneNodeList/*<E extends AstNode>*/(List/*<E>*/ nodes) {
int count = nodes.length;
List/*<E>*/ clonedNodes = new List/*<E>*/();
for (int i = 0; i < count; i++) {
@ -936,6 +935,7 @@ class AstCloner implements AstVisitor<AstNode> {
Token nonComment(Token token) {
return token is CommentToken ? token.parent : token;
}
token = nonComment(token);
if (_lastCloned == null) {
_lastCloned = new Token(TokenType.EOF, -1);
@ -4706,8 +4706,7 @@ class NodeReplacer implements AstVisitor<bool> {
}
bool visitNode(AstNode node) {
throw new IllegalArgumentException(
"The old node is not a child of it's parent");
throw new ArgumentError("The old node is not a child of it's parent");
}
bool visitNormalFormalParameter(NormalFormalParameter node) {
@ -5065,21 +5064,18 @@ class NodeReplacer implements AstVisitor<bool> {
* Replace the [oldNode] with the [newNode] in the AST structure containing
* the old node. Return `true` if the replacement was successful.
*
* Throws an [IllegalArgumentException] if either node is `null`, if the old
* node does not have a parent node, or if the AST structure has been
* corrupted.
* Throws an [ArgumentError] if either node is `null`, if the old node does
* not have a parent node, or if the AST structure has been corrupted.
*/
static bool replace(AstNode oldNode, AstNode newNode) {
if (oldNode == null || newNode == null) {
throw new IllegalArgumentException(
"The old and new nodes must be non-null");
throw new ArgumentError("The old and new nodes must be non-null");
} else if (identical(oldNode, newNode)) {
return true;
}
AstNode parent = oldNode.parent;
if (parent == null) {
throw new IllegalArgumentException(
"The old node is not a child of another node");
throw new ArgumentError("The old node is not a child of another node");
}
NodeReplacer replacer = new NodeReplacer(oldNode, newNode);
return parent.accept(replacer);

View file

@ -13,7 +13,6 @@ import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/generated/error.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
import 'package:analyzer/src/generated/utilities_general.dart';
@ -240,7 +239,7 @@ class DartObjectImpl implements DartObject {
return new DartObjectImpl(typeProvider.stringType, result);
}
// We should never get here.
throw new IllegalStateException("add returned a ${result.runtimeType}");
throw new StateError("add returned a ${result.runtimeType}");
}
/**
@ -339,7 +338,7 @@ class DartObjectImpl implements DartObject {
return new DartObjectImpl(typeProvider.numType, result);
}
// We should never get here.
throw new IllegalStateException("divide returned a ${result.runtimeType}");
throw new StateError("divide returned a ${result.runtimeType}");
}
/**
@ -508,7 +507,7 @@ class DartObjectImpl implements DartObject {
return new DartObjectImpl(typeProvider.numType, result);
}
// We should never get here.
throw new IllegalStateException("minus returned a ${result.runtimeType}");
throw new StateError("minus returned a ${result.runtimeType}");
}
/**
@ -528,7 +527,7 @@ class DartObjectImpl implements DartObject {
return new DartObjectImpl(typeProvider.numType, result);
}
// We should never get here.
throw new IllegalStateException("negated returned a ${result.runtimeType}");
throw new StateError("negated returned a ${result.runtimeType}");
}
/**
@ -589,8 +588,7 @@ class DartObjectImpl implements DartObject {
return new DartObjectImpl(typeProvider.numType, result);
}
// We should never get here.
throw new IllegalStateException(
"remainder returned a ${result.runtimeType}");
throw new StateError("remainder returned a ${result.runtimeType}");
}
/**
@ -647,7 +645,7 @@ class DartObjectImpl implements DartObject {
return new DartObjectImpl(typeProvider.numType, result);
}
// We should never get here.
throw new IllegalStateException("times returned a ${result.runtimeType}");
throw new StateError("times returned a ${result.runtimeType}");
}
@override
@ -1231,9 +1229,9 @@ class DynamicState extends InstanceState {
}
/**
* A run-time exception that would be thrown during the evaluation of Dart code.
* Exception that would be thrown during the evaluation of Dart code.
*/
class EvaluationException extends JavaException {
class EvaluationException {
/**
* The error code associated with the exception.
*/

View file

@ -8414,7 +8414,7 @@ abstract class VariableElementImpl extends ElementImpl
* constant expression to the given [result].
*/
void set evaluationResult(EvaluationResultImpl result) {
throw new IllegalStateException(
throw new StateError(
"Invalid attempt to set a compile-time constant result");
}

View file

@ -149,7 +149,7 @@ abstract class ExecutableMember extends Member implements ExecutableElement {
// Elements within this element should have type parameters substituted,
// just like this element.
//
throw new UnsupportedOperationException();
throw new UnsupportedError('functions');
// return getBaseElement().getFunctions();
}
@ -186,7 +186,7 @@ abstract class ExecutableMember extends Member implements ExecutableElement {
// Elements within this element should have type parameters substituted,
// just like this element.
//
throw new UnsupportedOperationException();
throw new UnsupportedError('localVariables');
// return getBaseElement().getLocalVariables();
}
@ -952,21 +952,21 @@ class TypeParameterMember extends Member implements TypeParameterElement {
@override
Element get enclosingElement => baseElement.enclosingElement;
@override
TypeParameterType get type => _type;
@override
accept(ElementVisitor visitor) => visitor.visitTypeParameterElement(this);
@override
int get hashCode => baseElement.hashCode;
@override
TypeParameterType get type => _type;
@override
bool operator ==(obj) =>
// TODO(jmesserly): this equality should consider the bound, see:
// https://github.com/dart-lang/sdk/issues/27210
obj is TypeParameterMember && obj.baseElement == baseElement;
@override
accept(ElementVisitor visitor) => visitor.visitTypeParameterElement(this);
/**
* If the given [parameter]'s type is different when any type parameters from
* the defining type's declaration are replaced with the actual type
@ -1033,7 +1033,7 @@ abstract class VariableMember extends Member implements VariableElement {
// Elements within this element should have type parameters substituted,
// just like this element.
//
throw new UnsupportedOperationException();
throw new UnsupportedError('initializer');
// return getBaseElement().getInitializer();
}

View file

@ -711,6 +711,7 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
needsComma = true;
}
}
void startOptionalParameters() {
if (needsComma) {
buffer.write(", ");
@ -759,7 +760,7 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
@override
FunctionTypeImpl instantiate(List<DartType> argumentTypes) {
if (argumentTypes.length != typeFormals.length) {
throw new IllegalArgumentException(
throw new ArgumentError(
"argumentTypes.length (${argumentTypes.length}) != "
"typeFormals.length (${typeFormals.length})");
}
@ -838,7 +839,7 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
// substituting once.
assert(this.prunedTypedefs == null);
if (argumentTypes.length != parameterTypes.length) {
throw new IllegalArgumentException(
throw new ArgumentError(
"argumentTypes.length (${argumentTypes.length}) != parameterTypes.length (${parameterTypes.length})");
}
Element element = this.element;
@ -1849,7 +1850,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
List<DartType> argumentTypes, List<DartType> parameterTypes,
[List<FunctionTypeAliasElement> prune]) {
if (argumentTypes.length != parameterTypes.length) {
throw new IllegalArgumentException(
throw new ArgumentError(
"argumentTypes.length (${argumentTypes.length}) != parameterTypes.length (${parameterTypes.length})");
}
if (argumentTypes.length == 0 || typeArguments.length == 0) {
@ -1936,6 +1937,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
visitedClasses.remove(type.element);
}
}
recurse(this);
return result;
}
@ -1959,7 +1961,25 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
List<InterfaceType> s = _intersection(si, sj);
return computeTypeAtMaxUniqueDepth(s);
}
/**
* Return the length of the longest inheritance path from the given [type] to
* Object.
*
* See [computeLeastUpperBound].
*/
static int computeLongestInheritancePathToObject(InterfaceType type) =>
_computeLongestInheritancePathToObject(
type, 0, new HashSet<ClassElement>());
/**
* Returns the set of all superinterfaces of the given [type].
*
* See [computeLeastUpperBound].
*/
static Set<InterfaceType> computeSuperinterfaceSet(InterfaceType type) =>
_computeSuperinterfaceSet(type, new HashSet<InterfaceType>());
/**
* Return the type from the [types] list that has the longest inheritence path
* to Object of unique length.
@ -1995,24 +2015,6 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
return null;
}
/**
* Return the length of the longest inheritance path from the given [type] to
* Object.
*
* See [computeLeastUpperBound].
*/
static int computeLongestInheritancePathToObject(InterfaceType type) =>
_computeLongestInheritancePathToObject(
type, 0, new HashSet<ClassElement>());
/**
* Returns the set of all superinterfaces of the given [type].
*
* See [computeLeastUpperBound].
*/
static Set<InterfaceType> computeSuperinterfaceSet(InterfaceType type) =>
_computeSuperinterfaceSet(type, new HashSet<InterfaceType>());
/**
* If there is a single type which is at least as specific as all of the
* types in [types], return it. Otherwise return `null`.
@ -2187,7 +2189,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
ClassElement firstElement = firstType.element;
ClassElement secondElement = secondType.element;
if (firstElement != secondElement) {
throw new IllegalArgumentException('The same elements expected, but '
throw new ArgumentError('The same elements expected, but '
'$firstElement and $secondElement are given.');
}
if (firstType == secondType) {

View file

@ -25,7 +25,7 @@ class BlockScope extends EnclosedScope {
*/
BlockScope(Scope enclosingScope, Block block) : super(enclosingScope) {
if (block == null) {
throw new IllegalArgumentException("block cannot be null");
throw new ArgumentError("block cannot be null");
}
_defineElements(block);
}
@ -69,7 +69,7 @@ class ClassScope extends EnclosedScope {
ClassScope(Scope enclosingScope, ClassElement classElement)
: super(enclosingScope) {
if (classElement == null) {
throw new IllegalArgumentException("class element cannot be null");
throw new ArgumentError("class element cannot be null");
}
_defineMembers(classElement);
}
@ -173,7 +173,7 @@ class FunctionScope extends EnclosedScope {
FunctionScope(Scope enclosingScope, this._functionElement)
: super(new EnclosedScope(new EnclosedScope(enclosingScope))) {
if (_functionElement == null) {
throw new IllegalArgumentException("function element cannot be null");
throw new ArgumentError("function element cannot be null");
}
_defineTypeParameters();
}
@ -1154,7 +1154,7 @@ class TypeParameterScope extends EnclosedScope {
TypeParameterScope(Scope enclosingScope, ClassElement classElement)
: super(enclosingScope) {
if (classElement == null) {
throw new IllegalArgumentException("class element cannot be null");
throw new ArgumentError("class element cannot be null");
}
_defineTypeParameters(classElement);
}

View file

@ -3202,9 +3202,9 @@ class ErrorReporter {
*/
ErrorReporter(this._errorListener, this._defaultSource) {
if (_errorListener == null) {
throw new IllegalArgumentException("An error listener must be provided");
throw new ArgumentError("An error listener must be provided");
} else if (_defaultSource == null) {
throw new IllegalArgumentException("A default source must be provided");
throw new ArgumentError("A default source must be provided");
}
this._source = _defaultSource;
}

View file

@ -86,8 +86,7 @@ String _printf(String fmt, List args) {
continue;
}
// unknown
throw new IllegalArgumentException(
'[$fmt][$i] = 0x${c.toRadixString(16)}');
throw new ArgumentError('[$fmt][$i] = 0x${c.toRadixString(16)}');
} else {
sb.writeCharCode(c);
}
@ -130,7 +129,7 @@ class Character {
static String toChars(int codePoint) {
if (codePoint < 0 || codePoint > MAX_CODE_POINT) {
throw new IllegalArgumentException();
throw new ArgumentError();
}
if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) {
return new String.fromCharCode(codePoint);
@ -154,15 +153,6 @@ abstract class Enum<E extends Enum> implements Comparable<E> {
String toString() => name;
}
class IllegalArgumentException extends JavaException {
IllegalArgumentException([message = "", cause = null])
: super(message, cause);
}
class IllegalStateException extends JavaException {
IllegalStateException([message = ""]) : super(message);
}
class JavaArrays {
static int makeHashCode(List a) {
// TODO(rnystrom): This is not used by analyzer, but is called by
@ -178,18 +168,6 @@ class JavaArrays {
}
}
class JavaException implements Exception {
final String message;
final Object cause;
JavaException([this.message = "", this.cause = null]);
JavaException.withCause(this.cause) : message = null;
String toString() => "$runtimeType: $message $cause";
}
class JavaIOException extends JavaException {
JavaIOException([message = "", cause = null]) : super(message, cause);
}
class JavaPatternMatcher {
Iterator<Match> _matches;
Match _match;
@ -237,26 +215,6 @@ class JavaSystem {
}
}
class MissingFormatArgumentException implements Exception {
final String s;
MissingFormatArgumentException(this.s);
String toString() => "MissingFormatArgumentException: $s";
}
class NoSuchElementException extends JavaException {
String toString() => "NoSuchElementException";
}
class NotImplementedException extends JavaException {
NotImplementedException(message) : super(message);
}
class NumberFormatException extends JavaException {
String toString() => "NumberFormatException";
}
class PrintStringWriter extends PrintWriter {
final StringBuffer _sb = new StringBuffer();
@ -284,19 +242,6 @@ abstract class PrintWriter {
}
}
class RuntimeException extends JavaException {
RuntimeException({String message: "", Exception cause: null})
: super(message, cause);
}
class StringIndexOutOfBoundsException extends JavaException {
StringIndexOutOfBoundsException(int index) : super('$index');
}
class UnsupportedOperationException extends JavaException {
UnsupportedOperationException([message = ""]) : super(message);
}
class URISyntaxException implements Exception {
final String message;
URISyntaxException(this.message);

View file

@ -275,12 +275,11 @@ class StringUtilities {
*/
static String printListOfQuotedNames(List<String> names) {
if (names == null) {
throw new IllegalArgumentException("The list must not be null");
throw new ArgumentError("The list must not be null");
}
int count = names.length;
if (count < 2) {
throw new IllegalArgumentException(
"The list must contain at least two names");
throw new ArgumentError("The list must contain at least two names");
}
StringBuffer buffer = new StringBuffer();
buffer.write("'");

View file

@ -6,7 +6,6 @@ library analyzer.src.generated.java_io;
import "dart:io";
import 'package:analyzer/src/generated/java_core.dart' show JavaIOException;
import 'package:path/path.dart' as path;
class JavaFile {
@ -51,11 +50,7 @@ class JavaFile {
JavaFile getCanonicalFile() => new JavaFile(getCanonicalPath());
String getCanonicalPath() {
try {
return _newFile().resolveSymbolicLinksSync();
} catch (e) {
throw new JavaIOException('IOException', e);
}
return _newFile().resolveSymbolicLinksSync();
}
String getName() => pathContext.basename(_path);

View file

@ -483,7 +483,7 @@ Object invokeParserMethodImpl(
MethodTrampoline method =
methodTable_Parser['${methodName}_${objects.length}'];
if (method == null) {
throw new IllegalArgumentException('There is no method named $methodName');
throw new ArgumentError('There is no method named $methodName');
}
return method.invoke(parser, objects);
}
@ -1670,7 +1670,7 @@ class IncrementalParseDispatcher implements AstVisitor<AstNode> {
* the node to be replaced.
*/
AstNode _notAChild(AstNode node) {
throw new IncrementalParseException.con1(
throw new IncrementalParseException(
"Internal error: the visited node (a ${node.runtimeType}) was not the parent of the node to be replaced (a ${_oldNode.runtimeType})");
}
}
@ -1680,24 +1680,10 @@ class IncrementalParseDispatcher implements AstVisitor<AstNode> {
* specified node in an existing AST structure.
*/
@deprecated
class IncrementalParseException extends RuntimeException {
/**
* Initialize a newly created exception to have no message and to be its own
* cause.
*/
IncrementalParseException() : super();
/**
* Initialize a newly created exception to have the given [message] and to be
* its own cause.
*/
IncrementalParseException.con1(String message) : super(message: message);
/**
* Initialize a newly created exception to have no message and to have the
* given [cause].
*/
IncrementalParseException.con2(Exception cause) : super(cause: cause);
class IncrementalParseException {
final String message;
IncrementalParseException([this.message = '']);
String toString() => '$runtimeType: $message';
}
/**
@ -1970,23 +1956,7 @@ class IncrementalParseStateBuilder extends SimpleAstVisitor {
*/
@deprecated
class InsufficientContextException extends IncrementalParseException {
/**
* Initialize a newly created exception to have no message and to be its own
* cause.
*/
InsufficientContextException() : super();
/**
* Initialize a newly created exception to have the given [message] and to be
* its own cause.
*/
InsufficientContextException.con1(String message) : super.con1(message);
/**
* Initialize a newly created exception to have no message and to have the
* given [cause].
*/
InsufficientContextException.con2(Exception cause) : super.con2(cause);
InsufficientContextException([String message = '']) : super(message);
}
/**
@ -1999,8 +1969,7 @@ class MethodTrampoline {
MethodTrampoline(this.parameterCount, this.trampoline);
Object invoke(target, List arguments) {
if (arguments.length != parameterCount) {
throw new IllegalArgumentException(
"${arguments.length} != $parameterCount");
throw new ArgumentError("${arguments.length} != $parameterCount");
}
switch (parameterCount) {
case 0:
@ -2015,7 +1984,7 @@ class MethodTrampoline {
return trampoline(
target, arguments[0], arguments[1], arguments[2], arguments[3]);
default:
throw new IllegalArgumentException("Not implemented for > 4 arguments");
throw new ArgumentError("Not implemented for > 4 arguments");
}
}
}
@ -2878,7 +2847,7 @@ class Parser {
} else {
// Internal error: this method should not have been invoked if the
// current token was something other than one of the above.
throw new IllegalStateException(
throw new StateError(
"parseDirective invoked in an invalid state (currentToken = $_currentToken)");
}
}
@ -5730,7 +5699,7 @@ class Parser {
} else {
// Internal error: this method should not have been invoked if the current
// token was something other than one of the above.
throw new IllegalStateException(
throw new StateError(
"parseDirective invoked in an invalid state; currentToken = $_currentToken");
}
}
@ -9599,8 +9568,7 @@ class Parser {
*/
void _unlockErrorListener() {
if (_errorListenerLock == 0) {
throw new IllegalStateException(
"Attempt to unlock not locked error listener.");
throw new StateError("Attempt to unlock not locked error listener.");
}
_errorListenerLock--;
}

View file

@ -533,8 +533,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
* [identifier] is not a name of a getter or a method that exists in the
* class [Null].
*/
void _checkForCanBeNullAfterNullAware(
Expression target, Token operator, SimpleIdentifier propertyName, SimpleIdentifier methodName) {
void _checkForCanBeNullAfterNullAware(Expression target, Token operator,
SimpleIdentifier propertyName, SimpleIdentifier methodName) {
if (operator?.type == TokenType.QUESTION_PERIOD) {
return;
}
@ -9097,7 +9097,7 @@ class TypeOverrideManager {
*/
void applyOverrides(Map<VariableElement, DartType> overrides) {
if (currentScope == null) {
throw new IllegalStateException("Cannot apply overrides without a scope");
throw new StateError("Cannot apply overrides without a scope");
}
currentScope.applyOverrides(overrides);
}
@ -9110,8 +9110,7 @@ class TypeOverrideManager {
*/
Map<VariableElement, DartType> captureLocalOverrides() {
if (currentScope == null) {
throw new IllegalStateException(
"Cannot capture local overrides without a scope");
throw new StateError("Cannot capture local overrides without a scope");
}
return currentScope.captureLocalOverrides();
}
@ -9126,8 +9125,7 @@ class TypeOverrideManager {
Map<VariableElement, DartType> captureOverrides(
VariableDeclarationList variableList) {
if (currentScope == null) {
throw new IllegalStateException(
"Cannot capture overrides without a scope");
throw new StateError("Cannot capture overrides without a scope");
}
return currentScope.captureOverrides(variableList);
}
@ -9144,7 +9142,7 @@ class TypeOverrideManager {
*/
void exitScope() {
if (currentScope == null) {
throw new IllegalStateException("No scope to exit");
throw new StateError("No scope to exit");
}
currentScope = currentScope._outerScope;
}
@ -9203,7 +9201,7 @@ class TypeOverrideManager {
*/
void setType(VariableElement element, DartType type) {
if (currentScope == null) {
throw new IllegalStateException("Cannot override without a scope");
throw new StateError("Cannot override without a scope");
}
currentScope.setType(element, type);
}
@ -9405,7 +9403,7 @@ class TypePromotionManager {
*/
void exitScope() {
if (currentScope == null) {
throw new IllegalStateException("No scope to exit");
throw new StateError("No scope to exit");
}
currentScope = currentScope._outerScope;
}
@ -9430,7 +9428,7 @@ class TypePromotionManager {
*/
void setType(Element element, DartType type) {
if (currentScope == null) {
throw new IllegalStateException("Cannot promote without a scope");
throw new StateError("Cannot promote without a scope");
}
currentScope.setType(element, type);
}

View file

@ -212,9 +212,9 @@ class LineInfo {
*/
LineInfo._(this.lineStarts) {
if (lineStarts == null) {
throw new IllegalArgumentException("lineStarts must be non-null");
throw new ArgumentError("lineStarts must be non-null");
} else if (lineStarts.length < 1) {
throw new IllegalArgumentException("lineStarts must be non-empty");
throw new ArgumentError("lineStarts must be non-empty");
}
}
@ -379,7 +379,7 @@ class NonExistingSource extends Source {
@override
TimestampedData<String> get contents {
throw new UnsupportedOperationException('$fullName does not exist.');
throw new UnsupportedError('$fullName does not exist.');
}
@override

View file

@ -376,7 +376,7 @@ class PackageUriResolver extends UriResolver {
*/
PackageUriResolver(this._packagesDirectories) {
if (_packagesDirectories.length < 1) {
throw new IllegalArgumentException(
throw new ArgumentError(
"At least one package directory must be provided");
}
}
@ -407,7 +407,7 @@ class PackageUriResolver extends UriResolver {
JavaFile pkgDir = new JavaFile.relative(packagesDirectory, pkgName);
try {
pkgDir = pkgDir.getCanonicalFile();
} on JavaIOException catch (exception, stackTrace) {
} catch (exception, stackTrace) {
if (!exception.toString().contains("Required key not available")) {
AnalysisEngine.instance.logger.logError("Canonical failed: $pkgDir",
new CaughtException(exception, stackTrace));

View file

@ -287,7 +287,7 @@ class ElementFactory {
int nameCount = names == null ? 0 : names.length;
int typeCount = namedParameters == null ? 0 : namedParameters.length;
if (names != null && nameCount != typeCount) {
throw new IllegalStateException(
throw new StateError(
"The passed String[] and ClassElement[] arrays had different lengths.");
}
int totalCount = normalCount + nameCount;

View file

@ -203,7 +203,7 @@ class DirectedGraph<N> {
*/
List<N> findCycleContaining(N node) {
if (node == null) {
throw new IllegalArgumentException();
throw new ArgumentError();
}
DirectedGraph_SccFinder<N> finder = new DirectedGraph_SccFinder<N>(this);
return finder.componentContaining(node);
@ -570,7 +570,7 @@ class MultipleMapIterator<K, V> implements MapIterator<K, V> {
@override
K get key {
if (_currentIterator == null) {
throw new NoSuchElementException();
throw new StateError('No element');
}
return _currentIterator.key;
}
@ -578,7 +578,7 @@ class MultipleMapIterator<K, V> implements MapIterator<K, V> {
@override
V get value {
if (_currentIterator == null) {
throw new NoSuchElementException();
throw new StateError('No element');
}
return _currentIterator.value;
}
@ -586,7 +586,7 @@ class MultipleMapIterator<K, V> implements MapIterator<K, V> {
@override
void set value(V newValue) {
if (_currentIterator == null) {
throw new NoSuchElementException();
throw new StateError('No element');
}
_currentIterator.value = newValue;
}
@ -672,7 +672,7 @@ class SingleMapIterator<K, V> implements MapIterator<K, V> {
@override
K get key {
if (_currentKey == null) {
throw new NoSuchElementException();
throw new StateError('No element');
}
return _currentKey;
}
@ -680,7 +680,7 @@ class SingleMapIterator<K, V> implements MapIterator<K, V> {
@override
V get value {
if (_currentKey == null) {
throw new NoSuchElementException();
throw new StateError('No element');
}
if (_currentValue == null) {
_currentValue = _map[_currentKey];
@ -691,7 +691,7 @@ class SingleMapIterator<K, V> implements MapIterator<K, V> {
@override
void set value(V newValue) {
if (_currentKey == null) {
throw new NoSuchElementException();
throw new StateError('No element');
}
_currentValue = newValue;
_map[_currentKey] = newValue;

View file

@ -12,8 +12,6 @@ import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/generated/element_resolver.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/resolver.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/testing/ast_factory.dart';
@ -884,12 +882,7 @@ class ElementResolverTest extends EngineTestCase {
_visitor = new ResolverVisitor(
_definingLibrary, source, _typeProvider, _listener,
nameScope: new LibraryScope(_definingLibrary));
try {
return _visitor.elementResolver;
} catch (exception) {
throw new IllegalArgumentException(
"Could not create resolver", exception);
}
return _visitor.elementResolver;
}
/**
@ -943,21 +936,16 @@ class ElementResolverTest extends EngineTestCase {
* @return the element to which the expression was resolved
*/
void _resolveInClass(AstNode node, ClassElement enclosingClass) {
Scope outerScope = _visitor.nameScope;
try {
Scope outerScope = _visitor.nameScope;
try {
_visitor.enclosingClass = enclosingClass;
EnclosedScope innerScope = new ClassScope(
new TypeParameterScope(outerScope, enclosingClass), enclosingClass);
_visitor.nameScope = innerScope;
node.accept(_resolver);
} finally {
_visitor.enclosingClass = null;
_visitor.nameScope = outerScope;
}
} catch (exception, stackTrace) {
throw new IllegalArgumentException(
"Could not resolve node", new CaughtException(exception, stackTrace));
_visitor.enclosingClass = enclosingClass;
EnclosedScope innerScope = new ClassScope(
new TypeParameterScope(outerScope, enclosingClass), enclosingClass);
_visitor.nameScope = innerScope;
node.accept(_resolver);
} finally {
_visitor.enclosingClass = null;
_visitor.nameScope = outerScope;
}
}
@ -986,22 +974,18 @@ class ElementResolverTest extends EngineTestCase {
* @return the element to which the expression was resolved
*/
void _resolveNode(AstNode node, [List<Element> definedElements]) {
Scope outerScope = _visitor.nameScope;
try {
Scope outerScope = _visitor.nameScope;
try {
EnclosedScope innerScope = new EnclosedScope(outerScope);
if (definedElements != null) {
for (Element element in definedElements) {
innerScope.define(element);
}
EnclosedScope innerScope = new EnclosedScope(outerScope);
if (definedElements != null) {
for (Element element in definedElements) {
innerScope.define(element);
}
_visitor.nameScope = innerScope;
node.accept(_resolver);
} finally {
_visitor.nameScope = outerScope;
}
} catch (exception) {
throw new IllegalArgumentException("Could not resolve node", exception);
_visitor.nameScope = innerScope;
node.accept(_resolver);
} finally {
_visitor.nameScope = outerScope;
}
}
@ -1015,23 +999,19 @@ class ElementResolverTest extends EngineTestCase {
*/
void _resolveStatement(
Statement statement, LabelElementImpl labelElement, AstNode labelTarget) {
LabelScope outerScope = _visitor.labelScope;
try {
LabelScope outerScope = _visitor.labelScope;
try {
LabelScope innerScope;
if (labelElement == null) {
innerScope = outerScope;
} else {
innerScope = new LabelScope(
outerScope, labelElement.name, labelTarget, labelElement);
}
_visitor.labelScope = innerScope;
statement.accept(_resolver);
} finally {
_visitor.labelScope = outerScope;
LabelScope innerScope;
if (labelElement == null) {
innerScope = outerScope;
} else {
innerScope = new LabelScope(
outerScope, labelElement.name, labelTarget, labelElement);
}
} catch (exception) {
throw new IllegalArgumentException("Could not resolve node", exception);
_visitor.labelScope = innerScope;
statement.accept(_resolver);
} finally {
_visitor.labelScope = outerScope;
}
}
}

View file

@ -81,7 +81,7 @@ class CompilationUnitMock extends TypedMock implements CompilationUnit {}
class MockSourceFactory extends SourceFactoryImpl {
MockSourceFactory() : super([]);
Source resolveUri(Source containingSource, String containedUri) {
throw new JavaIOException();
throw new UnimplementedError();
}
}

View file

@ -985,24 +985,18 @@ class SubtypeManagerTest {
class TypeOverrideManagerTest extends EngineTestCase {
void test_exitScope_noScopes() {
TypeOverrideManager manager = new TypeOverrideManager();
try {
expect(() {
manager.exitScope();
fail("Expected IllegalStateException");
} on IllegalStateException {
// Expected
}
}, throwsStateError);
}
void test_exitScope_oneScope() {
TypeOverrideManager manager = new TypeOverrideManager();
manager.enterScope();
manager.exitScope();
try {
expect(() {
manager.exitScope();
fail("Expected IllegalStateException");
} on IllegalStateException {
// Expected
}
}, throwsStateError);
}
void test_exitScope_twoScopes() {
@ -1011,12 +1005,9 @@ class TypeOverrideManagerTest extends EngineTestCase {
manager.exitScope();
manager.enterScope();
manager.exitScope();
try {
expect(() {
manager.exitScope();
fail("Expected IllegalStateException");
} on IllegalStateException {
// Expected
}
}, throwsStateError);
}
void test_getType_enclosedOverride() {

View file

@ -590,7 +590,7 @@ class ResolverTestCase extends EngineTestCase {
// "fail_*" tests. However, an assertion failure is success for the
// purpose of "fail_*" tests, so without catching them here "fail_*" tests
// can succeed by failing for the wrong reason.
throw new JavaException("Unexexpected assertion failure: $exception");
throw new StateError("Unexpected assertion failure: $exception");
}
}

View file

@ -239,14 +239,13 @@ class SourceFactoryTest {
void test_fromEncoding_invalidUri() {
SourceFactory factory = new SourceFactory([]);
expect(() => factory.fromEncoding("<:&%>"),
throwsA(new isInstanceOf<IllegalArgumentException>()));
expect(() => factory.fromEncoding("<:&%>"), throwsArgumentError);
}
void test_fromEncoding_noResolver() {
SourceFactory factory = new SourceFactory([]);
expect(() => factory.fromEncoding("foo:/does/not/exist.dart"),
throwsA(new isInstanceOf<IllegalArgumentException>()));
throwsArgumentError);
}
void test_fromEncoding_valid() {

View file

@ -15,7 +15,6 @@ import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/member.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/resolver.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/static_type_analyzer.dart';
@ -1427,12 +1426,7 @@ class StaticTypeAnalyzerTest extends EngineTestCase {
*/
DartType _analyze4(
Expression node, InterfaceType thisType, bool useStaticType) {
try {
_analyzer.thisType = thisType;
} catch (exception) {
throw new IllegalArgumentException(
"Could not set type of 'this'", exception);
}
_analyzer.thisType = thisType;
node.accept(_analyzer);
if (useStaticType) {
return node.staticType;
@ -1554,12 +1548,7 @@ class StaticTypeAnalyzerTest extends EngineTestCase {
definingLibrary, source, _typeProvider, _listener,
nameScope: new LibraryScope(definingLibrary));
_visitor.overrideManager.enterScope();
try {
return _visitor.typeAnalyzer;
} catch (exception) {
throw new IllegalArgumentException(
"Could not create analyzer", exception);
}
return _visitor.typeAnalyzer;
}
DartType _flatten(DartType type) => type.flattenFutures(_typeSystem);

View file

@ -12,7 +12,6 @@ import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/error.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:plugin/manager.dart';
@ -129,7 +128,7 @@ class EngineTestCase {
AstNode root, String code, String prefix, Predicate<AstNode> predicate) {
int offset = code.indexOf(prefix);
if (offset == -1) {
throw new IllegalArgumentException("Not found '$prefix'.");
throw new ArgumentError("Not found '$prefix'.");
}
AstNode node = new NodeLocator(offset).searchWithin(root);
return node.getAncestor(predicate);
@ -142,7 +141,7 @@ class EngineTestCase {
AstNode root, String code, String prefix) {
int offset = code.indexOf(prefix);
if (offset == -1) {
throw new IllegalArgumentException("Not found '$prefix'.");
throw new ArgumentError("Not found '$prefix'.");
}
return new NodeLocator(offset).searchWithin(root);
}
@ -589,7 +588,7 @@ class TestSource extends Source {
Uri get uri => new Uri.file(_name);
UriKind get uriKind {
throw new UnsupportedOperationException();
throw new UnsupportedError('uriKind');
}
bool operator ==(Object other) {
@ -601,11 +600,11 @@ class TestSource extends Source {
bool exists() => exists2;
void getContentsToReceiver(Source_ContentReceiver receiver) {
throw new UnsupportedOperationException();
throw new UnsupportedError('getContentsToReceiver');
}
Source resolve(String uri) {
throw new UnsupportedOperationException();
throw new UnsupportedError('resolve');
}
void setContents(String value) {

View file

@ -1455,12 +1455,7 @@ class DirectedGraphTest extends EngineTestCase {
void test_findCycleContaining_null() {
DirectedGraph<DirectedGraphTest_Node> graph =
new DirectedGraph<DirectedGraphTest_Node>();
try {
graph.findCycleContaining(null);
fail("Expected IllegalArgumentException");
} on IllegalArgumentException {
// Expected
}
expect(() => graph.findCycleContaining(null), throwsArgumentError);
}
void test_findCycleContaining_singleton() {
@ -2524,21 +2519,15 @@ class LineInfoTest {
}
void test_creation_empty() {
try {
expect(() {
new LineInfo(<int>[]);
fail("Expected IllegalArgumentException");
} on IllegalArgumentException {
// Expected
}
}, throwsArgumentError);
}
void test_creation_null() {
try {
expect(() {
new LineInfo(null);
fail("Expected IllegalArgumentException");
} on IllegalArgumentException {
// Expected
}
}, throwsArgumentError);
}
void test_firstLine() {
@ -2899,24 +2888,11 @@ class MultipleMapIteratorTest extends EngineTestCase {
Map<String, String> map = new HashMap<String, String>();
MultipleMapIterator<String, String> iterator = _iterator(<Map>[map]);
expect(iterator.moveNext(), isFalse);
try {
iterator.key;
fail("Expected NoSuchElementException");
} on NoSuchElementException {
// Expected
}
try {
iterator.value;
fail("Expected NoSuchElementException");
} on NoSuchElementException {
// Expected
}
try {
iterator.value = "x";
fail("Expected NoSuchElementException");
} on NoSuchElementException {
// Expected
}
expect(() => iterator.key, throwsStateError);
expect(() => iterator.value, throwsStateError);
expect(() {
iterator.value = 'x';
}, throwsStateError);
}
void test_singleMap_multiple() {
@ -3904,24 +3880,11 @@ class SingleMapIteratorTest extends EngineTestCase {
SingleMapIterator<String, String> iterator =
new SingleMapIterator<String, String>(map);
expect(iterator.moveNext(), isFalse);
try {
iterator.key;
fail("Expected NoSuchElementException");
} on NoSuchElementException {
// Expected
}
try {
iterator.value;
fail("Expected NoSuchElementException");
} on NoSuchElementException {
// Expected
}
try {
iterator.value = "x";
fail("Expected NoSuchElementException");
} on NoSuchElementException {
// Expected
}
expect(() => iterator.key, throwsStateError);
expect(() => iterator.value, throwsStateError);
expect(() {
iterator.value = 'x';
}, throwsStateError);
expect(iterator.moveNext(), isFalse);
}
@ -4214,12 +4177,9 @@ class StringUtilitiesTest {
}
void test_printListOfQuotedNames_empty() {
try {
expect(() {
StringUtilities.printListOfQuotedNames(new List<String>(0));
fail("Expected IllegalArgumentException");
} on IllegalArgumentException {
// Expected
}
}, throwsArgumentError);
}
void test_printListOfQuotedNames_five() {
@ -4230,21 +4190,15 @@ class StringUtilitiesTest {
}
void test_printListOfQuotedNames_null() {
try {
expect(() {
StringUtilities.printListOfQuotedNames(null);
fail("Expected IllegalArgumentException");
} on IllegalArgumentException {
// Expected
}
}, throwsArgumentError);
}
void test_printListOfQuotedNames_one() {
try {
expect(() {
StringUtilities.printListOfQuotedNames(<String>["a"]);
fail("Expected IllegalArgumentException");
} on IllegalArgumentException {
// Expected
}
}, throwsArgumentError);
}
void test_printListOfQuotedNames_three() {