@Override public Source mapDartUri(String dartUri) { String libraryName; String relativePath; int index = dartUri.indexOf('/'); if (index >= 0) { libraryName = dartUri.substring(0, index); relativePath = dartUri.substring(index + 1); } else { libraryName = dartUri; relativePath = ""; } SdkLibrary library = getSdkLibrary(libraryName); if (library == null) { return null; } try { File file = new File(getLibraryDirectory(), library.getPath()); if (!relativePath.isEmpty()) { file = file.getParentFile(); file = new File(file, relativePath); } return new FileBasedSource(new URI(dartUri), file); } catch (URISyntaxException exception) { return null; } }
@Override public Source fromFileUri(URI uri) { File file = new File(uri); String filePath = file.getAbsolutePath(); String libPath = getLibraryDirectory().getAbsolutePath(); if (!filePath.startsWith(libPath + File.separator)) { return null; } filePath = filePath.substring(libPath.length() + 1); for (SdkLibrary library : libraryMap.getSdkLibraries()) { String libraryPath = library.getPath(); if (filePath.replace('\\', '/').equals(libraryPath)) { String path = library.getShortName(); try { return new FileBasedSource(new URI(path), file); } catch (URISyntaxException exception) { AnalysisEngine.getInstance() .getLogger() .logInformation("Failed to create URI: " + path, exception); return null; } } libraryPath = new File(libraryPath).getParent(); if (filePath.startsWith(libraryPath + File.separator)) { String path = library.getShortName() + "/" + filePath.substring(libraryPath.length() + 1); try { return new FileBasedSource(new URI(path), file); } catch (URISyntaxException exception) { AnalysisEngine.getInstance() .getLogger() .logInformation("Failed to create URI: " + path, exception); return null; } } } return null; }