use of com.intellij.usages.impl.rules.UsageType in project smali by JesusFreke.
the class UsageTypeTest method doTest.
protected void doTest(@NotNull String fileName, @NotNull String text, @NotNull Object... expectedUsageTypes) throws Exception {
Assert.assertTrue(expectedUsageTypes.length % 2 == 0);
Map<Integer, UsageType> expectedUsageTypesMap = Maps.newHashMap();
for (int i = 0; i < expectedUsageTypes.length; i += 2) {
expectedUsageTypesMap.put((Integer) expectedUsageTypes[i], (UsageType) expectedUsageTypes[i + 1]);
}
PsiFile psiFile = createFile(fileName, REF_PATTERN.matcher(text).replaceAll(""));
Map<Integer, Integer> refIndexMap = getRefIndexes(text);
for (Map.Entry<Integer, Integer> entry : refIndexMap.entrySet()) {
int refId = entry.getKey();
int index = entry.getValue();
PsiReference reference = psiFile.getFirstChild().findReferenceAt(index);
Assert.assertNotNull(reference);
if (reference instanceof PsiMultiReference) {
// If there are multiple reference parents, the default seems to be the last one,
// i.e. the highest parent. We actually want the lowest one here.
reference = ((PsiMultiReference) reference).getReferences()[0];
}
UsageType usageType = usageTypeProvider.getUsageType(reference.getElement());
Assert.assertNotNull(usageType);
Assert.assertSame(expectedUsageTypesMap.get(refId), usageType);
expectedUsageTypesMap.remove(refId);
}
Assert.assertTrue(expectedUsageTypesMap.isEmpty());
}
use of com.intellij.usages.impl.rules.UsageType in project intellij-community by JetBrains.
the class JavaUsageTypeProviderTest method assertUsageType.
private void assertUsageType(UsageType expected, PsiClass target) {
UsageTarget[] targets = { new PsiElement2UsageTargetAdapter(target) };
PsiElement element = myFixture.getReferenceAtCaretPositionWithAssertion().getElement();
UsageType usageType = new JavaUsageTypeProvider().getUsageType(element, targets);
assertEquals(expected, usageType);
}
use of com.intellij.usages.impl.rules.UsageType in project intellij-community by JetBrains.
the class ChunkExtractor method processIntersectingRange.
private void processIntersectingRange(@NotNull UsageInfo2UsageAdapter usageInfo2UsageAdapter, @NotNull final CharSequence chars, int hiStart, final int hiEnd, @NotNull final TextAttributesKey[] tokenHighlights, final boolean selectUsageWithBold, @NotNull final List<TextChunk> result) {
final TextAttributes originalAttrs = convertAttributes(tokenHighlights);
if (selectUsageWithBold) {
originalAttrs.setFontType(Font.PLAIN);
}
final int[] lastOffset = { hiStart };
usageInfo2UsageAdapter.processRangeMarkers(segment -> {
int usageStart = segment.getStartOffset();
int usageEnd = segment.getEndOffset();
if (rangeIntersect(lastOffset[0], hiEnd, usageStart, usageEnd)) {
addChunk(chars, lastOffset[0], Math.max(lastOffset[0], usageStart), originalAttrs, false, null, result);
UsageType usageType = isHighlightedAsString(tokenHighlights) ? UsageType.LITERAL_USAGE : isHighlightedAsComment(tokenHighlights) ? UsageType.COMMENT_USAGE : null;
addChunk(chars, Math.max(lastOffset[0], usageStart), Math.min(hiEnd, usageEnd), originalAttrs, selectUsageWithBold, usageType, result);
lastOffset[0] = usageEnd;
if (usageEnd > hiEnd) {
return false;
}
}
return true;
});
if (lastOffset[0] < hiEnd) {
addChunk(chars, lastOffset[0], hiEnd, originalAttrs, false, null, result);
}
}
use of com.intellij.usages.impl.rules.UsageType in project intellij-community by JetBrains.
the class UsageInfo2UsageAdapter method getUsageType.
@Nullable
public UsageType getUsageType() {
UsageType usageType = myUsageType;
if (usageType == null) {
usageType = UsageType.UNCLASSIFIED;
PsiFile file = getPsiFile();
if (file != null) {
Segment segment = getFirstSegment();
if (segment != null) {
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
if (document != null) {
ChunkExtractor extractor = ChunkExtractor.getExtractor(file);
SmartList<TextChunk> chunks = new SmartList<>();
extractor.createTextChunks(this, document.getCharsSequence(), segment.getStartOffset(), segment.getEndOffset(), false, chunks);
for (TextChunk chunk : chunks) {
UsageType chunkUsageType = chunk.getType();
if (chunkUsageType != null) {
usageType = chunkUsageType;
break;
}
}
}
}
}
myUsageType = usageType;
}
return usageType;
}
Aggregations