在折叠匿名类时,IntelliJ IDEA是否显示方法体? [英] Does IntelliJ IDEA reveal the method body when folding anonymous classes?

查看:355
本文介绍了在折叠匿名类时,IntelliJ IDEA是否显示方法体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于IntelliJ的文档,在折叠匿名类时,您仍应该能够看到内部方法的内容。请参阅以下图片:

Based on IntelliJ's documentation, when folding an anonymous class you should still be able to see the contents of the inner method. See image below taken from their documentation:

这不是我看到的行为。以下是我看到的内容:

This isn't the behavior I'm seeing though. Here is what I see:

我似乎只能折叠内部方法内容或整个匿名类主体。这只是他们的文档中的错误还是有办法实际实现这种行为?

I can only seem to collapse the inner method contents or the entire anonymous class body. Is this just an error in their documentation or is there a way to actually achieve this behavior?

======= 更新 = ========

======= UPDATE =========

我接受了彼得格罗莫夫的回答,但我的版本似乎仍然有些不对劲。当我打开文件并默认设置折叠闭包时(文件 - >设置 - >编辑器 - >代码折叠 - >选择'默认折叠'下的'闭包'),它似乎正确折叠,如下图所示:

I've accepted the answer from Peter Gromov, but there still seems to be something amiss with my version. When I have files open and set folding closures by default (File -> Settings -> Editor -> Code Folding -> Select 'Closures' under 'Collapse by default:'), it does seem to fold correctly as seen in the following image:

请注意,展开的因子在边距中显示单个可折叠区域。关闭文件并重新打开会产生以下内容(在我折叠第一个文件后):

Notice that the expanded Because shows a single collapsible region in the margin. Closing the file and reopening produces the following (after I collapse the first one):

首次打开文件时,这两个语句都会被扩展(问题#1)。在折叠第一个语句的最外层区域之后,它会折叠整个匿名类(问题#2),而不是在关闭文件之前它的工作方式。另请注意,我打开的第二个语句对于匿名类的方法(问题#3)有一个额外的可折叠区域。这是关闭时默认折叠设置的行为方式。这里肯定有一些错误。自从我发布了这个问题以来,已经发布了一个新版本,所以问题可能只出现在我的版本(10.0.3),但据我所知,这是一个相当古老的功能。我欢迎任何解释,为什么我可能会看到这些问题(包括在我的机器上工作)。

When first opening the file, both of these statements are expanded (issue #1). After collapsing the outer most region for the first statement, it folds over the entire anonymous class (issue #2) rather than how it worked before I closed the file. Notice also that the second statement that I've left open has an additional collapsible region for the method of the anonymous class (issue #3). This is how it behaves with the default folding settings for closures are turned off. There's definitely something buggy here. Since I've posted this question, there has been a new version released so perhaps the issue is only with the version I have (10.0.3), but as far as I know this is a fairly old feature. I'd welcome any explanation as to why I might be seeing these issues (including "Works on my machine").

推荐答案

你想要的是'封闭折叠',可以在代码折叠设置中打开。

What you want is called 'Closure folding' and can be turned on in the Code Folding settings.

这篇关于在折叠匿名类时,IntelliJ IDEA是否显示方法体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