Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
bd934aff
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 搜索 >>
未验证
提交
bd934aff
编写于
12月 30, 2019
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix annotaion & add creatorclass
上级
f0414789
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
943 addition
and
41 deletion
+943
-41
_fixtures/tbs/code/RedundantAssertionTest.java
_fixtures/tbs/code/RedundantAssertionTest.java
+4
-0
_fixtures/tbs/regression/CallAssertInClassTests.java
_fixtures/tbs/regression/CallAssertInClassTests.java
+680
-19
_fixtures/tbs/regression/EnvironmentSystemIntegrationTests.java
...res/tbs/regression/EnvironmentSystemIntegrationTests.java
+150
-0
core/adapter/call/java_call_app_test.go
core/adapter/call/java_call_app_test.go
+71
-1
core/adapter/call/java_call_listener.go
core/adapter/call/java_call_listener.go
+38
-21
未找到文件。
_fixtures/tbs/code/RedundantAssertionTest.java
浏览文件 @
bd934aff
...
...
@@ -7,6 +7,10 @@ import static org.junit.Assert.assertEquals;
public
class
RedundantAssertionTest
{
@Test
public
void
testTrue
()
{
Calculate
calculate
=
new
Calculate
();
int
result
=
calculate
.
add
(
7
,
8
);
int
success
=
15
;
assertEquals
(
true
,
true
);
}
}
_fixtures/tbs/regression/CallAssertInClassTests.java
浏览文件 @
bd934aff
此差异已折叠。
点击以展开。
_fixtures/tbs/regression/EnvironmentSystemIntegrationTests.java
0 → 100644
浏览文件 @
bd934aff
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.core.env
;
import
java.io.File
;
import
java.io.IOException
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
import
org.springframework.beans.factory.xml.XmlBeanDefinitionReader
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.annotation.AnnotatedBeanDefinitionReader
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ClassPathBeanDefinitionScanner
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.Profile
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.context.support.FileSystemXmlApplicationContext
;
import
org.springframework.context.support.GenericApplicationContext
;
import
org.springframework.context.support.GenericXmlApplicationContext
;
import
org.springframework.context.support.StaticApplicationContext
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.jca.context.ResourceAdapterApplicationContext
;
import
org.springframework.jca.support.SimpleBootstrapContext
;
import
org.springframework.jca.work.SimpleTaskWorkManager
;
import
org.springframework.mock.env.MockEnvironment
;
import
org.springframework.mock.env.MockPropertySource
;
import
org.springframework.mock.web.MockServletConfig
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.web.context.WebApplicationContext
;
import
org.springframework.web.context.support.AbstractRefreshableWebApplicationContext
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
org.springframework.web.context.support.GenericWebApplicationContext
;
import
org.springframework.web.context.support.StandardServletEnvironment
;
import
org.springframework.web.context.support.StaticWebApplicationContext
;
import
org.springframework.web.context.support.XmlWebApplicationContext
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
static
org
.
springframework
.
beans
.
factory
.
support
.
BeanDefinitionBuilder
.
rootBeanDefinition
;
import
static
org
.
springframework
.
context
.
ConfigurableApplicationContext
.
ENVIRONMENT_BEAN_NAME
;
import
static
org
.
springframework
.
core
.
env
.
EnvironmentSystemIntegrationTests
.
Constants
.
DERIVED_DEV_BEAN_NAME
;
import
static
org
.
springframework
.
core
.
env
.
EnvironmentSystemIntegrationTests
.
Constants
.
DERIVED_DEV_ENV_NAME
;
import
static
org
.
springframework
.
core
.
env
.
EnvironmentSystemIntegrationTests
.
Constants
.
DEV_BEAN_NAME
;
import
static
org
.
springframework
.
core
.
env
.
EnvironmentSystemIntegrationTests
.
Constants
.
DEV_ENV_NAME
;
import
static
org
.
springframework
.
core
.
env
.
EnvironmentSystemIntegrationTests
.
Constants
.
ENVIRONMENT_AWARE_BEAN_NAME
;
import
static
org
.
springframework
.
core
.
env
.
EnvironmentSystemIntegrationTests
.
Constants
.
PROD_BEAN_NAME
;
import
static
org
.
springframework
.
core
.
env
.
EnvironmentSystemIntegrationTests
.
Constants
.
PROD_ENV_NAME
;
import
static
org
.
springframework
.
core
.
env
.
EnvironmentSystemIntegrationTests
.
Constants
.
TRANSITIVE_BEAN_NAME
;
import
static
org
.
springframework
.
core
.
env
.
EnvironmentSystemIntegrationTests
.
Constants
.
XML_PATH
;
/**
* System integration tests for container support of the {@link Environment} API.
*
* <p>
* Tests all existing BeanFactory and ApplicationContext implementations to ensure that:
* <ul>
* <li>a standard environment object is always present
* <li>a custom environment object can be set and retrieved against the factory/context
* <li>the {@link EnvironmentAware} interface is respected
* <li>the environment object is registered with the container as a singleton bean (if an
* ApplicationContext)
* <li>bean definition files (if any, and whether XML or @Configuration) are registered
* conditionally based on environment metadata
* </ul>
*
* @author Chris Beams
* @author Sam Brannen
* @see org.springframework.context.support.EnvironmentIntegrationTests
*/
@SuppressWarnings
(
"resource"
)
public
class
EnvironmentSystemIntegrationTests
{
private
final
ConfigurableEnvironment
prodEnv
=
new
StandardEnvironment
();
private
final
ConfigurableEnvironment
devEnv
=
new
StandardEnvironment
();
private
final
ConfigurableEnvironment
prodWebEnv
=
new
StandardServletEnvironment
();
@BeforeEach
void
setUp
()
{
prodEnv
.
setActiveProfiles
(
PROD_ENV_NAME
);
devEnv
.
setActiveProfiles
(
DEV_ENV_NAME
);
prodWebEnv
.
setActiveProfiles
(
PROD_ENV_NAME
);
}
@Test
void
mostSpecificDerivedClassDrivesEnvironment_withDevEnvAndDerivedDevConfigClass
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
setEnvironment
(
devEnv
);
ctx
.
register
(
DerivedDevConfig
.
class
);
ctx
.
refresh
();
assertThat
(
ctx
.
containsBean
(
DEV_BEAN_NAME
)).
isFalse
();
assertThat
(
ctx
.
containsBean
(
DERIVED_DEV_BEAN_NAME
)).
isFalse
();
assertThat
(
ctx
.
containsBean
(
TRANSITIVE_BEAN_NAME
)).
isFalse
();
}
@Test
void
annotationConfigApplicationContext_withProfileExpressionMatchOr
()
{
testProfileExpression
(
true
,
"p3"
);
}
@Test
void
annotationConfigApplicationContext_withProfileExpressionMatchAnd
()
{
testProfileExpression
(
true
,
"p1"
,
"p2"
);
}
@Test
void
annotationConfigApplicationContext_withProfileExpressionNoMatchAnd
()
{
testProfileExpression
(
false
,
"p1"
);
}
@Test
void
annotationConfigApplicationContext_withProfileExpressionNoMatchNone
()
{
testProfileExpression
(
false
,
"p4"
);
}
private
void
testProfileExpression
(
boolean
expected
,
String
...
activeProfiles
)
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
StandardEnvironment
environment
=
new
StandardEnvironment
();
environment
.
setActiveProfiles
(
activeProfiles
);
ctx
.
setEnvironment
(
environment
);
ctx
.
register
(
ProfileExpressionConfig
.
class
);
ctx
.
refresh
();
assertThat
(
ctx
.
containsBean
(
"expressionBean"
)).
isEqualTo
(
expected
);
}
}
core/adapter/call/java_call_app_test.go
浏览文件 @
bd934aff
...
...
@@ -107,4 +107,74 @@ func TestAnnotation(t *testing.T) {
}
g
.
Expect
(
true
)
.
To
(
Equal
(
true
))
}
\ No newline at end of file
}
func
Test_ShouldHaveOnlyOneAnnotation
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../_fixtures/tbs/regression/CallAssertInClassTests.java"
codePath
=
filepath
.
FromSlash
(
codePath
)
callNodes
:=
getCallNodes
(
codePath
)
methodMap
:=
make
(
map
[
string
]
models
.
JMethod
)
for
_
,
c
:=
range
callNodes
[
0
]
.
Methods
{
methodMap
[
c
.
Name
]
=
c
}
g
.
Expect
(
len
(
methodMap
[
"supportsEventType"
]
.
Annotations
))
.
To
(
Equal
(
1
))
g
.
Expect
(
len
(
methodMap
[
"genericListenerRawTypeTypeErasure"
]
.
Annotations
))
.
To
(
Equal
(
1
))
}
func
Test_ShouldHaveOnlyOneAnnotationWithMultipleSame
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../_fixtures/tbs/regression/EnvironmentSystemIntegrationTests.java"
codePath
=
filepath
.
FromSlash
(
codePath
)
callNodes
:=
getCallNodes
(
codePath
)
methodMap
:=
make
(
map
[
string
]
models
.
JMethod
)
for
_
,
c
:=
range
callNodes
[
0
]
.
Methods
{
methodMap
[
c
.
Name
]
=
c
}
g
.
Expect
(
len
(
methodMap
[
"setUp"
]
.
Annotations
))
.
To
(
Equal
(
1
))
g
.
Expect
(
len
(
methodMap
[
"annotationConfigApplicationContext_withProfileExpressionMatchOr"
]
.
Annotations
))
.
To
(
Equal
(
1
))
g
.
Expect
(
len
(
methodMap
[
"annotationConfigApplicationContext_withProfileExpressionMatchAnd"
]
.
Annotations
))
.
To
(
Equal
(
1
))
g
.
Expect
(
len
(
methodMap
[
"annotationConfigApplicationContext_withProfileExpressionNoMatchAnd"
]
.
Annotations
))
.
To
(
Equal
(
1
))
g
.
Expect
(
len
(
methodMap
[
"annotationConfigApplicationContext_withProfileExpressionNoMatchNone"
]
.
Annotations
))
.
To
(
Equal
(
1
))
}
func
Test_CreatorAnnotation
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../_fixtures/grammar/HostDependentDownloadableContribution.java"
codePath
=
filepath
.
FromSlash
(
codePath
)
callNodes
:=
getCallNodes
(
codePath
)
methodMap
:=
make
(
map
[
string
]
models
.
JMethod
)
for
_
,
c
:=
range
callNodes
[
0
]
.
Methods
{
methodMap
[
c
.
Name
]
=
c
}
g
.
Expect
(
len
(
methodMap
[
"macOsXPositiveTest"
]
.
Annotations
))
.
To
(
Equal
(
0
))
}
func
Test_ShouldGetMethodCreators
(
t
*
testing
.
T
)
{
g
:=
NewGomegaWithT
(
t
)
codePath
:=
"../../../_fixtures/grammar/HostDependentDownloadableContribution.java"
codePath
=
filepath
.
FromSlash
(
codePath
)
callNodes
:=
getCallNodes
(
codePath
)
methodMap
:=
make
(
map
[
string
]
models
.
JMethod
)
for
_
,
c
:=
range
callNodes
[
0
]
.
Methods
{
methodMap
[
c
.
Name
]
=
c
}
fmt
.
Println
(
methodMap
[
"macOsXPositiveTest"
])
g
.
Expect
(
len
(
methodMap
[
"macOsXPositiveTest"
]
.
Creators
))
.
To
(
Equal
(
2
))
}
core/adapter/call/java_call_listener.go
浏览文件 @
bd934aff
...
...
@@ -99,7 +99,7 @@ func (s *JavaCallListener) exitBody() {
currentNode
.
Path
=
fileName
}
if
currentType
==
"Creator"
{
if
currentType
==
"Creator
Class
"
{
var
methodsArray
[]
models
.
JMethod
for
_
,
value
:=
range
creatorMethodMap
{
methodsArray
=
append
(
methodsArray
,
value
)
...
...
@@ -246,7 +246,7 @@ func (s *JavaCallListener) EnterAnnotation(ctx *parser.AnnotationContext) {
currentMethod
.
Annotations
=
append
(
currentMethod
.
Annotations
,
annotation
)
}
else
{
annotation
:=
common_listener
.
BuildAnnotation
(
ctx
)
if
currentType
==
"Creator"
{
if
currentType
==
"Creator
Class
"
{
currentCreatorNode
.
Annotations
=
append
(
currentCreatorNode
.
Annotations
,
annotation
)
}
else
{
currentNode
.
Annotations
=
append
(
currentNode
.
Annotations
,
annotation
)
...
...
@@ -300,6 +300,7 @@ func (s *JavaCallListener) EnterMethodDeclaration(ctx *parser.MethodDeclarationC
Annotations
:
currentMethod
.
Annotations
,
Override
:
isOverrideMethod
,
Parameters
:
nil
,
Creators
:
nil
,
}
parameters
:=
ctx
.
FormalParameters
()
...
...
@@ -336,7 +337,7 @@ func buildMethodParameters(parameters parser.IFormalParametersContext, method *m
}
func
updateMethod
(
method
*
models
.
JMethod
)
{
if
currentType
==
"Creator"
{
if
currentType
==
"Creator
Class
"
{
creatorMethodMap
[
getMethodMapName
(
*
method
)]
=
*
method
}
else
{
currentMethod
=
*
method
...
...
@@ -350,21 +351,23 @@ func (s *JavaCallListener) ExitMethodDeclaration(ctx *parser.MethodDeclarationCo
}
func
exitMethod
()
{
if
currentType
==
"Creator"
{
if
currentType
==
"Creator
Class
"
{
return
}
if
methodQueue
==
nil
||
len
(
methodQueue
)
<
1
{
currentMethod
=
models
.
NewJMethod
()
return
}
if
len
(
methodQueue
)
<=
2
{
currentMethod
=
methodQueue
[
0
]
}
else
{
methodQueue
=
methodQueue
[
0
:
len
(
methodQueue
)
-
1
]
currentMethod
=
models
.
NewJMethod
()
}
currentMethod
=
models
.
NewJMethod
()
//
//if methodQueue == nil || len(methodQueue) < 1 {
// currentMethod = models.NewJMethod()
// return
//}
//
//if len(methodQueue) <= 2 {
// currentMethod = methodQueue[0]
//} else {
// methodQueue = methodQueue[0 : len(methodQueue)-1]
// currentMethod = models.NewJMethod()
//}
}
// TODO: add inner creator examples
...
...
@@ -401,15 +404,27 @@ func (s *JavaCallListener) EnterCreator(ctx *parser.CreatorContext) {
createdName
:=
identifier
.
GetText
()
localVars
[
variableName
]
=
createdName
currentType
=
"Creator"
classNodeQueue
=
append
(
classNodeQueue
,
*
currentNode
)
buildCreatedCall
(
createdName
,
ctx
)
if
currentMethod
.
Name
==
""
{
return
}
if
ctx
.
ClassCreatorRest
()
==
nil
{
return
}
if
ctx
.
ClassCreatorRest
()
.
(
*
parser
.
ClassCreatorRestContext
)
.
ClassBody
()
==
nil
{
return
}
currentType
=
"CreatorClass"
text
:=
ctx
.
CreatedName
()
.
GetText
()
creatorNode
:=
&
models
.
JClassNode
{
Package
:
currentPkg
,
Class
:
text
,
Type
:
"Creator"
,
Type
:
"Creator
Class
"
,
Path
:
""
,
Fields
:
nil
,
Methods
:
nil
,
...
...
@@ -425,14 +440,16 @@ func (s *JavaCallListener) EnterCreator(ctx *parser.CreatorContext) {
}
func
(
s
*
JavaCallListener
)
ExitCreator
(
ctx
*
parser
.
CreatorContext
)
{
method
:=
methodMap
[
getMethodMapName
(
currentMethod
)]
method
.
Creators
=
append
(
method
.
Creators
,
currentCreatorNode
)
methodMap
[
getMethodMapName
(
currentMethod
)]
=
method
currentType
=
""
currentCreatorNode
=
*
models
.
NewClassNode
()
if
classNodeQueue
==
nil
||
len
(
classNodeQueue
)
<
=
1
{
if
classNodeQueue
==
nil
||
len
(
classNodeQueue
)
<
1
{
return
}
currentMethod
.
Creators
=
append
(
currentMethod
.
Creators
,
currentCreatorNode
)
}
func
buildCreatedCall
(
createdName
string
,
ctx
*
parser
.
CreatorContext
)
{
...
...
@@ -441,7 +458,7 @@ func buildCreatedCall(createdName string, ctx *parser.CreatorContext) {
jMethodCall
:=
&
models
.
JMethodCall
{
Package
:
removeTarget
(
fullType
),
Type
:
"
creator
"
,
Type
:
"
CreatorClass
"
,
Class
:
createdName
,
MethodName
:
""
,
StartLine
:
ctx
.
GetStart
()
.
GetLine
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录