Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
12c62286
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
12c62286
编写于
10月 29, 2019
作者:
P
Phodal HUANG
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: refactor code
上级
d8b352a8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
47 addition
and
46 deletion
+47
-46
cmd/refactor.go
cmd/refactor.go
+7
-3
refactor/base/models/JFullIdentifier.go
refactor/base/models/JFullIdentifier.go
+0
-6
refactor/base/models/JMoveStruct.go
refactor/base/models/JMoveStruct.go
+15
-0
refactor/move_class_app.go
refactor/move_class_app.go
+3
-10
refactor/refactor.go
refactor/refactor.go
+0
-18
refactor/unused/remove_unused_import.go
refactor/unused/remove_unused_import.go
+22
-9
未找到文件。
cmd/refactor.go
浏览文件 @
12c62286
package
cmd
import
(
.
"../refactor"
//. "../refactor"
.
"../refactor/unused"
"github.com/spf13/cobra"
)
...
...
@@ -14,8 +15,11 @@ var refactorCmd *cobra.Command = &cobra.Command{
path
:=
cmd
.
Flag
(
"path"
)
.
Value
.
String
()
if
moveConfig
!=
""
&&
path
!=
""
{
app
:=
NewMoveClassApp
(
moveConfig
,
path
)
app
.
Analysis
()
//app := NewMoveClassApp(moveConfig, path)
//app.Analysis()
app2
:=
NewRemoveUnusedImportApp
(
moveConfig
,
path
)
app2
.
Analysis
()
}
},
}
...
...
refactor/base/models/JFullIdentifier.go
浏览文件 @
12c62286
...
...
@@ -17,12 +17,6 @@ type JField struct {
//StopLinePosition int
}
type
JImport
struct
{
Name
string
StartLine
int
StopLine
int
}
type
JPkgInfo
struct
{
Name
string
StartLine
int
...
...
refactor/base/models/JMoveStruct.go
0 → 100644
浏览文件 @
12c62286
package
models
type
JImport
struct
{
Name
string
StartLine
int
StopLine
int
}
type
JMoveStruct
struct
{
*
JFullIdentifier
Path
string
Deps
[]
JImport
}
refactor/move_class_app.go
浏览文件 @
12c62286
...
...
@@ -20,13 +20,6 @@ var currentFile string
var
moveConfig
string
var
configPath
string
type
JMoveStruct
struct
{
*
JFullIdentifier
path
string
deps
[]
JImport
}
var
nodes
[]
JMoveStruct
type
MoveClassApp
struct
{
...
...
@@ -114,10 +107,10 @@ func updatePackageInfo(structs []JMoveStruct, originImport string, newImport str
func
updateImportSide
(
originImport
string
,
newImport
string
)
{
for
index
:=
range
nodes
{
node
:=
nodes
[
index
]
for
j
:=
range
node
.
d
eps
{
dep
:=
node
.
d
eps
[
j
]
for
j
:=
range
node
.
D
eps
{
dep
:=
node
.
D
eps
[
j
]
if
dep
.
Name
==
originImport
{
updateFile
(
node
.
p
ath
,
dep
.
StartLine
,
"import "
+
newImport
+
";"
)
updateFile
(
node
.
P
ath
,
dep
.
StartLine
,
"import "
+
newImport
+
";"
)
}
}
}
...
...
refactor/refactor.go
已删除
100644 → 0
浏览文件 @
d8b352a8
package
refactor
import
(
.
"./base"
"os"
)
func
main
()
{
//cmd.Execute()
path
:=
"examples/unused-import"
if
len
(
os
.
Args
)
>
1
{
path
=
os
.
Args
[
1
:
][
0
]
}
callApp
:=
new
(
JavaRefactorApp
)
callApp
.
AnalysisPath
(
path
)
}
refactor/
base/JavaRefactorApp
.go
→
refactor/
unused/remove_unused_import
.go
浏览文件 @
12c62286
package
base
package
unused
import
(
"fmt"
...
...
@@ -8,17 +8,30 @@ import (
"path/filepath"
"strings"
.
"./models"
.
"../base"
.
"../base/models"
.
"../utils"
)
var
currentFile
string
var
moveConfig
string
var
configPath
string
type
JavaRefactor
App
struct
{
type
RemoveUnusedImport
App
struct
{
}
func
(
j
*
JavaRefactorApp
)
AnalysisPath
(
codeDir
string
)
{
files
:=
GetJavaFiles
(
codeDir
)
var
nodes
[]
JMoveStruct
func
NewRemoveUnusedImportApp
(
config
string
,
pPath
string
)
*
RemoveUnusedImportApp
{
moveConfig
=
config
configPath
=
pPath
nodes
=
nil
return
&
RemoveUnusedImportApp
{}
}
func
(
j
*
RemoveUnusedImportApp
)
Analysis
()
{
files
:=
GetJavaFiles
(
configPath
)
for
index
:=
range
files
{
file
:=
files
[
index
]
...
...
@@ -36,18 +49,18 @@ func (j *JavaRefactorApp) AnalysisPath(codeDir string) {
antlr
.
NewParseTreeWalker
()
.
Walk
(
listener
,
context
)
if
node
.
Name
!=
""
{
handleNode
()
handleNode
(
node
)
}
}
}
func
handleNode
()
{
func
handleNode
(
node
*
JFullIdentifier
)
{
var
fields
map
[
string
]
JField
=
node
.
GetFields
()
var
imports
[]
JImport
=
node
.
GetImports
()
fmt
.
Println
(
node
.
Pkg
+
"."
+
node
.
Name
,
imports
,
node
.
GetMethods
(),
fields
)
if
len
(
fields
)
==
0
{
//
removeAllImports(imports)
removeAllImports
(
imports
)
return
}
...
...
@@ -69,7 +82,7 @@ func handleNode() {
//}
}
func
removeAllImports
(
imports
map
[
string
]
JImport
)
{
func
removeAllImports
(
imports
[
]
JImport
)
{
for
index
:=
range
imports
{
imp
:=
imports
[
index
]
removeImportByLineNum
(
imp
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录