Chromium Code Reviews| Index: pkg/analysis_server/lib/src/services/correction/util.dart |
| diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart |
| index a14fb8ab759345dbf5210d2cd7cb27bbff3b34ea..0745ea57c0e98fd72c43f95595a4410b29f97ad8 100644 |
| --- a/pkg/analysis_server/lib/src/services/correction/util.dart |
| +++ b/pkg/analysis_server/lib/src/services/correction/util.dart |
| @@ -534,6 +534,12 @@ Expression stepUpNamedExpression(Expression expression) { |
| class CorrectionUtils { |
| final CompilationUnit unit; |
| + /** |
| + * The [ClassElement] the generated code is inserted to, so we can decide if |
| + * a type parameter may or may not be used. |
| + */ |
| + ClassElement targetClassElement; |
| + |
| LibraryElement _library; |
| String _buffer; |
| String _endOfLine; |
| @@ -877,7 +883,8 @@ class CorrectionUtils { |
| // return type |
| DartType returnType = functionType.returnType; |
| if (returnType != null && !returnType.isDynamic) { |
| - sb.write(getTypeSource(returnType, librariesToImport)); |
| + String returnTypeSource = getTypeSource(returnType, librariesToImport); |
| + sb.write(returnTypeSource); |
| sb.write(' '); |
| } |
| // parameter name |
| @@ -965,14 +972,13 @@ class CorrectionUtils { |
| List<DartType> arguments = type.typeArguments; |
| // check if has arguments |
| bool hasArguments = false; |
| + bool allArgumentsVisible = true; |
| for (DartType argument in arguments) { |
| - if (!argument.isDynamic) { |
| - hasArguments = true; |
| - break; |
| - } |
| + hasArguments = hasArguments || !argument.isDynamic; |
| + allArgumentsVisible = allArgumentsVisible && _isTypeVisible(argument); |
| } |
| // append type arguments |
| - if (hasArguments) { |
| + if (hasArguments && allArgumentsVisible) { |
| sb.write("<"); |
| for (int i = 0; i < arguments.length; i++) { |
| DartType argument = arguments[i]; |
| @@ -990,6 +996,19 @@ class CorrectionUtils { |
| } |
| /** |
| + * Checks if [type] is visible at [targetOffset]. |
| + */ |
| + bool _isTypeVisible(DartType type) { |
| + // TODO(scheglov) |
|
Brian Wilkerson
2014/12/15 23:29:15
What's left to do?
|
| + if (type is TypeParameterType) { |
| + TypeParameterElement parameterElement = type.element; |
| + Element parameterClassElement = parameterElement.enclosingElement; |
| + return identical(parameterClassElement, targetClassElement); |
| + } |
| + return true; |
| + } |
| + |
| + /** |
| * Indents given source left or right. |
| */ |
| String indentSourceLeftRight(String source, bool right) { |