当前位置: 首页>>代码示例>>Java>>正文


Java Spacing类代码示例

本文整理汇总了Java中com.intellij.formatting.Spacing的典型用法代码示例。如果您正苦于以下问题:Java Spacing类的具体用法?Java Spacing怎么用?Java Spacing使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Spacing类属于com.intellij.formatting包,在下文中一共展示了Spacing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSpacing

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@Nullable
@Override
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
    if (!formattingInfo.getCsvCodeStyleSettings().TABULARIZE || formattingInfo.getCsvCodeStyleSettings().WHITE_SPACES_OUTSIDE_QUOTES || child1 == null) {
        return null;
    }
    int spaces = 0;
    CsvBlockElement block1 = (CsvBlockElement) child1;
    CsvBlockElement block2 = (CsvBlockElement) child2;
    if ((block1.getElementType() == CsvTypes.QUOTE && formattingInfo.getCsvCodeStyleSettings().LEADING_WHITE_SPACES) ||
            (block2.getElementType() == CsvTypes.QUOTE && !formattingInfo.getCsvCodeStyleSettings().LEADING_WHITE_SPACES)) {
        spaces = getColumnInfo().getMaxLength() - getTextLength();
    } else {
        return formattingInfo.getSpacingBuilder().getSpacing(this, child1, child2);
    }
    return Spacing.createSpacing(spaces, spaces, 0, true, 0);
}
 
开发者ID:SeeSharpSoft,项目名称:intellij-csv-validator,代码行数:18,代码来源:CsvBlockField.java

示例2: getSpacing

import com.intellij.formatting.Spacing; //导入依赖的package包/类
private static Spacing getSpacing(ASTNode node, CodeStyleSettings settings) {
  LuaSpacingProcessor spacingProcessor = mySharedProcessorAllocator.get();
  try {
    if (spacingProcessor == null) {
      spacingProcessor = new LuaSpacingProcessor(new MyLuaSpacingVisitor(node, settings));
      mySharedProcessorAllocator.set(spacingProcessor);
    } else {
      spacingProcessor.setVisitor(new MyLuaSpacingVisitor(node, settings));
    }
    spacingProcessor.doInit();
    return spacingProcessor.getResult();
  }
  catch (Exception e) {
    LOG.error(e);
    return null;
  }
  finally {
    spacingProcessor.clear();
  }
}
 
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:21,代码来源:LuaSpacingProcessor.java

示例3: getSpacing

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@Nullable
@Override
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
    if (child1 == null) {
        return StatementBlock.NONE;
    }
    if (child2 instanceof ASTBlock) {
        ASTBlock block = (ASTBlock) child2;
        IElementType elementType = block.getNode().getElementType();

        // Do not move trailing comments to new line.
        if (LINE_COMMENT.equals(elementType)
                || COMMENT.equals(elementType)) {
            return SPACE_OR_NEW_LINE;
        }
    }
    return StatementBlock.NEW_LINE;
}
 
开发者ID:protostuff,项目名称:protobuf-jetbrains-plugin,代码行数:19,代码来源:ProtoFileBlock.java

示例4: getSpacing

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@Nullable
@Override
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
    if (child2 instanceof ASTBlock) {
        ASTBlock block = (ASTBlock) child2;
        // Do not move semicolon after '}' to new line.
        IElementType elementType = block.getNode().getElementType();
        if (SEMICOLON.equals(elementType)) {
            return NONE;
        }
        // Do not move trailing comments to new line.
        if (LINE_COMMENT.equals(elementType)
                || COMMENT.equals(elementType)) {
            return SPACE_OR_NEW_LINE;
        }
    }
    if (headerBlocks.contains(child1)) {
        return super.getSpacing(child1, child2);
    }
    return NEW_LINE;
}
 
开发者ID:protostuff,项目名称:protobuf-jetbrains-plugin,代码行数:22,代码来源:ParentBlock.java

