未验证 提交 cac619db 编写于 作者: P Phodal Huang

refactor: add identy for evaluate api

上级 6f9c70ca
......@@ -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
......
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;
}
}
}
......@@ -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(*&parsedDeps)
analyser.Analysis(parsedDeps, identifiers)
},
}
......
......@@ -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 nodes {
for _, node := range classNodes {
nodeMap[node.Class] = node
}
for _, node := range nodes {
for _, node := range classNodes {
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)
}
......@@ -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
......@@ -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)
}
......@@ -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
package evaluator
import (
"github.com/phodal/coca/core/models"
)
type NullException struct {
}
func (NullException) EvaluateList([]models.JClassNode, map[string]models.JClassNode, []models.JIdentifier) {
}
......@@ -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.
先完成此消息的编辑!
想要评论请 注册