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

Unified Diff: third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/ValidatorContext.java

Issue 2464463002: Revert of DevTools: clean up scripts folder (Closed)
Patch Set: Created 4 years, 2 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: third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/ValidatorContext.java
diff --git a/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/ValidatorContext.java b/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/ValidatorContext.java
new file mode 100644
index 0000000000000000000000000000000000000000..393f7056d9b1ade28da1f00364496584332a9fae
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/ValidatorContext.java
@@ -0,0 +1,94 @@
+package org.chromium.devtools.jsdoc;
+
+import com.google.javascript.jscomp.SourceFile;
+import com.google.javascript.rhino.Node;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class ValidatorContext {
+
+ private static final Comparator<MessageRecord> MESSAGE_RECORD_COMPARATOR =
+ new Comparator<MessageRecord>() {
+ @Override
+ public int compare(MessageRecord left, MessageRecord right) {
+ return left.position - right.position;
+ }
+ };
+
+ public final String scriptFileName;
+ public final SourceFile sourceFile;
+ private final SortedSet<MessageRecord> validationResult =
+ new TreeSet<>(MESSAGE_RECORD_COMPARATOR);
+
+
+ public ValidatorContext(String text, String scriptFileName) {
+ this.scriptFileName = scriptFileName;
+ this.sourceFile = SourceFile.builder().buildFromCode(scriptFileName, text);
+ }
+
+ public SortedSet<MessageRecord> getValidationResult() {
+ return Collections.unmodifiableSortedSet(validationResult);
+ }
+
+ public String getNodeText(Node node) {
+ if (node == null) {
+ return null;
+ }
+ try {
+ return sourceFile.getCode().substring(
+ node.getSourceOffset(), node.getSourceOffset() + node.getLength());
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ public SourcePosition getPosition(int offset) {
+ return new SourcePosition(
+ sourceFile.getLineOfOffset(offset), sourceFile.getColumnOfOffset(offset));
+ }
+
+ public void reportErrorInNode(Node node, int offsetInNodeText, String errorText) {
+ int errorAbsoluteOffset = node.getSourceOffset() + offsetInNodeText;
+ reportErrorAtOffset(errorAbsoluteOffset, errorText);
+ }
+
+ public void reportErrorAtOffset(int offset, String errorText) {
+ SourcePosition position = getPosition(offset);
+ StringBuilder positionMarker = new StringBuilder(position.column + 1);
+ for (int i = position.column; i > 0; --i) {
+ positionMarker.append(' ');
+ }
+ positionMarker.append('^');
+ String message = String.format("%s:%d: ERROR - %s%n%s%n%s%n",
+ scriptFileName,
+ position.line,
+ errorText,
+ sourceFile.getLine(position.line),
+ positionMarker.toString());
+ validationResult.add(new MessageRecord(offset, message));
+ }
+
+ public static class MessageRecord {
+ public final int position;
+ public final String text;
+
+ public MessageRecord(int position, String text) {
+ this.position = position;
+ this.text = text;
+ }
+ }
+
+ public static class SourcePosition {
+ public final int line;
+ public final int column;
+
+ public SourcePosition(int line, int column) {
+ this.line = line;
+ this.column = column;
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698