Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the IntelliJ plugin to use v1.12.0 #688

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions idea_plugin/.gitignore
@@ -0,0 +1,5 @@
build
.gradle
gradle
gradlew
gradlew.bat
24 changes: 14 additions & 10 deletions idea_plugin/build.gradle
Expand Up @@ -15,31 +15,35 @@
*/

plugins {
id "org.jetbrains.intellij" version "1.3.0"
id "org.jetbrains.intellij" version "1.3.1"
}

repositories {
mavenCentral()
}

ext {
googleJavaFormatVersion = '1.13.0'
googleJavaFormatVersion = "1.13.0"
}

apply plugin: 'org.jetbrains.intellij'
apply plugin: 'java'
apply plugin: "org.jetbrains.intellij"
apply plugin: "java"

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

intellij {
pluginName = "google-java-format"
version = "IC-213.5744.18-EAP-SNAPSHOT"
plugins = ["java"]
version = "221.3427-EAP-CANDIDATE-SNAPSHOT"
}

patchPluginXml {
pluginDescription = "Formats source code using the google-java-format tool. This version of " +
"the plugin uses version ${googleJavaFormatVersion} of the tool."
version = "${googleJavaFormatVersion}.0"
sinceBuild = '201'
untilBuild = ''
version.set("${googleJavaFormatVersion}.0")
sinceBuild = "203"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why you updated this to 2020.3? AFAIK there's no reason it shouldn't continue to work with 2020.1. (I just tested the 1.13 plugin with 2020.1 and it still seems to work...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I updated it to 2020.3 was for the newer features regarding notification groups
https://plugins.jetbrains.com/docs/intellij/notifications.html#top-level-notifications-balloons
+ https://plugins.jetbrains.com/docs/marketplace/product-versions-in-use-statistics.html

I considered it acceptable to move to 203 from 201 to get the newer features to ease the pain in the future

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay, yeah that's totally reasonable. I thought it was just an arbitrary change, but if it's enabling that notification configuration change, that defintiely makes sense.

untilBuild = ""
}

publishPlugin {
Expand All @@ -48,8 +52,8 @@ publishPlugin {

sourceSets {
main {
java.srcDir 'src'
resources.srcDir 'resources'
java.srcDir "src"
resources.srcDir "resources"
}
}

Expand Down
24 changes: 15 additions & 9 deletions idea_plugin/resources/META-INF/plugin.xml
Expand Up @@ -14,7 +14,8 @@
limitations under the License.
-->

<idea-plugin url="https://github.com/google/google-java-format/tree/master/idea_plugin" require-restart="true">
<idea-plugin url="https://github.com/google/google-java-format/tree/master/idea_plugin"
require-restart="true">
<id>google-java-format</id>
<name>google-java-format</name>
<vendor url="https://github.com/google/google-java-format">
Expand All @@ -24,7 +25,7 @@
<!-- Mark it as available on all JetBrains IDEs. It's really only useful in
IDEA and Android Studio, but there's no way to specify that for some
reason. It won't crash PyCharm or anything, so whatever. -->
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.java</depends>

<change-notes><![CDATA[
<dl>
Expand Down Expand Up @@ -58,17 +59,22 @@
]]></change-notes>

<applicationListeners>
<listener class="com.google.googlejavaformat.intellij.InitialConfigurationProjectManagerListener"
topic="com.intellij.openapi.project.ProjectManagerListener"/>
<listener
class="com.google.googlejavaformat.intellij.InitialConfigurationProjectManagerListener"
topic="com.intellij.openapi.project.ProjectManagerListener"/>
<listener class="com.google.googlejavaformat.intellij.GoogleJavaFormatInstaller"
topic="com.intellij.openapi.project.ProjectManagerListener"/>
topic="com.intellij.openapi.project.ProjectManagerListener"/>
</applicationListeners>

<extensions defaultExtensionNs="com.intellij">
<projectConfigurable instance="com.google.googlejavaformat.intellij.GoogleJavaFormatConfigurable"
id="google-java-format.settings"
displayName="google-java-format Settings"/>
<projectService serviceImplementation="com.google.googlejavaformat.intellij.GoogleJavaFormatSettings"/>
<projectConfigurable
instance="com.google.googlejavaformat.intellij.GoogleJavaFormatConfigurable"
id="google-java-format.settings"
displayName="google-java-format Settings"/>
<projectService
serviceImplementation="com.google.googlejavaformat.intellij.GoogleJavaFormatSettings"/>
<notificationGroup displayType="STICKY_BALLOON" id="Enable google-java-format"
isLogByDefault="true"/>
</extensions>

</idea-plugin>
Expand Up @@ -34,10 +34,11 @@
import com.intellij.util.ThrowableRunnable;
import java.util.Collection;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

/**
* Decorates the {@link CodeStyleManager} abstract class by delegating to a concrete implementation
* instance (likely IJ's default instance).
* instance (likely IntelliJ's default instance).
*/
@SuppressWarnings("deprecation")
class CodeStyleManagerDecorator extends CodeStyleManager
Expand All @@ -54,98 +55,101 @@ CodeStyleManager getDelegate() {
}

@Override
public Project getProject() {
public @NotNull Project getProject() {
return delegate.getProject();
}

@Override
public PsiElement reformat(PsiElement element) throws IncorrectOperationException {
public @NotNull PsiElement reformat(@NotNull PsiElement element)
throws IncorrectOperationException {
return delegate.reformat(element);
}

@Override
public PsiElement reformat(PsiElement element, boolean canChangeWhiteSpacesOnly)
public @NotNull PsiElement reformat(@NotNull PsiElement element, boolean canChangeWhiteSpacesOnly)
throws IncorrectOperationException {
return delegate.reformat(element, canChangeWhiteSpacesOnly);
}

@Override
public PsiElement reformatRange(PsiElement element, int startOffset, int endOffset)
public PsiElement reformatRange(@NotNull PsiElement element, int startOffset, int endOffset)
throws IncorrectOperationException {
return delegate.reformatRange(element, startOffset, endOffset);
}

@Override
public PsiElement reformatRange(
PsiElement element, int startOffset, int endOffset, boolean canChangeWhiteSpacesOnly)
@NotNull PsiElement element, int startOffset, int endOffset, boolean canChangeWhiteSpacesOnly)
throws IncorrectOperationException {
return delegate.reformatRange(element, startOffset, endOffset, canChangeWhiteSpacesOnly);
}

@Override
public void reformatText(PsiFile file, int startOffset, int endOffset)
public void reformatText(@NotNull PsiFile file, int startOffset, int endOffset)
throws IncorrectOperationException {
delegate.reformatText(file, startOffset, endOffset);
}

@Override
public void reformatText(PsiFile file, Collection<? extends TextRange> ranges)
public void reformatText(@NotNull PsiFile file, @NotNull Collection<? extends TextRange> ranges)
throws IncorrectOperationException {
delegate.reformatText(file, ranges);
}

@Override
public void reformatTextWithContext(PsiFile psiFile, ChangedRangesInfo changedRangesInfo)
public void reformatTextWithContext(
@NotNull PsiFile psiFile, @NotNull ChangedRangesInfo changedRangesInfo)
throws IncorrectOperationException {
delegate.reformatTextWithContext(psiFile, changedRangesInfo);
}

@Override
public void reformatTextWithContext(PsiFile file, Collection<? extends TextRange> ranges)
public void reformatTextWithContext(@NotNull PsiFile file, @NotNull Collection<? extends TextRange> ranges)
throws IncorrectOperationException {
delegate.reformatTextWithContext(file, ranges);
}

@Override
public void adjustLineIndent(PsiFile file, TextRange rangeToAdjust)
public void adjustLineIndent(@NotNull PsiFile file, TextRange rangeToAdjust)
throws IncorrectOperationException {
delegate.adjustLineIndent(file, rangeToAdjust);
}

@Override
public int adjustLineIndent(PsiFile file, int offset) throws IncorrectOperationException {
public int adjustLineIndent(@NotNull PsiFile file, int offset)
throws IncorrectOperationException {
return delegate.adjustLineIndent(file, offset);
}

@Override
public int adjustLineIndent(Document document, int offset) {
public int adjustLineIndent(@NotNull Document document, int offset) {
return delegate.adjustLineIndent(document, offset);
}

public void scheduleIndentAdjustment(Document document, int offset) {
public void scheduleIndentAdjustment(@NotNull Document document, int offset) {
delegate.scheduleIndentAdjustment(document, offset);
}

@Override
public boolean isLineToBeIndented(PsiFile file, int offset) {
public boolean isLineToBeIndented(@NotNull PsiFile file, int offset) {
return delegate.isLineToBeIndented(file, offset);
}

@Override
@Nullable
public String getLineIndent(PsiFile file, int offset) {
public String getLineIndent(@NotNull PsiFile file, int offset) {
return delegate.getLineIndent(file, offset);
}

@Override
@Nullable
public String getLineIndent(PsiFile file, int offset, FormattingMode mode) {
public String getLineIndent(@NotNull PsiFile file, int offset, FormattingMode mode) {
return delegate.getLineIndent(file, offset, mode);
}

@Override
@Nullable
public String getLineIndent(Document document, int offset) {
public String getLineIndent(@NotNull Document document, int offset) {
return delegate.getLineIndent(document, offset);
}

Expand All @@ -165,7 +169,7 @@ public Indent zeroIndent() {
}

@Override
public void reformatNewlyAddedElement(ASTNode block, ASTNode addedElement)
public void reformatNewlyAddedElement(@NotNull ASTNode block, @NotNull ASTNode addedElement)
throws IncorrectOperationException {
delegate.reformatNewlyAddedElement(block, addedElement);
}
Expand All @@ -192,22 +196,23 @@ public <T> T performActionWithFormatterDisabled(Computable<T> r) {
}

@Override
public int getSpacing(PsiFile file, int offset) {
public int getSpacing(@NotNull PsiFile file, int offset) {
return delegate.getSpacing(file, offset);
}

@Override
public int getMinLineFeeds(PsiFile file, int offset) {
public int getMinLineFeeds(@NotNull PsiFile file, int offset) {
return delegate.getMinLineFeeds(file, offset);
}

@Override
public void runWithDocCommentFormattingDisabled(PsiFile file, Runnable runnable) {
public void runWithDocCommentFormattingDisabled(
@NotNull PsiFile file, @NotNull Runnable runnable) {
delegate.runWithDocCommentFormattingDisabled(file, runnable);
}

@Override
public DocCommentSettings getDocCommentSettings(PsiFile file) {
public @NotNull DocCommentSettings getDocCommentSettings(@NotNull PsiFile file) {
return delegate.getDocCommentSettings(file);
}

Expand All @@ -223,7 +228,8 @@ public FormattingMode getCurrentFormattingMode() {
}

@Override
public int adjustLineIndent(final Document document, final int offset, FormattingMode mode)
public int adjustLineIndent(
final @NotNull Document document, final int offset, FormattingMode mode)
throws IncorrectOperationException {
if (delegate instanceof FormattingModeAwareIndentAdjuster) {
return ((FormattingModeAwareIndentAdjuster) delegate)
Expand All @@ -233,7 +239,7 @@ public int adjustLineIndent(final Document document, final int offset, Formattin
}

@Override
public void scheduleReformatWhenSettingsComputed(PsiFile file) {
public void scheduleReformatWhenSettingsComputed(@NotNull PsiFile file) {
delegate.scheduleReformatWhenSettingsComputed(file);
}
}
Expand Up @@ -50,8 +50,7 @@ static Map<TextRange, String> getReplacements(
}

private static Collection<Range<Integer>> toRanges(Collection<? extends TextRange> textRanges) {
return textRanges
.stream()
return textRanges.stream()
.map(textRange -> Range.closedOpen(textRange.getStartOffset(), textRange.getEndOffset()))
.collect(Collectors.toList());
}
Expand Down
Expand Up @@ -22,10 +22,10 @@
import com.google.googlejavaformat.java.Formatter;
import com.google.googlejavaformat.java.JavaFormatterOptions;
import com.google.googlejavaformat.java.JavaFormatterOptions.Style;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
Expand All @@ -44,7 +44,7 @@

/**
* A {@link CodeStyleManager} implementation which formats .java files with google-java-format.
* Formatting of all other types of files is delegated to IJ's default implementation.
* Formatting of all other types of files is delegated to IntelliJ's default implementation.
*/
class GoogleJavaFormatCodeStyleManager extends CodeStyleManagerDecorator {

Expand All @@ -53,7 +53,7 @@ public GoogleJavaFormatCodeStyleManager(@NotNull CodeStyleManager original) {
}

@Override
public void reformatText(PsiFile file, int startOffset, int endOffset)
public void reformatText(@NotNull PsiFile file, int startOffset, int endOffset)
throws IncorrectOperationException {
if (overrideFormatterForFile(file)) {
formatInternal(file, ImmutableList.of(new TextRange(startOffset, endOffset)));
Expand All @@ -63,7 +63,7 @@ public void reformatText(PsiFile file, int startOffset, int endOffset)
}

@Override
public void reformatText(PsiFile file, Collection<? extends TextRange> ranges)
public void reformatText(@NotNull PsiFile file, @NotNull Collection<? extends TextRange> ranges)
throws IncorrectOperationException {
if (overrideFormatterForFile(file)) {
formatInternal(file, ranges);
Expand All @@ -73,7 +73,7 @@ public void reformatText(PsiFile file, Collection<? extends TextRange> ranges)
}

@Override
public void reformatTextWithContext(PsiFile file, ChangedRangesInfo info)
public void reformatTextWithContext(@NotNull PsiFile file, @NotNull ChangedRangesInfo info)
throws IncorrectOperationException {
List<TextRange> ranges = new ArrayList<>();
if (info.insertedRanges != null) {
Expand All @@ -84,7 +84,8 @@ public void reformatTextWithContext(PsiFile file, ChangedRangesInfo info)
}

@Override
public void reformatTextWithContext(PsiFile file, Collection<? extends TextRange> ranges) {
public void reformatTextWithContext(
@NotNull PsiFile file, @NotNull Collection<? extends TextRange> ranges) {
if (overrideFormatterForFile(file)) {
formatInternal(file, ranges);
} else {
Expand All @@ -94,7 +95,10 @@ public void reformatTextWithContext(PsiFile file, Collection<? extends TextRange

@Override
public PsiElement reformatRange(
PsiElement element, int startOffset, int endOffset, boolean canChangeWhiteSpacesOnly) {
@NotNull PsiElement element,
int startOffset,
int endOffset,
boolean canChangeWhiteSpacesOnly) {
// Only handle elements that are PsiFile for now -- otherwise we need to search for some
// element within the file at new locations given the original startOffset and endOffsets
// to serve as the return value.
Expand All @@ -107,9 +111,9 @@ public PsiElement reformatRange(
}
}

/** Return whether or not this formatter can handle formatting the given file. */
/** Return whether this formatter can handle formatting the given file. */
private boolean overrideFormatterForFile(PsiFile file) {
return StdFileTypes.JAVA.equals(file.getFileType())
return JavaFileType.INSTANCE.equals(file.getFileType())
&& GoogleJavaFormatSettings.getInstance(getProject()).isEnabled();
}

Expand Down Expand Up @@ -137,7 +141,7 @@ private void formatInternal(PsiFile file, Collection<? extends TextRange> ranges
* Format the ranges of the given document.
*
* <p>Overriding methods will need to modify the document with the result of the external
* formatter (usually using {@link #performReplacements(Document, Map)}.
* formatter (usually using {@link #performReplacements(Document, Map)}).
*/
private void format(Document document, Collection<? extends TextRange> ranges) {
Style style = GoogleJavaFormatSettings.getInstance(getProject()).getStyle();
Expand Down