Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
fab14cc3
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fab14cc3
编写于
4月 06, 2012
作者:
E
Evgeny Gerashchenko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Made example-vfs compilable and workable.
上级
77b6a5f7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
41 deletion
+44
-41
examples/example-vfs/src/FileSystem.kt
examples/example-vfs/src/FileSystem.kt
+6
-10
examples/example-vfs/src/RefreshQueue.kt
examples/example-vfs/src/RefreshQueue.kt
+10
-11
examples/example-vfs/src/VirtualFile.kt
examples/example-vfs/src/VirtualFile.kt
+17
-17
examples/example-vfs/src/VirtualFileEvent.kt
examples/example-vfs/src/VirtualFileEvent.kt
+11
-3
未找到文件。
examples/example-vfs/src/FileSystem.kt
浏览文件 @
fab14cc3
...
...
@@ -82,19 +82,19 @@ public object FileSystem {
/* Scans file recursively and adds info about it to fileToInfo map */
private
fun
scanAndAddRecursivelyNoEvents
(
file
:
VirtualFile
)
{
assert
(
FileSystem
.
fileToInfo
[
file
.
path
]
==
null
)
require
(
FileSystem
.
fileToInfo
[
file
.
path
]
==
null
)
val
fileInfo
=
VirtualFileInfo
(
file
)
FileSystem
.
fileToInfo
[
file
.
path
]
=
fileInfo
fileInfo
.
children
.
for
e
ach
{
scanAndAddRecursivelyNoEvents
(
it
)
}
fileInfo
.
children
.
for
E
ach
{
scanAndAddRecursivelyNoEvents
(
it
)
}
}
internal
inline
fun
assertCanRead
()
{
assert
(
lock
.
getReadHoldCount
()
!=
0
||
lock
.
isWriteLockedByCurrentThread
())
check
(
lock
.
getReadHoldCount
()
!=
0
||
lock
.
isWriteLockedByCurrentThread
())
}
internal
inline
fun
assertCanWrite
()
{
assert
(
lock
.
isWriteLockedByCurrentThread
())
check
(
lock
.
isWriteLockedByCurrentThread
())
}
/**
...
...
@@ -107,12 +107,8 @@ public object FileSystem {
/**
* Adds file system listener which should be notified about changing of file system.
*/
public
fun
addVirtualFileListener
(
listener
:
VirtualFileListener
.(
VirtualFileEvent
)->
Unit
)
:
VirtualFileListener
{
val
vfl
=
object
:
VirtualFileListener
{
override
fun
eventHappened
(
event
:
VirtualFileEvent
)
{
listener
(
event
)
}
}
public
fun
addVirtualFileListener
(
listener
:
(
VirtualFileEvent
)->
Unit
)
:
VirtualFileListener
{
val
vfl
=
SimpleVirtualFileListener
(
listener
)
addVirtualFileListener
(
vfl
)
return
vfl
}
...
...
examples/example-vfs/src/RefreshQueue.kt
浏览文件 @
fab14cc3
...
...
@@ -12,7 +12,6 @@ import java.util.Timer
import
java.util.TimerTask
import
org.jetbrains.jet.samples.vfs.utils.*
import
org.jetbrains.jet.samples.vfs.utils.listDifference
/**
* Singleton which creates thread for periodically checking if there are changes in
...
...
@@ -37,13 +36,13 @@ internal object RefreshQueue {
}
private
fun
takeAndRefreshFiles
()
{
refreshFiles
(
taskQueue
.
take
())
refreshFiles
(
taskQueue
.
take
()
!!
)
}
/* Acquires write lock and refreshes file system */
private
fun
refreshFiles
(
files
:
List
<
VirtualFile
>)
{
FileSystem
.
write
{
files
.
for
e
ach
{
refreshFile
(
it
)
}
files
.
for
E
ach
{
refreshFile
(
it
)
}
}
}
...
...
@@ -51,7 +50,7 @@ internal object RefreshQueue {
private
fun
refreshFile
(
file
:
VirtualFile
)
{
FileSystem
.
assertCanWrite
()
val
fileInfo
=
FileSystem
.
fileToInfo
[
file
.
path
]
assert
(
fileInfo
!=
null
)
check
(
fileInfo
!=
null
)
if
(
fileInfo
==
null
)
{
return
}
...
...
@@ -64,13 +63,13 @@ internal object RefreshQueue {
val
deletedChildren
=
listDifference
(
oldChildren
,
newChildren
)
val
commonChildren
=
listIntersection
(
oldChildren
,
newChildren
)
addedChildren
.
for
e
ach
{
addRecursively
(
it
)
}
deletedChildren
.
for
e
ach
{
deleteRecursively
(
it
)
}
addedChildren
.
for
E
ach
{
addRecursively
(
it
)
}
deletedChildren
.
for
E
ach
{
deleteRecursively
(
it
)
}
fileInfo
.
children
.
clear
()
fileInfo
.
children
.
addAll
(
newChildren
)
commonChildren
.
for
e
ach
{
refreshFile
(
it
)
}
commonChildren
.
for
E
ach
{
refreshFile
(
it
)
}
}
else
{
val
newModificationTime
=
file
.
modificationTime
()
if
(
fileInfo
.
lastModified
!=
newModificationTime
)
{
...
...
@@ -83,21 +82,21 @@ internal object RefreshQueue {
/* Adds file to file system recursively, notifying listeners */
private
fun
addRecursively
(
file
:
VirtualFile
)
{
assert
(
FileSystem
.
fileToInfo
[
file
]
==
null
)
require
(
FileSystem
.
fileToInfo
[
file
]
==
null
)
val
fileInfo
=
VirtualFileInfo
(
file
)
FileSystem
.
fileToInfo
[
file
.
path
]
=
fileInfo
FileSystem
.
notifyEventHappened
(
VirtualFileCreateEvent
(
file
))
fileInfo
.
children
.
for
e
ach
{
addRecursively
(
it
)
}
fileInfo
.
children
.
for
E
ach
{
addRecursively
(
it
)
}
}
/* Deletes file from file system recursively, notifying listeners */
private
fun
deleteRecursively
(
file
:
VirtualFile
)
{
val
fileInfoMaybe
:
VirtualFileInfo
?
=
FileSystem
.
fileToInfo
[
file
.
path
]
val
fileInfo
=
fileInfoMaybe
.
sure
()
fileInfo
.
children
.
for
e
ach
{
deleteRecursively
(
it
)
}
fileInfo
.
children
.
for
E
ach
{
deleteRecursively
(
it
)
}
FileSystem
.
notifyEventHappened
(
VirtualFileDeletedEvent
(
file
))
FileSystem
.
fileToInfo
.
remove
(
file
)
}
...
...
@@ -115,7 +114,7 @@ internal object RefreshQueue {
public
fun
scheduleRefresh
(
vararg
files
:
VirtualFile
)
{
// FIXME This could be written more concise, using map() & toList() (KT-1164 & KT-1172)
val
filesList
=
ArrayList
<
VirtualFile
>()
files
.
for
e
ach
{
filesList
.
add
(
it
)
}
files
.
for
E
ach
{
filesList
.
add
(
it
)
}
taskQueue
.
put
(
filesList
)
// taskQueue.put(ArrayList<VirtualFile>(files.map{ it }))
...
...
examples/example-vfs/src/VirtualFile.kt
浏览文件 @
fab14cc3
...
...
@@ -63,38 +63,38 @@ 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
fun
kind
()
:
String
=
"Physical"
override
public
fun
kind
()
:
String
=
"Physical"
private
val
ioFile
:
File
get
()
=
File
(
this
.
path
.
toSystemDependentPath
())
override
fun
exists
():
Boolean
{
override
public
fun
exists
():
Boolean
{
FileSystem
.
assertCanRead
()
return
ioFile
.
exists
()
}
override
fun
size
():
Long
{
override
public
fun
size
():
Long
{
FileSystem
.
assertCanRead
()
return
ioFile
.
length
()
}
override
fun
modificationTime
():
Long
{
override
public
fun
modificationTime
():
Long
{
FileSystem
.
assertCanRead
()
return
ioFile
.
lastModified
()
}
override
fun
isDirectory
():
Boolean
{
override
public
fun
isDirectory
():
Boolean
{
FileSystem
.
assertCanRead
()
return
ioFile
.
isDirectory
()
}
override
fun
children
():
List
<
VirtualFile
>
{
override
public
fun
children
():
List
<
VirtualFile
>
{
FileSystem
.
assertCanRead
()
return
(
ioFile
.
listFiles
()
?:
Array
<
File
>(
0
)).
return
(
ioFile
.
listFiles
()
?:
array
<
File
?>(
)).
map
{
FileSystem
.
getFileByIoFile
(
it
.
sure
())
}
?.
toList
()
}
override
fun
openInputStream
():
InputStream
{
override
public
fun
openInputStream
():
InputStream
{
FileSystem
.
assertCanRead
()
if
(
isDirectory
())
{
throw
IllegalArgumentException
(
"Can't open directory for reading"
);
...
...
@@ -117,47 +117,47 @@ private fun String.toSystemIndependentPath() : String {
* InputStream wrapper which checks that file system read lock is acquired on each operation.
*/
private
class
CheckedInputStream
(
private
val
wrapped
:
InputStream
)
:
InputStream
()
{
override
fun
read
():
Int
{
override
public
fun
read
():
Int
{
FileSystem
.
assertCanRead
()
return
wrapped
.
read
()
}
override
fun
read
(
b
:
ByteArray
?,
off
:
Int
,
len
:
Int
)
:
Int
{
override
public
fun
read
(
b
:
ByteArray
?,
off
:
Int
,
len
:
Int
)
:
Int
{
FileSystem
.
assertCanRead
()
return
wrapped
.
read
(
b
,
off
,
len
)
}
override
fun
markSupported
():
Boolean
{
override
public
fun
markSupported
():
Boolean
{
FileSystem
.
assertCanRead
()
return
wrapped
.
markSupported
()
}
override
fun
skip
(
n
:
Long
):
Long
{
override
public
fun
skip
(
n
:
Long
):
Long
{
FileSystem
.
assertCanRead
()
return
wrapped
.
skip
(
n
)
}
override
fun
close
()
{
override
public
fun
close
()
{
FileSystem
.
assertCanRead
()
return
wrapped
.
close
()
}
override
fun
mark
(
readlimit
:
Int
)
{
override
public
fun
mark
(
readlimit
:
Int
)
{
FileSystem
.
assertCanRead
()
return
wrapped
.
mark
(
readlimit
)
}
override
fun
read
(
b
:
ByteArray
?):
Int
{
override
public
fun
read
(
b
:
ByteArray
?):
Int
{
FileSystem
.
assertCanRead
()
return
wrapped
.
read
(
b
)
}
override
fun
reset
()
{
override
public
fun
reset
()
{
FileSystem
.
assertCanRead
()
return
wrapped
.
reset
()
}
override
fun
available
():
Int
{
override
public
fun
available
():
Int
{
FileSystem
.
assertCanRead
()
return
wrapped
.
available
()
}
...
...
examples/example-vfs/src/VirtualFileEvent.kt
浏览文件 @
fab14cc3
...
...
@@ -7,6 +7,14 @@ public trait VirtualFileListener : java.util.EventListener {
fun
eventHappened
(
val
event
:
VirtualFileEvent
)
}
// FIXME using this wrapper because of codegen bug KT-1737, should be replaced with
private
class
SimpleVirtualFileListener
(
val
listenerFunction
:
(
VirtualFileEvent
)->
Unit
)
:
VirtualFileListener
{
override
fun
eventHappened
(
event
:
VirtualFileEvent
)
{
val
f
=
listenerFunction
// FIXME saving to local variable because of the bug in codegen (KT-1739)
f
(
event
)
}
}
/**
* Base type of virtual file events
* @property file affected by event
...
...
@@ -18,7 +26,7 @@ public abstract class VirtualFileEvent(val file : VirtualFile) : Object() {
* Event of creating file
*/
public
class
VirtualFileCreateEvent
(
file
:
VirtualFile
)
:
VirtualFileEvent
(
file
)
{
override
fun
toString
():
String
?
{
override
public
fun
toString
():
String
?
{
return
"created ${file}"
}
}
...
...
@@ -27,7 +35,7 @@ public class VirtualFileCreateEvent(file : VirtualFile) : VirtualFileEvent(file)
* Event of deleting file
*/
public
class
VirtualFileDeletedEvent
(
file
:
VirtualFile
)
:
VirtualFileEvent
(
file
)
{
override
fun
toString
():
String
?
{
override
public
fun
toString
():
String
?
{
return
"deleted ${file}"
}
}
...
...
@@ -36,7 +44,7 @@ public class VirtualFileDeletedEvent(file : VirtualFile) : VirtualFileEvent(file
* Event of changing file contents
*/
public
class
VirtualFileChangedEvent
(
file
:
VirtualFile
)
:
VirtualFileEvent
(
file
)
{
override
fun
toString
():
String
?
{
override
public
fun
toString
():
String
?
{
return
"changed ${file}"
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录