Skip to content

Commit 0103b76

Browse files
committed
Fixes krasa#145 Javadoc indent broken after hitting return in first line
1 parent 1c0110c commit 0103b76

File tree

5 files changed

+95
-9
lines changed

5 files changed

+95
-9
lines changed

META-INF/plugin.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<name>Eclipse Code Formatter</name>
66
<id>EclipseCodeFormatter</id>
7-
<version>17.0.132.637.1</version>
7+
<version>17.1.132.637.0</version>
88

99

1010
<!--145 IntelliJ IDEA 2016.1, AppCode 2016.1, CLion 2016.1, DataGrip 2016.1, PhpStorm 2016.1, PyCharm 2016.1, RubyMine 2016.1, WebStorm 2016.1-->
@@ -40,6 +40,9 @@
4040
</vendor>
4141

4242
<change-notes><![CDATA[
43+
<br>17.1 (2017-07-14)
44+
<br>- Javadoc indent fix
45+
<br>- Improved performance
4346
<br>17.0 (2017-07-07)
4447
<br>- Bundled formatters from Eclipse 4.7
4548
<br>- Introduced Project Specific profile

src/java/krasa/formatter/plugin/DelegatingCodeStyleManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,16 @@ public void reformatTextWithContext(@NotNull PsiFile psiFile, @NotNull ChangedRa
192192
public void reformatTextWithContext(@NotNull PsiFile psiFile, @NotNull Collection<TextRange> collection) throws IncorrectOperationException {
193193
original.reformatTextWithContext(psiFile, collection);
194194
}
195+
196+
// 2017.2
197+
@Override
198+
public int getSpacing(@NotNull PsiFile file, int offset) {
199+
return original.getSpacing(file, offset);
200+
}
201+
202+
// 2017.2
203+
@Override
204+
public int getMinLineFeeds(@NotNull PsiFile file, int offset) {
205+
return original.getMinLineFeeds(file, offset);
206+
}
195207
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package krasa.formatter.plugin;
2+
3+
import com.intellij.formatting.FormattingMode;
4+
import com.intellij.openapi.diagnostic.Logger;
5+
import com.intellij.openapi.editor.Document;
6+
import com.intellij.openapi.util.TextRange;
7+
import com.intellij.psi.PsiFile;
8+
import com.intellij.psi.codeStyle.CodeStyleManager;
9+
import com.intellij.psi.codeStyle.FormattingModeAwareIndentAdjuster;
10+
import com.intellij.util.IncorrectOperationException;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
import java.util.Collection;
14+
15+
public class ManualCodeStyleManagerDelegator extends DelegatingCodeStyleManager implements FormattingModeAwareIndentAdjuster {
16+
private static final Logger log = Logger.getInstance(ManualCodeStyleManagerDelegator.class.getName());
17+
18+
private final EclipseCodeStyleManager eclipseCodeStyleManager;
19+
20+
21+
public ManualCodeStyleManagerDelegator(@NotNull CodeStyleManager original, EclipseCodeStyleManager eclipseCodeStyleManager) {
22+
super(original);
23+
this.eclipseCodeStyleManager = eclipseCodeStyleManager;
24+
}
25+
26+
@Override
27+
public void reformatTextWithContext(@NotNull PsiFile psiFile, @NotNull Collection<TextRange> collection) throws IncorrectOperationException {
28+
eclipseCodeStyleManager.reformatTextWithContext(psiFile, collection);
29+
}
30+
31+
@Override
32+
public void reformatText(@NotNull PsiFile psiFile, @NotNull Collection<TextRange> textRanges) throws IncorrectOperationException {
33+
eclipseCodeStyleManager.reformatText(psiFile, textRanges);
34+
}
35+
36+
@Override
37+
public void reformatText(@NotNull PsiFile psiFile, int startOffset, int endOffset) throws IncorrectOperationException {
38+
eclipseCodeStyleManager.reformatText(psiFile, startOffset, endOffset);
39+
}
40+
41+
@Override
42+
public int adjustLineIndent(@NotNull Document document, int offset, FormattingMode formattingMode) {
43+
if (original instanceof FormattingModeAwareIndentAdjuster) {
44+
return ((FormattingModeAwareIndentAdjuster) original).adjustLineIndent(document, offset, formattingMode);
45+
} else {
46+
return offset;
47+
}
48+
}
49+
50+
@Override
51+
public FormattingMode getCurrentFormattingMode() {
52+
if (original instanceof FormattingModeAwareIndentAdjuster) {
53+
return ((FormattingModeAwareIndentAdjuster) original).getCurrentFormattingMode();
54+
} else {
55+
return FormattingMode.REFORMAT;
56+
}
57+
}
58+
}

src/java/krasa/formatter/plugin/ProjectCodeStyleInstaller.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88

99
package krasa.formatter.plugin;
1010

11-
import static krasa.formatter.plugin.ProxyUtils.createProxy;
12-
13-
import org.jetbrains.annotations.NotNull;
14-
import org.picocontainer.MutablePicoContainer;
15-
1611
import com.intellij.openapi.diagnostic.Logger;
1712
import com.intellij.openapi.project.Project;
1813
import com.intellij.psi.codeStyle.CodeStyleManager;
19-
2014
import krasa.formatter.settings.Settings;
15+
import org.jetbrains.annotations.NotNull;
16+
import org.picocontainer.MutablePicoContainer;
17+
18+
import static krasa.formatter.plugin.ProxyUtils.createProxy;
2119

2220
/**
2321
* Switches a project's {@link CodeStyleManager} to a eclipse formatter and back.
@@ -53,6 +51,7 @@ public EclipseCodeStyleManager install(@NotNull Settings settings) {
5351
overridingObject = new EclipseCodeStyleManager(currentManager, settings);
5452
}
5553
CodeStyleManager proxy = createProxy(currentManager, overridingObject);
54+
// CodeStyleManager proxy = new ManualCodeStyleManagerDelegator(currentManager, overridingObject);
5655

5756
LOG.info("Overriding " + currentManager.getClass().getCanonicalName() + " with " + overridingObject.getClass().getCanonicalName() + "' for project '"
5857
+ project.getName() + "' using CGLIB proxy");

src/java/krasa/formatter/plugin/ProxyUtils.java

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

33

44
import com.intellij.psi.codeStyle.CodeStyleManager;
5+
import com.intellij.psi.codeStyle.FormattingModeAwareIndentAdjuster;
6+
import org.jetbrains.annotations.NotNull;
57

68
public class ProxyUtils {
79
public static CodeStyleManager createProxy(CodeStyleManager manager, EclipseCodeStyleManager overridingObject) {
8-
return (CodeStyleManager) net.sf.cglib.proxy.Enhancer.create(CodeStyleManager.class, new ProxyCodeStyleManagerDelegator(manager, overridingObject));
9-
}
10+
return (CodeStyleManager) net.sf.cglib.proxy.Enhancer.create(CodeStyleManager.class,
11+
getInterfaces(),
12+
new ProxyCodeStyleManagerDelegator(manager, overridingObject));
13+
}
14+
15+
@NotNull
16+
private static Class[] getInterfaces() {
17+
try {
18+
return new Class[]{FormattingModeAwareIndentAdjuster.class};
19+
} catch (Throwable e) {
20+
//old API < IJ ~2017
21+
return new Class[]{};
22+
}
23+
}
1024

1125

1226
}

0 commit comments

Comments
 (0)