示例5: getSpaceBeforeMethodLBrace

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@NotNull
private Spacing getSpaceBeforeMethodLBrace(@NotNull PsiMethod method) {
  final int space = mySettings.SPACE_BEFORE_METHOD_LBRACE ? 1 : 0;
  final int methodBraceStyle = mySettings.METHOD_BRACE_STYLE;

  if (methodBraceStyle == CommonCodeStyleSettings.END_OF_LINE) {
    return createNonLFSpace(space, null, false);
  }
  else if (methodBraceStyle == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED) {
    TextRange headerRange = new TextRange(getMethodHeaderStartOffset(method), getMethodHeaderEndOffset(method));
    return createNonLFSpace(space, headerRange, false);
  }
  else if (shouldHandleAsSimpleMethod(method)) {
    TextRange rangeWithoutAnnotations = new TextRange(getMethodHeaderStartOffset(method), method.getTextRange().getEndOffset());
    return createNonLFSpace(space, rangeWithoutAnnotations, false);
  }

  return Spacing.createSpacing(space, space, 1, false, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:JavaSpacePropertyProcessor.java

示例6: getSpaceBeforeClassLBrace

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@NotNull
private Spacing getSpaceBeforeClassLBrace(@NotNull PsiClass aClass) {
  final int space = mySettings.SPACE_BEFORE_CLASS_LBRACE ? 1 : 0;
  final int classBraceStyle = mySettings.CLASS_BRACE_STYLE;

  if (classBraceStyle == CommonCodeStyleSettings.END_OF_LINE || shouldHandleAsSimpleClass(aClass)) {
    return createNonLFSpace(space, null, false);
  }
  else if (classBraceStyle == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED) {
    final PsiIdentifier nameIdentifier = aClass.getNameIdentifier();
    final int startOffset = nameIdentifier == null ? myParent.getTextRange().getStartOffset() : nameIdentifier.getTextRange().getStartOffset();
    TextRange range = new TextRange(startOffset, myChild1.getTextRange().getEndOffset());
    return createNonLFSpace(space, range, false);
  }

  return Spacing.createSpacing(space, space, 1, false, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:JavaSpacePropertyProcessor.java

示例7: visitField

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@Override
public void visitField(PsiField field) {
  if (myChild1.getElementType() == JavaDocElementType.DOC_COMMENT) {
    myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_DECLARATIONS);
    return;
  }

  if (myRole1 == ChildRole.INITIALIZER_EQ || myRole2 == ChildRole.INITIALIZER_EQ) {
    createSpaceInCode(mySettings.SPACE_AROUND_ASSIGNMENT_OPERATORS);
  }
  else if (myRole1 == ChildRole.TYPE || myRole2 == ChildRole.TYPE) {
    createSpaceInCode(true);
  }
  else if (myChild2.getElementType() == JavaTokenType.SEMICOLON) {
    createSpaceProperty(false, false, 0);
  }
  else if (myRole1 == ChildRole.MODIFIER_LIST) {
    createSpaceProperty(true, false, 0);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:JavaSpacePropertyProcessor.java

示例8: createSpaceProperty

import com.intellij.formatting.Spacing; //导入依赖的package包/类
private void createSpaceProperty(boolean space, boolean keepLineBreaks, final int keepBlankLines) {
  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 (!space && !canStickChildrenTogether(myChild1, myChild2)) {
      space = true;
    }

    if (!keepLineBreaks && myRole2 == ChildRoleBase.NONE) {
      keepLineBreaks = true;
    }
    myResult = Spacing.createSpacing(space ? 1 : 0, space ? 1 : 0, 0, keepLineBreaks, keepBlankLines);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:JavaSpacePropertyProcessor.java

示例9: manageComments

import com.intellij.formatting.Spacing; //导入依赖的package包/类
private boolean manageComments() {
  if (mySettings.KEEP_FIRST_COLUMN_COMMENT && TokenSets.COMMENT_SET.contains(myType2)) {
    if (!isAfterElementOrSemi(GroovyElementTypes.IMPORT_STATEMENT)) {
      myResult = Spacing.createKeepingFirstColumnSpacing(0, Integer.MAX_VALUE, true, 1);
      return true;
    }
    return false;
  }

  ASTNode prev = FormatterUtil.getPreviousNonWhitespaceLeaf(myChild2);
  if (prev != null && prev.getElementType() == GroovyTokenTypes.mNLS) {
    prev = FormatterUtil.getPreviousNonWhitespaceLeaf(prev);
  }
  if (prev != null && prev.getElementType() == GroovyTokenTypes.mSL_COMMENT) {
    myResult = Spacing.createSpacing(0, Integer.MAX_VALUE, 1, mySettings.KEEP_LINE_BREAKS, keepBlankLines());
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GroovySpacingProcessor.java

示例10: visitOpenBlock

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@Override
public void visitOpenBlock(GrOpenBlock block) {
  boolean isMethod = block.getParent() instanceof GrMethod;
  boolean keepInOneLine = isMethod ? mySettings.KEEP_SIMPLE_METHODS_IN_ONE_LINE : mySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE;

  if (myType1 == GroovyTokenTypes.mLCURLY && myType2 == GroovyTokenTypes.mRCURLY) {
    createLF(!keepInOneLine);
  }
  else if (myType1 == GroovyTokenTypes.mLCURLY) {
    if (keepInOneLine) {
      createDependentLFSpacing(true, mySettings.SPACE_WITHIN_BRACES, block.getTextRange());
    }
    else {
      int lineFeedsCount = isMethod ? mySettings.BLANK_LINES_BEFORE_METHOD_BODY + 1 : 1;
      myResult = Spacing.createSpacing(0, 0, lineFeedsCount, mySettings.KEEP_LINE_BREAKS, keepBlankLines());
    }
  }
  else if (myType2 == GroovyTokenTypes.mRCURLY) {
    if (keepInOneLine) {
      createDependentLFSpacing(true, mySettings.SPACE_WITHIN_BRACES, block.getTextRange());
    }
    else {
      createLF(true);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:GroovySpacingProcessor.java

示例11: visitTypeDefinitionBody

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@Override
public void visitTypeDefinitionBody(GrTypeDefinitionBody typeDefinitionBody) {
  if (myType1 == GroovyTokenTypes.mLCURLY && myType2 == GroovyTokenTypes.mRCURLY) {
    if (mySettings.KEEP_SIMPLE_CLASSES_IN_ONE_LINE) {
      createSpaceInCode(false);
    }
    else {
      createLF(true);
    }
  }
  else if (myType1 == GroovyTokenTypes.mLCURLY) {
    myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_AFTER_CLASS_HEADER + 1, mySettings.KEEP_LINE_BREAKS, keepBlankLines());
  }
  else if (myType2 == GroovyTokenTypes.mRCURLY) {
    createLF(true);
  }
  else {
    processClassMembers(typeDefinitionBody);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:GroovySpacingProcessor.java

示例12: createDependentSpacingForClosure

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@NotNull
static Spacing createDependentSpacingForClosure(@NotNull CommonCodeStyleSettings settings,
                                                @NotNull GroovyCodeStyleSettings groovySettings,
                                                @NotNull GrClosableBlock closure,
                                                final boolean forArrow) {
  boolean spaceWithinBraces = closure.getParent() instanceof GrStringInjection
                              ? groovySettings.SPACE_WITHIN_GSTRING_INJECTION_BRACES
                              : settings.SPACE_WITHIN_BRACES;
  GrStatement[] statements = closure.getStatements();
  if (statements.length > 0) {
    final PsiElement startElem = forArrow ? statements[0] : closure;
    int start = startElem.getTextRange().getStartOffset();
    int end = statements[statements.length - 1].getTextRange().getEndOffset();
    TextRange range = new TextRange(start, end);

    int minSpaces = spaceWithinBraces || forArrow ? 1 : 0;
    int maxSpaces = spaceWithinBraces || forArrow ? 1 : 0;
    return Spacing.createDependentLFSpacing(minSpaces, maxSpaces, range, settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_CODE);
  }
  return spaceWithinBraces || forArrow ? COMMON_SPACING : NO_SPACING_WITH_NEWLINE;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GroovySpacingProcessorBasic.java

示例13: setBraceSpace

import com.intellij.formatting.Spacing; //导入依赖的package包/类
public Spacing setBraceSpace(boolean needSpaceSetting,
                             @CommonCodeStyleSettings.BraceStyleConstant int braceStyleSetting,
                             TextRange textRange, ASTNode child2) {
    final int spaces = needSpaceSetting ? 1 : 0;
    IElementType parentType = child2.getTreeParent().getElementType();

    // Don't wrap simple block event if line breaks set to NEXT_LINE (unless there are manual line breaks)
    if (braceStyleSetting == CommonCodeStyleSettings.NEXT_LINE && SquirrelFormatterUtil.isSimpleBlock(child2) &&
            ((parentType == FUNCTION_BODY && cmSettings.KEEP_SIMPLE_METHODS_IN_ONE_LINE) ||
                    (parentType == CLASS_DECLARATION && cmSettings.KEEP_SIMPLE_CLASSES_IN_ONE_LINE) ||
                    (parentType != FUNCTION_BODY && parentType != CLASS_DECLARATION && cmSettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE))
            ) {
        return Spacing.createSpacing(spaces, spaces, 0, cmSettings.KEEP_LINE_BREAKS,
                cmSettings.KEEP_BLANK_LINES_IN_CODE);
    }

    else if (braceStyleSetting == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED && textRange != null) {
        return Spacing.createDependentLFSpacing(spaces, spaces, textRange, cmSettings.KEEP_LINE_BREAKS,
                cmSettings.KEEP_BLANK_LINES_IN_CODE);
    }
    else {
        final int lineBreaks = (braceStyleSetting == CommonCodeStyleSettings.END_OF_LINE || braceStyleSetting == CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED) ? 0: 1;
        return Spacing.createSpacing(spaces, spaces, lineBreaks, false, 0);
    }
}
 
开发者ID:shvetsgroup,项目名称:squirrel-lang-idea-plugin,代码行数:26,代码来源:SquirrelSpacingProcessor.java

示例14: visitField

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@Override public void visitField(PsiField field) {
  if (myChild1.getElementType() == JavaDocElementType.DOC_COMMENT) {
    myResult = Spacing
      .createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_DECLARATIONS);
    return;
  }

  if (myRole1 == ChildRole.INITIALIZER_EQ || myRole2 == ChildRole.INITIALIZER_EQ) {
    createSpaceInCode(mySettings.SPACE_AROUND_ASSIGNMENT_OPERATORS);
  }
  else if (myRole1 == ChildRole.TYPE || myRole2 == ChildRole.TYPE) {
    createSpaceInCode(true);
  }
  else if (myChild2.getElementType() == JavaTokenType.SEMICOLON) {
    createSpaceProperty(false, false, 0);
  }
  else if (myRole1 == ChildRole.MODIFIER_LIST) {
    createSpaceProperty(true, false, 0);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:JavaSpacePropertyProcessor.java

示例15: visitExpressionList

import com.intellij.formatting.Spacing; //导入依赖的package包/类
@Override public void visitExpressionList(PsiExpressionList list) {
  if (myRole1 == ChildRole.LPARENTH && myRole2 == ChildRole.RPARENTH) {
    createParenthSpace(mySettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE, mySettings.SPACE_WITHIN_EMPTY_METHOD_CALL_PARENTHESES);
  }
  else if (myRole2 == ChildRole.RPARENTH) {
    if (JavaFormatterUtil.hasAnonymousClassesArguments(list, 2)) {
      myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, 0);
    }
    else {
      createParenthSpace(mySettings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE,
                         myRole1 == ChildRole.COMMA || mySettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES);
    }
  }
  else if (myRole1 == ChildRole.LPARENTH) {
    createParenthSpace(mySettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE, mySettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES);
  }
  else if (myRole1 == ChildRole.COMMA) {
    createSpaceInCode(mySettings.SPACE_AFTER_COMMA);
  }
  else if (myRole2 == ChildRole.COMMA) {
    createSpaceInCode(false);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:JavaSpacePropertyProcessor.java


注:本文中的com.intellij.formatting.Spacing类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。