This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert changes in deserialization, typescript"
This reverts commit 50f10a9.
- Loading branch information
Showing
11 changed files
with
172 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...nnotations/src/main/java/org/eclipse/ice/dev/annotations/processors/TypeScriptWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/******************************************************************************* | ||
* 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters