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

Unified Diff: pkg/fasta/lib/src/builder/class_builder.dart

Issue 2629063005: Fasta builders. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: pkg/fasta/lib/src/builder/class_builder.dart
diff --git a/pkg/fasta/lib/src/builder/class_builder.dart b/pkg/fasta/lib/src/builder/class_builder.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2a8f63ec6f3bc69ce4e79f6405356ca07402f16b
--- /dev/null
+++ b/pkg/fasta/lib/src/builder/class_builder.dart
@@ -0,0 +1,103 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library fasta.class_builder;
+
+import 'builder.dart' show
+ Builder,
+ ConstructorReferenceBuilder,
+ LibraryBuilder,
+ MetadataBuilder,
+ TypeBuilder,
+ TypeDeclarationBuilder,
+ TypeVariableBuilder;
+
+import 'scope.dart' show
+ AmbiguousBuilder,
+ Scope;
+
+abstract class ClassBuilder<T extends TypeBuilder, R>
+ extends TypeDeclarationBuilder<T, R> {
+ final List<TypeVariableBuilder> typeVariables;
+
+ T supertype;
+
+ List<T> interfaces;
+
+ final Map<String, Builder> members;
+
+ ClassBuilder(
+ List<MetadataBuilder> metadata, int modifiers,
+ String name, this.typeVariables, this.supertype, this.interfaces,
+ this.members, List<T> types, LibraryBuilder parent)
+ : super(metadata, modifiers, name, types, parent);
+
+ List<ConstructorReferenceBuilder> get constructorReferences => null;
+
+ Map<String, Builder> get constructors;
+
+ Map<String, Builder> get membersInScope => members;
+
+ int resolveTypes(LibraryBuilder library) {
+ Scope scope;
+ int count = 0;
+ if (types != null) {
+ scope = computeInstanceScope(library.scope);
+ for (T t in types) {
+ t.resolveIn(scope);
+ }
+ count += types.length;
+ }
+ return count;
+ }
+
+ int resolveConstructors(LibraryBuilder library) {
+ if (constructorReferences == null) return 0;
+ Scope scope = computeInstanceScope(library.scope);
+ for (ConstructorReferenceBuilder ref in constructorReferences) {
+ ref.resolveIn(scope);
+ }
+ return constructorReferences.length;
+ }
+
+ Scope computeInstanceScope(Scope parent) {
+ if (typeVariables != null) {
+ Map<String, Builder> local = <String, Builder>{};
+ for (TypeVariableBuilder t in typeVariables) {
+ local[t.name] = t;
+ }
+ parent = new Scope(local, parent, isModifiable: false);
+ }
+ return new Scope(membersInScope, parent, isModifiable: false);
+ }
+
+ Builder findStaticBuilder(String name, {bool isSetter: false}) {
Johnni Winther 2017/01/16 13:01:19 Add dartdoc. When is this used? Is it only for get
ahe 2017/01/16 15:26:33 Added: /// Lookup a static member of this class
+ Builder builder = members[name];
+ if (builder?.next != null) {
+ Builder getterBuilder;
+ Builder setterBuilder;
+ Builder current = builder;
+ while (current != null) {
+ if (current.isGetter && getterBuilder == null) {
+ getterBuilder = current;
+ } else if (current.isSetter && setterBuilder == null) {
+ setterBuilder = current;
+ } else {
+ return new AmbiguousBuilder(builder);
+ }
+ current = current.next;
+ }
+ builder = isSetter ? setterBuilder : getterBuilder;
+ }
+ if (builder == null) {
+ return null;
+ } else if (isSetter && builder.isGetter) {
+ return null;
+ } else {
+ return builder.isInstanceMember ? null : builder;
+ }
+ }
+
+ Builder findConstructorOrFactory(String name);
+}

Powered by Google App Engine
This is Rietveld 408576698