| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library analyzer_impl; | 5 library analyzer_impl; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'generated/java_io.dart'; | 10 import 'generated/java_io.dart'; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 status = status.max(severity); | 64 status = status.max(severity); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 return status; | 67 return status; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void prepareAnalysisContext(JavaFile sourceFile) { | 70 void prepareAnalysisContext(JavaFile sourceFile) { |
| 71 List<UriResolver> resolvers = [new DartUriResolver(sdk), new FileUriResolver
()]; | 71 List<UriResolver> resolvers = [new DartUriResolver(sdk), new FileUriResolver
()]; |
| 72 // may be add package resolver | 72 // may be add package resolver |
| 73 { | 73 { |
| 74 var packageDirectory = getPackageDirectoryFor(sourceFile); | 74 JavaFile packageDirectory; |
| 75 if (options.packageRootPath != null) { |
| 76 packageDirectory = new JavaFile(options.packageRootPath); |
| 77 } else { |
| 78 packageDirectory = getPackageDirectoryFor(sourceFile); |
| 79 } |
| 75 if (packageDirectory != null) { | 80 if (packageDirectory != null) { |
| 76 resolvers.add(new PackageUriResolver([packageDirectory])); | 81 resolvers.add(new PackageUriResolver([packageDirectory])); |
| 77 } | 82 } |
| 78 } | 83 } |
| 79 sourceFactory = new SourceFactory.con1(contentCache, resolvers); | 84 sourceFactory = new SourceFactory.con1(contentCache, resolvers); |
| 80 context = AnalysisEngine.instance.createAnalysisContext(); | 85 context = AnalysisEngine.instance.createAnalysisContext(); |
| 81 context.sourceFactory = sourceFactory; | 86 context.sourceFactory = sourceFactory; |
| 82 } | 87 } |
| 83 | 88 |
| 84 /// Fills [sources]. | 89 /// Fills [sources]. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 136 |
| 132 /// Fills [errorInfos]. | 137 /// Fills [errorInfos]. |
| 133 void prepareErrors() { | 138 void prepareErrors() { |
| 134 for (Source source in sources) { | 139 for (Source source in sources) { |
| 135 var sourceErrors = context.getErrors(source); | 140 var sourceErrors = context.getErrors(source); |
| 136 errorInfos.add(sourceErrors); | 141 errorInfos.add(sourceErrors); |
| 137 } | 142 } |
| 138 } | 143 } |
| 139 | 144 |
| 140 static JavaFile getPackageDirectoryFor(JavaFile sourceFile) { | 145 static JavaFile getPackageDirectoryFor(JavaFile sourceFile) { |
| 141 JavaFile sourceFolder = sourceFile.getParentFile(); | 146 // we are going to ask parent file, so get absolute path |
| 142 JavaFile packagesFolder = new JavaFile.relative(sourceFolder, "packages"); | 147 sourceFile = sourceFile.getAbsoluteFile(); |
| 143 if (packagesFolder.exists()) { | 148 // look in the containing directories |
| 144 return packagesFolder; | 149 JavaFile dir = sourceFile.getParentFile(); |
| 150 while (dir != null) { |
| 151 JavaFile packagesDir = new JavaFile.relative(dir, "packages"); |
| 152 if (packagesDir.exists()) { |
| 153 return packagesDir; |
| 154 } |
| 155 dir = dir.getParentFile(); |
| 145 } | 156 } |
| 157 // not found |
| 146 return null; | 158 return null; |
| 147 } | 159 } |
| 148 } | 160 } |
| OLD | NEW |