Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix escaped word added as property key and set type constrain a non flatten type #491

Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,21 @@ private void addRemainingParamsToPropertyMap(LinkedHashMap<String, ParameterResu
continue;
}

String unescapedParamName = ParamUtils.removeLeadingSingleQuote(paramResult.name());
Property.Builder<FormBuilder<NodeBuilder>> customPropBuilder = nodeBuilder.properties().custom();
customPropBuilder
.metadata()
.label(paramResult.name())
.label(unescapedParamName)
.description(paramResult.description())
.stepOut()
.codedata()
.kind(paramResult.kind().name())
.originalName(paramResult.name())
.stepOut()
.placeholder(paramResult.defaultValue())
.typeConstraint(paramResult.type())
.editable()
.defaultable(paramResult.optional() == 1)
.kind(paramResult.kind().name());
.defaultable(paramResult.optional() == 1);

if (paramResult.kind() == Parameter.Kind.INCLUDED_RECORD_REST) {
if (hasOnlyRestParams) {
Expand All @@ -354,7 +358,7 @@ private void addRemainingParamsToPropertyMap(LinkedHashMap<String, ParameterResu
}
customPropBuilder
.stepOut()
.addProperty(paramResult.name());
.addProperty(unescapedParamName);
}
}

Expand Down Expand Up @@ -418,11 +422,11 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
funcParamMap.remove(parameterSymbol.getName().get());
Property.Builder<FormBuilder<NodeBuilder>> customPropBuilder =
nodeBuilder.properties().custom();

String value = paramValue != null ? paramValue.toSourceCode() : null;
String unescapedParamName = ParamUtils.removeLeadingSingleQuote(paramResult.name());
customPropBuilder
.metadata()
.label(paramResult.name())
.label(unescapedParamName)
.description(paramResult.description())
.stepOut()
.type(getPropertyTypeFromParamKind(paramResult.kind()))
Expand All @@ -431,9 +435,12 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
.placeholder(paramResult.defaultValue())
.editable()
.defaultable(paramResult.optional() == 1)
.kind(paramResult.kind().name())
.codedata()
.kind(paramResult.kind().name())
.originalName(paramResult.name())
.stepOut()
.stepOut()
.addProperty(paramResult.name(), paramValue);
.addProperty(unescapedParamName);
}

