Chromium Code Reviews| Index: pkg/analysis_server/lib/src/services/correction/util.dart |
| diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart |
| index f48c2fc23892c36b201be1a1e6abeb8543aba631..b4f993857b666ba261fbcbf84a87520fa8b42669 100644 |
| --- a/pkg/analysis_server/lib/src/services/correction/util.dart |
| +++ b/pkg/analysis_server/lib/src/services/correction/util.dart |
| @@ -143,6 +143,18 @@ List<SourceRange> getCommentRanges(CompilationUnit unit) { |
| return ranges; |
| } |
| +/** |
| + * Return the given [element] if it is a [CompilationUnitElement]. |
| + * Return the enclosing [CompilationUnitElement] of the given [element], |
| + * maybe `null`. |
| + */ |
| +CompilationUnitElement getCompilationUnitElement(Element element) { |
| + if (element is CompilationUnitElement) { |
| + return element; |
| + } |
| + return element.getAncestor((e) => e is CompilationUnitElement); |
| +} |
| + |
| String getDefaultValueCode(DartType type) { |
| if (type != null) { |
| String typeName = type.displayName; |
| @@ -441,8 +453,7 @@ List<AstNode> getParents(AstNode node) { |
| * The resulting AST structure may or may not be resolved. |
| */ |
| AstNode getParsedClassElementNode(ClassElement classElement) { |
| - CompilationUnitElement unitElement = |
| - classElement.getAncestor((e) => e is CompilationUnitElement); |
| + CompilationUnitElement unitElement = getCompilationUnitElement(classElement); |
|
Brian Wilkerson
2015/09/30 00:48:31
Not sure what value this refactoring has. The meth
|
| CompilationUnit unit = getParsedUnit(unitElement); |
| int offset = classElement.nameOffset; |
| AstNode classNameNode = new NodeLocator(offset).searchWithin(unit); |