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

Unified Diff: pkg/analyzer/lib/src/generated/incremental_resolver.dart

Issue 742103003: Update 'nameOffset' for elements during incremental analysis. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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/analyzer/lib/src/generated/incremental_resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/incremental_resolver.dart b/pkg/analyzer/lib/src/generated/incremental_resolver.dart
index f4c65410bd98d28947949beced1d1f715778a25a..c31581ec40b41fc56c7c23fa3b8780877f28cb41 100644
--- a/pkg/analyzer/lib/src/generated/incremental_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/incremental_resolver.dart
@@ -775,44 +775,59 @@ class DeclarationMatcher extends RecursiveAstVisitor {
*/
class IncrementalResolver {
/**
- * The element for the library containing the compilation unit being visited.
+ * The error listener that will be informed of any errors that are found
+ * during resolution.
+ */
+ final AnalysisErrorListener _errorListener;
+
+ /**
+ * The object used to access the types from the core library.
+ */
+ final TypeProvider _typeProvider;
+
+ /**
+ * The element for the library containing the compilation unit being resolved.
*/
final LibraryElement _definingLibrary;
/**
+ * The element of the compilation unit being resolved.
+ */
+ final CompilationUnitElement _definingUnit;
+
+ /**
* The source representing the compilation unit being visited.
*/
final Source _source;
/**
- * The object used to access the types from the core library.
+ * The offset of the changed contents.
*/
- final TypeProvider _typeProvider;
+ final int _updateOffset;
/**
- * The error listener that will be informed of any errors that are found during resolution.
+ * The number of characters in the original contents that were replaced.
*/
- final AnalysisErrorListener _errorListener;
+ final int _updateOldLength;
/**
- * Initialize a newly created incremental resolver to resolve a node in the given source in the
- * given library, reporting errors to the given error listener.
- *
- * @param definingLibrary the element for the library containing the compilation unit being
- * visited
- * @param source the source representing the compilation unit being visited
- * @param typeProvider the object used to access the types from the core library
- * @param errorListener the error listener that will be informed of any errors that are found
- * during resolution
+ * The number of characters in the replacement text.
*/
- IncrementalResolver(this._definingLibrary, this._source, this._typeProvider,
- this._errorListener);
+ final int _updateNewLength;
/**
- * Resolve the given node, reporting any errors or warnings to the given listener.
+ * Initialize a newly created incremental resolver to resolve a node in the
+ * given source in the given library, reporting errors to the given error
+ * listener.
+ */
+ IncrementalResolver(this._errorListener, this._typeProvider,
+ this._definingLibrary, this._definingUnit, this._source, this._updateOffset,
+ this._updateOldLength, this._updateNewLength);
+
+ /**
+ * Resolve [node], reporting any errors or warnings to the given listener.
*
- * @param node the root of the AST structure to be resolved
- * @throws AnalysisException if the node could not be resolved
+ * [node] - the root of the AST structure to be resolved.
*/
void resolve(AstNode node) {
AstNode rootNode = _findResolutionRoot(node);
@@ -820,18 +835,21 @@ class IncrementalResolver {
if (_elementModelChanged(rootNode.parent)) {
throw new AnalysisException("Cannot resolve node: element model changed");
}
+ _definingUnit.accept(
+ new _ElementNameOffsetUpdater(_updateOffset, _updateNewLength - _updateOldLength));
_resolveTypes(node, scope);
_resolveVariables(node, scope);
_resolveReferences(node, scope);
}
/**
- * Return `true` if the given node can be resolved independently of any other nodes.
+ * Return `true` if the given node can be resolved independently of any other
+ * nodes.
*
- * <b>Note:</b> This method needs to be kept in sync with [ScopeBuilder.scopeForAstNode].
+ * *Note*: This method needs to be kept in sync with
+ * [ScopeBuilder.scopeForAstNode].
*
- * @param node the node being tested
- * @return `true` if the given node can be resolved independently of any other nodes
+ * [node] - the node being tested.
*/
bool _canBeResolved(AstNode node) =>
node is ClassDeclaration ||
@@ -843,11 +861,13 @@ class IncrementalResolver {
node is MethodDeclaration;
/**
- * Return `true` if the portion of the element model defined by the given node has changed.
+ * Return `true` if the portion of the element model defined by the given node
+ * has changed.
+ *
+ * [node] - the node defining the portion of the element model being tested.
*
- * @param node the node defining the portion of the element model being tested
- * @return `true` if the element model defined by the given node has changed
- * @throws AnalysisException if the correctness of the element model cannot be determined
+ * Throws [AnalysisException] if the correctness of the element model cannot
+ * be determined.
*/
bool _elementModelChanged(AstNode node) {
Element element = _getElement(node);
@@ -860,12 +880,12 @@ class IncrementalResolver {
}
/**
- * Starting at the given node, find the smallest AST node that can be resolved independently of
- * any other nodes. Return the node that was found.
+ * Starting at [node], find the smallest AST node that can be resolved
+ * independently of any other nodes. Return the node that was found.
*
- * @param node the node at which the search is to begin
- * @return the smallest AST node that can be resolved independently of any other nodes
- * @throws AnalysisException if there is no such node
+ * [node] - the node at which the search is to begin
+ *
+ * Throws [AnalysisException] if there is no such node.
*/
AstNode _findResolutionRoot(AstNode node) {
AstNode result = node;
@@ -881,11 +901,8 @@ class IncrementalResolver {
}
/**
- * Return the element defined by the given node, or `null` if the node does not define an
- * element.
- *
- * @param node the node defining the element to be returned
- * @return the element defined by the given node
+ * Return the element defined by [node], or `null` if the node does not
+ * define an element.
*/
Element _getElement(AstNode node) {
if (node is Declaration) {
@@ -1108,3 +1125,20 @@ class _ElementsGatherer extends GeneralizingElementVisitor {
}
}
}
+
+
+class _ElementNameOffsetUpdater extends GeneralizingElementVisitor {
+ final int updateOffset;
+ final int updateDelta;
+
+ _ElementNameOffsetUpdater(this.updateOffset, this.updateDelta);
+
+ @override
+ visitElement(Element element) {
+ int nameOffset = element.nameOffset;
+ if (nameOffset >= updateOffset) {
+ (element as ElementImpl).nameOffset = nameOffset + updateDelta;
+ }
+ super.visitElement(element);
+ }
+}
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698