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

Allow google-format version specification for removeUnusedImports #23

Open
weisJ opened this issue Oct 15, 2020 · 0 comments
Open

Allow google-format version specification for removeUnusedImports #23

weisJ opened this issue Oct 15, 2020 · 0 comments

Comments

@weisJ
Copy link
Contributor

weisJ commented Oct 15, 2020

When using removeUnusedImports() with Jdk 14 autostyleApply fails when using the new switch-expression syntax.
This is because the default version of google-java-format does not support the new syntax.
It would be great if either

  • the default version could be updated
  • or there was an option to specify the default version in this case oneself.

Example to reproduce:

public class SwitchSyntax {

    public static void main(String[] args) {
        int i = 0;
        int j = switch(i) {
            case 1 -> 2;
            case 2 -> 3;
            default -> 4;
        };
    }
}

results in

    Execution failed for task ':autostyleJavaApply':
        com.github.autostyle.FormatterException: Error while formatting src\main\java\SwitchSyntax.java: 5:18: error: illegal start of expression
            at com.github.autostyle.Formatter.compute(Formatter.java:226)
            at com.github.autostyle.Formatter.applyToAndReturnResultIfDirty(Formatter.java:177)
            at com.github.autostyle.gradle.AutostyleApplyTask.applyFormat(AutostyleApplyTask.kt:116)
            at com.github.autostyle.gradle.AutostyleApplyTask.performAction(AutostyleApplyTask.kt:88)
            at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
            at org.gradle.api.internal.project.taskfactory.IncrementalInputsTaskAction.doExecute(IncrementalInputsTaskAction.java:32)
            at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
            at org.gradle.api.internal.project.taskfactory.AbstractIncrementalTaskAction.execute(AbstractIncrementalTaskAction.java:25)
            at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.run(ExecuteActionsTaskExecuter.java:570)
            at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:395)
            at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:387)
            at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157)
            at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242)
            at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150)
            at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:84)
            at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:555)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:538)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$300(ExecuteActionsTaskExecuter.java:109)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.executeWithPreviousOutputFiles(ExecuteActionsTaskExecuter.java:279)
            at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:268)
            at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$0(ExecuteStep.java:32)
            at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:32)
            at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
            at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:67)
            at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:36)
            at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:49)
            at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:34)
            at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:43)
            at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
            at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
            at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:34)
            at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:44)
            at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:54)
            at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:38)
            at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
            at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:159)
            at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:72)
            at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:43)
            at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:44)
            at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:33)
            at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
            at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
            at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:92)
            at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:85)
            at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:55)
            at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:39)
            at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:76)
            at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
            at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
            at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
            at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:94)
            at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:49)
            at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:79)
            at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:53)
            at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:74)
            at org.gradle.internal.execution.steps.SkipEmptyWorkStep.lambda$execute$2(SkipEmptyWorkStep.java:78)
            at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:78)
            at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:34)
            at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:39)
            at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:40)
            at org.gradle.internal.execution.steps.LoadExecutionStateStep.execute(LoadExecutionStateStep.java:28)
            Caused by: com.google.googlejavaformat.java.FormatterException: 5:18: error: illegal start of expression
                at com.google.googlejavaformat.java.FormatterException.fromJavacDiagnostics(FormatterException.java:50)
            Caused by: com.google.googlejavaformat.java.FormatterException: 5:18: error: illegal start of expression

                at com.google.googlejavaformat.java.RemoveUnusedImports.parse(RemoveUnusedImports.java:253)
                at com.google.googlejavaformat.java.RemoveUnusedImports.removeUnusedImports(RemoveUnusedImports.java:211)
                at com.google.googlejavaformat.java.RemoveUnusedImports.removeUnusedImports(RemoveUnusedImports.java:204)
                at com.github.autostyle.java.GoogleJavaFormatStep$State.lambda$createRemoveUnusedImportsOnly$1(GoogleJavaFormatStep.java:156)
                at com.github.autostyle.FormatterFunc.apply(FormatterFunc.java:31)
                at com.github.autostyle.FormatterStepImpl$Standard.format(FormatterStepImpl.java:77)
                at com.github.autostyle.FormatterStep$Strict.format(FormatterStep.java:76)
                at com.github.autostyle.Formatter.compute(Formatter.java:215)
                ... 62 more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant