本文整理汇总了Java中com.intellij.psi.formatter.FormatterUtil.isFormatterCalledExplicitly方法的典型用法代码示例。如果您正苦于以下问题:Java FormatterUtil.isFormatterCalledExplicitly方法的具体用法?Java FormatterUtil.isFormatterCalledExplicitly怎么用?Java FormatterUtil.isFormatterCalledExplicitly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.formatter.FormatterUtil
的用法示例。
在下文中一共展示了FormatterUtil.isFormatterCalledExplicitly方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setProgressTask
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
@Override
public void setProgressTask(@NotNull FormattingProgressTask progressIndicator) {
if (!FormatterUtil.isFormatterCalledExplicitly()) {
return;
}
myProgressTask.set(progressIndicator);
}
示例2: processStatement
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
private void processStatement(PsiStatement statement, PsiStatement blockCandidate, int options) {
if (blockCandidate instanceof PsiBlockStatement || blockCandidate == null) return;
boolean forceNewLine = !FormatterUtil.isFormatterCalledExplicitly() && !ApplicationManager.getApplication().isUnitTestMode()
&& !myPostProcessor.getSettings().KEEP_CONTROL_STATEMENT_IN_ONE_LINE;
if (forceNewLine
|| options == CommonCodeStyleSettings.FORCE_BRACES_ALWAYS
|| (options == CommonCodeStyleSettings.FORCE_BRACES_IF_MULTILINE && PostFormatProcessorHelper.isMultiline(statement)))
{
replaceWithBlock(statement, blockCandidate, forceNewLine);
}
}
示例3: setProgressTask
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
@Override
public void setProgressTask(@Nonnull FormattingProgressTask progressIndicator) {
if (!FormatterUtil.isFormatterCalledExplicitly()) {
return;
}
myProgressTask.set(progressIndicator);
}
示例4: doInit
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
private void doInit(ASTNode child, CommonCodeStyleSettings settings, JavaCodeStyleSettings javaSettings) {
init(child);
mySettings = settings;
myJavaSettings = javaSettings;
if (myChild1 == null) {
// Given node corresponds to the first document block.
if (FormatterUtil.isFormatterCalledExplicitly()) {
createSpaceInCode(false);
}
return;
}
final PsiElement myChild1Psi1 = myChild1.getPsi();
final PsiElement myChild1Psi2 = myChild2.getPsi();
if (myChild1Psi1 == null || myChild1Psi1.getLanguage() != JavaLanguage.INSTANCE ||
myChild1Psi2 == null || myChild1Psi2.getLanguage() != JavaLanguage.INSTANCE) {
return;
}
if (myChild2 != null && StdTokenSets.COMMENT_BIT_SET.contains(myChild2.getElementType())) {
if (myChild2.getElementType() == JavaTokenType.C_STYLE_COMMENT) {
myResult = Spacing.getReadOnlySpacing();
}
else if (mySettings.KEEP_FIRST_COLUMN_COMMENT) {
myResult = Spacing.createKeepingFirstColumnSpacing(0, Integer.MAX_VALUE, true, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else {
myResult = Spacing.createSpacing(0, Integer.MAX_VALUE, 0, true, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
else {
if (myParent != null) {
myParent.accept(this);
if (myResult == null) {
final ASTNode prev = getPrevElementType(myChild2);
if (prev != null && prev.getElementType() == JavaTokenType.END_OF_LINE_COMMENT) {
myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else if (!canStickChildrenTogether(myChild1, myChild2)) {
myResult = Spacing.createSpacing(1, Integer.MIN_VALUE, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else if (myChild1.getElementType() == JavaTokenType.C_STYLE_COMMENT){
myResult = null;
}
else if (!shouldKeepSpace(myParent)){
myResult = Spacing.createSpacing(0, 0, 0, true, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
}
}
}
示例5: processCodeBlock
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
private void processCodeBlock(final boolean keepInOneLine, final TextRange textRange) {
final boolean lhsStatement = myChild1.getPsi() instanceof PsiStatement;
final boolean rhsStatement = myChild2.getPsi() instanceof PsiStatement;
if (myParent instanceof JspCodeBlock) {
myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else if (myRole1 == ChildRoleBase.NONE && !lhsStatement || myRole2 == ChildRoleBase.NONE && !rhsStatement) {
final IElementType firstElementType = myChild1.getElementType();
if (
firstElementType == JavaTokenType.END_OF_LINE_COMMENT
||
firstElementType == JavaTokenType.C_STYLE_COMMENT) {
myResult = Spacing.createDependentLFSpacing(0, 1, myParent.getTextRange(),
mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else {
myResult = null;
}
}
else if (myRole1 == ChildRole.LBRACE) {
if (!keepInOneLine) {
int blankLines = 1;
if (myParent != null) {
ASTNode parentNode = myParent.getNode();
if (parentNode != null) {
ASTNode grandPa = parentNode.getTreeParent();
if (grandPa != null && grandPa.getElementType() == JavaElementType.METHOD) {
blankLines += mySettings.BLANK_LINES_BEFORE_METHOD_BODY;
}
}
}
myResult = Spacing.createSpacing(0, 0, blankLines, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else {
myResult = Spacing.createDependentLFSpacing(0, 1, textRange, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
else if (myRole2 == ChildRole.RBRACE) {
if (!keepInOneLine) {
myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_BEFORE_RBRACE);
}
else {
myResult = Spacing.createDependentLFSpacing(0, 1, textRange, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_BEFORE_RBRACE);
}
}
else if (myChild1.getElementType() == JavaElementType.SWITCH_LABEL_STATEMENT
&& myChild2.getElementType() == JavaElementType.BLOCK_STATEMENT)
{
myResult = getSpaceBeforeLBrace(myChild2, mySettings.SPACE_BEFORE_SWITCH_LBRACE, null);
}
else if (lhsStatement && rhsStatement) {
int minSpaces = 0;
int minLineFeeds = 1;
PsiElement psi = myChild1.getPsi();
// We want to avoid situations like below:
// 1. Call 'introduce variable' refactoring for the code like 'System.out.println(1);';
// 2. When KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE is on, the output looks like 'int i = 1; System.out.println(i);';
// That's why we process the option only during the explicit reformat (directly invoked by an user).
if ((mySettings.KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE
&& (FormatterUtil.isFormatterCalledExplicitly() || ApplicationManager.getApplication().isUnitTestMode()))
|| psi != null && PsiTreeUtil.hasErrorElements(psi))
{
minSpaces = 1;
minLineFeeds = 0;
if (myChild1 != null) {
ASTNode lastElement = myChild1;
while (lastElement.getLastChildNode() != null) lastElement = lastElement.getLastChildNode();
//Not to place second statement on the same line with first one, if last ends with single line comment
if (lastElement instanceof PsiComment && lastElement.getElementType() == JavaTokenType.END_OF_LINE_COMMENT) minLineFeeds = 1;
}
}
myResult = Spacing.createSpacing(minSpaces, 0, minLineFeeds, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
示例6: doInit
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
private void doInit(final ASTNode child, final CommonCodeStyleSettings settings) {
init(child);
mySettings = settings;
if (myChild1 == null) {
// Given node corresponds to the first document block.
if (FormatterUtil.isFormatterCalledExplicitly()) {
createSpaceInCode(false);
}
return;
}
final PsiElement myChild1Psi1 = myChild1.getPsi();
final PsiElement myChild1Psi2 = myChild2.getPsi();
if (myChild1Psi1 == null || myChild1Psi1.getLanguage() != JavaLanguage.INSTANCE ||
myChild1Psi2 == null || myChild1Psi2.getLanguage() != JavaLanguage.INSTANCE) {
return;
}
if (myChild2 != null && StdTokenSets.COMMENT_BIT_SET.contains(myChild2.getElementType())) {
if (myChild2.getElementType() == JavaTokenType.C_STYLE_COMMENT) {
myResult = Spacing.getReadOnlySpacing();
}
else if (mySettings.KEEP_FIRST_COLUMN_COMMENT) {
myResult = Spacing
.createKeepingFirstColumnSpacing(0, Integer.MAX_VALUE, true, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else {
myResult = Spacing.createSpacing(0, Integer.MAX_VALUE, 0, true, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
else {
if (myParent != null) {
myParent.accept(this);
if (myResult == null) {
final ASTNode prev = getPrevElementType(myChild2);
if (prev != null && prev.getElementType() == JavaTokenType.END_OF_LINE_COMMENT) {
myResult = Spacing
.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else if (!canStickChildrenTogether(myChild1, myChild2)) {
myResult = Spacing
.createSpacing(1, Integer.MIN_VALUE, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else if (myChild1.getElementType() == JavaTokenType.C_STYLE_COMMENT){
myResult = null;
}
else if (!shouldKeepSpace(myParent)){
myResult = Spacing.createSpacing(0, 0, 0, true, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
}
}
}
示例7: processCodeBlock
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
private void processCodeBlock(final boolean keepInOneLine, final TextRange textRange) {
final boolean lhsStatement = myChild1.getPsi() instanceof PsiStatement;
final boolean rhsStatement = myChild2.getPsi() instanceof PsiStatement;
if (myParent instanceof JspCodeBlock) {
myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else if (myRole1 == ChildRoleBase.NONE && !lhsStatement || myRole2 == ChildRoleBase.NONE && !rhsStatement) {
final IElementType firstElementType = myChild1.getElementType();
if (
firstElementType == JavaTokenType.END_OF_LINE_COMMENT
||
firstElementType == JavaTokenType.C_STYLE_COMMENT) {
myResult = Spacing.createDependentLFSpacing(0, 1, myParent.getTextRange(),
mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else {
myResult = null;
}
}
else if (myRole1 == ChildRole.LBRACE) {
if (!keepInOneLine) {
int blankLines = 1;
if (myParent != null) {
ASTNode parentNode = myParent.getNode();
if (parentNode != null) {
ASTNode grandPa = parentNode.getTreeParent();
if (grandPa != null && grandPa.getElementType() == JavaElementType.METHOD) {
blankLines += mySettings.BLANK_LINES_BEFORE_METHOD_BODY;
}
}
}
myResult = Spacing.createSpacing(
0, 0, blankLines, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE
);
}
else {
myResult = Spacing
.createDependentLFSpacing(0, 1, textRange, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
else if (myRole2 == ChildRole.RBRACE) {
if (!keepInOneLine) {
myResult = Spacing
.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_BEFORE_RBRACE);
}
else {
myResult = Spacing
.createDependentLFSpacing(0, 1, textRange, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_BEFORE_RBRACE);
}
}
else if (myChild1.getElementType() == JavaElementType.SWITCH_LABEL_STATEMENT
&& myChild2.getElementType() == JavaElementType.BLOCK_STATEMENT)
{
myResult = getSpaceBeforeLBrace(mySettings.SPACE_BEFORE_SWITCH_LBRACE, mySettings.BRACE_STYLE, null, false, true);
}
else if (lhsStatement && rhsStatement) {
int minSpaces = 0;
int minLineFeeds = 1;
PsiElement psi = myChild1.getPsi();
// We want to avoid situations like below:
// 1. Call 'introduce variable' refactoring for the code like 'System.out.println(1);';
// 2. When KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE is on, the output looks like 'int i = 1; System.out.println(i);';
// That's why we process the option only during the explicit reformat (directly invoked by an user).
if ((mySettings.KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE
&& (FormatterUtil.isFormatterCalledExplicitly() || ApplicationManager.getApplication().isUnitTestMode()))
|| psi != null && PsiTreeUtil.hasErrorElements(psi))
{
minSpaces = 1;
minLineFeeds = 0;
}
myResult = Spacing.createSpacing(minSpaces, 0, minLineFeeds, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
示例8: reformatText
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
private void reformatText(@Nonnull PsiFile file, @Nonnull FormatTextRanges ranges, @Nullable Editor editor, boolean reformatContext) throws IncorrectOperationException {
if (ranges.isEmpty()) {
return;
}
boolean isFullReformat = ranges.isFullReformat(file);
ApplicationManager.getApplication().assertWriteAccessAllowed();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
CheckUtil.checkWritable(file);
if (!SourceTreeToPsiMap.hasTreeElement(file)) {
return;
}
ASTNode treeElement = SourceTreeToPsiMap.psiElementToTree(file);
transformAllChildren(treeElement);
final CodeFormatterFacade codeFormatter = new CodeFormatterFacade(getSettings(), file.getLanguage());
codeFormatter.setReformatContext(reformatContext);
LOG.assertTrue(file.isValid(), "File name: " + file.getName() + " , class: " + file.getClass().getSimpleName());
if (editor == null) {
editor = PsiUtilBase.findEditor(file);
}
CaretPositionKeeper caretKeeper = null;
if (editor != null) {
caretKeeper = new CaretPositionKeeper(editor, getSettings(), file.getLanguage());
}
if (FormatterUtil.isFormatterCalledExplicitly()) {
removeEndingWhiteSpaceFromEachRange(file, ranges);
}
final SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(getProject());
List<RangeFormatInfo> infos = new ArrayList<>();
for (TextRange range : ranges.getTextRanges()) {
final PsiElement start = findElementInTreeWithFormatterEnabled(file, range.getStartOffset());
final PsiElement end = findElementInTreeWithFormatterEnabled(file, range.getEndOffset());
if (start != null && !start.isValid()) {
LOG.error("start=" + start + "; file=" + file);
}
if (end != null && !end.isValid()) {
LOG.error("end=" + start + "; end=" + file);
}
boolean formatFromStart = range.getStartOffset() == 0;
boolean formatToEnd = range.getEndOffset() == file.getTextLength();
infos.add(new RangeFormatInfo(start == null ? null : smartPointerManager.createSmartPsiElementPointer(start), end == null ? null : smartPointerManager.createSmartPsiElementPointer(end),
formatFromStart, formatToEnd));
}
codeFormatter.processText(file, ranges, true);
for (RangeFormatInfo info : infos) {
final PsiElement startElement = info.startPointer == null ? null : info.startPointer.getElement();
final PsiElement endElement = info.endPointer == null ? null : info.endPointer.getElement();
if ((startElement != null || info.fromStart) && (endElement != null || info.toEnd)) {
postProcessText(file, new TextRange(info.fromStart ? 0 : startElement.getTextRange().getStartOffset(), info.toEnd ? file.getTextLength() : endElement.getTextRange().getEndOffset()));
}
if (info.startPointer != null) smartPointerManager.removePointer(info.startPointer);
if (info.endPointer != null) smartPointerManager.removePointer(info.endPointer);
}
if (caretKeeper != null) {
caretKeeper.restoreCaretPosition();
}
if (editor instanceof EditorEx && isFullReformat) {
((EditorEx)editor).reinitSettings();
DetectedIndentOptionsNotificationProvider.updateIndentNotification(file, true);
}
}
示例9: doInit
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
private void doInit(ASTNode child, CommonCodeStyleSettings settings, JavaCodeStyleSettings javaSettings)
{
if(isErrorElement(child))
{
myResult = Spacing.getReadOnlySpacing();
return;
}
init(child);
mySettings = settings;
myJavaSettings = javaSettings;
if(myChild1 == null)
{
// Given node corresponds to the first document block.
if(FormatterUtil.isFormatterCalledExplicitly())
{
createSpaceInCode(false);
}
return;
}
final PsiElement myChild1Psi1 = myChild1.getPsi();
final PsiElement myChild1Psi2 = myChild2.getPsi();
if(myChild1Psi1 == null || myChild1Psi1.getLanguage() != JavaLanguage.INSTANCE || myChild1Psi2 == null || myChild1Psi2.getLanguage() != JavaLanguage.INSTANCE)
{
return;
}
if(myChild2 != null && StdTokenSets.COMMENT_BIT_SET.contains(myChild2.getElementType()))
{
if(myChild2.getElementType() == JavaTokenType.C_STYLE_COMMENT)
{
myResult = Spacing.getReadOnlySpacing();
}
else if(mySettings.KEEP_FIRST_COLUMN_COMMENT)
{
myResult = Spacing.createKeepingFirstColumnSpacing(0, Integer.MAX_VALUE, true, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else
{
myResult = Spacing.createSpacing(0, Integer.MAX_VALUE, 0, true, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
else if(myParent != null)
{
myParent.accept(this);
if(myResult == null)
{
final ASTNode prev = getPrevElementType(myChild2);
if(prev != null && prev.getElementType() == JavaTokenType.END_OF_LINE_COMMENT)
{
myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else if(!canStickChildrenTogether(myChild1, myChild2))
{
myResult = Spacing.createSpacing(1, Integer.MIN_VALUE, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
else if(myChild1.getElementType() == JavaTokenType.C_STYLE_COMMENT)
{
myResult = null;
}
else if(!shouldKeepSpace(myParent))
{
myResult = Spacing.createSpacing(0, 0, 0, true, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
}
}
}