Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: pkg/analysis_server/lib/src/services/correction/util.dart

Issue 1375043004: Issue 24459. Fix for 'Create Method' QF in different unit. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698