intellij-idea - Android Studio/IntelliJ 匿名类格式化

标签 intellij-idea android-studio code-formatting anonymous-class

我想知道是否有可能更改 Android Studio 中的自动格式设置,将匿名类的大括号放在同一行,同时将常规类、方法和块的大括号放在新行上。

目前,IntelliJ 给了我这个结果:

class TestClass
{
    public void test()
    {
        FooBar foo = new FooBar(new Runnable() // I want the brace here...
        { // ...not here.
            @Override
            public void run()
            {
                //
            }
        });
    }
}

但是,我希望代码的格式如下:

class TestClass
{
    public void test()
    {
        FooBar foo = new FooBar(new Runnable() { // <- Same Line
            @Override
            public void run()
            {
                //
            }
        });
    }
}

一切都很好,除了我无法像第二个示例中那样格式化大括号的一个细节。这是不可能的还是我只是忽略了设置?

最佳答案

我现在也想要这个很长时间了,但不幸的是它在 Intellij 中是不可能的。

最接近的是将 Wrapping 和 Braces/Braces Placement/In 类声明设置为“下一行如果已包装”或“行尾”(我使用的)。这当然会修改大括号的包装方式,不仅适用于匿名内部类(所需的结果),还适用于顶级和内部类;但是,methods/if/else/for/while/do-while/try/catch/finally/switch 等不受影响。

我真的希望 IntelliJ 能像 Eclipse 一样添加一个环绕和大括号/大括号放置/匿名类声明选项。

关于intellij-idea - Android Studio/IntelliJ 匿名类格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21346090/

相关文章:

intellij-idea - 如何让 Jetbrains IDE 的嵌入式终端将 ALT/Option 识别为 Meta 键?

Android 代码检查 : Implement custom inspection

regex - 代码格式 - 减轻不可读的大正则表达式的方法?

perl - 将Perl代码分成两行的正确方法是什么?

python - 使用方法调用在 Python 中格式化多行

java - 无法配置 IntelliJ Idea 使用 @Immutables 注释

java - 无法从中读取 VR 路径注册表

android - 数据库搜索只返回 1 个搜索结果

android - 为 android studio 编写 SOAP API

android - 错误 :Execution failed for task ':app:transformClassesWithDexForDebug' . > com.android.build.api.transform.TransformException :. .非零退出值 3