Move DeclaredVariables to a better location

Change-Id: I17190a8e888cc37cded141cbaf028691db061e49
Reviewed-on: https://dart-review.googlesource.com/50540
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2018-04-10 19:25:11 +00:00 committed by commit-bot@chromium.org
parent 3851591642
commit 8054721512
14 changed files with 119 additions and 113 deletions

View file

@ -2,105 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@deprecated
library analyzer.context.declared_variables;
import 'dart:collection';
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/src/dart/constant/value.dart';
import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
/**
* An object used to provide access to the values of variables that have been
* defined on the command line using the `-D` option.
*
* Clients may not extend, implement or mix-in this class.
*/
class DeclaredVariables {
/**
* A table mapping the names of declared variables to their values.
*/
Map<String, String> _declaredVariables = new HashMap<String, String>();
/**
* Return the names of the variables for which a value has been defined.
*/
Iterable<String> get variableNames => _declaredVariables.keys;
/**
* Add all variables of [other] to this object.
*/
void addAll(DeclaredVariables other) {
_declaredVariables.addAll(other._declaredVariables);
}
/**
* Define a variable with the given [name] to have the given [value].
*/
void define(String name, String value) {
_declaredVariables[name] = value;
}
/**
* Return the raw string value of the variable with the given [name],
* or `null` of the variable is not defined.
*/
String get(String name) => _declaredVariables[name];
/**
* Return the value of the variable with the given [name] interpreted as a
* 'boolean' value. If the variable is not defined (or [name] is `null`), a
* DartObject representing "unknown" is returned. If the value cannot be
* parsed as a boolean, a DartObject representing 'null' is returned. The
* [typeProvider] is the type provider used to find the type 'bool'.
*/
DartObject getBool(TypeProvider typeProvider, String name) {
String value = _declaredVariables[name];
if (value == null) {
return new DartObjectImpl(typeProvider.boolType, BoolState.UNKNOWN_VALUE);
}
if (value == "true") {
return new DartObjectImpl(typeProvider.boolType, BoolState.TRUE_STATE);
} else if (value == "false") {
return new DartObjectImpl(typeProvider.boolType, BoolState.FALSE_STATE);
}
return new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE);
}
/**
* Return the value of the variable with the given [name] interpreted as an
* integer value. If the variable is not defined (or [name] is `null`), a
* DartObject representing "unknown" is returned. If the value cannot be
* parsed as an integer, a DartObject representing 'null' is returned.
*/
DartObject getInt(TypeProvider typeProvider, String name) {
String value = _declaredVariables[name];
if (value == null) {
return new DartObjectImpl(typeProvider.intType, IntState.UNKNOWN_VALUE);
}
int bigInteger;
try {
bigInteger = int.parse(value);
} on FormatException {
return new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE);
}
return new DartObjectImpl(typeProvider.intType, new IntState(bigInteger));
}
/**
* Return the value of the variable with the given [name] interpreted as a
* String value, or `null` if the variable is not defined. Return the value of
* the variable with the given name interpreted as a String value. If the
* variable is not defined (or [name] is `null`), a DartObject representing
* "unknown" is returned. The [typeProvider] is the type provider used to find
* the type 'String'.
*/
DartObject getString(TypeProvider typeProvider, String name) {
String value = _declaredVariables[name];
if (value == null) {
return new DartObjectImpl(
typeProvider.stringType, StringState.UNKNOWN_VALUE);
}
return new DartObjectImpl(typeProvider.stringType, new StringState(value));
}
}
export 'package:analyzer/dart/analysis/declared_variables.dart';

View file

@ -2,9 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/analysis_context.dart';
import 'package:analyzer/dart/analysis/context_root.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/context_builder.dart';
import 'package:meta/meta.dart';

View file

