Commit db1853f9 authored by PONCELET's avatar PONCELET
Browse files

update model to sonar netcdf 1.1

parent ee5239bd
......@@ -10,6 +10,7 @@
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
......
This diff is collapsed.
......@@ -188,15 +188,16 @@ public class AsciiDoctorGenerator {
creturn(context.currentOutput);
}
private void writeVariables(List<Variable> variables, Context context) throws IOException {
if(variables.isEmpty())
return;
reallyWriteVariable("Variables", variables, context);
}
private void writeVariableAttributes( List<Attribute> attributes, Context context) throws IOException {
for(Attribute v:attributes)
{
if(v.getValue().compareTo("Float.NaN")==0)
if(v.getValue()!=null && v.getValue().compareTo("Float.NaN")==0)
continue;
String value = v.getType()!=null ? v.getType():"";
String value = v.getType()!=null ? v.getType().trim()+" ":"";
value+=":";
value+=v.getName();
//assume a string type
......@@ -213,11 +214,19 @@ public class AsciiDoctorGenerator {
{
if(v.getValue()!=null)
{
String lValue=v.getValue().replaceAll("\u002D", "\u2212");
//on utilise des espace insécables pour se conformer à la doc WCFAST
value+="\u00A0=\u00A0";
//remove hyphen minus U002D sign with minus sign U2212
value+=v.getValue().replaceAll("\u002D", "\u2212").replaceAll(".0f", ".0");
if(v.getName().compareTo("valid_range")==0)
{
value+=lValue.replaceAll("f", "");
} else
{
value+=lValue.replaceAll(".0f", ".0");
}
}
}
......
......@@ -26,7 +26,7 @@ import fr.ifremer.fr.xsf.generator.model.Variable;
public class CodeGenerator {
static File outputDir=new File("d:\\tmp");
static File outputDir=new File("d:\\tmp\\XSFGenerator");
private static final String OUTPUT_DIR_OPTION="out";
private static final String MODEL_FILE_OPTION="model";
......
package fr.ifremer.fr.xsf.generator;
import java.util.HashMap;
import java.util.List;
public class DataTypeConverter {
private static HashMap<String , DataType > vlen_specific_types=new HashMap<>();
public static DataType get(String value) throws Exception
{
switch(value.toUpperCase())
{
case "BOOLEAN":
return DataType.BOOLEAN;
//on triche un peu et map les types enum sur des bytes
case "TRANSDUCER_TYPE_T":
case "DETECTION_TYPE_T":
case "TRANSMIT_T":
case "BYTE":
return DataType.BYTE;
case "CHAR":
......@@ -35,7 +41,43 @@ public class DataTypeConverter {
case "STRING":
return DataType.BYTE;
default:
throw new Exception("Unknown netcdf type " + value);
}
// type was not found, should be a specific type, as such it shall have been declared earlier
DataType spec=vlen_specific_types.get(value);
if(spec!=null)
{
return spec;
}
throw new Exception("Unknown netcdf type " + value);
}
/**
* Check if a type is a user defined type
* */
public static boolean isSpecific(String name)
{
return vlen_specific_types.containsKey(name);
}
/**
* declare a specific type
* @param name the name of the type
* @param declaration the declaration type (in a float* form)
* @return the name of the type
* */
public static String declareType(String declaration)
{
//parse declaration
//ignore enum type for now
if(declaration.contains("enum"))
return declaration;
//we are in a float* case
String[] decode=declaration.split(" ");
String name=decode[1];
String typeName=decode[0].replace("*", "").replace("(", "").replace(")","");
DataType type=DataType.getType(typeName);
vlen_specific_types.put(name,type);
return name;
}
}
......@@ -9,6 +9,8 @@ import java.util.TreeSet;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.WordUtils;
import fr.ifremer.fr.xsf.generator.DataTypeConverter;
public class SCGroupAdapter {
private static boolean forceVariableDeclaration=false;
/** @return class name **/
......@@ -62,7 +64,7 @@ public class SCGroupAdapter {
// Variable declaration
group.variables.forEach(v -> sourceCode.add(SCVariableAdapter.getSourceDeclaration(v)));
group.variables.forEach(v -> sourceCode.addAll(SCVariableAdapter.getSourceDeclaration(v)));
// Dimension declaration
group.dims.forEach(d -> sourceCode.add(SCDimensionAdapter.getSourceDeclaration(d)));
......@@ -81,7 +83,10 @@ public class SCGroupAdapter {
// Types
if (!group.types.isEmpty()) {
sourceCode.add("\n\t\t/** Types **/");
group.types.forEach(t -> sourceCode.add("\t\t// " + t.name));
group.types.forEach(t -> {
String name = DataTypeConverter.declareType(t.name);
sourceCode.addAll(SCTypeAdapter.getSourceCode(name));
});
}
// Dimensions
......
package fr.ifremer.fr.xsf.generator.model;
import java.util.Arrays;
import java.util.List;
import fr.ifremer.fr.xsf.generator.DataTypeConverter;
public class SCTypeAdapter {
public static List<String> getSourceCode( String type) {
if(DataTypeConverter.isSpecific(type))
{
return Arrays.asList(String.format("\t\tthis.addType(%s,%s);",type,type));
}
return Arrays.asList(String.format("\t\t// %s", type));
}
}
......@@ -8,8 +8,10 @@ import fr.ifremer.fr.xsf.generator.DataTypeConverter;
public class SCVariableAdapter {
public static String getSourceDeclaration(Variable variable) {
return String.format("\tprivate NCVariable %s;", variable.name);
public static List<String> getSourceDeclaration(Variable variable) {
return Arrays.asList(
String.format("\tpublic static final String %s=\"%s\";", variable.name.toUpperCase(),variable.name),
String.format("\tprivate NCVariable %s;", variable.name));
}
public static List<String> getSourceAccessor(Variable variable) {
......@@ -50,9 +52,20 @@ public class SCVariableAdapter {
dimString=new StringBuilder("new ArrayList<NCDimension>()");
}
// variable declaration
codeLines.add(String.format("\t\t%s = addVariable(\"%s\", DataType.%s, %s);", variable.name, variable.name,DataTypeConverter.get(variable.type.toUpperCase()).name(),
dimString));
if(DataTypeConverter.isSpecific(variable.type))
{
// variable declaration
codeLines.add(String.format("\t\t%s = addVariable(%s, getTypes(%s).getReference(), %s);", variable.name, variable.name.toUpperCase(),variable.type,
dimString));
} else
{
// variable declaration
codeLines.add(String.format("\t\t%s = addVariable(%s, DataType.%s, %s);", variable.name, variable.name.toUpperCase(),DataTypeConverter.get(variable.type).name(),
dimString));
}
// attributes declarations
variable.attributes.forEach(
......
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