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


Java Segment.getStartOffset方法代码示例

本文整理汇总了Java中com.intellij.openapi.util.Segment.getStartOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Segment.getStartOffset方法的具体用法?Java Segment.getStartOffset怎么用?Java Segment.getStartOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.util.Segment的用法示例。


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

示例1: compareTo

import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Override
public int compareTo(@NotNull UsageGroup usageGroup) {
  if (!(usageGroup instanceof MethodUsageGroup)) {
    LOG.error("MethodUsageGroup expected but " + usageGroup.getClass() + " found");
  }
  MethodUsageGroup other = (MethodUsageGroup)usageGroup;
  if (SmartPointerManager.getInstance(myProject).pointToTheSameElement(myMethodPointer, other.myMethodPointer)) {
    return 0;
  }
  if (!UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) {
    Segment segment1 = myMethodPointer.getRange();
    Segment segment2 = other.myMethodPointer.getRange();
    if (segment1 != null && segment2 != null) {
      return segment1.getStartOffset() - segment2.getStartOffset();
    }
  }

  return myName.compareToIgnoreCase(other.myName);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:MethodGroupingRule.java

示例2: 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:InjectedLanguageManagerImpl.java

示例3: compareTo

import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Override
public int compareTo(UsageGroup usageGroup) {
  if (!(usageGroup instanceof MethodUsageGroup)) {
    LOG.error("MethodUsageGroup expected but " + usageGroup.getClass() + " found");
  }
  MethodUsageGroup other = (MethodUsageGroup)usageGroup;
  if (SmartPointerManager.getInstance(myProject).pointToTheSameElement(myMethodPointer, other.myMethodPointer)) {
    return 0;
  }
  if (!UsageViewSettings.getInstance().IS_SORT_MEMBERS_ALPHABETICALLY) {
    Segment segment1 = myMethodPointer.getRange();
    Segment segment2 = other.myMethodPointer.getRange();
    if (segment1 != null && segment2 != null) {
      return segment1.getStartOffset() - segment2.getStartOffset();
    }
  }

  return myName.compareToIgnoreCase(other.myName);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:MethodGroupingRule.java

示例4: compareTo

import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Override
public int compareTo(final UsageInfo2UsageAdapter o) {
  VirtualFile containingFile = getFile();
  int shift1 = 0;
  if (containingFile instanceof VirtualFileWindow) {
    shift1 = ((VirtualFileWindow)containingFile).getDocumentWindow().injectedToHost(0);
    containingFile = ((VirtualFileWindow)containingFile).getDelegate();
  }
  VirtualFile oContainingFile = o.getFile();
  int shift2 = 0;
  if (oContainingFile instanceof VirtualFileWindow) {
    shift2 = ((VirtualFileWindow)oContainingFile).getDocumentWindow().injectedToHost(0);
    oContainingFile = ((VirtualFileWindow)oContainingFile).getDelegate();
  }
  if (containingFile == null && oContainingFile == null || !Comparing.equal(containingFile, oContainingFile)) {
    return 0;
  }
  Segment s1 = getFirstSegment();
  Segment s2 = o.getFirstSegment();
  if (s1 == null || s2 == null) return 0;
  return s1.getStartOffset() + shift1 - s2.getStartOffset() - shift2;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:UsageInfo2UsageAdapter.java

示例5: 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;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:17,代码来源:InjectedLanguageManagerImpl.java

示例6: 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PersistentRangeMarkerUtil.java

示例7: 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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:PersistentRangeMarker.java

示例8: 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ShredImpl.java

示例9: getLocation

import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
@Override
@Nullable
public FileEditorLocation getLocation() {
  VirtualFile virtualFile = getFile();
  if (virtualFile == null) return null;
  FileEditor editor = FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile);
  if (!(editor instanceof TextEditor)) return null;

  Segment segment = getUsageInfo().getSegment();
  if (segment == null) return null;
  return new TextEditorLocation(segment.getStartOffset(), (TextEditor)editor);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:13,代码来源:UsageInfo2UsageAdapter.java

示例10: 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();
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:29,代码来源:FindResultUsageInfo.java

示例11: 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;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:15,代码来源:ShredImpl.java

示例12: 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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:50,代码来源:ChunkExtractor.java

示例13: isEmpty

import com.intellij.openapi.util.Segment; //导入方法依赖的package包/类
private static boolean isEmpty(@NotNull Segment segment) {
  return segment.getEndOffset() <= segment.getStartOffset();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:ShowIntentionsPass.java

示例14: 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:58,代码来源:FindResultUsageInfo.java

示例15: 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');
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:60,代码来源:AndroidTestBase.java


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