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

Unified Diff: pkg/analysis_server/bin/fuzz/protocol.dart

Issue 584963002: first cut fuzz test for analysis server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge and address comments Created 6 years, 3 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/bin/fuzz/protocol.dart
diff --git a/pkg/analysis_server/lib/src/protocol.dart b/pkg/analysis_server/bin/fuzz/protocol.dart
similarity index 64%
copy from pkg/analysis_server/lib/src/protocol.dart
copy to pkg/analysis_server/bin/fuzz/protocol.dart
index 65c4d0e27a82bc5fd2fc6066104fce4040f86ef3..b41b28eba62d26fac81a5077ebf871dfdf384131 100644
--- a/pkg/analysis_server/lib/src/protocol.dart
+++ b/pkg/analysis_server/bin/fuzz/protocol.dart
@@ -7,19 +7,7 @@ library protocol;
import 'dart:collection';
import 'dart:convert';
-import 'package:analysis_server/src/computer/element.dart' show
- elementFromEngine;
-import 'package:analysis_server/src/search/search_result.dart' show
- searchResultFromMatch;
-import 'package:analysis_server/src/services/correction/fix.dart' show Fix;
-import 'package:analysis_server/src/services/json.dart';
-import 'package:analysis_server/src/services/search/search_engine.dart' as
- engine;
-import 'package:analyzer/src/generated/ast.dart' as engine;
-import 'package:analyzer/src/generated/element.dart' as engine;
-import 'package:analyzer/src/generated/engine.dart' as engine;
-import 'package:analyzer/src/generated/error.dart' as engine;
-import 'package:analyzer/src/generated/source.dart' as engine;
+import 'json.dart';
part 'generated_protocol.dart';
@@ -69,7 +57,7 @@ void _addEditForSource(SourceFileEdit sourceFileEdit, SourceEdit sourceEdit) {
* Adds [edit] to the [FileEdit] for the given [file].
*/
void _addEditToSourceChange(SourceChange change, String file, int fileStamp,
- SourceEdit edit) {
+ SourceEdit edit) {
SourceFileEdit fileEdit = change.getFileEdit(file);
if (fileEdit == null) {
fileEdit = new SourceFileEdit(file, fileStamp);
@@ -78,70 +66,6 @@ void _addEditToSourceChange(SourceChange change, String file, int fileStamp,
fileEdit.add(edit);
}
-
-void _addElementEditToSourceChange(SourceChange change, engine.Element element,
- SourceEdit edit) {
- engine.AnalysisContext context = element.context;
- engine.Source source = element.source;
- _addSourceEditToSourceChange(change, context, source, edit);
-}
-
-
-void _addSourceEditToSourceChange(SourceChange change,
- engine.AnalysisContext context, engine.Source source, SourceEdit edit) {
- String file = source.fullName;
- int fileStamp = context.getModificationStamp(source);
- change.addEdit(file, fileStamp, edit);
-}
-
-/**
- * Create an AnalysisError based on error information from the analyzer
- * engine. Access via AnalysisError.fromEngine().
- */
-AnalysisError _analysisErrorFromEngine(engine.LineInfo lineInfo,
- engine.AnalysisError error) {
- engine.ErrorCode errorCode = error.errorCode;
- // prepare location
- Location location;
- {
- String file = error.source.fullName;
- int offset = error.offset;
- int length = error.length;
- int startLine = -1;
- int startColumn = -1;
- if (lineInfo != null) {
- engine.LineInfo_Location lineLocation = lineInfo.getLocation(offset);
- if (lineLocation != null) {
- startLine = lineLocation.lineNumber;
- startColumn = lineLocation.columnNumber;
- }
- }
- location = new Location(file, offset, length, startLine, startColumn);
- }
- // done
- var severity = new AnalysisErrorSeverity(errorCode.errorSeverity.name);
- var type = new AnalysisErrorType(errorCode.type.name);
- String message = error.message;
- String correction = error.correction;
- return new AnalysisError(
- severity,
- type,
- location,
- message,
- correction: correction);
-}
-
-/**
- * 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().
@@ -168,105 +92,6 @@ 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().
- */
-ElementKind _elementKindFromEngine(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;
-}
-
-/**
* Returns the [FileEdit] for the given [file], maybe `null`.
*/
SourceFileEdit _getChangeFileEdit(SourceChange change, String file) {
@@ -295,85 +120,6 @@ bool _listEqual(List listA, List listB, bool itemEqual(a, b)) {
}
/**
- * Creates a new [Location].
- */
-Location _locationForArgs(engine.AnalysisContext context, engine.Source source,
- engine.SourceRange range) {
- int startLine = 0;
- int startColumn = 0;
- {
- engine.LineInfo lineInfo = context.getLineInfo(source);
- if (lineInfo != null) {
- engine.LineInfo_Location offsetLocation =
- lineInfo.getLocation(range.offset);
- startLine = offsetLocation.lineNumber;
- startColumn = offsetLocation.columnNumber;
- }
- }
- return new Location(
- source.fullName,
- range.offset,
- range.length,
- startLine,
- startColumn);
-}
-
-/**
- * Creates a new [Location] for the given [engine.Element].
- */
-Location _locationFromElement(engine.Element element) {
- engine.AnalysisContext context = element.context;
- engine.Source source = element.source;
- if (context == null || source == null) {
- return null;
- }
- String name = element.displayName;
- int offset = element.nameOffset;
- int length = name != null ? name.length : 0;
- if (element is engine.CompilationUnitElement) {
- offset = 0;
- length = 0;
- }
- engine.SourceRange range = new engine.SourceRange(offset, length);
- return _locationForArgs(context, source, range);
-}
-
-/**
- * Creates a new [Location] for the given [engine.SearchMatch].
- */
-Location _locationFromMatch(engine.SearchMatch match) {
- engine.Element enclosingElement = match.element;
- return _locationForArgs(
- enclosingElement.context,
- enclosingElement.source,
- match.sourceRange);
-}
-
-/**
- * Creates a new [Location] for the given [engine.AstNode].
- */
-Location _locationFromNode(engine.AstNode node) {
- engine.CompilationUnit unit =
- node.getAncestor((node) => node is engine.CompilationUnit);
- engine.CompilationUnitElement unitElement = unit.element;
- engine.AnalysisContext context = unitElement.context;
- engine.Source source = unitElement.source;
- engine.SourceRange range = new engine.SourceRange(node.offset, node.length);
- return _locationForArgs(context, source, range);
-}
-
-/**
- * Creates a new [Location] for the given [engine.CompilationUnit].
- */
-Location _locationFromUnit(engine.CompilationUnit unit,
- engine.SourceRange range) {
- engine.CompilationUnitElement unitElement = unit.element;
- engine.AnalysisContext context = unitElement.context;
- engine.Source source = unitElement.source;
- return _locationForArgs(context, source, range);
-}
-
-/**
* Compare the maps [mapA] and [mapB], using [valueEqual] to compare map
* values.
*/
@@ -416,16 +162,6 @@ RefactoringProblemSeverity
}
/**
- * Create an OverriddenMember based on an element from the analyzer engine.
- */
-OverriddenMember _overriddenMemberFromEngine(engine.Element member) {
- Element element = elementFromEngine(member);
- String className = member.enclosingElement.displayName;
- return new OverriddenMember(element, className);
-}
-
-
-/**
* Create a [RefactoringFeedback] corresponding the given [kind].
*/
RefactoringFeedback _refactoringFeedbackFromJson(JsonDecoder jsonDecoder,
@@ -436,13 +172,19 @@ RefactoringFeedback _refactoringFeedbackFromJson(JsonDecoder jsonDecoder,
}
RefactoringKind kind = REQUEST_ID_REFACTORING_KINDS.remove(requestId);
if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) {
- return new ExtractLocalVariableFeedback.fromJson(jsonDecoder, jsonPath, json);
+ return new ExtractLocalVariableFeedback.fromJson(
+ jsonDecoder,
+ jsonPath,
+ json);
}
if (kind == RefactoringKind.EXTRACT_METHOD) {
return new ExtractMethodFeedback.fromJson(jsonDecoder, jsonPath, json);
}
if (kind == RefactoringKind.INLINE_LOCAL_VARIABLE) {
- return new InlineLocalVariableFeedback.fromJson(jsonDecoder, jsonPath, json);
+ return new InlineLocalVariableFeedback.fromJson(
+ jsonDecoder,
+ jsonPath,
+ json);
}
if (kind == RefactoringKind.INLINE_METHOD) {
return new InlineMethodFeedback.fromJson(jsonDecoder, jsonPath, json);
@@ -460,7 +202,10 @@ RefactoringFeedback _refactoringFeedbackFromJson(JsonDecoder jsonDecoder,
RefactoringOptions _refactoringOptionsFromJson(JsonDecoder jsonDecoder,
String jsonPath, Object json, RefactoringKind kind) {
if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) {
- return new ExtractLocalVariableOptions.fromJson(jsonDecoder, jsonPath, json);
+ return new ExtractLocalVariableOptions.fromJson(
+ jsonDecoder,
+ jsonPath,
+ json);
}
if (kind == RefactoringKind.EXTRACT_METHOD) {
return new ExtractMethodOptions.fromJson(jsonDecoder, jsonPath, json);
@@ -468,42 +213,12 @@ RefactoringOptions _refactoringOptionsFromJson(JsonDecoder jsonDecoder,
if (kind == RefactoringKind.INLINE_METHOD) {
return new InlineMethodOptions.fromJson(jsonDecoder, jsonPath, json);
}
- if (kind == RefactoringKind.MOVE_FILE) {
- return new MoveFileOptions.fromJson(jsonDecoder, jsonPath, json);
- }
if (kind == RefactoringKind.RENAME) {
return new RenameOptions.fromJson(jsonDecoder, jsonPath, json);
}
return null;
}
-
-/**
- * Create a SearchResultKind based on a value from the search engine.
- */
-SearchResultKind _searchResultKindFromEngine(engine.MatchKind kind) {
- if (kind == engine.MatchKind.DECLARATION) {
- return SearchResultKind.DECLARATION;
- }
- if (kind == engine.MatchKind.READ) {
- return SearchResultKind.READ;
- }
- if (kind == engine.MatchKind.READ_WRITE) {
- return SearchResultKind.READ_WRITE;
- }
- if (kind == engine.MatchKind.WRITE) {
- return SearchResultKind.WRITE;
- }
- if (kind == engine.MatchKind.INVOCATION) {
- return SearchResultKind.INVOCATION;
- }
- if (kind == engine.MatchKind.REFERENCE) {
- return SearchResultKind.REFERENCE;
- }
- return SearchResultKind.UNKNOWN;
-}
-
-
/**
* Type of callbacks used to decode parts of JSON objects. [jsonPath] is a
* string describing the part of the JSON object being decoded, and [value] is
@@ -679,7 +394,8 @@ class Notification {
* Initialize a newly created instance based upon the given JSON data
*/
factory Notification.fromJson(Map<String, Object> json) {
- return new Notification(json[Notification.EVENT],
+ return new Notification(
+ json[Notification.EVENT],
json[Notification.PARAMS]);
}
@@ -918,16 +634,15 @@ class Response {
Object error = json[Response.ERROR];
RequestError decodedError;
if (error is Map) {
- decodedError = new RequestError.fromJson(new ResponseDecoder(null),
- '.error', error);
+ decodedError =
+ new RequestError.fromJson(new ResponseDecoder(null), '.error', error);
}
Object result = json[Response.RESULT];
Map<String, Object> decodedResult;
if (result is Map) {
decodedResult = result;
}
- return new Response(id, error: decodedError,
- result: decodedResult);
+ return new Response(id, error: decodedError, result: decodedResult);
} catch (exception) {
return null;
}
@@ -938,10 +653,11 @@ class Response {
* GET_ERRORS_INVALID_FILE error condition.
*/
Response.getErrorsInvalidFile(Request request)
- : this(
- request.id,
- error: new RequestError(RequestErrorCode.GET_ERRORS_INVALID_FILE,
- 'Error during `analysis.getErrors`: invalid file.'));
+ : this(
+ request.id,
+ error: new RequestError(
+ RequestErrorCode.GET_ERRORS_INVALID_FILE,
+ 'Error during `analysis.getErrors`: invalid file.'));
/**
* Initialize a newly created instance to represent an error condition caused
@@ -951,15 +667,20 @@ class Response {
* [expectation] is a description of the type of data that was expected.
*/
Response.invalidParameter(Request request, String path, String expectation)
- : this(request.id, error: new RequestError(RequestErrorCode.INVALID_PARAMETER,
- "Expected parameter $path to $expectation"));
+ : this(
+ request.id,
+ error: new RequestError(
+ RequestErrorCode.INVALID_PARAMETER,
+ "Expected parameter $path to $expectation"));
/**
* Initialize a newly created instance to represent an error condition caused
* by a malformed request.
*/
Response.invalidRequestFormat()
- : this('', error: new RequestError(RequestErrorCode.INVALID_REQUEST, 'Invalid request'));
+ : this(
+ '',
+ error: new RequestError(RequestErrorCode.INVALID_REQUEST, 'Invalid request'));
/**
* Initialize a newly created instance to represent an error condition caused
@@ -967,17 +688,25 @@ class Response {
* that are not being analyzed.
*/
Response.unanalyzedPriorityFiles(Request request, String fileNames)
- : this(request.id, error: new RequestError(RequestErrorCode.UNANALYZED_PRIORITY_FILES, "Unanalyzed files cannot be a priority: '$fileNames'"));
+ : this(
+ request.id,
+ error: new RequestError(
+ RequestErrorCode.UNANALYZED_PRIORITY_FILES,
+ "Unanalyzed files cannot be a priority: '$fileNames'"));
/**
* Initialize a newly created instance to represent an error condition caused
* by a [request] that cannot be handled by any known handlers.
*/
Response.unknownRequest(Request request)
- : this(request.id, error: new RequestError(RequestErrorCode.UNKNOWN_REQUEST, 'Unknown request'));
+ : this(
+ request.id,
+ error: new RequestError(RequestErrorCode.UNKNOWN_REQUEST, 'Unknown request'));
Response.unsupportedFeature(String requestId, String message)
- : this(requestId, error: new RequestError(RequestErrorCode.UNSUPPORTED_FEATURE, message));
+ : this(
+ requestId,
+ error: new RequestError(RequestErrorCode.UNSUPPORTED_FEATURE, message));
/**
* Return a table representing the structure of the Json object that will be
« no previous file with comments | « pkg/analysis_server/bin/fuzz/logging_client_channel.dart ('k') | pkg/analysis_server/bin/fuzz/server_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698