diff --git a/_fixtures/call/BookController.java b/_fixtures/call/BookController.java new file mode 100644 index 0000000000000000000000000000000000000000..c2b1ad3885b77fcbc4e8e542f1789107a351c56b --- /dev/null +++ b/_fixtures/call/BookController.java @@ -0,0 +1,45 @@ +package com.phodal.pholedge.book; + +import com.phodal.pholedge.book.model.BookRepresentaion; +import com.phodal.pholedge.book.model.command.CreateBookCommand; +import com.phodal.pholedge.book.model.command.UpdateBookCommand; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + +import static com.google.common.collect.ImmutableSortedMap.of; + +@RestController +@RequestMapping(value = "/books") +public class BookController { + private final BookService applicationService; + + public BookController(BookService applicationService) { + this.applicationService = applicationService; + } + + @PostMapping + @ResponseStatus(HttpStatus.CREATED) + public Map createBook(@RequestBody @Valid CreateBookCommand command) { + return of("id", applicationService.createBook(command)); + } + + @PutMapping("/{id}") + @ResponseStatus(HttpStatus.OK) + public BookRepresentaion updateBook(@PathVariable(name = "id") String id, @RequestBody @Valid UpdateBookCommand command) { + return applicationService.updateBook(id, command); + } + + @GetMapping("/") + public List getBookList() { + return applicationService.getBooksLists(); + } + + @GetMapping("/{id}") + public BookRepresentaion getBookById(@PathVariable(name = "id") String id) { + return applicationService.getBookById(id); + } +} diff --git a/cmd/concept.go b/cmd/concept.go index 311dfae5bdb0178117dae61c24d15983e7f5acae..37e0009a6edc860d99dfef9aa10c41242e3ab424 100644 --- a/cmd/concept.go +++ b/cmd/concept.go @@ -6,6 +6,7 @@ import ( "coca/core/models" . "coca/core/support" "encoding/json" + "fmt" "github.com/spf13/cobra" "log" ) @@ -28,7 +29,12 @@ var conceptCmd = &cobra.Command{ _ = json.Unmarshal(file, &parsedDeps) - analyser.Analysis(&parsedDeps) + wordCounts := analyser.Analysis(&parsedDeps) + for _, word := range wordCounts { + if word.Value > 0 { + fmt.Println(word.Key, word.Value) + } + } } }, } diff --git a/core/adapter/call/JavaCallApp_test.go b/core/adapter/call/JavaCallApp_test.go index a7c2d23b82ef1b9ad6b1667e7a36241a60ac9ef1..f8c81d23691b3d3727b4ef02d11e2935e5f2650a 100644 --- a/core/adapter/call/JavaCallApp_test.go +++ b/core/adapter/call/JavaCallApp_test.go @@ -1,9 +1,26 @@ package call import ( + "coca/core/adapter/identifier" + "fmt" + . "github.com/onsi/gomega" "testing" ) func TestJavaCallApp_AnalysisPath(t *testing.T) { + g := NewGomegaWithT(t) + codePath := "../../../_fixtures/call" + identifierApp := new(identifier.JavaIdentifierApp) + iNodes := identifierApp.AnalysisPath(codePath) + var classes []string = nil + for _, node := range iNodes { + classes = append(classes, node.Package+"."+node.ClassName) + } + + callApp := new(JavaCallApp) + + callNodes := callApp.AnalysisPath(codePath, classes, iNodes) + + g.Expect(len(callNodes)).To(Equal(1)) } \ No newline at end of file diff --git a/core/adapter/identifier/JavaIdentifierApp_test.go b/core/adapter/identifier/JavaIdentifierApp_test.go index 1719e2108a7ac46bdc903c80a27247cbb2da90eb..b7f6eba0aa64554c5c50dfaee1c9b107c838b4aa 100644 --- a/core/adapter/identifier/JavaIdentifierApp_test.go +++ b/core/adapter/identifier/JavaIdentifierApp_test.go @@ -9,9 +9,11 @@ func TestJavaIdentifierApp_AnalysisPath(t *testing.T) { g := NewGomegaWithT(t) identApp := new(JavaIdentifierApp) - identifiers := identApp.AnalysisPath("../../../examples/method-call") + identifiers := identApp.AnalysisPath("../../../_fixtures/call") g.Expect(len(identifiers)).To(Equal(1)) - g.Expect(identifiers[0].ClassName).To(Equal("BlogRepositoryImpl")) - g.Expect(identifiers[0].Methods[0].Name).To(Equal("save")) + g.Expect(identifiers[0].ClassName).To(Equal("BookController")) + g.Expect(identifiers[0].Methods[0].Name).To(Equal("createBook")) + + g.Expect(identifiers[0].Annotations[0].QualifiedName).To(Equal("RestController")) } \ No newline at end of file diff --git a/core/domain/concept/concept_analyser.go b/core/domain/concept/concept_analyser.go index d57d0dbfdefbf56094ce5b442757fbc48a27e268..6c5bcb57bfc1e2bc2721756f652bcabb249d6637 100644 --- a/core/domain/concept/concept_analyser.go +++ b/core/domain/concept/concept_analyser.go @@ -4,7 +4,6 @@ import ( languages2 "coca/core/domain/call_graph/stop_words/languages" "coca/core/models" "coca/core/support" - "fmt" ) type ConceptAnalyser struct { @@ -18,11 +17,11 @@ func (c ConceptAnalyser) run() { } -func (c ConceptAnalyser) Analysis(clzs *[]models.JClassNode) { - buildMethodsFromDeps(*clzs) +func (c ConceptAnalyser) Analysis(clzs *[]models.JClassNode) support.PairList { + return buildMethodsFromDeps(*clzs) } -func buildMethodsFromDeps(clzs []models.JClassNode) { +func buildMethodsFromDeps(clzs []models.JClassNode) support.PairList { var methodsName []string var methodStr string for _, clz := range clzs { @@ -38,11 +37,7 @@ func buildMethodsFromDeps(clzs []models.JClassNode) { words = removeNormalWords(words) wordCounts := support.RankByWordCount(words) - for _, word := range wordCounts { - if word.Value > 0 { - fmt.Println(word.Key, word.Value) - } - } + return wordCounts } var itStopWords = []string{ diff --git a/core/domain/concept/concept_analyser_test.go b/core/domain/concept/concept_analyser_test.go new file mode 100644 index 0000000000000000000000000000000000000000..a81aae7b18e89dc0b6a532f78dd8023355d6765c --- /dev/null +++ b/core/domain/concept/concept_analyser_test.go @@ -0,0 +1,28 @@ +package concept + +import ( + "coca/core/models" + "coca/core/support" + "encoding/json" + "log" + "testing" + + . "github.com/onsi/gomega" +) + +func TestConceptAnalyser_Analysis(t *testing.T) { + g := NewGomegaWithT(t) + + var parsedDeps []models.JClassNode + analyser := NewConceptAnalyser() + file := support.ReadFile("../../../_fixtures/call_api_test.json") + if file == nil { + log.Fatal("lost file") + } + + _ = json.Unmarshal(file, &parsedDeps) + + counts := analyser.Analysis(&parsedDeps) + + g.Expect(counts.Len()).To(Equal(4)) +} \ No newline at end of file