| 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 analyzer.src.dart.element.element; | 5 library analyzer.src.dart.element.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 * class. | 1902 * class. |
| 1903 */ | 1903 */ |
| 1904 class ConstFieldElementImpl extends FieldElementImpl with ConstVariableElement { | 1904 class ConstFieldElementImpl extends FieldElementImpl with ConstVariableElement { |
| 1905 /** | 1905 /** |
| 1906 * Initialize a newly created synthetic field element to have the given | 1906 * Initialize a newly created synthetic field element to have the given |
| 1907 * [name] and [offset]. | 1907 * [name] and [offset]. |
| 1908 */ | 1908 */ |
| 1909 ConstFieldElementImpl(String name, int offset) : super(name, offset); | 1909 ConstFieldElementImpl(String name, int offset) : super(name, offset); |
| 1910 | 1910 |
| 1911 /** | 1911 /** |
| 1912 * Initialize using the given kernel. |
| 1913 */ |
| 1914 ConstFieldElementImpl.forKernel( |
| 1915 ElementImpl enclosingElement, kernel.Field kernel) |
| 1916 : super.forKernel(enclosingElement, kernel); |
| 1917 |
| 1918 /** |
| 1912 * Initialize a newly created field element to have the given [name]. | 1919 * Initialize a newly created field element to have the given [name]. |
| 1913 */ | 1920 */ |
| 1914 ConstFieldElementImpl.forNode(Identifier name) : super.forNode(name); | 1921 ConstFieldElementImpl.forNode(Identifier name) : super.forNode(name); |
| 1915 | 1922 |
| 1916 /** | 1923 /** |
| 1917 * Initialize using the given serialized information. | 1924 * Initialize using the given serialized information. |
| 1918 */ | 1925 */ |
| 1919 ConstFieldElementImpl.forSerialized( | 1926 ConstFieldElementImpl.forSerialized( |
| 1920 UnlinkedVariable unlinkedVariable, ElementImpl enclosingElement) | 1927 UnlinkedVariable unlinkedVariable, ElementImpl enclosingElement) |
| 1921 : super.forSerialized(unlinkedVariable, enclosingElement); | 1928 : super.forSerialized(unlinkedVariable, enclosingElement); |
| 1922 | |
| 1923 /** | |
| 1924 * Initialize using the given kernel. | |
| 1925 */ | |
| 1926 ConstFieldElementImpl.forKernel( | |
| 1927 ElementImpl enclosingElement, kernel.Field kernel) | |
| 1928 : super.forKernel(enclosingElement, kernel); | |
| 1929 } | 1929 } |
| 1930 | 1930 |
| 1931 /** | 1931 /** |
| 1932 * A field element representing an enum constant. | 1932 * A field element representing an enum constant. |
| 1933 */ | 1933 */ |
| 1934 class ConstFieldElementImpl_EnumValue extends ConstFieldElementImpl_ofEnum { | 1934 class ConstFieldElementImpl_EnumValue extends ConstFieldElementImpl_ofEnum { |
| 1935 final UnlinkedEnumValue _unlinkedEnumValue; | 1935 final UnlinkedEnumValue _unlinkedEnumValue; |
| 1936 final int _index; | 1936 final int _index; |
| 1937 | 1937 |
| 1938 ConstFieldElementImpl_EnumValue( | 1938 ConstFieldElementImpl_EnumValue( |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2544 class DefaultFieldFormalParameterElementImpl | 2544 class DefaultFieldFormalParameterElementImpl |
| 2545 extends FieldFormalParameterElementImpl with ConstVariableElement { | 2545 extends FieldFormalParameterElementImpl with ConstVariableElement { |
| 2546 /** | 2546 /** |
| 2547 * Initialize a newly created parameter element to have the given [name] and | 2547 * Initialize a newly created parameter element to have the given [name] and |
| 2548 * [nameOffset]. | 2548 * [nameOffset]. |
| 2549 */ | 2549 */ |
| 2550 DefaultFieldFormalParameterElementImpl(String name, int nameOffset) | 2550 DefaultFieldFormalParameterElementImpl(String name, int nameOffset) |
| 2551 : super(name, nameOffset); | 2551 : super(name, nameOffset); |
| 2552 | 2552 |
| 2553 /** | 2553 /** |
| 2554 * Initialize using the given kernel. |
| 2555 */ |
| 2556 DefaultFieldFormalParameterElementImpl.forKernel(ElementImpl enclosingElement, |
| 2557 kernel.VariableDeclaration kernel, ParameterKind parameterKind) |
| 2558 : super.forKernel(enclosingElement, kernel, parameterKind); |
| 2559 |
| 2560 /** |
| 2554 * Initialize a newly created parameter element to have the given [name]. | 2561 * Initialize a newly created parameter element to have the given [name]. |
| 2555 */ | 2562 */ |
| 2556 DefaultFieldFormalParameterElementImpl.forNode(Identifier name) | 2563 DefaultFieldFormalParameterElementImpl.forNode(Identifier name) |
| 2557 : super.forNode(name); | 2564 : super.forNode(name); |
| 2558 | 2565 |
| 2559 /** | 2566 /** |
| 2560 * Initialize using the given serialized information. | 2567 * Initialize using the given serialized information. |
| 2561 */ | 2568 */ |
| 2562 DefaultFieldFormalParameterElementImpl.forSerialized( | 2569 DefaultFieldFormalParameterElementImpl.forSerialized( |
| 2563 UnlinkedParam unlinkedParam, ElementImpl enclosingElement) | 2570 UnlinkedParam unlinkedParam, ElementImpl enclosingElement) |
| 2564 : super.forSerialized(unlinkedParam, enclosingElement); | 2571 : super.forSerialized(unlinkedParam, enclosingElement); |
| 2565 } | 2572 } |
| 2566 | 2573 |
| 2567 /** | 2574 /** |
| 2568 * A [ParameterElement] for parameters that have an initializer. | 2575 * A [ParameterElement] for parameters that have an initializer. |
| 2569 */ | 2576 */ |
| 2570 class DefaultParameterElementImpl extends ParameterElementImpl | 2577 class DefaultParameterElementImpl extends ParameterElementImpl |
| 2571 with ConstVariableElement { | 2578 with ConstVariableElement { |
| 2572 /** | 2579 /** |
| 2573 * Initialize a newly created parameter element to have the given [name] and | 2580 * Initialize a newly created parameter element to have the given [name] and |
| 2574 * [nameOffset]. | 2581 * [nameOffset]. |
| 2575 */ | 2582 */ |
| 2576 DefaultParameterElementImpl(String name, int nameOffset) | 2583 DefaultParameterElementImpl(String name, int nameOffset) |
| 2577 : super(name, nameOffset); | 2584 : super(name, nameOffset); |
| 2578 | 2585 |
| 2579 /** | 2586 /** |
| 2587 * Initialize using the given kernel. |
| 2588 */ |
| 2589 DefaultParameterElementImpl.forKernel(ElementImpl enclosingElement, |
| 2590 kernel.VariableDeclaration kernel, ParameterKind parameterKind) |
| 2591 : super.forKernel(enclosingElement, kernel, parameterKind); |
| 2592 |
| 2593 /** |
| 2580 * Initialize a newly created parameter element to have the given [name]. | 2594 * Initialize a newly created parameter element to have the given [name]. |
| 2581 */ | 2595 */ |
| 2582 DefaultParameterElementImpl.forNode(Identifier name) : super.forNode(name); | 2596 DefaultParameterElementImpl.forNode(Identifier name) : super.forNode(name); |
| 2583 | 2597 |
| 2584 /** | 2598 /** |
| 2585 * Initialize using the given serialized information. | 2599 * Initialize using the given serialized information. |
| 2586 */ | 2600 */ |
| 2587 DefaultParameterElementImpl.forSerialized( | 2601 DefaultParameterElementImpl.forSerialized( |
| 2588 UnlinkedParam unlinkedParam, ElementImpl enclosingElement) | 2602 UnlinkedParam unlinkedParam, ElementImpl enclosingElement) |
| 2589 : super.forSerialized(unlinkedParam, enclosingElement); | 2603 : super.forSerialized(unlinkedParam, enclosingElement); |
| (...skipping 1844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4434 FieldElement _field; | 4448 FieldElement _field; |
| 4435 | 4449 |
| 4436 /** | 4450 /** |
| 4437 * Initialize a newly created parameter element to have the given [name] and | 4451 * Initialize a newly created parameter element to have the given [name] and |
| 4438 * [nameOffset]. | 4452 * [nameOffset]. |
| 4439 */ | 4453 */ |
| 4440 FieldFormalParameterElementImpl(String name, int nameOffset) | 4454 FieldFormalParameterElementImpl(String name, int nameOffset) |
| 4441 : super(name, nameOffset); | 4455 : super(name, nameOffset); |
| 4442 | 4456 |
| 4443 /** | 4457 /** |
| 4458 * Initialize using the given kernel. |
| 4459 */ |
| 4460 FieldFormalParameterElementImpl.forKernel(ElementImpl enclosingElement, |
| 4461 kernel.VariableDeclaration kernel, ParameterKind parameterKind) |
| 4462 : super.forKernel(enclosingElement, kernel, parameterKind); |
| 4463 |
| 4464 /** |
| 4444 * Initialize a newly created parameter element to have the given [name]. | 4465 * Initialize a newly created parameter element to have the given [name]. |
| 4445 */ | 4466 */ |
| 4446 FieldFormalParameterElementImpl.forNode(Identifier name) | 4467 FieldFormalParameterElementImpl.forNode(Identifier name) |
| 4447 : super.forNode(name); | 4468 : super.forNode(name); |
| 4448 | 4469 |
| 4449 /** | 4470 /** |
| 4450 * Initialize using the given serialized information. | 4471 * Initialize using the given serialized information. |
| 4451 */ | 4472 */ |
| 4452 FieldFormalParameterElementImpl.forSerialized( | 4473 FieldFormalParameterElementImpl.forSerialized( |
| 4453 UnlinkedParam unlinkedParam, ElementImpl enclosingElement) | 4474 UnlinkedParam unlinkedParam, ElementImpl enclosingElement) |
| (...skipping 3477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7931 } | 7952 } |
| 7932 | 7953 |
| 7933 /** | 7954 /** |
| 7934 * Create and return [ParameterElement]s for the given [function]. | 7955 * Create and return [ParameterElement]s for the given [function]. |
| 7935 */ | 7956 */ |
| 7936 static List<ParameterElement> forKernelFunction( | 7957 static List<ParameterElement> forKernelFunction( |
| 7937 ElementImpl enclosingElement, kernel.FunctionNode function) { | 7958 ElementImpl enclosingElement, kernel.FunctionNode function) { |
| 7938 if (function.positionalParameters.isNotEmpty || | 7959 if (function.positionalParameters.isNotEmpty || |
| 7939 function.namedParameters.isNotEmpty) { | 7960 function.namedParameters.isNotEmpty) { |
| 7940 var parameters = <ParameterElement>[]; | 7961 var parameters = <ParameterElement>[]; |
| 7962 |
| 7963 // Add positional required and optional parameters. |
| 7941 for (int i = 0; i < function.positionalParameters.length; i++) { | 7964 for (int i = 0; i < function.positionalParameters.length; i++) { |
| 7942 parameters.add(new ParameterElementImpl.forKernel( | 7965 kernel.VariableDeclaration parameter = function.positionalParameters[i]; |
| 7943 enclosingElement, | 7966 if (i < function.requiredParameterCount) { |
| 7944 function.positionalParameters[i], | 7967 if (parameter.isFieldFormal) { |
| 7945 i < function.requiredParameterCount | 7968 parameters.add(new FieldFormalParameterElementImpl.forKernel( |
| 7946 ? ParameterKind.REQUIRED | 7969 enclosingElement, parameter, ParameterKind.REQUIRED)); |
| 7947 : ParameterKind.POSITIONAL)); | 7970 } else { |
| 7971 parameters.add(new ParameterElementImpl.forKernel( |
| 7972 enclosingElement, parameter, ParameterKind.REQUIRED)); |
| 7973 } |
| 7974 } else { |
| 7975 if (parameter.isFieldFormal) { |
| 7976 parameters.add(new DefaultFieldFormalParameterElementImpl.forKernel( |
| 7977 enclosingElement, parameter, ParameterKind.POSITIONAL)); |
| 7978 } else { |
| 7979 parameters.add(new DefaultParameterElementImpl.forKernel( |
| 7980 enclosingElement, parameter, ParameterKind.POSITIONAL)); |
| 7981 } |
| 7982 } |
| 7948 } | 7983 } |
| 7984 |
| 7985 // Add named parameters. |
| 7949 for (var k in function.namedParameters) { | 7986 for (var k in function.namedParameters) { |
| 7950 parameters.add(new ParameterElementImpl.forKernel( | 7987 if (k.isFieldFormal) { |
| 7951 enclosingElement, k, ParameterKind.NAMED)); | 7988 parameters.add(new DefaultFieldFormalParameterElementImpl.forKernel( |
| 7989 enclosingElement, k, ParameterKind.NAMED)); |
| 7990 } else { |
| 7991 parameters.add(new DefaultParameterElementImpl.forKernel( |
| 7992 enclosingElement, k, ParameterKind.NAMED)); |
| 7993 } |
| 7952 } | 7994 } |
| 7995 |
| 7953 return parameters; | 7996 return parameters; |
| 7954 } else { | 7997 } else { |
| 7955 return const <ParameterElement>[]; | 7998 return const <ParameterElement>[]; |
| 7956 } | 7999 } |
| 7957 } | 8000 } |
| 7958 | 8001 |
| 7959 /** | 8002 /** |
| 7960 * Create and return [ParameterElement]s for the given [unlinkedParameters]. | 8003 * Create and return [ParameterElement]s for the given [unlinkedParameters]. |
| 7961 */ | 8004 */ |
| 7962 static List<ParameterElement> resynthesizeList( | 8005 static List<ParameterElement> resynthesizeList( |
| (...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9246 | 9289 |
| 9247 @override | 9290 @override |
| 9248 DartObject computeConstantValue() => null; | 9291 DartObject computeConstantValue() => null; |
| 9249 | 9292 |
| 9250 @override | 9293 @override |
| 9251 void visitChildren(ElementVisitor visitor) { | 9294 void visitChildren(ElementVisitor visitor) { |
| 9252 super.visitChildren(visitor); | 9295 super.visitChildren(visitor); |
| 9253 _initializer?.accept(visitor); | 9296 _initializer?.accept(visitor); |
| 9254 } | 9297 } |
| 9255 } | 9298 } |
| OLD | NEW |