| 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 library summary_resynthesizer; | 5 library summary_resynthesizer; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 serializedDocumentationComment.length); | 435 serializedDocumentationComment.length); |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 | 438 |
| 439 /** | 439 /** |
| 440 * Resynthesize the [ClassElement] corresponding to an enum, along with the | 440 * Resynthesize the [ClassElement] corresponding to an enum, along with the |
| 441 * associated fields and implicit accessors. | 441 * associated fields and implicit accessors. |
| 442 */ | 442 */ |
| 443 void buildEnum(UnlinkedEnum serializedEnum) { | 443 void buildEnum(UnlinkedEnum serializedEnum) { |
| 444 assert(!isCoreLibrary); | 444 assert(!isCoreLibrary); |
| 445 // TODO(paulberry): add offset support (for this element type and others) | |
| 446 ClassElementImpl classElement = | 445 ClassElementImpl classElement = |
| 447 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); | 446 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); |
| 448 classElement.enum2 = true; | 447 classElement.enum2 = true; |
| 449 InterfaceType enumType = new InterfaceTypeImpl(classElement); | 448 InterfaceType enumType = new InterfaceTypeImpl(classElement); |
| 450 classElement.type = enumType; | 449 classElement.type = enumType; |
| 451 classElement.supertype = summaryResynthesizer.typeProvider.objectType; | 450 classElement.supertype = summaryResynthesizer.typeProvider.objectType; |
| 452 buildDocumentation(classElement, serializedEnum.documentationComment); | 451 buildDocumentation(classElement, serializedEnum.documentationComment); |
| 453 ElementHolder memberHolder = new ElementHolder(); | 452 ElementHolder memberHolder = new ElementHolder(); |
| 454 FieldElementImpl indexField = new FieldElementImpl('index', -1); | 453 FieldElementImpl indexField = new FieldElementImpl('index', -1); |
| 455 indexField.final2 = true; | 454 indexField.final2 = true; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 FieldElementImpl field = buildImplicitField(name, type, kind, holder); | 541 FieldElementImpl field = buildImplicitField(name, type, kind, holder); |
| 543 field.static = serializedExecutable.isStatic; | 542 field.static = serializedExecutable.isStatic; |
| 544 implicitVariable = field; | 543 implicitVariable = field; |
| 545 } | 544 } |
| 546 executableElement.variable = implicitVariable; | 545 executableElement.variable = implicitVariable; |
| 547 if (kind == UnlinkedExecutableKind.getter) { | 546 if (kind == UnlinkedExecutableKind.getter) { |
| 548 implicitVariable.getter = executableElement; | 547 implicitVariable.getter = executableElement; |
| 549 } else { | 548 } else { |
| 550 implicitVariable.setter = executableElement; | 549 implicitVariable.setter = executableElement; |
| 551 } | 550 } |
| 552 // TODO(paulberry): do the right thing when getter and setter are in | |
| 553 // different units. | |
| 554 break; | 551 break; |
| 555 default: | 552 default: |
| 556 // The only other executable type is a constructor, and that is handled | 553 // The only other executable type is a constructor, and that is handled |
| 557 // separately (in [buildConstructor]. So this code should be | 554 // separately (in [buildConstructor]. So this code should be |
| 558 // unreachable. | 555 // unreachable. |
| 559 assert(false); | 556 assert(false); |
| 560 } | 557 } |
| 561 } | 558 } |
| 562 | 559 |
| 563 /** | 560 /** |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 variable.final2 = false; | 759 variable.final2 = false; |
| 763 return variable; | 760 return variable; |
| 764 } | 761 } |
| 765 } | 762 } |
| 766 | 763 |
| 767 /** | 764 /** |
| 768 * Resynthesize an [ImportElement]. | 765 * Resynthesize an [ImportElement]. |
| 769 */ | 766 */ |
| 770 ImportElement buildImport(UnlinkedImport serializedImport, int dependency) { | 767 ImportElement buildImport(UnlinkedImport serializedImport, int dependency) { |
| 771 bool isSynthetic = serializedImport.isImplicit; | 768 bool isSynthetic = serializedImport.isImplicit; |
| 772 // TODO(paulberry): it seems problematic for the offset to be 0 for | |
| 773 // non-synthetic imports, since it is used to disambiguate location. | |
| 774 ImportElementImpl importElement = | 769 ImportElementImpl importElement = |
| 775 new ImportElementImpl(isSynthetic ? -1 : serializedImport.offset); | 770 new ImportElementImpl(isSynthetic ? -1 : serializedImport.offset); |
| 776 String absoluteUri = summaryResynthesizer.sourceFactory | 771 String absoluteUri = summaryResynthesizer.sourceFactory |
| 777 .resolveUri(librarySource, linkedLibrary.dependencies[dependency].uri) | 772 .resolveUri(librarySource, linkedLibrary.dependencies[dependency].uri) |
| 778 .uri | 773 .uri |
| 779 .toString(); | 774 .toString(); |
| 780 importElement.importedLibrary = new LibraryElementHandle( | 775 importElement.importedLibrary = new LibraryElementHandle( |
| 781 summaryResynthesizer, | 776 summaryResynthesizer, |
| 782 new ElementLocationImpl.con3(<String>[absoluteUri])); | 777 new ElementLocationImpl.con3(<String>[absoluteUri])); |
| 783 if (isSynthetic) { | 778 if (isSynthetic) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 return VoidTypeImpl.instance; | 973 return VoidTypeImpl.instance; |
| 979 } else { | 974 } else { |
| 980 return summaryResynthesizer.typeProvider.dynamicType; | 975 return summaryResynthesizer.typeProvider.dynamicType; |
| 981 } | 976 } |
| 982 } | 977 } |
| 983 if (type.paramReference != 0) { | 978 if (type.paramReference != 0) { |
| 984 // TODO(paulberry): make this work for generic methods. | 979 // TODO(paulberry): make this work for generic methods. |
| 985 return currentTypeParameters[ | 980 return currentTypeParameters[ |
| 986 currentTypeParameters.length - type.paramReference].type; | 981 currentTypeParameters.length - type.paramReference].type; |
| 987 } else { | 982 } else { |
| 988 // TODO(paulberry): handle references to things other than classes (note: | |
| 989 // this should only occur in the case of erroneous code). | |
| 990 // TODO(paulberry): test reference to something inside a part. | |
| 991 // TODO(paulberry): test reference to something inside a part of the | |
| 992 // current lib. | |
| 993 LinkedReference referenceResolution = | 983 LinkedReference referenceResolution = |
| 994 linkedUnit.references[type.reference]; | 984 linkedUnit.references[type.reference]; |
| 995 String name; | 985 String name; |
| 996 if (type.reference < unlinkedUnit.references.length) { | 986 if (type.reference < unlinkedUnit.references.length) { |
| 997 name = unlinkedUnit.references[type.reference].name; | 987 name = unlinkedUnit.references[type.reference].name; |
| 998 } else { | 988 } else { |
| 999 name = referenceResolution.name; | 989 name = referenceResolution.name; |
| 1000 } | 990 } |
| 1001 ElementLocationImpl location; | 991 ElementLocationImpl location; |
| 1002 if (referenceResolution.dependency != 0) { | 992 if (referenceResolution.dependency != 0) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 for (PropertyAccessorElementImpl accessor in unit.accessors) { | 1215 for (PropertyAccessorElementImpl accessor in unit.accessors) { |
| 1226 elementMap[accessor.identifier] = accessor; | 1216 elementMap[accessor.identifier] = accessor; |
| 1227 } | 1217 } |
| 1228 resummarizedElements[absoluteUri] = elementMap; | 1218 resummarizedElements[absoluteUri] = elementMap; |
| 1229 unitHolder = null; | 1219 unitHolder = null; |
| 1230 linkedUnit = null; | 1220 linkedUnit = null; |
| 1231 unlinkedUnit = null; | 1221 unlinkedUnit = null; |
| 1232 linkedTypeMap = null; | 1222 linkedTypeMap = null; |
| 1233 } | 1223 } |
| 1234 } | 1224 } |
| OLD | NEW |