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

Side by Side Diff: compiler/java/com/google/dart/compiler/ast/LibraryUnit.java

Issue 10919133: Support for new 'export' directive in resolver (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak for parsing import/export directives Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 package com.google.dart.compiler.ast; 5 package com.google.dart.compiler.ast;
6 6
7 import com.google.common.base.Objects; 7 import com.google.common.base.Objects;
8 import com.google.common.collect.ImmutableList; 8 import com.google.common.collect.ImmutableList;
9 import com.google.common.collect.Lists; 9 import com.google.common.collect.Lists;
10 import com.google.common.collect.Sets; 10 import com.google.common.collect.Sets;
(...skipping 14 matching lines...) Expand all
25 import java.util.Set; 25 import java.util.Set;
26 import java.util.concurrent.ConcurrentSkipListMap; 26 import java.util.concurrent.ConcurrentSkipListMap;
27 27
28 /** 28 /**
29 * Represents the parsed source from a {@link LibrarySource}. 29 * Represents the parsed source from a {@link LibrarySource}.
30 */ 30 */
31 public class LibraryUnit { 31 public class LibraryUnit {
32 private final LibrarySource libSource; 32 private final LibrarySource libSource;
33 private final LibraryNode selfSourcePath; 33 private final LibraryNode selfSourcePath;
34 private final List<LibraryNode> importPaths = Lists.newArrayList(); 34 private final List<LibraryNode> importPaths = Lists.newArrayList();
35 private final List<LibraryNode> exportPaths = Lists.newArrayList();
35 private final List<LibraryNode> sourcePaths = Lists.newArrayList(); 36 private final List<LibraryNode> sourcePaths = Lists.newArrayList();
36 private final List<LibraryNode> nativePaths = Lists.newArrayList(); 37 private final List<LibraryNode> nativePaths = Lists.newArrayList();
37 38
38 private final Map<String, DartUnit> units = new ConcurrentSkipListMap<String, DartUnit>(); 39 private final Map<String, DartUnit> units = new ConcurrentSkipListMap<String, DartUnit>();
39 private final List<LibraryImport> imports = Lists.newArrayList(); 40 private final List<LibraryImport> imports = Lists.newArrayList();
41 private final List<LibraryExport> exports = Lists.newArrayList();
40 42
41 private final LibraryElement element; 43 private final LibraryElement element;
42 44
43 private LibraryDeps deps; 45 private LibraryDeps deps;
44 46
45 private LibraryNode entryNode; 47 private LibraryNode entryNode;
46 private DartUnit selfDartUnit; 48 private DartUnit selfDartUnit;
47 49
48 private String name; 50 private String name;
49 51
(...skipping 22 matching lines...) Expand all
72 if ((lastSlash = self.lastIndexOf('/')) > -1) { 74 if ((lastSlash = self.lastIndexOf('/')) > -1) {
73 self = self.substring(lastSlash + 1); 75 self = self.substring(lastSlash + 1);
74 } 76 }
75 selfSourcePath = new LibraryNode(self); 77 selfSourcePath = new LibraryNode(self);
76 } 78 }
77 79
78 public void addImportPath(LibraryNode path) { 80 public void addImportPath(LibraryNode path) {
79 assert path != null; 81 assert path != null;
80 importPaths.add(path); 82 importPaths.add(path);
81 } 83 }
84
85 public void addExportPath(LibraryNode path) {
86 assert path != null;
87 exportPaths.add(path);
88 }
82 89
83 public void addSourcePath(LibraryNode path) { 90 public void addSourcePath(LibraryNode path) {
84 assert path != null; 91 assert path != null;
85 sourcePaths.add(path); 92 sourcePaths.add(path);
86 sourceCount++; 93 sourceCount++;
87 } 94 }
88 95
89 public int getSourceCount() { 96 public int getSourceCount() {
90 return sourceCount; 97 return sourceCount;
91 } 98 }
92 99
93 public void addNativePath(LibraryNode path) { 100 public void addNativePath(LibraryNode path) {
94 assert path != null; 101 assert path != null;
95 nativePaths.add(path); 102 nativePaths.add(path);
96 } 103 }
97 104
98 public void putUnit(DartUnit unit) { 105 public void putUnit(DartUnit unit) {
99 unit.setLibrary(this); 106 unit.setLibrary(this);
100 units.put(unit.getSourceName(), unit); 107 units.put(unit.getSourceName(), unit);
101 } 108 }
102 109
103 public DartUnit getUnit(String sourceName) { 110 public DartUnit getUnit(String sourceName) {
104 return units.get(sourceName); 111 return units.get(sourceName);
105 } 112 }
106 113
107 public void addImport(LibraryUnit unit, LibraryNode node) { 114 public void addImport(LibraryUnit unit, LibraryNode node) {
108 if (unit != null) { 115 if (unit != null) {
109 if (node != null) { 116 if (node != null) {
110 imports.add(new LibraryImport(unit, node.getPrefix(), node.getCombinator s(), 117 imports.add(new LibraryImport(unit, node.getPrefix(), node.getCombinator s()));
111 node.isExported()));
112 } else { 118 } else {
113 imports.add(new LibraryImport(unit, null, ImmutableList.<ImportCombinato r> of(), false)); 119 imports.add(new LibraryImport(unit, null, ImmutableList.<ImportCombinato r> of()));
114 } 120 }
115 } 121 }
116 } 122 }
123
124 public void addExport(LibraryUnit unit, LibraryNode node) {
125 if (unit != null) {
126 if (node != null) {
127 exports.add(new LibraryExport(unit, node.getCombinators()));
128 }
129 }
130 }
117 131
118 public Collection<LibraryUnit> getLibrariesWithPrefix(String prefixToMatch) { 132 public Collection<LibraryUnit> getLibrariesWithPrefix(String prefixToMatch) {
119 List<LibraryUnit> result = Lists.newArrayList(); 133 List<LibraryUnit> result = Lists.newArrayList();
120 for (LibraryImport libraryImport : imports) { 134 for (LibraryImport libraryImport : imports) {
121 if (Objects.equal(libraryImport.getPrefix(), prefixToMatch)) { 135 if (Objects.equal(libraryImport.getPrefix(), prefixToMatch)) {
122 result.add(libraryImport.getLibrary()); 136 result.add(libraryImport.getLibrary());
123 } 137 }
124 } 138 }
125 return result; 139 return result;
126 } 140 }
127 141
128 public LibraryElement getElement() { 142 public LibraryElement getElement() {
129 return element; 143 return element;
130 } 144 }
131 145
132 public Iterable<DartUnit> getUnits() { 146 public Iterable<DartUnit> getUnits() {
133 return units.values(); 147 return units.values();
134 } 148 }
135 149
136 public Iterable<LibraryImport> getImports() { 150 public Iterable<LibraryImport> getImports() {
137 return imports; 151 return imports;
138 } 152 }
153
154 public List<LibraryExport> getExports() {
155 return exports;
156 }
139 157
140 public Iterable<LibraryUnit> getImportedLibraries() { 158 public Iterable<LibraryUnit> getImportedLibraries() {
141 Set<LibraryUnit> libraries = Sets.newHashSet(); 159 Set<LibraryUnit> libraries = Sets.newHashSet();
142 for (LibraryImport libraryImport : imports) { 160 for (LibraryImport libraryImport : imports) {
143 libraries.add(libraryImport.getLibrary()); 161 libraries.add(libraryImport.getLibrary());
144 } 162 }
145 return libraries; 163 return libraries;
146 } 164 }
147 165
148 public boolean hasImport(LibraryUnit unit) { 166 public boolean hasImport(LibraryUnit unit) {
149 return imports.contains(new LibraryImport(unit, null, ImmutableList.<ImportC ombinator> of(), 167 return imports.contains(new LibraryImport(unit, null, ImmutableList.<ImportC ombinator> of()));
150 false));
151 } 168 }
152 169
153 public DartExpression getEntryPoint() { 170 public DartExpression getEntryPoint() {
154 return entryPoint; 171 return entryPoint;
155 } 172 }
156 173
157 public void setEntryPoint(DartExpression entry) { 174 public void setEntryPoint(DartExpression entry) {
158 this.entryPoint = entry; 175 this.entryPoint = entry;
159 } 176 }
160 177
161 public DartUnit getSelfDartUnit() { 178 public DartUnit getSelfDartUnit() {
162 return this.selfDartUnit; 179 return this.selfDartUnit;
163 } 180 }
164 181
165 public void setSelfDartUnit(DartUnit unit) { 182 public void setSelfDartUnit(DartUnit unit) {
166 this.selfDartUnit = unit; 183 this.selfDartUnit = unit;
167 } 184 }
168 185
169 /** 186 /**
170 * Return a collection of paths to {@link LibrarySource}s upon which this libr ary or application 187 * Return a collection of paths to {@link LibrarySource}s upon which this libr ary or application
171 * depends. 188 * depends.
172 * 189 *
173 * @return the paths (not <code>null</code>, contains no <code>null</code>) 190 * @return the paths (not <code>null</code>, contains no <code>null</code>)
174 */ 191 */
175 public Iterable<LibraryNode> getImportPaths() { 192 public Iterable<LibraryNode> getImportPaths() {
176 return importPaths; 193 return importPaths;
177 } 194 }
195
196 public Iterable<LibraryNode> getExportPaths() {
197 return exportPaths;
198 }
178 199
179 /** 200 /**
180 * Return all prefixes used by this library. 201 * Return all prefixes used by this library.
181 */ 202 */
182 public Set<String> getPrefixes() { 203 public Set<String> getPrefixes() {
183 Set<String> result = Sets.newTreeSet(); 204 Set<String> result = Sets.newTreeSet();
184 for (LibraryImport libraryImport : imports) { 205 for (LibraryImport libraryImport : imports) {
185 String prefix = libraryImport.getPrefix(); 206 String prefix = libraryImport.getPrefix();
186 if (prefix != null) { 207 if (prefix != null) {
187 result.add(prefix); 208 result.add(prefix);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 290
270 /** 291 /**
271 * Writes this library's associated dependencies. 292 * Writes this library's associated dependencies.
272 */ 293 */
273 public void writeDeps(DartCompilerContext context) throws IOException { 294 public void writeDeps(DartCompilerContext context) throws IOException {
274 Writer writer = context.getArtifactWriter(libSource, "", DartCompiler.EXTENS ION_DEPS); 295 Writer writer = context.getArtifactWriter(libSource, "", DartCompiler.EXTENS ION_DEPS);
275 deps.write(writer); 296 deps.write(writer);
276 writer.close(); 297 writer.close();
277 } 298 }
278 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698