use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class GroovySpacingProcessorBasic method createDependentSpacingForClosure.
@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;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class ClosureBodyBlock method init.
private void init() {
if (mySubBlocks == null) {
GroovyBlockGenerator generator = new GroovyBlockGenerator(this);
List<ASTNode> children = GroovyBlockGenerator.getClosureBodyVisibleChildren(myNode.getTreeParent());
mySubBlocks = generator.generateSubBlockForCodeBlocks(false, children, myContext.getGroovySettings().INDENT_LABEL_BLOCKS);
//at least -> exists
assert !mySubBlocks.isEmpty();
TextRange firstRange = mySubBlocks.get(0).getTextRange();
TextRange lastRange = mySubBlocks.get(mySubBlocks.size() - 1).getTextRange();
myTextRange = new TextRange(firstRange.getStartOffset(), lastRange.getEndOffset());
}
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class GrLabelBlock method createTextRange.
private static TextRange createTextRange(List<ASTNode> subStatements) {
ASTNode first = subStatements.get(0);
ASTNode last = subStatements.get(subStatements.size() - 1);
return new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset());
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class ConvertToGeeseBracesIntention method findRange.
private static TextRange findRange(PsiElement element) {
PsiElement first = null;
PsiElement last = null;
for (PsiElement cur = element; GeeseUtil.isClosureRBrace(cur) && GeeseUtil.isClosureContainLF(cur); cur = getNext(cur)) {
last = cur;
}
for (PsiElement cur = element; GeeseUtil.isClosureRBrace(cur) && GeeseUtil.isClosureContainLF(cur); cur = getPrev(cur)) {
first = cur;
}
LOG.assertTrue(first != null);
LOG.assertTrue(last != null);
return new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset());
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class JavaFxTagNameReference method getRangeInElement.
@Override
public TextRange getRangeInElement() {
final TextRange rangeInElement = super.getRangeInElement();
final XmlTag tagElement = getTagElement();
if (tagElement != null) {
final String tagElementName = tagElement.getName();
final int dotIdx = tagElementName.indexOf(".");
final int startOffset = rangeInElement.getStartOffset();
if (dotIdx > -1 && startOffset + dotIdx + 2 < rangeInElement.getEndOffset()) {
return new TextRange(startOffset + dotIdx + 1, rangeInElement.getEndOffset());
}
}
return rangeInElement;
}
Aggregations