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

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

Issue 1047673005: Use parsed unit/class nodes instead of resolved in fixes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c19a4c8e55b3f03c656f8960fde9b28b8acc74db..c40907dbf2d3753af8eda528a26adbdd39ede252 100644
--- a/pkg/analysis_server/lib/src/services/correction/util.dart
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart
@@ -27,7 +27,8 @@ import 'package:path/path.dart';
*/
void addLibraryImports(SourceChange change, LibraryElement targetLibrary,
Set<LibraryElement> libraries) {
- CompilationUnit libUnit = targetLibrary.definingCompilationUnit.node;
+ CompilationUnitElement libUnitElement = targetLibrary.definingCompilationUnit;
+ CompilationUnit libUnit = getParsedUnit(libUnitElement);
// prepare new import location
int offset = 0;
String prefix;
@@ -113,6 +114,16 @@ String findAbsoluteUri(AnalysisContext context, String path) {
}
/**
+ * Returns the EOL to use for the given [code].
+ */
+String getCodeEndOfLine(String code) {
+ if (code.contains('\r\n')) {
+ return '\r\n';
+ }
+ return '\n';
+}
+
+/**
* TODO(scheglov) replace with nodes once there will be [CompilationUnit.getComments].
*
* Returns [SourceRange]s of all comments in [unit].
@@ -419,6 +430,41 @@ List<AstNode> getParents(AstNode node) {
}
/**
+ * Returns a parsed [AstNode] for the given [classElement].
+ *
+ * The resulting AST structure may or may not be resolved.
+ */
+AstNode getParsedClassElementNode(ClassElement classElement) {
+ CompilationUnitElement unitElement =
+ classElement.getAncestor((e) => e is CompilationUnitElement);
+ CompilationUnit unit = getParsedUnit(unitElement);
+ int offset = classElement.nameOffset;
+ AstNode classNameNode = new NodeLocator.con1(offset).searchWithin(unit);
+ if (classElement.isEnum) {
+ return classNameNode.getAncestor((node) => node is EnumDeclaration);
+ } else {
+ return classNameNode.getAncestor(
+ (node) => node is ClassDeclaration || node is ClassTypeAlias);
+ }
+}
+
+/**
+ * Returns a parsed [CompilationUnit] for the given [unitElement].
+ *
+ * The resulting AST structure may or may not be resolved.
+ * If it is not resolved, then at least the given [unitElement] will be set.
+ */
+CompilationUnit getParsedUnit(CompilationUnitElement unitElement) {
+ AnalysisContext context = unitElement.context;
+ Source source = unitElement.source;
+ CompilationUnit unit = context.parseCompilationUnit(source);
+ if (unit.element == null) {
+ unit.element = unitElement;
+ }
+ return unit;
+}
+
+/**
* Returns a [PropertyAccessorElement] if the given [SimpleIdentifier] is a
* reference to a property, or `null` in the other case.
*/
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698