Clean up some code in plugins

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2967683002 .
This commit is contained in:
Brian Wilkerson 2017-06-30 10:39:19 -07:00
parent e64c18435f
commit 6f4420562c
3 changed files with 18 additions and 107 deletions

View file

@ -121,7 +121,6 @@ class PluginIsolateChannel implements PluginCommunicationChannel {
{Function onError, void onDone()}) {
void onData(data) {
Map<String, Object> requestMap = data;
// print('[plugin] Received request: ${JSON.encode(requestMap)}');
Request request = new Request.fromJson(requestMap);
if (request != null) {
onRequest(request);
@ -138,14 +137,12 @@ class PluginIsolateChannel implements PluginCommunicationChannel {
@override
void sendNotification(Notification notification) {
Map<String, Object> json = notification.toJson();
// print('[plugin] Send notification: ${JSON.encode(json)}');
_sendPort.send(json);
}
@override
void sendResponse(Response response) {
Map<String, Object> json = response.toJson();
// print('[plugin] Send response: ${JSON.encode(json)}');
_sendPort.send(json);
}
}

View file

@ -131,22 +131,21 @@ bool mapEqual(Map mapA, Map mapB, bool valueEqual(a, b)) {
* Translate the input [map], applying [keyCallback] to all its keys, and
* [valueCallback] to all its values.
*/
Map/*<KR, VR>*/ mapMap/*<KP, VP, KR, VR>*/(Map/*<KP, VP>*/ map,
{dynamic/*=KR*/ keyCallback(/*<KP>*/ key),
dynamic/*=VR*/ valueCallback(/*<VP>*/ value)}) {
Map/*<KR, VR>*/ result = new HashMap/*<KR, VR>*/();
Map<KR, VR> mapMap<KP, VP, KR, VR>(Map<KP, VP> map,
{KR keyCallback(KP key), VR valueCallback(VP value)}) {
Map<KR, VR> result = new HashMap<KR, VR>();
map.forEach((key, value) {
Object/*=KR*/ resultKey;
Object/*=VR*/ resultValue;
KR resultKey;
VR resultValue;
if (keyCallback != null) {
resultKey = keyCallback(key);
} else {
resultKey = key as Object/*=KR*/;
resultKey = key as KR;
}
if (valueCallback != null) {
resultValue = valueCallback(value);
} else {
resultValue = value as Object/*=VR*/;
resultValue = value as VR;
}
result[resultKey] = resultValue;
});
@ -225,56 +224,6 @@ RefactoringOptions refactoringOptionsFromJson(JsonDecoder jsonDecoder,
return null;
}
///**
// * Create a [RefactoringFeedback] corresponding the given [kind].
// */
//RefactoringFeedback refactoringFeedbackFromJson(
// JsonDecoder jsonDecoder, String jsonPath, Object json, Map feedbackJson) {
// RefactoringKind kind = jsonDecoder.refactoringKind;
// if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) {
// 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);
// }
// if (kind == RefactoringKind.INLINE_METHOD) {
// return new InlineMethodFeedback.fromJson(jsonDecoder, jsonPath, json);
// }
// if (kind == RefactoringKind.RENAME) {
// return new RenameFeedback.fromJson(jsonDecoder, jsonPath, json);
// }
// return null;
//}
//
///**
// * Create a [RefactoringOptions] corresponding the given [kind].
// */
//RefactoringOptions refactoringOptionsFromJson(JsonDecoder jsonDecoder,
// String jsonPath, Object json, RefactoringKind kind) {
// if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) {
// return new ExtractLocalVariableOptions.fromJson(
// jsonDecoder, jsonPath, json);
// }
// if (kind == RefactoringKind.EXTRACT_METHOD) {
// return new ExtractMethodOptions.fromJson(jsonDecoder, jsonPath, json);
// }
// 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;
//}
/**
* 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
@ -341,12 +290,12 @@ abstract class JsonDecoder {
*
* The type parameter [E] is the expected type of the elements in the list.
*/
List/*<E>*/ decodeList/*<E>*/(String jsonPath, Object json,
[JsonDecoderCallback/*<E>*/ decoder]) {
List<E> decodeList<E>(String jsonPath, Object json,
[JsonDecoderCallback<E> decoder]) {
if (json == null) {
return/*<E>*/ [];
return <E>[];
} else if (json is List) {
List/*<E>*/ result = /*<E>*/ [];
List<E> result = <E>[];
for (int i = 0; i < json.length; i++) {
result.add(decoder('$jsonPath[$i]', json[i]));
}
@ -360,24 +309,24 @@ abstract class JsonDecoder {
* Decode a JSON object that is expected to be a Map. [keyDecoder] is used
* to decode the keys, and [valueDecoder] is used to decode the values.
*/
Map/*<K, V>*/ decodeMap/*<K, V>*/(String jsonPath, Object json,
{JsonDecoderCallback/*<K>*/ keyDecoder,
JsonDecoderCallback/*<V>*/ valueDecoder}) {
Map<K, V> decodeMap<K, V>(String jsonPath, Object json,
{JsonDecoderCallback<K> keyDecoder,
JsonDecoderCallback<V> valueDecoder}) {
if (json == null) {
return {};
} else if (json is Map) {
Map/*<K, V>*/ result = /*<K, V>*/ {};
Map<K, V> result = <K, V>{};
json.forEach((String key, value) {
Object/*=K*/ decodedKey;
K decodedKey;
if (keyDecoder != null) {
decodedKey = keyDecoder('$jsonPath.key', key);
} else {
decodedKey = key as Object/*=K*/;
decodedKey = key as K;
}
if (valueDecoder != null) {
value = valueDecoder('$jsonPath[${JSON.encode(key)}]', value);
}
result[decodedKey] = value as Object/*=V*/;
result[decodedKey] = value as V;
});
return result;
} else {

View file

@ -357,7 +357,6 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder {
// TO-DO
write(prefix2);
writeln('// TODO: implement ${member.displayName}');
// REVIEW: Added return statement.
if (shouldReturn) {
write(prefix2);
writeln('return null;');
@ -978,11 +977,6 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
*/
Set<Source> librariesToImport = new Set<Source>();
// /**
// * The content of the file being edited.
// */
// String _content;
/**
* Initialize a newly created builder to build a source file edit within the
* change being built by the given [changeBuilder]. The file being edited has
@ -1273,21 +1267,6 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
offset, insertEmptyLineBefore, insertEmptyLineAfter);
}
// /**
// * Return the content of the file being edited.
// */
// String getContent() {
// if (_content == null) {
// CompilationUnitElement unitElement = unit.element;
// AnalysisContext context = unitElement.context;
// if (context == null) {
// throw new CancelCorrectionException();
// }
// _content = context.getContents(unitElement.source).data;
// }
// return _content;
// }
/**
* Computes the best URI to import [what] into [from].
*/
@ -1312,20 +1291,6 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
return content.substring(offset, offset + length);
}
// /**
// * Returns the text of the given [AstNode] in the unit.
// */
// String _getNodeText(AstNode node) {
// return _getText(node.offset, node.length);
// }
//
// /**
// * Returns the text of the given range in the unit.
// */
// String _getText(int offset, int length) {
// return getContent().substring(offset, offset + length);
// }
/**
* Create an edit to replace the return type of the innermost function
* containing the given [node] with the type `Future`. The [typeProvider] is