Skip to content

Commit

Permalink
Ditch the sdkcompat messiness. This CodeStyleManagerDecorator works o…
Browse files Browse the repository at this point in the history
…n v171+.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183002514
  • Loading branch information
plumpy authored and ronshapiro committed Jan 24, 2018
1 parent 01d2ffa commit 128ee6e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 173 deletions.
64 changes: 31 additions & 33 deletions idea_plugin/build.gradle
Expand Up @@ -24,45 +24,43 @@ task showProps {
}
}

subprojects {
repositories {
mavenCentral()
}
repositories {
mavenCentral()
}

ext {
googleJavaFormatVersion = '1.5'
}
ext {
googleJavaFormatVersion = '1.5'
}

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

intellij {
pluginName = "google-java-format"
updateSinceUntilBuild = true
sameSinceUntilBuild = true
}
intellij {
pluginName = "google-java-format"
updateSinceUntilBuild = true
sameSinceUntilBuild = true
version = "2017.3.3"
}

patchPluginXml {
pluginDescription = "Formats source code using the google-java-format tool. This version of " +
"the plugin uses version ${googleJavaFormatVersion} of the tool." + googleJavaFormatVersion
}
patchPluginXml {
pluginDescription = "Formats source code using the google-java-format tool. This version of " +
"the plugin uses version ${googleJavaFormatVersion} of the tool." + googleJavaFormatVersion
version = "${googleJavaFormatVersion}.1.171"
sinceBuild = '171'
}

publishPlugin {
username = project.ext.properties.jetbrainsPluginRepoUsername
password = project.ext.properties.jetbrainsPluginRepoPassword
}
publishPlugin {
username = project.ext.properties.jetbrainsPluginRepoUsername
password = project.ext.properties.jetbrainsPluginRepoPassword
}

sourceSets {
main {
java.srcDir '../src'
resources.srcDir '../resources'
}
test {
java.srcDir 'test'
}
sourceSets {
main {
java.srcDir 'src'
resources.srcDir 'resources'
}
}

dependencies {
compile "com.google.googlejavaformat:google-java-format:${googleJavaFormatVersion}"
}
dependencies {
compile "com.google.googlejavaformat:google-java-format:${googleJavaFormatVersion}"
}
1 change: 0 additions & 1 deletion idea_plugin/settings.gradle

This file was deleted.

Expand Up @@ -16,6 +16,7 @@

package com.google.googlejavaformat.intellij;

import com.intellij.formatting.FormattingMode;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileTypes.FileType;
Expand All @@ -26,6 +27,8 @@
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.ChangedRangesInfo;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.DocCommentSettings;
import com.intellij.psi.codeStyle.FormattingModeAwareIndentAdjuster;
import com.intellij.psi.codeStyle.Indent;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ThrowableRunnable;
Expand All @@ -39,7 +42,9 @@
* @author bcsf@google.com (Brian Chang)
*/
@SuppressWarnings("deprecation")
class CodeStyleManagerDecorator extends CodeStyleManager {
class CodeStyleManagerDecorator extends CodeStyleManager
implements FormattingModeAwareIndentAdjuster {

private final CodeStyleManager delegate;

CodeStyleManagerDecorator(CodeStyleManager delegate) {
Expand Down Expand Up @@ -173,4 +178,43 @@ public <T extends Throwable> void performActionWithFormatterDisabled(ThrowableRu
public <T> T performActionWithFormatterDisabled(Computable<T> r) {
return delegate.performActionWithFormatterDisabled(r);
}

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

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

/** Uses same fallback as {@link CodeStyleManager#getCurrentFormattingMode}. */
@Override
public FormattingMode getCurrentFormattingMode() {
if (delegate instanceof FormattingModeAwareIndentAdjuster) {
return ((FormattingModeAwareIndentAdjuster) delegate).getCurrentFormattingMode();
}
return FormattingMode.REFORMAT;
}

@Override
public int adjustLineIndent(final Document document, final int offset, FormattingMode mode)
throws IncorrectOperationException {
if (delegate instanceof FormattingModeAwareIndentAdjuster) {
return ((FormattingModeAwareIndentAdjuster) delegate)
.adjustLineIndent(document, offset, mode);
}
return offset;
}

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

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

This file was deleted.

30 changes: 0 additions & 30 deletions idea_plugin/v163/build.gradle

This file was deleted.

0 comments on commit 128ee6e

Please sign in to comment.