Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
0972ef34
Commit
0972ef34
authored
Apr 04, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
Closes gh-16451
parents
537a97c1
fbb5ffe0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
4 deletions
+112
-4
TypeUtils.java
...pringframework/boot/configurationprocessor/TypeUtils.java
+17
-4
GenericsMetadataGenerationTests.java
...nfigurationprocessor/GenericsMetadataGenerationTests.java
+17
-0
ComplexGenericProperties.java
...configurationsample/generic/ComplexGenericProperties.java
+43
-0
UpperBoundGenericPojo.java
...ot/configurationsample/generic/UpperBoundGenericPojo.java
+35
-0
No files found.
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java
View file @
0972ef34
...
@@ -305,15 +305,28 @@ class TypeUtils {
...
@@ -305,15 +305,28 @@ class TypeUtils {
TypeMirror
typeMirror
=
descriptor
.
resolveGeneric
(
t
);
TypeMirror
typeMirror
=
descriptor
.
resolveGeneric
(
t
);
if
(
typeMirror
!=
null
)
{
if
(
typeMirror
!=
null
)
{
if
(
typeMirror
instanceof
TypeVariable
)
{
if
(
typeMirror
instanceof
TypeVariable
)
{
// Still unresolved, let's use upper bound
TypeVariable
typeVariable
=
(
TypeVariable
)
typeMirror
;
return
visit
(((
TypeVariable
)
typeMirror
).
getUpperBound
(),
descriptor
);
// Still unresolved, let's use the upper bound, checking first if
// a cycle may exist
if
(!
hasCycle
(
typeVariable
))
{
return
visit
(
typeVariable
.
getUpperBound
(),
descriptor
);
}
}
}
else
{
else
{
return
visit
(
typeMirror
,
descriptor
);
return
visit
(
typeMirror
,
descriptor
);
}
}
}
}
// Unresolved generics, use upper bound
// Fallback to simple representation of the upper bound
return
visit
(
t
.
getUpperBound
(),
descriptor
);
return
defaultAction
(
t
.
getUpperBound
(),
descriptor
);
}
private
boolean
hasCycle
(
TypeVariable
variable
)
{
TypeMirror
upperBound
=
variable
.
getUpperBound
();
if
(
upperBound
instanceof
DeclaredType
)
{
return
((
DeclaredType
)
upperBound
).
getTypeArguments
().
stream
()
.
anyMatch
((
candidate
)
->
candidate
.
equals
(
variable
));
}
return
false
;
}
}
@Override
@Override
...
...
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/GenericsMetadataGenerationTests.java
View file @
0972ef34
...
@@ -21,9 +21,11 @@ import org.junit.Test;
...
@@ -21,9 +21,11 @@ import org.junit.Test;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.Metadata
;
import
org.springframework.boot.configurationprocessor.metadata.Metadata
;
import
org.springframework.boot.configurationsample.generic.AbstractGenericProperties
;
import
org.springframework.boot.configurationsample.generic.AbstractGenericProperties
;
import
org.springframework.boot.configurationsample.generic.ComplexGenericProperties
;
import
org.springframework.boot.configurationsample.generic.GenericConfig
;
import
org.springframework.boot.configurationsample.generic.GenericConfig
;
import
org.springframework.boot.configurationsample.generic.SimpleGenericProperties
;
import
org.springframework.boot.configurationsample.generic.SimpleGenericProperties
;
import
org.springframework.boot.configurationsample.generic.UnresolvedGenericProperties
;
import
org.springframework.boot.configurationsample.generic.UnresolvedGenericProperties
;
import
org.springframework.boot.configurationsample.generic.UpperBoundGenericPojo
;
import
org.springframework.boot.configurationsample.generic.WildcardConfig
;
import
org.springframework.boot.configurationsample.generic.WildcardConfig
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -52,6 +54,21 @@ public class GenericsMetadataGenerationTests extends AbstractMetadataGenerationT
...
@@ -52,6 +54,21 @@ public class GenericsMetadataGenerationTests extends AbstractMetadataGenerationT
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
}
@Test
public
void
complexGenericProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
ComplexGenericProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"generic"
).
fromSource
(
ComplexGenericProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"generic.test"
).
ofType
(
UpperBoundGenericPojo
.
class
)
.
fromSource
(
ComplexGenericProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.test.mappings"
,
"java.util.Map<java.lang.Enum<T>,java.lang.String>"
)
.
fromSource
(
UpperBoundGenericPojo
.
class
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
@Test
@Test
public
void
unresolvedGenericProperties
()
{
public
void
unresolvedGenericProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
AbstractGenericProperties
.
class
,
ConfigurationMetadata
metadata
=
compile
(
AbstractGenericProperties
.
class
,
...
...
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/generic/ComplexGenericProperties.java
0 → 100644
View file @
0972ef34
/*
* Copyright 2012-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
.
boot
.
configurationsample
.
generic
;
import
org.springframework.boot.configurationsample.ConfigurationProperties
;
import
org.springframework.boot.configurationsample.NestedConfigurationProperty
;
/**
* More advanced generic setup.
*
* @author Stephane Nicoll
*/
@ConfigurationProperties
(
"generic"
)
public
class
ComplexGenericProperties
{
@NestedConfigurationProperty
private
UpperBoundGenericPojo
<
Test
>
test
=
new
UpperBoundGenericPojo
<>();
public
UpperBoundGenericPojo
<
Test
>
getTest
()
{
return
this
.
test
;
}
public
enum
Test
{
ONE
,
TWO
,
THREE
}
}
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/generic/UpperBoundGenericPojo.java
0 → 100644
View file @
0972ef34
/*
* Copyright 2012-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
.
boot
.
configurationsample
.
generic
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* A pojo with a complex generic signature.
*
* @author Stephane Nicoll
*/
public
class
UpperBoundGenericPojo
<
T
extends
Enum
<
T
>>
{
private
final
Map
<
T
,
String
>
mappings
=
new
HashMap
<>();
public
Map
<
T
,
String
>
getMappings
()
{
return
this
.
mappings
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment