Commit 50f10a98 authored by Daniel Bluhm's avatar Daniel Bluhm

Revert changes in deserialization, typescript

Cleanup state for merging upstream
Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 3c2639b9
......@@ -56,15 +56,6 @@ public class DataElementWriterGenerator implements WriterGenerator {
.fields(data.getFields())
.types(data.getFields().getTypes())
.build());
try {
writers.add(TypeScriptWriter.builder()
.name(data.getName())
.fields(nonDefaults)
.types(nonDefaults.getTypes())
.build());
} catch (UnsupportedOperationException e) {
logger.info("Failed to create typescript writer for element:", e);
}
return writers;
}
......
/*******************************************************************************
* Copyright (c) 2020- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Daniel Bluhm - Initial implementation
*******************************************************************************/
package org.eclipse.ice.dev.annotations.processors;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import javax.annotation.processing.Filer;
import javax.tools.StandardLocation;
import lombok.Builder;
import lombok.NonNull;
/**
* Writer for TypeScript representation of DataElement.
* @author Daniel Bluhm
*/
public class TypeScriptWriter
extends VelocitySourceWriter
implements GeneratedFileWriter
{
/**
* Template used for this writer.
*/
private static final String TYPESCRIPT_TEMPLATE = "templates/TypeScript.vm";
/**
* Context key for name.
*/
private static final String NAME = "name";
/**
* Context key for fields.
*/
private static final String FIELDS = "fields";
/**
* Context key for types.
*/
private static final String TYPES = "types";
/**
* Context key for primitiveMap.
*/
private static final String PRIMITIVE_MAP = "primitiveMap";
/**
* Map of Java primitive + String type strings to TypeScript type strings.
*/
private static Map<String, String> primitiveMap = Map.ofEntries(
Map.entry("java.lang.String", "string"),
Map.entry("boolean", "boolean"),
Map.entry("float", "number"),
Map.entry("long", "number"),
Map.entry("int", "number"),
Map.entry("double", "number"),
Map.entry("java.util.Date", "Date")
);
/**
* Name of file generated.
*/
private String filename;
/**
* Create Writer.
* @param name of TypeScript class generated.
* @param fields present on data element.
* @param types of fields.
* @throws UnsupportedOperationException When any field is not supported.
*/
@Builder
public TypeScriptWriter(
String name, @NonNull Fields fields, @NonNull Types types
) {
super();
for (Field field : fields) {
if (!primitiveMap.containsKey(field.getType())) {
throw new UnsupportedOperationException(String.format(
"Field %s: type %s is unsupported",
field.getName(), field.getType()
));
}
}
this.template = TYPESCRIPT_TEMPLATE;
this.filename = name;
this.context.put(NAME, name);
this.context.put(FIELDS, fields);
this.context.put(TYPES, types);
this.context.put(PRIMITIVE_MAP, primitiveMap);
}
@Override
public Writer openWriter(Filer filer) throws IOException {
return filer.createResource(
StandardLocation.SOURCE_OUTPUT,
"",
String.format("frontend/%s.ts", filename)
).openWriter();
}
}
\ No newline at end of file
......@@ -13,16 +13,12 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
......@@ -32,9 +28,7 @@ import lombok.Setter;
* This is an implementation of $interface that satisfies the dependencies of
* the @DataElement Annotation and was auto-generated by the ICE Framework.
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -43,22 +37,12 @@ import lombok.Setter;
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = ${class}.${class}Builder.class)
public class ${class} implements ${interface}, Serializable {
/**
* Logging tool
*/
private static final Logger logger = LoggerFactory.getLogger(${class}.class);
/**
* Deserialization helpers.
*/
@JsonPOJOBuilder(withPrefix = "")
public static class ${class}Builder implements ${class}BuilderMeta {
}
private interface ${class}BuilderMeta {
}
#foreach($field in $fields)
#fielddoc
......@@ -69,7 +53,7 @@ public class ${class} implements ${interface}, Serializable {
#if(!${field.Setter} || ${field.VarNameDifferent})
@Setter(AccessLevel.NONE)
#end
#fielddecl(true)
#fielddecl
#end
#foreach($field in ${fields.Constants})
......@@ -98,6 +82,25 @@ public class ${class} implements ${interface}, Serializable {
#end
#end
/**
* All args constructor for $class.
*
* Used in JSON Deserialization.
#foreach($field in $fields)
* @param ${field.VarName} {@code #fieldtype} for field ${field.VarName}
#end
*/
@JsonCreator
public $class(
#foreach($field in $fields)
@JsonProperty("${field.VarName}") #fieldparametertype ${field.VarName}#if($foreach.hasNext),#end
#end
) {
#foreach($field in $fields)
this.${field.VarName} = ${field.VarName};
#end
}
/**
* Copy constructor for $class.
* @param other Instance of $class to copy
......
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -9,7 +7,6 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
public int shouldBePublic;
protected int shouldBeProtected;
......
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -9,7 +7,6 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
@Builder.Default public int testInt = 42;
public int testInt = 42;
}
\ No newline at end of file
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -9,7 +7,6 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
@NonNull @Builder.Default public String test = "A String Value";
@NonNull public String test = "A String Value";
}
\ No newline at end of file
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -9,18 +7,17 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
@NonNull
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
@Builder.Default protected UUID privateId = UUID.randomUUID();
@Builder.Default protected long id = 0L;
@NonNull @Builder.Default protected String name = "name";
@NonNull @Builder.Default protected String description = "description";
@NonNull @Builder.Default protected String comment = "no comment";
@NonNull @Builder.Default protected String context = "default";
@Builder.Default protected boolean required = false;
@Builder.Default protected boolean secret = false;
protected UUID privateId = UUID.randomUUID();
protected long id = 0L;
@NonNull protected String name = "name";
@NonNull protected String description = "description";
@NonNull protected String comment = "no comment";
@NonNull protected String context = "default";
protected boolean required = false;
protected boolean secret = false;
protected JavascriptValidator<Test> validator;
}
\ No newline at end of file
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -9,7 +7,6 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
public byte testByte;
public short testShort;
......
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -9,7 +7,6 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
@NonNull public UUID testUuid;
@NonNull public String testString;
......
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -9,7 +7,6 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
public int testInt;
}
\ No newline at end of file
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -9,7 +7,6 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
@NonNull public UUID testUuid;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment