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

Erroneous formatting with Google #137

Closed
cbm64chris opened this issue Sep 9, 2020 · 12 comments
Closed

Erroneous formatting with Google #137

cbm64chris opened this issue Sep 9, 2020 · 12 comments
Assignees
Labels
Milestone

Comments

@cbm64chris
Copy link

cbm64chris commented Sep 9, 2020

Using the Google format, I am seeing some odd behaviour when hitting enter to autocomplete. Turing back to the NetBeans, auto complete working fine. 1.14.0 installed from the plugins repo on NetBeans 12.1.

ExternalFormatter

@funfried
Copy link
Owner

Sorry for the late response and thanks for reporting the issue!
I'll have a look at this as soon as possible.

@funfried funfried self-assigned this Sep 16, 2020
@funfried funfried added this to the 1.14.1 milestone Sep 16, 2020
@funfried funfried added the bug label Sep 16, 2020
@moacirrf
Copy link

I have issues like that when i have blank lines before package declaration.

@rkraneis
Copy link

rkraneis commented Jan 4, 2021

I have issues like that when i have blank lines before package declaration.

I can confirm this problem does appear when there are blank lines before the package declaration. The more blank lines there are, the further up above the cursor code get overridden.

What I also see quite often (independently from the other issue) is that if I try auto complete inside a chain of method calls, that the cursor does not highlight the method arguments (as it does when adding to such a chain, so that I can immediately override them with something useful) but jumps to the next line. This seems to be cause by the code formatter being triggered upon selecting the auto completion when inside such a chain. At the end of a chain no auto formatting happens when selecting the proposed auto complete value.

@moacirrf
Copy link

moacirrf commented Jan 5, 2021

I am using branch release/1.14.x, everything is fine.
Thanks @funfried

@funfried
Copy link
Owner

funfried commented Jan 8, 2021

I saw this issue in the meantime with the Eclipse formatter myself, but I wasn't able to securely reproduce the issue yet. I'm still investigating, if you have any ideas how to fix it, please let me know.

funfried added a commit that referenced this issue Jan 13, 2021
Updated to newest formatter versions
@funfried
Copy link
Owner

funfried commented Jan 14, 2021

I've updated all formatter dependencies to the newest versions and tried to reproduce this issue and I wasn't really able to reproduce this exact issue, but I saw weird behaviour if the formatting of the file didn't match the formatter which was configured and I was writing new code to the file, especially fluent API code like the one in the video above, but as soon as the formatting of the file did match the configured formatting everything was fine.

@cbm64chris and @rkraneis could you please try the latest SNAPSHOT version (1.14.1-SNAPSHOT) and see if that version acts better as the current main release? Thanks in advance

EDIT: Sorry, I guess you have to wait until everything is merged and all the pipelines ran. I try to merge as soon as possible and write another comment when the SNAPSHOT release will be ready

@cbm64chris
Copy link
Author

@funfried built with zulu11 with NetBeans 12.2 target running on zulu15. Installs fine - will let you know how it goes over the next few days.

@rkraneis
Copy link

Same here (but s/zulu/adopt/ :trollface:).

@funfried
Copy link
Owner

@cbm64chris and @rkraneis I finally got my release pipeline back to work again and so you can download the latest SNAPSHOT from either GitHub Packages or from Maven Central.

@moacirrf
Copy link

moacirrf commented Apr 4, 2021

With google formatter, Netbeans 12.3, Adopt JDK 16.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.mypackage;

/**
 *
 * @author Moacir da Roza Flores <moacirrf@gmail.com>
 */
public class DossieXmlBuilderTest {

  public DossieXmlBuilderTest() {
  }
}

I receive an exception in Google Formatter