@ -0,0 +1,104 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:collection';
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/src/dart/constant/value.dart';
import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
/**
* An object used to provide access to the values of variables that have been
* defined on the command line using the `-D` option.
*
* Clients may not extend, implement or mix-in this class.
*/
class DeclaredVariables {
/**
* A table mapping the names of declared variables to their values.
*/
Map<String, String> _declaredVariables = new HashMap<String, String>();
/**
* Return the names of the variables for which a value has been defined.
*/
Iterable<String> get variableNames => _declaredVariables.keys;
/**
* Add all variables of [other] to this object.
*/
void addAll(DeclaredVariables other) {
_declaredVariables.addAll(other._declaredVariables);
}
/**
* Define a variable with the given [name] to have the given [value].
*/
void define(String name, String value) {
_declaredVariables[name] = value;
}
/**
* Return the raw string value of the variable with the given [name],
* or `null` of the variable is not defined.
*/
String get(String name) => _declaredVariables[name];
/**
* Return the value of the variable with the given [name] interpreted as a
* 'boolean' value. If the variable is not defined (or [name] is `null`), a
* DartObject representing "unknown" is returned. If the value cannot be
* parsed as a boolean, a DartObject representing 'null' is returned. The
* [typeProvider] is the type provider used to find the type 'bool'.
*/
DartObject getBool(TypeProvider typeProvider, String name) {
String value = _declaredVariables[name];
if (value == null) {
return new DartObjectImpl(typeProvider.boolType, BoolState.UNKNOWN_VALUE);
}
if (value == "true") {
return new DartObjectImpl(typeProvider.boolType, BoolState.TRUE_STATE);
} else if (value == "false") {
return new DartObjectImpl(typeProvider.boolType, BoolState.FALSE_STATE);
}
return new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE);
}
/**
* Return the value of the variable with the given [name] interpreted as an
* integer value. If the variable is not defined (or [name] is `null`), a
* DartObject representing "unknown" is returned. If the value cannot be
* parsed as an integer, a DartObject representing 'null' is returned.
*/
DartObject getInt(TypeProvider typeProvider, String name) {
String value = _declaredVariables[name];
if (value == null) {
return new DartObjectImpl(typeProvider.intType, IntState.UNKNOWN_VALUE);
}
int bigInteger;
try {
bigInteger = int.parse(value);
} on FormatException {
return new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE);
}
return new DartObjectImpl(typeProvider.intType, new IntState(bigInteger));
}
/**
* Return the value of the variable with the given [name] interpreted as a
* String value, or `null` if the variable is not defined. Return the value of
* the variable with the given name interpreted as a String value. If the
* variable is not defined (or [name] is `null`), a DartObject representing
* "unknown" is returned. The [typeProvider] is the type provider used to find
* the type 'String'.
*/
DartObject getString(TypeProvider typeProvider, String name) {
String value = _declaredVariables[name];
if (value == null) {
return new DartObjectImpl(
typeProvider.stringType, StringState.UNKNOWN_VALUE);
}
return new DartObjectImpl(typeProvider.stringType, new StringState(value));
}
}

View file

@ -6,7 +6,7 @@ import 'dart:collection';
import 'dart:core';
import 'package:analyzer/context/context_root.dart';
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/plugin/resolver_provider.dart';
import 'package:analyzer/source/analysis_options_provider.dart';

View file

@ -3,10 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/context/context_root.dart' as old;
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/analysis_context.dart';
import 'package:analyzer/dart/analysis/context_builder.dart';
import 'package:analyzer/dart/analysis/context_root.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/context/builder.dart' as old

View file

@ -7,7 +7,7 @@ import 'dart:collection';
import 'dart:typed_data';
import 'package:analyzer/context/context_root.dart';
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/dart/analysis/results.dart' as results;
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/ast/ast.dart';

View file

@ -4,7 +4,7 @@
import 'dart:async';
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement;
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/dart/analysis/file_state.dart';

View file

@ -5,7 +5,7 @@
import 'dart:async';
import 'dart:collection';
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';

View file

@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/dart/element/element.dart'
show CompilationUnitElement, LibraryElement;
import 'package:analyzer/src/context/context.dart';

View file

@ -4,7 +4,7 @@
import 'dart:collection';
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/standard_ast_factory.dart';
import 'package:analyzer/dart/ast/token.dart';

View file

@ -4,7 +4,7 @@
library analyzer.src.generated.constant;
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/src/dart/constant/evaluation.dart';
@ -16,7 +16,7 @@ import 'package:analyzer/src/generated/source.dart' show Source;
import 'package:analyzer/src/generated/type_system.dart'
show TypeSystem, TypeSystemImpl;
export 'package:analyzer/context/declared_variables.dart';
export 'package:analyzer/dart/analysis/declared_variables.dart';
export 'package:analyzer/dart/constant/value.dart';
export 'package:analyzer/src/dart/constant/evaluation.dart';
export 'package:analyzer/src/dart/constant/utilities.dart';

View file

@ -4,7 +4,7 @@
library analyzer.test.context.declared_variables_test;
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/generated/constant.dart';
import 'package:analyzer/src/generated/testing/test_type_provider.dart';

View file

@ -4,9 +4,9 @@
import 'dart:io' as io;
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/analysis_context.dart';
import 'package:analyzer/dart/analysis/context_root.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/context_builder.dart';
import 'package:analyzer/src/dart/analysis/context_root.dart';

View file

@ -6,7 +6,7 @@ library analyzer.test.constant_test;
import 'dart:async';
import 'package:analyzer/context/declared_variables.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/standard_resolution_map.dart';
import 'package:analyzer/dart/ast/token.dart';