From 6b41a4e2f9043dee0139c26abbcb6b78f7f9cac3 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 25 Jan 2016 15:12:06 +0100 Subject: [PATCH] convert SourceInfo to kotlin --- .../org/jetbrains/debugger/SourceInfo.java | 99 ++++--------------- 1 file changed, 17 insertions(+), 82 deletions(-) diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/SourceInfo.java b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/SourceInfo.java index 47485237899c..c86ffa5561f7 100644 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/SourceInfo.java +++ b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/SourceInfo.java @@ -13,94 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.debugger; +package org.jetbrains.debugger -import com.intellij.openapi.application.AccessToken; -import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.fileEditor.OpenFileDescriptor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.pom.Navigatable; -import com.intellij.xdebugger.XSourcePosition; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import com.intellij.openapi.application.runReadAction +import com.intellij.openapi.fileEditor.FileDocumentManager +import com.intellij.openapi.fileEditor.OpenFileDescriptor +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.xdebugger.XSourcePosition -public class SourceInfo implements XSourcePosition { - private final String functionName; +class SourceInfo(private val file: VirtualFile, private val line: Int, val column: Int = -1, private var offset: Int = -1, val functionName: String? = null) : XSourcePosition { + override fun getFile() = file - private final VirtualFile file; - private final int line; - private final int column; + override fun getLine() = line - private int offset = -1; - - public SourceInfo(@Nullable String functionName, @NotNull VirtualFile file, int line, int column, int offset) { - this.functionName = functionName; - this.file = file; - this.line = line; - this.column = column; - this.offset = offset; - } - - @Nullable - public static SourceInfo create(@Nullable String functionName, @Nullable VirtualFile file, int line, int column) { - if (file == null || !file.isValid()) { - return null; - } - return new SourceInfo(functionName, file, line, column, -1); - } - - @Nullable - public String getFunctionName() { - return functionName; - } - - @Override - public int getLine() { - return line; - } - - public int getColumn() { - return column; - } - - @Override - public int getOffset() { + override fun getOffset(): Int { if (offset == -1) { - Document document; - AccessToken token = ReadAction.start(); - try { - document = file.isValid() ? FileDocumentManager.getInstance().getDocument(file) : null; - } - finally { - token.finish(); - } - - if (document == null) { - return -1; - } - - offset = line < document.getLineCount() ? document.getLineStartOffset(line) : -1; + val document = runReadAction { if (file.isValid) FileDocumentManager.getInstance().getDocument(file) else null } ?: return -1 + offset = if (line < document.lineCount) document.getLineStartOffset(line) else -1 } - return offset; + return offset } - @NotNull - @Override - public VirtualFile getFile() { - return file; - } + override fun createNavigatable(project: Project) = OpenFileDescriptor(project, file, line, column) - @NotNull - @Override - public Navigatable createNavigatable(@NotNull Project project) { - return new OpenFileDescriptor(project, file, line, column); - } - - @Override - public String toString() { - return getFile() + ":" + getLine() + (column == -1 ? "": (":" + getColumn())); - } -} + override fun toString() = file.path + ":" + line + if (column == -1) "" else ":" + column +} \ No newline at end of file