Convert SourcePositionInfo to kotlin
This also removes unused column property.
Test: existing tests pass
Bug: 153691074
(bug number is for CP)
Merged-in: I0d4c83c2fdfd9d20b240f3b4c5a6f99ba21dd7d5
Change-Id: If925385094a80d8203987abd2d0cfaa7dcfa5059
diff --git a/src/main/java/com/android/tools/metalava/doclava1/ApiFile.java b/src/main/java/com/android/tools/metalava/doclava1/ApiFile.java
index 6f7466f..3b1341f 100644
--- a/src/main/java/com/android/tools/metalava/doclava1/ApiFile.java
+++ b/src/main/java/com/android/tools/metalava/doclava1/ApiFile.java
@@ -896,7 +896,7 @@
}
SourcePositionInfo pos() {
- return new SourcePositionInfo(mFilename, mLine, 0);
+ return new SourcePositionInfo(mFilename, mLine);
}
public int getLine() {
diff --git a/src/main/java/com/android/tools/metalava/doclava1/SourcePositionInfo.java b/src/main/java/com/android/tools/metalava/doclava1/SourcePositionInfo.java
deleted file mode 100644
index fc21b40..0000000
--- a/src/main/java/com/android/tools/metalava/doclava1/SourcePositionInfo.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tools.metalava.doclava1;
-
-import org.jetbrains.annotations.NotNull;
-
-// Copied from doclava1
-public class SourcePositionInfo implements Comparable<SourcePositionInfo> {
- public static final SourcePositionInfo UNKNOWN = new SourcePositionInfo("(unknown)", 0, 0);
-
- public SourcePositionInfo(String file, int line, int column) {
- this.file = file;
- this.line = line;
- this.column = column;
- }
-
- /**
- * Given this position and str which occurs at that position, as well as str an index into str,
- * find the SourcePositionInfo.
- *
- * @throws StringIndexOutOfBoundsException if index > str.length()
- */
- public static SourcePositionInfo add(SourcePositionInfo that, String str, int index) {
- if (that == null) {
- return null;
- }
- int line = that.line;
- char prev = 0;
- for (int i = 0; i < index; i++) {
- char c = str.charAt(i);
- if (c == '\r' || (c == '\n' && prev != '\r')) {
- line++;
- }
- prev = c;
- }
- return new SourcePositionInfo(that.file, line, 0);
- }
-
- @Override
- public String toString() {
- return file + ':' + line;
- }
-
- @Override
- public int compareTo(@NotNull SourcePositionInfo that) {
- int r = this.file.compareTo(that.file);
- if (r != 0) return r;
- return this.line - that.line;
- }
-
- private final String file;
- private final int line;
- private final int column;
-}
diff --git a/src/main/java/com/android/tools/metalava/doclava1/SourcePositionInfo.kt b/src/main/java/com/android/tools/metalava/doclava1/SourcePositionInfo.kt
new file mode 100644
index 0000000..29f770b
--- /dev/null
+++ b/src/main/java/com/android/tools/metalava/doclava1/SourcePositionInfo.kt
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tools.metalava.doclava1
+
+class SourcePositionInfo(
+ private val file: String,
+ private val line: Int
+) : Comparable<SourcePositionInfo> {
+ override fun toString(): String {
+ return "$file:$line"
+ }
+
+ override fun compareTo(other: SourcePositionInfo): Int {
+ val r = file.compareTo(other.file)
+ return if (r != 0) r else line - other.line
+ }
+
+ companion object {
+ val UNKNOWN = SourcePositionInfo("(unknown)", 0)
+
+ /**
+ * Given this position and str which occurs at that position, as well as str an index into str,
+ * find the SourcePositionInfo.
+ *
+ * @throws StringIndexOutOfBoundsException if index > str.length()
+ */
+ fun add(
+ that: SourcePositionInfo?,
+ str: String,
+ index: Int
+ ): SourcePositionInfo? {
+ if (that == null) {
+ return null
+ }
+ var line = that.line
+ var prev = 0.toChar()
+ for (i in 0 until index) {
+ val c = str[i]
+ if (c == '\r' || c == '\n' && prev != '\r') {
+ line++
+ }
+ prev = c
+ }
+ return SourcePositionInfo(that.file, line)
+ }
+ }
+}
\ No newline at end of file