Skip to content

Commit d33256d

Browse files
author
Vitaliy
authored
Merge pull request #591 from bohdan-harniuk/adjust-php-class-types-builder
Simplified file properties definition for the php file generation
2 parents d4c03c7 + 9fa4613 commit d33256d

21 files changed

+200
-269
lines changed

src/com/magento/idea/magento2plugin/actions/generation/generator/DataModelGenerator.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.magento.idea.magento2plugin.actions.generation.data.DataModelData;
10-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil;
11-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder;
1210
import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile;
1311
import com.magento.idea.magento2plugin.magento.files.DataModelFile;
1412
import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile;
@@ -60,29 +58,20 @@ protected AbstractPhpFile initFile() {
6058
*/
6159
@Override
6260
protected void fillAttributes(final @NotNull Properties attributes) {
63-
final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder();
64-
65-
phpClassTypesBuilder
66-
.appendProperty("NAMESPACE", file.getNamespace())
67-
.appendProperty("NAME", data.getName())
68-
.appendProperty("PROPERTIES", data.getProperties())
69-
.appendProperty("HASINTERFACE", Boolean.toString(data.hasInterface()))
61+
typesBuilder
62+
.append("NAMESPACE", file.getNamespace(), false)
63+
.append("NAME", data.getName(), false)
64+
.append("PROPERTIES", data.getProperties(), false)
65+
.append("HASINTERFACE", Boolean.toString(data.hasInterface()), false)
7066
.append("EXTENDS", DataModelFile.DATA_OBJECT);
7167

7268
if (data.hasInterface()) {
73-
phpClassTypesBuilder.append(
69+
typesBuilder.append(
7470
"IMPLEMENTS",
7571
new DataModelInterfaceFile(
7672
data.getModuleName(),
7773
data.getInterfaceName()
7874
).getClassFqn());
7975
}
80-
81-
phpClassTypesBuilder.mergeProperties(attributes);
82-
83-
attributes.setProperty(
84-
"USES",
85-
PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())
86-
);
8776
}
8877
}

src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityByIdCommandGenerator.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityByIdCommandData;
10-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil;
11-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder;
1210
import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile;
1311
import com.magento.idea.magento2plugin.magento.files.ModelFile;
1412
import com.magento.idea.magento2plugin.magento.files.ResourceModelFile;
@@ -63,29 +61,24 @@ protected AbstractPhpFile initFile() {
6361
*/
6462
@Override
6563
protected void fillAttributes(final @NotNull Properties attributes) {
66-
final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder();
6764
final ModelFile modelFile = new ModelFile(data.getModuleName(), data.getModelName());
6865
final String modelType = modelFile.getClassFqn();
6966
final String modelFactoryType = modelType.concat("Factory");
7067
final ResourceModelFile resourceFile =
7168
new ResourceModelFile(data.getModuleName(), data.getResourceModelName());
7269

73-
phpClassTypesBuilder
74-
.appendProperty("ENTITY_NAME", data.getEntityName())
75-
.appendProperty("NAMESPACE", file.getNamespace())
76-
.appendProperty("CLASS_NAME", DeleteEntityByIdCommandFile.CLASS_NAME)
77-
.appendProperty("ENTITY_ID", data.getEntityId())
70+
typesBuilder
71+
.append("ENTITY_NAME", data.getEntityName(), false)
72+
.append("NAMESPACE", file.getNamespace(), false)
73+
.append("CLASS_NAME", DeleteEntityByIdCommandFile.CLASS_NAME, false)
74+
.append("ENTITY_ID", data.getEntityId(), false)
7875
.append("Exception", "Exception")
7976
.append("COULD_NOT_DELETE", ExceptionType.COULD_NOT_DELETE.getType())
8077
.append("NO_SUCH_ENTITY_EXCEPTION",
8178
ExceptionType.NO_SUCH_ENTITY_EXCEPTION.getType())
8279
.append("LOGGER", FrameworkLibraryType.LOGGER.getType())
8380
.append("MODEL", modelType)
8481
.append("MODEL_FACTORY", modelFactoryType)
85-
.append("RESOURCE", resourceFile.getClassFqn())
86-
.mergeProperties(attributes);
87-
88-
attributes.setProperty("USES",
89-
PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()));
82+
.append("RESOURCE", resourceFile.getClassFqn());
9083
}
9184
}

