| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library codegen.protocol; | 5 library codegen.protocol; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'api.dart'; | 9 import 'api.dart'; |
| 10 import 'codegen_dart.dart'; | 10 import 'codegen_dart.dart'; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 }); | 343 }); |
| 344 writeln('}'); | 344 writeln('}'); |
| 345 } | 345 } |
| 346 | 346 |
| 347 /** | 347 /** |
| 348 * If the class named [className] requires special static members, emit them | 348 * If the class named [className] requires special static members, emit them |
| 349 * and return true. | 349 * and return true. |
| 350 */ | 350 */ |
| 351 bool emitSpecialStaticMembers(String className) { | 351 bool emitSpecialStaticMembers(String className) { |
| 352 switch (className) { | 352 switch (className) { |
| 353 case 'AnalysisError': | |
| 354 docComment( | |
| 355 [ | |
| 356 new dom.Text( | |
| 357 'Returns a list of AnalysisErrors ' + | |
| 358 'correponding to the given list of Engine errors.')]); | |
| 359 writeln( | |
| 360 'static List<AnalysisError> listFromEngine(engine.LineInfo lineInfo,
List<engine.AnalysisError> errors) =>'); | |
| 361 writeln(' _analysisErrorListFromEngine(lineInfo, errors);'); | |
| 362 return true; | |
| 363 case 'Element': | 353 case 'Element': |
| 364 List<String> makeFlagsArgs = <String>[]; | 354 List<String> makeFlagsArgs = <String>[]; |
| 365 List<String> makeFlagsStatements = <String>[]; | 355 List<String> makeFlagsStatements = <String>[]; |
| 366 specialElementFlags.forEach((String name, String value) { | 356 specialElementFlags.forEach((String name, String value) { |
| 367 String flag = 'FLAG_${name.toUpperCase()}'; | 357 String flag = 'FLAG_${name.toUpperCase()}'; |
| 368 String camelName = camelJoin(['is', name]); | 358 String camelName = camelJoin(['is', name]); |
| 369 writeln('static const int $flag = $value;'); | 359 writeln('static const int $flag = $value;'); |
| 370 makeFlagsArgs.add('$camelName: false'); | 360 makeFlagsArgs.add('$camelName: false'); |
| 371 makeFlagsStatements.add('if ($camelName) flags |= $flag;'); | 361 makeFlagsStatements.add('if ($camelName) flags |= $flag;'); |
| 372 }); | 362 }); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 396 return false; | 386 return false; |
| 397 } | 387 } |
| 398 } | 388 } |
| 399 | 389 |
| 400 /** | 390 /** |
| 401 * If the class named [className] requires special constructors, emit them | 391 * If the class named [className] requires special constructors, emit them |
| 402 * and return true. | 392 * and return true. |
| 403 */ | 393 */ |
| 404 bool emitSpecialConstructors(String className) { | 394 bool emitSpecialConstructors(String className) { |
| 405 switch (className) { | 395 switch (className) { |
| 406 case 'AnalysisError': | |
| 407 docComment( | |
| 408 [ | |
| 409 new dom.Text( | |
| 410 'Construct based on error information from the analyzer engi
ne.')]); | |
| 411 writeln( | |
| 412 'factory AnalysisError.fromEngine(engine.LineInfo lineInfo, engine.A
nalysisError error) =>'); | |
| 413 writeln(' _analysisErrorFromEngine(lineInfo, error);'); | |
| 414 return true; | |
| 415 case 'CompletionSuggestionKind': | |
| 416 docComment( | |
| 417 [new dom.Text('Construct from an analyzer engine element kind.')]); | |
| 418 writeln( | |
| 419 'factory CompletionSuggestionKind.fromElementKind(engine.ElementKind
kind) =>'); | |
| 420 writeln(' _completionSuggestionKindFromElementKind(kind);'); | |
| 421 return true; | |
| 422 case 'Element': | |
| 423 docComment( | |
| 424 [new dom.Text('Construct based on a value from the analyzer engine.'
)]); | |
| 425 writeln('factory Element.fromEngine(engine.Element element) =>'); | |
| 426 writeln(' elementFromEngine(element);'); | |
| 427 return true; | |
| 428 case 'ElementKind': | |
| 429 docComment( | |
| 430 [new dom.Text('Construct based on a value from the analyzer engine.'
)]); | |
| 431 writeln('factory ElementKind.fromEngine(engine.ElementKind kind) =>'); | |
| 432 writeln(' _elementKindFromEngine(kind);'); | |
| 433 return true; | |
| 434 case 'LinkedEditGroup': | 396 case 'LinkedEditGroup': |
| 435 docComment([new dom.Text('Construct an empty LinkedEditGroup.')]); | 397 docComment([new dom.Text('Construct an empty LinkedEditGroup.')]); |
| 436 writeln( | 398 writeln( |
| 437 'LinkedEditGroup.empty() : this(<Position>[], 0, <LinkedEditSuggesti
on>[]);'); | 399 'LinkedEditGroup.empty() : this(<Position>[], 0, <LinkedEditSuggesti
on>[]);'); |
| 438 return true; | 400 return true; |
| 439 case 'Location': | |
| 440 docComment( | |
| 441 [new dom.Text('Create a Location based on an [engine.Element].')]); | |
| 442 writeln('factory Location.fromElement(engine.Element element) =>'); | |
| 443 writeln(' _locationFromElement(element);'); | |
| 444 writeln(); | |
| 445 docComment( | |
| 446 [new dom.Text('Create a Location based on an [engine.SearchMatch].')
]); | |
| 447 writeln('factory Location.fromMatch(engine.SearchMatch match) =>'); | |
| 448 writeln(' _locationFromMatch(match);'); | |
| 449 writeln(); | |
| 450 docComment( | |
| 451 [new dom.Text('Create a Location based on an [engine.AstNode].')]); | |
| 452 writeln('factory Location.fromNode(engine.AstNode node) =>'); | |
| 453 writeln(' _locationFromNode(node);'); | |
| 454 writeln(); | |
| 455 docComment( | |
| 456 [new dom.Text('Create a Location based on an [engine.CompilationUnit
].')]); | |
| 457 writeln( | |
| 458 'factory Location.fromUnit(engine.CompilationUnit unit, engine.Sourc
eRange range) =>'); | |
| 459 writeln(' _locationFromUnit(unit, range);'); | |
| 460 return true; | |
| 461 case 'OverriddenMember': | |
| 462 docComment( | |
| 463 [new dom.Text('Construct based on an element from the analyzer engin
e.')]); | |
| 464 writeln( | |
| 465 'factory OverriddenMember.fromEngine(engine.Element member) =>'); | |
| 466 writeln(' _overriddenMemberFromEngine(member);'); | |
| 467 return true; | |
| 468 case 'RefactoringProblemSeverity': | 401 case 'RefactoringProblemSeverity': |
| 469 docComment( | 402 docComment( |
| 470 [ | 403 [ |
| 471 new dom.Text( | 404 new dom.Text( |
| 472 'Returns the [RefactoringProblemSeverity] with the maximal s
everity.')]); | 405 'Returns the [RefactoringProblemSeverity] with the maximal s
everity.')]); |
| 473 writeln( | 406 writeln( |
| 474 'static RefactoringProblemSeverity max(RefactoringProblemSeverity a,
RefactoringProblemSeverity b) =>'); | 407 'static RefactoringProblemSeverity max(RefactoringProblemSeverity a,
RefactoringProblemSeverity b) =>'); |
| 475 writeln(' _maxRefactoringProblemSeverity(a, b);'); | 408 writeln(' _maxRefactoringProblemSeverity(a, b);'); |
| 476 return true; | 409 return true; |
| 477 case 'SearchResult': | |
| 478 docComment( | |
| 479 [new dom.Text('Construct based on a value from the search engine.')]
); | |
| 480 writeln('factory SearchResult.fromMatch(engine.SearchMatch match) =>'); | |
| 481 writeln(' searchResultFromMatch(match);'); | |
| 482 return true; | |
| 483 case 'SearchResultKind': | |
| 484 docComment( | |
| 485 [new dom.Text('Construct based on a value from the search engine.')]
); | |
| 486 writeln( | |
| 487 'factory SearchResultKind.fromEngine(engine.MatchKind kind) =>'); | |
| 488 writeln(' _searchResultKindFromEngine(kind);'); | |
| 489 return true; | |
| 490 case 'SourceEdit': | |
| 491 docComment([new dom.Text('Construct based on a SourceRange.')]); | |
| 492 writeln( | |
| 493 'SourceEdit.range(engine.SourceRange range, String replacement, {Str
ing id})'); | |
| 494 writeln(' : this(range.offset, range.length, replacement, id: id);'); | |
| 495 return true; | |
| 496 default: | 410 default: |
| 497 return false; | 411 return false; |
| 498 } | 412 } |
| 499 } | 413 } |
| 500 | 414 |
| 501 /** | 415 /** |
| 502 * If the class named [className] requires special getters, emit them and | 416 * If the class named [className] requires special getters, emit them and |
| 503 * return true. | 417 * return true. |
| 504 */ | 418 */ |
| 505 bool emitSpecialGetters(String className) { | 419 bool emitSpecialGetters(String className) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 519 return false; | 433 return false; |
| 520 } | 434 } |
| 521 } | 435 } |
| 522 | 436 |
| 523 /** | 437 /** |
| 524 * If the class named [className] requires special methods, emit them and | 438 * If the class named [className] requires special methods, emit them and |
| 525 * return true. | 439 * return true. |
| 526 */ | 440 */ |
| 527 bool emitSpecialMethods(String className) { | 441 bool emitSpecialMethods(String className) { |
| 528 switch (className) { | 442 switch (className) { |
| 529 case 'AnalysisErrorFixes': | |
| 530 docComment([new dom.Text('Add a [Fix]')]); | |
| 531 writeln('void addFix(Fix fix) {'); | |
| 532 indent(() { | |
| 533 writeln('fixes.add(fix.change);'); | |
| 534 }); | |
| 535 writeln('}'); | |
| 536 return true; | |
| 537 case 'LinkedEditGroup': | 443 case 'LinkedEditGroup': |
| 538 docComment([new dom.Text('Add a new position and change the length.')]); | 444 docComment([new dom.Text('Add a new position and change the length.')]); |
| 539 writeln('void addPosition(Position position, int length) {'); | 445 writeln('void addPosition(Position position, int length) {'); |
| 540 indent(() { | 446 indent(() { |
| 541 writeln('positions.add(position);'); | 447 writeln('positions.add(position);'); |
| 542 writeln('this.length = length;'); | 448 writeln('this.length = length;'); |
| 543 }); | 449 }); |
| 544 writeln('}'); | 450 writeln('}'); |
| 545 writeln(); | 451 writeln(); |
| 546 docComment([new dom.Text('Add a new suggestion.')]); | 452 docComment([new dom.Text('Add a new suggestion.')]); |
| 547 writeln('void addSuggestion(LinkedEditSuggestion suggestion) {'); | 453 writeln('void addSuggestion(LinkedEditSuggestion suggestion) {'); |
| 548 indent(() { | 454 indent(() { |
| 549 writeln('suggestions.add(suggestion);'); | 455 writeln('suggestions.add(suggestion);'); |
| 550 }); | 456 }); |
| 551 writeln('}'); | 457 writeln('}'); |
| 552 return true; | 458 return true; |
| 553 case 'SourceChange': | 459 case 'SourceChange': |
| 554 docComment( | 460 docComment( |
| 555 [new dom.Text('Adds [edit] to the [FileEdit] for the given [file].')
]); | 461 [new dom.Text('Adds [edit] to the [FileEdit] for the given [file].')
]); |
| 556 writeln('void addEdit(String file, int fileStamp, SourceEdit edit) =>'); | 462 writeln('void addEdit(String file, int fileStamp, SourceEdit edit) =>'); |
| 557 writeln(' _addEditToSourceChange(this, file, fileStamp, edit);'); | 463 writeln(' _addEditToSourceChange(this, file, fileStamp, edit);'); |
| 558 writeln(); | 464 writeln(); |
| 559 docComment( | |
| 560 [new dom.Text('Adds [edit] to the [FileEdit] for the given [source].
')]); | |
| 561 writeln('void addSourceEdit(engine.AnalysisContext context,'); | |
| 562 writeln(' engine.Source source, SourceEdit edit) =>'); | |
| 563 writeln( | |
| 564 ' _addSourceEditToSourceChange(this, context, source, edit);'); | |
| 565 writeln(); | |
| 566 docComment( | |
| 567 [new dom.Text('Adds [edit] to the [FileEdit] for the given [element]
.')]); | |
| 568 writeln( | |
| 569 'void addElementEdit(engine.Element element, SourceEdit edit) =>'); | |
| 570 writeln(' _addElementEditToSourceChange(this, element, edit);'); | |
| 571 writeln(); | |
| 572 docComment([new dom.Text('Adds the given [FileEdit].')]); | 465 docComment([new dom.Text('Adds the given [FileEdit].')]); |
| 573 writeln('void addFileEdit(SourceFileEdit edit) {'); | 466 writeln('void addFileEdit(SourceFileEdit edit) {'); |
| 574 indent(() { | 467 indent(() { |
| 575 writeln('edits.add(edit);'); | 468 writeln('edits.add(edit);'); |
| 576 }); | 469 }); |
| 577 writeln('}'); | 470 writeln('}'); |
| 578 writeln(); | 471 writeln(); |
| 579 docComment([new dom.Text('Adds the given [LinkedEditGroup].')]); | 472 docComment([new dom.Text('Adds the given [LinkedEditGroup].')]); |
| 580 writeln('void addLinkedEditGroup(LinkedEditGroup linkedEditGroup) {'); | 473 writeln('void addLinkedEditGroup(LinkedEditGroup linkedEditGroup) {'); |
| 581 indent(() { | 474 indent(() { |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 CodegenProtocolVisitor visitor = new CodegenProtocolVisitor(readApi()); | 1173 CodegenProtocolVisitor visitor = new CodegenProtocolVisitor(readApi()); |
| 1281 return visitor.collectCode(visitor.visitApi); | 1174 return visitor.collectCode(visitor.visitApi); |
| 1282 }); | 1175 }); |
| 1283 | 1176 |
| 1284 /** | 1177 /** |
| 1285 * Translate spec_input.html into protocol_matchers.dart. | 1178 * Translate spec_input.html into protocol_matchers.dart. |
| 1286 */ | 1179 */ |
| 1287 main() { | 1180 main() { |
| 1288 target.generate(); | 1181 target.generate(); |
| 1289 } | 1182 } |
| OLD | NEW |