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

Unified Diff: pkg/analysis_server/lib/src/computer/computer_outline.dart

Issue 1941793002: Use null aware operators to clean up code (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/computer/computer_outline.dart
diff --git a/pkg/analysis_server/lib/src/computer/computer_outline.dart b/pkg/analysis_server/lib/src/computer/computer_outline.dart
index 860388463d1c8f2aa8c066e583ddf0042fb7f95b..a89ff0230fe1e4c188c47a6d39ee3defed6e7d92 100644
--- a/pkg/analysis_server/lib/src/computer/computer_outline.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_outline.dart
@@ -41,8 +41,7 @@ class DartUnitOutlineComputer {
VariableDeclarationList fields = fieldDeclaration.fields;
if (fields != null) {
TypeName fieldType = fields.type;
- String fieldTypeName =
- fieldType != null ? fieldType.toSource() : '';
+ String fieldTypeName = _safeToSource(fieldType);
for (VariableDeclaration field in fields.variables) {
classContents.add(_newVariableOutline(fieldTypeName,
ElementKind.FIELD, field, fieldDeclaration.isStatic));
@@ -69,7 +68,7 @@ class DartUnitOutlineComputer {
VariableDeclarationList fields = fieldDeclaration.variables;
if (fields != null) {
TypeName fieldType = fields.type;
- String fieldTypeName = fieldType != null ? fieldType.toSource() : '';
+ String fieldTypeName = _safeToSource(fieldType);
for (VariableDeclaration field in fields.variables) {
unitContents.add(_newVariableOutline(
fieldTypeName, ElementKind.TOP_LEVEL_VARIABLE, field, false));
@@ -207,7 +206,7 @@ class DartUnitOutlineComputer {
}
_SourceRegion sourceRegion = _getSourceRegion(constructor);
FormalParameterList parameters = constructor.parameters;
- String parametersStr = parameters != null ? parameters.toSource() : '';
+ String parametersStr = _safeToSource(parameters);
Element element = new Element(
ElementKind.CONSTRUCTOR,
name,
@@ -266,8 +265,8 @@ class DartUnitOutlineComputer {
kind = ElementKind.FUNCTION;
}
_SourceRegion sourceRegion = _getSourceRegion(function);
- String parametersStr = parameters != null ? parameters.toSource() : '';
- String returnTypeStr = returnType != null ? returnType.toSource() : '';
+ String parametersStr = _safeToSource(parameters);
+ String returnTypeStr = _safeToSource(returnType);
Element element = new Element(
kind,
name,
@@ -291,8 +290,8 @@ class DartUnitOutlineComputer {
String name = nameNode.name;
_SourceRegion sourceRegion = _getSourceRegion(node);
FormalParameterList parameters = node.parameters;
- String parametersStr = parameters != null ? parameters.toSource() : '';
- String returnTypeStr = returnType != null ? returnType.toSource() : '';
+ String parametersStr = _safeToSource(parameters);
+ String returnTypeStr = _safeToSource(returnType);
Element element = new Element(
ElementKind.FUNCTION_TYPE_ALIAS,
name,
@@ -320,8 +319,8 @@ class DartUnitOutlineComputer {
kind = ElementKind.METHOD;
}
_SourceRegion sourceRegion = _getSourceRegion(method);
- String parametersStr = parameters != null ? parameters.toSource() : null;
- String returnTypeStr = returnType != null ? returnType.toSource() : '';
+ String parametersStr = parameters?.toSource();
+ String returnTypeStr = _safeToSource(returnType);
Element element = new Element(
kind,
name,
@@ -383,6 +382,9 @@ class DartUnitOutlineComputer {
engine.Element element = declaration.element;
return element != null && element.isDeprecated;
}
+
+ static String _safeToSource(AstNode node) =>
+ node == null ? '' : node.toSource();
scheglov 2016/05/02 15:22:43 node?.toSource() ?? '' Not that it is much better
Brian Wilkerson 2016/05/02 15:28:09 Is that better? Looks to me like this would incur
scheglov 2016/05/02 15:29:57 You're right, it isn't better.
}
/**

Powered by Google App Engine
This is Rietveld 408576698