for (int i = paramCount; i < argCount; i++) {
Expand All @@ -444,9 +451,10 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
String escapedParamName = CommonUtil.escapeReservedKeyword(restParamSymbol.getName().get());
ParameterResult restParamResult = funcParamMap.get(escapedParamName);
funcParamMap.remove(restParamSymbol.getName().get());
String unescapedParamName = ParamUtils.removeLeadingSingleQuote(restParamResult.name());
customPropBuilder
.metadata()
.label(restParamResult.name())
.label(unescapedParamName)
.description(restParamResult.description())
.stepOut()
.type(getPropertyTypeFromParamKind(restParamResult.kind()))
Expand All @@ -455,9 +463,12 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
.placeholder(restParamResult.defaultValue())
.editable()
.defaultable(!hasOnlyRestParams)
.kind(restParamSymbol.kind().name())
.codedata()
.kind(restParamResult.kind().name())
.originalName(restParamResult.name())
.stepOut()
.stepOut()
.addProperty(restParamResult.name());
.addProperty(unescapedParamName);
}
// iterate over functionParamMap
addRemainingParamsToPropertyMap(funcParamMap, hasOnlyRestParams);
Expand Down Expand Up @@ -496,9 +507,10 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
Property.Builder<FormBuilder<NodeBuilder>> customPropBuilder =
nodeBuilder.properties().custom();
String value = paramValue != null ? paramValue.toSourceCode() : null;
String unescapedParamName = ParamUtils.removeLeadingSingleQuote(paramResult.name());
customPropBuilder
.metadata()
.label(paramResult.name())
.label(unescapedParamName)
.description(paramResult.description())
.stepOut()
.type(getPropertyTypeFromParamKind(paramResult.kind()))
Expand All @@ -507,9 +519,12 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
.placeholder(paramResult.defaultValue())
.editable()
.defaultable(paramResult.optional() == 1)
.kind(paramResult.kind().name())
.codedata()
.kind(paramResult.kind().name())
.originalName(paramResult.name())
.stepOut()
.stepOut()
.addProperty(paramResult.name(), paramValue);
.addProperty(unescapedParamName, paramValue);
} else {
if (funcParamMap.containsKey(argName)) { // included record attribute
paramResult = funcParamMap.get(argName);
Expand All @@ -521,9 +536,10 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
namedArgValueMap.remove(argName);
}
String value = paramValue != null ? paramValue.toSourceCode() : null;
String unescapedParamName = ParamUtils.removeLeadingSingleQuote(paramResult.name());
customPropBuilder
.metadata()
.label(paramResult.name())
.label(unescapedParamName)
.description(paramResult.description())
.stepOut()
.type(getPropertyTypeFromParamKind(paramResult.kind()))
Expand All @@ -532,9 +548,12 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
.placeholder(paramResult.defaultValue())
.editable()
.defaultable(paramResult.optional() == 1)
.kind(paramResult.kind().name())
.codedata()
.kind(paramResult.kind().name())
.originalName(paramResult.name())
.stepOut()
.stepOut()
.addProperty(paramResult.name(), paramValue);
.addProperty(unescapedParamName, paramValue);

} else { // included record rest
funcParamMap.remove(escapedParamName);
Expand All @@ -549,11 +568,12 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
Property.Builder<FormBuilder<NodeBuilder>> customPropBuilder =
nodeBuilder.properties().custom();

String unescapedParamName = ParamUtils.removeLeadingSingleQuote(paramResult.name());
funcParamMap.remove(escapedParamName);
String value = paramValue.toSourceCode();
customPropBuilder
.metadata()
.label(paramResult.name())
.label(unescapedParamName)
.description(paramResult.description())
.stepOut()
.type(getPropertyTypeFromParamKind(paramResult.kind()))
Expand All @@ -562,9 +582,12 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
.placeholder(paramResult.defaultValue())
.editable()
.defaultable(paramResult.optional() == 1)
.kind(paramResult.kind().name())
.codedata()
.kind(paramResult.kind().name())
.originalName(paramResult.name())
.stepOut()
.stepOut()
.addProperty(paramResult.name(), paramValue);
.addProperty(unescapedParamName, paramValue);
return;
}
}
Expand All @@ -578,9 +601,10 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
nodeBuilder.properties().custom();
funcParamMap.remove(escapedParamName);
String value = paramValue != null ? paramValue.toSourceCode() : null;
String unescapedParamName = ParamUtils.removeLeadingSingleQuote(paramResult.name());
customPropBuilder
.metadata()
.label(paramResult.name())
.label(unescapedParamName)
.description(paramResult.description())
.stepOut()
.type(getPropertyTypeFromParamKind(paramResult.kind()))
Expand All @@ -589,9 +613,12 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
.placeholder(paramResult.defaultValue())
.editable()
.defaultable(paramResult.optional() == 1)
.kind(paramResult.kind().name())
.codedata()
.kind(paramResult.kind().name())
.originalName(paramResult.name())
.stepOut()
.stepOut()
.addProperty(paramResult.name(), paramValue);
.addProperty(unescapedParamName, paramValue);
}
for (Map.Entry<String, Node> entry : namedArgValueMap.entrySet()) {
LinkedHashMap<String, String> map = new LinkedHashMap<>();
Expand All @@ -603,9 +630,10 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
funcParamMap.remove("INCLUDED_RECORD_REST");
Property.Builder<FormBuilder<NodeBuilder>> customPropBuilder =
nodeBuilder.properties().custom();
String unescapedParamName = ParamUtils.removeLeadingSingleQuote(includedRecordRest.name());
customPropBuilder
.metadata()
.label(includedRecordRest.name())
.label(unescapedParamName)
.description(includedRecordRest.description())
.stepOut()
.type(getPropertyTypeFromParamKind(includedRecordRest.kind()))
Expand All @@ -614,9 +642,12 @@ private void buildPropsFromFuncCallArgs(SeparatedNodeList<FunctionArgumentNode>
.placeholder(includedRecordRest.defaultValue())
.editable()
.defaultable(includedRecordRest.optional() == 1)
.kind(includedRecordRest.kind().name())
.codedata()
.kind(includedRecordRest.kind().name())
.originalName(includedRecordRest.name())
.stepOut()
.stepOut()
.addProperty(includedRecordRest.name());
.addProperty(unescapedParamName);
}
addRemainingParamsToPropertyMap(funcParamMap, hasOnlyRestParams);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
* @param editable whether the property is not readonly
* @param advanced whether the property should be shown in the advanced tab
* @param diagnostics diagnostics of the property
* @param kind kind of the property
* @param codedata codedata of the property
* @since 1.4.0
*/
public record Property(Metadata metadata, String valueType, Object valueTypeConstraint, Object value,
String placeholder, boolean optional, boolean editable, boolean advanced,
Diagnostics diagnostics, String kind) {
Diagnostics diagnostics, PropertyCodedata codedata) {

private static final Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();

Expand Down Expand Up @@ -173,9 +173,9 @@ public static class Builder<T> extends FacetedBuilder<T> implements DiagnosticHa
private boolean editable;
private boolean advanced;
private Object typeConstraint;
private String kind;
private Metadata.Builder<Builder<T>> metadataBuilder;
private Diagnostics.Builder<Builder<T>> diagnosticsBuilder;
private PropertyCodedata.Builder<Builder<T>> codedataBuilder;

public Builder(T parentBuilder) {
super(parentBuilder);
Expand Down Expand Up @@ -217,11 +217,6 @@ public Builder<T> advanced(boolean advanced) {
return this;
}

public Builder<T> kind(String kind) {
this.kind = kind;
return this;
}

public Builder<T> editable() {
this.editable = true;
return this;
Expand All @@ -244,6 +239,13 @@ public Metadata.Builder<Builder<T>> metadata() {
return this.metadataBuilder;
}

public PropertyCodedata.Builder<Builder<T>> codedata() {
if (this.codedataBuilder == null) {
this.codedataBuilder = new PropertyCodedata.Builder<>(this);
}
return this.codedataBuilder;
}

@Override
public Diagnostics.Builder<Builder<T>> diagnostics() {
if (this.diagnosticsBuilder == null) {
Expand All @@ -256,7 +258,8 @@ public Property build() {
Property property =
new Property(metadataBuilder == null ? null : metadataBuilder.build(), type, typeConstraint, value,
placeholder, optional, editable, advanced,
diagnosticsBuilder == null ? null : diagnosticsBuilder.build(), kind);
diagnosticsBuilder == null ? null : diagnosticsBuilder.build(),
codedataBuilder == null ? null : codedataBuilder.build());
this.metadataBuilder = null;
this.type = null;
this.typeConstraint = null;
Expand All @@ -266,7 +269,7 @@ public Property build() {
this.editable = false;
this.advanced = false;
this.diagnosticsBuilder = null;
this.kind = null;
this.codedataBuilder = null;
return property;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/


package io.ballerina.flowmodelgenerator.core.model;

/**
* Represents the codedata of a property.
*
* @param kind The kind of the property
* @param originalName The original name of the property
* @since 1.4.0
*/
public record PropertyCodedata(String kind, String originalName) {

public static class Builder<T> extends FacetedBuilder<T> {

private String kind;
private String originalName;

public Builder(T parentBuilder) {
super(parentBuilder);
}

public Builder<T> kind(String kind) {
this.kind = kind;
return this;
}

public Builder<T> originalName(String originalName) {
this.originalName = originalName;
return this;
}

public PropertyCodedata build() {
return new PropertyCodedata(kind, originalName);
}
}
}
Loading
Loading