Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
9d46ca16
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9d46ca16
编写于
12月 29, 2019
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix move file test
上级
453ea3c7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
44 addition
and
32 deletion
+44
-32
.gitignore
.gitignore
+1
-0
_fixtures/refactor/move.config
_fixtures/refactor/move.config
+1
-1
_fixtures/refactor/move/a/ImportForB.java
_fixtures/refactor/move/a/ImportForB.java
+5
-0
core/domain/refactor/move_class/move_class_app.go
core/domain/refactor/move_class/move_class_app.go
+31
-3
core/domain/refactor/move_class/move_class_app_test.go
core/domain/refactor/move_class/move_class_app_test.go
+6
-2
core/support/file_helper.go
core/support/file_helper.go
+0
-26
未找到文件。
.gitignore
浏览文件 @
9d46ca16
...
...
@@ -67,3 +67,4 @@ coca_reporter
*.coverprofile
bug
_fixtures/tbs/tbs
_fixtures/refactor/move/b/ImportForB.java
_fixtures/refactor/move.config
浏览文件 @
9d46ca16
move
.
a
.
ImportForB
->
move
.
a
.
ImportForB
move
.
a
.
ImportForB
->
move
.
b
.
ImportForB
_fixtures/refactor/move/a/ImportForB.java
浏览文件 @
9d46ca16
package
move.a
;
public
class
ImportForB
{
}
core/domain/refactor/move_class/move_class_app.go
浏览文件 @
9d46ca16
...
...
@@ -7,6 +7,7 @@ import (
base2
"github.com/phodal/coca/core/domain/refactor/base"
models2
"github.com/phodal/coca/core/domain/refactor/base/models"
utils2
"github.com/phodal/coca/core/support"
"io"
"io/ioutil"
"log"
"os"
...
...
@@ -32,7 +33,7 @@ func NewMoveClassApp(config string, pPath string) *MoveClassApp {
return
&
MoveClassApp
{}
}
func
(
j
*
MoveClassApp
)
Analysis
()
{
func
(
j
*
MoveClassApp
)
Analysis
()
[]
models2
.
JMoveStruct
{
// TODO: 使用 Deps.json 来移动包
files
:=
utils2
.
GetJavaFiles
(
configPath
)
for
index
:=
range
files
{
...
...
@@ -49,11 +50,13 @@ func (j *MoveClassApp) Analysis() {
antlr
.
NewParseTreeWalker
()
.
Walk
(
listener
,
context
)
node
=
listener
.
GetNodeInfo
()
moveStruct
:=
&
models2
.
JMoveStruct
{
node
,
currentFile
,
node
.
GetImports
()}
nodes
=
append
(
nodes
,
*
moveStruct
)
}
parseRename
()
return
nodes
}
func
parseRename
()
{
...
...
@@ -95,6 +98,7 @@ func updatePackageInfo(originImport string, newImport string) {
if
originNode
.
Name
==
""
{
return
}
path
:=
buildJavaPath
(
configPath
+
newImport
)
split
:=
strings
.
Split
(
newImport
,
"."
)
pkg
:=
strings
.
Join
(
split
[
:
len
(
split
)
-
1
],
"."
)
...
...
@@ -142,8 +146,7 @@ func copyClass(originFile string, newFile string) {
newFile
=
strings
.
ReplaceAll
(
newFile
,
"."
,
"/"
)
+
".java"
}
fmt
.
Println
(
originFile
,
newFile
)
_
,
err
:=
utils2
.
CopyFile
(
originFile
,
newFile
)
_
,
err
:=
CopyFile
(
originFile
,
newFile
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -160,3 +163,28 @@ func buildJavaPath(originFile string) string {
}
return
str
}
func
CopyFile
(
src
,
dst
string
)
(
int64
,
error
)
{
sourceFileStat
,
err
:=
os
.
Stat
(
src
)
if
err
!=
nil
{
return
0
,
err
}
if
!
sourceFileStat
.
Mode
()
.
IsRegular
()
{
return
0
,
fmt
.
Errorf
(
"%s is not a regular file"
,
src
)
}
source
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
return
0
,
err
}
defer
source
.
Close
()
destination
,
err
:=
os
.
Create
(
dst
)
if
err
!=
nil
{
return
0
,
err
}
defer
destination
.
Close
()
nBytes
,
err
:=
io
.
Copy
(
destination
,
source
)
return
nBytes
,
err
}
core/domain/refactor/move_class/move_class_app_test.go
浏览文件 @
9d46ca16
...
...
@@ -2,6 +2,8 @@ package move_class
import
(
.
"github.com/onsi/gomega"
"os"
"path/filepath"
"testing"
)
...
...
@@ -10,8 +12,10 @@ func TestNewMoveClassApp(t *testing.T) {
config
:=
"../../../../_fixtures/refactor/move.config"
path
:=
"../../../../_fixtures/refactor/"
app
:=
NewMoveClassApp
(
config
,
path
)
abs_path
,
_
:=
filepath
.
Abs
(
path
)
app
:=
NewMoveClassApp
(
config
,
abs_path
+
"/"
)
app
.
Analysis
()
g
.
Expect
(
true
)
.
To
(
Equal
(
true
))
stat
,
_
:=
os
.
Stat
(
path
+
"/move/b/ImportForB.java"
)
g
.
Expect
(
stat
.
Name
())
.
To
(
Equal
(
"ImportForB.java"
))
}
\ No newline at end of file
core/support/file_helper.go
浏览文件 @
9d46ca16
...
...
@@ -3,7 +3,6 @@ package support
import
(
"fmt"
"github.com/phodal/coca/config"
"io"
"io/ioutil"
"os"
)
...
...
@@ -33,28 +32,3 @@ func ReadFile(fileName string) []byte {
}
return
contents
}
func
CopyFile
(
src
,
dst
string
)
(
int64
,
error
)
{
sourceFileStat
,
err
:=
os
.
Stat
(
src
)
if
err
!=
nil
{
return
0
,
err
}
if
!
sourceFileStat
.
Mode
()
.
IsRegular
()
{
return
0
,
fmt
.
Errorf
(
"%s is not a regular file"
,
src
)
}
source
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
return
0
,
err
}
defer
source
.
Close
()
destination
,
err
:=
os
.
Create
(
dst
)
if
err
!=
nil
{
return
0
,
err
}
defer
destination
.
Close
()
nBytes
,
err
:=
io
.
Copy
(
destination
,
source
)
return
nBytes
,
err
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录