|
| 1 | +/* |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +package com.magento.idea.magento2plugin.actions.generation.generator.php; |
| 7 | + |
| 8 | +import com.intellij.openapi.project.Project; |
| 9 | +import com.magento.idea.magento2plugin.actions.generation.data.php.SearchResultsData; |
| 10 | +import com.magento.idea.magento2plugin.actions.generation.generator.PhpFileGenerator; |
| 11 | +import com.magento.idea.magento2plugin.magento.files.AbstractPhpFile; |
| 12 | +import com.magento.idea.magento2plugin.magento.files.SearchResultsFile; |
| 13 | +import com.magento.idea.magento2plugin.magento.files.SearchResultsInterfaceFile; |
| 14 | +import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType; |
| 15 | +import java.util.Properties; |
| 16 | +import org.jetbrains.annotations.NotNull; |
| 17 | + |
| 18 | +public class SearchResultsGenerator extends PhpFileGenerator { |
| 19 | + |
| 20 | + private final SearchResultsData data; |
| 21 | + |
| 22 | + /** |
| 23 | + * Search results file generator constructor. |
| 24 | + * |
| 25 | + * @param data SearchResultsData |
| 26 | + * @param project Project |
| 27 | + */ |
| 28 | + public SearchResultsGenerator( |
| 29 | + final @NotNull SearchResultsData data, |
| 30 | + final @NotNull Project project |
| 31 | + ) { |
| 32 | + this(data, project, true); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Search results file generator constructor. |
| 37 | + * |
| 38 | + * @param data SearchResultsData |
| 39 | + * @param project Project |
| 40 | + * @param checkFileAlreadyExists boolean |
| 41 | + */ |
| 42 | + public SearchResultsGenerator( |
| 43 | + final @NotNull SearchResultsData data, |
| 44 | + final @NotNull Project project, |
| 45 | + final boolean checkFileAlreadyExists |
| 46 | + ) { |
| 47 | + super(project, checkFileAlreadyExists); |
| 48 | + this.data = data; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + protected AbstractPhpFile initFile() { |
| 53 | + return new SearchResultsFile(data.getModuleName(), data.getEntityName()); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + protected void fillAttributes(final @NotNull Properties attributes) { |
| 58 | + final String interfaceClassFqn = new SearchResultsInterfaceFile( |
| 59 | + data.getModuleName(), |
| 60 | + data.getEntityName() |
| 61 | + ).getClassFqn(); |
| 62 | + |
| 63 | + typesBuilder |
| 64 | + .append("NAMESPACE", file.getNamespace(), false) |
| 65 | + .append("ENTITY_NAME", data.getEntityName(), false) |
| 66 | + .append("CLASS_NAME", file.getClassName(), false) |
| 67 | + .append("INTERFACE_NAME", interfaceClassFqn) |
| 68 | + .append( |
| 69 | + "PARENT_CLASS_NAME", |
| 70 | + FrameworkLibraryType.SEARCH_RESULT_IMPLEMENTATION.getType() |
| 71 | + ); |
| 72 | + } |
| 73 | +} |
0 commit comments