src/com/magento/idea/magento2plugin/actions/generation/generator/DeleteEntityControllerFileGenerator.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.magento.idea.magento2plugin.actions.generation.data.DeleteEntityControllerFileData;
10-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil;
11-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder;
1210
import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile;
1311
import com.magento.idea.magento2plugin.magento.files.actions.DeleteActionFile;
1412
import com.magento.idea.magento2plugin.magento.files.commands.DeleteEntityByIdCommandFile;
@@ -64,14 +62,12 @@ protected AbstractPhpFile initFile() {
6462
*/
6563
@Override
6664
protected void fillAttributes(final @NotNull Properties attributes) {
67-
final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder();
68-
69-
phpClassTypesBuilder
70-
.appendProperty("NAMESPACE", file.getNamespace())
71-
.appendProperty("ENTITY_NAME", data.getEntityName())
72-
.appendProperty("CLASS_NAME", DeleteActionFile.CLASS_NAME)
73-
.appendProperty("ADMIN_RESOURCE", data.getAcl())
74-
.appendProperty("ENTITY_ID", data.getEntityId())
65+
typesBuilder
66+
.append("NAMESPACE", file.getNamespace(), false)
67+
.append("ENTITY_NAME", data.getEntityName(), false)
68+
.append("CLASS_NAME", DeleteActionFile.CLASS_NAME, false)
69+
.append("ADMIN_RESOURCE", data.getAcl(), false)
70+
.append("ENTITY_ID", data.getEntityId(), false)
7571
.append("DELETE_COMMAND",
7672
new DeleteEntityByIdCommandFile(
7773
data.getModuleName(),
@@ -86,10 +82,6 @@ protected void fillAttributes(final @NotNull Properties attributes) {
8682
.append("IMPLEMENTS_GET", HttpMethod.GET.getInterfaceFqn())
8783
.append("NO_SUCH_ENTITY_EXCEPTION",
8884
ExceptionType.NO_SUCH_ENTITY_EXCEPTION.getType())
89-
.append("COULD_NOT_DELETE", ExceptionType.COULD_NOT_DELETE.getType())
90-
.mergeProperties(attributes);
91-
92-
attributes.setProperty("USES",
93-
PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()));
85+
.append("COULD_NOT_DELETE", ExceptionType.COULD_NOT_DELETE.getType());
9486
}
9587
}

src/com/magento/idea/magento2plugin/actions/generation/generator/EditEntityActionGenerator.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.magento.idea.magento2plugin.actions.generation.data.EditEntityActionData;
10-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil;
11-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder;
1210
import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile;
1311
import com.magento.idea.magento2plugin.magento.files.actions.EditActionFile;
1412
import com.magento.idea.magento2plugin.magento.packages.HttpMethod;
@@ -62,22 +60,16 @@ protected AbstractPhpFile initFile() {
6260
*/
6361
@Override
6462
protected void fillAttributes(final @NotNull Properties attributes) {
65-
final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder();
66-
67-
phpClassTypesBuilder
68-
.appendProperty("NAMESPACE", file.getNamespace())
69-
.appendProperty("ENTITY_NAME", data.getEntityName())
70-
.appendProperty("CLASS_NAME", file.getClassName())
71-
.appendProperty("ADMIN_RESOURCE", data.getAcl())
72-
.appendProperty("MENU_IDENTIFIER", data.getMenu())
63+
typesBuilder
64+
.append("NAMESPACE", file.getNamespace(), false)
65+
.append("ENTITY_NAME", data.getEntityName(), false)
66+
.append("CLASS_NAME", file.getClassName(), false)
67+
.append("ADMIN_RESOURCE", data.getAcl(), false)
68+
.append("MENU_IDENTIFIER", data.getMenu(), false)
7369
.append("EXTENDS", BackendModuleType.EXTENDS.getType())
7470
.append("IMPLEMENTS", HttpMethod.GET.getInterfaceFqn())
7571
.append("RESULT_INTERFACE", FrameworkLibraryType.RESULT_INTERFACE.getType())
7672
.append("RESULT_FACTORY", FrameworkLibraryType.RESULT_FACTORY.getType())
77-
.append("RESULT_PAGE", BackendModuleType.RESULT_PAGE.getType())
78-
.mergeProperties(attributes);
79-
80-
attributes.setProperty("USES",
81-
PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()));
73+
.append("RESULT_PAGE", BackendModuleType.RESULT_PAGE.getType());
8274
}
8375
}

src/com/magento/idea/magento2plugin/actions/generation/generator/EntityDataMapperGenerator.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.magento.idea.magento2plugin.actions.generation.data.EntityDataMapperData;
10-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil;
11-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder;
1210
import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile;
1311
import com.magento.idea.magento2plugin.magento.files.DataModelFile;
1412
import com.magento.idea.magento2plugin.magento.files.DataModelInterfaceFile;
@@ -63,8 +61,6 @@ protected AbstractPhpFile initFile() {
6361
*/
6462
@Override
6563
protected void fillAttributes(final @NotNull Properties attributes) {
66-
final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder();
67-
6864
final ModelFile modelFile = new ModelFile(data.getModuleName(), data.getModelName());
6965
final DataModelFile dtoFile = new DataModelFile(data.getDtoName(), data.getModuleName());
7066
final DataModelInterfaceFile dtoInterfaceFile =
@@ -77,20 +73,14 @@ protected void fillAttributes(final @NotNull Properties attributes) {
7773
dtoType = dtoFile.getClassFqn();
7874
}
7975

80-
phpClassTypesBuilder
81-
.appendProperty("NAMESPACE", file.getNamespace())
82-
.appendProperty("ENTITY_NAME", data.getEntityName())
83-
.appendProperty("CLASS_NAME", file.getClassName())
76+
typesBuilder
77+
.append("NAMESPACE", file.getNamespace(), false)
78+
.append("ENTITY_NAME", data.getEntityName(), false)
79+
.append("CLASS_NAME", file.getClassName(), false)
8480
.append("DATA_OBJECT", FrameworkLibraryType.DATA_OBJECT.getType())
8581
.append("DTO_TYPE", dtoType)
8682
.append("MAGENTO_MODEL_TYPE", modelFile.getClassFqn())
8783
.append("DTO_FACTORY", dtoType.concat("Factory"))
88-
.append("ABSTRACT_COLLECTION", FrameworkLibraryType.ABSTRACT_COLLECTION.getType())
89-
.mergeProperties(attributes);
90-
91-
attributes.setProperty(
92-
"USES",
93-
PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())
94-
);
84+
.append("ABSTRACT_COLLECTION", FrameworkLibraryType.ABSTRACT_COLLECTION.getType());
9585
}
9686
}

