Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Unified Diff: pkg/analysis_server/lib/src/protocol_server.dart

Issue 1398333002: Extract protocol_dart.dart APIs. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add new files. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/protocol_server.dart
diff --git a/pkg/analysis_server/lib/src/protocol_server.dart b/pkg/analysis_server/lib/src/protocol_server.dart
index 1df67f7277f30d330f161be7d60e38f27e314b5c..678361f5f1b0c397c55b5288345f326de90094ef 100644
--- a/pkg/analysis_server/lib/src/protocol_server.dart
+++ b/pkg/analysis_server/lib/src/protocol_server.dart
@@ -5,6 +5,7 @@
library protocol.server;
import 'package:analysis_server/plugin/protocol/protocol.dart';
+import 'package:analysis_server/plugin/protocol/protocol_dart.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/services/search/search_engine.dart'
as engine;
@@ -16,6 +17,7 @@ import 'package:analyzer/src/generated/source.dart' as engine;
import 'package:analyzer/src/generated/utilities_dart.dart' as engine;
export 'package:analysis_server/plugin/protocol/protocol.dart';
+export 'package:analysis_server/plugin/protocol/protocol_dart.dart';
/**
* Returns a list of AnalysisErrors correponding to the given list of Engine
@@ -99,114 +101,6 @@ AnalysisError newAnalysisError_fromEngine(
}
/**
- * Construct based on a value from the analyzer engine.
- */
-Element newElement_fromEngine(engine.Element element) {
- String name = element.displayName;
- String elementTypeParameters = _getTypeParametersString(element);
- String elementParameters = _getParametersString(element);
- String elementReturnType = getReturnTypeString(element);
- ElementKind kind = newElementKind_fromEngineElement(element);
- return new Element(
- kind,
- name,
- Element.makeFlags(
- isPrivate: element.isPrivate,
- isDeprecated: element.isDeprecated,
- isAbstract: _isAbstract(element),
- isConst: _isConst(element),
- isFinal: _isFinal(element),
- isStatic: _isStatic(element)),
- location: newLocation_fromElement(element),
- typeParameters: elementTypeParameters,
- parameters: elementParameters,
- returnType: elementReturnType);
-}
-
-/**
- * Construct based on a value from the analyzer engine.
- * This does not take into account that
- * instances of ClassElement can be an enum and
- * instances of FieldElement can be an enum constant.
- * Use [newElementKind_fromEngineElement] where possible.
- */
-ElementKind newElementKind_fromEngine(engine.ElementKind kind) {
- if (kind == engine.ElementKind.CLASS) {
- return ElementKind.CLASS;
- }
- if (kind == engine.ElementKind.COMPILATION_UNIT) {
- return ElementKind.COMPILATION_UNIT;
- }
- if (kind == engine.ElementKind.CONSTRUCTOR) {
- return ElementKind.CONSTRUCTOR;
- }
- if (kind == engine.ElementKind.FIELD) {
- return ElementKind.FIELD;
- }
- if (kind == engine.ElementKind.FUNCTION) {
- return ElementKind.FUNCTION;
- }
- if (kind == engine.ElementKind.FUNCTION_TYPE_ALIAS) {
- return ElementKind.FUNCTION_TYPE_ALIAS;
- }
- if (kind == engine.ElementKind.GETTER) {
- return ElementKind.GETTER;
- }
- if (kind == engine.ElementKind.LABEL) {
- return ElementKind.LABEL;
- }
- if (kind == engine.ElementKind.LIBRARY) {
- return ElementKind.LIBRARY;
- }
- if (kind == engine.ElementKind.LOCAL_VARIABLE) {
- return ElementKind.LOCAL_VARIABLE;
- }
- if (kind == engine.ElementKind.METHOD) {
- return ElementKind.METHOD;
- }
- if (kind == engine.ElementKind.PARAMETER) {
- return ElementKind.PARAMETER;
- }
- if (kind == engine.ElementKind.PREFIX) {
- return ElementKind.PREFIX;
- }
- if (kind == engine.ElementKind.SETTER) {
- return ElementKind.SETTER;
- }
- if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) {
- return ElementKind.TOP_LEVEL_VARIABLE;
- }
- if (kind == engine.ElementKind.TYPE_PARAMETER) {
- return ElementKind.TYPE_PARAMETER;
- }
- return ElementKind.UNKNOWN;
-}
-
-/**
- * Construct based on a value from the analyzer engine.
- */
-ElementKind newElementKind_fromEngineElement(engine.Element element) {
- if (element is engine.ClassElement && element.isEnum) {
- return ElementKind.ENUM;
- }
- if (element is engine.FieldElement &&
- element.isEnumConstant &&
- // MyEnum.values and MyEnum.one.index return isEnumConstant = true
- // so these additional checks are necessary.
- // TODO(danrubel) MyEnum.values is constant, but is a list
- // so should it return isEnumConstant = true?
- // MyEnum.one.index is final but *not* constant
- // so should it return isEnumConstant = true?
- // Or should we return ElementKind.ENUM_CONSTANT here
- // in either or both of these cases?
- element.type != null &&
- element.type.element == element.enclosingElement) {
- return ElementKind.ENUM_CONSTANT;
- }
- return newElementKind_fromEngine(element.kind);
-}
-
-/**
* Create a Location based on an [engine.Element].
*/
Location newLocation_fromElement(engine.Element element) {
@@ -262,7 +156,7 @@ Location newLocation_fromUnit(
* Construct based on an element from the analyzer engine.
*/
OverriddenMember newOverriddenMember_fromEngine(engine.Element member) {
- Element element = newElement_fromEngine(member);
+ Element element = convertElement(member);
String className = member.enclosingElement.displayName;
return new OverriddenMember(element, className);
}
@@ -313,7 +207,7 @@ SourceEdit newSourceEdit_range(engine.SourceRange range, String replacement,
List<Element> _computePath(engine.Element element) {
List<Element> path = <Element>[];
while (element != null) {
- path.add(newElement_fromEngine(element));
+ path.add(convertElement(element));
// go up
if (element is engine.PrefixElement) {
// imports are library children, but they are physically in the unit
@@ -326,101 +220,6 @@ List<Element> _computePath(engine.Element element) {
return path;
}
-String _getParametersString(engine.Element element) {
- // TODO(scheglov) expose the corresponding feature from ExecutableElement
- List<engine.ParameterElement> parameters;
- if (element is engine.ExecutableElement) {
- // valid getters don't have parameters
- if (element.kind == engine.ElementKind.GETTER &&
- element.parameters.isEmpty) {
- return null;
- }
- parameters = element.parameters;
- } else if (element is engine.FunctionTypeAliasElement) {
- parameters = element.parameters;
- } else {
- return null;
- }
- StringBuffer sb = new StringBuffer();
- String closeOptionalString = '';
- for (engine.ParameterElement parameter in parameters) {
- if (sb.isNotEmpty) {
- sb.write(', ');
- }
- if (closeOptionalString.isEmpty) {
- engine.ParameterKind kind = parameter.parameterKind;
- if (kind == engine.ParameterKind.NAMED) {
- sb.write('{');
- closeOptionalString = '}';
- }
- if (kind == engine.ParameterKind.POSITIONAL) {
- sb.write('[');
- closeOptionalString = ']';
- }
- }
- parameter.appendToWithoutDelimiters(sb);
- }
- sb.write(closeOptionalString);
- return '(' + sb.toString() + ')';
-}
-
-String _getTypeParametersString(engine.Element element) {
- List<engine.TypeParameterElement> typeParameters;
- if (element is engine.ClassElement) {
- typeParameters = element.typeParameters;
- } else if (element is engine.FunctionTypeAliasElement) {
- typeParameters = element.typeParameters;
- }
- if (typeParameters == null || typeParameters.isEmpty) {
- return null;
- }
- return '<${typeParameters.join(', ')}>';
-}
-
-bool _isAbstract(engine.Element element) {
- // TODO(scheglov) add isAbstract to Element API
- if (element is engine.ClassElement) {
- return element.isAbstract;
- }
- if (element is engine.MethodElement) {
- return element.isAbstract;
- }
- if (element is engine.PropertyAccessorElement) {
- return element.isAbstract;
- }
- return false;
-}
-
-bool _isConst(engine.Element element) {
- // TODO(scheglov) add isConst to Element API
- if (element is engine.ConstructorElement) {
- return element.isConst;
- }
- if (element is engine.VariableElement) {
- return element.isConst;
- }
- return false;
-}
-
-bool _isFinal(engine.Element element) {
- // TODO(scheglov) add isFinal to Element API
- if (element is engine.VariableElement) {
- return element.isFinal;
- }
- return false;
-}
-
-bool _isStatic(engine.Element element) {
- // TODO(scheglov) add isStatic to Element API
- if (element is engine.ExecutableElement) {
- return element.isStatic;
- }
- if (element is engine.PropertyInducingElement) {
- return element.isStatic;
- }
- return false;
-}
-
/**
* Creates a new [Location].
*/

Powered by Google App Engine
This is Rietveld 408576698