Java equivalent to #region in C#
문제
I want to use regions for code folding in Eclipse; how can that be done in Java?
An example usage in C#:
#region name
//code
#endregion
해결책
There's no such standard equivalent. Some IDEs - Intellij, for instance, or Eclipse - can fold depending on the code types involved (constructors, imports etc.), but there's nothing quite like #region
.
다른 팁
Jet Brains IDEA has this feature. You can use hotkey surround with for that (ctrl + alt + T). It's just IDEA feature.
Regions there look like this:
//region Description
Some code
//endregion
With Android Studio, try this:
//region VARIABLES
private String _sMyVar1;
private String _sMyVar2;
//endregion
Careful : no blank line after //region ...
And you will get:
No equivalent in the language... Based on IDEs...
For example in netbeans:
NetBeans/Creator supports this syntax:
// <editor-fold defaultstate="collapsed" desc="Your Fold Comment">
...
// </editor-fold>
For Eclipse IDE the Coffee-Bytes plugin can do it, download link is here.
EDIT:
동일한 목록에 대한 워크 플로를 트리거하고있는 것 같습니다.항목이 변경된 경우 워크 플로를 시작하고 워크 플로를 사용하여 동일한 목록 항목을 변경하려고합니다.그래서 그 오류를 반환합니다.
This is more of an IDE feature than a language feature. Netbeans allows you to define your own folding definitions using the following definition:
// <editor-fold defaultstate="collapsed" desc="user-description">
...any code...
// </editor-fold>
As noted in the article, this may be supported by other editors too, but there are no guarantees.
the fastest way in
Android Studio
(orIntelliJ IDEA
)
highlight the code
you want to surround it- press
ctrl
+alt
+t
- press
c
==> then enter the description - enjoy
AndroidStudio
region
Create region
First, find (and define short cut if need) for Surround With
menu
Then, select the code, press Ctrl+Alt+Semicolon
-> choose region..endregion...
Go to region
First, find Custom Folding
short cut
Second, from anywhere in your code, press Ctrl+Alt+Period('>' on keyboard)
이 페이지는 게시 사이트 나 공동 작업에서 사용되는 데 사용되는 것과 관련이 있지만 오히려 웹 응용 프로그램 수준에서 변경할 수있는 응용 프로그램 페이지입니다. - 자세히보기 http://geekswithblogs.net/jayantsharma/charive/2012/07/09/ How-to-change-system-application-pages.aspx (및 error.aspx 페이지에서 찾기 http://www.learningsharepoint.com/2013/06/17/replace-default-pagenotfoundError -aspx-with-custom-page-in-sharepoint-2013 / )
SharePoint 2013 관련 게시 사이트에서는 바꿀 수있는 오류 페이지에 연결된 새로운 콘텐츠 유형이 있습니다 ( https://www.nothingbutsharepoint.com/sites/devwiki/articles/pages/sharepoint-2013-custom-error-pages.aspx < / a>)
The best way
//region DESCRIPTION_REGION
int x = 22;
// Comments
String s = "SomeString";
//endregion;
Tip: Put ";" at the end of the "endregion"
하위 사이트 수준에서 게시 기능을 활성화하는 것과 같습니다.그러면 사이트 페이지 라이브러리가 생성됩니다.
사이트 작업> 사이트 설정> 사이트 기능 관리> 활성 "SharePoint Server Publishing"으로 이동하십시오.페이지 작성 옵션이 누락 된 하위 사이트 수준 에서이 작업을 수행해야합니다.
If anyone is interested, in Eclipse you can collapse all your methods etc in one go, just right click when you'd normally insert a break point, click 'Folding' > 'Collapse all'. It know it's not an answer to the question, but just providing an alternative to quick code folding.
#region
// code
#endregion
Really only gets you any benefit in the IDE. With Java, there's no set standard in IDE, so there's really no standard parallel to #region
.
I usually need this for commented code so I use curly brackets at start and end of that.
{
// Code
// Code
// Code
// Code
}
It could be used for code snippets but can create problems in some code because it changes the scope of variable.
Actually johann, the #
indicates that it's a preprocessor directive, which basically means it tells the IDE what to do.
In the case of using #region
and #endregion
in your code, it makes NO difference in the final code whether it's there or not. Can you really call it a language element if using it changes nothing?
Apart from that, java doesn't have preprocessor directives, which means the option of code folding is defined on a per-ide basis, in netbeans for example with a //< code-fold> statement
In Eclipse you can collapse the brackets wrapping variable region block. The closest is to do something like this:
public class counter_class
{
{ // Region
int variable = 0;
}
}
SharePoint는 자동으로 꺼진 경고 및 워크 플로의 링크에 대한 기본 URL을 사용합니다.경고와 관련하여 기본 영역의 URL을 변경하는 것입니다.이것은 CMDlet Set-SpalTernateURL 또는 (내 환경 설정) 웹 응용 프로그램을 삭제하고 새 URL을 사용하기 위해 새 웹 응용 프로그램을 만드는 새 응용 프로그램을 사용하여 AAM이있는 CA에서 수행 할 수 있습니다.선택한 옵션은 웹 응용 프로그램과 해당 인증 공급자에게 수행 한 구성의 양에 따라 다릅니다.처음 두 가지 옵션이 사용자를 위해 작동 할 수 있지만 웹 앱이 생성 된 후에 수행 한 구성의 양에 따라 실제로 의존합니다.아무 것도 없을 것으로 확신 할 수있는 유일한 방법은 웹 응용 프로그램을 재현하는 것입니다.
TechNet 문서는 이전 환경의 URL을 사용하는 이주 된 웹 앱에 대한 것입니다.
There is some option to achieve the same, Follow the below points.
1) Open Macro explorer:
2) Create new macro:
3) Name it "OutlineRegions" (Or whatever you want)
4) Right Click on the "OutlineRegions" (Showing on Macro Explorer) select the "Edit" option and paste the following VB code into it:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Collections
Public Module OutlineRegions
Sub OutlineRegions()
Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
Const REGION_START As String = "//#region"
Const REGION_END As String = "//#endregion"
selection.SelectAll()
Dim text As String = selection.Text
selection.StartOfDocument(True)
Dim startIndex As Integer
Dim endIndex As Integer
Dim lastIndex As Integer = 0
Dim startRegions As Stack = New Stack()
Do
startIndex = text.IndexOf(REGION_START, lastIndex)
endIndex = text.IndexOf(REGION_END, lastIndex)
If startIndex = -1 AndAlso endIndex = -1 Then
Exit Do
End If
If startIndex <> -1 AndAlso startIndex < endIndex Then
startRegions.Push(startIndex)
lastIndex = startIndex + 1
Else
' Outline region ...
selection.MoveToLineAndOffset(CalcLineNumber(text, CInt(startRegions.Pop())), 1)
selection.MoveToLineAndOffset(CalcLineNumber(text, endIndex) + 1, 1, True)
selection.OutlineSection()
lastIndex = endIndex + 1
End If
Loop
selection.StartOfDocument()
End Sub
Private Function CalcLineNumber(ByVal text As String, ByVal index As Integer)
Dim lineNumber As Integer = 1
Dim i As Integer = 0
While i < index
If text.Chars(i) = vbCr Then
lineNumber += 1
i += 1
End If
i += 1
End While
Return lineNumber
End Function
End Module
5) Save the macro and close the editor.
6) Now let's assign shortcut to the macro. Go to Tools->Options->Environment->Keyboard and search for your macro in "show commands containing" textbox (Type: Macro into the text box, it will suggest the macros name, choose yours one.)
7) now in textbox under the "Press shortcut keys" you can enter the desired shortcut. I use Ctrl+M+N.
Use:
return
{
//Properties
//#region
Name:null,
Address:null
//#endregion
}
8) Press the saved shortcut key
See below result: