mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 05:21:58 +00:00
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:
parent
3851591642
commit
8054721512
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
104
pkg/analyzer/lib/dart/analysis/declared_variables.dart
Normal file
104
pkg/analyzer/lib/dart/analysis/declared_variables.dart
Normal 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));
|
||||
}
|
||||
}
|
|
@ -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';
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in a new issue