AndroidIDEOfficial / AndroidIDE

AndroidIDE is an IDE for Android to develop full featured Android apps.
https://m.androidide.com
GNU General Public License v3.0
2.37k stars 302 forks source link

[Bug]: Format Code is not working #1313

Closed ask9027 closed 1 year ago

ask9027 commented 1 year ago

What happened?

when i try to format code,BTW i am using latest build from github action 2.5.3-beta

What's the expected behavior?

Code format without any errro

What version of AndroidIDE you're using?

v2.5.2 (debug builds)

Relevant log output

Failed to format code. 
JavaCodeFormatProvider    E  com.google.googlejavaformat.java.FormatterException: 10:2: error: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/collect/Streams;
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.splitModifiers(JavaInputAstVisitor.java:3400)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitModifiers(JavaInputAstVisitor.java:2494)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitModifiers(JavaInputAstVisitor.java:2480)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.typeDeclarationModifiers(JavaInputAstVisitor.java:2469)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitClassDeclaration(JavaInputAstVisitor.java:2357)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitClass(JavaInputAstVisitor.java:566)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitClass(JavaInputAstVisitor.java:170)
JavaCodeFormatProvider    E     at openjdk.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:874)
JavaCodeFormatProvider    E     at openjdk.source.util.TreePathScanner.scan(TreePathScanner.java:86)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:2098)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitCompilationUnit(JavaInputAstVisitor.java:517)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitCompilationUnit(JavaInputAstVisitor.java:170)
JavaCodeFormatProvider    E     at openjdk.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:616)
JavaCodeFormatProvider    E     at openjdk.source.util.TreePathScanner.scan(TreePathScanner.java:86)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:2098)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.Formatter.format(Formatter.java:264)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:206)
JavaCodeFormatProvider    E     at com.itsaky.androidide.lsp.java.providers.CodeFormatProvider.format(CodeFormatProvider.java:76)
JavaCodeFormatProvider    E     at com.itsaky.androidide.lsp.java.JavaLanguageServer.formatCode(JavaLanguageServer.java:263)
JavaCodeFormatProvider    E     at com.itsaky.androidide.editor.language.LSPFormatter.doFormat(LSPFormatter.kt:66)
JavaCodeFormatProvider    E     at com.itsaky.androidide.editor.language.LSPFormatter.doFormat$default(LSPFormatter.kt:50)
JavaCodeFormatProvider    E     at com.itsaky.androidide.editor.language.LSPFormatter.formatAsync(LSPFormatter.kt:39)
JavaCodeFormatProvider    E     at io.github.rosemoe.sora.lang.format.AsyncFormatter$FormattingThread.run(AsyncFormatter.java:178)
JavaCodeFormatProvider    E  Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.common.collect.Streams" on path: DexPathList[[zip file "/data/app/~~D3Yf37AkIa-x67H4VKOzsg==/com.itsaky.androidide-FRb3za_QlT815_JLnFSKSA==/base.apk"],nativeLibraryDirectories=[/data/app/~~D3Yf37AkIa-x67H4VKOzsg==/com.itsaky.androidide-FRb3za_QlT815_JLnFSKSA==/lib/arm64, /data/app/~~D3Yf37AkIa-x67H4VKOzsg==/com.itsaky.androidide-FRb3za_QlT815_JLnFSKSA==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
JavaCodeFormatProvider    E     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
JavaCodeFormatProvider    E     at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
JavaCodeFormatProvider    E     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
JavaCodeFormatProvider    E     ... 23 more
JavaCodeFormatProvider    E  
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.splitModifiers(JavaInputAstVisitor.java:3400)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitModifiers(JavaInputAstVisitor.java:2494)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitModifiers(JavaInputAstVisitor.java:2480)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.typeDeclarationModifiers(JavaInputAstVisitor.java:2469)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitClassDeclaration(JavaInputAstVisitor.java:2357)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitClass(JavaInputAstVisitor.java:566)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitClass(JavaInputAstVisitor.java:170)
JavaCodeFormatProvider    E     at openjdk.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:874)
JavaCodeFormatProvider    E     at openjdk.source.util.TreePathScanner.scan(TreePathScanner.java:86)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:2098)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitCompilationUnit(JavaInputAstVisitor.java:517)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.visitCompilationUnit(JavaInputAstVisitor.java:170)
JavaCodeFormatProvider    E     at openjdk.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:616)
JavaCodeFormatProvider    E     at openjdk.source.util.TreePathScanner.scan(TreePathScanner.java:86)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.JavaInputAstVisitor.scan(JavaInputAstVisitor.java:2098)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.Formatter.format(Formatter.java:264)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:206)
JavaCodeFormatProvider    E     at com.itsaky.androidide.lsp.java.providers.CodeFormatProvider.format(CodeFormatProvider.java:76)
JavaCodeFormatProvider    E     at com.itsaky.androidide.lsp.java.JavaLanguageServer.formatCode(JavaLanguageServer.java:263)
JavaCodeFormatProvider    E     at com.itsaky.androidide.editor.language.LSPFormatter.doFormat(LSPFormatter.kt:66)
JavaCodeFormatProvider    E     at com.itsaky.androidide.editor.language.LSPFormatter.doFormat$default(LSPFormatter.kt:50)
JavaCodeFormatProvider    E     at com.itsaky.androidide.editor.language.LSPFormatter.formatAsync(LSPFormatter.kt:39)
JavaCodeFormatProvider    E     at io.github.rosemoe.sora.lang.format.AsyncFormatter$FormattingThread.run(AsyncFormatter.java:178)

