| 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/ast/ast.dart'; |     9 import 'package:analyzer/dart/ast/ast.dart'; | 
|    10 import 'package:analyzer/dart/ast/token.dart'; |    10 import 'package:analyzer/dart/ast/token.dart'; | 
| (...skipping 2290 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2301       constElement.constantInitializer = _buildConstExpression( |  2301       constElement.constantInitializer = _buildConstExpression( | 
|  2302           enclosingExecutable, serializedVariable.constExpr); |  2302           enclosingExecutable, serializedVariable.constExpr); | 
|  2303     } else { |  2303     } else { | 
|  2304       element = new LocalVariableElementImpl.forSerialized( |  2304       element = new LocalVariableElementImpl.forSerialized( | 
|  2305           serializedVariable, enclosingExecutable); |  2305           serializedVariable, enclosingExecutable); | 
|  2306     } |  2306     } | 
|  2307     if (serializedVariable.visibleOffset != 0) { |  2307     if (serializedVariable.visibleOffset != 0) { | 
|  2308       element.setVisibleRange( |  2308       element.setVisibleRange( | 
|  2309           serializedVariable.visibleOffset, serializedVariable.visibleLength); |  2309           serializedVariable.visibleOffset, serializedVariable.visibleLength); | 
|  2310     } |  2310     } | 
|  2311     buildVariableCommonParts(element, serializedVariable, |  2311     buildVariableCommonParts(element, serializedVariable); | 
|  2312         isLazilyResynthesized: true); |  | 
|  2313     return element; |  2312     return element; | 
|  2314   } |  2313   } | 
|  2315  |  2314  | 
|  2316   /** |  2315   /** | 
|  2317    * Resynthesize a [ParameterElement]. |  2316    * Resynthesize a [ParameterElement]. | 
|  2318    */ |  2317    */ | 
|  2319   ParameterElement buildParameter( |  2318   ParameterElement buildParameter( | 
|  2320       UnlinkedParam serializedParameter, ElementImpl enclosingElement, |  2319       UnlinkedParam serializedParameter, ElementImpl enclosingElement, | 
|  2321       {bool synthetic: false}) { |  2320       {bool synthetic: false}) { | 
|  2322     ParameterElementImpl parameterElement; |  2321     ParameterElementImpl parameterElement; | 
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2414             serializedParameter.visibleLength); |  2413             serializedParameter.visibleLength); | 
|  2415       } |  2414       } | 
|  2416     } |  2415     } | 
|  2417     return parameterElement; |  2416     return parameterElement; | 
|  2418   } |  2417   } | 
|  2419  |  2418  | 
|  2420   /** |  2419   /** | 
|  2421    * Handle the parts that are common to top level variables and fields. |  2420    * Handle the parts that are common to top level variables and fields. | 
|  2422    */ |  2421    */ | 
|  2423   void buildPropertyIntroducingElementCommonParts( |  2422   void buildPropertyIntroducingElementCommonParts( | 
|  2424       PropertyInducingElementImpl element, UnlinkedVariable serializedVariable, |  2423       PropertyInducingElementImpl element, | 
|  2425       {bool isLazilyResynthesized: false}) { |  2424       UnlinkedVariable serializedVariable) { | 
|  2426     buildVariableCommonParts(element, serializedVariable, |  2425     buildVariableCommonParts(element, serializedVariable); | 
|  2427         isLazilyResynthesized: isLazilyResynthesized); |  | 
|  2428     element.propagatedType = buildLinkedType( |  2426     element.propagatedType = buildLinkedType( | 
|  2429         serializedVariable.propagatedTypeSlot, |  2427         serializedVariable.propagatedTypeSlot, | 
|  2430         _currentTypeParameterizedElement); |  2428         _currentTypeParameterizedElement); | 
|  2431   } |  2429   } | 
|  2432  |  2430  | 
|  2433   List<FunctionElementImpl> buildTopLevelFunctions() { |  2431   List<FunctionElementImpl> buildTopLevelFunctions() { | 
|  2434     List<FunctionElementImpl> functions = <FunctionElementImpl>[]; |  2432     List<FunctionElementImpl> functions = <FunctionElementImpl>[]; | 
|  2435     List<UnlinkedExecutable> executables = unlinkedUnit.executables; |  2433     List<UnlinkedExecutable> executables = unlinkedUnit.executables; | 
|  2436     for (UnlinkedExecutable unlinkedExecutable in executables) { |  2434     for (UnlinkedExecutable unlinkedExecutable in executables) { | 
|  2437       if (unlinkedExecutable.kind == UnlinkedExecutableKind.functionOrMethod) { |  2435       if (unlinkedExecutable.kind == UnlinkedExecutableKind.functionOrMethod) { | 
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2617         ConstTopLevelVariableElementImpl constElement = |  2615         ConstTopLevelVariableElementImpl constElement = | 
|  2618             new ConstTopLevelVariableElementImpl.forSerialized( |  2616             new ConstTopLevelVariableElementImpl.forSerialized( | 
|  2619                 unlinkedVariable, unit); |  2617                 unlinkedVariable, unit); | 
|  2620         element = constElement; |  2618         element = constElement; | 
|  2621         constElement.constantInitializer = |  2619         constElement.constantInitializer = | 
|  2622             _buildConstExpression(null, unlinkedVariable.constExpr); |  2620             _buildConstExpression(null, unlinkedVariable.constExpr); | 
|  2623       } else { |  2621       } else { | 
|  2624         element = new TopLevelVariableElementImpl.forSerialized( |  2622         element = new TopLevelVariableElementImpl.forSerialized( | 
|  2625             unlinkedVariable, unit); |  2623             unlinkedVariable, unit); | 
|  2626       } |  2624       } | 
|  2627       buildPropertyIntroducingElementCommonParts(element, unlinkedVariable, |  2625       buildPropertyIntroducingElementCommonParts(element, unlinkedVariable); | 
|  2628           isLazilyResynthesized: true); |  | 
|  2629       variablesData.variables[i] = element; |  2626       variablesData.variables[i] = element; | 
|  2630       // implicit accessors |  2627       // implicit accessors | 
|  2631       String name = element.name; |  2628       String name = element.name; | 
|  2632       DartType type = element.type; |  2629       DartType type = element.type; | 
|  2633       variablesData.implicitAccessors |  2630       variablesData.implicitAccessors | 
|  2634           .add(buildImplicitGetter(element, name, type)); |  2631           .add(buildImplicitGetter(element, name, type)); | 
|  2635       if (!(element.isConst || element.isFinal)) { |  2632       if (!(element.isConst || element.isFinal)) { | 
|  2636         variablesData.implicitAccessors |  2633         variablesData.implicitAccessors | 
|  2637             .add(buildImplicitSetter(element, name, type)); |  2634             .add(buildImplicitSetter(element, name, type)); | 
|  2638       } |  2635       } | 
|  2639     } |  2636     } | 
|  2640     return variablesData; |  2637     return variablesData; | 
|  2641   } |  2638   } | 
|  2642  |  2639  | 
|  2643   /** |  2640   /** | 
|  2644    * Resynthesize a [TopLevelVariableElement] or [FieldElement]. |  2641    * Resynthesize a [TopLevelVariableElement] or [FieldElement]. | 
|  2645    */ |  2642    */ | 
|  2646   void buildVariable( |  2643   void buildVariable( | 
|  2647       ClassElementImpl enclosingClass, UnlinkedVariable serializedVariable, |  2644       ClassElementImpl enclosingClass, UnlinkedVariable serializedVariable, | 
|  2648       [ElementHolder holder]) { |  2645       [ElementHolder holder]) { | 
|  2649     if (holder == null) { |  2646     if (holder == null) { | 
|  2650       throw new UnimplementedError('Must be lazy'); |  2647       throw new UnimplementedError('Must be lazy'); | 
|  2651     } else { |  2648     } else { | 
|  2652       FieldElementImpl element; |  2649       FieldElementImpl element; | 
|  2653       if (serializedVariable.constExpr != null && |  2650       if (serializedVariable.constExpr != null && | 
|  2654           (serializedVariable.isConst || |  2651           (serializedVariable.isConst || | 
|  2655               serializedVariable.isFinal && !serializedVariable.isStatic)) { |  2652               serializedVariable.isFinal && !serializedVariable.isStatic)) { | 
|  2656         ConstFieldElementImpl constElement = new ConstFieldElementImpl( |  2653         ConstFieldElementImpl constElement = | 
|  2657             serializedVariable.name, serializedVariable.nameOffset); |  2654             new ConstFieldElementImpl.forSerialized( | 
 |  2655                 serializedVariable, enclosingClass); | 
|  2658         element = constElement; |  2656         element = constElement; | 
|  2659         constElement.constantInitializer = |  2657         constElement.constantInitializer = | 
|  2660             _buildConstExpression(enclosingClass, serializedVariable.constExpr); |  2658             _buildConstExpression(enclosingClass, serializedVariable.constExpr); | 
|  2661       } else { |  2659       } else { | 
|  2662         element = new FieldElementImpl( |  2660         element = new FieldElementImpl.forSerialized( | 
|  2663             serializedVariable.name, serializedVariable.nameOffset); |  2661             serializedVariable, enclosingClass); | 
|  2664       } |  2662       } | 
|  2665       buildPropertyIntroducingElementCommonParts(element, serializedVariable); |  2663       buildPropertyIntroducingElementCommonParts(element, serializedVariable); | 
|  2666       element.static = serializedVariable.isStatic; |  2664       element.static = serializedVariable.isStatic; | 
|  2667       holder.addField(element); |  2665       holder.addField(element); | 
|  2668       buildImplicitAccessors(element, holder); |  2666       buildImplicitAccessors(element, holder); | 
|  2669       fields[element.name] = element; |  2667       fields[element.name] = element; | 
|  2670     } |  2668     } | 
|  2671   } |  2669   } | 
|  2672  |  2670  | 
|  2673   /** |  2671   /** | 
|  2674    * Handle the parts that are common to variables. |  2672    * Handle the parts that are common to variables. | 
|  2675    */ |  2673    */ | 
|  2676   void buildVariableCommonParts( |  2674   void buildVariableCommonParts( | 
|  2677       VariableElementImpl element, UnlinkedVariable serializedVariable, |  2675       VariableElementImpl element, UnlinkedVariable serializedVariable) { | 
|  2678       {bool isLazilyResynthesized: false}) { |  | 
|  2679     element.type = buildLinkedType(serializedVariable.inferredTypeSlot, |  2676     element.type = buildLinkedType(serializedVariable.inferredTypeSlot, | 
|  2680             _currentTypeParameterizedElement) ?? |  2677             _currentTypeParameterizedElement) ?? | 
|  2681         buildType(serializedVariable.type, _currentTypeParameterizedElement); |  2678         buildType(serializedVariable.type, _currentTypeParameterizedElement); | 
|  2682     if (!isLazilyResynthesized) { |  | 
|  2683       element.const3 = serializedVariable.isConst; |  | 
|  2684       element.final2 = serializedVariable.isFinal; |  | 
|  2685       element.hasImplicitType = serializedVariable.type == null; |  | 
|  2686       buildDocumentation(element, serializedVariable.documentationComment); |  | 
|  2687       buildAnnotations(element, serializedVariable.annotations); |  | 
|  2688       buildCodeRange(element, serializedVariable.codeRange); |  | 
|  2689     } |  | 
|  2690     buildVariableInitializer(element, serializedVariable.initializer); |  2679     buildVariableInitializer(element, serializedVariable.initializer); | 
|  2691   } |  2680   } | 
|  2692  |  2681  | 
|  2693   /** |  2682   /** | 
|  2694    * If the given [serializedInitializer] is not `null`, create the |  2683    * If the given [serializedInitializer] is not `null`, create the | 
|  2695    * corresponding [FunctionElementImpl] and set it for the [variable]. |  2684    * corresponding [FunctionElementImpl] and set it for the [variable]. | 
|  2696    */ |  2685    */ | 
|  2697   void buildVariableInitializer( |  2686   void buildVariableInitializer( | 
|  2698       VariableElementImpl variable, UnlinkedExecutable serializedInitializer) { |  2687       VariableElementImpl variable, UnlinkedExecutable serializedInitializer) { | 
|  2699     if (serializedInitializer == null) { |  2688     if (serializedInitializer == null) { | 
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2971   static String _getElementIdentifier(String name, ReferenceKind kind) { |  2960   static String _getElementIdentifier(String name, ReferenceKind kind) { | 
|  2972     if (kind == ReferenceKind.topLevelPropertyAccessor || |  2961     if (kind == ReferenceKind.topLevelPropertyAccessor || | 
|  2973         kind == ReferenceKind.propertyAccessor) { |  2962         kind == ReferenceKind.propertyAccessor) { | 
|  2974       if (!name.endsWith('=')) { |  2963       if (!name.endsWith('=')) { | 
|  2975         return name + '?'; |  2964         return name + '?'; | 
|  2976       } |  2965       } | 
|  2977     } |  2966     } | 
|  2978     return name; |  2967     return name; | 
|  2979   } |  2968   } | 
|  2980 } |  2969 } | 
| OLD | NEW |