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

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

Issue 497393002: Make more use of generated code in analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
« no previous file with comments | « pkg/analysis_server/lib/src/protocol.dart ('k') | pkg/analysis_server/lib/src/search/search_domain.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/protocol2.dart
diff --git a/pkg/analysis_server/lib/src/protocol2.dart b/pkg/analysis_server/lib/src/protocol2.dart
index 49bb9b1edca305d8c1117cf5f26a005a631ed406..8817570731b9735b4850b677556899f60c8a2f17 100644
--- a/pkg/analysis_server/lib/src/protocol2.dart
+++ b/pkg/analysis_server/lib/src/protocol2.dart
@@ -8,6 +8,7 @@ import 'dart:convert';
import 'package:analysis_server/src/computer/element.dart' show
elementFromEngine;
+import 'package:analysis_server/src/services/correction/fix.dart' show Fix;
import 'package:analysis_server/src/search/search_result.dart' show
searchResultFromMatch;
import 'package:analysis_server/src/services/json.dart';
@@ -62,6 +63,30 @@ void _addEditForSource(SourceFileEdit sourceFileEdit, SourceEdit sourceEdit) {
}
/**
+ * Adds [edit] to the [FileEdit] for the given [file].
+ */
+void _addEditToSourceChange(SourceChange change, String file, SourceEdit edit) {
+ SourceFileEdit fileEdit = change.getFileEdit(file);
+ if (fileEdit == null) {
+ fileEdit = new SourceFileEdit(file);
+ change.addFileEdit(fileEdit);
+ }
+ fileEdit.add(edit);
+}
+
+/**
+ * Returns the [FileEdit] for the given [file], maybe `null`.
+ */
+SourceFileEdit _getChangeFileEdit(SourceChange change, String file) {
+ for (SourceFileEdit fileEdit in change.edits) {
+ if (fileEdit.file == file) {
+ return fileEdit;
+ }
+ }
+ return null;
+}
+
+/**
* Create an AnalysisError based on error information from the analyzer
* engine. Access via AnalysisError.fromEngine().
*/
@@ -99,6 +124,17 @@ AnalysisError _analysisErrorFromEngine(engine.LineInfo lineInfo,
}
/**
+ * Returns a list of AnalysisErrors correponding to the given list of Engine
+ * errors. Access via AnalysisError.listFromEngine().
+ */
+List<AnalysisError> _analysisErrorListFromEngine(engine.LineInfo lineInfo,
+ List<engine.AnalysisError> errors) {
+ return errors.map((engine.AnalysisError error) {
+ return new AnalysisError.fromEngine(lineInfo, error);
+ }).toList();
+}
+
+/**
* Get the result of applying the edit to the given [code]. Access via
* SourceEdit.apply().
*/
@@ -121,6 +157,49 @@ String _applySequence(String code, Iterable<SourceEdit> edits) {
}
/**
+ * Map an element kind from the analyzer engine to a [CompletionSuggestionKind].
+ */
+CompletionSuggestionKind _completionSuggestionKindFromElementKind(engine.ElementKind kind) {
+ // ElementKind.ANGULAR_FORMATTER,
+ // ElementKind.ANGULAR_COMPONENT,
+ // ElementKind.ANGULAR_CONTROLLER,
+ // ElementKind.ANGULAR_DIRECTIVE,
+ // ElementKind.ANGULAR_PROPERTY,
+ // ElementKind.ANGULAR_SCOPE_PROPERTY,
+ // ElementKind.ANGULAR_SELECTOR,
+ // ElementKind.ANGULAR_VIEW,
+ if (kind == engine.ElementKind.CLASS) return CompletionSuggestionKind.CLASS;
+ // ElementKind.COMPILATION_UNIT,
+ if (kind == engine.ElementKind.CONSTRUCTOR) return CompletionSuggestionKind.CONSTRUCTOR;
+ // ElementKind.DYNAMIC,
+ // ElementKind.EMBEDDED_HTML_SCRIPT,
+ // ElementKind.ERROR,
+ // ElementKind.EXPORT,
+ // ElementKind.EXTERNAL_HTML_SCRIPT,
+ if (kind == engine.ElementKind.FIELD) return CompletionSuggestionKind.FIELD;
+ if (kind == engine.ElementKind.FUNCTION) return CompletionSuggestionKind.FUNCTION;
+ if (kind == engine.ElementKind.FUNCTION_TYPE_ALIAS) return CompletionSuggestionKind.FUNCTION_TYPE_ALIAS;
+ if (kind == engine.ElementKind.GETTER) return CompletionSuggestionKind.GETTER;
+ // ElementKind.HTML,
+ if (kind == engine.ElementKind.IMPORT) return CompletionSuggestionKind.IMPORT;
+ // ElementKind.LABEL,
+ // ElementKind.LIBRARY,
+ if (kind == engine.ElementKind.LOCAL_VARIABLE) return CompletionSuggestionKind.LOCAL_VARIABLE;
+ if (kind == engine.ElementKind.METHOD) return CompletionSuggestionKind.METHOD;
+ // ElementKind.NAME,
+ if (kind == engine.ElementKind.PARAMETER) return CompletionSuggestionKind.PARAMETER;
+ // ElementKind.POLYMER_ATTRIBUTE,
+ // ElementKind.POLYMER_TAG_DART,
+ // ElementKind.POLYMER_TAG_HTML,
+ // ElementKind.PREFIX,
+ if (kind == engine.ElementKind.SETTER) return CompletionSuggestionKind.SETTER;
+ if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) return CompletionSuggestionKind.TOP_LEVEL_VARIABLE;
+ // ElementKind.TYPE_PARAMETER,
+ // ElementKind.UNIVERSE
+ throw new ArgumentError('Unknown CompletionSuggestionKind for: $kind');
+}
+
+/**
* Create an ElementKind based on a value from the analyzer engine. Access
* this function via new ElementKind.fromEngine().
*/
« no previous file with comments | « pkg/analysis_server/lib/src/protocol.dart ('k') | pkg/analysis_server/lib/src/search/search_domain.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698