mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
OffsetsElementSignatureProvider cleanup
This commit is contained in:
+13
-9
@@ -155,11 +155,8 @@ public class OffsetsElementSignatureProvider extends AbstractElementSignaturePro
|
||||
|
||||
// There is a possible case that we have a hierarchy of PSI elements that target the same document range. We need to find
|
||||
// out the right one then.
|
||||
|
||||
int indexFromRoot = 0;
|
||||
for (PsiElement e = element.getParent(); e != null && range.equals(e.getTextRange()); e = e.getParent()) {
|
||||
indexFromRoot++;
|
||||
}
|
||||
|
||||
int indexFromRoot = getElementHierarchyIndex(element);
|
||||
|
||||
if (processingInfoStorage != null) {
|
||||
processingInfoStorage.append(String.format("Target element index is %d. Current index from root is %d%n", index, indexFromRoot));
|
||||
@@ -203,10 +200,8 @@ public class OffsetsElementSignatureProvider extends AbstractElementSignaturePro
|
||||
|
||||
// There is a possible case that given PSI element has a parent or child that targets the same range. So, we remember
|
||||
// not only target range offsets but 'hierarchy index' as well.
|
||||
int index = 0;
|
||||
for (PsiElement e = element.getParent(); e != null && range.equals(e.getTextRange()); e = e.getParent()) {
|
||||
index++;
|
||||
}
|
||||
int index = getElementHierarchyIndex(element);
|
||||
|
||||
buffer.append(ELEMENT_TOKENS_SEPARATOR).append(index);
|
||||
PsiFile containingFile = element.getContainingFile();
|
||||
if (containingFile != null && containingFile.getViewProvider().getLanguages().size() > 1) {
|
||||
@@ -214,4 +209,13 @@ public class OffsetsElementSignatureProvider extends AbstractElementSignaturePro
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private static int getElementHierarchyIndex(@NotNull PsiElement element) {
|
||||
TextRange range = element.getTextRange();
|
||||
int index = 0;
|
||||
for (PsiElement e = element.getParent(); e != null && range.equals(e.getTextRange()); e = e.getParent()) {
|
||||
index++;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user