Skip to content

857: fixed error when class already exists #893

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

Merged
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 @@ -31,6 +31,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JOptionPane;

public class ModuleControllerClassGenerator extends FileGenerator {
Expand Down Expand Up @@ -73,47 +74,49 @@ public ModuleControllerClassGenerator(
@Override
public PsiFile generate(final String actionName) {
final PsiFile[] controllerFiles = new PsiFile[1];
final AtomicBoolean isControllerExists = new AtomicBoolean(false);
final AtomicBoolean isControllerCanNotBeCreated = new AtomicBoolean(false);

WriteCommandAction.runWriteCommandAction(project, () -> {
PhpClass controller = GetPhpClassByFQN.getInstance(project).execute(
getControllerFqn()
);

if (controller != null) {
final String errorMessage = this.validatorBundle.message(
"validator.file.alreadyExists",
"Controller Class"
);
JOptionPane.showMessageDialog(
null,
errorMessage,
commonBundle.message("common.error"),
JOptionPane.ERROR_MESSAGE
);

isControllerExists.set(true);
return;
}

controller = createControllerClass(actionName);

if (controller == null) {
final String errorMessage = this.validatorBundle.message(
"validator.file.cantBeCreated",
"Controller Class"
);
JOptionPane.showMessageDialog(
null,
errorMessage,
commonBundle.message("common.error"),
JOptionPane.ERROR_MESSAGE
);

isControllerCanNotBeCreated.set(true);
return;
}

controllerFiles[0] = controller.getContainingFile();
});

if (isControllerExists.get()) {
JOptionPane.showMessageDialog(
null,
validatorBundle.message(
"validator.file.alreadyExists",
"Controller Class"
),
commonBundle.message("common.error"),
JOptionPane.ERROR_MESSAGE
);
} else if (isControllerCanNotBeCreated.get()) {
JOptionPane.showMessageDialog(
null,
validatorBundle.message(
"validator.file.cantBeCreated",
"Controller Class"
),
commonBundle.message("common.error"),
JOptionPane.ERROR_MESSAGE
);
}

return controllerFiles[0];
}

Expand Down