Java 类com.intellij.psi.ReferenceRange 实例源码

项目:intellij-ce-playground    文件:SingleTargetRequestResultProcessor.java   
@Override
public boolean processTextOccurrence(@NotNull PsiElement element, int offsetInElement, @NotNull final Processor<PsiReference> consumer) {
  if (!myTarget.isValid()) {
    return false;
  }

  final List<PsiReference> references = ourReferenceService.getReferences(element,
                                                                          new PsiReferenceService.Hints(myTarget, offsetInElement));
  //noinspection ForLoopReplaceableByForEach
  for (int i = 0; i < references.size(); i++) {
    PsiReference ref = references.get(i);
    ProgressManager.checkCanceled();
    if (ReferenceRange.containsOffsetInElement(ref, offsetInElement) && ref.isReferenceTo(myTarget) && !consumer.process(ref)) {
      return false;
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:LegacyCompletionContributor.java   
private static void processReference(final CompletionResultSet result,
                                     final int startOffset,
                                     final PairConsumer<PsiReference, CompletionResultSet> consumer,
                                     final PsiReference reference) {
  PsiElement element = reference.getElement();
  final int offsetInElement = startOffset - element.getTextRange().getStartOffset();
  if (!ReferenceRange.containsOffsetInElement(reference, offsetInElement)) {
    return;
  }

  TextRange range = reference.getRangeInElement();
  try {
    final String prefix = element.getText().substring(range.getStartOffset(), offsetInElement);
    consumer.consume(reference, result.withPrefixMatcher(prefix));
  }
  catch (StringIndexOutOfBoundsException e) {
    LOG.error("Reference=" + reference +
              "; element=" + element + " of " + element.getClass() +
              "; range=" + range +
              "; offset=" + offsetInElement,
              e);
  }
}
项目:Intellij-Plugin    文件:StepCompletionContributor.java   
public static String getPrefix(CompletionParameters parameters) {
    PsiElement insertedElement = parameters.getPosition();
    int offsetInFile = parameters.getOffset();

    PsiReference ref = insertedElement.getContainingFile().findReferenceAt(offsetInFile);
    if (isStep(insertedElement) && ref != null) {
        List<TextRange> ranges = ReferenceRange.getRanges(ref);
        PsiElement element = ref.getElement();
        int startOffset = element.getTextRange().getStartOffset();
        for (TextRange range : ranges) {
            if (range.contains(offsetInFile - startOffset)) {
                int endIndex = offsetInFile - startOffset;
                int startIndex = range.getStartOffset();
                return StringUtil.trimStart(element.getText().substring(startIndex + 1, endIndex), " ");
            }
        }

    }
    return parameters.getPosition().getText().replace("IntellijIdeaRulezzz ", "").trim();
}
项目:tools-idea    文件:LegacyCompletionContributor.java   
private static void processReference(final CompletionResultSet result,
                                     final int startOffset,
                                     final PairConsumer<PsiReference, CompletionResultSet> consumer,
                                     final PsiReference reference) {
  PsiElement element = reference.getElement();
  final int offsetInElement = startOffset - element.getTextRange().getStartOffset();
  if (!ReferenceRange.containsOffsetInElement(reference, offsetInElement)) {
    return;
  }

  TextRange range = reference.getRangeInElement();
  try {
    final String prefix = element.getText().substring(range.getStartOffset(), offsetInElement);
    consumer.consume(reference, result.withPrefixMatcher(prefix));
  }
  catch (StringIndexOutOfBoundsException e) {
    LOG.error("Reference=" + reference +
              "; element=" + element + " of " + element.getClass() +
              "; range=" + range +
              "; offset=" + offsetInElement,
              e);
  }
}
项目:consulo-csharp    文件:CC0006.java   
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@NotNull CSharpLanguageVersion languageVersion, @NotNull CSharpHighlightContext highlightContext, @NotNull CSharpConstantExpressionImpl element)
{
    PsiReference[] references = element.getReferences();
    for(PsiReference reference : references)
    {
        PsiElement resolved = reference.resolve();
        if(resolved != null)
        {
            continue;
        }

        if(reference instanceof CSharpReferenceWithValidation)
        {
            String errorMessage = ((CSharpReferenceWithValidation) reference).getErrorMessage(element);
            List<TextRange> ranges = ReferenceRange.getAbsoluteRanges(reference);
            return newBuilder(ranges.get(0)).setText(errorMessage);
        }
    }
    return null;
}
项目:consulo    文件:SingleTargetRequestResultProcessor.java   
@Override
public boolean processTextOccurrence(@Nonnull PsiElement element, int offsetInElement, @Nonnull final Processor<PsiReference> consumer) {
  if (!myTarget.isValid()) {
    return false;
  }

  final List<PsiReference> references = ourReferenceService.getReferences(element, new PsiReferenceService.Hints(myTarget, offsetInElement));
  //noinspection ForLoopReplaceableByForEach
  for (int i = 0; i < references.size(); i++) {
    PsiReference ref = references.get(i);
    ProgressManager.checkCanceled();
    if (ReferenceRange.containsOffsetInElement(ref, offsetInElement) && ref.isReferenceTo(myTarget) && !consumer.process(ref)) {
      return false;
    }
  }
  return true;
}
项目:consulo    文件:LegacyCompletionContributor.java   
private static void processReference(final CompletionResultSet result,
                                     final int startOffset,
                                     final PairConsumer<PsiReference, CompletionResultSet> consumer,
                                     final PsiReference reference) {
  PsiElement element = reference.getElement();
  final int offsetInElement = startOffset - element.getTextRange().getStartOffset();
  if (!ReferenceRange.containsOffsetInElement(reference, offsetInElement)) {
    return;
  }

  TextRange range = reference.getRangeInElement();
  try {
    final String prefix = element.getText().substring(range.getStartOffset(), offsetInElement);
    consumer.consume(reference, result.withPrefixMatcher(prefix));
  }
  catch (StringIndexOutOfBoundsException e) {
    LOG.error("Reference=" + reference +
              "; element=" + element + " of " + element.getClass() +
              "; range=" + range +
              "; offset=" + offsetInElement,
              e);
  }
}
项目:intellij-ce-playground    文件:CompletionProgressIndicator.java   
private static int findReplacementOffset(int selectionEndOffset, PsiReference reference) {
  final List<TextRange> ranges = ReferenceRange.getAbsoluteRanges(reference);
  for (TextRange range : ranges) {
    if (range.contains(selectionEndOffset)) {
      return range.getEndOffset();
    }
  }

  return selectionEndOffset;
}
项目:tools-idea    文件:SingleTargetRequestResultProcessor.java   
public boolean processTextOccurrence(@NotNull PsiElement element, int offsetInElement, @NotNull final Processor<PsiReference> consumer) {
  final List<PsiReference> references = ourReferenceService.getReferences(element,
                                                                          new PsiReferenceService.Hints(myTarget, offsetInElement));
  for (PsiReference ref : references) {
    ProgressManager.checkCanceled();
    if (ReferenceRange.containsOffsetInElement(ref, offsetInElement) && ref.isReferenceTo(myTarget) && !consumer.process(ref)) {
      return false;
    }
  }
  return true;
}
项目:tools-idea    文件:CompletionProgressIndicator.java   
private static int findReplacementOffset(int selectionEndOffset, PsiReference reference) {
  final List<TextRange> ranges = ReferenceRange.getAbsoluteRanges(reference);
  for (TextRange range : ranges) {
    if (range.contains(selectionEndOffset)) {
      return range.getEndOffset();
    }
  }

  return reference.getElement().getTextRange().getStartOffset() + reference.getRangeInElement().getEndOffset();
}
项目:consulo    文件:CompletionProgressIndicator.java   
private static int findReplacementOffset(int selectionEndOffset, PsiReference reference) {
  final List<TextRange> ranges = ReferenceRange.getAbsoluteRanges(reference);
  for (TextRange range : ranges) {
    if (range.contains(selectionEndOffset)) {
      return range.getEndOffset();
    }
  }

  return selectionEndOffset;
}