diff --git a/pkg/domain/trial/code_data_struct.go b/pkg/domain/trial/code_data_struct.go index 458e11cc67b2c31efdedadb02e23065cac17b01e..6da78b11bcf5c58020cdfe017ff65d7ef294cbb6 100644 --- a/pkg/domain/trial/code_data_struct.go +++ b/pkg/domain/trial/code_data_struct.go @@ -1,14 +1,23 @@ package trial type CodeDataStruct struct { + Name string + ID string + MemberIds []string + Properties []CodeProperty + Extend string + Implements []string + Annotations []interface{} + Extension interface{} +} + +type JavaExtension struct { + MethodCalls []CodeCall + Fields []CodeProperty + Tag []interface{} +} + +type PythonAnnotation struct { Name string - ID string - MemberIds []string Properties []CodeProperty - //Fields []CodeProperty - //MethodCalls []CodeCall - //Extend string - //Implements []string - //Annotations []interface{} - //Tag []interface{} } diff --git a/pkg/domain/trial/code_file.go b/pkg/domain/trial/code_file.go index 5db0e5ba5ad34e044cf4a153518321ec318b50d3..3e68f426deaac6f840f8ea49c911a034926e493c 100644 --- a/pkg/domain/trial/code_file.go +++ b/pkg/domain/trial/code_file.go @@ -7,6 +7,7 @@ type CodeFile struct { PackageName string Imports []string Members []*CodeMember - ClassNodes []domain.JClassNode DataStructures []CodeDataStruct + // Deprecated: support for migration only + ClassNodes []domain.JClassNode } diff --git a/trial/cocago/testdata/node_infos/basic_interface.json b/trial/cocago/testdata/node_infos/basic_interface.json index 4e3b792ff01dab92627d69cb2fb83054e84cce19..7ea54413c585dabd562d80f36e5c8610abd2c67a 100644 --- a/trial/cocago/testdata/node_infos/basic_interface.json +++ b/trial/cocago/testdata/node_infos/basic_interface.json @@ -2,7 +2,11 @@ "ClassNodes": null, "DataStructures": [ { + "Annotations": null, + "Extend": "", + "Extension": null, "ID": "", + "Implements": null, "MemberIds": null, "Name": "Shape", "Properties": [ @@ -35,7 +39,11 @@ ] }, { + "Annotations": null, + "Extend": "", + "Extension": null, "ID": "", + "Implements": null, "MemberIds": null, "Name": "Object", "Properties": [ @@ -59,7 +67,11 @@ ] }, { + "Annotations": null, + "Extend": "", + "Extension": null, "ID": "", + "Implements": null, "MemberIds": null, "Name": "Material", "Properties": [ diff --git a/trial/cocago/testdata/node_infos/data_struct_property.json b/trial/cocago/testdata/node_infos/data_struct_property.json index 83db0cd8d5d5bd01c45de561cc89b0ab90468644..1caa29650111716384bade1b7c3b6861d159a1c7 100644 --- a/trial/cocago/testdata/node_infos/data_struct_property.json +++ b/trial/cocago/testdata/node_infos/data_struct_property.json @@ -2,7 +2,11 @@ "ClassNodes": null, "DataStructures": [ { + "Annotations": null, + "Extend": "", + "Extension": null, "ID": "", + "Implements": null, "MemberIds": null, "Name": "CodeFile", "Properties": [ diff --git a/trial/cocago/testdata/node_infos/struct_type_zero.json b/trial/cocago/testdata/node_infos/struct_type_zero.json index d5c9a08acd9075405694acaf7081a59f0f811f06..13742583fce10458e0badd762c90f2196ca5c1e3 100644 --- a/trial/cocago/testdata/node_infos/struct_type_zero.json +++ b/trial/cocago/testdata/node_infos/struct_type_zero.json @@ -2,7 +2,11 @@ "ClassNodes": null, "DataStructures": [ { + "Annotations": null, + "Extend": "", + "Extension": null, "ID": "", + "Implements": null, "MemberIds": null, "Name": "O", "Properties": null diff --git a/trial/cocago/testdata/node_infos/struct_with_func.json b/trial/cocago/testdata/node_infos/struct_with_func.json index 5775c6f9cd886ada66dab5e3f7257e2e4dcaa36d..c63e97d3629666287aa94dba59cceb1798be6f73 100644 --- a/trial/cocago/testdata/node_infos/struct_with_func.json +++ b/trial/cocago/testdata/node_infos/struct_with_func.json @@ -2,7 +2,11 @@ "ClassNodes": null, "DataStructures": [ { + "Annotations": null, + "Extend": "", + "Extension": null, "ID": "", + "Implements": null, "MemberIds": null, "Name": "Person", "Properties": [ diff --git a/trial/cocago/testdata/node_infos/struct_with_func_decl.json b/trial/cocago/testdata/node_infos/struct_with_func_decl.json index 701b94785d5c8b996863be4b27f88defe5d59e1e..a535ab4563cc7d4a3923102f53d98f21a7aed356 100644 --- a/trial/cocago/testdata/node_infos/struct_with_func_decl.json +++ b/trial/cocago/testdata/node_infos/struct_with_func_decl.json @@ -2,7 +2,11 @@ "ClassNodes": null, "DataStructures": [ { + "Annotations": null, + "Extend": "", + "Extension": null, "ID": "", + "Implements": null, "MemberIds": null, "Name": "person", "Properties": [ diff --git a/trial/pkg/application/pyapp/py_ident_app_test.go b/trial/pkg/application/pyapp/py_ident_app_test.go index 11c89fbedef1683327981121767a490bbf260a36..35a7d4a5cff85fbea7942b955cc9476fb93a132b 100644 --- a/trial/pkg/application/pyapp/py_ident_app_test.go +++ b/trial/pkg/application/pyapp/py_ident_app_test.go @@ -42,3 +42,14 @@ func Test_PythonClass(t *testing.T) { results := app.Analysis(string(defs), "testdata/grammar/classdef.py") g.Expect(len(results.DataStructures)).To(Equal(3)) } + +func Test_PythonClassWithDecorator(t *testing.T) { + g := NewGomegaWithT(t) + + app := new(PythonApiApp) + + file, _ := ioutil.ReadFile("testdata/grammar/class_or_func_def_stmt.py") + codeFile := app.Analysis(string(file), "testdata/grammar/class_or_func_def_stmt.py") + + g.Expect(len(codeFile.DataStructures)).To(Equal(1)) +} diff --git a/trial/pkg/ast/pyast/python_ident_listener.go b/trial/pkg/ast/pyast/python_ident_listener.go index fba8ade8f5a959c0c7a6332d789ce29fca380a02..fad4ab1f1b626f4e7c1ab09eabfe30d9a4f6b889 100644 --- a/trial/pkg/ast/pyast/python_ident_listener.go +++ b/trial/pkg/ast/pyast/python_ident_listener.go @@ -1,8 +1,10 @@ package pyast import ( + "fmt" parser "github.com/phodal/coca/languages/python" "github.com/phodal/coca/pkg/domain/trial" + "reflect" ) type PythonIdentListener struct { @@ -25,6 +27,13 @@ func (s *PythonIdentListener) EnterClassdef(ctx *parser.ClassdefContext) { Properties: nil, } + switch x := ctx.GetParent().GetChild(0).(type) { + case *parser.DecoratorContext: + + default: + fmt.Println(reflect.TypeOf(x)) + } + currentCodeFile.DataStructures = append(currentCodeFile.DataStructures, dataStruct) }