Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1771243002: Change when enum constant elements are created to fix bug in re-creating ASTs from existing element… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.generated.resolver; 5 library analyzer.src.generated.resolver;
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 3390 matching lines...) Expand 10 before | Expand all | Expand 10 after
3401 fields.add(valuesField); 3401 fields.add(valuesField);
3402 getters.add(_createGetter(valuesField)); 3402 getters.add(_createGetter(valuesField));
3403 // 3403 //
3404 // Build the enum constants. 3404 // Build the enum constants.
3405 // 3405 //
3406 NodeList<EnumConstantDeclaration> constants = node.constants; 3406 NodeList<EnumConstantDeclaration> constants = node.constants;
3407 List<DartObjectImpl> constantValues = new List<DartObjectImpl>(); 3407 List<DartObjectImpl> constantValues = new List<DartObjectImpl>();
3408 int constantCount = constants.length; 3408 int constantCount = constants.length;
3409 for (int i = 0; i < constantCount; i++) { 3409 for (int i = 0; i < constantCount; i++) {
3410 EnumConstantDeclaration constant = constants[i]; 3410 EnumConstantDeclaration constant = constants[i];
3411 SimpleIdentifier constantName = constant.name; 3411 FieldElementImpl constantField = constant.name.staticElement;
3412 FieldElementImpl constantField =
3413 new ConstFieldElementImpl.forNode(constantName);
3414 constantField.static = true;
3415 constantField.const3 = true;
3416 constantField.type = enumType;
3417 setElementDocumentationComment(constantField, constant);
3418 // 3412 //
3419 // Create a value for the constant. 3413 // Create a value for the constant.
3420 // 3414 //
3421 HashMap<String, DartObjectImpl> fieldMap = 3415 HashMap<String, DartObjectImpl> fieldMap =
3422 new HashMap<String, DartObjectImpl>(); 3416 new HashMap<String, DartObjectImpl>();
3423 fieldMap[indexFieldName] = new DartObjectImpl(intType, new IntState(i)); 3417 fieldMap[indexFieldName] = new DartObjectImpl(intType, new IntState(i));
3424 DartObjectImpl value = 3418 DartObjectImpl value =
3425 new DartObjectImpl(enumType, new GenericState(fieldMap)); 3419 new DartObjectImpl(enumType, new GenericState(fieldMap));
3426 constantValues.add(value); 3420 constantValues.add(value);
3427 constantField.evaluationResult = new EvaluationResultImpl(value); 3421 constantField.evaluationResult = new EvaluationResultImpl(value);
3428 fields.add(constantField); 3422 fields.add(constantField);
3429 getters.add(_createGetter(constantField)); 3423 getters.add(constantField.getter);
3430 constantName.staticElement = constantField;
3431 } 3424 }
3432 // 3425 //
3433 // Build the value of the 'values' field. 3426 // Build the value of the 'values' field.
3434 // 3427 //
3435 valuesField.evaluationResult = new EvaluationResultImpl( 3428 valuesField.evaluationResult = new EvaluationResultImpl(
3436 new DartObjectImpl(valuesField.type, new ListState(constantValues))); 3429 new DartObjectImpl(valuesField.type, new ListState(constantValues)));
3437 // 3430 //
3438 // Finish building the enum. 3431 // Finish building the enum.
3439 // 3432 //
3440 enumElement.fields = fields; 3433 enumElement.fields = fields;
(...skipping 9535 matching lines...) Expand 10 before | Expand all | Expand 10 after
12976 nonFields.add(node); 12969 nonFields.add(node);
12977 return null; 12970 return null;
12978 } 12971 }
12979 12972
12980 @override 12973 @override
12981 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 12974 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
12982 12975
12983 @override 12976 @override
12984 Object visitWithClause(WithClause node) => null; 12977 Object visitWithClause(WithClause node) => null;
12985 } 12978 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/builder.dart ('k') | pkg/analyzer/test/generated/declaration_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698