Commit b6e6370b authored by Jeno Attila Balasko's avatar Jeno Attila Balasko Committed by Gerrit Code Review
Browse files

Merge "fix JSON variant text as"

parents 7c82ca92 0c6a19c2
......@@ -41,7 +41,7 @@ public class JsonAST {
public String from;
public String to;
public int index; // set during semantic analysis
JsonEnumText(final String p_from, final String p_to){
public JsonEnumText(final String p_from, final String p_to){
from = p_from;
to = p_to;
}
......
......@@ -625,8 +625,8 @@ public final class EnumeratedGenerator {
source.append("\t\t\t} else {\n");
source.append("\t\t\t\tboolean text_found = false;\n");
source.append("\t\t\t\tfor (int i = 0; i < p_td.json.getNof_enum_texts(); ++i) {\n");
source.append("\t\t\t\t\tif (p_td.json.getEnum_texts().get(i).index == enum_value.ordinal()) {\n");
source.append("\t\t\t\t\t\ttmp_str = \"\\\"\" + p_td.json.getEnum_texts().get(i).text + \"\\\"\";\n");
source.append("\t\t\t\t\tif (p_td.json.getEnum_texts().get(i).getIndex() == enum_value.ordinal()) {\n");
source.append("\t\t\t\t\t\ttmp_str = \"\\\"\" + p_td.json.getEnum_texts().get(i).getText() + \"\\\"\";\n");
source.append("\t\t\t\t\t\ttext_found = true;\n");
source.append("\t\t\t\t\t\tbreak;\n");
source.append("\t\t\t\t\t}\n");
......@@ -670,8 +670,8 @@ public final class EnumeratedGenerator {
source.append("\t\t\t\t\tboolean text_found = false;\n");
source.append("\t\t\t\t\tfinal String tmpValue = use_default ? value.toString() : value.substring(1);\n");
source.append("\t\t\t\t\tfor (int i = 0; i < p_td.json.getNof_enum_texts(); ++i) {\n");
source.append("\t\t\t\t\t\tif (p_td.json.getEnum_texts().get(i).text.equals(tmpValue)) {\n");
source.append("\t\t\t\t\t\t\tenum_value = enum_type.getValue(p_td.json.getEnum_texts().get(i).index);\n");
source.append("\t\t\t\t\t\tif (p_td.json.getEnum_texts().get(i).getText().equals(tmpValue)) {\n");
source.append("\t\t\t\t\t\t\tenum_value = enum_type.getValue(p_td.json.getEnum_texts().get(i).getIndex());\n");
source.append("\t\t\t\t\t\t\ttext_found = true;\n");
source.append("\t\t\t\t\t\t\tbreak;\n");
source.append("\t\t\t\t\t\t}\n");
......
......@@ -3021,18 +3021,16 @@ public abstract class Type extends Governor implements IType, IIncrementallyUpda
JSON_value.append(jsonAttribute.enum_texts.size()).append(',');
if (jsonAttribute.enum_texts.size() != 0) {
aData.addBuiltinTypeImport("JSON.JsonEnumText");
enum_texts_name = MessageFormat.format("{0}_json_enum_texts", genname);
final StringBuilder enum_texts_value = new StringBuilder();
enum_texts_value.append(MessageFormat.format("final JsonEnumText[] {0} = '{", enum_texts_name));
enum_texts_value.append(MessageFormat.format("\t\tfinal static List<JsonEnumText> {0} = new ArrayList<JsonEnumText>();\n", enum_texts_name));
enum_texts_value.append("\t\tstatic {\n");
for (int i = 0; i < jsonAttribute.enum_texts.size(); i++) {
final JsonEnumText element = jsonAttribute.enum_texts.get(i);
if (i == 0) {
enum_texts_value.append(MessageFormat.format(("'{{0}, \"{1}\"'}"),element.index, element.to));
}
enum_texts_value.append(MessageFormat.format((", '{{0}, \"{1}\"'}"),element.index, element.to));
enum_texts_value.append(MessageFormat.format("\t\t\t{0}.add(new JsonEnumText({1}, \"{2}\"));\n", enum_texts_name, element.index, element.to));
}
enum_texts_value.append("};\n");
enum_texts_value.append("\t\t}\n");
if (localTarget == null) {
aData.addGlobalVariable(enum_texts_name, enum_texts_value.toString());
} else {
......
......@@ -9,6 +9,7 @@ import org.eclipse.titan.designer.AST.IType.MessageEncoding_type;
import org.eclipse.titan.designer.AST.ASN1.values.ASN1_Null_Value;
import org.eclipse.titan.designer.AST.TTCN3.attributes.*;
import org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute.ExtensionAttribute_type;
import org.eclipse.titan.designer.AST.TTCN3.attributes.JsonAST.JsonEnumText;
import org.eclipse.titan.designer.AST.TTCN3.attributes.JsonAST.json_string_escaping;
import org.eclipse.titan.designer.AST.TTCN3.attributes.JsonAST.json_type_indicator;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function.EncodingPrototype_type;
......@@ -921,7 +922,11 @@ pr_XERAttribute:
| LISTKeyword
| pr_name
| pr_namespace
| pr_text
| t = pr_text
{
jsonstruct.enum_texts.add(new JsonEnumText($t.prefix, $t.uri));
json_f = true;
}
| UNTAGGEDKeyword
| USENILKeyword
| USENUMBERKeyword
......@@ -960,9 +965,9 @@ pr_form: FORMKeyword ASKeyword ( UNQUALIFIEDKeyword | QUALIFIEDKeyword );
pr_name: NAMEKeyword ASKeyword pr_newNameOrKeyword;
pr_newNameOrKeyword:
( pr_keyword
| XSTRING
pr_newNameOrKeyword returns [String name]:
( k = pr_keyword { $name = $k.text; }
| XSTRING { $name = $XSTRING.getText().replaceAll("^\'|\'$", ""); }
);
pr_keyword:
......@@ -981,11 +986,17 @@ pr_optPrefix:
| PREFIXKeyword XSTRING
);
pr_text:
pr_text returns [String prefix, String uri]:
( TEXTKeyword
( /* empty */
| XSTRING ASKeyword pr_newNameOrKeyword
| ALLKeyword ASKeyword pr_newNameOrKeyword
| XSTRING ASKeyword newname = pr_newNameOrKeyword
{ $prefix = $XSTRING.getText().replaceAll("^\'|\'$", "");
$uri = $newname.name;
}
| ALLKeyword ASKeyword newname = pr_newNameOrKeyword
{ $prefix = $ALLKeyword.getText();
$uri = $newname.name;
}
)
);
......
......@@ -41,8 +41,21 @@ public class JSON {
* Enumerated text change structure
*/
public static final class JsonEnumText {
public int index;
public String text;
private int index;
private String text;
public JsonEnumText(final int index, final String text) {
this.index = index;
this.text = text;
}
public int getIndex() {
return index;
}
public String getText() {
return text;
}
}
/** Helper enumerated type for storing the different methods of escaping in character strings */
......
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