Revive IntelliJ Plugin
MOE_MIGRATED_REVID=129262872
diff --git a/idea_plugin/README.md b/idea_plugin/README.md
new file mode 100644
index 0000000..c13a777
--- /dev/null
+++ b/idea_plugin/README.md
@@ -0,0 +1,5 @@
+# google-java-format Intellij Plugin
+
+## Set-up
+
+Add `google-java-format*all-deps.jar` to `lib/`.
diff --git a/idea_plugin/google-java-format.iml b/idea_plugin/google-java-format.iml
new file mode 100644
index 0000000..2808d73
--- /dev/null
+++ b/idea_plugin/google-java-format.iml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PLUGIN_MODULE" version="4">
+ <component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="google-java-format-1.1-20160728.050102-25-all-deps" level="project" />
+ </component>
+</module>
\ No newline at end of file
diff --git a/idea_plugin/idea-plugin.iml b/idea_plugin/idea-plugin.iml
deleted file mode 100644
index 938f438..0000000
--- a/idea_plugin/idea-plugin.iml
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="PLUGIN_MODULE" version="4">
- <component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/src/main/resources/META-INF/plugin.xml" />
- <component name="NewModuleRootManager" inherit-compiler-output="true">
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
- <excludeFolder url="file://$MODULE_DIR$/target" />
- </content>
- <orderEntry type="jdk" jdkName="IDEA SDK" jdkType="IDEA JDK" />
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="module" module-name="core" />
- </component>
-</module>
\ No newline at end of file
diff --git a/idea_plugin/pom.xml b/idea_plugin/pom.xml
deleted file mode 100644
index 76d795e..0000000
--- a/idea_plugin/pom.xml
+++ /dev/null
@@ -1,168 +0,0 @@
-<!--
- ~ Copyright 2015 Google Inc.
- ~
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>com.google.googlejavaformat</groupId>
- <artifactId>google-java-format-parent</artifactId>
- <version>0.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>google-java-format-idea-plugin</artifactId>
-
- <name>Google Java Format Plugin for IntelliJ IDEA</name>
-
- <description>
- A Java source code formatter that follows Google Java Style.
- </description>
-
- <properties>
- <!-- IJ release 14.1.1 -->
- <idea.platform.version>141.1532.4</idea.platform.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>com.google.googlejavaformat</groupId>
- <artifactId>google-java-format</artifactId>
- <version>0.1-SNAPSHOT</version>
- </dependency>
-
- <!--
- The IJ dependencies below must be installed from your IDEA installation directory
- using src/main/scripts/install-idea-jars.sh .
- 141.1532.4 maps to IJ release version 14.1.4.
- -->
- <dependency>
- <groupId>com.jetbrains.intellij.platform</groupId>
- <artifactId>annotations</artifactId>
- <version>${idea.platform.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>com.jetbrains.intellij.platform</groupId>
- <artifactId>extensions</artifactId>
- <version>${idea.platform.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>com.jetbrains.intellij.platform</groupId>
- <artifactId>idea</artifactId>
- <version>${idea.platform.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>com.jetbrains.intellij.platform</groupId>
- <artifactId>openapi</artifactId>
- <version>${idea.platform.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>com.jetbrains.intellij.platform</groupId>
- <artifactId>picocontainer</artifactId>
- <version>${idea.platform.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>com.jetbrains.intellij.platform</groupId>
- <artifactId>util</artifactId>
- <version>${idea.platform.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.6</version>
- <executions>
- <execution>
- <id>copy-plugin-xml</id>
- <phase>process-resources</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <outputDirectory>
- ${project.build.outputDirectory}/META-INF
- </outputDirectory>
- <resources>
- <resource>
- <directory>META-INF</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.4.1</version>
- <configuration>
- <descriptors>
- <descriptor>src/main/assembly/assembly.xml</descriptor>
- </descriptors>
- <encoding>UTF-8</encoding>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- <!--
- IJ doesn't make it easy to run their tests from anywhere but inside IJ,
- so unfortunately we must skip when building with Maven.
- -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.3</version>
- <executions>
- <execution>
- <id>default-testCompile</id>
- <phase>test-compile</phase>
- <goals>
- <goal>testCompile</goal>
- </goals>
- <configuration>
- <skip>true</skip>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.18.1</version>
- <configuration>
- <skipTests>true</skipTests>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
diff --git a/idea_plugin/resources/META-INF/plugin.xml b/idea_plugin/resources/META-INF/plugin.xml
new file mode 100644
index 0000000..f0f5efb
--- /dev/null
+++ b/idea_plugin/resources/META-INF/plugin.xml
@@ -0,0 +1,27 @@
+<idea-plugin version="2">
+ <id>google-java-format</id>
+ <name>google-java-format</name>
+ <version>1.0</version>
+ <vendor url="https://github.com/google/google-java-format">
+ Google
+ </vendor>
+
+ <description><![CDATA[
+ Formats Java source code to comply with Google Style.
+ ]]></description>
+
+ <idea-version since-build="141.0"/>
+
+ <extensions defaultExtensionNs="com.intellij">
+ </extensions>
+
+ <actions>
+ <action
+ id="GoogleJavaFormat"
+ class="com.google.googlejavaformat.intellij.GoogleJavaFormatAction"
+ text="Reformat with google-java-format">
+ <add-to-group group-id="CodeFormatGroup" anchor="last"/>
+ </action>
+ </actions>
+
+</idea-plugin>
\ No newline at end of file
diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/CodeStyleManagerDecorator.java b/idea_plugin/src/com/google/googlejavaformat/intellij/CodeStyleManagerDecorator.java
similarity index 92%
rename from idea_plugin/src/main/java/com/google/googlejavaformat/intellij/CodeStyleManagerDecorator.java
rename to idea_plugin/src/com/google/googlejavaformat/intellij/CodeStyleManagerDecorator.java
index b40e2da..6e321a6 100644
--- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/CodeStyleManagerDecorator.java
+++ b/idea_plugin/src/com/google/googlejavaformat/intellij/CodeStyleManagerDecorator.java
@@ -33,15 +33,14 @@
import org.jetbrains.annotations.Nullable;
/**
- * Decorates the {@link CodeStyleManager} abstract class by delegating to a concrete
- * implementation instance (likely IJ's default instance).
+ * Decorates the {@link CodeStyleManager} abstract class by delegating to a concrete implementation
+ * instance (likely IJ's default instance).
*
* @author bcsf@google.com (Brian Chang)
*/
@SuppressWarnings("deprecation")
-abstract class CodeStyleManagerDecorator extends CodeStyleManager {
- @NotNull
- private final CodeStyleManager delegate;
+class CodeStyleManagerDecorator extends CodeStyleManager {
+ @NotNull private final CodeStyleManager delegate;
protected CodeStyleManagerDecorator(@NotNull CodeStyleManager delegate) {
this.delegate = delegate;
@@ -92,6 +91,12 @@
}
@Override
+ public void reformatTextWithContext(@NotNull PsiFile file, @NotNull Collection<TextRange> ranges)
+ throws IncorrectOperationException {
+ delegate.reformatTextWithContext(file, ranges);
+ }
+
+ @Override
public void adjustLineIndent(@NotNull PsiFile file, TextRange rangeToAdjust)
throws IncorrectOperationException {
delegate.adjustLineIndent(file, rangeToAdjust);
diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatAction.java b/idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatAction.java
similarity index 100%
rename from idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatAction.java
rename to idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatAction.java
diff --git a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java b/idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java
similarity index 76%
rename from idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java
rename to idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java
index 95034bb..a9c8e40 100644
--- a/idea_plugin/src/main/java/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java
+++ b/idea_plugin/src/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManager.java
@@ -43,10 +43,11 @@
*
* @author bcsf@google.com (Brian Chang)
*/
-public class GoogleJavaFormatCodeStyleManager extends CodeStyleManagerDecorator {
+class GoogleJavaFormatCodeStyleManager extends CodeStyleManagerDecorator {
+
private final Formatter formatter = new Formatter();
- public GoogleJavaFormatCodeStyleManager(@NotNull CodeStyleManager original) {
+ GoogleJavaFormatCodeStyleManager(@NotNull CodeStyleManager original) {
super(original);
}
@@ -61,12 +62,22 @@
}
@Override
- public void reformatText(@NotNull PsiFile file, @NotNull Collection<TextRange> textRanges)
+ public void reformatText(@NotNull PsiFile file, @NotNull Collection<TextRange> ranges)
throws IncorrectOperationException {
if (StdFileTypes.JAVA.equals(file.getFileType())) {
- formatInternal(file, convertToRanges(textRanges));
+ formatInternal(file, convertToRanges(ranges));
} else {
- super.reformatText(file, textRanges);
+ super.reformatText(file, ranges);
+ }
+ }
+
+ @Override
+ public void reformatTextWithContext(@NotNull PsiFile file, @NotNull Collection<TextRange> ranges)
+ throws IncorrectOperationException {
+ if (StdFileTypes.JAVA.equals(file.getFileType())) {
+ formatInternal(file, convertToRanges(ranges));
+ } else {
+ super.reformatTextWithContext(file, ranges);
}
}
@@ -91,19 +102,20 @@
}
private void performReplacements(
- final Document document,
- final List<Replacement> reverseSortedReplacements) {
- WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
- @Override
- public void run() {
- for (Replacement replacement : reverseSortedReplacements) {
- Range<Integer> range = replacement.getReplaceRange();
- document.replaceString(
- range.lowerEndpoint(), range.upperEndpoint(), replacement.getReplacementString());
- }
- PsiDocumentManager.getInstance(getProject()).commitDocument(document);
- }
- });
+ final Document document, final List<Replacement> reverseSortedReplacements) {
+ WriteCommandAction.runWriteCommandAction(
+ getProject(),
+ new Runnable() {
+ @Override
+ public void run() {
+ for (Replacement replacement : reverseSortedReplacements) {
+ Range<Integer> range = replacement.getReplaceRange();
+ document.replaceString(
+ range.lowerEndpoint(), range.upperEndpoint(), replacement.getReplacementString());
+ }
+ PsiDocumentManager.getInstance(getProject()).commitDocument(document);
+ }
+ });
}
private static List<Range<Integer>> convertToRanges(Collection<TextRange> textRanges) {
diff --git a/idea_plugin/src/main/assembly/assembly.xml b/idea_plugin/src/main/assembly/assembly.xml
deleted file mode 100644
index eebdb9e..0000000
--- a/idea_plugin/src/main/assembly/assembly.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
- <id>plugin</id>
- <formats>
- <format>zip</format>
- </formats>
-
- <dependencySets>
- <dependencySet>
- <outputDirectory>lib</outputDirectory>
- </dependencySet>
- </dependencySets>
-</assembly>
diff --git a/idea_plugin/src/main/resources/META-INF/plugin.xml b/idea_plugin/src/main/resources/META-INF/plugin.xml
deleted file mode 100644
index e96a68a..0000000
--- a/idea_plugin/src/main/resources/META-INF/plugin.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<idea-plugin version="2">
- <id>GoogleJavaFormat</id>
- <name>Google Java Format</name>
- <version>0.1.1</version>
- <vendor url="https://github.com/google/google-java-format">
- Google
- </vendor>
-
- <description><![CDATA[
- Formats Java source code to comply with Google Style.
- ]]></description>
-
- <change-notes><![CDATA[
- <li>
- 0.1.1 (Initial version): Perform a reformat by selecting
- Code > Reformat with google-java-format
- </li>
- ]]></change-notes>
-
- <idea-version since-build="131"/>
-
- <extensions defaultExtensionNs="com.intellij">
- </extensions>
-
- <application-components>
- </application-components>
-
- <project-components>
- </project-components>
-
- <actions>
- <action
- id="GoogleJavaFormat"
- class="com.google.googlejavaformat.intellij.GoogleJavaFormatAction"
- text="Reformat with google-java-format">
- <add-to-group group-id="CodeFormatGroup" anchor="last"/>
- </action>
- </actions>
-
-</idea-plugin>
diff --git a/idea_plugin/src/main/scripts/install-idea-jars.sh b/idea_plugin/src/main/scripts/install-idea-jars.sh
deleted file mode 100755
index 529a9f8..0000000
--- a/idea_plugin/src/main/scripts/install-idea-jars.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright 2015 Google Inc. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#!/bin/bash
-
-if [[ -z "$1" ]]; then
- echo "Usage: $0 IDEA_HOME"
- echo "Example: $0 /opt/jetbrains/idea-IU-141.178.9"
- exit 1
-fi
-
-if [[ ! -d "$1" ]]; then
- echo "$1 is not a directory"
- exit 1
-fi
-
-ideaHomeDir=$1
-ideaHomeName=$(basename $ideaHomeDir)
-ideaHomeRegex="idea-I[CU]-([0-9]+\.[0-9]+(\.[0-9]+)?)"
-
-if [[ ! $ideaHomeName =~ $ideaHomeRegex ]]; then
- echo "$ideaHomeDir does not appear to be an IDEA directory"
- exit 1
-fi
-
-ideaVersion="${BASH_REMATCH[1]}"
-
-if [[ ! -d $ideaHomeDir/lib ]]; then
- echo "$ideaHomeDir/lib does not exist or is not a directory"
- exit 1
-fi
-
-for artifactPath in $ideaHomeDir/lib/*.jar; do
- artifact=$(basename $artifactPath .jar)
- if [[ -f $artifactPath ]]; then
- mvn install:install-file \
- -DgroupId=com.jetbrains.intellij.platform \
- -DartifactId=$artifact \
- -Dversion=$ideaVersion \
- -Dpackaging=jar \
- -Dfile=$artifactPath
- else
- echo "$artifactPath not found"
- fi
-done
diff --git a/idea_plugin/src/test/java/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManagerTest.java b/idea_plugin/test/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManagerTest.java
similarity index 71%
rename from idea_plugin/src/test/java/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManagerTest.java
rename to idea_plugin/test/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManagerTest.java
index 2651cfb..2b516e9 100644
--- a/idea_plugin/src/test/java/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManagerTest.java
+++ b/idea_plugin/test/com/google/googlejavaformat/intellij/GoogleJavaFormatCodeStyleManagerTest.java
@@ -23,6 +23,7 @@
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
+
import java.net.URL;
import java.net.URLClassLoader;
@@ -42,7 +43,9 @@
"If you see a SecurityException while running this test from within IJ,\n"
+ "unfortunately you'll need to somehow remove ecj.jar from your classpath,\n"
+ "as it will cause a cert conflict with org.eclipse.jdt.core.jar.\n"
- + "e.g. if " + url.getPath() + " is in IDEA_HOME/lib, temporarily relocate it");
+ + "e.g. if "
+ + url.getPath()
+ + " is in IDEA_HOME/lib, temporarily relocate it");
}
}
}
@@ -58,18 +61,21 @@
"public class Test {public static void main(String[]args){System.out.println();}}");
final int startOffset = 0;
final int endOffset = myFixture.getFile().getTextLength();
- ApplicationManager.getApplication().runWriteAction(new Runnable() {
- @Override
- public void run() {
- googleJavaFormat.reformatText(myFixture.getFile(), startOffset, endOffset);
- }
- });
- myFixture.checkResult(join(
- "public class Test {",
- " public static void main(String[] args) {",
- " System.out.println();",
- " }",
- "}"));
+ ApplicationManager.getApplication()
+ .runWriteAction(
+ new Runnable() {
+ @Override
+ public void run() {
+ googleJavaFormat.reformatText(myFixture.getFile(), startOffset, endOffset);
+ }
+ });
+ myFixture.checkResult(
+ join(
+ "public class Test {",
+ " public static void main(String[] args) {",
+ " System.out.println();",
+ " }",
+ "}"));
}
public void testDontFormatNonJavaFile() {
@@ -81,12 +87,14 @@
"public class Test {public static void main(String[]args){System.out.println();}}");
final int startOffset = 0;
final int endOffset = myFixture.getFile().getTextLength();
- ApplicationManager.getApplication().runWriteAction(new Runnable() {
- @Override
- public void run() {
- googleJavaFormat.reformatText(myFixture.getFile(), startOffset, endOffset);
- }
- });
+ ApplicationManager.getApplication()
+ .runWriteAction(
+ new Runnable() {
+ @Override
+ public void run() {
+ googleJavaFormat.reformatText(myFixture.getFile(), startOffset, endOffset);
+ }
+ });
myFixture.checkResult(
"public class Test {public static void main(String[]args){System.out.println();}}");
}
@@ -95,12 +103,13 @@
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(getProject());
final GoogleJavaFormatCodeStyleManager googleJavaFormat =
new GoogleJavaFormatCodeStyleManager(codeStyleManager);
- String content = join(
- "public class Test {",
- " int a=0;",
- " int b=1;",
- " int c=2;",
- "}");
+ String content =
+ join(
+ "public class Test {", //
+ " int a=0;",
+ " int b=1;",
+ " int c=2;",
+ "}");
myFixture.configureByText(StdFileTypes.JAVA, content);
int aLineStart = content.indexOf("int a");
int aLineEnd = content.indexOf("\n", aLineStart);
@@ -108,18 +117,21 @@
int cLineEnd = content.indexOf("\n", cLineStart);
final ImmutableList<TextRange> ranges =
ImmutableList.of(new TextRange(aLineStart, aLineEnd), new TextRange(cLineStart, cLineEnd));
- ApplicationManager.getApplication().runWriteAction(new Runnable() {
- @Override
- public void run() {
- googleJavaFormat.reformatText(myFixture.getFile(), ranges);
- }
- });
- myFixture.checkResult(join(
- "public class Test {",
- " int a = 0;",
- " int b=1;",
- " int c = 2;",
- "}"));
+ ApplicationManager.getApplication()
+ .runWriteAction(
+ new Runnable() {
+ @Override
+ public void run() {
+ googleJavaFormat.reformatText(myFixture.getFile(), ranges);
+ }
+ });
+ myFixture.checkResult(
+ join(
+ "public class Test {", //
+ " int a = 0;",
+ " int b=1;",
+ " int c = 2;",
+ "}"));
}
private static String join(String... lines) {