java.lang.NoSuchFieldError: reader
	at com.google.googlejavaformat.java.JavacTokens$CommentSavingTokenizer.processComment(JavacTokens.java:131)
	at jdk.compiler/com.sun.tools.javac.parser.JavaTokenizer.readToken(JavaTokenizer.java:949)
	at jdk.compiler/com.sun.tools.javac.parser.Scanner.nextToken(Scanner.java:115)
	at com.google.googlejavaformat.java.JavacTokens.getTokens(JavacTokens.java:88)
	at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:364)
	at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:334)
	at com.google.googlejavaformat.java.JavaInput.<init>(JavaInput.java:276)
	at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:280)
	at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:267)
	at de.funfried.netbeans.plugins.external.formatter.java.google.GoogleJavaFormatterWrapper.format(GoogleJavaFormatterWrapper.java:85)
	at de.funfried.netbeans.plugins.external.formatter.java.google.GoogleFormatJob.format(GoogleFormatJob.java:67)
	at de.funfried.netbeans.plugins.external.formatter.java.base.AbstractJavaFormatterService.format(AbstractJavaFormatterService.java:47)
	at de.funfried.netbeans.plugins.external.formatter.FormatterServiceDelegate.format(FormatterServiceDelegate.java:94)
	at de.funfried.netbeans.plugins.external.formatter.ui.editor.ExternalFormatterReformatTaskFactory$2.reformat(ExternalFormatterReformatTaskFactory.java:93)
	at org.netbeans.modules.editor.indent.TaskHandler$MimeItem.runTask(TaskHandler.java:550)
	at org.netbeans.modules.editor.indent.TaskHandler.runTasks(TaskHandler.java:309)
	at org.netbeans.modules.editor.indent.IndentImpl.reformat(IndentImpl.java:349)
	at org.netbeans.modules.editor.indent.api.Reformat.reformat(Reformat.java:129)
	at org.netbeans.modules.editor.impl.ReformatBeforeSaveTask.reformat(ReformatBeforeSaveTask.java:245)
	at org.netbeans.modules.editor.impl.ReformatBeforeSaveTask.performTask(ReformatBeforeSaveTask.java:80)
	at org.netbeans.modules.editor.lib.BeforeSaveTasks$TaskRunnable$1.run(BeforeSaveTasks.java:148)
	at org.netbeans.editor.GuardedDocument.runAtomicAsUser(GuardedDocument.java:333)
	at org.netbeans.modules.editor.lib.BeforeSaveTasks$TaskRunnable.run(BeforeSaveTasks.java:131)
	at org.netbeans.modules.editor.lib.TrailingWhitespaceRemove.runLocked(TrailingWhitespaceRemove.java:77)
	at org.netbeans.modules.editor.lib.BeforeSaveTasks$TaskRunnable.run(BeforeSaveTasks.java:128)
	at org.netbeans.modules.editor.impl.ReformatBeforeSaveTask.runLocked(ReformatBeforeSaveTask.java:96)
	at org.netbeans.modules.editor.lib.BeforeSaveTasks$TaskRunnable.run(BeforeSaveTasks.java:128)
	at org.netbeans.modules.java.hints.onsave.RemoveUnusedAfterSave$1.run(RemoveUnusedAfterSave.java:98)
	at org.netbeans.modules.java.hints.onsave.RemoveUnusedAfterSave$1.run(RemoveUnusedAfterSave.java:96)
	at org.netbeans.api.java.source.JavaSource$MultiTask.run(JavaSource.java:502)
	at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:586)
	at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:130)
	at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:114)
	at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:181)
	at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:178)
	at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:153)
	at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:335)
	at org.netbeans.modules.parsing.nb.DataObjectEnvFactory.runPriorityIO(DataObjectEnvFactory.java:118)
	at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:67)
	at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:178)
	at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:81)
	at org.netbeans.api.java.source.JavaSource.runUserActionTaskImpl(JavaSource.java:452)
	at org.netbeans.api.java.source.JavaSource.runUserActionTask(JavaSource.java:423)
	at org.netbeans.modules.java.hints.onsave.RemoveUnusedAfterSave.runLocked(RemoveUnusedAfterSave.java:96)
	at org.netbeans.modules.editor.lib.BeforeSaveTasks$TaskRunnable.run(BeforeSaveTasks.java:128)
	at org.netbeans.modules.editor.lib.BeforeSaveTasks.runTasks(BeforeSaveTasks.java:105)
	at org.netbeans.modules.editor.lib.BeforeSaveTasks$2.run(BeforeSaveTasks.java:86)
	at org.openide.text.CloneableEditorSupport.saveDocumentImpl(CloneableEditorSupport.java:728)
	at org.openide.text.CloneableEditorSupport.saveDocument(CloneableEditorSupport.java:619)
	at org.openide.text.DataEditorSupport.superSaveDoc(DataEditorSupport.java:572)
	at org.openide.text.DataEditorSupport$SaveImpl.run(DataEditorSupport.java:1332)
	at org.openide.filesystems.EventControl.runAtomicAction(EventControl.java:102)
	at org.openide.filesystems.FileSystem.runAtomicAction(FileSystem.java:494)
	at org.openide.filesystems.FileUtil.runAtomicAction(FileUtil.java:397)
	at org.openide.text.DataEditorSupport.saveDocument(DataEditorSupport.java:568)
	at org.netbeans.modules.openide.loaders.SimpleES$SaveCookieImpl.save(SimpleES.java:202)
	at org.openide.actions.SaveAction.performAction(SaveAction.java:107)
	at org.openide.actions.SaveAction.performAction(SaveAction.java:77)
	at org.openide.actions.SaveAction$Delegate.actionPerformed(SaveAction.java:224)
	at org.openide.awt.ContextAction$Performer.actionPerformed(ContextAction.java:446)
	at org.openide.awt.ContextManager.actionPerformed(ContextManager.java:263)
	at org.openide.awt.ContextAction.actionPerformed(ContextAction.java:106)
	at org.openide.util.actions.ActionInvoker$1.run(ActionInvoker.java:68)
	at org.openide.util.actions.ActionInvoker$ActionRunnable.actionPerformed(ActionInvoker.java:137)
	at org.netbeans.core.ModuleActions.invokeAction(ModuleActions.java:84)
	at org.netbeans.modules.openide.actions.ActionsBridgeImpl.invokeAction(ActionsBridgeImpl.java:35)
	at org.openide.util.actions.ActionInvoker$ActionRunnable.doRun(ActionInvoker.java:128)
	at org.openide.util.actions.ActionInvoker$2.run(ActionInvoker.java:85)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
	at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
	at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
[catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)

The comments and the javadoc is the problem, is a problem with google formatter, https://github.com/google/google-java-format/issues/538

To fix i updated google java formatter to 1.10.0
<google-java-format.version>1.10.0</google-java-format.version>

And comment google-guava exclusion.

<!--			<exclusions>
				<exclusion>
					<groupId>com.google.guava</groupId>
					<artifactId>guava</artifactId>
				</exclusion>
			</exclusions>-->

@funfried
Copy link
Owner

funfried commented Apr 5, 2021

@moacirrf Thanks for the hint, I'll check within the next days and push another SNAPSHOT release

@funfried
Copy link
Owner

I updated to the latest Google formatter version and it seems the exclusion is not necessary anymore, actually it breaks the formatter when I keep the exclusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants