Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).

- Class cast exception when resolving observer name references outside a valid `event` tag in `events.xml`.
- JetBrains MCP Server is now an optional plugin dependency; Magento MCP tools are registered only when MCP support is available.
- File generation dialogs no longer wrap the whole OK action in a write action, preventing `runBlockingCancellable` write-action errors during PSI file creation.

## 2026.2.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package com.magento.idea.magento2plugin.actions.generation.dialog;

import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
Expand Down Expand Up @@ -113,16 +112,17 @@ protected void exit() {
}

/**
* Executes onOK within a WriteAction context.
* Executes onOK after validation.
*/
protected final void executeOnOk() {
WriteAction.run(this::onWriteActionOK);
onWriteActionOK();
}

/**
* This method should contain the core logic for onOk.
* Subclasses can override to provide their implementation.
* Must be invoked via executeOnOk().
* Must be invoked via executeOnOk(). PSI and VFS mutations should be wrapped
* by the generator that performs them.
*/
protected abstract void onWriteActionOK();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,22 +568,21 @@

for (int count = 0; count < model.getRowCount(); count++) {

final String name = model.getValueAt(count, 0).toString();
final String dataType = model.getValueAt(count, 1).toString();
final String name = getTrimmedTableValue(model, count, 0);
final String dataType = getTrimmedTableValue(model, count, 1);

final String label = Arrays.stream(name.split("_")).map(
string -> string.substring(0, 1).toUpperCase(Locale.getDefault())
+ string.substring(1)).collect(Collectors.joining(" ")
);
if (name.isEmpty() || dataType.isEmpty()) {
continue;
}
final String label = formatSnakeCaseLabel(name);
final String sortOrder = String.valueOf(count).concat("0");
final String fieldset = "general";

final PropertiesTypes property =
PropertiesTypes.getByValue(model.getValueAt(count, 1).toString());
final PropertiesTypes property = PropertiesTypes.getByValue(dataType);
final String formElementType =
FormElementType.getDefaultForProperty(property).getType();

final String source = model.getValueAt(count, 0).toString(); //todo: convert
final String source = name; //todo: convert

Check warning on line 585 in src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java

View workflow job for this annotation

GitHub Actions / static-tests

Redundant local variable

Local variable `source` is redundant

final UiComponentFormFieldData fieldsetData = new UiComponentFormFieldData(//NOPMD
name,
Expand Down Expand Up @@ -644,10 +643,7 @@
return;
}
final String entityName = CamelCaseToSnakeCase.getInstance().convert(entityNameValue);
final String entityNameLabel = Arrays.stream(entityName.split("_")).map(
string -> string.substring(0, 1).toUpperCase(Locale.getDefault())
+ string.substring(1)
).collect(Collectors.joining(" "));
final String entityNameLabel = formatSnakeCaseLabel(entityName);

dbTableName.setText(entityName);
entityId.setText(entityName.concat("_id"));
Expand All @@ -661,6 +657,31 @@
menuTitle.setText(entityNameLabel.concat(" Management"));
}

static String formatSnakeCaseLabel(final String value) {
return Arrays.stream(value.split("_"))
.filter(string -> !string.isEmpty())
.map(NewEntityDialog::capitalizeLabelPart)
.collect(Collectors.joining(" "));
}

private static String capitalizeLabelPart(final String value) {
return value.substring(0, 1).toUpperCase(Locale.getDefault()) + value.substring(1);
}

private static String getTrimmedTableValue(
final DefaultTableModel model,
final int row,
final int column
) {
final Object value = model.getValueAt(row, column);

if (value == null) {
return "";
}

return value.toString().trim();
}

