Editor Indentation
Under Development
Overview of Editor Indentation module
Editor Indentation module defines
EditorIndentationAPI
providing indentation and reformatting services to the clients.
It also contains SPI allowing the modules to register language-specific
indenters and formatters into
MimeLookup
through XML layers.
What is New (see all changes)?
- Jun 16 '19 Indent can be given as a string Added method org.netbeans.modules.editor.indent.spi.Context.modifyIndent(int, int, String), which allows to set indent by specifying particular indent string.
- Sep 2 '14 Indentation Support module created Implementation of indentation which depends on typing hooks moved to a separate module, see its javadoc for more info.
- Dec 3 '10 Adding org.netbeans.modules.editor.indent.api.IndentUtils.createIndentString Method IndentUtils.createIndentString(int indent, boolean expandTabs, int tabSize) added.
-
Feb 17 '10 Adding CodeStylePreferences.Provider
Adding
CodeStylePreferences.Provider
interface in order to allow isolating the project-dependent code style preferences storage from the rest of the editor infrastructure. - Mar 3 '09 Enhance Context class with Lookup so that indenters can communicate with each other. Let IndentTask and/or ReformatTask implement Lookup.Provider and before executing indentation/reformat call these providers and provide merged result via getLookup() method in Context. Individual formatters check lookup for presence of other formatters and communicate with them via domain specific APIs.
Use Cases
API Usecases
Fix indentation of a single or multiple lines of a document.
Altghough there are formatting actions already there may be clients wishing to explicitly fix indentation of e.g. a newly inserted code into a Swing document.
The same code is used after inserting a newline into a document.
The Indent is an entry point for performing reindentation. The following code should be used by clients:Indent indent = Indent.get(doc); indent.lock(); try { doc.atomicLock(); try { indent.reindent(startOffset, endOffset); } finally { doc.atomicUnlock(); } } finally { indent.unlock(); }
Code beautification of a selected area of a document.
Code beautification should not only fix line indentation but it may also perform extra changes to code according to formatting rules. For example add newlines or additional whitespace or add/remove extra braces etc.
The Reformat class should be used:Reformat reformat = Reformat.get(doc); reformat.lock(); try { doc.atomicLock(); try { reformat.reformat(startOffset, endOffset); } finally { doc.atomicUnlock(); } } finally { reformat.unlock(); }
Exported Interfaces
This table lists all of the module exported APIs with defined stability classifications. It is generated based on answers to questions about the architecture of the module. Read them all...Group of java interfaces
Interface Name | In/Out | Stability | Specified in What Document? |
---|---|---|---|
EditorIndentationAPI | Exported | Under Development |
Implementation Details
Where are the sources for the module?
The sources for the module are in the Apache Git repositories or in the GitHub repositories
What do other modules need to do to declare a dependency on this one, in addition to or instead of a plain module dependency?
Nothing.
Read more about the implementation in the answers to architecture questions.