src/com/magento/idea/magento2plugin/actions/generation/generator/FormGenericButtonBlockGenerator.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.magento.idea.magento2plugin.actions.generation.data.FormGenericButtonBlockData;
10-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil;
11-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder;
1210
import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile;
1311
import com.magento.idea.magento2plugin.magento.files.FormGenericButtonBlockFile;
1412
import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType;
@@ -63,22 +61,17 @@ protected AbstractPhpFile initFile() {
6361
*/
6462
@Override
6563
protected void fillAttributes(final @NotNull Properties attributes) {
66-
final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder();
6764
final String entityIdGetter = "get" + Arrays.stream(data.getEntityId().split("_"))
6865
.map(s -> s.substring(0, 1).toUpperCase(Locale.getDefault()) + s.substring(1))
6966
.collect(Collectors.joining());
7067

71-
phpClassTypesBuilder
72-
.appendProperty("NAMESPACE", file.getNamespace())
73-
.appendProperty("ENTITY_NAME", data.getEntityName())
74-
.appendProperty("CLASS_NAME", FormGenericButtonBlockFile.CLASS_NAME)
75-
.appendProperty("ENTITY_ID", data.getEntityId())
76-
.appendProperty("ENTITY_ID_GETTER", entityIdGetter)
68+
typesBuilder
69+
.append("NAMESPACE", file.getNamespace(), false)
70+
.append("ENTITY_NAME", data.getEntityName(), false)
71+
.append("CLASS_NAME", FormGenericButtonBlockFile.CLASS_NAME, false)
72+
.append("ENTITY_ID", data.getEntityId(), false)
73+
.append("ENTITY_ID_GETTER", entityIdGetter, false)
7774
.append("CONTEXT", FormGenericButtonBlockFile.CONTEXT)
78-
.append("URL", FrameworkLibraryType.URL.getType())
79-
.mergeProperties(attributes);
80-
81-
attributes.setProperty("USES",
82-
PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()));
75+
.append("URL", FrameworkLibraryType.URL.getType());
8376
}
8477
}

