Skip to content

Commit

Permalink
Merge pull request #370 from iljapostnovs/development
Browse files Browse the repository at this point in the history
fix formatter and TS XML Interface generator
  • Loading branch information
iljapostnovs committed Aug 31, 2023
2 parents 0ab6f84 + e97d0de commit 5a3f3ea
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.13.2 (31-08-2023)

- XML Formatter doesn't replace `"` with `'` in attribute value anymore for such cases as `\{type: 'sap.ui.model.type.Date', formatOptions: \{UTC: true\}, constraints: \{\} \}`
- TS id to control generator command now ignores commented tags. Output is sorted now.

## 1.13.1 (13-08-2023)

- [UI5 Parser](https://github.com/iljapostnovs/ui5plugin-parser) updated to v1.6.1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ui5plugin",
"displayName": "SAPUI5 Extension",
"description": "Extension for working with UI5 projects",
"version": "1.13.1",
"version": "1.13.2",
"publisher": "iljapostnovs",
"license": "Apache-2.0",
"author": "Ilja Postnovs <ilja.postnovs@gmail.com>",
Expand Down
6 changes: 5 additions & 1 deletion src/classes/utils/XMLFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ export class XMLFormatter extends ParserBearer {
}
formattedValue = `"${formattedValue}"`;
} else {
formattedValue = `'${attributeValue}'`;
if (attributeValue.includes("'")) {
formattedValue = `"${attributeValue}"`;
} else {
formattedValue = `'${attributeValue}'`;
}
}

return formattedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class TSXMLInterfaceGenerator extends ParserBearer implements ITSInterfac
const className = toImport.split("/").pop();
return `import ${className} from "${toImport}";`;
}
);
).sort();
const aInterfaces = mInterfaceData.map(interfaceData => {
const sExtends = [...new Set(interfaceData.extends)].join(" & ");
return `export type ${interfaceData.name} = {\n\t${interfaceData.rows}\n}${
Expand All @@ -35,7 +35,7 @@ export class TSXMLInterfaceGenerator extends ParserBearer implements ITSInterfac
return aUniqueImports.join("\n") + "\n\n" + aInterfaces.join("\n\n");
}
private _generateInterfaceDataForFile(XMLFile: IXMLFile) {
const tags = this._parser.xmlParser.getAllTags(XMLFile);
const tags = this._parser.xmlParser.getAllTags(XMLFile).filter(tag => !tag.text.startsWith("<!--"));
const mInterfaceData = tags.reduce(
(
accumulator: {
Expand Down Expand Up @@ -69,8 +69,8 @@ export class TSXMLInterfaceGenerator extends ParserBearer implements ITSInterfac

const isView = XMLFile.fsPath.endsWith(".view.xml");
const interfaceName = XMLFile.name.split(".").pop() + (isView ? "View" : "Fragment");
const uniqueImports = [...new Set(mInterfaceData.import)];
const interfaceRows = mInterfaceData.interfaces.join("\n\t");
const uniqueImports = [...new Set(mInterfaceData.import)].sort();
const interfaceRows = mInterfaceData.interfaces.sort().join("\n\t");
const aExtends = XMLFile.fragments.map(fragment => {
const isView = fragment.fsPath.endsWith(".view.xml");
const interfaceName = fragment.name.split(".").pop() + (isView ? "View" : "Fragment");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns="sap.m"
xmlns:c="sap.ui.core"
>
<Text text="\{type: 'sap.ui.model.type.Date', formatOptions: \{UTC: true\}, constraints: \{\} \}"></Text>
<Button
id="idButtonFragmentController2"
text="{
Expand Down
2 changes: 1 addition & 1 deletion src/test/js/suite/data/XMLFormatterData.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"className": "com.extend.fragmenttest.view.fragments.FormatterTest",
"formattedText": "<c:FragmentDefinition\n\txmlns=\"sap.m\"\n\txmlns:c=\"sap.ui.core\"\n>\n\t<Button\n\t\tid=\"idButtonFragmentController2\"\n\t\ttext=\"{\n\t\t\tformatter: '.formatter.formatValueFragmentController2',\n\t\t\ttest: [1, 2, 3],\n\t\t\ttest2: ['abc', 'asd'],\n\t\t\ttest3: {\n\t\t\t\ttest: [1, 2, 3],\n\t\t\t\ttest2: ['abc', 'asd']\n\t\t\t},\n\t\t\ttest4: [{\n\t\t\t\tpath: 'asd'\n\t\t\t}, {\n\t\t\t\tpath: 123\n\t\t\t}]\n\t\t}\"\n\t\tpress=\"onButton11Press\"\n\t/>\n\t<Input value=\"{\n\t\tpath: '/',\n\t\ttype: 'sap.ui.model.type.String',\n\t\tconstraints: {\n\t\t\tsearch: '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]{2,}\\\\.[a-zA-Z0-9-.]{2,}$'\n\t\t}\n\t}\"/>\n\t<Button text=\"{= ${/SupportModel}}\"/>\n\t<Button text=\"{Test}\"/>\n\t<Button\n\t\ticon=\"asd\"\n\t\ttext=\"{\n\t\t\tpath: 'test'\n\t\t}\"\n\t/>\n\t<Text\n\t\ttext=\"{\n\t\t\tpath: 'Test>Confidence',\n\t\t\ttype: 'sap.ui.model.type.Integer'\n\t\t} %\"\n\t\twrapping=\"false\"\n\t/>\n\t<Text\n\t\ttext=\"{\n\t\t\tpath: 'Test>Confidence',\n\t\t\ttype: 'sap.ui.model.type.Integer'\n\t\t} {\n\t\t\tpath: 'Test>Confidence',\n\t\t\ttype: 'sap.ui.model.type.Integer'\n\t\t}\"\n\t\twrapping=\"false\"\n\t/>\n\t<HBox\n\t\tjustifyContent=\"End\"\n\t\tvisible=\"{=\r\n\t\t\t${ZoneModel>ProcessingState} === '1' ||\r\n\t\t\t${ZoneModel>ProcessingState} === '6' ||\r\n\t\t\t${ZoneModel>ProcessingState} === '5'\r\n\t\t}\"\n\t/>\n\t<HBox visible=\"{=\r\n\t\t${device>/isDesktop} &amp;&amp;\r\n\t\t${\n\t\t\tpath: 'SupportModel>asd',\n\t\t\tformatter: '.documentStatusMapping.getPhInvGroupIsPostingAllowed'\n\t\t}\r\n\t}\"/>\n\t<Button visible=\"{=\r\n\t\t(\n\t\t\t(\r\n\t\t\t\t${TestModel>IS_SINGLE_PRODUCT_OFFER}\r\n\t\t\t) || (\r\n\t\t\t\t(\r\n\t\t\t\t\t${TestModel>LEVEL} === 'STORE_FORMAT_LEVEL' ||\r\n\t\t\t\t\t${TestModel>LEVEL} === 'PRODUCT_LEVEL'\r\n\t\t\t\t) &amp;&amp;\r\n\t\t\t\t!${TestModel>IS_SINGLE_PRODUCT_OFFER}\r\n\t\t\t)\n\t\t)\r\n\t}\"/>\n\t<Button visible=\"{=\r\n\t\t!(${SupportModel>/Layout})\n\t\t.startsWith('Three')\r\n\t}\"/>\n\t<Button\n\t\ttext=\"({TestModel>Test/Test})\"\n\t\ticon=\"({\n\t\t\tpath: 'TestModel>Test/Test',\n\t\t\tformatter: 'hello.Test'\n\t\t})\"\n\t\ttooltip=\"{=\r\n\t\t\tparseFloat(${TestModel>Test}) &gt; parseFloat(${TestModel>Test}) ?\r\n\t\t\t'random text (' + ${TestModel>Test} + ') random text (' + ${TestModel>Test} + ')' :\r\n\t\t\t''\r\n\t\t}\"\n\t/>\n</c:FragmentDefinition>"
"formattedText": "<c:FragmentDefinition\n\txmlns=\"sap.m\"\n\txmlns:c=\"sap.ui.core\"\n>\n\t<Text text=\"\\{type: 'sap.ui.model.type.Date', formatOptions: \\{UTC: true\\}, constraints: \\{\\} \\}\"/>\n\t<Button\n\t\tid=\"idButtonFragmentController2\"\n\t\ttext=\"{\n\t\t\tformatter: '.formatter.formatValueFragmentController2',\n\t\t\ttest: [1, 2, 3],\n\t\t\ttest2: ['abc', 'asd'],\n\t\t\ttest3: {\n\t\t\t\ttest: [1, 2, 3],\n\t\t\t\ttest2: ['abc', 'asd']\n\t\t\t},\n\t\t\ttest4: [{\n\t\t\t\tpath: 'asd'\n\t\t\t}, {\n\t\t\t\tpath: 123\n\t\t\t}]\n\t\t}\"\n\t\tpress=\"onButton11Press\"\n\t/>\n\t<Input value=\"{\n\t\tpath: '/',\n\t\ttype: 'sap.ui.model.type.String',\n\t\tconstraints: {\n\t\t\tsearch: '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]{2,}\\\\.[a-zA-Z0-9-.]{2,}$'\n\t\t}\n\t}\"/>\n\t<Button text=\"{= ${/SupportModel}}\"/>\n\t<Button text=\"{Test}\"/>\n\t<Button\n\t\ticon=\"asd\"\n\t\ttext=\"{\n\t\t\tpath: 'test'\n\t\t}\"\n\t/>\n\t<Text\n\t\ttext=\"{\n\t\t\tpath: 'Test>Confidence',\n\t\t\ttype: 'sap.ui.model.type.Integer'\n\t\t} %\"\n\t\twrapping=\"false\"\n\t/>\n\t<Text\n\t\ttext=\"{\n\t\t\tpath: 'Test>Confidence',\n\t\t\ttype: 'sap.ui.model.type.Integer'\n\t\t} {\n\t\t\tpath: 'Test>Confidence',\n\t\t\ttype: 'sap.ui.model.type.Integer'\n\t\t}\"\n\t\twrapping=\"false\"\n\t/>\n\t<HBox\n\t\tjustifyContent=\"End\"\n\t\tvisible=\"{=\r\n\t\t\t${ZoneModel>ProcessingState} === '1' ||\r\n\t\t\t${ZoneModel>ProcessingState} === '6' ||\r\n\t\t\t${ZoneModel>ProcessingState} === '5'\r\n\t\t}\"\n\t/>\n\t<HBox visible=\"{=\r\n\t\t${device>/isDesktop} &amp;&amp;\r\n\t\t${\n\t\t\tpath: 'SupportModel>asd',\n\t\t\tformatter: '.documentStatusMapping.getPhInvGroupIsPostingAllowed'\n\t\t}\r\n\t}\"/>\n\t<Button visible=\"{=\r\n\t\t(\n\t\t\t(\r\n\t\t\t\t${TestModel>IS_SINGLE_PRODUCT_OFFER}\r\n\t\t\t) || (\r\n\t\t\t\t(\r\n\t\t\t\t\t${TestModel>LEVEL} === 'STORE_FORMAT_LEVEL' ||\r\n\t\t\t\t\t${TestModel>LEVEL} === 'PRODUCT_LEVEL'\r\n\t\t\t\t) &amp;&amp;\r\n\t\t\t\t!${TestModel>IS_SINGLE_PRODUCT_OFFER}\r\n\t\t\t)\n\t\t)\r\n\t}\"/>\n\t<Button visible=\"{=\r\n\t\t!(${SupportModel>/Layout})\n\t\t.startsWith('Three')\r\n\t}\"/>\n\t<Button\n\t\ttext=\"({TestModel>Test/Test})\"\n\t\ticon=\"({\n\t\t\tpath: 'TestModel>Test/Test',\n\t\t\tformatter: 'hello.Test'\n\t\t})\"\n\t\ttooltip=\"{=\r\n\t\t\tparseFloat(${TestModel>Test}) &gt; parseFloat(${TestModel>Test}) ?\r\n\t\t\t'random text (' + ${TestModel>Test} + ') random text (' + ${TestModel>Test} + ')' :\r\n\t\t\t''\r\n\t\t}\"\n\t/>\n</c:FragmentDefinition>"
}
]
}

0 comments on commit 5a3f3ea

Please sign in to comment.