Replaced getter methods with properties (because of fixed compiler bugs)

This commit is contained in:
Evgeny Gerashchenko
2012-04-08 16:40:55 +04:00
parent 41fb628004
commit 6772df3298
4 changed files with 28 additions and 25 deletions
+3 -3
View File
@@ -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<VirtualFile> = ArrayList<VirtualFile>;
{
children.addAll(file.children())
lastModified = file.modificationTime()
children.addAll(file.children)
lastModified = file.modificationTime
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ fun main(args : Array<String>) {
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}")
}
}
+3 -3
View File
@@ -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
+21 -18
View File
@@ -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<VirtualFile>
public abstract val children : List<VirtualFile>
/**
* 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<VirtualFile> {
override public val children: List<VirtualFile>
get() {
FileSystem.assertCanRead()
return (ioFile.listFiles() ?: array<File?>()).
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))