Skip to content

Commit f0c19df

Browse files
committed
[code] Fixed compatibility with 213
1 parent 795b444 commit f0c19df

File tree

6 files changed

+101
-24
lines changed

6 files changed

+101
-24
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ jobs:
7575
key: ${{ runner.os }}-plugin-verifier-${{ steps.properties.outputs.ideVersions }}
7676

7777
# Run Qodana inspections
78-
- name: Qodana - Code Inspection
79-
uses: JetBrains/[email protected]
78+
# - name: Qodana - Code Inspection
79+
# uses: JetBrains/[email protected]
8080

8181
# Run tests
8282
- name: Run Tests

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- Keep a Changelog guide -> https://keepachangelog.com -->
22

3-
# intellij-java-code-aligner Changelog
3+
# Java Code Aligner Changelog
44

55
## [Unreleased]
66
### Added

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
# intellij-java-code-aligner
1+
# Java Code Aligner
22

33
![Build](https://github.com/bash-spbu/intellij-java-code-aligner/workflows/Build/badge.svg)
44
[![Version](https://img.shields.io/jetbrains/plugin/v/17939-java-code-aligner.svg)](https://plugins.jetbrains.com/plugin/17939-java-code-aligner)
55
[![Downloads](https://img.shields.io/jetbrains/plugin/d/17939-java-code-aligner.svg)](https://plugins.jetbrains.com/plugin/17939-java-code-aligner)
66

7-
## Template ToDo list
8-
- [x] Create a new [IntelliJ Platform Plugin Template][template] project.
9-
- [ ] Get known with the [template documentation][template].
10-
- [ ] Verify the [pluginGroup](/gradle.properties), [plugin ID](/src/main/resources/META-INF/plugin.xml) and [sources package](/src/main/kotlin).
11-
- [ ] Review the [Legal Agreements](https://plugins.jetbrains.com/docs/marketplace/legal-agreements.html).
12-
- [ ] [Publish a plugin manually](https://plugins.jetbrains.com/docs/intellij/publishing-plugin.html?from=IJPluginTemplate) for the first time.
13-
- [ ] Set the Plugin ID in the above README badges.
14-
- [ ] Set the [Deployment Token](https://plugins.jetbrains.com/docs/marketplace/plugin-upload.html).
15-
- [ ] Click the <kbd>Watch</kbd> button on the top of the [IntelliJ Platform Plugin Template][template] to be notified about releases containing new features and fixes.
16-
177
<!-- Plugin description -->
18-
This Fancy IntelliJ Platform Plugin is going to be your implementation of the brilliant ideas that you have.
8+
Provides displaying the Java code as aligned horizontally in columns without actual formatting of the code.
9+
10+
It mainly serves for _increasing code readability_ and _reducing tension_
11+
when reading dozens of tightly placed code lines with different elements.
12+
13+
More formally the plugin provides:
1914

20-
This specific section is a source for the [plugin.xml](/src/main/resources/META-INF/plugin.xml) file which will be extracted by the [Gradle](/build.gradle.kts) during the build process.
15+
- alignment of consecutive fields, local variables and params in columns of annotations, modifiers, types, names,
16+
initializers;
17+
- alignment of consecutive assignments by the equal sign;
18+
- pretty rich set of alignment settings in `File | Settings | Editor | Inlay Hints | Java | Java Code Aligner`.
2119

22-
To keep everything working, do not remove `<!-- ... -->` sections.
20+
From the technical side, plugin works by adding invisible inlay hints (like the ones shown as parameter names for method
21+
calls), which can be made visible via `Enable debug mode` in settings above.
22+
23+
Additionally, the plugin provides **folding of explicit types** to `var` and `final var` for local variable
24+
declarations, which can be enabled in `File | Settings | Editor | General | Code Folding | Java Code Aligner`.
2325
<!-- Plugin description end -->
2426

2527
## Installation
2628

2729
- Using IDE built-in plugin system:
28-
29-
<kbd>Settings/Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>Marketplace</kbd> > <kbd>Search for "intellij-java-code-aligner"</kbd> >
30+
31+
<kbd>Settings/Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>Marketplace</kbd> > <kbd>Search for "
32+
intellij-java-code-aligner"</kbd> >
3033
<kbd>Install Plugin</kbd>
31-
34+
3235
- Manually:
3336

3437
Download the [latest release](https://github.com/bash-spbu/intellij-java-code-aligner/releases/latest) and install it manually using

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
33

44
pluginGroup = com.github.bashspbu.intellijjavacodealigner
5-
pluginName = Java Code Aligner
6-
pluginVersion = 1.0.0
5+
pluginName=Java Code Aligner
6+
pluginVersion=1.0.1
77

88
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
99
# for insight into build numbers and IntelliJ Platform versions.

src/main/kotlin/com/github/bashspbu/intellijjavacodealigner/JavaAligningInlaysConfigurable.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
package com.github.bashspbu.intellijjavacodealigner
44

5+
import com.github.bashspbu.intellijjavacodealigner.util.myIntTextField
56
import com.intellij.codeInsight.hints.ChangeListener
67
import com.intellij.codeInsight.hints.ImmediateConfigurable
78
import com.intellij.ui.ContextHelpLabel
89
import com.intellij.ui.DocumentAdapter
910
import com.intellij.ui.EnumComboBoxModel
1011
import com.intellij.ui.layout.Row
1112
import com.intellij.ui.layout.panel
12-
import kotlin.reflect.KMutableProperty0
1313
import javax.swing.JComponent
1414
import javax.swing.event.DocumentEvent
15+
import kotlin.reflect.KMutableProperty0
1516

1617

1718
class JavaAligningInlaysConfigurable(private val settings: JavaAligningInlaysSettings) : ImmediateConfigurable {
@@ -77,7 +78,7 @@ class JavaAligningInlaysConfigurable(private val settings: JavaAligningInlaysSet
7778
private fun Row.maxColumnLengthIntField(labelName: String, listener: ChangeListener, settingsProperty: KMutableProperty0<Int>) {
7879
row {
7980
label(labelName)
80-
intTextField(settingsProperty, range = 5..1000)
81+
myIntTextField(settingsProperty, range = 5..1000)
8182
.component
8283
.let { intTextField ->
8384
intTextField.document.addDocumentListener(object : DocumentAdapter() {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.github.bashspbu.intellijjavacodealigner.util
2+
3+
import com.intellij.ui.UIBundle
4+
import com.intellij.ui.components.JBTextField
5+
import com.intellij.ui.layout.Cell
6+
import com.intellij.ui.layout.CellBuilder
7+
import com.intellij.ui.layout.PropertyBinding
8+
import com.intellij.ui.layout.toBinding
9+
import com.intellij.util.MathUtil
10+
import java.awt.event.KeyAdapter
11+
import java.awt.event.KeyEvent
12+
import kotlin.reflect.KMutableProperty0
13+
14+
15+
internal fun Cell.myIntTextField(
16+
prop: KMutableProperty0<Int>,
17+
columns: Int? = null,
18+
range: IntRange? = null,
19+
step: Int? = null
20+
): CellBuilder<JBTextField> {
21+
return myIntTextField(prop.toBinding(), columns, range, step)
22+
}
23+
24+
/**
25+
* Copy-pasted from the IntelliJ Community 213.
26+
* It changed from 212 to 213, so it was copied in order to be compatible with both 212 and 213.
27+
*/
28+
internal fun Cell.myIntTextField(
29+
binding: PropertyBinding<Int>,
30+
columns: Int? = null,
31+
range: IntRange? = null,
32+
step: Int? = null
33+
): CellBuilder<JBTextField> {
34+
return textField(
35+
{ binding.get().toString() },
36+
{ value ->
37+
value.toIntOrNull()?.let { intValue ->
38+
binding.set(range?.let { intValue.coerceIn(it.first, it.last) } ?: intValue)
39+
}
40+
},
41+
columns
42+
)
43+
.withValidationOnInput {
44+
val value = it.text.toIntOrNull()
45+
when {
46+
value == null -> error(UIBundle.message("please.enter.a.number"))
47+
range != null && value !in range -> error(UIBundle.message("please.enter.a.number.from.0.to.1", range.first, range.last))
48+
else -> null
49+
}
50+
}
51+
.apply {
52+
step ?: return@apply
53+
component.addKeyListener(object : KeyAdapter() {
54+
override fun keyPressed(e: KeyEvent?) {
55+
val increment: Int = when (e?.keyCode) {
56+
KeyEvent.VK_UP -> step
57+
KeyEvent.VK_DOWN -> -step
58+
else -> return
59+
}
60+
61+
var value = component.text.toIntOrNull()
62+
if (value != null) {
63+
value += increment
64+
if (range != null) {
65+
value = MathUtil.clamp(value, range.first, range.last)
66+
}
67+
component.text = value.toString()
68+
e.consume()
69+
}
70+
}
71+
})
72+
}
73+
}

0 commit comments

Comments
 (0)