Skip to content

Commit

Permalink
fix: Other params dialog state (#15)
Browse files Browse the repository at this point in the history
* fix: Persistent old state on Other Params table

Signed-off-by: Nahuel Rodriguez <12597182+Nahuel92@users.noreply.github.com>
  • Loading branch information
Nahuel92 authored Oct 25, 2024
1 parent 05911de commit 9a23c34
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 141 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

PIT4U is a Plugin for IntelliJ to help you run mutation testing using [PIT](http://pitest.org).

## Where?

You can find it available on [Jetbrains Marketplace](https://plugins.jetbrains.com/plugin/25570-pit4u)

## Why?

I created this plugin because the [reference plugin](https://github.com/mjedynak/pit-idea-plugin) by Michal Jedynak (
thank you for that amazing plugin) seems to be abandoned, and latest version is using deprecated APIs that is causing
IntelliJ to freeze and report errors when using it.
thank you for that amazing plugin) seems to be abandoned, and its latest version is using deprecated APIs that is
causing IntelliJ to freeze and report errors when using it. I also expect to add new features that, at the time of
writing, don't exist in the aforementioned plugin.

## Roadmap

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ intellijPlatform {
version = providers.gradleProperty("pluginVersion")
id = "io.github.nahuel92.pit4u"
name = "PIT4U"
version = "0.1.2"
version = "0.1.3"
description = "Plugin that allows you to run PIT mutation tests directly from your IDE"
ideaVersion {
sinceBuild.set("242")
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.List;

class JavaParametersCreator {
private static final Path PIT4U_LIB_PATH = Path.of(PathManager.getPluginsPath())
private static final Path PIT4U_LIB_PATH = PathManager.getPluginsDir()
.resolve("pit4u")
.resolve("lib");
private static final Path JPL_PATH = PIT4U_LIB_PATH.resolve("junit-platform-launcher-1.9.2.jar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void setReportDir(final String reportDir) {
}

public String getOtherParams() {
return otherParams;
return otherParams.replace(System.lineSeparator(), StringUtils.SPACE);
}

public void setOtherParams(final String otherParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.List;

public class PIT4URunConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule, PIT4URunConfiguration>
implements RunConfiguration, Disposable {
implements Disposable {
private final Logger log = Logger.getInstance(PIT4URunConfiguration.class);
private final PIT4UEditorStatus pit4UEditorStatus = new PIT4UEditorStatus();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import com.intellij.openapi.util.Disposer;
import io.github.nahuel92.pit4u.configuration.PIT4UEditorStatus;
import io.github.nahuel92.pit4u.configuration.PIT4URunConfiguration;
import io.github.nahuel92.pit4u.gui.table.OtherParamItem;
import io.github.nahuel92.pit4u.gui.table.OtherParamsDialog;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
Expand All @@ -25,7 +23,6 @@
import java.awt.event.KeyEvent;
import java.util.Arrays;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class PIT4USettingsEditor extends SettingsEditor<PIT4URunConfiguration> {
private static final Logger log = Logger.getInstance(PIT4USettingsEditor.class);
Expand Down Expand Up @@ -151,15 +148,11 @@ private ActionListener getDirectoryListener(final String title, final TextFieldW
private ActionListener getOtherParamsDialogListener() {
return e -> ApplicationManager.getApplication().invokeLater(
() -> {
final var otherParamsDialog = new OtherParamsDialog();
final var otherParamsDialog = new OtherParamsDialog(pit4UEditorStatus.getOtherParams());
Disposer.register(this, otherParamsDialog);
if (otherParamsDialog.showAndGet()) {
final var otherParameters = otherParamsDialog.getTableItems()
.stream()
.map(OtherParamItem::toString)
.collect(Collectors.joining(StringUtils.SPACE));
otherParams.setText(otherParameters);
pit4UEditorStatus.setOtherParams(otherParams.getText());
otherParams.setText(otherParamsDialog.getUserFriendlyModel());
pit4UEditorStatus.setOtherParams(otherParamsDialog.getModelToSave());
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ public Object getCellEditorValue() {
@Override
public Component getTableCellEditorComponent(final JTable table, final Object value,
boolean isSelected, int row, int column) {
if (row < 5) {
checkBox.setSelected((Boolean) value);
return checkBox;
}
if (row == 5) {
comboBox.setSelectedItem(value);
return comboBox;
}
textField.setText(value.toString());
return textField;
return switch (value) {
case Boolean b -> {
checkBox.setSelected(b);
yield checkBox;
}
case String s when row == 5 -> {
comboBox.setSelectedItem(s);
yield comboBox;
}
default -> {
textField.setText(value.toString());
yield textField;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,28 @@

import org.apache.commons.lang3.StringUtils;

public class OtherParamItem<V> {
protected final V defaultParameterValue;
private final String parameterName;
protected V parameterValue;
private boolean hasBeenUpdated;

public OtherParamItem(final String parameterName, final V defaultParameterValue) {
this.parameterName = parameterName;
this.defaultParameterValue = defaultParameterValue;
this.parameterValue = defaultParameterValue;
}

public String getParameterName() {
return parameterName;
}

public V getParameterValue() {
return parameterValue;
}

@SuppressWarnings("unchecked")
public void setParameterValue(final Object newValue) {
this.parameterValue = (V) newValue;
this.hasBeenUpdated = true;
public record OtherParamItem<V>(String name, V defaultValue, V value) {
public OtherParamItem(String name, V defaultValue) {
this(name, defaultValue, defaultValue);
}

public void resetDefaults() {
this.parameterValue = defaultParameterValue;
public OtherParamItem<V> from(final Object newValue) {
final var typedNewValue = switch (newValue) {
case Boolean b -> b;
case String s -> s;
case Float f -> f;
case Integer i -> i;
default -> throw new IllegalStateException("Unexpected value: " + value);
};
return new OtherParamItem<>(name, defaultValue, (V) typedNewValue);
}

public boolean hasBeenUpdated() {
return hasBeenUpdated && !defaultParameterValue.equals(parameterValue);
return !defaultValue.equals(value);
}

@Override
public String toString() {
return parameterName + StringUtils.SPACE + parameterValue;
return name + StringUtils.SPACE + value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.List;

public class OtherParamsDialog extends DialogWrapper implements Disposable {
private static final Logger log = Logger.getInstance(OtherParamsDialog.class);
private final OtherParamsTableModel otherParamsTableModel;
private final TableView<OtherParamItem<?>> table;
private final JButton defaultButton;

public OtherParamsDialog() {
public OtherParamsDialog(final String otherParams) {
super(true);

this.otherParamsTableModel = new OtherParamsTableModel();
this.otherParamsTableModel = new OtherParamsTableModel(otherParams);
this.table = new TableView<>(this.otherParamsTableModel);
this.table.getColumnModel()
.getColumn(1)
Expand All @@ -48,8 +47,12 @@ public void dispose() {
log.info("Other Parameters Dialog Disposed");
}

public List<OtherParamItem<?>> getTableItems() {
return otherParamsTableModel.getUpdatedItems();
public String getUserFriendlyModel() {
return otherParamsTableModel.getUserFriendlyModel();
}

public String getModelToSave() {
return otherParamsTableModel.getModelToSave();
}

private JPanel getCenterPanel() {
Expand Down
Loading

0 comments on commit 9a23c34

Please sign in to comment.