src/com/magento/idea/magento2plugin/actions/generation/generator/GetListQueryModelGenerator.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import com.intellij.openapi.project.Project;
99
import com.magento.idea.magento2plugin.actions.generation.data.GetListQueryModelData;
1010
import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder;
11-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil;
12-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder;
1311
import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile;
1412
import com.magento.idea.magento2plugin.magento.files.CollectionModelFile;
1513
import com.magento.idea.magento2plugin.magento.files.EntityDataMapperFile;
@@ -63,7 +61,6 @@ protected AbstractPhpFile initFile() {
6361
*/
6462
@Override
6563
protected void fillAttributes(final @NotNull Properties attributes) {
66-
final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder();
6764
final CollectionModelFile collectionModelFile =
6865
new CollectionModelFile(
6966
data.getModuleName(),
@@ -73,10 +70,10 @@ protected void fillAttributes(final @NotNull Properties attributes) {
7370
final NamespaceBuilder collectionNamespace =
7471
collectionModelFile.getNamespaceBuilder();
7572

76-
phpClassTypesBuilder
77-
.appendProperty("ENTITY_NAME", data.getEntityName())
78-
.appendProperty("NAMESPACE", file.getNamespace())
79-
.appendProperty("CLASS_NAME", GetListQueryFile.CLASS_NAME)
73+
typesBuilder
74+
.append("ENTITY_NAME", data.getEntityName(), false)
75+
.append("NAMESPACE", file.getNamespace(), false)
76+
.append("CLASS_NAME", GetListQueryFile.CLASS_NAME, false)
8077
.append(
8178
"ENTITY_COLLECTION_TYPE",
8279
collectionNamespace.getClassFqn()
@@ -111,12 +108,6 @@ protected void fillAttributes(final @NotNull Properties attributes) {
111108
.append(
112109
"SEARCH_RESULT_FACTORY_TYPE",
113110
FrameworkLibraryType.SEARCH_RESULT.getFactory()
114-
)
115-
.mergeProperties(attributes);
116-
117-
attributes.setProperty(
118-
"USES",
119-
PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses())
120-
);
111+
);
121112
}
122113
}

src/com/magento/idea/magento2plugin/actions/generation/generator/GridActionColumnFileGenerator.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.magento.idea.magento2plugin.actions.generation.data.GridActionColumnData;
10-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassGeneratorUtil;
11-
import com.magento.idea.magento2plugin.actions.generation.generator.util.PhpClassTypesBuilder;
1210
import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile;
1311
import com.magento.idea.magento2plugin.magento.files.GridActionColumnFile;
1412
import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType;
@@ -60,22 +58,16 @@ protected AbstractPhpFile initFile() {
6058
*/
6159
@Override
6260
protected void fillAttributes(final @NotNull Properties attributes) {
63-
final PhpClassTypesBuilder phpClassTypesBuilder = new PhpClassTypesBuilder();
64-
65-
phpClassTypesBuilder
66-
.appendProperty("ENTITY_NAME", data.getEntityName())
67-
.appendProperty("ENTITY_ID", data.getEntityIdColumn())
68-
.appendProperty("NAMESPACE", file.getNamespace())
69-
.appendProperty("CLASS_NAME", file.getClassName())
70-
.appendProperty("EDIT_URL_PATH", data.getEditUrlPath())
71-
.appendProperty("DELETE_URL_PATH", data.getDeleteUrlPath())
61+
typesBuilder
62+
.append("ENTITY_NAME", data.getEntityName(), false)
63+
.append("ENTITY_ID", data.getEntityIdColumn(), false)
64+
.append("NAMESPACE", file.getNamespace(), false)
65+
.append("CLASS_NAME", file.getClassName(), false)
66+
.append("EDIT_URL_PATH", data.getEditUrlPath(), false)
67+
.append("DELETE_URL_PATH", data.getDeleteUrlPath(), false)
7268
.append("PARENT_CLASS", GridActionColumnFile.PARENT_CLASS)
7369
.append("URL", FrameworkLibraryType.URL.getType())
7470
.append("CONTEXT", GridActionColumnFile.CONTEXT)
75-
.append("UI_COMPONENT_FACTORY", GridActionColumnFile.UI_COMPONENT_FACTORY)
76-
.mergeProperties(attributes);
77-
78-
attributes.setProperty("USES",
79-
PhpClassGeneratorUtil.formatUses(phpClassTypesBuilder.getUses()));
71+
.append("UI_COMPONENT_FACTORY", GridActionColumnFile.UI_COMPONENT_FACTORY);
8072
}
8173
}

0 commit comments

Comments
 (0)