Skip to content

Commit 0224ad9

Browse files
committed
Rename the IntelliJ settings' State class to StoredSettings
State also named IntelliJ's @State annotation on the same class, which the previous commit wrote out in full to tell the two apart. The class gets a name of its own and the annotation its import back. The class name is not in .idea/open-java-format.xml: IntelliJ writes the bean's fields into the component element, and PalantirJavaFormatSettingsTest loads files written before.
1 parent e890042 commit 0224ad9

5 files changed

Lines changed: 19 additions & 18 deletions

File tree

‎open-java-format-idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.intellij.formatting.service.FormattingService;
2020
import com.intellij.openapi.components.PersistentStateComponent;
21+
import com.intellij.openapi.components.State;
2122
import com.intellij.openapi.components.Storage;
2223
import com.intellij.openapi.extensions.PluginDescriptor;
2324
import com.intellij.openapi.project.Project;
@@ -36,25 +37,25 @@
3637

3738
import static java.util.Optional.ofNullable;
3839

39-
@com.intellij.openapi.components.State(
40+
@State(
4041
name = "PalantirJavaFormatSettings",
4142
storages = {@Storage("open-java-format.xml")})
42-
public class PalantirJavaFormatSettings implements PersistentStateComponent<PalantirJavaFormatSettings.State> {
43+
public class PalantirJavaFormatSettings implements PersistentStateComponent<PalantirJavaFormatSettings.StoredSettings> {
4344

44-
private State state = new State();
45+
private StoredSettings state = new StoredSettings();
4546

4647
static PalantirJavaFormatSettings getInstance(Project project) {
4748
return project.getService(PalantirJavaFormatSettings.class);
4849
}
4950

5051
@Nullable
5152
@Override
52-
public State getState() {
53+
public StoredSettings getState() {
5354
return state;
5455
}
5556

5657
@Override
57-
public void loadState(State state) {
58+
public void loadState(StoredSettings state) {
5859
this.state = state;
5960
}
6061

@@ -148,7 +149,7 @@ enum EnabledState {
148149
DISABLED
149150
}
150151

151-
static class State {
152+
static class StoredSettings {
152153

153154
private EnabledState enabled = EnabledState.UNKNOWN;
154155
private Optional<List<URI>> implementationClassPath = Optional.empty();

‎open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/FormatterProviderTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.intellij.testFramework.fixtures.JavaTestFixtureFactory;
2323
import com.palantir.javaformat.bootstrap.BootstrappingFormatterService;
2424
import com.palantir.javaformat.bootstrap.NativeImageFormatterService;
25-
import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.State;
25+
import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.StoredSettings;
2626
import java.nio.file.Path;
2727
import java.util.Optional;
2828
import java.util.concurrent.atomic.AtomicReference;
@@ -45,7 +45,7 @@ void setUp() throws Exception {
4545
fixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
4646
fixture.setUp();
4747
settings = PalantirJavaFormatSettings.getInstance(fixture.getProject());
48-
settings.loadState(new State());
48+
settings.loadState(new StoredSettings());
4949
}
5050

5151
@AfterEach

‎open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatConfigurableTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.palantir.javaformat.intellij.EmbeddedNativeImage.Installed;
3535
import com.palantir.javaformat.intellij.EmbeddedNativeImage.Status;
3636
import com.palantir.javaformat.intellij.PalantirJavaFormatConfigurable.StatusLine;
37-
import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.State;
37+
import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.StoredSettings;
3838
import java.awt.Component;
3939
import java.awt.Container;
4040
import java.io.IOException;
@@ -74,7 +74,7 @@ void setUp() throws Exception {
7474
fixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
7575
fixture.setUp();
7676
settings = PalantirJavaFormatSettings.getInstance(fixture.getProject());
77-
settings.loadState(new State());
77+
settings.loadState(new StoredSettings());
7878
settings.setEnabled(true);
7979
// Nothing downloaded, and nowhere to download from.
8080
var embedded = new EmbeddedNativeImage(
@@ -104,7 +104,7 @@ void hasNoChoiceOfCodeStyle() {
104104

105105
@Test
106106
void readsAndWritesTheEnabledSetting() throws Throwable {
107-
State disabled = new State();
107+
var disabled = new StoredSettings();
108108
disabled.setEnabled("false");
109109
settings.loadState(disabled);
110110

‎open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture;
3636
import com.intellij.testFramework.fixtures.JavaTestFixtureFactory;
3737
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
38-
import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.State;
38+
import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.StoredSettings;
3939
import org.jetbrains.annotations.NotNull;
4040
import org.junit.jupiter.api.AfterEach;
4141
import org.junit.jupiter.api.BeforeEach;
@@ -70,7 +70,7 @@ void setUp() throws Exception {
7070

7171
settings = PalantirJavaFormatSettings.getInstance(fixture.getProject());
7272

73-
State resetState = new State();
73+
var resetState = new StoredSettings();
7474
resetState.setEnabled("true");
7575
settings.loadState(resetState);
7676
}

‎open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettingsTest.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.intellij.openapi.util.JDOMUtil;
2020
import com.intellij.util.xmlb.XmlSerializer;
21-
import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.State;
21+
import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.StoredSettings;
2222
import java.nio.file.Path;
2323
import java.util.Optional;
2424
import org.intellij.lang.annotations.Language;
@@ -42,7 +42,7 @@ void loadsAFileThatStillHasTheCodeStyle() throws Exception {
4242

4343
@Test
4444
void doesNotWriteACodeStyle() {
45-
var xml = JDOMUtil.write(XmlSerializer.serialize(new State()));
45+
var xml = JDOMUtil.write(XmlSerializer.serialize(new StoredSettings()));
4646

4747
assertThat(xml).doesNotContain("style");
4848
}
@@ -78,15 +78,15 @@ void ignoresTheNativeImageTheGradlePluginUsedToWrite() throws Exception {
7878

7979
@Test
8080
void takesABlankPathForNone() {
81-
var state = new State();
81+
var state = new StoredSettings();
8282
state.nativeImagePath = " ";
8383
var settings = new PalantirJavaFormatSettings();
8484
settings.loadState(state);
8585

8686
assertThat(settings.getNativeImagePath()).isEmpty();
8787
}
8888

89-
private static State deserialize(@Language("xml") String xml) throws Exception {
90-
return XmlSerializer.deserialize(JDOMUtil.load(xml), State.class);
89+
private static StoredSettings deserialize(@Language("xml") String xml) throws Exception {
90+
return XmlSerializer.deserialize(JDOMUtil.load(xml), StoredSettings.class);
9191
}
9292
}

0 commit comments

Comments
 (0)