Skip to content

W-17864898: Mule framework DslSyntaxResolver resolves DslElementSynta… #1228

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.mule.runtime.api.meta.model.ComponentModel;
import org.mule.runtime.api.meta.model.ComponentModelVisitor;
import org.mule.runtime.api.meta.model.ComposableModel;
import org.mule.runtime.api.meta.model.EnrichableModel;
import org.mule.runtime.api.meta.model.ExtensionModel;
import org.mule.runtime.api.meta.model.ImportedTypeModel;
import org.mule.runtime.api.meta.model.ParameterDslConfiguration;
Expand Down Expand Up @@ -291,7 +292,7 @@ public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
resolveMapDslFromParameter(objectType, builder, isContent,
expressionSupport, dslConfig, parameter.getName(),
prefix.get(), namespace.get());
prefix.get(), namespace.get(), skipComponent(parameter));
} else {
builder.withElementName(elementName.get());

Expand Down Expand Up @@ -505,11 +506,11 @@ private void resolveRecursiveComponent(ComponentModel componentModel, DslElement
}
}

private boolean skipComponent(ComponentModel componentModel) {
private boolean skipComponent(EnrichableModel enrichableModel) {
// The syntax for those component models having the NoWrapperModelProperty won't be included on the DSL Syntax tree.
// In case that a component having the mentioned property has children, these will be included on the DSL Syntax tree as
// direct children of the parent of the skipped/excluded component
return componentModel.getModelProperty(NoWrapperModelProperty.class).isPresent();
return enrichableModel.getModelProperty(NoWrapperModelProperty.class).isPresent();
}

private void resolveObjectDslFromParameter(ParameterModel parameter, ObjectType objectType, DslElementSyntaxBuilder builder,
Expand Down Expand Up @@ -548,9 +549,11 @@ private void resolveObjectDslFromParameter(ParameterModel parameter, ObjectType
private void resolveMapDslFromParameter(ObjectType objectType, DslElementSyntaxBuilder builder,
boolean isContent, ExpressionSupport expressionSupport,
ParameterDslConfiguration dslModel,
String name, String namespace, String namespaceUri) {
String name, String namespace, String namespaceUri, boolean skipWrapper) {

final String parameterName = isContent ? name : pluralize(name);
// In case this a non-wrapped parameter, then it should consider that the word is uncountable
boolean canBeUncountable = skipWrapper;
final String parameterName = isContent ? name : pluralize(name, canBeUncountable);
builder.withElementName(hyphenize(parameterName))
.supportsChildDeclaration(supportsInlineDeclaration(objectType, expressionSupport, dslModel, isContent));

Expand All @@ -559,7 +562,7 @@ private void resolveMapDslFromParameter(ObjectType objectType, DslElementSyntaxB
.ifPresent(type -> type
.accept(getMapValueTypeVisitor(builder, name,
namespace, namespaceUri,
dslModel)));
dslModel, skipWrapper)));
}
}

