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

feat: make first map

上级 d43da88b
......@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class AssertionRoulette {
public class AssertionRouletteTest {
@Test
public void testCloneNonBareRepoFromLocalTestServer() throws Exception {
Calculate calculate = new Calculate();
......
......@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ConstructorInitialization {
public class ConstructorInitializationTest {
@Before
public void init() throws Exception {
......
......@@ -4,7 +4,7 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class DuplicateAssert {
public class DuplicateAssertTest {
@Test
public void testXmlSanitizer() {
boolean valid = XmlSanitizer.isValid("Fritzbox");
......
......@@ -6,7 +6,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class MysteryGuest {
public class MysteryGuestTest {
@Test
public void testPersistence() throws Exception {
try (FileOutputStream out = new FileOutputStream("people.bin");) {
......
......@@ -2,7 +2,7 @@ package tbs;
import org.junit.Test;
public class RedundantPrint {
public class RedundantPrintTest {
@Test
public void testTransform10mNEUAndBack() {
String result = "a, b, c";
......
package cmd
import (
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/config"
"encoding/json"
"github.com/phodal/coca/core/adapter"
"github.com/phodal/coca/core/adapter/call"
"github.com/phodal/coca/core/domain/tbs"
"github.com/phodal/coca/core/models"
"github.com/phodal/coca/core/support"
"github.com/spf13/cobra"
)
type TbsCmdConfig struct {
DependencePath string
Path string
}
var (
......@@ -21,17 +23,33 @@ var tbsCmd = &cobra.Command{
Short: "test bad smell",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
identifiers = adapter.LoadIdentify(apiCmdConfig.DependencePath)
files := support.GetJavaTestFiles(tbsCmdConfig.Path)
var identifiers []models.JIdentifier
identifiers = adapter.LoadTestIdentify(files)
identifiersMap = adapter.BuildIdentifierMap(identifiers)
parsedDeps := cmd_util.GetDepsFromJson(tbsCmdConfig.DependencePath)
var classes []string = nil
for _, node := range identifiers {
classes = append(classes, node.Package+"."+node.ClassName)
}
analysisApp := call.NewJavaCallApp()
classNodes := analysisApp.AnalysisFiles(identifiers, files, classes)
nodeContent, _ := json.MarshalIndent(classNodes, "", "\t")
support.WriteToCocaFile("tdeps.json", string(nodeContent))
app := tbs.NewTbsApp()
app.AnalysisPath(parsedDeps, identifiersMap)
result := app.AnalysisPath(classNodes, identifiersMap)
resultContent, _ := json.MarshalIndent(result, "", "\t")
support.WriteToCocaFile("tbs.json", string(resultContent))
},
}
func init() {
rootCmd.AddCommand(tbsCmd)
tbsCmd.PersistentFlags().StringVarP(&tbsCmdConfig.DependencePath, "dependence", "d", config.CocaConfig.ReporterPath+"/deps.json", "get dependence file")
tbsCmd.PersistentFlags().StringVarP(&tbsCmdConfig.Path, "path", "p", ".", "example -p core/main")
}
......@@ -34,6 +34,23 @@ func LoadIdentify(importPath string) []models.JIdentifier {
return *&identifiers
}
func LoadTestIdentify(files []string) []models.JIdentifier {
var identifiers []models.JIdentifier
apiContent := support.ReadCocaFile("tidentify.json")
if apiContent == nil {
identifierApp := new(identifier.JavaIdentifierApp)
ident := identifierApp.AnalysisFiles(files)
identModel, _ := json.MarshalIndent(ident, "", "\t")
support.WriteToCocaFile("tidentify.json", string(identModel))
return *&ident
}
_ = json.Unmarshal(apiContent, &identifiers)
return *&identifiers
}
func BuildDIMap(identifiers []models.JIdentifier, identifierMap map[string]models.JIdentifier) map[string]string {
var diMap = make(map[string]string)
......
package tbs
import "github.com/phodal/coca/core/models"
import (
"github.com/phodal/coca/core/models"
)
type TbsApp struct {
}
func NewTbsApp() *TbsApp {
return &TbsApp{}
}
func (a TbsApp) AnalysisPath(deps []models.JClassNode, identifiersMap map[string]models.JIdentifier) {
type TestBadSmell struct {
FileName string
Type string
Description string
Line int
}
func (a TbsApp) AnalysisPath(deps []models.JClassNode, identifiersMap map[string]models.JIdentifier) []TestBadSmell {
var results []TestBadSmell = nil
var identMethodMap = make(map[string]models.JMethod)
for key, clzMap := range identifiersMap {
for _, method := range clzMap.Methods {
identMethodMap[key + "." + method.Name] = method
}
}
for _, clz := range deps {
// TODO refactoring identify & annotation
for _, method := range clz.Methods {
fullName := clz.Package + "." + clz.Class + "." + method.Name
checkIgnoreTest(clz, identMethodMap[fullName], &results)
}
}
return results
}
func checkIgnoreTest(clz models.JClassNode, method models.JMethod, results *[]TestBadSmell) {
for _, annotation := range method.Annotations {
if annotation.QualifiedName == "Ignore" {
tbs := *&TestBadSmell{
FileName: clz.Path,
Type: "IgnoreTest",
Description: "",
Line: 0,
}
*results = append(*results, tbs)
}
}
}
......@@ -24,7 +24,29 @@ func GetJavaFiles(codeDir string) []string {
}
}
if strings.HasSuffix(path, ".java") && !strings.Contains(path, "Test.java")&& !strings.Contains(path, "Tests.java"){
if strings.HasSuffix(path, ".java") && !strings.Contains(path, "Test.java") && !strings.Contains(path, "Tests.java") {
files = append(files, path)
}
return nil
})
return files
}
func GetJavaTestFiles(codeDir string) []string {
files := make([]string, 0)
gitIgnore, err := ignore.CompileIgnoreFile(".gitignore")
if err != nil {
fmt.Println(err)
}
_ = filepath.Walk(codeDir, func(path string, fi os.FileInfo, err error) error {
if gitIgnore != nil {
if gitIgnore.MatchesPath(path) {
return nil
}
}
if strings.Contains(path, "Test.java") || strings.Contains(path, "Tests.java") {
files = append(files, path)
}
return nil
......@@ -35,7 +57,7 @@ func GetJavaFiles(codeDir string) []string {
func ProcessFile(path string) *JavaParser {
is, _ := antlr.NewFileStream(path)
lexer := NewJavaLexer(is)
stream := antlr.NewCommonTokenStream(lexer, 0);
stream := antlr.NewCommonTokenStream(lexer, 0)
parser := NewJavaParser(stream)
return parser
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册