/**
* Resolve ui components panel state.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ public static List<String> formatProperties(final DefaultTableModel table) {
final List<String> properties = new ArrayList<>();

for (int index = 0; index < table.getRowCount(); index++) {
final String name = table.getValueAt(index, 0).toString();
final String type = table.getValueAt(index, 1).toString();
final String name = getTrimmedValue(table, index, 0);
final String type = getTrimmedValue(table, index, 1);

if (name.isEmpty() || type.isEmpty()) {
continue;
}
properties.add(ClassPropertyFormatterUtil.formatSingleProperty(name, type));
}

Expand All @@ -46,12 +49,14 @@ public static List<String> formatProperties(final DefaultTableModel table) {
* @return String
*/
public static String formatSingleProperty(final String name, final String type) {
final String propertyName = name.trim();

return new ClassPropertyData(
type,
CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name),
CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name),
name,
formatNameToConstant(name)
type.trim(),
CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, propertyName),
CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, propertyName),
propertyName,
formatNameToConstant(propertyName)
).string();
}

Expand Down Expand Up @@ -88,4 +93,18 @@ public static String formatNameToConstant(final String name, final String typeFq
public static String formatNameToConstant(final String name) {
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_UNDERSCORE, name);
}

private static String getTrimmedValue(
final DefaultTableModel table,
final int row,
final int column
) {
final Object value = table.getValueAt(row, column);

if (value == null) {
return StringUtils.EMPTY;
}

return value.toString().trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import com.magento.idea.magento2plugin.magento.packages.database.ColumnAttributes;
import com.magento.idea.magento2plugin.magento.packages.database.PropertyToDefaultTypeMapperUtil;
import com.magento.idea.magento2plugin.magento.packages.database.TableColumnTypes;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;

public final class DbSchemaGeneratorUtil {
Expand All @@ -39,7 +41,12 @@ public static List<Map<String, String>> complementShortPropertiesByDefaults(
final String name = property.get(PROPERTY_NAME);
final String type = property.get(PROPERTY_TYPE);

final PropertiesTypes propType = PropertiesTypes.getByValue(type);
if (name == null || name.trim().isEmpty() || type == null || type.trim().isEmpty()) {
continue;
}
final String trimmedName = name.trim();
final String trimmedType = type.trim();
final PropertiesTypes propType = PropertiesTypes.getByValue(trimmedType);
final TableColumnTypes tableColumnType = PropertyToDefaultTypeMapperUtil.map(propType);

final List<String> allowedAttributes = ModuleDbSchemaXml.getAllowedAttributes(
Expand All @@ -48,7 +55,7 @@ public static List<Map<String, String>> complementShortPropertiesByDefaults(

final Map<String, String> columnData = new LinkedHashMap<>();
columnData.put(ColumnAttributes.TYPE.getName(), tableColumnType.getColumnType());
columnData.put(ColumnAttributes.NAME.getName(), name);
columnData.put(ColumnAttributes.NAME.getName(), trimmedName);

for (final String columnAttributeName : allowedAttributes) {
final ColumnAttributes attribute = ColumnAttributes.getByName(columnAttributeName);
Expand All @@ -58,7 +65,7 @@ public static List<Map<String, String>> complementShortPropertiesByDefaults(
}
columnData.put(columnAttributeName, attribute.getDefault());
}
columnData.put(ColumnAttributes.COMMENT.getName(), getColumnCommentByName(name));
columnData.put(ColumnAttributes.COMMENT.getName(), getColumnCommentByName(trimmedName));

complemented.add(columnData);
}
Expand Down Expand Up @@ -96,16 +103,19 @@ public static Map<String, String> getTableIdentityColumnData(final @NotNull Stri
*/
@SuppressWarnings("PMD.UseLocaleWithCaseConversions")
private static String getColumnCommentByName(final @NotNull String name) {
final StringBuilder commentStringBuilder = new StringBuilder();
final String[] nameParts = name.split("_");

for (final String namePart : nameParts) {
commentStringBuilder
.append(namePart.substring(0, 1).toUpperCase())
.append(namePart.substring(1))
.append(' ');
final String formattedName = Arrays.stream(name.split("_"))
.filter(namePart -> !namePart.isEmpty())
.map(DbSchemaGeneratorUtil::capitalizeCommentPart)
.collect(Collectors.joining(" "));

if (formattedName.isEmpty()) {
return "Column";
}

return commentStringBuilder.append("Column").toString();
return formattedName.concat(" Column");
}

private static String capitalizeCommentPart(final @NotNull String namePart) {
return namePart.substring(0, 1).toUpperCase() + namePart.substring(1);
}
}
Loading
Loading