public abstract class CodeStyleManager
extends java.lang.Object
PreFormatProcessor
,
PostFormatProcessor
Constructor and Description |
---|
CodeStyleManager() |
Modifier and Type | Method and Description |
---|---|
abstract int |
adjustLineIndent(Document document,
int offset)
Reformats the line at the specified offset in the specified file, modifying only the line indent
and leaving all other whitespace intact.
|
abstract int |
adjustLineIndent(PsiFile file,
int offset)
Reformats the line at the specified offset in the specified file, modifying only the line indent
and leaving all other whitespace intact.
|
abstract void |
adjustLineIndent(PsiFile file,
TextRange rangeToAdjust)
Re-formats the specified range of a file, modifying only line indents and leaving
all other whitespace intact.
|
abstract java.lang.String |
fillIndent(Indent indent,
FileType fileType)
Deprecated.
obsolete
|
static FormattingMode |
getCurrentFormattingMode(Project project)
Retrieves the current formatting mode.
|
DocCommentSettings |
getDocCommentSettings(PsiFile file) |
abstract Indent |
getIndent(java.lang.String text,
FileType fileType)
Deprecated.
obsolete
|
static CodeStyleManager |
getInstance(Project project)
Returns the code style manager for the specified project.
|
static CodeStyleManager |
getInstance(PsiManager manager)
Returns the code style manager for the project associated with the specified
PSI manager.
|
abstract java.lang.String |
getLineIndent(Document document,
int offset)
Calculates the indent that should be used for the current line in the specified
editor.
|
abstract java.lang.String |
getLineIndent(PsiFile file,
int offset)
Calculates the indent that should be used for the specified line in
the specified file.
|
java.lang.String |
getLineIndent(PsiFile file,
int offset,
FormattingMode mode)
Calculates the indent that should be used for the specified line in
the specified file with the given formatting mode.
|
int |
getMinLineFeeds(PsiFile file,
int offset)
Calculates minimum number of line feeds that should precede block starting at given offset, as dictated by formatting model.
|
abstract Project |
getProject()
Gets the project with which the code style manager is associated.
|
int |
getSpacing(PsiFile file,
int offset)
Calculates minimum spacing, allowed by formatting model (in columns) for a block starting at given offset,
relative to its previous sibling block.
|
abstract boolean |
isLineToBeIndented(PsiFile file,
int offset)
Deprecated.
this method is not intended to be used by plugins.
|
abstract boolean |
isSequentialProcessingAllowed()
Formatting may be executed sequentially, i.e.
|
abstract <T> T |
performActionWithFormatterDisabled(Computable<T> r) |
abstract void |
performActionWithFormatterDisabled(java.lang.Runnable r)
Disables automatic formatting of modified PSI elements, runs the specified operation
and re-enables the formatting.
|
abstract <T extends java.lang.Throwable> |
performActionWithFormatterDisabled(ThrowableRunnable<T> r) |
abstract PsiElement |
reformat(PsiElement element)
Reformats the contents of the specified PSI element, enforces braces and splits import
statements according to the user's code style.
|
abstract PsiElement |
reformat(PsiElement element,
boolean canChangeWhiteSpacesOnly)
Reformats the contents of the specified PSI element, and optionally enforces braces
and splits import statements according to the user's code style.
|
abstract void |
reformatNewlyAddedElement(ASTNode block,
ASTNode addedElement)
Reformats line indents inside new element and reformats white spaces around it
|
abstract PsiElement |
reformatRange(PsiElement element,
int startOffset,
int endOffset)
Reformats part of the contents of the specified PSI element, enforces braces
and splits import statements according to the user's code style.
|
abstract PsiElement |
reformatRange(PsiElement element,
int startOffset,
int endOffset,
boolean canChangeWhiteSpacesOnly)
Reformats part of the contents of the specified PSI element, and optionally enforces braces
and splits import statements according to the user's code style.
|
abstract void |
reformatText(PsiFile file,
java.util.Collection<TextRange> ranges)
Re-formats a ranges of text in the specified file.
|
abstract void |
reformatText(PsiFile file,
int startOffset,
int endOffset)
Delegates to the
reformatText(PsiFile, Collection) with the single range defined by the given offsets. |
abstract void |
reformatTextWithContext(PsiFile file,
ChangedRangesInfo info) |
void |
reformatTextWithContext(PsiFile file,
java.util.Collection<TextRange> ranges) |
void |
runWithDocCommentFormattingDisabled(PsiFile file,
java.lang.Runnable runnable)
Run the given runnable disabling doc comment formatting.
|
void |
scheduleIndentAdjustment(Document document,
int offset)
Performs a delayed indent adjustment for large documents bigger than
FormatterBasedIndentAdjuster.MAX_SYNCHRONOUS_ADJUSTMENT_DOC_SIZE
by scheduling it to a time when the document is committed. |
abstract Indent |
zeroIndent()
Deprecated.
obsolete
|
public static CodeStyleManager getInstance(Project project)
project
- the project to get the code style manager for.public static CodeStyleManager getInstance(PsiManager manager)
manager
- the PSI manager to get the code style manager for.public abstract Project getProject()
public abstract PsiElement reformat(PsiElement element) throws IncorrectOperationException
element
- the element to reformat.IncorrectOperationException
- if the file to reformat is read-only.reformatText(PsiFile, int, int)
public abstract PsiElement reformat(PsiElement element, boolean canChangeWhiteSpacesOnly) throws IncorrectOperationException
element
- the element to reformat.canChangeWhiteSpacesOnly
- if true
, only reformatting is performed; if false
,
braces and import statements also can be modified if necessary.IncorrectOperationException
- if the file to reformat is read-only.reformatText(PsiFile, int, int)
public abstract PsiElement reformatRange(PsiElement element, int startOffset, int endOffset) throws IncorrectOperationException
element
- the element to reformat.startOffset
- the start offset in the document of the text range to reformat.endOffset
- the end offset in the document of the text range to reformat.IncorrectOperationException
- if the file to reformat is read-only.reformatText(PsiFile, int, int)
public abstract PsiElement reformatRange(PsiElement element, int startOffset, int endOffset, boolean canChangeWhiteSpacesOnly) throws IncorrectOperationException
element
- the element to reformat.startOffset
- the start offset in the document of the text range to reformat.endOffset
- the end offset in the document of the text range to reformat.canChangeWhiteSpacesOnly
- if true
, only reformatting is performed; if false
,
braces and import statements also can be modified if necessary.IncorrectOperationException
- if the file to reformat is read-only.reformatText(PsiFile, int, int)
public abstract void reformatText(PsiFile file, int startOffset, int endOffset) throws IncorrectOperationException
reformatText(PsiFile, Collection)
with the single range defined by the given offsets.file
- the file to reformat.startOffset
- the start of the text range to reformat.endOffset
- the end of the text range to reformat.IncorrectOperationException
- if the file to reformat is read-only.public abstract void reformatText(PsiFile file, java.util.Collection<TextRange> ranges) throws IncorrectOperationException
reformatRange(PsiElement, int, int)
but invalidates the
PSI structure for the file.file
- the file to reformatranges
- ranges to processIncorrectOperationException
- if the file to reformat is read-only.public abstract void reformatTextWithContext(PsiFile file, ChangedRangesInfo info) throws IncorrectOperationException
IncorrectOperationException
public void reformatTextWithContext(PsiFile file, java.util.Collection<TextRange> ranges) throws IncorrectOperationException
IncorrectOperationException
public abstract void adjustLineIndent(PsiFile file, TextRange rangeToAdjust) throws IncorrectOperationException
file
- the file to reformat.rangeToAdjust
- the range of text in which indents should be reformatted.IncorrectOperationException
- if the file is read-only.public abstract int adjustLineIndent(PsiFile file, int offset) throws IncorrectOperationException
file
- the file to reformat.offset
- the offset the line at which should be reformatted.IncorrectOperationException
- if the file is read-only.scheduleIndentAdjustment(Document, int)
public abstract int adjustLineIndent(Document document, int offset)
document
- the document to reformat.offset
- the offset the line at which should be reformatted.IncorrectOperationException
- if the file is read-only.scheduleIndentAdjustment(Document, int)
public void scheduleIndentAdjustment(Document document, int offset)
FormatterBasedIndentAdjuster.MAX_SYNCHRONOUS_ADJUSTMENT_DOC_SIZE
by scheduling it to a time when the document is committed. Uses formatter to calculate the new indent on a
background thread. Only the actual change is done on EDT: the old indent is replaced with a new indent string
directly in the document. Doesn't commit the document, thus a subsequent PsiDocumentManager.commitDocument(Document)
may be required.
Note: visually it may lead to a text jump which becomes more obvious, more time it takes to calculate the
new indent using a formatting model. A better way to handle large documents is to implement LineIndentProvider
returning a non-null value when possible.
document
- The document to be modified.offset
- The offset in the line whose indent is to be adjusted.@Deprecated public abstract boolean isLineToBeIndented(PsiFile file, int offset)
public abstract java.lang.String getLineIndent(PsiFile file, int offset)
file
- the file for which the indent should be calculated.offset
- the offset for the line at which the indent should be calculated.null
if it
was not possible to calculate the indent.public java.lang.String getLineIndent(PsiFile file, int offset, FormattingMode mode)
getLineIndent(PsiFile, int)
file
- the file for which the indent should be calculated.offset
- the offset for the line at which the indent should be calculated.mode
- the formatting mode FormattingMode
null
if it
was not possible to calculate the indent.public abstract java.lang.String getLineIndent(Document document, int offset)
document
- for which the indent should be calculated.null
if it
was not possible to calculate the indent.@Deprecated public abstract Indent getIndent(java.lang.String text, FileType fileType)
@Deprecated public abstract java.lang.String fillIndent(Indent indent, FileType fileType)
@Deprecated public abstract Indent zeroIndent()
public abstract void reformatNewlyAddedElement(ASTNode block, ASTNode addedElement) throws IncorrectOperationException
block
- - added element parentaddedElement
- - new elementIncorrectOperationException
- if the operation fails for some reason (for example,
the file is read-only).public abstract boolean isSequentialProcessingAllowed()
true
if 'sequential' formatting is allowed now; false
otherwisepublic abstract void performActionWithFormatterDisabled(java.lang.Runnable r)
r
- the operation to run.public abstract <T extends java.lang.Throwable> void performActionWithFormatterDisabled(ThrowableRunnable<T> r) throws T extends java.lang.Throwable
T extends java.lang.Throwable
public abstract <T> T performActionWithFormatterDisabled(Computable<T> r)
public int getSpacing(PsiFile file, int offset)
-1
, if required block cannot be found at provided offset,
or spacing cannot be calculated due to some other reason.public int getMinLineFeeds(PsiFile file, int offset)
-1
, if required block cannot be found at provided offset,
or spacing cannot be calculated due to some other reason.public static FormattingMode getCurrentFormattingMode(Project project)
project
- The current project used to obtain CodeStyleManager
instance.FormattingMode
public void runWithDocCommentFormattingDisabled(PsiFile file, java.lang.Runnable runnable)
file
- The file for which doc comment formatting should be temporarily disabled.runnable
- The runnable to run.public DocCommentSettings getDocCommentSettings(PsiFile file)