use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class GroovyTypeDefinitionBodySelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
if (e instanceof GrTypeDefinitionBody) {
GrTypeDefinitionBody block = ((GrTypeDefinitionBody) e);
int startOffset = findOpeningBrace(block);
int endOffset = findClosingBrace(block, startOffset);
TextRange range = new TextRange(startOffset, endOffset);
result.addAll(expandToWholeLine(editorText, range));
}
return result;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class GroovyWordSelectionHandler method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
final TextRange originalRange = e.getTextRange();
LOG.assertTrue(originalRange.getEndOffset() <= editorText.length(), getClass() + "; " + e);
List<TextRange> ranges;
if (isSeparateStatement(e)) {
ranges = ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, originalRange, true);
if (ranges.size() == 1 && ranges.contains(originalRange)) {
ranges = ExtendWordSelectionHandlerBase.expandToWholeLine(editorText, originalRange, false);
}
} else {
ranges = new ArrayList<>();
ranges.add(e.getTextRange());
}
SelectWordUtil.addWordOrLexemeSelection(editor.getSettings().isCamelWords(), editor, cursorOffset, ranges);
return ranges;
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class GrHighlightExitPointHandler method computeUsages.
@Override
public void computeUsages(List<PsiElement> targets) {
PsiElement parent = myTarget.getParent();
if (!(parent instanceof GrReturnStatement) && !(parent instanceof GrThrowStatement))
return;
final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(parent);
ControlFlowUtils.visitAllExitPoints(flowOwner, new ControlFlowUtils.ExitPointVisitor() {
@Override
public boolean visitExitPoint(Instruction instruction, @Nullable GrExpression returnValue) {
final PsiElement returnElement = instruction.getElement();
if (returnElement != null && isCorrectReturn(returnElement)) {
final TextRange range = returnElement.getTextRange();
myReadUsages.add(range);
}
return true;
}
});
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class GroovySpacingProcessor method processParentheses.
private boolean processParentheses(@NotNull IElementType left, @NotNull IElementType right, @NotNull Boolean spaceWithin, @Nullable Boolean spaceWithinEmpty, @Nullable Boolean leftLF, @Nullable Boolean rightLF) {
if (myType1 == left && myType2 == right && spaceWithinEmpty != null) {
createSpaceInCode(spaceWithinEmpty);
return true;
} else if (myType1 == left) {
final ASTNode rparenth = findFrom(myChild1, right, true);
if (rparenth == null || leftLF == null) {
createSpaceInCode(spaceWithin);
} else {
final TextRange range = new TextRange(myChild1.getStartOffset(), rparenth.getTextRange().getEndOffset());
createDependentLFSpacing(leftLF, spaceWithin, range);
}
return true;
} else if (myType2 == right) {
final ASTNode lparenth = findFrom(myChild1, left, false);
if (lparenth == null || rightLF == null) {
createSpaceInCode(spaceWithin);
} else {
final TextRange range = new TextRange(lparenth.getStartOffset(), myChild2.getTextRange().getEndOffset());
createDependentLFSpacing(rightLF, spaceWithin, range);
}
return true;
} else {
return false;
}
}
use of com.intellij.openapi.util.TextRange in project intellij-community by JetBrains.
the class MavenFixedValueReferenceProvider method getReferencesByElement.
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull MavenDomConfiguration domCfg, @NotNull ProcessingContext context) {
ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(element);
TextRange range = manipulator.getRangeInElement(element);
String text = range.substring(element.getText());
Matcher matcher = MavenPropertyResolver.PATTERN.matcher(text);
if (matcher.find()) {
return PsiReference.EMPTY_ARRAY;
}
return new PsiReference[] { new PsiReferenceBase<PsiElement>(element, mySoft) {
@Nullable
@Override
public PsiElement resolve() {
if (mySoft) {
return null;
}
if (Arrays.asList(myValues).contains(getValue())) {
return getElement();
}
return null;
}
@NotNull
@Override
public Object[] getVariants() {
return myValues;
}
} };
}
Aggregations