Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
cac619db
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 搜索 >>
未验证
提交
cac619db
编写于
12月 26, 2019
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: add identy for evaluate api
上级
6f9c70ca
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
89 addition
and
15 deletion
+89
-15
README.md
README.md
+2
-0
_fixtures/evaluate/null/StreamNonNull.java
_fixtures/evaluate/null/StreamNonNull.java
+56
-0
cmd/evaluate.go
cmd/evaluate.go
+5
-2
core/domain/evaluate/analyser.go
core/domain/evaluate/analyser.go
+4
-4
core/domain/evaluate/analyser_test.go
core/domain/evaluate/analyser_test.go
+4
-4
core/domain/evaluate/evaluate.go
core/domain/evaluate/evaluate.go
+3
-3
core/domain/evaluate/evaluator/empty.go
core/domain/evaluate/evaluator/empty.go
+1
-1
core/domain/evaluate/evaluator/null_exception.go
core/domain/evaluate/evaluator/null_exception.go
+13
-0
core/domain/evaluate/evaluator/service.go
core/domain/evaluate/evaluator/service.go
+1
-1
未找到文件。
README.md
浏览文件 @
cac619db
...
...
@@ -17,6 +17,8 @@ Todo:
-
[x] factory pattern
-
[ ] strategy
-
[ ] builder
-
[ ] Docs
-
[ ] Lifecycle for new projects: evaluate (cloc, bad smell, api, git, todo) -> design -> patterns (suggest) -> refactoring ()
## Usage
...
...
_fixtures/evaluate/null/StreamNonNull.java
0 → 100644
浏览文件 @
cac619db
package
nonnull
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
org.apache.commons.lang3.StringUtils
;
import
javax.annotation.Nullable
;
public
class
StreamNonNull
{
public
static
void
main
(
String
[]
args
)
{
Stream
<
String
>
language
=
Stream
.
of
(
"java"
,
"python"
,
"node"
,
null
,
"ruby"
,
null
,
"php"
);
List
<
String
>
result
=
language
.
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
());
result
.
forEach
(
System
.
out
::
println
);
String
a
=
testNull
(
"3"
);
a
.
charAt
(
0
);
String
output
=
orElseNull
();
output
.
charAt
(
0
);
StringUtils
.
isNotEmpty
(
null
);
}
public
static
String
testNull
(
String
input
)
{
if
(
input
.
length
()
>
2
)
{
return
input
;
}
return
null
;
}
@Nullable
public
static
String
orElseNull
()
{
Name
userName
=
new
Name
();
userName
.
setName
(
null
);
return
Optional
.
ofNullable
(
userName
)
// will be an empty optional if userName is null
.
map
(
Name:
:
getName
)
// will turn to empty optional if getName returns null
.
map
(
"Name is: "
::
concat
)
// prepend "Name is: " (only when we have a name)
.
orElse
(
null
);
// get the result string or the alternative
}
private
static
class
Name
{
private
String
name
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
}
cmd/evaluate.go
浏览文件 @
cac619db
...
...
@@ -3,6 +3,7 @@ package cmd
import
(
"github.com/phodal/coca/config"
"github.com/phodal/coca/core/domain/evaluate"
"github.com/phodal/coca/core/models"
.
"github.com/phodal/coca/core/support"
"encoding/json"
"github.com/spf13/cobra"
...
...
@@ -30,11 +31,13 @@ var evaluateCmd = &cobra.Command{
log
.
Fatal
(
"lost file:"
+
dependence
)
}
// util
var
identifiers
[]
models
.
JIdentifier
identContent
:=
ReadCocaFile
(
"identify.json"
)
_
=
json
.
Unmarshal
(
identContent
,
&
identifiers
)
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
analyser
.
Analysis
(
*&
parsedDep
s
)
analyser
.
Analysis
(
parsedDeps
,
identifier
s
)
},
}
...
...
core/domain/evaluate/analyser.go
浏览文件 @
cac619db
...
...
@@ -14,16 +14,16 @@ func NewEvaluateAnalyser() Analyser {
return
*&
Analyser
{}
}
func
(
a
Analyser
)
Analysis
(
nodes
[]
models
.
JClassNode
)
{
func
(
a
Analyser
)
Analysis
(
classNodes
[]
models
.
JClassNode
,
identifiers
[]
models
.
JIdentifier
)
{
var
servicesNode
[]
models
.
JClassNode
=
nil
var
evaluation
Evaluation
var
nodeMap
=
make
(
map
[
string
]
models
.
JClassNode
)
for
_
,
node
:=
range
n
odes
{
for
_
,
node
:=
range
classN
odes
{
nodeMap
[
node
.
Class
]
=
node
}
for
_
,
node
:=
range
n
odes
{
for
_
,
node
:=
range
classN
odes
{
if
strings
.
Contains
(
strings
.
ToLower
(
node
.
Class
),
"service"
)
{
servicesNode
=
append
(
servicesNode
,
node
)
}
else
{
...
...
@@ -32,5 +32,5 @@ func (a Analyser) Analysis(nodes []models.JClassNode) {
}
evaluation
=
Evaluation
{
evaluator
.
Service
{}}
evaluation
.
EvaluateList
(
servicesNode
,
nodeMap
)
evaluation
.
EvaluateList
(
servicesNode
,
nodeMap
,
identifiers
)
}
core/domain/evaluate/analyser_test.go
浏览文件 @
cac619db
...
...
@@ -16,7 +16,7 @@ func TestAnalyser_Analysis(t *testing.T) {
file
:=
support
.
ReadFile
(
"../../../_fixtures/evaluate/service.json"
)
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
analyser
.
Analysis
(
parsedDeps
)
analyser
.
Analysis
(
parsedDeps
,
nil
)
g
.
Expect
(
true
)
.
To
(
Equal
(
true
))
}
...
...
@@ -28,7 +28,7 @@ func Test_Service_LifeCycle(t *testing.T) {
file
:=
support
.
ReadFile
(
"../../../_fixtures/evaluate/service_lifecycle.json"
)
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
analyser
.
Analysis
(
parsedDeps
)
analyser
.
Analysis
(
parsedDeps
,
nil
)
g
.
Expect
(
true
)
.
To
(
Equal
(
true
))
}
...
...
@@ -40,7 +40,7 @@ func Test_Service_Same_Return_Type(t *testing.T) {
file
:=
support
.
ReadFile
(
"../../../_fixtures/evaluate/service_same_return_type.json"
)
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
analyser
.
Analysis
(
parsedDeps
)
analyser
.
Analysis
(
parsedDeps
,
nil
)
g
.
Expect
(
true
)
.
To
(
Equal
(
true
))
}
...
...
@@ -52,6 +52,6 @@ func Test_Long_Parameters(t *testing.T) {
file
:=
support
.
ReadFile
(
"../../../_fixtures/evaluate/service_long_parameters.json"
)
_
=
json
.
Unmarshal
(
file
,
&
parsedDeps
)
analyser
.
Analysis
(
parsedDeps
)
analyser
.
Analysis
(
parsedDeps
,
nil
)
g
.
Expect
(
true
)
.
To
(
Equal
(
true
))
}
\ No newline at end of file
core/domain/evaluate/evaluate.go
浏览文件 @
cac619db
...
...
@@ -4,7 +4,7 @@ import "github.com/phodal/coca/core/models"
type
Evaluator
interface
{
Evaluate
(
node
models
.
JClassNode
)
EvaluateList
(
nodes
[]
models
.
JClassNode
,
nodeMap
map
[
string
]
models
.
JClassNode
)
EvaluateList
(
nodes
[]
models
.
JClassNode
,
nodeMap
map
[
string
]
models
.
JClassNode
,
identifiers
[]
models
.
JIdentifier
)
}
type
Evaluation
struct
{
...
...
@@ -15,6 +15,6 @@ func (o *Evaluation) Evaluate(node models.JClassNode) {
o
.
Evaluator
.
Evaluate
(
node
)
}
func
(
o
*
Evaluation
)
EvaluateList
(
nodes
[]
models
.
JClassNode
,
nodeMap
map
[
string
]
models
.
JClassNode
)
{
o
.
Evaluator
.
EvaluateList
(
nodes
,
nodeMap
)
func
(
o
*
Evaluation
)
EvaluateList
(
nodes
[]
models
.
JClassNode
,
nodeMap
map
[
string
]
models
.
JClassNode
,
identifiers
[]
models
.
JIdentifier
)
{
o
.
Evaluator
.
EvaluateList
(
nodes
,
nodeMap
,
nil
)
}
core/domain/evaluate/evaluator/empty.go
浏览文件 @
cac619db
...
...
@@ -12,6 +12,6 @@ func (Empty) Evaluate(models.JClassNode) {
}
func
(
Empty
)
EvaluateList
([]
models
.
JClassNode
,
map
[
string
]
models
.
JClassNode
)
{
func
(
Empty
)
EvaluateList
([]
models
.
JClassNode
,
map
[
string
]
models
.
JClassNode
,
[]
models
.
JIdentifier
)
{
}
\ No newline at end of file
core/domain/evaluate/evaluator/null_exception.go
0 → 100644
浏览文件 @
cac619db
package
evaluator
import
(
"github.com/phodal/coca/core/models"
)
type
NullException
struct
{
}
func
(
NullException
)
EvaluateList
([]
models
.
JClassNode
,
map
[
string
]
models
.
JClassNode
,
[]
models
.
JIdentifier
)
{
}
core/domain/evaluate/evaluator/service.go
浏览文件 @
cac619db
...
...
@@ -15,7 +15,7 @@ var nodeMap map[string]models.JClassNode
var
returnTypeMap
map
[
string
][]
string
var
longParameterList
[]
models
.
JMethod
func
(
s
Service
)
EvaluateList
(
nodes
[]
models
.
JClassNode
,
classNodeMap
map
[
string
]
models
.
JClassNode
)
{
func
(
s
Service
)
EvaluateList
(
nodes
[]
models
.
JClassNode
,
classNodeMap
map
[
string
]
models
.
JClassNode
,
identifiers
[]
models
.
JIdentifier
)
{
nodeMap
=
classNodeMap
longParameterList
=
nil
returnTypeMap
=
make
(
map
[
string
][]
string
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录