| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart' | 7 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 8 hide Element, ElementKind; | 8 hide Element, ElementKind; |
| 9 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_co
re.dart'; | 9 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_co
re.dart'; |
| 10 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_da
rt.dart'; | 10 import 'package:analysis_server/src/provisional/edit/utilities/change_builder_da
rt.dart'; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 {Iterable<DartType> interfaces, | 96 {Iterable<DartType> interfaces, |
| 97 bool isAbstract: false, | 97 bool isAbstract: false, |
| 98 void memberWriter(), | 98 void memberWriter(), |
| 99 Iterable<DartType> mixins, | 99 Iterable<DartType> mixins, |
| 100 String nameGroupName, | 100 String nameGroupName, |
| 101 DartType superclass, | 101 DartType superclass, |
| 102 String superclassGroupName}) { | 102 String superclassGroupName}) { |
| 103 // TODO(brianwilkerson) Add support for type parameters, probably as a | 103 // TODO(brianwilkerson) Add support for type parameters, probably as a |
| 104 // parameterWriter parameter. | 104 // parameterWriter parameter. |
| 105 if (isAbstract) { | 105 if (isAbstract) { |
| 106 write(Keyword.ABSTRACT.syntax); | 106 write(Keyword.ABSTRACT.lexeme); |
| 107 write(' '); | 107 write(' '); |
| 108 } | 108 } |
| 109 write('class '); | 109 write('class '); |
| 110 if (nameGroupName == null) { | 110 if (nameGroupName == null) { |
| 111 write(name); | 111 write(name); |
| 112 } else { | 112 } else { |
| 113 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { | 113 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { |
| 114 write(name); | 114 write(name); |
| 115 }); | 115 }); |
| 116 } | 116 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 @override | 134 @override |
| 135 void writeConstructorDeclaration(String className, | 135 void writeConstructorDeclaration(String className, |
| 136 {ArgumentList argumentList, | 136 {ArgumentList argumentList, |
| 137 SimpleIdentifier constructorName, | 137 SimpleIdentifier constructorName, |
| 138 String constructorNameGroupName, | 138 String constructorNameGroupName, |
| 139 List<String> fieldNames, | 139 List<String> fieldNames, |
| 140 bool isConst: false}) { | 140 bool isConst: false}) { |
| 141 if (isConst) { | 141 if (isConst) { |
| 142 write(Keyword.CONST.syntax); | 142 write(Keyword.CONST.lexeme); |
| 143 write(' '); | 143 write(' '); |
| 144 } | 144 } |
| 145 write(className); | 145 write(className); |
| 146 if (constructorName != null) { | 146 if (constructorName != null) { |
| 147 write('.'); | 147 write('.'); |
| 148 if (constructorNameGroupName == null) { | 148 if (constructorNameGroupName == null) { |
| 149 write(constructorName.name); | 149 write(constructorName.name); |
| 150 } else { | 150 } else { |
| 151 addLinkedEdit(constructorNameGroupName, (LinkedEditBuilder builder) { | 151 addLinkedEdit(constructorNameGroupName, (LinkedEditBuilder builder) { |
| 152 write(constructorName.name); | 152 write(constructorName.name); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 171 @override | 171 @override |
| 172 void writeFieldDeclaration(String name, | 172 void writeFieldDeclaration(String name, |
| 173 {void initializerWriter(), | 173 {void initializerWriter(), |
| 174 bool isConst: false, | 174 bool isConst: false, |
| 175 bool isFinal: false, | 175 bool isFinal: false, |
| 176 bool isStatic: false, | 176 bool isStatic: false, |
| 177 String nameGroupName, | 177 String nameGroupName, |
| 178 DartType type, | 178 DartType type, |
| 179 String typeGroupName}) { | 179 String typeGroupName}) { |
| 180 if (isStatic) { | 180 if (isStatic) { |
| 181 write(Keyword.STATIC.syntax); | 181 write(Keyword.STATIC.lexeme); |
| 182 write(' '); | 182 write(' '); |
| 183 } | 183 } |
| 184 bool typeRequired = true; | 184 bool typeRequired = true; |
| 185 if (isConst) { | 185 if (isConst) { |
| 186 write(Keyword.CONST.syntax); | 186 write(Keyword.CONST.lexeme); |
| 187 typeRequired = false; | 187 typeRequired = false; |
| 188 } else if (isFinal) { | 188 } else if (isFinal) { |
| 189 write(Keyword.FINAL.syntax); | 189 write(Keyword.FINAL.lexeme); |
| 190 typeRequired = false; | 190 typeRequired = false; |
| 191 } | 191 } |
| 192 if (type != null) { | 192 if (type != null) { |
| 193 writeType(type, groupName: typeGroupName, required: true); | 193 writeType(type, groupName: typeGroupName, required: true); |
| 194 } else if (typeRequired) { | 194 } else if (typeRequired) { |
| 195 write(Keyword.VAR.syntax); | 195 write(Keyword.VAR.lexeme); |
| 196 } | 196 } |
| 197 write(' '); | 197 write(' '); |
| 198 if (nameGroupName != null) { | 198 if (nameGroupName != null) { |
| 199 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { | 199 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { |
| 200 write(name); | 200 write(name); |
| 201 }); | 201 }); |
| 202 } else { | 202 } else { |
| 203 write(name); | 203 write(name); |
| 204 } | 204 } |
| 205 if (initializerWriter != null) { | 205 if (initializerWriter != null) { |
| 206 write(' = '); | 206 write(' = '); |
| 207 initializerWriter(); | 207 initializerWriter(); |
| 208 } | 208 } |
| 209 write(';'); | 209 write(';'); |
| 210 } | 210 } |
| 211 | 211 |
| 212 @override | 212 @override |
| 213 void writeFunctionDeclaration(String name, | 213 void writeFunctionDeclaration(String name, |
| 214 {void bodyWriter(), | 214 {void bodyWriter(), |
| 215 bool isStatic: false, | 215 bool isStatic: false, |
| 216 String nameGroupName, | 216 String nameGroupName, |
| 217 void parameterWriter(), | 217 void parameterWriter(), |
| 218 DartType returnType, | 218 DartType returnType, |
| 219 String returnTypeGroupName}) { | 219 String returnTypeGroupName}) { |
| 220 if (isStatic) { | 220 if (isStatic) { |
| 221 write(Keyword.STATIC.syntax); | 221 write(Keyword.STATIC.lexeme); |
| 222 write(' '); | 222 write(' '); |
| 223 } | 223 } |
| 224 if (returnType != null) { | 224 if (returnType != null) { |
| 225 writeType(returnType, groupName: returnTypeGroupName); | 225 writeType(returnType, groupName: returnTypeGroupName); |
| 226 write(' '); | 226 write(' '); |
| 227 } | 227 } |
| 228 if (nameGroupName != null) { | 228 if (nameGroupName != null) { |
| 229 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { | 229 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { |
| 230 write(name); | 230 write(name); |
| 231 }); | 231 }); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 @override | 252 @override |
| 253 void writeGetterDeclaration(String name, | 253 void writeGetterDeclaration(String name, |
| 254 {void bodyWriter(), | 254 {void bodyWriter(), |
| 255 bool isStatic: false, | 255 bool isStatic: false, |
| 256 String nameGroupName, | 256 String nameGroupName, |
| 257 DartType returnType, | 257 DartType returnType, |
| 258 String returnTypeGroupName}) { | 258 String returnTypeGroupName}) { |
| 259 if (isStatic) { | 259 if (isStatic) { |
| 260 write(Keyword.STATIC.syntax); | 260 write(Keyword.STATIC.lexeme); |
| 261 write(' '); | 261 write(' '); |
| 262 } | 262 } |
| 263 if (returnType != null && !returnType.isDynamic) { | 263 if (returnType != null && !returnType.isDynamic) { |
| 264 writeType(returnType, groupName: returnTypeGroupName); | 264 writeType(returnType, groupName: returnTypeGroupName); |
| 265 write(' '); | 265 write(' '); |
| 266 } | 266 } |
| 267 write(Keyword.GET.syntax); | 267 write(Keyword.GET.lexeme); |
| 268 write(' '); | 268 write(' '); |
| 269 if (nameGroupName != null) { | 269 if (nameGroupName != null) { |
| 270 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { | 270 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { |
| 271 write(name); | 271 write(name); |
| 272 }); | 272 }); |
| 273 } else { | 273 } else { |
| 274 write(name); | 274 write(name); |
| 275 } | 275 } |
| 276 if (bodyWriter == null) { | 276 if (bodyWriter == null) { |
| 277 write(' => null;'); | 277 write(' => null;'); |
| 278 } else { | 278 } else { |
| 279 write(' '); | 279 write(' '); |
| 280 bodyWriter(); | 280 bodyWriter(); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 @override | 284 @override |
| 285 void writeLocalVariableDeclaration(String name, | 285 void writeLocalVariableDeclaration(String name, |
| 286 {void initializerWriter(), | 286 {void initializerWriter(), |
| 287 bool isConst: false, | 287 bool isConst: false, |
| 288 bool isFinal: false, | 288 bool isFinal: false, |
| 289 String nameGroupName, | 289 String nameGroupName, |
| 290 DartType type, | 290 DartType type, |
| 291 String typeGroupName}) { | 291 String typeGroupName}) { |
| 292 bool typeRequired = true; | 292 bool typeRequired = true; |
| 293 if (isConst) { | 293 if (isConst) { |
| 294 write(Keyword.CONST.syntax); | 294 write(Keyword.CONST.lexeme); |
| 295 typeRequired = false; | 295 typeRequired = false; |
| 296 } else if (isFinal) { | 296 } else if (isFinal) { |
| 297 write(Keyword.FINAL.syntax); | 297 write(Keyword.FINAL.lexeme); |
| 298 typeRequired = false; | 298 typeRequired = false; |
| 299 } | 299 } |
| 300 if (type != null) { | 300 if (type != null) { |
| 301 if (!typeRequired) { | 301 if (!typeRequired) { |
| 302 // The type is required unless we're written a keyword. | 302 // The type is required unless we're written a keyword. |
| 303 write(' '); | 303 write(' '); |
| 304 } | 304 } |
| 305 writeType(type, groupName: typeGroupName); | 305 writeType(type, groupName: typeGroupName); |
| 306 } else if (typeRequired) { | 306 } else if (typeRequired) { |
| 307 write(Keyword.VAR.syntax); | 307 write(Keyword.VAR.lexeme); |
| 308 } | 308 } |
| 309 write(' '); | 309 write(' '); |
| 310 if (nameGroupName != null) { | 310 if (nameGroupName != null) { |
| 311 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { | 311 addLinkedEdit(nameGroupName, (LinkedEditBuilder builder) { |
| 312 write(name); | 312 write(name); |
| 313 }); | 313 }); |
| 314 } else { | 314 } else { |
| 315 write(name); | 315 write(name); |
| 316 } | 316 } |
| 317 if (initializerWriter != null) { | 317 if (initializerWriter != null) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 339 write(prefix); | 339 write(prefix); |
| 340 } | 340 } |
| 341 // @override | 341 // @override |
| 342 writeln('@override'); | 342 writeln('@override'); |
| 343 write(prefix); | 343 write(prefix); |
| 344 // return type | 344 // return type |
| 345 bool shouldReturn = | 345 bool shouldReturn = |
| 346 writeType(member.type.returnType, groupName: returnTypeGroupName); | 346 writeType(member.type.returnType, groupName: returnTypeGroupName); |
| 347 write(' '); | 347 write(' '); |
| 348 if (isGetter) { | 348 if (isGetter) { |
| 349 write(Keyword.GET.syntax); | 349 write(Keyword.GET.lexeme); |
| 350 write(' '); | 350 write(' '); |
| 351 } else if (isSetter) { | 351 } else if (isSetter) { |
| 352 write(Keyword.SET.syntax); | 352 write(Keyword.SET.lexeme); |
| 353 write(' '); | 353 write(' '); |
| 354 } else if (isOperator) { | 354 } else if (isOperator) { |
| 355 write(Keyword.OPERATOR.syntax); | 355 write(Keyword.OPERATOR.lexeme); |
| 356 write(' '); | 356 write(' '); |
| 357 } | 357 } |
| 358 // name | 358 // name |
| 359 write(member.displayName); | 359 write(member.displayName); |
| 360 // parameters + body | 360 // parameters + body |
| 361 if (isGetter) { | 361 if (isGetter) { |
| 362 writeln(' => null;'); | 362 writeln(' => null;'); |
| 363 } else { | 363 } else { |
| 364 List<ParameterElement> parameters = member.parameters; | 364 List<ParameterElement> parameters = member.parameters; |
| 365 writeParameters(parameters); | 365 writeParameters(parameters); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 _addSuperTypeProposals(builder, type, new Set<DartType>()); | 494 _addSuperTypeProposals(builder, type, new Set<DartType>()); |
| 495 } | 495 } |
| 496 }); | 496 }); |
| 497 } else { | 497 } else { |
| 498 write(typeSource); | 498 write(typeSource); |
| 499 } | 499 } |
| 500 return true; | 500 return true; |
| 501 } | 501 } |
| 502 } | 502 } |
| 503 if (required) { | 503 if (required) { |
| 504 write(Keyword.VAR.syntax); | 504 write(Keyword.VAR.lexeme); |
| 505 return true; | 505 return true; |
| 506 } | 506 } |
| 507 return false; | 507 return false; |
| 508 } | 508 } |
| 509 | 509 |
| 510 @override | 510 @override |
| 511 void writeTypeParameter(TypeParameterElement typeParameter) { | 511 void writeTypeParameter(TypeParameterElement typeParameter) { |
| 512 write(typeParameter.name); | 512 write(typeParameter.name); |
| 513 if (typeParameter.bound != null) { | 513 if (typeParameter.bound != null) { |
| 514 write(' extends '); | 514 write(' extends '); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 void _addSuperTypesAsSuggestions(DartType type, Set<DartType> alreadyAdded) { | 718 void _addSuperTypesAsSuggestions(DartType type, Set<DartType> alreadyAdded) { |
| 719 if (type is InterfaceType && alreadyAdded.add(type)) { | 719 if (type is InterfaceType && alreadyAdded.add(type)) { |
| 720 addSuggestion(LinkedEditSuggestionKind.TYPE, type.displayName); | 720 addSuggestion(LinkedEditSuggestionKind.TYPE, type.displayName); |
| 721 _addSuperTypesAsSuggestions(type.superclass, alreadyAdded); | 721 _addSuperTypesAsSuggestions(type.superclass, alreadyAdded); |
| 722 for (InterfaceType interfaceType in type.interfaces) { | 722 for (InterfaceType interfaceType in type.interfaces) { |
| 723 _addSuperTypesAsSuggestions(interfaceType, alreadyAdded); | 723 _addSuperTypesAsSuggestions(interfaceType, alreadyAdded); |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 } | 726 } |
| 727 } | 727 } |
| OLD | NEW |