Expand Down Expand Up @@ -641,7 +644,7 @@ protected void defaultVisit(MetadataType metadataType) {

private MetadataTypeVisitor getMapValueTypeVisitor(final DslElementSyntaxBuilder mapBuilder, final String parameterName,
final String namespace, final String namespaceUri,
ParameterDslConfiguration dslModel) {
ParameterDslConfiguration dslModel, final boolean skipWrapper) {
return new MetadataTypeVisitor() {

/**
Expand All @@ -655,6 +658,13 @@ private MetadataTypeVisitor getMapValueTypeVisitor(final DslElementSyntaxBuilder
*/
@Override
protected void defaultVisit(MetadataType metadataType) {
if (skipWrapper) {
mapBuilder
.containing(KEY_ATTRIBUTE_NAME, DslElementSyntaxBuilder.create().withAttributeName(KEY_ATTRIBUTE_NAME).build())
.containing(VALUE_ATTRIBUTE_NAME, DslElementSyntaxBuilder.create().withAttributeName(VALUE_ATTRIBUTE_NAME).build());
return;
}

mapBuilder.withGeneric(metadataType,
createBaseValueEntryDefinition()
.containing(VALUE_ATTRIBUTE_NAME, DslElementSyntaxBuilder.create()
Expand Down Expand Up @@ -868,7 +878,8 @@ private void handleMapObject(ObjectType objectType) {
.ifPresent(type -> type.accept(getMapValueTypeVisitor(objectFieldBuilder, fieldName,
ownerNamespace, ownerNamespaceUri,
ParameterDslConfiguration
.getDefaultInstance())));
.getDefaultInstance(),
false)));
}

@Override
Expand Down Expand Up @@ -1008,4 +1019,5 @@ private Optional<QName> getCustomQName(ParameterModel parameter) {
private Optional<QName> getCustomQName(MetadataType type) {
return type.getAnnotation(QNameTypeAnnotation.class).map(QNameTypeAnnotation::getValue);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,9 @@ public class NameUtils extends org.mule.runtime.api.util.NameUtils {
irregular("sex", "sexes");
irregular("move", "moves");

uncountable("equipment");
uncountable("information");
uncountable("rice");
uncountable("money");
uncountable("species");
uncountable("series");
uncountable("fish");
uncountable("sheep");
Comment on lines -124 to -131
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok to remove these?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They weren't working either way (because of the incorrect code in isUncountable), if we keep them we would actually be changing behavior of those cases

// W-17864898: core elements that are not wrapped, so they are not consistent with SDK implemented components
uncountable("metadata");
uncountable("property");
}

private NameUtils() {}
Expand Down Expand Up @@ -170,7 +165,19 @@ private static void uncountable(String word) {
* @return The pluralized word
*/
public static String pluralize(String word) {
if (isUncountable(word)) {
return pluralize(word, false);
}


/**
* Return the pluralized version of a word.
*
* @param word The word
* @param considerUncountable if it should consider that the word may be uncountable
* @return The pluralized word
*/
public static String pluralize(String word, boolean considerUncountable) {
if (isUncountable(word) && considerUncountable) {
return word;
} else {
for (Inflection inflection : plural) {
Expand All @@ -189,7 +196,18 @@ public static String pluralize(String word) {
* @return The singularized word
*/
public static String singularize(String word) {
if (isUncountable(word)) {
return singularize(word, false);
}

/**
* Return the singularized version of a word.
*
* @param word The word
* @param considerUncountable if it should consider that the word may be uncountable
* @return The singularized word
*/
public static String singularize(String word, boolean considerUncountable) {
if (isUncountable(word) && considerUncountable) {
return word;
} else {
for (Inflection inflection : singular) {
Expand Down Expand Up @@ -220,10 +238,11 @@ public static String itemize(String word) {
*/
public static boolean isUncountable(String word) {
if (isBlank(word)) {
for (String w : uncountable) {
if (w.equalsIgnoreCase(word)) {
return true;
}
return false;
}
for (String w : uncountable) {
if (w.equalsIgnoreCase(word)) {
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.mule.metadata.api.model.MetadataFormat.JSON;
import static org.mule.runtime.extension.api.util.NameUtils.getTopLevelTypeName;
import static org.mule.runtime.extension.api.util.NameUtils.hyphenize;
import static org.mule.runtime.extension.api.util.NameUtils.pluralize;

import static java.util.Optional.empty;
import static java.util.Optional.of;
Expand Down Expand Up @@ -94,6 +95,14 @@ public void hyphenization() {
assertThat("parameter-dsl-name", is(hyphenize("ParameterDSLName")));
}

@Test
public void uncountables() {
assertThat(pluralize("metadata"), is("metadatas"));
assertThat(pluralize("metadata", true), is("metadata"));
assertThat(pluralize("property", true), is("property"));
assertThat(pluralize("property", false), is("properties"));
}

@Alias(TYPE_ALIAS)
private static class AliasedClass {

Expand Down