本文整理汇总了Java中com.intellij.openapi.util.TextRange.getStartOffset方法的典型用法代码示例。如果您正苦于以下问题:Java TextRange.getStartOffset方法的具体用法?Java TextRange.getStartOffset怎么用?Java TextRange.getStartOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.util.TextRange
的用法示例。
在下文中一共展示了TextRange.getStartOffset方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendDescriptors
import com.intellij.openapi.util.TextRange; //导入方法依赖的package包/类
private void appendDescriptors(final ASTNode node, final Document document, final List<FoldingDescriptor> descriptors) {
if (node.getElementType() == GCMTypes.CLASS_DECLARATION || node.getElementType() == GCMTypes.CUSTOM_TYPE_DECLARATION) {
TextRange fullRange = node.getTextRange();
if (fullRange.getEndOffset() - fullRange.getStartOffset() > 0) {
try {
int startOffset = fullRange.getStartOffset() + document.getText(fullRange).indexOf("{") + 1;
int endOffset = fullRange.getEndOffset() - 1;
if (startOffset < endOffset) {
TextRange shortRange = new TextRange(startOffset, fullRange.getEndOffset() - 1);
if (shortRange.getEndOffset() - shortRange.getStartOffset() > 1) {
descriptors.add(new FoldingDescriptor(node, shortRange));
}
}
} catch (Throwable e) {
}
}
}
ASTNode child = node.getFirstChildNode();
while (child != null) {
appendDescriptors(child, document, descriptors);
child = child.getTreeNext();
}
}
示例2: getLineNumber
import com.intellij.openapi.util.TextRange; //导入方法依赖的package包/类
private static int getLineNumber(VirtualFile virtualFile, TextRange textRange) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(virtualFile.getInputStream()));
String line;
int pos = 0;
int lineNumber = 0;
while ((line = br.readLine()) != null) {
pos += line.length() + 1; //+1 for new line
lineNumber++;
if (pos >= textRange.getStartOffset()) {
return lineNumber;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return -1;
}
示例3: getRangeInElement
import com.intellij.openapi.util.TextRange; //导入方法依赖的package包/类
@Override
public TextRange getRangeInElement() {
final TextRange textRange = getTextRange();
AppleScriptReferenceElement[] appleScriptReferences = PsiTreeUtil.getChildrenOfType(this, AppleScriptReferenceElement.class);
if (appleScriptReferences != null && appleScriptReferences.length > 0) {
TextRange lastReferenceRange = appleScriptReferences[appleScriptReferences.length - 1].getTextRange();
return new UnfairTextRange(
lastReferenceRange.getStartOffset() - textRange.getStartOffset(),
lastReferenceRange.getEndOffset() - textRange.getEndOffset()
);
}
return new UnfairTextRange(0, textRange.getEndOffset() - textRange.getStartOffset());
}
示例4: rangeInParent
import com.intellij.openapi.util.TextRange; //导入方法依赖的package包/类
@NotNull
private static TextRange rangeInParent(@NotNull TextRange parent, @NotNull TextRange child) {
int start = child.getStartOffset() - parent.getStartOffset();
if (start < 0) {
return TextRange.EMPTY_RANGE;
}
return TextRange.create(start, start + child.getLength());
}
示例5: applyHighlight
import com.intellij.openapi.util.TextRange; //导入方法依赖的package包/类
@NotNull
private RangeHighlighter applyHighlight(Editor editor, TextAttributes attributes, PsiMethod psiMethod) {
TextRange textRange = psiMethod.getTextRange();
int start = textRange.getStartOffset();
int end = textRange.getEndOffset();
MarkupModel markupModel = editor.getMarkupModel();
return markupModel.addRangeHighlighter(start, end, COLOR_Z_INDEX, attributes, TARGET_AREA);
}
示例6: ellipsizeText
import com.intellij.openapi.util.TextRange; //导入方法依赖的package包/类
String ellipsizeText(@NotNull String text, Matcher matcher) {
final int textLength = text.length();
if (textLength > MAX_LENGTH) {
if (matcher instanceof MinusculeMatcher) {
FList iterable = ((MinusculeMatcher) matcher).matchingFragments(text);
if (iterable != null) {
TextRange textRange = (TextRange) iterable.getHead();
int startOffset = textRange.getStartOffset();
int startIndex = 0;
int endIndex = textLength;
if (startOffset > ELLIPSIS_EXTRA_LENGTH) {
startIndex = startOffset - ELLIPSIS_EXTRA_LENGTH;
}
if (textLength > startIndex + MAX_LENGTH) {
endIndex = startIndex + MAX_LENGTH;
}
String ellipsizedText = text.substring(startIndex, endIndex);
if (startIndex > 0) {
ellipsizedText = DOTS + ellipsizedText;
}
if (endIndex < textLength) {
ellipsizedText = ellipsizedText + DOTS;
}
return ellipsizedText;
}
}
}
return text;
}
示例7: clearHighlights
import com.intellij.openapi.util.TextRange; //导入方法依赖的package包/类
private static void clearHighlights(Editor editor, HighlightManager highlightManager,
List<TextRange> toRemoves) {
if (editor instanceof EditorWindow) {
editor = ((EditorWindow) editor).getDelegate();
}
RangeHighlighter[] highlighters =
((HighlightManagerImpl) highlightManager).getHighlighters(editor);
Arrays.sort(highlighters, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
Collections.sort(toRemoves, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
int i = 0;
int j = 0;
while (i < highlighters.length && j < toRemoves.size()) {
RangeHighlighter highlighter = highlighters[i];
final TextAttributes ta = highlighter.getTextAttributes();
final TextRange textRange = TextRange.create(highlighter);
final TextRange toRemove = toRemoves.get(j);
if (ta != null && ta instanceof NamedTextAttr // wrap
&& highlighter.getLayer() == HighlighterLayer.SELECTION - 1 // wrap
&& toRemove.equals(textRange)) {
highlightManager.removeSegmentHighlighter(editor, highlighter);
i++;
} else if (toRemove.getStartOffset() > textRange.getEndOffset()) {
i++;
} else if (toRemove.getEndOffset() < textRange.getStartOffset()) {
j++;
} else {
i++;
j++;
}
}
}
示例8: getOffsetInHost
import com.intellij.openapi.util.TextRange; //导入方法依赖的package包/类
@Override
public int getOffsetInHost(int offsetInDecoded, @NotNull TextRange rangeInsideHost) {
int result = offsetInDecoded < sourceOffsets.length ? sourceOffsets[offsetInDecoded] : -1;
if (result == -1) return -1;
return (result <= rangeInsideHost.getLength() ? result : rangeInsideHost.getLength()) + rangeInsideHost.getStartOffset();
}