com.intellij.psi.ReferenceRange Java Examples
The following examples show how to use
com.intellij.psi.ReferenceRange.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StepCompletionContributor.java From Intellij-Plugin with Apache License 2.0 | 6 votes |
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(); }
Example #2
Source File: CC0006.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @Nullable @Override public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull 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; }
Example #3
Source File: SingleTargetRequestResultProcessor.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean processTextOccurrence(@Nonnull PsiElement element, int offsetInElement, @Nonnull final Processor<? super 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; }
Example #4
Source File: LegacyCompletionContributor.java From consulo with Apache License 2.0 | 6 votes |
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); } }
Example #5
Source File: CompletionProgressIndicator.java From consulo with Apache License 2.0 | 5 votes |
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; }