| 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 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/element_handle.dart'; | 9 import 'package:analyzer/src/generated/element_handle.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 void buildClass(UnlinkedClass serializedClass) { | 239 void buildClass(UnlinkedClass serializedClass) { |
| 240 try { | 240 try { |
| 241 currentTypeParameters = | 241 currentTypeParameters = |
| 242 serializedClass.typeParameters.map(buildTypeParameter).toList(); | 242 serializedClass.typeParameters.map(buildTypeParameter).toList(); |
| 243 for (int i = 0; i < serializedClass.typeParameters.length; i++) { | 243 for (int i = 0; i < serializedClass.typeParameters.length; i++) { |
| 244 finishTypeParameter( | 244 finishTypeParameter( |
| 245 serializedClass.typeParameters[i], currentTypeParameters[i]); | 245 serializedClass.typeParameters[i], currentTypeParameters[i]); |
| 246 } | 246 } |
| 247 ClassElementImpl classElement = | 247 ClassElementImpl classElement = |
| 248 new ClassElementImpl(serializedClass.name, -1); | 248 new ClassElementImpl(serializedClass.name, -1); |
| 249 if (serializedClass.isMixinApplication) { | 249 classElement.mixinApplication = serializedClass.isMixinApplication; |
| 250 classElement.setModifier(Modifier.MIXIN_APPLICATION, true); | |
| 251 } | |
| 252 InterfaceTypeImpl correspondingType = new InterfaceTypeImpl(classElement); | 250 InterfaceTypeImpl correspondingType = new InterfaceTypeImpl(classElement); |
| 253 if (serializedClass.supertype != null) { | 251 if (serializedClass.supertype != null) { |
| 254 classElement.supertype = buildType(serializedClass.supertype); | 252 classElement.supertype = buildType(serializedClass.supertype); |
| 255 } else { | 253 } else { |
| 256 // TODO(paulberry): don't make Object point to itself. | 254 // TODO(paulberry): don't make Object point to itself. |
| 257 classElement.supertype = summaryResynthesizer.typeProvider.objectType; | 255 classElement.supertype = summaryResynthesizer.typeProvider.objectType; |
| 258 } | 256 } |
| 259 classElement.interfaces = | 257 classElement.interfaces = |
| 260 serializedClass.interfaces.map(buildType).toList(); | 258 serializedClass.interfaces.map(buildType).toList(); |
| 261 classElement.mixins = serializedClass.mixins.map(buildType).toList(); | 259 classElement.mixins = serializedClass.mixins.map(buildType).toList(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 277 } | 275 } |
| 278 } | 276 } |
| 279 for (UnlinkedVariable serializedVariable in serializedClass.fields) { | 277 for (UnlinkedVariable serializedVariable in serializedClass.fields) { |
| 280 buildVariable(serializedVariable, memberHolder); | 278 buildVariable(serializedVariable, memberHolder); |
| 281 } | 279 } |
| 282 if (!serializedClass.isMixinApplication) { | 280 if (!serializedClass.isMixinApplication) { |
| 283 if (!constructorFound) { | 281 if (!constructorFound) { |
| 284 // Synthesize implicit constructors. | 282 // Synthesize implicit constructors. |
| 285 ConstructorElementImpl constructor = | 283 ConstructorElementImpl constructor = |
| 286 new ConstructorElementImpl('', -1); | 284 new ConstructorElementImpl('', -1); |
| 287 constructor.setModifier(Modifier.SYNTHETIC, true); | 285 constructor.synthetic = true; |
| 288 constructor.returnType = correspondingType; | 286 constructor.returnType = correspondingType; |
| 289 constructor.type = new FunctionTypeImpl(constructor); | 287 constructor.type = new FunctionTypeImpl(constructor); |
| 290 memberHolder.addConstructor(constructor); | 288 memberHolder.addConstructor(constructor); |
| 291 } | 289 } |
| 292 classElement.constructors = memberHolder.constructors; | 290 classElement.constructors = memberHolder.constructors; |
| 293 } | 291 } |
| 294 classElement.accessors = memberHolder.accessors; | 292 classElement.accessors = memberHolder.accessors; |
| 295 classElement.fields = memberHolder.fields; | 293 classElement.fields = memberHolder.fields; |
| 296 classElement.methods = memberHolder.methods; | 294 classElement.methods = memberHolder.methods; |
| 297 correspondingType.typeArguments = | 295 correspondingType.typeArguments = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 324 | 322 |
| 325 /** | 323 /** |
| 326 * Resynthesize a [ConstructorElement] and place it in the given [holder]. | 324 * Resynthesize a [ConstructorElement] and place it in the given [holder]. |
| 327 */ | 325 */ |
| 328 void buildConstructor( | 326 void buildConstructor( |
| 329 UnlinkedExecutable serializedExecutable, ElementHolder holder) { | 327 UnlinkedExecutable serializedExecutable, ElementHolder holder) { |
| 330 assert(serializedExecutable.kind == UnlinkedExecutableKind.constructor); | 328 assert(serializedExecutable.kind == UnlinkedExecutableKind.constructor); |
| 331 ConstructorElementImpl constructorElement = | 329 ConstructorElementImpl constructorElement = |
| 332 new ConstructorElementImpl(serializedExecutable.name, -1); | 330 new ConstructorElementImpl(serializedExecutable.name, -1); |
| 333 buildExecutableCommonParts(constructorElement, serializedExecutable); | 331 buildExecutableCommonParts(constructorElement, serializedExecutable); |
| 334 if (serializedExecutable.isFactory) { | 332 constructorElement.factory = serializedExecutable.isFactory; |
| 335 constructorElement.setModifier(Modifier.FACTORY, true); | 333 constructorElement.const2 = serializedExecutable.isConst; |
| 336 } | |
| 337 if (serializedExecutable.isConst) { | |
| 338 constructorElement.setModifier(Modifier.CONST, true); | |
| 339 } | |
| 340 holder.addConstructor(constructorElement); | 334 holder.addConstructor(constructorElement); |
| 341 } | 335 } |
| 342 | 336 |
| 343 /** | 337 /** |
| 344 * Resynthesize the [ClassElement] corresponding to an enum, along with the | 338 * Resynthesize the [ClassElement] corresponding to an enum, along with the |
| 345 * associated fields and implicit accessors. | 339 * associated fields and implicit accessors. |
| 346 */ | 340 */ |
| 347 void buildEnum(UnlinkedEnum serializedEnum) { | 341 void buildEnum(UnlinkedEnum serializedEnum) { |
| 348 // TODO(paulberry): add offset support (for this element type and others) | 342 // TODO(paulberry): add offset support (for this element type and others) |
| 349 ClassElementImpl classElement = | 343 ClassElementImpl classElement = |
| 350 new ClassElementImpl(serializedEnum.name, -1); | 344 new ClassElementImpl(serializedEnum.name, -1); |
| 351 classElement.setModifier(Modifier.ENUM, true); | 345 classElement.enum2 = true; |
| 352 InterfaceType enumType = new InterfaceTypeImpl(classElement); | 346 InterfaceType enumType = new InterfaceTypeImpl(classElement); |
| 353 classElement.type = enumType; | 347 classElement.type = enumType; |
| 354 classElement.supertype = summaryResynthesizer.typeProvider.objectType; | 348 classElement.supertype = summaryResynthesizer.typeProvider.objectType; |
| 355 ElementHolder memberHolder = new ElementHolder(); | 349 ElementHolder memberHolder = new ElementHolder(); |
| 356 FieldElementImpl indexField = new FieldElementImpl('index', -1); | 350 FieldElementImpl indexField = new FieldElementImpl('index', -1); |
| 357 indexField.setModifier(Modifier.FINAL, true); | 351 indexField.final2 = true; |
| 358 indexField.setModifier(Modifier.SYNTHETIC, true); | 352 indexField.synthetic = true; |
| 359 indexField.type = summaryResynthesizer.typeProvider.intType; | 353 indexField.type = summaryResynthesizer.typeProvider.intType; |
| 360 memberHolder.addField(indexField); | 354 memberHolder.addField(indexField); |
| 361 buildImplicitAccessors(indexField, memberHolder); | 355 buildImplicitAccessors(indexField, memberHolder); |
| 362 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); | 356 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); |
| 363 valuesField.setModifier(Modifier.SYNTHETIC, true); | 357 valuesField.synthetic = true; |
| 364 valuesField.setModifier(Modifier.CONST, true); | 358 valuesField.const3 = true; |
| 365 valuesField.setModifier(Modifier.STATIC, true); | 359 valuesField.static = true; |
| 366 valuesField.type = summaryResynthesizer.typeProvider.listType | 360 valuesField.type = summaryResynthesizer.typeProvider.listType |
| 367 .substitute4(<DartType>[enumType]); | 361 .substitute4(<DartType>[enumType]); |
| 368 memberHolder.addField(valuesField); | 362 memberHolder.addField(valuesField); |
| 369 buildImplicitAccessors(valuesField, memberHolder); | 363 buildImplicitAccessors(valuesField, memberHolder); |
| 370 for (UnlinkedEnumValue serializedEnumValue in serializedEnum.values) { | 364 for (UnlinkedEnumValue serializedEnumValue in serializedEnum.values) { |
| 371 ConstFieldElementImpl valueField = | 365 ConstFieldElementImpl valueField = |
| 372 new ConstFieldElementImpl(serializedEnumValue.name, -1); | 366 new ConstFieldElementImpl(serializedEnumValue.name, -1); |
| 373 valueField.setModifier(Modifier.CONST, true); | 367 valueField.const3 = true; |
| 374 valueField.setModifier(Modifier.STATIC, true); | 368 valueField.static = true; |
| 375 valueField.type = enumType; | 369 valueField.type = enumType; |
| 376 memberHolder.addField(valueField); | 370 memberHolder.addField(valueField); |
| 377 buildImplicitAccessors(valueField, memberHolder); | 371 buildImplicitAccessors(valueField, memberHolder); |
| 378 } | 372 } |
| 379 classElement.fields = memberHolder.fields; | 373 classElement.fields = memberHolder.fields; |
| 380 classElement.accessors = memberHolder.accessors; | 374 classElement.accessors = memberHolder.accessors; |
| 381 classElement.constructors = <ConstructorElement>[]; | 375 classElement.constructors = <ConstructorElement>[]; |
| 382 unitHolder.addEnum(classElement); | 376 unitHolder.addEnum(classElement); |
| 383 } | 377 } |
| 384 | 378 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 399 switch (kind) { | 393 switch (kind) { |
| 400 case UnlinkedExecutableKind.functionOrMethod: | 394 case UnlinkedExecutableKind.functionOrMethod: |
| 401 if (isTopLevel) { | 395 if (isTopLevel) { |
| 402 FunctionElementImpl executableElement = | 396 FunctionElementImpl executableElement = |
| 403 new FunctionElementImpl(name, -1); | 397 new FunctionElementImpl(name, -1); |
| 404 buildExecutableCommonParts(executableElement, serializedExecutable); | 398 buildExecutableCommonParts(executableElement, serializedExecutable); |
| 405 holder.addFunction(executableElement); | 399 holder.addFunction(executableElement); |
| 406 } else { | 400 } else { |
| 407 MethodElementImpl executableElement = new MethodElementImpl(name, -1); | 401 MethodElementImpl executableElement = new MethodElementImpl(name, -1); |
| 408 buildExecutableCommonParts(executableElement, serializedExecutable); | 402 buildExecutableCommonParts(executableElement, serializedExecutable); |
| 409 executableElement.setModifier( | 403 executableElement.static = serializedExecutable.isStatic; |
| 410 Modifier.STATIC, serializedExecutable.isStatic); | |
| 411 holder.addMethod(executableElement); | 404 holder.addMethod(executableElement); |
| 412 } | 405 } |
| 413 break; | 406 break; |
| 414 case UnlinkedExecutableKind.getter: | 407 case UnlinkedExecutableKind.getter: |
| 415 case UnlinkedExecutableKind.setter: | 408 case UnlinkedExecutableKind.setter: |
| 416 PropertyAccessorElementImpl executableElement = | 409 PropertyAccessorElementImpl executableElement = |
| 417 new PropertyAccessorElementImpl(name, -1); | 410 new PropertyAccessorElementImpl(name, -1); |
| 418 if (isTopLevel) { | 411 if (isTopLevel) { |
| 419 executableElement.setModifier(Modifier.STATIC, true); | 412 executableElement.static = true; |
| 420 } else { | 413 } else { |
| 421 executableElement.setModifier( | 414 executableElement.static = serializedExecutable.isStatic; |
| 422 Modifier.STATIC, serializedExecutable.isStatic); | |
| 423 } | 415 } |
| 424 buildExecutableCommonParts(executableElement, serializedExecutable); | 416 buildExecutableCommonParts(executableElement, serializedExecutable); |
| 425 DartType type; | 417 DartType type; |
| 426 if (kind == UnlinkedExecutableKind.getter) { | 418 if (kind == UnlinkedExecutableKind.getter) { |
| 427 executableElement.setModifier(Modifier.GETTER, true); | 419 executableElement.getter = true; |
| 428 type = executableElement.returnType; | 420 type = executableElement.returnType; |
| 429 } else { | 421 } else { |
| 430 executableElement.setModifier(Modifier.SETTER, true); | 422 executableElement.setter = true; |
| 431 type = executableElement.parameters[0].type; | 423 type = executableElement.parameters[0].type; |
| 432 } | 424 } |
| 433 holder.addAccessor(executableElement); | 425 holder.addAccessor(executableElement); |
| 434 // TODO(paulberry): consider removing implicit variables from the | 426 // TODO(paulberry): consider removing implicit variables from the |
| 435 // element model; the spec doesn't call for them, and they cause | 427 // element model; the spec doesn't call for them, and they cause |
| 436 // trouble when getters/setters exist in different parts. | 428 // trouble when getters/setters exist in different parts. |
| 437 PropertyInducingElementImpl implicitVariable; | 429 PropertyInducingElementImpl implicitVariable; |
| 438 if (isTopLevel) { | 430 if (isTopLevel) { |
| 439 implicitVariable = buildImplicitTopLevelVariable(name, kind, holder); | 431 implicitVariable = buildImplicitTopLevelVariable(name, kind, holder); |
| 440 } else { | 432 } else { |
| 441 implicitVariable = buildImplicitField(name, type, kind, holder); | 433 FieldElementImpl field = buildImplicitField(name, type, kind, holder); |
| 442 implicitVariable.setModifier( | 434 field.static = serializedExecutable.isStatic; |
| 443 Modifier.STATIC, serializedExecutable.isStatic); | 435 implicitVariable = field; |
| 444 } | 436 } |
| 445 executableElement.variable = implicitVariable; | 437 executableElement.variable = implicitVariable; |
| 446 if (kind == UnlinkedExecutableKind.getter) { | 438 if (kind == UnlinkedExecutableKind.getter) { |
| 447 implicitVariable.getter = executableElement; | 439 implicitVariable.getter = executableElement; |
| 448 } else { | 440 } else { |
| 449 implicitVariable.setter = executableElement; | 441 implicitVariable.setter = executableElement; |
| 450 } | 442 } |
| 451 // TODO(paulberry): do the right thing when getter and setter are in | 443 // TODO(paulberry): do the right thing when getter and setter are in |
| 452 // different units. | 444 // different units. |
| 453 break; | 445 break; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 466 void buildExecutableCommonParts(ExecutableElementImpl executableElement, | 458 void buildExecutableCommonParts(ExecutableElementImpl executableElement, |
| 467 UnlinkedExecutable serializedExecutable) { | 459 UnlinkedExecutable serializedExecutable) { |
| 468 executableElement.parameters = | 460 executableElement.parameters = |
| 469 serializedExecutable.parameters.map(buildParameter).toList(); | 461 serializedExecutable.parameters.map(buildParameter).toList(); |
| 470 if (serializedExecutable.returnType != null) { | 462 if (serializedExecutable.returnType != null) { |
| 471 executableElement.returnType = buildType(serializedExecutable.returnType); | 463 executableElement.returnType = buildType(serializedExecutable.returnType); |
| 472 } else { | 464 } else { |
| 473 executableElement.returnType = VoidTypeImpl.instance; | 465 executableElement.returnType = VoidTypeImpl.instance; |
| 474 } | 466 } |
| 475 executableElement.type = new FunctionTypeImpl(executableElement); | 467 executableElement.type = new FunctionTypeImpl(executableElement); |
| 476 if (serializedExecutable.hasImplicitReturnType) { | 468 executableElement.hasImplicitReturnType = |
| 477 executableElement.setModifier(Modifier.IMPLICIT_TYPE, true); | 469 serializedExecutable.hasImplicitReturnType; |
| 478 } | |
| 479 } | 470 } |
| 480 | 471 |
| 481 /** | 472 /** |
| 482 * Resynthesize an [ExportElement], | 473 * Resynthesize an [ExportElement], |
| 483 */ | 474 */ |
| 484 ExportElement buildExport(UnlinkedExport serializedExport) { | 475 ExportElement buildExport(UnlinkedExport serializedExport) { |
| 485 ExportElementImpl exportElement = new ExportElementImpl(0); | 476 ExportElementImpl exportElement = new ExportElementImpl(0); |
| 486 String exportedLibraryUri = summaryResynthesizer.sourceFactory | 477 String exportedLibraryUri = summaryResynthesizer.sourceFactory |
| 487 .resolveUri(librarySource, serializedExport.uri) | 478 .resolveUri(librarySource, serializedExport.uri) |
| 488 .uri | 479 .uri |
| 489 .toString(); | 480 .toString(); |
| 490 exportElement.exportedLibrary = new LibraryElementHandle( | 481 exportElement.exportedLibrary = new LibraryElementHandle( |
| 491 summaryResynthesizer, | 482 summaryResynthesizer, |
| 492 new ElementLocationImpl.con3(<String>[exportedLibraryUri])); | 483 new ElementLocationImpl.con3(<String>[exportedLibraryUri])); |
| 493 exportElement.uri = serializedExport.uri; | 484 exportElement.uri = serializedExport.uri; |
| 494 exportElement.combinators = | 485 exportElement.combinators = |
| 495 serializedExport.combinators.map(buildCombinator).toList(); | 486 serializedExport.combinators.map(buildCombinator).toList(); |
| 496 return exportElement; | 487 return exportElement; |
| 497 } | 488 } |
| 498 | 489 |
| 499 /** | 490 /** |
| 500 * Resynthesize a [FieldElement]. | 491 * Resynthesize a [FieldElement]. |
| 501 */ | 492 */ |
| 502 FieldElement buildField(UnlinkedVariable serializedField) { | 493 FieldElement buildField(UnlinkedVariable serializedField) { |
| 503 FieldElementImpl fieldElement = | 494 FieldElementImpl fieldElement = |
| 504 new FieldElementImpl(serializedField.name, -1); | 495 new FieldElementImpl(serializedField.name, -1); |
| 505 fieldElement.type = buildType(serializedField.type); | 496 fieldElement.type = buildType(serializedField.type); |
| 506 if (serializedField.isConst) { | 497 fieldElement.const3 = serializedField.isConst; |
| 507 fieldElement.setModifier(Modifier.CONST, true); | |
| 508 } | |
| 509 return fieldElement; | 498 return fieldElement; |
| 510 } | 499 } |
| 511 | 500 |
| 512 /** | 501 /** |
| 513 * Build the implicit getter and setter associated with [element], and place | 502 * Build the implicit getter and setter associated with [element], and place |
| 514 * them in [holder]. | 503 * them in [holder]. |
| 515 */ | 504 */ |
| 516 void buildImplicitAccessors( | 505 void buildImplicitAccessors( |
| 517 PropertyInducingElementImpl element, ElementHolder holder) { | 506 PropertyInducingElementImpl element, ElementHolder holder) { |
| 518 String name = element.name; | 507 String name = element.name; |
| 519 DartType type = element.type; | 508 DartType type = element.type; |
| 520 PropertyAccessorElementImpl getter = | 509 PropertyAccessorElementImpl getter = |
| 521 new PropertyAccessorElementImpl(name, -1); | 510 new PropertyAccessorElementImpl(name, -1); |
| 522 getter.setModifier(Modifier.GETTER, true); | 511 getter.getter = true; |
| 523 getter.setModifier(Modifier.STATIC, element.isStatic); | 512 getter.static = element.isStatic; |
| 524 getter.setModifier(Modifier.SYNTHETIC, true); | 513 getter.synthetic = true; |
| 525 getter.returnType = type; | 514 getter.returnType = type; |
| 526 getter.type = new FunctionTypeImpl(getter); | 515 getter.type = new FunctionTypeImpl(getter); |
| 527 getter.variable = element; | 516 getter.variable = element; |
| 528 holder.addAccessor(getter); | 517 holder.addAccessor(getter); |
| 529 element.getter = getter; | 518 element.getter = getter; |
| 530 if (!(element.isConst || element.isFinal)) { | 519 if (!(element.isConst || element.isFinal)) { |
| 531 PropertyAccessorElementImpl setter = | 520 PropertyAccessorElementImpl setter = |
| 532 new PropertyAccessorElementImpl(name, -1); | 521 new PropertyAccessorElementImpl(name, -1); |
| 533 setter.setModifier(Modifier.SETTER, true); | 522 setter.setter = true; |
| 534 setter.setModifier(Modifier.STATIC, element.isStatic); | 523 setter.static = element.isStatic; |
| 535 setter.setModifier(Modifier.SYNTHETIC, true); | 524 setter.synthetic = true; |
| 536 setter.parameters = <ParameterElement>[ | 525 setter.parameters = <ParameterElement>[ |
| 537 new ParameterElementImpl('_$name', -1) | 526 new ParameterElementImpl('_$name', -1) |
| 538 ..setModifier(Modifier.SYNTHETIC, true) | 527 ..synthetic = true |
| 539 ..type = type | 528 ..type = type |
| 540 ..parameterKind = ParameterKind.REQUIRED | 529 ..parameterKind = ParameterKind.REQUIRED |
| 541 ]; | 530 ]; |
| 542 setter.returnType = VoidTypeImpl.instance; | 531 setter.returnType = VoidTypeImpl.instance; |
| 543 setter.type = new FunctionTypeImpl(setter); | 532 setter.type = new FunctionTypeImpl(setter); |
| 544 setter.variable = element; | 533 setter.variable = element; |
| 545 holder.addAccessor(setter); | 534 holder.addAccessor(setter); |
| 546 element.setter = setter; | 535 element.setter = setter; |
| 547 } | 536 } |
| 548 } | 537 } |
| 549 | 538 |
| 550 /** | 539 /** |
| 551 * Build the implicit field associated with a getter or setter, and place it | 540 * Build the implicit field associated with a getter or setter, and place it |
| 552 * in [holder]. | 541 * in [holder]. |
| 553 */ | 542 */ |
| 554 PropertyInducingElementImpl buildImplicitField(String name, DartType type, | 543 FieldElementImpl buildImplicitField(String name, DartType type, |
| 555 UnlinkedExecutableKind kind, ElementHolder holder) { | 544 UnlinkedExecutableKind kind, ElementHolder holder) { |
| 556 if (holder.getField(name) == null) { | 545 if (holder.getField(name) == null) { |
| 557 FieldElementImpl field = new FieldElementImpl(name, -1); | 546 FieldElementImpl field = new FieldElementImpl(name, -1); |
| 558 field.setModifier(Modifier.SYNTHETIC, true); | 547 field.synthetic = true; |
| 559 if (kind == UnlinkedExecutableKind.getter) { | 548 field.final2 = kind == UnlinkedExecutableKind.getter; |
| 560 field.setModifier(Modifier.FINAL, true); | |
| 561 } | |
| 562 field.type = type; | 549 field.type = type; |
| 563 holder.addField(field); | 550 holder.addField(field); |
| 564 return field; | 551 return field; |
| 565 } else { | 552 } else { |
| 566 // TODO(paulberry): if adding a setter where there was previously | 553 // TODO(paulberry): if adding a setter where there was previously |
| 567 // only a getter, remove "final" modifier. | 554 // only a getter, remove "final" modifier. |
| 568 // TODO(paulberry): what if the getter and setter have a type mismatch? | 555 // TODO(paulberry): what if the getter and setter have a type mismatch? |
| 569 throw new UnimplementedError(); | 556 throw new UnimplementedError(); |
| 570 } | 557 } |
| 571 } | 558 } |
| 572 | 559 |
| 573 /** | 560 /** |
| 574 * Build the implicit top level variable associated with a getter or setter, | 561 * Build the implicit top level variable associated with a getter or setter, |
| 575 * and place it in [holder]. | 562 * and place it in [holder]. |
| 576 */ | 563 */ |
| 577 PropertyInducingElementImpl buildImplicitTopLevelVariable( | 564 PropertyInducingElementImpl buildImplicitTopLevelVariable( |
| 578 String name, UnlinkedExecutableKind kind, ElementHolder holder) { | 565 String name, UnlinkedExecutableKind kind, ElementHolder holder) { |
| 579 if (holder.getTopLevelVariable(name) == null) { | 566 if (holder.getTopLevelVariable(name) == null) { |
| 580 TopLevelVariableElementImpl variable = | 567 TopLevelVariableElementImpl variable = |
| 581 new TopLevelVariableElementImpl(name, -1); | 568 new TopLevelVariableElementImpl(name, -1); |
| 582 variable.setModifier(Modifier.SYNTHETIC, true); | 569 variable.synthetic = true; |
| 583 if (kind == UnlinkedExecutableKind.getter) { | 570 variable.final2 = kind == UnlinkedExecutableKind.getter; |
| 584 variable.setModifier(Modifier.FINAL, true); | |
| 585 } | |
| 586 holder.addTopLevelVariable(variable); | 571 holder.addTopLevelVariable(variable); |
| 587 return variable; | 572 return variable; |
| 588 } else { | 573 } else { |
| 589 // TODO(paulberry): if adding a setter where there was previously | 574 // TODO(paulberry): if adding a setter where there was previously |
| 590 // only a getter, remove "final" modifier. | 575 // only a getter, remove "final" modifier. |
| 591 // TODO(paulberry): what if the getter and setter have a type mismatch? | 576 // TODO(paulberry): what if the getter and setter have a type mismatch? |
| 592 throw new UnimplementedError(); | 577 throw new UnimplementedError(); |
| 593 } | 578 } |
| 594 } | 579 } |
| 595 | 580 |
| 596 /** | 581 /** |
| 597 * Resynthesize an [ImportElement]. | 582 * Resynthesize an [ImportElement]. |
| 598 */ | 583 */ |
| 599 ImportElement buildImport(UnlinkedImport serializedImport, int dependency) { | 584 ImportElement buildImport(UnlinkedImport serializedImport, int dependency) { |
| 600 bool isSynthetic = serializedImport.isImplicit; | 585 bool isSynthetic = serializedImport.isImplicit; |
| 601 // TODO(paulberry): it seems problematic for the offset to be 0 for | 586 // TODO(paulberry): it seems problematic for the offset to be 0 for |
| 602 // non-synthetic imports, since it is used to disambiguate location. | 587 // non-synthetic imports, since it is used to disambiguate location. |
| 603 ImportElementImpl importElement = | 588 ImportElementImpl importElement = |
| 604 new ImportElementImpl(isSynthetic ? -1 : serializedImport.offset); | 589 new ImportElementImpl(isSynthetic ? -1 : serializedImport.offset); |
| 605 String absoluteUri = summaryResynthesizer.sourceFactory | 590 String absoluteUri = summaryResynthesizer.sourceFactory |
| 606 .resolveUri( | 591 .resolveUri( |
| 607 librarySource, prelinkedLibrary.dependencies[dependency].uri) | 592 librarySource, prelinkedLibrary.dependencies[dependency].uri) |
| 608 .uri | 593 .uri |
| 609 .toString(); | 594 .toString(); |
| 610 importElement.importedLibrary = new LibraryElementHandle( | 595 importElement.importedLibrary = new LibraryElementHandle( |
| 611 summaryResynthesizer, | 596 summaryResynthesizer, |
| 612 new ElementLocationImpl.con3(<String>[absoluteUri])); | 597 new ElementLocationImpl.con3(<String>[absoluteUri])); |
| 613 if (isSynthetic) { | 598 if (isSynthetic) { |
| 614 importElement.setModifier(Modifier.SYNTHETIC, true); | 599 importElement.synthetic = true; |
| 615 } else { | 600 } else { |
| 616 importElement.uri = serializedImport.uri; | 601 importElement.uri = serializedImport.uri; |
| 617 } | 602 } |
| 618 if (serializedImport.prefixReference != 0) { | 603 if (serializedImport.prefixReference != 0) { |
| 619 UnlinkedReference serializedPrefix = prelinkedLibrary.units[0] | 604 UnlinkedReference serializedPrefix = prelinkedLibrary.units[0] |
| 620 .unlinked | 605 .unlinked |
| 621 .references[serializedImport.prefixReference]; | 606 .references[serializedImport.prefixReference]; |
| 622 importElement.prefix = new PrefixElementImpl(serializedPrefix.name, -1); | 607 importElement.prefix = new PrefixElementImpl(serializedPrefix.name, -1); |
| 623 } | 608 } |
| 624 importElement.combinators = | 609 importElement.combinators = |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 654 |
| 670 /** | 655 /** |
| 671 * Resynthesize a [ParameterElement]. | 656 * Resynthesize a [ParameterElement]. |
| 672 */ | 657 */ |
| 673 ParameterElement buildParameter(UnlinkedParam serializedParameter) { | 658 ParameterElement buildParameter(UnlinkedParam serializedParameter) { |
| 674 ParameterElementImpl parameterElement = | 659 ParameterElementImpl parameterElement = |
| 675 new ParameterElementImpl(serializedParameter.name, -1); | 660 new ParameterElementImpl(serializedParameter.name, -1); |
| 676 if (serializedParameter.isFunctionTyped) { | 661 if (serializedParameter.isFunctionTyped) { |
| 677 FunctionElementImpl parameterTypeElement = | 662 FunctionElementImpl parameterTypeElement = |
| 678 new FunctionElementImpl('', -1); | 663 new FunctionElementImpl('', -1); |
| 679 parameterTypeElement.setModifier(Modifier.SYNTHETIC, true); | 664 parameterTypeElement.synthetic = true; |
| 680 parameterElement.parameters = | 665 parameterElement.parameters = |
| 681 serializedParameter.parameters.map(buildParameter).toList(); | 666 serializedParameter.parameters.map(buildParameter).toList(); |
| 682 parameterTypeElement.enclosingElement = parameterElement; | 667 parameterTypeElement.enclosingElement = parameterElement; |
| 683 parameterTypeElement.shareParameters(parameterElement.parameters); | 668 parameterTypeElement.shareParameters(parameterElement.parameters); |
| 684 if (serializedParameter.type != null) { | 669 if (serializedParameter.type != null) { |
| 685 parameterTypeElement.returnType = buildType(serializedParameter.type); | 670 parameterTypeElement.returnType = buildType(serializedParameter.type); |
| 686 } else { | 671 } else { |
| 687 parameterTypeElement.returnType = VoidTypeImpl.instance; | 672 parameterTypeElement.returnType = VoidTypeImpl.instance; |
| 688 } | 673 } |
| 689 parameterElement.type = new FunctionTypeImpl(parameterTypeElement); | 674 parameterElement.type = new FunctionTypeImpl(parameterTypeElement); |
| 690 } else { | 675 } else { |
| 691 parameterElement.type = buildType(serializedParameter.type); | 676 parameterElement.type = buildType(serializedParameter.type); |
| 692 if (serializedParameter.hasImplicitType) { | 677 parameterElement.hasImplicitType = serializedParameter.hasImplicitType; |
| 693 parameterElement.setModifier(Modifier.IMPLICIT_TYPE, true); | |
| 694 } | |
| 695 } | 678 } |
| 696 switch (serializedParameter.kind) { | 679 switch (serializedParameter.kind) { |
| 697 case UnlinkedParamKind.named: | 680 case UnlinkedParamKind.named: |
| 698 parameterElement.parameterKind = ParameterKind.NAMED; | 681 parameterElement.parameterKind = ParameterKind.NAMED; |
| 699 break; | 682 break; |
| 700 case UnlinkedParamKind.positional: | 683 case UnlinkedParamKind.positional: |
| 701 parameterElement.parameterKind = ParameterKind.POSITIONAL; | 684 parameterElement.parameterKind = ParameterKind.POSITIONAL; |
| 702 break; | 685 break; |
| 703 case UnlinkedParamKind.required: | 686 case UnlinkedParamKind.required: |
| 704 parameterElement.parameterKind = ParameterKind.REQUIRED; | 687 parameterElement.parameterKind = ParameterKind.REQUIRED; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 if (holder == null) { | 850 if (holder == null) { |
| 868 TopLevelVariableElementImpl element = | 851 TopLevelVariableElementImpl element = |
| 869 new TopLevelVariableElementImpl(serializedVariable.name, -1); | 852 new TopLevelVariableElementImpl(serializedVariable.name, -1); |
| 870 buildVariableCommonParts(element, serializedVariable); | 853 buildVariableCommonParts(element, serializedVariable); |
| 871 unitHolder.addTopLevelVariable(element); | 854 unitHolder.addTopLevelVariable(element); |
| 872 buildImplicitAccessors(element, unitHolder); | 855 buildImplicitAccessors(element, unitHolder); |
| 873 } else { | 856 } else { |
| 874 FieldElementImpl element = | 857 FieldElementImpl element = |
| 875 new FieldElementImpl(serializedVariable.name, -1); | 858 new FieldElementImpl(serializedVariable.name, -1); |
| 876 buildVariableCommonParts(element, serializedVariable); | 859 buildVariableCommonParts(element, serializedVariable); |
| 860 element.static = serializedVariable.isStatic; |
| 877 holder.addField(element); | 861 holder.addField(element); |
| 878 buildImplicitAccessors(element, holder); | 862 buildImplicitAccessors(element, holder); |
| 879 } | 863 } |
| 880 } | 864 } |
| 881 | 865 |
| 882 /** | 866 /** |
| 883 * Handle the parts that are common to top level variables and fields. | 867 * Handle the parts that are common to top level variables and fields. |
| 884 */ | 868 */ |
| 885 void buildVariableCommonParts(PropertyInducingElementImpl element, | 869 void buildVariableCommonParts(PropertyInducingElementImpl element, |
| 886 UnlinkedVariable serializedVariable) { | 870 UnlinkedVariable serializedVariable) { |
| 887 element.type = buildType(serializedVariable.type); | 871 element.type = buildType(serializedVariable.type); |
| 888 element.setModifier(Modifier.CONST, serializedVariable.isConst); | 872 element.const3 = serializedVariable.isConst; |
| 889 element.setModifier(Modifier.STATIC, serializedVariable.isStatic); | |
| 890 } | 873 } |
| 891 | 874 |
| 892 /** | 875 /** |
| 893 * Finish creating a [TypeParameterElement] by deserializing its bound. | 876 * Finish creating a [TypeParameterElement] by deserializing its bound. |
| 894 */ | 877 */ |
| 895 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, | 878 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, |
| 896 TypeParameterElementImpl typeParameterElement) { | 879 TypeParameterElementImpl typeParameterElement) { |
| 897 if (serializedTypeParameter.bound != null) { | 880 if (serializedTypeParameter.bound != null) { |
| 898 typeParameterElement.bound = buildType(serializedTypeParameter.bound); | 881 typeParameterElement.bound = buildType(serializedTypeParameter.bound); |
| 899 } | 882 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 elementMap[cls.name] = cls; | 916 elementMap[cls.name] = cls; |
| 934 } | 917 } |
| 935 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { | 918 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { |
| 936 elementMap[typeAlias.name] = typeAlias; | 919 elementMap[typeAlias.name] = typeAlias; |
| 937 } | 920 } |
| 938 resummarizedElements[absoluteUri] = elementMap; | 921 resummarizedElements[absoluteUri] = elementMap; |
| 939 unitHolder = null; | 922 unitHolder = null; |
| 940 prelinkedUnit = null; | 923 prelinkedUnit = null; |
| 941 } | 924 } |
| 942 } | 925 } |
| OLD | NEW |