From 6772df32984c5d12847f5295dc2c024477187e53 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Sun, 8 Apr 2012 16:40:55 +0400 Subject: [PATCH] Replaced getter methods with properties (because of fixed compiler bugs) --- examples/example-vfs/src/FileSystem.kt | 6 ++-- examples/example-vfs/src/Main.kt | 2 +- examples/example-vfs/src/RefreshQueue.kt | 6 ++-- examples/example-vfs/src/VirtualFile.kt | 39 +++++++++++++----------- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/examples/example-vfs/src/FileSystem.kt b/examples/example-vfs/src/FileSystem.kt index 75628f33232..f056cd21ea8 100644 --- a/examples/example-vfs/src/FileSystem.kt +++ b/examples/example-vfs/src/FileSystem.kt @@ -72,7 +72,7 @@ public object FileSystem { */ public fun addWatchedDirectory(dir : VirtualFile) { assertCanRead() - if (dir.isDirectory()) { + if (dir.isDirectory) { watchedDirectories.add(dir) scanAndAddRecursivelyNoEvents(dir) @@ -135,7 +135,7 @@ private class VirtualFileInfo(file : VirtualFile) { val children : List = ArrayList; { - children.addAll(file.children()) - lastModified = file.modificationTime() + children.addAll(file.children) + lastModified = file.modificationTime } } diff --git a/examples/example-vfs/src/Main.kt b/examples/example-vfs/src/Main.kt index 374e4986c69..0e32b334e53 100644 --- a/examples/example-vfs/src/Main.kt +++ b/examples/example-vfs/src/Main.kt @@ -27,7 +27,7 @@ fun main(args : Array) { println(event) if (event is VirtualFileChangedEvent) { // FIXME explicit type casting to avoid overload ambiguity (KT-1461) - println("new file size is ${(event as VirtualFileChangedEvent).file.size()}") + println("new file size is ${(event as VirtualFileChangedEvent).file.size}") } } diff --git a/examples/example-vfs/src/RefreshQueue.kt b/examples/example-vfs/src/RefreshQueue.kt index 1589d702963..925136ed9f6 100644 --- a/examples/example-vfs/src/RefreshQueue.kt +++ b/examples/example-vfs/src/RefreshQueue.kt @@ -54,9 +54,9 @@ internal object RefreshQueue { if (fileInfo == null) { return } - if (file.isDirectory()) { + if (file.isDirectory) { val oldChildren = fileInfo.children - val newChildren = file.children() + val newChildren = file.children val addedChildren = listDifference(newChildren, oldChildren) @@ -71,7 +71,7 @@ internal object RefreshQueue { commonChildren.forEach{ refreshFile(it) } } else { - val newModificationTime = file.modificationTime() + val newModificationTime = file.modificationTime if (fileInfo.lastModified != newModificationTime) { fileInfo.lastModified = newModificationTime diff --git a/examples/example-vfs/src/VirtualFile.kt b/examples/example-vfs/src/VirtualFile.kt index 9daad220aa2..0e83dbc7c35 100644 --- a/examples/example-vfs/src/VirtualFile.kt +++ b/examples/example-vfs/src/VirtualFile.kt @@ -13,31 +13,29 @@ import kotlin.util.* * Abstract virtual file. */ public abstract class VirtualFile(public val path : String) { - // FIXME this method should be replaced with val (KT-1168, KT-1170) - protected abstract fun kind() : String + protected abstract val kind : String - // FIXME these abstract methods should be replaced with vals (KT-1165) /** * Returns file size. */ - public abstract fun size() : Long + public abstract val size : Long /** * Returns the time that the virtual file was last modified (milliseconds since * the epoch (00:00:00 GMT, January 1, 1970). */ - public abstract fun modificationTime() : Long + public abstract val modificationTime : Long /** * Returns if virtual file exists. */ - public abstract fun exists() : Boolean + public abstract val exists : Boolean /** * Returns if virtual file is directory */ - public abstract fun isDirectory() : Boolean + public abstract val isDirectory : Boolean /** * Returns list of virtual files which are children for this. */ - public abstract fun children() : List + public abstract val children : List /** * Opens input stream for reading. After reading, stream should be closed. @@ -46,16 +44,16 @@ public abstract class VirtualFile(public val path : String) { public abstract fun openInputStream() : InputStream fun equals(other : Any?) : Boolean { - return other is VirtualFile && kind() == other.kind() && path == other.path + return other is VirtualFile && kind == other.kind && path == other.path } fun hashCode() : Int { // FIXME rewrite without casting when it will be possible - return (kind() as java.lang.String).hashCode() * 31 + (path as java.lang.String).hashCode() + return (kind as java.lang.String).hashCode() * 31 + (path as java.lang.String).hashCode() } fun toString(): String { - return "${kind()}[path=$path]" + return "${kind}[path=$path]" } } @@ -63,32 +61,37 @@ public abstract class VirtualFile(public val path : String) { * Type of virtual file which corresponds to real file in file system of OS. */ public class PhysicalVirtualFile(path : String) : VirtualFile(path) { - override public fun kind() : String = "Physical" + override public val kind : String = "Physical" private val ioFile : File get() = File(this.path.toSystemDependentPath()) - override public fun exists(): Boolean { + override public val exists: Boolean + get() { FileSystem.assertCanRead() return ioFile.exists() } - override public fun size(): Long { + override public val size: Long + get() { FileSystem.assertCanRead() return ioFile.length() } - override public fun modificationTime(): Long { + override public val modificationTime: Long + get() { FileSystem.assertCanRead() return ioFile.lastModified() } - override public fun isDirectory(): Boolean { + override public val isDirectory: Boolean + get() { FileSystem.assertCanRead() return ioFile.isDirectory() } - override public fun children(): List { + override public val children: List + get() { FileSystem.assertCanRead() return (ioFile.listFiles() ?: array()). map{ FileSystem.getFileByIoFile(it.sure()) }?.toList() @@ -96,7 +99,7 @@ public class PhysicalVirtualFile(path : String) : VirtualFile(path) { override public fun openInputStream(): InputStream { FileSystem.assertCanRead() - if (isDirectory()) { + if (isDirectory) { throw IllegalArgumentException("Can't open directory for reading"); } return CheckedInputStream(FileInputStream(ioFile))