Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
analyzer_plugin no implicit-casts.
Browse files Browse the repository at this point in the history
Change-Id: I12e5d4da5b61938b3eb7cc7c0e2ade6a64510b9e
Reviewed-on: https://dart-review.googlesource.com/69201
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
devoncarew authored and commit-bot@chromium.org committed Aug 9, 2018
1 parent 2940157 commit 6fc1dd4
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 46 deletions.
3 changes: 3 additions & 0 deletions pkg/analyzer_plugin/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
analyzer:
strong-mode:
implicit-casts: false
linter:
rules:
- annotate_overrides
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer_plugin/lib/plugin/assist_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ abstract class AssistsMixin implements ServerPlugin {
AssistRequest request = await getAssistRequest(parameters);
AssistGenerator generator =
new AssistGenerator(getAssistContributors(path));
GeneratorResult result = await generator.generateAssistsResponse(request);
GeneratorResult<EditGetAssistsResult> result =
await generator.generateAssistsResponse(request);
result.sendNotifications(channel);
return result.result;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer_plugin/lib/plugin/completion_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract class CompletionMixin implements ServerPlugin {
CompletionRequest request = await getCompletionRequest(parameters);
CompletionGenerator generator =
new CompletionGenerator(getCompletionContributors(path));
GeneratorResult result =
GeneratorResult<CompletionGetSuggestionsResult> result =
await generator.generateCompletionResponse(request);
result.sendNotifications(channel);
return result.result;
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer_plugin/lib/plugin/fix_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ abstract class FixesMixin implements ServerPlugin {
String path = parameters.file;
FixesRequest request = await getFixesRequest(parameters);
FixGenerator generator = new FixGenerator(getFixContributors(path));
GeneratorResult result = await generator.generateFixesResponse(request);
GeneratorResult<EditGetFixesResult> result =
await generator.generateFixesResponse(request);
result.sendNotifications(channel);
return result.result;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer_plugin/lib/plugin/kythe_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ abstract class EntryMixin implements ServerPlugin {
String path = parameters.file;
EntryRequest request = await getEntryRequest(parameters);
EntryGenerator generator = new EntryGenerator(getEntryContributors(path));
GeneratorResult result =
GeneratorResult<KytheGetKytheEntriesResult> result =
await generator.generateGetEntriesResponse(request);
result.sendNotifications(channel);
return result.result;
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer_plugin/lib/plugin/navigation_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class NavigationMixin implements ServerPlugin {
NavigationRequest request = await getNavigationRequest(parameters);
NavigationGenerator generator =
new NavigationGenerator(getNavigationContributors(path));
GeneratorResult result =
GeneratorResult<AnalysisGetNavigationResult> result =
await generator.generateNavigationResponse(request);
result.sendNotifications(channel);
return result.result;
Expand Down
9 changes: 5 additions & 4 deletions pkg/analyzer_plugin/lib/protocol/protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Notification {
* Initialize a newly created instance based on the given JSON data.
*/
factory Notification.fromJson(Map json) {
return new Notification(json[Notification.EVENT],
return new Notification(json[Notification.EVENT] as String,
json[Notification.PARAMS] as Map<String, Object>);
}

Expand Down Expand Up @@ -164,7 +164,8 @@ class Request {
}
var params = result[Request.PARAMS];
if (params is Map || params == null) {
return new Request(id, method, params as Map<String, Object>, time);
return new Request(id as String, method as String,
params as Map<String, Object>, time as int);
} else {
return null;
}
Expand Down Expand Up @@ -302,7 +303,7 @@ class RequestErrorFactory {
/**
* Return a request error representing an error that occurred in the plugin.
*/
static RequestError pluginError(exception, String stackTrace) =>
static RequestError pluginError(dynamic exception, String stackTrace) =>
new RequestError(RequestErrorCode.PLUGIN_ERROR, exception.toString(),
stackTrace: stackTrace);

Expand Down Expand Up @@ -417,7 +418,7 @@ class Response {
if (result is Map) {
decodedResult = result as Map<String, Object>;
}
return new Response(id, requestTime,
return new Response(id as String, requestTime as int,
error: decodedError, result: decodedResult);
} catch (exception) {
return null;
Expand Down
17 changes: 11 additions & 6 deletions pkg/analyzer_plugin/lib/protocol/protocol_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1480,12 +1480,12 @@ class Element implements HasToJson {
static const int FLAG_DEPRECATED = 0x20;

static int makeFlags(
{isAbstract: false,
isConst: false,
isFinal: false,
isStatic: false,
isPrivate: false,
isDeprecated: false}) {
{bool isAbstract: false,
bool isConst: false,
bool isFinal: false,
bool isStatic: false,
bool isPrivate: false,
bool isDeprecated: false}) {
int flags = 0;
if (isAbstract) flags |= FLAG_ABSTRACT;
if (isConst) flags |= FLAG_CONST;
Expand Down Expand Up @@ -1697,10 +1697,15 @@ class Element implements HasToJson {
}

bool get isAbstract => (flags & FLAG_ABSTRACT) != 0;

bool get isConst => (flags & FLAG_CONST) != 0;

bool get isFinal => (flags & FLAG_FINAL) != 0;

bool get isStatic => (flags & FLAG_STATIC) != 0;

bool get isPrivate => (flags & FLAG_PRIVATE) != 0;

bool get isDeprecated => (flags & FLAG_DEPRECATED) != 0;

@override
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer_plugin/lib/protocol/protocol_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1758,8 +1758,8 @@ class AnalysisUpdateContentParams implements RequestParams {
Map<String, dynamic> files;
if (json.containsKey("files")) {
files = jsonDecoder.decodeMap(jsonPath + ".files", json["files"],
valueDecoder: (String jsonPath, Object json) =>
jsonDecoder.decodeUnion(jsonPath, json, "type", {
valueDecoder: (String jsonPath, dynamic json) =>
jsonDecoder.decodeUnion(jsonPath, json as Map, "type", {
"add": (String jsonPath, Object json) =>
new AddContentOverlay.fromJson(
jsonDecoder, jsonPath, json),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ RefactoringOptions refactoringOptionsFromJson(JsonDecoder jsonDecoder,
* string describing the part of the JSON object being decoded, and [value] is
* the part to decode.
*/
typedef E JsonDecoderCallback<E>(String jsonPath, Object value);
typedef E JsonDecoderCallback<E>(String jsonPath, dynamic value);

/**
* Instances of the class [HasToJson] implement [toJson] method that returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder {
DartFileEditBuilderImpl sourceFileEditBuilder, int offset, int length)
: super(sourceFileEditBuilder, offset, length);

DartFileEditBuilderImpl get dartFileEditBuilder => fileEditBuilder;
DartFileEditBuilderImpl get dartFileEditBuilder =>
fileEditBuilder as DartFileEditBuilderImpl;

@override
void addLinkedEdit(String groupName,
void buildLinkedEdit(DartLinkedEditBuilder builder)) =>
super.addLinkedEdit(groupName, (builder) => buildLinkedEdit(builder));
super.addLinkedEdit(groupName,
(builder) => buildLinkedEdit(builder as DartLinkedEditBuilder));

@override
LinkedEditBuilderImpl createLinkedEditBuilder() {
Expand Down Expand Up @@ -1124,12 +1126,14 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl

@override
void addInsertion(int offset, void buildEdit(DartEditBuilder builder)) =>
super.addInsertion(offset, (builder) => buildEdit(builder));
super.addInsertion(
offset, (builder) => buildEdit(builder as DartEditBuilder));

@override
void addReplacement(
SourceRange range, void buildEdit(DartEditBuilder builder)) =>
super.addReplacement(range, (builder) => buildEdit(builder));
super.addReplacement(
range, (builder) => buildEdit(builder as DartEditBuilder));

@override
void convertFunctionFromSyncToAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
index = node.arguments.length - 1;
}
} else {
index = node.arguments.indexOf(entity);
index = node.arguments.indexOf(entity as Expression);
}
if (0 <= index && index < parameters.length) {
ParameterElement param = parameters[index];
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer_plugin/lib/utilities/assist/assist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class AssistGenerator {
* by the given [request]. If any of the contributors throws an exception,
* also create a non-fatal 'plugin.error' notification.
*/
GeneratorResult generateAssistsResponse(AssistRequest request) {
GeneratorResult<EditGetAssistsResult> generateAssistsResponse(
AssistRequest request) {
List<Notification> notifications = <Notification>[];
AssistCollectorImpl collector = new AssistCollectorImpl();
for (AssistContributor contributor in contributors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class CompletionGenerator {
* [path]. If any of the contributors throws an exception, also create a
* non-fatal 'plugin.error' notification.
*/
Future<GeneratorResult> generateCompletionResponse(
CompletionRequest request) async {
Future<GeneratorResult<CompletionGetSuggestionsResult>>
generateCompletionResponse(CompletionRequest request) async {
// TODO(brianwilkerson) Determine whether this await is necessary.
await null;
List<Notification> notifications = <Notification>[];
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer_plugin/lib/utilities/fixes/fixes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class FixGenerator {
* by the given [request]. If any of the contributors throws an exception,
* also create a non-fatal 'plugin.error' notification.
*/
GeneratorResult generateFixesResponse(FixesRequest request) {
GeneratorResult<EditGetFixesResult> generateFixesResponse(
FixesRequest request) {
List<Notification> notifications = <Notification>[];
FixCollectorImpl collector = new FixCollectorImpl();
for (FixContributor contributor in contributors) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer_plugin/lib/utilities/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import 'package:analyzer_plugin/src/protocol/protocol_internal.dart';
*
* Clients may not extend, implement or mix-in this class.
*/
class GeneratorResult {
class GeneratorResult<T extends ResponseResult> {
/**
* The result to be sent to the server, or `null` if there is no response, as
* when the generator is generating a notification.
*/
final ResponseResult result;
final T result;

/**
* The notifications that should be sent to the server. The list will be empty
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer_plugin/lib/utilities/kythe/entries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class EntryGenerator {
* [request]. If any of the contributors throws an exception, also create a
* non-fatal 'plugin.error' notification.
*/
GeneratorResult generateGetEntriesResponse(EntryRequest request) {
GeneratorResult<KytheGetKytheEntriesResult> generateGetEntriesResponse(
EntryRequest request) {
List<Notification> notifications = <Notification>[];
EntryCollectorImpl collector = new EntryCollectorImpl();
for (EntryContributor contributor in contributors) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer_plugin/lib/utilities/navigation/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class NavigationGenerator {
* specified by the given [request]. If any of the contributors throws an
* exception, also create a non-fatal 'plugin.error' notification.
*/
GeneratorResult generateNavigationResponse(NavigationRequest request) {
GeneratorResult<AnalysisGetNavigationResult> generateNavigationResponse(
NavigationRequest request) {
List<Notification> notifications = <Notification>[];
NavigationCollectorImpl collector = new NavigationCollectorImpl();
for (NavigationContributor contributor in contributors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class MatchesJsonObject extends _RecursiveMatcher {
if (requiredFields != null && requiredFields.containsKey(key)) {
// Already checked this field
} else if (optionalFields != null && optionalFields.containsKey(key)) {
_checkField(key, value, optionalFields[key], mismatches);
_checkField(key as String, value, optionalFields[key], mismatches);
} else {
mismatches.add((Description mismatchDescription) => mismatchDescription
.add('has unexpected field ')
Expand Down Expand Up @@ -572,7 +572,8 @@ class Server {
// params.
outOfTestExpect(messageAsMap, contains('event'));
outOfTestExpect(messageAsMap['event'], isString);
notificationProcessor(messageAsMap['event'], messageAsMap['params']);
notificationProcessor(
messageAsMap['event'] as String, messageAsMap['params']);
// Check that the message is well-formed. We do this after calling
// notificationController.add() so that we don't stall the test in the
// event of an error.
Expand Down Expand Up @@ -751,7 +752,7 @@ class _ListOf extends Matcher {
*/
final Matcher iterableMatcher;

_ListOf(elementMatcher)
_ListOf(Matcher elementMatcher)
: elementMatcher = elementMatcher,
iterableMatcher = everyElement(elementMatcher);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ main() {
}

abstract class BuilderTestMixin {
SourceEdit getEdit(DartChangeBuilderImpl builder) {
SourceEdit getEdit(DartChangeBuilder builder) {
SourceChange sourceChange = builder.sourceChange;
expect(sourceChange, isNotNull);
List<SourceFileEdit> fileEdits = sourceChange.edits;
Expand All @@ -45,7 +45,7 @@ abstract class BuilderTestMixin {
return edits[0];
}

List<SourceEdit> getEdits(DartChangeBuilderImpl builder) {
List<SourceEdit> getEdits(DartChangeBuilder builder) {
SourceChange sourceChange = builder.sourceChange;
expect(sourceChange, isNotNull);
List<SourceFileEdit> fileEdits = sourceChange.edits;
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer_plugin/test/support/abstract_single_unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class AbstractSingleUnitTest extends AbstractContextTest {
* Returns the [SimpleIdentifier] at the given search pattern.
*/
SimpleIdentifier findIdentifier(String search) {
return findNodeAtString(search, (node) => node is SimpleIdentifier);
return findNodeAtString(search, (node) => node is SimpleIdentifier)
as SimpleIdentifier;
}

AstNode findNodeAtOffset(int offset, [Predicate<AstNode> predicate]) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer_plugin/test/support/mock_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const Map<String, LibraryInfo> libraries = const {

MockSdk(
{bool generateSummaryFiles: false,
resource.ResourceProvider resourceProvider})
resource.MemoryResourceProvider resourceProvider})
: provider = resourceProvider ?? new resource.MemoryResourceProvider() {
LIBRARIES.forEach((SdkLibrary library) {
provider.newFile(library.path, (library as MockSdkLibrary).content);
Expand Down
11 changes: 5 additions & 6 deletions pkg/analyzer_plugin/tool/spec/codegen_dart_protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
String fieldAccessor = 'json[$fieldNameString]';
String jsonPath = 'jsonPath + ${literalString('.${field.name}')}';
if (field.value != null) {
String valueString = literalString(field.value);
String valueString = literalString(field.value as String);
writeln('if ($fieldAccessor != $valueString) {');
indent(() {
writeln(
Expand Down Expand Up @@ -897,7 +897,8 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
for (TypeObjectField field in type.fields) {
String fieldNameString = literalString(field.name);
if (field.value != null) {
writeln('result[$fieldNameString] = ${literalString(field.value)};');
writeln(
'result[$fieldNameString] = ${literalString(field.value as String)};');
continue;
}
String fieldToJson = toJsonCode(field.type).asSnippet(field.name);
Expand Down Expand Up @@ -1066,7 +1067,7 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
'Each choice in the union needs a constant value for the field ${type.field}');
}
String closure = fromJsonCode(choice).asClosure;
decoders.add('${literalString(field.value)}: $closure');
decoders.add('${literalString(field.value as String)}: $closure');
} else {
throw new Exception('Union types must be unions of objects.');
}
Expand Down Expand Up @@ -1108,9 +1109,7 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
/**
* Create a string literal that evaluates to [s].
*/
String literalString(String s) {
return json.encode(s);
}
String literalString(String s) => json.encode(s);

/**
* Compute the code necessary to convert [type] to JSON.
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer_plugin/tool/spec/from_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ApiReader {
throw new Exception(
'$context: Unexpected attribute in ${element.localName}: $name');
}
attributesFound.add(name);
attributesFound.add(name as String);
});
for (String expectedAttribute in requiredAttributes) {
if (!attributesFound.contains(expectedAttribute)) {
Expand Down Expand Up @@ -296,7 +296,7 @@ class ApiReader {
if (valueType == null) {
throw new Exception('$context: Value type not specified');
}
types.add(new TypeMap(keyType, valueType, child));
types.add(new TypeMap(keyType as TypeReference, valueType, child));
},
'enum': (dom.Element child) {
types.add(typeEnumFromHtml(child, context));
Expand Down

0 comments on commit 6fc1dd4

Please sign in to comment.