OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.tools.core.utilities.compiler; | 14 package com.google.dart.tools.core.utilities.compiler; |
15 | 15 |
| 16 import com.google.common.collect.Sets; |
16 import com.google.dart.compiler.CommandLineOptions.CompilerOptions; | 17 import com.google.dart.compiler.CommandLineOptions.CompilerOptions; |
17 import com.google.dart.compiler.CompilerConfiguration; | 18 import com.google.dart.compiler.CompilerConfiguration; |
18 import com.google.dart.compiler.DartArtifactProvider; | 19 import com.google.dart.compiler.DartArtifactProvider; |
19 import com.google.dart.compiler.DartCompilationError; | 20 import com.google.dart.compiler.DartCompilationError; |
20 import com.google.dart.compiler.DartCompiler; | 21 import com.google.dart.compiler.DartCompiler; |
21 import com.google.dart.compiler.DartCompilerListener; | 22 import com.google.dart.compiler.DartCompilerListener; |
22 import com.google.dart.compiler.DartSource; | 23 import com.google.dart.compiler.DartSource; |
23 import com.google.dart.compiler.DefaultCompilerConfiguration; | 24 import com.google.dart.compiler.DefaultCompilerConfiguration; |
24 import com.google.dart.compiler.LibrarySource; | 25 import com.google.dart.compiler.LibrarySource; |
25 import com.google.dart.compiler.Source; | 26 import com.google.dart.compiler.Source; |
26 import com.google.dart.compiler.SourceDelta; | 27 import com.google.dart.compiler.SourceDelta; |
27 import com.google.dart.compiler.SystemLibraryManager; | 28 import com.google.dart.compiler.SystemLibraryManager; |
28 import com.google.dart.compiler.ast.DartNode; | 29 import com.google.dart.compiler.ast.DartNode; |
29 import com.google.dart.compiler.ast.DartUnit; | 30 import com.google.dart.compiler.ast.DartUnit; |
30 import com.google.dart.compiler.ast.LibraryUnit; | 31 import com.google.dart.compiler.ast.LibraryUnit; |
31 import com.google.dart.compiler.parser.CommentPreservingParser; | |
32 import com.google.dart.compiler.parser.DartParser; | 32 import com.google.dart.compiler.parser.DartParser; |
33 import com.google.dart.compiler.resolver.LibraryElement; | 33 import com.google.dart.compiler.resolver.LibraryElement; |
34 import com.google.dart.compiler.util.DartSourceString; | 34 import com.google.dart.compiler.util.DartSourceString; |
35 import com.google.dart.tools.core.DartCore; | 35 import com.google.dart.tools.core.DartCore; |
36 import com.google.dart.tools.core.analysis.AnalysisServer; | 36 import com.google.dart.tools.core.analysis.AnalysisServer; |
37 import com.google.dart.tools.core.internal.builder.LocalArtifactProvider; | 37 import com.google.dart.tools.core.internal.builder.LocalArtifactProvider; |
38 import com.google.dart.tools.core.internal.builder.RootArtifactProvider; | 38 import com.google.dart.tools.core.internal.builder.RootArtifactProvider; |
39 import com.google.dart.tools.core.internal.cache.LRUCache; | 39 import com.google.dart.tools.core.internal.cache.LRUCache; |
40 import com.google.dart.tools.core.internal.model.CompilationUnitImpl; | 40 import com.google.dart.tools.core.internal.model.CompilationUnitImpl; |
41 import com.google.dart.tools.core.internal.model.DartLibraryImpl; | 41 import com.google.dart.tools.core.internal.model.DartLibraryImpl; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 this.source = source; | 393 this.source = source; |
394 this.preserveComments = preserveComments; | 394 this.preserveComments = preserveComments; |
395 } | 395 } |
396 | 396 |
397 @Override | 397 @Override |
398 public void run() throws Exception { | 398 public void run() throws Exception { |
399 result = secureParseUnit(createParser(), sourceRef); | 399 result = secureParseUnit(createParser(), sourceRef); |
400 } | 400 } |
401 | 401 |
402 private DartParser createParser() { | 402 private DartParser createParser() { |
403 if (preserveComments) { | 403 return new DartParser(sourceRef, source, false, Sets.<String> newHashSet()
, this, null); |
404 return new CommentPreservingParser(CommentPreservingParser.createContext
( | |
405 sourceRef, | |
406 source, | |
407 this), false); | |
408 } else { | |
409 return new DartParser(sourceRef, source, this); | |
410 } | |
411 } | 404 } |
412 } | 405 } |
413 | 406 |
414 /** | 407 /** |
415 * Internal class for safely calling the | 408 * Internal class for safely calling the |
416 * {@link DartCompiler#analyzeLibrary(LibrarySource, Map, CompilerConfiguratio
n, DartArtifactProvider, DartCompilerListener)} | 409 * {@link DartCompiler#analyzeLibrary(LibrarySource, Map, CompilerConfiguratio
n, DartArtifactProvider, DartCompilerListener)} |
417 * , recording compilation errors, and capturing any parser exception. | 410 * , recording compilation errors, and capturing any parser exception. |
418 */ | 411 */ |
419 private static final class ResolverRunnable extends CompilerRunner { | 412 private static final class ResolverRunnable extends CompilerRunner { |
420 private LibrarySource librarySource; | 413 private LibrarySource librarySource; |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 performanceListener.compileComplete(start, libSource.getName()); | 869 performanceListener.compileComplete(start, libSource.getName()); |
877 } | 870 } |
878 } | 871 } |
879 | 872 |
880 /** | 873 /** |
881 * A synchronized call to {@link DartParser#parseUnit(DartSource)} | 874 * A synchronized call to {@link DartParser#parseUnit(DartSource)} |
882 */ | 875 */ |
883 public static DartUnit secureParseUnit(DartParser parser, DartSource sourceRef
) { | 876 public static DartUnit secureParseUnit(DartParser parser, DartSource sourceRef
) { |
884 // All calls to DartC must be synchronized | 877 // All calls to DartC must be synchronized |
885 synchronized (compilerLock) { | 878 synchronized (compilerLock) { |
886 return parser.parseUnit(sourceRef); | 879 return parser.parseUnit(); |
887 } | 880 } |
888 } | 881 } |
889 | 882 |
890 public static void setPerformanceListener(PerformanceListener performanceListe
ner) { | 883 public static void setPerformanceListener(PerformanceListener performanceListe
ner) { |
891 DartCompilerUtilities.performanceListener = performanceListener; | 884 DartCompilerUtilities.performanceListener = performanceListener; |
892 } | 885 } |
893 | 886 |
894 private static Map<URI, DartUnit> createMap(Collection<DartUnit> suppliedUnits
) { | 887 private static Map<URI, DartUnit> createMap(Collection<DartUnit> suppliedUnits
) { |
895 if (suppliedUnits == null || suppliedUnits.isEmpty()) { | 888 if (suppliedUnits == null || suppliedUnits.isEmpty()) { |
896 return null; | 889 return null; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 } else if (secondScheme == null || !firstScheme.equals(secondScheme)) { | 938 } else if (secondScheme == null || !firstScheme.equals(secondScheme)) { |
946 return false; | 939 return false; |
947 } else if (SystemLibraryManager.isDartUri(firstUri) | 940 } else if (SystemLibraryManager.isDartUri(firstUri) |
948 || SystemLibraryManager.isDartUri(secondUri)) { | 941 || SystemLibraryManager.isDartUri(secondUri)) { |
949 return URIUtilities.safelyResolveDartUri(firstUri).equals( | 942 return URIUtilities.safelyResolveDartUri(firstUri).equals( |
950 URIUtilities.safelyResolveDartUri(secondUri)); | 943 URIUtilities.safelyResolveDartUri(secondUri)); |
951 } | 944 } |
952 return URIUtil.toPath(firstUri).equals(URIUtil.toPath(secondUri)); | 945 return URIUtil.toPath(firstUri).equals(URIUtil.toPath(secondUri)); |
953 } | 946 } |
954 } | 947 } |
OLD | NEW |