Skip to content

Commit 399e08f

Browse files
committed
Revive IntelliJ Plugin
MOE_MIGRATED_REVID=129262872
1 parent d2d2239 commit 399e08f

File tree

12 files changed

+136
-353
lines changed

12 files changed

+136
-353
lines changed

idea_plugin/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# google-java-format Intellij Plugin
2+
3+
## Set-up
4+
5+
Add `google-java-format*all-deps.jar` to `lib/`.

idea_plugin/google-java-format.iml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="PLUGIN_MODULE" version="4">
3+
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
4+
<component name="NewModuleRootManager" inherit-compiler-output="true">
5+
<exclude-output />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
9+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
10+
</content>
11+
<orderEntry type="inheritedJdk" />
12+
<orderEntry type="sourceFolder" forTests="false" />
13+
<orderEntry type="library" name="google-java-format-1.1-20160728.050102-25-all-deps" level="project" />
14+
</component>
15+
</module>

idea_plugin/idea-plugin.iml

Lines changed: 0 additions & 15 deletions
This file was deleted.

idea_plugin/pom.xml

Lines changed: 0 additions & 168 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<idea-plugin version="2">
2+
<id>google-java-format</id>
3+
<name>google-java-format</name>
4+
<version>1.0</version>
5+
<vendor url="https://github.com/google/google-java-format">
6+
Google
7+
</vendor>
8+
9+
<description><![CDATA[
10+
Formats Java source code to comply with Google Style.
11+
]]></description>
12+
13+
<idea-version since-build="141.0"/>
14+
15+
<extensions defaultExtensionNs="com.intellij">
16+
</extensions>
17+
18+
<actions>
19+
<action
20+
id="GoogleJavaFormat"
21+
class="com.google.googlejavaformat.intellij.GoogleJavaFormatAction"
22+
text="Reformat with google-java-format">
23+
<add-to-group group-id="CodeFormatGroup" anchor="last"/>
24+
</action>
25+
</actions>
26+
27+
</idea-plugin>

idea_plugin/src/main/java/com/google/googlejavaformat/intellij/CodeStyleManagerDecorator.java renamed to idea_plugin/src/com/google/googlejavaformat/intellij/CodeStyleManagerDecorator.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@
3333
import org.jetbrains.annotations.Nullable;
3434

3535
/**
36-
* Decorates the {@link CodeStyleManager} abstract class by delegating to a concrete
37-
* implementation instance (likely IJ's default instance).
36+
* Decorates the {@link CodeStyleManager} abstract class by delegating to a concrete implementation
37+
* instance (likely IJ's default instance).
3838
*
3939
* @author bcsf@google.com (Brian Chang)
4040
*/
4141
@SuppressWarnings("deprecation")
42-
abstract class CodeStyleManagerDecorator extends CodeStyleManager {
43-
@NotNull
44-
private final CodeStyleManager delegate;
42+
class CodeStyleManagerDecorator extends CodeStyleManager {
43+
@NotNull private final CodeStyleManager delegate;
4544

4645
protected CodeStyleManagerDecorator(@NotNull CodeStyleManager delegate) {
4746
this.delegate = delegate;
@@ -91,6 +90,12 @@ public void reformatText(@NotNull PsiFile file, @NotNull Collection<TextRange> r
9190
delegate.reformatText(file, ranges);
9291
}
9392

93+
@Override
94+
public void reformatTextWithContext(@NotNull PsiFile file, @NotNull Collection<TextRange> ranges)
95+
throws IncorrectOperationException {
96+
delegate.reformatTextWithContext(file, ranges);
97+
}
98+
9499
@Override
95100
public void adjustLineIndent(@NotNull PsiFile file, TextRange rangeToAdjust)
96101
throws IncorrectOperationException {

idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatAction.java renamed to idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatAction.java

File renamed without changes.

idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java renamed to idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@
4343
*
4444
* @author bcsf@google.com (Brian Chang)
4545
*/
46-
public class GoogleJavaFormatCodeStyleManager extends CodeStyleManagerDecorator {
46+
class GoogleJavaFormatCodeStyleManager extends CodeStyleManagerDecorator {
47+
4748
private final Formatter formatter = new Formatter();
4849

49-
public GoogleJavaFormatCodeStyleManager(@NotNull CodeStyleManager original) {
50+
GoogleJavaFormatCodeStyleManager(@NotNull CodeStyleManager original) {
5051
super(original);
5152
}
5253

@@ -61,12 +62,22 @@ public void reformatText(@NotNull PsiFile file, int startOffset, int endOffset)
6162
}
6263

6364
@Override
64-
public void reformatText(@NotNull PsiFile file, @NotNull Collection<TextRange> textRanges)
65+
public void reformatText(@NotNull PsiFile file, @NotNull Collection<TextRange> ranges)
66+
throws IncorrectOperationException {
67+
if (StdFileTypes.JAVA.equals(file.getFileType())) {
68+
formatInternal(file, convertToRanges(ranges));
69+
} else {
70+
super.reformatText(file, ranges);
71+
}
72+
}
73+
74+
@Override
75+
public void reformatTextWithContext(@NotNull PsiFile file, @NotNull Collection<TextRange> ranges)
6576
throws IncorrectOperationException {
6677
if (StdFileTypes.JAVA.equals(file.getFileType())) {
67-
formatInternal(file, convertToRanges(textRanges));
78+
formatInternal(file, convertToRanges(ranges));
6879
} else {
69-
super.reformatText(file, textRanges);
80+
super.reformatTextWithContext(file, ranges);
7081
}
7182
}
7283

@@ -91,19 +102,20 @@ private void formatInternal(PsiFile file, List<Range<Integer>> ranges)
91102
}
92103

93104
private void performReplacements(
94-
final Document document,
95-
final List<Replacement> reverseSortedReplacements) {
96-
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
97-
@Override
98-
public void run() {
99-
for (Replacement replacement : reverseSortedReplacements) {
100-
Range<Integer> range = replacement.getReplaceRange();
101-
document.replaceString(
102-
range.lowerEndpoint(), range.upperEndpoint(), replacement.getReplacementString());
103-
}
104-
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
105-
}
106-
});
105+
final Document document, final List<Replacement> reverseSortedReplacements) {
106+
WriteCommandAction.runWriteCommandAction(
107+
getProject(),
108+
new Runnable() {
109+
@Override
110+
public void run() {
111+
for (Replacement replacement : reverseSortedReplacements) {
112+
Range<Integer> range = replacement.getReplaceRange();
113+
document.replaceString(
114+
range.lowerEndpoint(), range.upperEndpoint(), replacement.getReplacementString());
115+
}
116+
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
117+
}
118+
});
107119
}
108120

109121
private static List<Range<Integer>> convertToRanges(Collection<TextRange> textRanges) {

idea_plugin/src/main/assembly/assembly.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)