Unverified Commit 1ae7dae1 authored by Gregory Cage's avatar Gregory Cage Committed by GitHub
Browse files

Merge pull request #2 from eclipse/next

Next
parents ed076d32 65e199d1
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-pomless</artifactId>
<version>${tycho-version}</version>
</extension>
</extensions>
......@@ -6,3 +6,19 @@ Build instructions are available [on our wiki too](http://wiki.eclipse.org/ICE_B
Contributions follow the standard Eclipse mechanisms and you should check out our [CONTRIBUTING.md](https://github.com/eclipse/ice/blob/master/CONTRIBUTING.md) file for more information. If you are looking at this, then you are most likely using Git and can start the process by issuing
a pull request on our GitHub repo.
# Getting started on development
If you're using Eclipse for development, you need to install Lombok into the Eclipse environment so that Eclipse knows about the bytecode changes that Lombok makes during the build process. Instructions are available here: https://projectlombok.org/setup/eclipse
Using the project generators
-
Instructions for generating a new project with the maven archeytpes.
pull the org.eclipse.ice.archetypes project
make sure that the data element renderer and annotations projects are built as well
build the package and it should build the archetypes as well.
then you can use mvn archetype:generate -DarchetypeGroupId=org.eclipse.ice -DarchetypeArtifactId=data-element-archetype -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=com.test -DartifactId=testApp
Note* use -DarchetypeArtifactId=data-element-webform-archetype for the webform archetype
replace the group and artifact id's with whatever.
\ No newline at end of file
......@@ -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(false)
.getter(true)
.setter(false)
.alias(
Field.builder()
.name("UUID")
.unique(true)
.getter(true)
.setter(false)
.defaultField(true)
.build()
)
.defaultField(true)
.unique(true)
.build();
/**
......
......@@ -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);
......
......@@ -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
......
......@@ -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.VarName}.
* @return ${field.Name}
*/
public #fieldtype get${alias.NameForMethod}() {
return ${field.Name};
public #fieldtype ${field.GetterName}() {
return ${field.VarName};
}
#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("", " ")#fieldtype ${field.Name}) {
this.${field.Name} = ${field.Name};
public void set${field.NameForMethod}(#fieldparametertype ${field.VarName}) {
this.${field.VarName} = ${field.VarName};
}
#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.VarName} {@code #fieldtype} for field ${field.VarName}
#end
*/
@JsonCreator
public $class(
#foreach($field in $fields)
@JsonProperty("${field.Name}") #nonnull("", " ")#fieldtype ${field.Name}#if($foreach.hasNext),#end
@JsonProperty("${field.VarName}") #fieldparametertype ${field.VarName}#if($foreach.hasNext),#end
#end
) {
#foreach($field in $fields)
this.${field.Name} = ${field.Name};
this.${field.VarName} = ${field.VarName};
#end
}
......@@ -131,8 +129,8 @@ public class ${class} implements ${interface}, Serializable {
@Override
public void copy(@NonNull $interface element) {
#foreach($field in $fields)
#if($field.hasGetter())
this.${field.Name} = element.${field.AnyGetter}();
#if($field.Getter)
this.${field.VarName} = element.${field.GetterName}();
#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.VarName}
boolean ${field.VarName}Match =
#if(${field.Nullable})
this.${field.Name} == null ?
this.${field.Name} == other.${field.Name} :
this.${field.Name}.equals(other.${field.Name});
this.${field.VarName} == null ?
this.${field.VarName} == other.${field.VarName} :
this.${field.VarName}.equals(other.${field.VarName});
#elseif(${field.Primitive})
this.${field.Name} == other.${field.Name};
this.${field.VarName} == other.${field.VarName};
#else
this.${field.Name}.equals(other.${field.Name});
this.${field.VarName}.equals(other.${field.VarName});
#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.VarName}Match#if($foreach.hasNext) &&#if($foreach.count % 3 == 0)$newline#else #end#end
#end#end;
#end
}
......
......@@ -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.VarName});
#end## if Setter
#end## if DefaultField
#end## foreach field
......
......@@ -85,15 +85,15 @@ public class $class implements $interface<$elementInterface> {
/**
* Find $elementInterface by ${var.Name}.
* @param ${var.Name}
* @param ${var.VarName}
* @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.VarName}) throws Exception {
Document doc = this.collection
.find(PersistenceFilters.eq("${docName}", ${var.Name}))
.find(PersistenceFilters.eq("${docName}", ${var.VarName}))
.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.VarName}
* @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.VarName}) throws Exception {
return this.collection.find(PersistenceFilters.eq("${var.VarName}", ${var.VarName}))
.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
......@@ -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.VarName}#if(${field.DefaultValue}) = #evaluate(${field.DefaultValue})#end;
#end
#end
......
......@@ -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 testAnyGetter() {
void testNameAndVarDifferences() {
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());
}
}
......@@ -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());
......
<factorypath>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/dagger/dagger-compiler/2.16/dagger-compiler-2.16.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/dagger/dagger/2.16/dagger-2.16.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/dagger/dagger-producers/2.16/dagger-producers-2.16.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/checkerframework/checker-compat-qual/2.3.0/checker-compat-qual-2.3.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/dagger/dagger-spi/2.16/dagger-spi-2.16.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/googlejavaformat/google-java-format/1.4/google-java-format-1.4.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/errorprone/javac-shaded/9-dev-r4023-3/javac-shaded-9-dev-r4023-3.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/guava/23.3-jre/guava-23.3-jre.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/errorprone/error_prone_annotations/2.0.18/error_prone_annotations-2.0.18.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/squareup/javapoet/1.8.0/javapoet-1.8.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/javax/inject/javax.inject/1/javax.inject-1.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
......@@ -20,16 +20,16 @@
<configuration>
<release>11</release>
<annotationProcessorPaths>
<path>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.16</version>
</path>
<path>
<groupId>org.eclipse.ice.dev</groupId>
<artifactId>org.eclipse.ice.dev.annotations</artifactId>
<version>3.0.0-SNAPSHOT</version>
</path>
<path>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.16</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
......
......@@ -15,6 +15,8 @@ import java.io.Serializable;
import java.util.function.BiConsumer;
import javax.inject.Inject;
import org.eclipse.ice.dev.annotations.IDataElement;
/**
* This class is a basic controller that connects data and UI classes in a
* simple, pre-determined way. Data can be provided through the DataElement<V>
......@@ -35,7 +37,7 @@ import javax.inject.Inject;
* @author Jay Jay Billings
*
*/
public class Renderer<T, V extends Serializable> implements Serializable {
public class Renderer<T, V extends IDataElement> implements Serializable {
/**
* Serial version id
......@@ -43,9 +45,9 @@ public class Renderer<T, V extends Serializable> implements Serializable {
private static final long serialVersionUID = -8514680453430699108L;
private T viewer;
private DataElement<V> dataElement;
private V dataElement;
private BiConsumer<T, DataElement<V>> drawMethod;