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
4da5245e
Commit
4da5245e
authored
Nov 29, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
2577d79f
06b2f125
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
13 deletions
+94
-13
ConfigurationMetadataAnnotationProcessor.java
...onprocessor/ConfigurationMetadataAnnotationProcessor.java
+3
-12
TypeElementMembers.java
...ework/boot/configurationprocessor/TypeElementMembers.java
+25
-1
ConfigurationMetadataAnnotationProcessorTests.java
...cessor/ConfigurationMetadataAnnotationProcessorTests.java
+12
-0
ClassWithNestedProperties.java
...configurationsample/simple/ClassWithNestedProperties.java
+54
-0
No files found.
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java
View file @
4da5245e
...
...
@@ -20,7 +20,6 @@ import java.io.FileNotFoundException;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -192,23 +191,15 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
private
void
processTypeElement
(
String
prefix
,
TypeElement
element
,
ExecutableElement
source
)
{
TypeElementMembers
members
=
new
TypeElementMembers
(
this
.
processingEnv
,
element
);
Map
<
String
,
Object
>
fieldValues
=
getFieldValues
(
element
);
TypeElementMembers
members
=
new
TypeElementMembers
(
this
.
processingEnv
,
this
.
fieldValuesParser
,
element
);
Map
<
String
,
Object
>
fieldValues
=
members
.
getFieldValues
();
processSimpleTypes
(
prefix
,
element
,
source
,
members
,
fieldValues
);
processSimpleLombokTypes
(
prefix
,
element
,
source
,
members
,
fieldValues
);
processNestedTypes
(
prefix
,
element
,
source
,
members
);
processNestedLombokTypes
(
prefix
,
element
,
source
,
members
);
}
private
Map
<
String
,
Object
>
getFieldValues
(
TypeElement
element
)
{
try
{
return
this
.
fieldValuesParser
.
getFieldValues
(
element
);
}
catch
(
Exception
ex
)
{
return
Collections
.
emptyMap
();
}
}
private
void
processSimpleTypes
(
String
prefix
,
TypeElement
element
,
ExecutableElement
source
,
TypeElementMembers
members
,
Map
<
String
,
Object
>
fieldValues
)
{
...
...
spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeElementMembers.java
View file @
4da5245e
...
...
@@ -32,6 +32,8 @@ import javax.lang.model.type.TypeKind;
import
javax.lang.model.type.TypeMirror
;
import
javax.lang.model.util.ElementFilter
;
import
org.springframework.boot.configurationprocessor.fieldvalues.FieldValuesParser
;
/**
* Provides access to relevant {@link TypeElement} members.
*
...
...
@@ -53,9 +55,14 @@ class TypeElementMembers {
private
final
Map
<
String
,
List
<
ExecutableElement
>>
publicSetters
=
new
LinkedHashMap
<
String
,
List
<
ExecutableElement
>>();
TypeElementMembers
(
ProcessingEnvironment
env
,
TypeElement
element
)
{
private
final
Map
<
String
,
Object
>
fieldValues
=
new
LinkedHashMap
<
String
,
Object
>();
private
final
FieldValuesParser
fieldValuesParser
;
TypeElementMembers
(
ProcessingEnvironment
env
,
FieldValuesParser
fieldValuesParser
,
TypeElement
element
)
{
this
.
env
=
env
;
this
.
typeUtils
=
new
TypeUtils
(
this
.
env
);
this
.
fieldValuesParser
=
fieldValuesParser
;
process
(
element
);
}
...
...
@@ -68,6 +75,19 @@ class TypeElementMembers {
.
fieldsIn
(
element
.
getEnclosedElements
()))
{
processField
(
field
);
}
try
{
Map
<
String
,
Object
>
fieldValues
=
this
.
fieldValuesParser
.
getFieldValues
(
element
);
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
fieldValues
.
entrySet
())
{
if
(!
this
.
fieldValues
.
containsKey
(
entry
.
getKey
()))
{
this
.
fieldValues
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
}
catch
(
Exception
ex
)
{
// continue
}
Element
superType
=
this
.
env
.
getTypeUtils
().
asElement
(
element
.
getSuperclass
());
if
(
superType
!=
null
&&
superType
instanceof
TypeElement
&&
!
OBJECT_CLASS_NAME
.
equals
(
superType
.
toString
()))
{
...
...
@@ -165,4 +185,8 @@ class TypeElementMembers {
return
null
;
}
public
Map
<
String
,
Object
>
getFieldValues
()
{
return
Collections
.
unmodifiableMap
(
this
.
fieldValues
);
}
}
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java
View file @
4da5245e
...
...
@@ -47,6 +47,7 @@ import org.springframework.boot.configurationsample.method.EmptyTypeMethodConfig
import
org.springframework.boot.configurationsample.method.InvalidMethodConfig
;
import
org.springframework.boot.configurationsample.method.MethodAndClassConfig
;
import
org.springframework.boot.configurationsample.method.SimpleMethodConfig
;
import
org.springframework.boot.configurationsample.simple.ClassWithNestedProperties
;
import
org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty
;
import
org.springframework.boot.configurationsample.simple.HierarchicalProperties
;
import
org.springframework.boot.configurationsample.simple.NotAnnotated
;
...
...
@@ -351,6 +352,17 @@ public class ConfigurationMetadataAnnotationProcessorTests {
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"specific.foo"
));
}
@Test
public
void
nestedClassChildProperties
()
throws
Exception
{
ConfigurationMetadata
metadata
=
compile
(
ClassWithNestedProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"nestedChildProps"
)
.
fromSource
(
ClassWithNestedProperties
.
NestedChildClass
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"nestedChildProps.child-class-property"
,
Integer
.
class
)
.
fromSource
(
ClassWithNestedProperties
.
NestedChildClass
.
class
).
withDefaultValue
(
20
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"nestedChildProps.parent-class-property"
,
Integer
.
class
)
.
fromSource
(
ClassWithNestedProperties
.
NestedChildClass
.
class
).
withDefaultValue
(
10
));
}
@Test
public
void
builderPojo
()
throws
IOException
{
ConfigurationMetadata
metadata
=
compile
(
BuilderPojo
.
class
);
...
...
spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/simple/ClassWithNestedProperties.java
0 → 100644
View file @
4da5245e
/*
* Copyright 2012-2014 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
*
* http://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
.
simple
;
import
org.springframework.boot.configurationsample.ConfigurationProperties
;
/**
* Class with nested configuration properties.
*
* @author Hrishikesh Joshi
*/
public
class
ClassWithNestedProperties
{
public
static
class
NestedParentClass
{
private
int
parentClassProperty
=
10
;
public
int
getParentClassProperty
()
{
return
this
.
parentClassProperty
;
}
public
void
setParentClassProperty
(
int
parentClassProperty
)
{
this
.
parentClassProperty
=
parentClassProperty
;
}
}
@ConfigurationProperties
(
prefix
=
"nestedChildProps"
)
public
static
class
NestedChildClass
extends
NestedParentClass
{
private
int
childClassProperty
=
20
;
public
int
getChildClassProperty
()
{
return
this
.
childClassProperty
;
}
public
void
setChildClassProperty
(
int
childClassProperty
)
{
this
.
childClassProperty
=
childClassProperty
;
}
}
}
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