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

Unified Diff: compiler/java/com/google/dart/compiler/parser/CommentPreservingParser.java

Issue 10542177: Fix for http://code.google.com/p/dart/issues/detail?id=3616 - missing dartdoc tooltips for getters … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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: compiler/java/com/google/dart/compiler/parser/CommentPreservingParser.java
===================================================================
--- compiler/java/com/google/dart/compiler/parser/CommentPreservingParser.java (revision 8707)
+++ compiler/java/com/google/dart/compiler/parser/CommentPreservingParser.java (working copy)
@@ -1,4 +1,4 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -7,10 +7,12 @@
import com.google.dart.compiler.DartCompilerListener;
import com.google.dart.compiler.DartSource;
import com.google.dart.compiler.Source;
+import com.google.dart.compiler.ast.ASTVisitor;
import com.google.dart.compiler.ast.DartComment;
import com.google.dart.compiler.ast.DartDeclaration;
+import com.google.dart.compiler.ast.DartField;
+import com.google.dart.compiler.ast.DartMethodDefinition;
import com.google.dart.compiler.ast.DartNode;
-import com.google.dart.compiler.ast.ASTVisitor;
import com.google.dart.compiler.ast.DartUnit;
import com.google.dart.compiler.common.SourceInfo;
import com.google.dart.compiler.metrics.CompilerMetrics;
@@ -186,6 +188,13 @@
DartDeclaration<?> decl = (DartDeclaration<?>)next;
if (!commentContainedBySibling(comment, decl)) {
+ // Dartc creates both a DartField and a DartMethodDefinition for getters and setters.
+ // They have the same source location; we want to assign the dartdoc to the method
+ // definition and not the field.
+ if (i + 2 < nodes.size()) {
+ decl = adjustDartdocTarget(next, nodes.get(i + 2));
+ }
+
decl.setDartDoc(comment);
}
}
@@ -194,6 +203,16 @@
}
}
+ private DartDeclaration<?> adjustDartdocTarget(DartNode currentNode, DartNode nextNode) {
+ if (currentNode instanceof DartField && nextNode instanceof DartMethodDefinition) {
+ if (currentNode.getSourceInfo().equals(nextNode.getSourceInfo())) {
+ return (DartDeclaration<?>)nextNode;
+ }
+ }
+
+ return (DartDeclaration<?>)currentNode;
+ }
+
private boolean commentContainedBySibling(DartComment comment, DartDeclaration<?> node) {
for (DartNode child : getChildren(node.getParent())) {
if (child != node && !(child instanceof DartComment)) {

Powered by Google App Engine
This is Rietveld 408576698