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

Unified Diff: compiler/javatests/com/google/dart/compiler/parser/CommentTest.java

Issue 10661022: Issue 3752. Support for @override annotations (as structured doc comments) (Closed) Base URL: https://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/javatests/com/google/dart/compiler/parser/CommentTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/parser/CommentTest.java b/compiler/javatests/com/google/dart/compiler/parser/CommentTest.java
index dee5e3a4dbadd83c3b3ebbb9eded51963bf1a15e..859baaa93c0e0e97f331f6a4e63e335f82d90ef1 100644
--- a/compiler/javatests/com/google/dart/compiler/parser/CommentTest.java
+++ b/compiler/javatests/com/google/dart/compiler/parser/CommentTest.java
@@ -4,14 +4,16 @@
package com.google.dart.compiler.parser;
+import com.google.common.collect.Lists;
import com.google.dart.compiler.CompilerTestCase;
import com.google.dart.compiler.DartCompilerListener;
import com.google.dart.compiler.Source;
+import com.google.dart.compiler.ast.DartComment;
import com.google.dart.compiler.ast.DartDeclaration;
import com.google.dart.compiler.ast.DartNode;
import com.google.dart.compiler.ast.DartUnit;
+import com.google.dart.compiler.common.SourceInfo;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -19,50 +21,6 @@ import java.util.List;
* in the javadoc for <code>DartScanner.recordCommentLocation().</code>
*/
public class CommentTest extends CompilerTestCase {
-
- /**
- * A parser context that uses its own scanner.
- */
- class CommentParserContext extends DartScannerParserContext {
-
- CommentParserContext(Source source, String sourceCode,
- DartCompilerListener listener) {
- super(source, sourceCode, listener);
- }
-
- @Override
- protected DartScanner createScanner(String sourceCode) {
- return new CommentScanner(sourceCode);
- }
- }
-
- /**
- * A specialized scanner that records comment locations. It would have been
- * more natural to use the parser context to record comments, but the
- * scanner doesn't know about the context.
- */
- class CommentScanner extends DartScanner {
-
- CommentScanner(String sourceCode) {
- super(sourceCode);
- }
-
- @Override
- protected void recordCommentLocation(int start, int stop, int line, int col) {
- int size = commentLocs.size();
- if (size > 0) {
- // check for duplicates
- int[] loc = commentLocs.get(size - 1);
- // use <= to allow parser to back up more than one token
- if (start <= loc[0] && stop <= loc[1]) {
- return;
- }
- }
- commentLocs.add(new int[]{start, stop});
- }
- }
-
- private List<int[]> commentLocs = new ArrayList<int[]>();
private String source;
private static String[] EXPECTED001 = {"/*\n * Beginning comment\n */",
@@ -71,14 +29,14 @@ public class CommentTest extends CompilerTestCase {
private static String[] EXPECTED002 = {"/*\n*\n //comment\nX Y"};
public void test001() {
- parseUnit("Comments.dart");
- compareComments(EXPECTED001);
+ DartUnit unit = parseUnit("Comments.dart");
+ compareComments(unit, EXPECTED001);
}
public void test002() {
- parseUnitErrors("BadCommentNegativeTest.dart",
+ DartUnit unit = parseUnitErrors("BadCommentNegativeTest.dart",
"Unexpected token 'ILLEGAL' (expected end of file)", 1, 1);
- compareComments(EXPECTED002);
+ compareComments(unit, EXPECTED002);
}
public void test003() {
@@ -88,25 +46,24 @@ public class CommentTest extends CompilerTestCase {
}
@Override
- protected ParserContext makeParserContext(Source src, String sourceCode,
- DartCompilerListener listener) {
- // initializing source and commentLocs here is a bit of a hack but it
- // means parseUnit() and parseUnitErrors() do not have to be overridden
+ protected DartParser makeParser(Source src, String sourceCode, DartCompilerListener listener) {
source = sourceCode;
- commentLocs.clear();
- return new CommentParserContext(src, sourceCode, listener);
+ return super.makeParser(src, sourceCode, listener);
}
- private List<String> extractComments() {
- List<String> comments = new ArrayList<String>();
- for (int[] loc : commentLocs) {
- comments.add(source.substring(loc[0], loc[1]));
+ private List<String> extractComments(DartUnit unit) {
+ List<String> comments = Lists.newArrayList();
+ List<DartComment> commentNodes = unit.getComments();
+ for (DartComment commentNode : commentNodes) {
+ SourceInfo sourceInfo = commentNode.getSourceInfo();
+ String comment = source.substring(sourceInfo.getOffset(), sourceInfo.getEnd());
+ comments.add(comment);
}
return comments;
}
- private void compareComments(String[] expected) {
- List<String> comments = extractComments();
+ private void compareComments(DartUnit unit, String[] expected) {
+ List<String> comments = extractComments(unit);
assertEquals(expected.length, comments.size());
for (int i = 0; i < expected.length; i++) {
assertEquals(expected[i], comments.get(i));

Powered by Google App Engine
This is Rietveld 408576698