Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eclipse Projects
The Eclipse Integrated Computational Environment
ice
Commits
65e199d1
Commit
65e199d1
authored
Jul 22, 2020
by
Jay Jay Billings
Browse files
Merge branch 'next' of
https://github.com/eclipse/ice
into next
parents
3373a439
a6c82006
Changes
9
Hide whitespace changes
Inline
Side-by-side
org.eclipse.ice.dev/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/DefaultFields.java
View file @
65e199d1
...
...
@@ -18,22 +18,16 @@ public class DefaultFields {
* This field is left out of the <code>DataElement.matches</code> checks.
*/
private
static
Field
privateId
=
Field
.
builder
()
.
name
(
"privateId"
)
.
name
(
"UUID"
)
.
varName
(
"privateId"
)
.
type
(
UUID
.
class
)
.
docString
(
"The private UUID of this element. This field is left out of matches()."
)
.
defaultValue
(
UUID
.
class
.
getCanonicalName
()
+
".randomUUID()"
)
.
match
(
false
)
.
getter
(
fals
e
)
.
getter
(
tru
e
)
.
setter
(
false
)
.
alias
(
Field
.
builder
()
.
name
(
"UUID"
)
.
unique
(
true
)
.
getter
(
true
)
.
setter
(
false
)
.
defaultField
(
true
)
.
build
()
)
.
defaultField
(
true
)
.
unique
(
true
)
.
build
();
/**
...
...
org.eclipse.ice.dev/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/Field.java
View file @
65e199d1
...
...
@@ -31,11 +31,24 @@ import lombok.Singular;
@Builder
@JsonDeserialize
(
builder
=
Field
.
FieldBuilder
.
class
)
public
class
Field
{
/**
* Name of the field.
*/
String
name
;
/**
* Name of the variable representing this field. If the same as
* {@link Field#name}, leave null.
*
* This handles cases like the default field {@link DefaultFields#privateId}
* being accessible through the method
* {@link org.eclipse.ice.dev.annotations.IDataElement#getUUID()} rather than
* {@code getPrivateId()}. In that example, the variable name would be
* {@code privateId} and the field name would be {@code UUID}.
*/
String
varName
;
/**
* String representation of the field's type.
*/
...
...
@@ -97,11 +110,6 @@ public class Field {
*/
boolean
unique
;
/**
* A list of alternate names for this field.
*/
@Singular
(
"alias"
)
List
<
Field
>
aliases
;
/**
* A list of annotations to apply to this field.
*/
...
...
@@ -112,6 +120,29 @@ public class Field {
*/
@Builder
.
Default
Set
<
String
>
modifiers
=
Set
.
of
(
"protected"
);
/**
* Get the name of the variable representing this field.
*
* If no variable name has been specifically set, var == name.
* @return the name of the variable
*/
@JsonIgnore
public
String
getVarName
()
{
if
(
this
.
varName
==
null
)
{
return
this
.
name
;
}
return
this
.
varName
;
}
/**
* Get whether this field has a variable name that differs from the field name.
* @return whether the variable name differs from the field name
*/
@JsonIgnore
public
boolean
isVarNameDifferent
()
{
return
this
.
varName
!=
null
;
}
/**
* Get a class by name or return null if not found
* @param cls
...
...
@@ -153,39 +184,6 @@ public class Field {
return
prefix
+
getNameForMethod
();
}
/**
* Return whether this field has a getter, directly or via one of its aliases.
*
* This method is separate from {@code getAnyGetter()} despite being very
* similar for ease of use in velocity templates.
* @return true if getter present, false otherwise
*/
@JsonIgnore
public
boolean
hasGetter
()
{
return
getAnyGetter
()
!=
null
;
}
/**
* Return the name of any valid getter for this field, either a direct getter
* for the field or one of its aliases.
* @return getter name, null if none present
*/
@JsonIgnore
public
String
getAnyGetter
()
{
String
retval
=
null
;
if
(
getter
)
{
retval
=
getGetterName
();
}
else
{
for
(
Field
alias
:
aliases
)
{
if
(
alias
.
isGetter
())
{
retval
=
alias
.
getGetterName
();
break
;
}
}
}
return
retval
;
}
/**
* Return if this field has a final modifier and is therefore a constant value.
* @return field is constant
...
...
@@ -199,7 +197,6 @@ public class Field {
* Instruct Jackson how to deserialize fields.
*/
private
interface
FieldBuilderMeta
{
@JsonDeserialize
(
contentAs
=
Field
.
class
)
FieldBuilder
aliases
(
Collection
<?
extends
Field
>
aliases
);
@JsonDeserialize
(
contentAs
=
String
.
class
)
FieldBuilder
annotations
(
Collection
<?
extends
String
>
annotations
);
@JsonDeserialize
(
contentAs
=
String
.
class
)
FieldBuilder
modifiers
(
Set
<
String
>
modifiers
);
@JsonAlias
(
"fieldName"
)
FieldBuilder
name
(
String
name
);
...
...
org.eclipse.ice.dev/org.eclipse.ice.dev.annotations/src/main/java/org/eclipse/ice/dev/annotations/processors/Fields.java
View file @
65e199d1
...
...
@@ -73,6 +73,19 @@ public class Fields implements Iterable<Field> {
.
iterator
();
}
/**
* Return iterator over fields where the variable name differs from the
* Field name.
*
* @return iterator over the fields
* @see Field#isVarDifferent()
*/
public
Iterator
<
Field
>
getVarNamesDiffer
()
{
return
fields
.
stream
()
.
filter
(
field
->
field
.
isVarNameDifferent
())
.
iterator
();
}
/**
* Returns an iterator over the mutable fields found in this collection. The
* mutable fields are the default set iterated over because they are the most
...
...
org.eclipse.ice.dev/org.eclipse.ice.dev.annotations/src/main/resources/templates/DataElement.vm
View file @
65e199d1
...
...
@@ -44,10 +44,10 @@ public class ${class} implements ${interface}, Serializable {
#
fielddoc
#
nonnull
($
tab
,
$
newline
)
#
if
(
!
${
field
.
Getter
})
#
if
(
!
${
field
.
Getter
}
||
${
field
.
VarNameDifferent
}
)
@Getter(AccessLevel.NONE)
#
end
#
if
(
!
${
field
.
Setter
})
#
if
(
!
${
field
.
Setter
}
||
${
field
.
VarNameDifferent
}
)
@Setter(AccessLevel.NONE)
#
end
#
fielddecl
...
...
@@ -57,27 +57,25 @@ public class ${class} implements ${interface}, Serializable {
#
fielddoc
#
fielddecl
#
end
#
foreach
($
field
in
$
fields
)
#
foreach
($
alias
in
${
field
.
aliases
})
#
if
(${
alias
.
Getter
})
#
foreach
($
field
in
${
fields
.
VarNamesDiffer
})
#
if
(${
field
.
Getter
})
/**
* Get
${
field
.
Name
}
by alias
${
alias
.
Name
}
.
* Get
${
field
.
Var
Name
}
.
* @return
${
field
.
Name
}
*/
public
#
fieldtype
get
${
alias
.
NameForMethod
}
()
{
return
${
field
.
Name
}
;
public
#
fieldtype
${
field
.
GetterName
}
()
{
return
${
field
.
Var
Name
}
;
}
#
end
#
if
(${
alias
.
Setter
})
#
end
#
if
(${
field
.
Setter
})
/**
* Set
${
field
.
Name
}
by alias
${
alias
.
Name
}
.
* Set
${
field
.
VarName
}
.
* @param
${
field
.
VarName
}
new value for
${
field
.
Name
}
.
*/
public void set
${
alias
.
NameForMethod
}
(
#
nonnull
(
""
,
" "
)#
field
type
${
field
.
Name
}
)
{
this.
${
field
.
Name
}
=
${
field
.
Name
}
;
public void set
${
field
.
NameForMethod
}
(
#
fieldparameter
type
${
field
.
Var
Name
}
)
{
this.
${
field
.
Var
Name
}
=
${
field
.
Var
Name
}
;
}
#
end
#
end
#
end
...
...
@@ -86,17 +84,17 @@ public class ${class} implements ${interface}, Serializable {
*
* Used in JSON Deserialization.
#
foreach
($
field
in
$
fields
)
* @param
${
field
.
Name
}
{
@code
#
fieldtype
}
for field
${
field
.
Name
}
* @param
${
field
.
Var
Name
}
{
@code
#
fieldtype
}
for field
${
field
.
Var
Name
}
#
end
*/
@JsonCreator
public
$
class
(
#foreach
($
field
in
$
fields
)
@JsonProperty
(
"${field.Name}"
)
#
non
null
(
""
,
" "
)
#field
type
${
field
.
Name
}
#if
($
foreach
.
hasNext
),
#end
@JsonProperty
(
"${field.
Var
Name}"
)
#
fieldparameter
type
${
field
.
Var
Name
}
#if
($
foreach
.
hasNext
),
#end
#end
)
{
#
foreach
($
field
in
$
fields
)
this.
${
field
.
Name
}
=
${
field
.
Name
}
;
this.
${
field
.
Var
Name
}
=
${
field
.
Var
Name
}
;
#
end
}
...
...
@@ -131,8 +129,8 @@ public class ${class} implements ${interface}, Serializable {
@Override
public void copy(@NonNull
$
interface
element)
{
#
foreach
($
field
in
$
fields
)
#
if
($
field
.
has
Getter
()
)
this.
${
field
.
Name
}
= element.
${
field
.
Any
Getter
}
();
#
if
($
field
.
Getter
)
this.
${
field
.
Var
Name
}
= element.
${
field
.
Getter
Name
}
();
#
end
#
end
}
...
...
@@ -162,23 +160,23 @@ public class ${class} implements ${interface}, Serializable {
// by debuggers.
#
foreach
($
field
in
${
fields
.
Match
})
// Matching
${
field
.
Name
}
boolean
${
field
.
Name
}
Match =
// Matching
${
field
.
Var
Name
}
boolean
${
field
.
Var
Name
}
Match =
#
if
(${
field
.
Nullable
})
this.
${
field
.
Name
}
== null ?
this.
${
field
.
Name
}
== other.
${
field
.
Name
}
:
this.
${
field
.
Name
}
.equals(other.
${
field
.
Name
}
);
this.
${
field
.
Var
Name
}
== null ?
this.
${
field
.
Var
Name
}
== other.
${
field
.
Var
Name
}
:
this.
${
field
.
Var
Name
}
.equals(other.
${
field
.
Var
Name
}
);
#
elseif
(${
field
.
Primitive
})
this.
${
field
.
Name
}
== other.
${
field
.
Name
}
;
this.
${
field
.
Var
Name
}
== other.
${
field
.
Var
Name
}
;
#
else
this.
${
field
.
Name
}
.equals(other.
${
field
.
Name
}
);
this.
${
field
.
Var
Name
}
.equals(other.
${
field
.
Var
Name
}
);
#
end
## if nullable
#
end
## foreach
retval =
#
@settab(6)
#
foreach
($
field
in
${
fields
.
Match
})
#
@nonewline
${
field
.
Name
}
Match
#
if
($
foreach
.
hasNext
)
&&
#
if
($
foreach
.
count
%
3
==
0
)$
newline
#
else
#
end
#
end
${
field
.
Var
Name
}
Match
#
if
($
foreach
.
hasNext
)
&&
#
if
($
foreach
.
count
%
3
==
0
)$
newline
#
else
#
end
#
end
#
end
#
end
;
#
end
}
...
...
org.eclipse.ice.dev/org.eclipse.ice.dev.annotations/src/main/resources/templates/ElementInterface.vm
View file @
65e199d1
...
...
@@ -25,7 +25,7 @@ public interface $interface extends IDataElement<${interface}> {
/**
* Set
${
field
.
Name
}
.
*/
public void set
${
field
.
NameForMethod
}
(
#
fieldtype
${
field
.
Name
}
);
public void set
${
field
.
NameForMethod
}
(
#
fieldtype
${
field
.
Var
Name
}
);
#
end
## if Setter
#
end
## if DefaultField
#
end
## foreach field
...
...
org.eclipse.ice.dev/org.eclipse.ice.dev.annotations/src/main/resources/templates/PersistenceHandler.vm
View file @
65e199d1
...
...
@@ -85,15 +85,15 @@ public class $class implements $interface<$elementInterface> {
/**
* Find
$
elementInterface
by
${
var
.
Name
}
.
* @param
${
var
.
Name
}
* @param
${
var
.
Var
Name
}
* @return found element or null
*/
#
if
(${
var
.
DefaultField
})
@Override
#
end
public
$
elementInterface
findBy
${
var
.
NameForMethod
}
(
$
type
${
var
.
Name
}
) throws Exception
{
public
$
elementInterface
findBy
${
var
.
NameForMethod
}
(
$
type
${
var
.
Var
Name
}
) throws Exception
{
Document doc = this.collection
.find(PersistenceFilters.eq("
${
docName
}
",
${
var
.
Name
}
))
.find(PersistenceFilters.eq("
${
docName
}
",
${
var
.
Var
Name
}
))
.first();
if (doc == null)
{
return null;
...
...
@@ -105,23 +105,20 @@ public class $class implements $interface<$elementInterface> {
/**
* Find
$
elementInterface
by
${
var
.
Name
}
.
* @param
${
var
.
Name
}
* @param
${
var
.
Var
Name
}
* @return Iterator of results
*/
#
if
(${
var
.
DefaultField
})
@Override
#
end
public Iterable
<
$
elementInterface
>
findBy
${
var
.
NameForMethod
}
(
${
var
.
Type
}
${
var
.
Name
}
) throws Exception
{
return this.collection.find(PersistenceFilters.eq("
${
var
.
Name
}
",
${
var
.
Name
}
))
public Iterable
<
$
elementInterface
>
findBy
${
var
.
NameForMethod
}
(
${
var
.
Type
}
${
var
.
Var
Name
}
) throws Exception
{
return this.collection.find(PersistenceFilters.eq("
${
var
.
Var
Name
}
",
${
var
.
Var
Name
}
))
.map(doc -> mapper.convertValue(doc,
${
implementation
}
.class));
}
#
end
## if unique
#
end
## if getter and search
#
end
## macro findmethod
#
foreach
($
field
in
$
fields
)
#
findmethod
($
field
${
field
.
Type
}
${
field
.
Name
})
#
foreach
($
alias
in
$
field
.
Aliases
)
#
findmethod
($
alias
${
field
.
Type
}
${
field
.
Name
})
#
end
#
findmethod
($
field
${
field
.
Type
}
${
field
.
VarName
})
#
end
}
\ No newline at end of file
org.eclipse.ice.dev/org.eclipse.ice.dev.annotations/src/main/resources/templates/common.vm
View file @
65e199d1
...
...
@@ -46,10 +46,13 @@
## Get evaluated field type
#
macro
(
fieldtype
)#
evaluate
(${
field
.
Type
})#
end
## Get the type of this field for use in parameter list (includes nonnull)
#
macro
(
fieldparametertype
)#
nonnull
(
""
,
" "
)#
fieldtype
#
end
## Get field declaration
#
macro
(
fielddecl
)
#
@settab(1)
#
join
(
" "
,
${
field
.
Annotations
})#
join
(
" "
,
${
field
.
Modifiers
})#
fieldtype
()
${
field
.
Name
}#
if
(${
field
.
DefaultValue
})
=
#
evaluate
(${
field
.
DefaultValue
})#
end
;
#
join
(
" "
,
${
field
.
Annotations
})#
join
(
" "
,
${
field
.
Modifiers
})#
fieldtype
()
${
field
.
Var
Name
}#
if
(${
field
.
DefaultValue
})
=
#
evaluate
(${
field
.
DefaultValue
})#
end
;
#
end
#
end
...
...
org.eclipse.ice.dev/org.eclipse.ice.dev.annotations/src/test/java/org/eclipse/ice/tests/dev/annotations/processors/FieldTest.java
View file @
65e199d1
...
...
@@ -5,6 +5,8 @@ package org.eclipse.ice.tests.dev.annotations.processors;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
java.util.UUID
;
import
org.eclipse.ice.dev.annotations.processors.Field
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -35,7 +37,6 @@ class FieldTest {
.
nullable
(
true
)
.
getter
(
false
)
.
setter
(
false
)
.
alias
(
Field
.
builder
().
name
(
"another"
).
getter
(
true
).
build
())
.
build
();
String
fJson
=
mapper
.
writeValueAsString
(
f
);
...
...
@@ -59,55 +60,30 @@ class FieldTest {
.
type
(
boolean
.
class
)
.
build
();
assertEquals
(
"isTest"
,
f
.
getGetterName
());
}
/**
* Test hasGetter.
*/
@Test
void
testHasGetter
()
{
Field
f
=
Field
.
builder
()
.
name
(
"test"
)
.
type
(
String
.
class
)
.
getter
(
true
)
.
build
();
assertTrue
(
f
.
hasGetter
());
f
=
Field
.
builder
()
.
name
(
"
test
"
)
.
name
(
"
TEST
"
)
.
type
(
String
.
class
)
.
getter
(
false
)
.
alias
(
Field
.
builder
().
name
(
"another"
).
getter
(
true
).
build
())
.
build
();
assertTrue
(
f
.
hasGetter
());
f
=
Field
.
builder
()
.
name
(
"test"
)
.
getter
(
false
)
.
build
();
assertFalse
(
f
.
hasGetter
());
assertEquals
(
"getTEST"
,
f
.
getGetterName
());
}
/**
* Test
getAnyGetter
.
* Test
our handling of differences between the field name and the var name
.
*/
@Test
void
test
AnyGetter
()
{
void
test
NameAndVarDifferences
()
{
Field
f
=
Field
.
builder
()
.
name
(
"test"
)
.
type
(
String
.
class
)
.
getter
(
true
)
.
build
();
assertEquals
(
"getTest"
,
f
.
getAnyGetter
());
f
=
Field
.
builder
()
.
name
(
"test"
)
.
type
(
String
.
class
)
.
getter
(
false
)
.
alias
(
Field
.
builder
().
name
(
"another"
).
getter
(
true
).
build
())
.
name
(
"UUID"
)
.
type
(
UUID
.
class
)
.
varName
(
"privateId"
)
.
build
();
assertEquals
(
"getAnother"
,
f
.
getAnyGetter
());
assertTrue
(
f
.
isVarNameDifferent
());
assertEquals
(
"privateId"
,
f
.
getVarName
());
f
=
Field
.
builder
()
.
name
(
"test"
)
.
getter
(
false
)
.
build
();
assertNull
(
f
.
getAnyGetter
());
assertEquals
(
"test"
,
f
.
getVarName
());
assertFalse
(
f
.
isVarNameDifferent
());
}
}
org.eclipse.ice.dev/org.eclipse.ice.dev.pojofromjson/src/test/java/org/eclipse/ice/tests/dev/pojofromjson/PojoOutlineTest.java
View file @
65e199d1
...
...
@@ -35,7 +35,6 @@ public class PojoOutlineTest {
.
match
(
false
)
.
primitive
(
true
)
.
nullable
(
true
)
.
alias
(
Field
.
builder
().
name
(
"another"
).
getter
(
true
).
build
())
.
build
()
).
build
();
...
...
@@ -61,7 +60,6 @@ public class PojoOutlineTest {
.
nullable
(
true
)
.
getter
(
false
)
.
setter
(
false
)
.
alias
(
Field
.
builder
().
name
(
"another"
).
getter
(
true
).
build
())
.
build
()
).
build
();
...
...
@@ -81,7 +79,6 @@ public class PojoOutlineTest {
.
nullable
(
true
)
.
getter
(
false
)
.
setter
(
false
)
.
alias
(
Field
.
builder
().
name
(
"another"
).
getter
(
true
).
build
())
.
build
()
).
build
();
assertEquals
(
"TestElementImpl"
,
pojo
.
getImplementation
());
...
...
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