mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
convert SourceInfo to kotlin
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user