Duplicate issues

Code of Conduct

sb-codz commented 1 year ago

IMG_20230929_151546.jpg

If the code is not formatted after writing the code, both the writing speed and the desire to write decrease together.

dr developer. Hope you will solve the problem of code format thinking about the users. Thank you.

ask9027 commented 1 year ago

IMG_20230929_151546.jpg

If the code is not formatted after writing the code, both the writing speed and the desire to write decrease together.

dr developer. Hope you will solve the problem of code format thinking about the users. Thank you.

then what is the use of Format Code?

sb-codz commented 1 year ago

1834

IMG_20230929_151546.jpg

If the code is not formatted after writing the code, both the writing speed and the desire to write decrease together.

dr developer. Hope you will solve the problem of code format thinking about the users. Thank you.

then what is the use of Format Code?

The "Format Code" feature in an integrated development environment (IDE) like AndroidIDE serves several important purposes:

  1. Code Consistency: It helps maintain a consistent coding style throughout your project. Consistent code formatting makes it easier for you and your team to read and understand the code.

  2. Readability: Properly formatted code is more readable, which can significantly improve code comprehension. It's easier to spot errors, identify logic, and navigate through the code when it's well-organized.

  3. Debugging: Cleanly formatted code can make debugging easier. When your code is properly structured, it's less likely to have hidden issues caused by formatting errors.

  4. Collaboration: In team projects, everyone might have their coding style preferences. Code formatting tools help bridge these differences by enforcing a common coding style, making collaboration smoother.

  5. Maintenance: Over time, code tends to change and evolve. Properly formatted code is easier to modify and maintain. It reduces the chances of introducing new bugs when making changes.

  6. Professionalism: Consistently well-formatted code reflects professionalism. It's a standard practice in software development and demonstrates a commitment to writing clean, maintainable code.

In summary, the "Format Code" feature ensures that your code is not only correct but also well-structured and easy to work with, which ultimately leads to more efficient and error-free development. 😁

ask9027 commented 1 year ago

IMG_20230929_151546.jpg If the code is not formatted after writing the code, both the writing speed and the desire to write decrease together. dr developer. Hope you will solve the problem of code format thinking about the users. Thank you.

then what is the use of Format Code?

The "Format Code" feature in an integrated development environment (IDE) like AndroidIDE serves several important purposes:

  1. Code Consistency: It helps maintain a consistent coding style throughout your project. Consistent code formatting makes it easier for you and your team to read and understand the code.
  2. Readability: Properly formatted code is more readable, which can significantly improve code comprehension. It's easier to spot errors, identify logic, and navigate through the code when it's well-organized.
  3. Debugging: Cleanly formatted code can make debugging easier. When your code is properly structured, it's less likely to have hidden issues caused by formatting errors.
  4. Collaboration: In team projects, everyone might have their coding style preferences. Code formatting tools help bridge these differences by enforcing a common coding style, making collaboration smoother.
  5. Maintenance: Over time, code tends to change and evolve. Properly formatted code is easier to modify and maintain. It reduces the chances of introducing new bugs when making changes.
  6. Professionalism: Consistently well-formatted code reflects professionalism. It's a standard practice in software development and demonstrates a commitment to writing clean, maintainable code.

In summary, the "Format Code" feature ensures that your code is not only correct but also well-structured and easy to work with, which ultimately leads to more efficient and error-free development. 😁

that why this report is here. While i just copy past some code then try to format code will not work , i need to fomat manually.

sb-codz commented 1 year ago

🤔 I don't understand how to format manually. I usually select all code and then click the format button to format.

ask9027 commented 1 year ago

🤔 I don't understand how to format manually. I usually select all code and then click the format button to format.

You are probably using released version

sb-codz commented 1 year ago

🤔 I don't understand how to format manually. I usually select all code and then click the format button to format.

You are probably using released version

No I am using currently this #1881 debug version.

ask9027 commented 1 year ago

Code formatter not working in latest build 58c3562

JavaCodeFormatProvider    E   Failed to format code. 
JavaCodeFormatProvider    E  java.lang.NoSuchMethodException: com.google.googlejavaformat.java.java17.Java17InputAstVisitor.<init> [class com.google.googlejavaformat.OpsBuilder, int]
JavaCodeFormatProvider    E     at java.lang.Class.getConstructor0(Class.java:2332)
JavaCodeFormatProvider    E     at java.lang.Class.getConstructor(Class.java:1728)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.Formatter.format(Unknown Source:167)
JavaCodeFormatProvider    E   Caused by: java.lang.LinkageError: com.google.googlejavaformat.java.java17.Java17InputAstVisitor.<init> [class com.google.googlejavaformat.OpsBuilder, int]
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.Formatter.format(Unknown Source:199)
JavaCodeFormatProvider    E     at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Unknown Source:420)
JavaCodeFormatProvider    E     at com.itsaky.androidide.lsp.java.JavaLanguageServer.formatCode(Unknown Source:133)
JavaCodeFormatProvider    E     at com.itsaky.androidide.editor.language.LSPFormatter.doFormat(Unknown Source:157)
JavaCodeFormatProvider    E     at com.blankj.utilcode.util.ThreadUtils$UtilsThreadFactory$1.run(Unknown Source:87)
itsaky commented 1 year ago

Fixed in v2.6.0-beta.