本文整理汇总了Java中com.intellij.openapi.util.Segment.getEndOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Segment.getEndOffset方法的具体用法?Java Segment.getEndOffset怎么用?Java Segment.getEndOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.util.Segment
的用法示例。
在下文中一共展示了Segment.getEndOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNonEditableFragments
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@NotNull
@Override
public List<TextRange> getNonEditableFragments(@NotNull DocumentWindow window) {
List<TextRange> result = ContainerUtil.newArrayList();
int offset = 0;
for (PsiLanguageInjectionHost.Shred shred : ((DocumentWindowImpl)window).getShreds()) {
Segment hostRange = shred.getHostRangeMarker();
if (hostRange == null) continue;
offset = appendRange(result, offset, shred.getPrefix().length());
offset += hostRange.getEndOffset() - hostRange.getStartOffset();
offset = appendRange(result, offset, shred.getSuffix().length());
}
return result;
}
示例2: getNonEditableFragments
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Nonnull
@Override
public List<TextRange> getNonEditableFragments(@Nonnull DocumentWindow window) {
List<TextRange> result = ContainerUtil.newArrayList();
int offset = 0;
for (PsiLanguageInjectionHost.Shred shred : ((DocumentWindowImpl)window).getShreds()) {
Segment hostRange = shred.getHostRangeMarker();
if (hostRange == null) continue;
offset = appendRange(result, offset, shred.getPrefix().length());
offset += hostRange.getEndOffset() - hostRange.getStartOffset();
offset = appendRange(result, offset, shred.getSuffix().length());
}
return result;
}
示例3: startBlinking
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
public void startBlinking() {
Project project = myEditor.getProject();
if (ApplicationManager.getApplication().isDisposed() || myEditor.isDisposed() || project != null && project.isDisposed()) {
return;
}
MarkupModel markupModel = myEditor.getMarkupModel();
if (show) {
for (Segment segment : myMarkers) {
if (segment.getEndOffset() > myEditor.getDocument().getTextLength()) continue;
RangeHighlighter highlighter = markupModel.addRangeHighlighter(segment.getStartOffset(), segment.getEndOffset(),
HighlighterLayer.ADDITIONAL_SYNTAX, myAttributes,
HighlighterTargetArea.EXACT_RANGE);
myAddedHighlighters.add(highlighter);
}
}
else {
removeHighlights();
}
stopBlinking();
myBlinkingAlarm.addRequest(new Runnable() {
@Override
public void run() {
if (myTimeToLive > 0 || show) {
myTimeToLive--;
show = !show;
startBlinking();
}
}
}, 400);
}
示例4: shouldTranslateViaDiff
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
/**
* Answers if document region identified by the given range marker should be translated via diff algorithm on document change
* identified by the given event.
*
* @param e event that describes document change
* @param rangeMarker target range marker which update strategy should be selected
* @return <code>true</code> if target document range referenced by the given range marker should be translated via
* diff algorithm; <code>false</code> otherwise
*/
static boolean shouldTranslateViaDiff(@NotNull DocumentEvent e, @NotNull Segment rangeMarker) {
if (e.isWholeTextReplaced()) {
// Perform translation if the whole text is replaced.
return true;
}
if (e.getOffset() >= rangeMarker.getEndOffset() || e.getOffset() + e.getOldLength() <= rangeMarker.getStartOffset()) {
// Don't perform complex processing if the change doesn't affect target range.
return false;
}
// Perform complex processing only if significant document part is updated.
return (Math.max(e.getNewLength(), e.getOldLength()) * 1.0) / e.getDocument().getTextLength() >= 0.8;
}
示例5: storeLinesAndCols
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Nullable
static LinesCols storeLinesAndCols(Segment range, Document myDocument) {
int myStartLine;
int myStartColumn;
int myEndLine;
int myEndColumn;
// document might have been changed already
int startOffset = range.getStartOffset();
if (startOffset <= myDocument.getTextLength()) {
myStartLine = myDocument.getLineNumber(startOffset);
myStartColumn = startOffset - myDocument.getLineStartOffset(myStartLine);
if (myStartColumn < 0) {
return null;
}
}
else {
return null;
}
int endOffset = range.getEndOffset();
if (endOffset <= myDocument.getTextLength()) {
myEndLine = myDocument.getLineNumber(endOffset);
myEndColumn = endOffset - myDocument.getLineStartOffset(myEndLine);
if (myEndColumn < 0) {
return null;
}
}
else {
return null;
}
return new LinesCols(myStartLine, myStartColumn, myEndLine, myEndColumn);
}
示例6: toString
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Override
@SuppressWarnings({"HardCodedStringLiteral"})
public String toString() {
PsiLanguageInjectionHost host = getHost();
Segment hostRange = getHostRangeMarker();
return "Shred " + (host == null ? null : host.getTextRange()) + ": " + host +
" In host range: " + (hostRange != null ? "(" + hostRange.getStartOffset() + "," + hostRange.getEndOffset() + ");" : "invalid;") +
" PSI range: " + this.range;
}
示例7: isValid
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Override
public boolean isValid() {
if (!super.isValid()) return false;
Segment segment = super.getSegment();
if (segment == null) return false;
VirtualFile file = getPsiFile().getVirtualFile();
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(getPsiFile());
if (document == null) return false;
Segment searchOffset;
if (myAnchor != null) {
searchOffset = myAnchor.getRange();
if (searchOffset == null) return false;
} else {
searchOffset = segment;
}
int offset = searchOffset.getStartOffset();
FindResult result;
do {
result = myFindManager.findString(document.getCharsSequence(), offset, myFindModel, file);
offset = result.getEndOffset() == offset ? offset + 1 : result.getEndOffset();
if (!result.isStringFound()) return false;
} while (result.getStartOffset() < segment.getStartOffset());
return segment.getStartOffset() == result.getStartOffset() && segment.getEndOffset() == result.getEndOffset();
}
示例8: recalculate
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
public void recalculate(List<? extends Segment> ranges) {
if (myIsDirty) {
return;
}
if (myVisibleAreaWidth <= 0) {
myIsDirty = true;
return;
}
Collections.sort(ranges, (o1, o2) -> {
int startDiff = o1.getStartOffset() - o2.getStartOffset();
return startDiff == 0 ? o2.getEndOffset() - o1.getEndOffset() : startDiff;
});
final int[] lastRecalculatedOffset = new int[] {0};
SoftWrapAwareDocumentParsingListenerAdapter listener = new SoftWrapAwareDocumentParsingListenerAdapter() {
@Override
public void onRecalculationEnd(@Nonnull IncrementalCacheUpdateEvent event) {
lastRecalculatedOffset[0] = event.getActualEndOffset();
}
};
myListeners.add(listener);
try {
for (Segment range : ranges) {
int lastOffset = lastRecalculatedOffset[0];
if (range.getEndOffset() > lastOffset) {
recalculateSoftWraps(new IncrementalCacheUpdateEvent(Math.max(range.getStartOffset(), lastOffset), range.getEndOffset(),
myEditor));
}
}
}
finally {
myListeners.remove(listener);
}
onRecalculationEnd();
}
示例9: toString
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Override
@SuppressWarnings("HardCodedStringLiteral")
public String toString() {
PsiLanguageInjectionHost host = getHost();
Segment hostRange = getHostRangeMarker();
return "Shred " +
(host == null ? null : host.getTextRange()) +
": " +
host +
" In host range: " +
(hostRange != null ? "(" + hostRange.getStartOffset() + "," + hostRange.getEndOffset() + ");" : "invalid;") +
" PSI range: " +
rangeInDecodedPSI;
}
示例10: extractChunks
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@NotNull
private TextChunk[] extractChunks(@NotNull UsageInfo2UsageAdapter usageInfo2UsageAdapter, @NotNull PsiFile file) {
int absoluteStartOffset = usageInfo2UsageAdapter.getNavigationOffset();
if (absoluteStartOffset == -1) return TextChunk.EMPTY_ARRAY;
Document visibleDocument = myDocument instanceof DocumentWindow ? ((DocumentWindow)myDocument).getDelegate() : myDocument;
int visibleStartOffset = myDocument instanceof DocumentWindow ? ((DocumentWindow)myDocument).injectedToHost(absoluteStartOffset) : absoluteStartOffset;
int lineNumber = myDocument.getLineNumber(absoluteStartOffset);
int visibleLineNumber = visibleDocument.getLineNumber(visibleStartOffset);
int visibleColumnNumber = visibleStartOffset - visibleDocument.getLineStartOffset(visibleLineNumber);
final List<TextChunk> result = new ArrayList<TextChunk>();
appendPrefix(result, visibleLineNumber, visibleColumnNumber);
int fragmentToShowStart = myDocument.getLineStartOffset(lineNumber);
int fragmentToShowEnd = fragmentToShowStart < myDocument.getTextLength() ? myDocument.getLineEndOffset(lineNumber) : 0;
if (fragmentToShowStart > fragmentToShowEnd) return TextChunk.EMPTY_ARRAY;
final CharSequence chars = myDocument.getCharsSequence();
if (fragmentToShowEnd - fragmentToShowStart > MAX_LINE_LENGTH_TO_SHOW) {
final int lineStartOffset = fragmentToShowStart;
fragmentToShowStart = Math.max(lineStartOffset, absoluteStartOffset - OFFSET_BEFORE_TO_SHOW_WHEN_LONG_LINE);
final int lineEndOffset = fragmentToShowEnd;
Segment segment = usageInfo2UsageAdapter.getUsageInfo().getSegment();
int usage_length = segment != null ? segment.getEndOffset() - segment.getStartOffset():0;
fragmentToShowEnd = Math.min(lineEndOffset, absoluteStartOffset + usage_length + OFFSET_AFTER_TO_SHOW_WHEN_LONG_LINE);
// if we search something like a word, then expand shown context from one symbol before / after at least for word boundary
// this should not cause restarts of the lexer as the tokens are usually words
if (usage_length > 0 &&
StringUtil.isJavaIdentifierStart(chars.charAt(absoluteStartOffset)) &&
StringUtil.isJavaIdentifierStart(chars.charAt(absoluteStartOffset + usage_length - 1))) {
while(fragmentToShowEnd < lineEndOffset && StringUtil.isJavaIdentifierStart(chars.charAt(fragmentToShowEnd - 1))) ++fragmentToShowEnd;
while(fragmentToShowStart > lineStartOffset && StringUtil.isJavaIdentifierStart(chars.charAt(fragmentToShowStart))) --fragmentToShowStart;
if (fragmentToShowStart != lineStartOffset) ++fragmentToShowStart;
if (fragmentToShowEnd != lineEndOffset) --fragmentToShowEnd;
}
}
if (myDocument instanceof DocumentWindow) {
List<TextRange> editable = InjectedLanguageManager.getInstance(file.getProject())
.intersectWithAllEditableFragments(file, new TextRange(fragmentToShowStart, fragmentToShowEnd));
for (TextRange range : editable) {
createTextChunks(usageInfo2UsageAdapter, chars, range.getStartOffset(), range.getEndOffset(), true, result);
}
return result.toArray(new TextChunk[result.size()]);
}
return createTextChunks(usageInfo2UsageAdapter, chars, fragmentToShowStart, fragmentToShowEnd, true, result);
}
示例11: recalculate
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
public void recalculate(List<? extends Segment> ranges) {
if (myIsDirty) {
return;
}
initListenerIfNecessary();
if (myVisibleAreaWidth <= 0) {
myIsDirty = true;
return;
}
Collections.sort(ranges, new Comparator<Segment>() {
@Override
public int compare(Segment o1, Segment o2) {
int startDiff = o1.getStartOffset() - o2.getStartOffset();
return startDiff == 0 ? o2.getEndOffset() - o1.getEndOffset() : startDiff;
}
});
final int[] lastRecalculatedOffset = new int[] {0};
SoftWrapAwareDocumentParsingListenerAdapter listener = new SoftWrapAwareDocumentParsingListenerAdapter() {
@Override
public void onRecalculationEnd(@NotNull IncrementalCacheUpdateEvent event) {
lastRecalculatedOffset[0] = event.getActualEndOffset();
}
};
myListeners.add(listener);
try {
for (Segment range : ranges) {
int lastOffset = lastRecalculatedOffset[0];
if (range.getEndOffset() > lastOffset) {
recalculateSoftWraps(new IncrementalCacheUpdateEvent(myEditor.getDocument(),
Math.max(range.getStartOffset(), lastOffset), range.getEndOffset(),
myDataMapper, myEditor));
}
}
}
finally {
myListeners.remove(listener);
}
onRecalculationEnd();
}
示例12: isEmpty
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
private static boolean isEmpty(@NotNull Segment segment) {
return segment.getEndOffset() <= segment.getStartOffset();
}
示例13: isValid
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Override
public boolean isValid() {
if (!super.isValid()) return false;
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(getPsiFile());
if (document == null) {
myCachedResult = null;
return false;
}
Boolean cachedResult = myCachedResult;
if (document.getModificationStamp() == myTimestamp && cachedResult != null) {
return cachedResult;
}
myTimestamp = document.getModificationStamp();
Segment segment = getSegment();
if (segment == null) {
myCachedResult = false;
return false;
}
VirtualFile file = getPsiFile().getVirtualFile();
Segment searchOffset;
if (myAnchor != null) {
searchOffset = myAnchor.getRange();
if (searchOffset == null) {
myCachedResult = false;
return false;
}
}
else {
searchOffset = segment;
}
int offset = searchOffset.getStartOffset();
Long data = myFindModel.getUserData(ourDocumentTimestampKey);
if (data == null || data != myTimestamp) {
data = myTimestamp;
FindManagerImpl.clearPreviousFindData(myFindModel);
}
myFindModel.putUserData(ourDocumentTimestampKey, data);
FindResult result;
do {
result = myFindManager.findString(document.getCharsSequence(), offset, myFindModel, file);
offset = result.getEndOffset() == offset ? offset + 1 : result.getEndOffset();
if (!result.isStringFound()) {
myCachedResult = false;
return false;
}
} while (result.getStartOffset() < segment.getStartOffset());
boolean ret = segment.getStartOffset() == result.getStartOffset() && segment.getEndOffset() == result.getEndOffset();
myCachedResult = ret;
return ret;
}
示例14: appendSourceDescription
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
/** Appends a description of the given elements, suitable as unit test golden file output */
public static void appendSourceDescription(@NotNull StringBuilder sb, @Nullable PsiFile file, int offset, @Nullable Segment segment) {
if (file != null && segment != null) {
if (ResourceHelper.getFolderType(file) != null) {
assertNotNull(file.getParent());
sb.append(file.getParent().getName());
sb.append("/");
}
sb.append(file.getName());
sb.append(':');
String text = file.getText();
int lineNumber = 1;
for (int i = 0; i < offset; i++) {
if (text.charAt(i) == '\n') {
lineNumber++;
}
}
sb.append(lineNumber);
sb.append(":");
sb.append('\n');
int startOffset = segment.getStartOffset();
int endOffset = segment.getEndOffset();
assertTrue(offset == -1 || offset >= startOffset);
assertTrue(offset == -1 || offset <= endOffset);
int lineStart = startOffset;
while (lineStart > 0 && text.charAt(lineStart - 1) != '\n') {
lineStart--;
}
// Skip over leading whitespace
while (lineStart < startOffset && Character.isWhitespace(text.charAt(lineStart))) {
lineStart++;
}
int lineEnd = startOffset;
while (lineEnd < text.length() && text.charAt(lineEnd) != '\n') {
lineEnd++;
}
String indent = " ";
sb.append(indent);
sb.append(text.substring(lineStart, lineEnd));
sb.append('\n');
sb.append(indent);
for (int i = lineStart; i < lineEnd; i++) {
if (i == offset) {
sb.append('|');
} else if (i >= startOffset && i <= endOffset) {
sb.append('~');
} else {
sb.append(' ');
}
}
} else {
sb.append(offset);
sb.append(":?");
}
sb.append('\n');
}
示例15: extractChunks
import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Nonnull
private TextChunk[] extractChunks(@Nonnull UsageInfo2UsageAdapter usageInfo2UsageAdapter, @Nonnull PsiFile file) {
int absoluteStartOffset = usageInfo2UsageAdapter.getNavigationOffset();
if (absoluteStartOffset == -1) return TextChunk.EMPTY_ARRAY;
Document visibleDocument = myDocument instanceof DocumentWindow ? ((DocumentWindow)myDocument).getDelegate() : myDocument;
int visibleStartOffset = myDocument instanceof DocumentWindow ? ((DocumentWindow)myDocument).injectedToHost(absoluteStartOffset) : absoluteStartOffset;
int lineNumber = myDocument.getLineNumber(absoluteStartOffset);
int visibleLineNumber = visibleDocument.getLineNumber(visibleStartOffset);
int visibleColumnNumber = visibleStartOffset - visibleDocument.getLineStartOffset(visibleLineNumber);
final List<TextChunk> result = new ArrayList<TextChunk>();
appendPrefix(result, visibleLineNumber, visibleColumnNumber);
int fragmentToShowStart = myDocument.getLineStartOffset(lineNumber);
int fragmentToShowEnd = fragmentToShowStart < myDocument.getTextLength() ? myDocument.getLineEndOffset(lineNumber) : 0;
if (fragmentToShowStart > fragmentToShowEnd) return TextChunk.EMPTY_ARRAY;
final CharSequence chars = myDocument.getCharsSequence();
if (fragmentToShowEnd - fragmentToShowStart > MAX_LINE_LENGTH_TO_SHOW) {
final int lineStartOffset = fragmentToShowStart;
fragmentToShowStart = Math.max(lineStartOffset, absoluteStartOffset - OFFSET_BEFORE_TO_SHOW_WHEN_LONG_LINE);
final int lineEndOffset = fragmentToShowEnd;
Segment segment = usageInfo2UsageAdapter.getUsageInfo().getSegment();
int usage_length = segment != null ? segment.getEndOffset() - segment.getStartOffset() : 0;
fragmentToShowEnd = Math.min(lineEndOffset, absoluteStartOffset + usage_length + OFFSET_AFTER_TO_SHOW_WHEN_LONG_LINE);
// if we search something like a word, then expand shown context from one symbol before / after at least for word boundary
// this should not cause restarts of the lexer as the tokens are usually words
if (usage_length > 0 && StringUtil.isJavaIdentifierStart(chars.charAt(absoluteStartOffset)) && StringUtil.isJavaIdentifierStart(chars.charAt(absoluteStartOffset + usage_length - 1))) {
while (fragmentToShowEnd < lineEndOffset && StringUtil.isJavaIdentifierStart(chars.charAt(fragmentToShowEnd - 1))) ++fragmentToShowEnd;
while (fragmentToShowStart > lineStartOffset && StringUtil.isJavaIdentifierStart(chars.charAt(fragmentToShowStart))) --fragmentToShowStart;
if (fragmentToShowStart != lineStartOffset) ++fragmentToShowStart;
if (fragmentToShowEnd != lineEndOffset) --fragmentToShowEnd;
}
}
if (myDocument instanceof DocumentWindow) {
List<TextRange> editable = InjectedLanguageManager.getInstance(file.getProject()).intersectWithAllEditableFragments(file, new TextRange(fragmentToShowStart, fragmentToShowEnd));
for (TextRange range : editable) {
createTextChunks(usageInfo2UsageAdapter, chars, range.getStartOffset(), range.getEndOffset(), true, result);
}
return result.toArray(new TextChunk[result.size()]);
}
return createTextChunks(usageInfo2UsageAdapter, chars, fragmentToShowStart, fragmentToShowEnd, true, result);
}