| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 import com.google.dart.compiler.ast.DartUnit; | 29 import com.google.dart.compiler.ast.DartUnit; |
| 30 import com.google.dart.compiler.metrics.CompilerMetrics; | 30 import com.google.dart.compiler.metrics.CompilerMetrics; |
| 31 import com.google.dart.compiler.parser.DartParser; | 31 import com.google.dart.compiler.parser.DartParser; |
| 32 import com.google.dart.compiler.util.DartSourceString; | 32 import com.google.dart.compiler.util.DartSourceString; |
| 33 | 33 |
| 34 import java.io.File; | 34 import java.io.File; |
| 35 import java.io.FileInputStream; | 35 import java.io.FileInputStream; |
| 36 import java.io.IOException; | 36 import java.io.IOException; |
| 37 import java.io.InputStreamReader; | 37 import java.io.InputStreamReader; |
| 38 import java.io.Reader; | 38 import java.io.Reader; |
| 39 import java.net.URI; |
| 39 import java.nio.charset.Charset; | 40 import java.nio.charset.Charset; |
| 41 import java.util.ArrayList; |
| 40 import java.util.HashMap; | 42 import java.util.HashMap; |
| 41 import java.util.HashSet; | 43 import java.util.HashSet; |
| 42 import java.util.List; | 44 import java.util.List; |
| 43 import java.util.Map; | 45 import java.util.Map; |
| 44 | 46 |
| 45 /** | 47 /** |
| 46 * A reader that parses and reads the libraries dart-sdk/lib/_internal/libraries
.dart file | 48 * A reader that parses and reads the libraries dart-sdk/lib/_internal/libraries
.dart file |
| 47 * for system library information | 49 * for system library information |
| 48 * | 50 * |
| 49 * library information is in the format | 51 * library information is in the format |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 152 } |
| 151 if (arg instanceof DartNamedExpression){ | 153 if (arg instanceof DartNamedExpression){ |
| 152 String name = ((DartNamedExpression) arg).getName().getName(); | 154 String name = ((DartNamedExpression) arg).getName().getName(); |
| 153 DartExpression expression = ((DartNamedExpression) arg).getExpressio
n(); | 155 DartExpression expression = ((DartNamedExpression) arg).getExpressio
n(); |
| 154 if (name.equals(CATEGORY)){ | 156 if (name.equals(CATEGORY)){ |
| 155 library.setCategory(((DartStringLiteral) expression).getValue()); | 157 library.setCategory(((DartStringLiteral) expression).getValue()); |
| 156 } else if (name.equals(IMPLEMENTATION)){ | 158 } else if (name.equals(IMPLEMENTATION)){ |
| 157 library.setImplementation(((DartBooleanLiteral)expression).getValu
e()); | 159 library.setImplementation(((DartBooleanLiteral)expression).getValu
e()); |
| 158 } else if (name.equals(DOCUMENTED)){ | 160 } else if (name.equals(DOCUMENTED)){ |
| 159 library.setDocumented(((DartBooleanLiteral)expression).getValue())
; | 161 library.setDocumented(((DartBooleanLiteral)expression).getValue())
; |
| 162 } else if (name.equals(PATCH_PATH)) { |
| 163 String path = ((DartStringLiteral) expression).getValue(); |
| 164 URI uri = sdkLibPath.getAbsoluteFile().toURI().resolve(URI.create(
path)); |
| 165 patchPaths.add(uri); |
| 160 } else if (name.equals(PLATFORMS)){ | 166 } else if (name.equals(PLATFORMS)){ |
| 161 if (expression instanceof DartIdentifier){ | 167 if (expression instanceof DartIdentifier){ |
| 162 String identifier = ((DartIdentifier)expression).getName(); | 168 String identifier = ((DartIdentifier)expression).getName(); |
| 163 if (identifier.equals("VM_PLATFORM")) { | 169 if (identifier.equals("VM_PLATFORM")) { |
| 164 library.setPlatforms(VM_PLATFORM); | 170 library.setPlatforms(VM_PLATFORM); |
| 165 } else { | 171 } else { |
| 166 library.setPlatforms(DART2JS_PLATFORM); | 172 library.setPlatforms(DART2JS_PLATFORM); |
| 167 } | 173 } |
| 168 } | 174 } |
| 169 } | 175 } |
| 170 } | 176 } |
| 171 } | 177 } |
| 172 librariesMap.put(keyString,library); | 178 librariesMap.put(keyString,library); |
| 173 } | 179 } |
| 174 return null; | 180 return null; |
| 175 } | 181 } |
| 176 | 182 |
| 177 } | 183 } |
| 178 | 184 |
| 179 | 185 |
| 180 public static final String LIBRARIES_FILE = "libraries.dart"; | 186 public static final String LIBRARIES_FILE = "libraries.dart"; |
| 181 public static final String INTERNAL_DIR = "_internal"; | 187 public static final String INTERNAL_DIR = "_internal"; |
| 182 | 188 |
| 183 private static final String IMPLEMENTATION = "implementation"; | 189 private static final String IMPLEMENTATION = "implementation"; |
| 184 private static final String DOCUMENTED = "documented"; | 190 private static final String DOCUMENTED = "documented"; |
| 185 private static final String CATEGORY = "category"; | 191 private static final String CATEGORY = "category"; |
| 192 private static final String PATCH_PATH = "dart2jsPatchPath"; |
| 186 private static final String PLATFORMS = "platforms"; | 193 private static final String PLATFORMS = "platforms"; |
| 187 | 194 |
| 195 |
| 188 private static final int DART2JS_PLATFORM = 1; | 196 private static final int DART2JS_PLATFORM = 1; |
| 189 private static final int VM_PLATFORM = 2; | 197 private static final int VM_PLATFORM = 2; |
| 190 | 198 |
| 191 private final File sdkLibPath; | 199 private final File sdkLibPath; |
| 192 private final Map<String, DartLibrary> librariesMap = new HashMap<String, Dart
Library>(); | 200 private final Map<String, DartLibrary> librariesMap = new HashMap<String, Dart
Library>(); |
| 193 | 201 private final List<URI> patchPaths = new ArrayList<URI>(); |
| 194 | 202 |
| 195 public SystemLibrariesReader(File sdkLibPath) { | 203 public SystemLibrariesReader(File sdkLibPath) { |
| 196 this.sdkLibPath =sdkLibPath; | 204 this.sdkLibPath =sdkLibPath; |
| 197 loadLibraryInfo(); | 205 loadLibraryInfo(); |
| 198 } | 206 } |
| 199 | 207 |
| 200 public Map<String, DartLibrary> getLibrariesMap() { | 208 public Map<String, DartLibrary> getLibrariesMap() { |
| 201 return librariesMap; | 209 return librariesMap; |
| 202 } | 210 } |
| 203 | 211 |
| 212 public List<URI> getPatchPaths() { |
| 213 return patchPaths; |
| 214 } |
| 215 |
| 204 private void loadLibraryInfo(){ | 216 private void loadLibraryInfo(){ |
| 205 File librariesFile = getLibrariesFile(); | 217 File librariesFile = getLibrariesFile(); |
| 206 | 218 |
| 207 DartUnit unit = getDartUnit(librariesFile); | 219 DartUnit unit = getDartUnit(librariesFile); |
| 208 | 220 |
| 209 List<DartNode> nodes = unit.getTopLevelNodes(); | 221 List<DartNode> nodes = unit.getTopLevelNodes(); |
| 210 for (DartNode node : nodes){ | 222 for (DartNode node : nodes){ |
| 211 if (node instanceof DartFieldDefinition){ | 223 if (node instanceof DartFieldDefinition){ |
| 212 node.accept(new LibrariesFileAstVistor()); | 224 node.accept(new LibrariesFileAstVistor()); |
| 213 } | 225 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 private File getLibrariesFile() { | 265 private File getLibrariesFile() { |
| 254 File file = new File(new File(sdkLibPath, INTERNAL_DIR), LIBRARIES_FILE); | 266 File file = new File(new File(sdkLibPath, INTERNAL_DIR), LIBRARIES_FILE); |
| 255 if (!file.exists()) { | 267 if (!file.exists()) { |
| 256 throw new InternalCompilerException("Failed to find " + file.toString() | 268 throw new InternalCompilerException("Failed to find " + file.toString() |
| 257 + ". Is dart-sdk path correct?"); | 269 + ". Is dart-sdk path correct?"); |
| 258 } | 270 } |
| 259 return file; | 271 return file; |
| 260 } | 272 } |
| 261 | 273 |
| 262 } | 274 } |
| OLD | NEW |