diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java')
-rw-r--r-- | platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java index 17a85304d4a1..3409d3f93fc8 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/folding/impl/PsiNamesElementSignatureProvider.java @@ -89,11 +89,23 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr return candidate instanceof PsiComment ? candidate : null; } else if (CODE_BLOCK_MARKER.equals(elementMarker)) { + int index = 0; + if (tokenizer.hasMoreTokens()) { + String indexStr = tokenizer.nextToken(); + try { + index = Integer.parseInt(indexStr); + } + catch (NumberFormatException e) { + if (processingInfoStorage != null) { + processingInfoStorage.append("Invalid block index: ").append(indexStr).append("\n"); + } + } + } for (PsiElement child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { - PsiElement firstChild = child.getFirstChild(); - PsiElement lastChild = child.getLastChild(); - if (firstChild != null && lastChild != null && "{".equals(firstChild.getText()) && "}".equals(lastChild.getText())) { - return child; + if (isBlockElement(child)) { + if (--index < 0) { + return child; + } } } return null; @@ -212,18 +224,39 @@ public class PsiNamesElementSignatureProvider extends AbstractElementSignaturePr PsiElement parent = element.getParent(); if (parent instanceof PsiNamedElement && !(parent instanceof PsiFile)) { - PsiElement firstChild = element.getFirstChild(); - PsiElement lastChild = element.getLastChild(); - if (firstChild != null && "{".equals(firstChild.getText()) && lastChild != null && "}".equals(lastChild.getText())) { + if (isBlockElement(element)) { + int index = getBlockElementIndex(element); StringBuilder bufferToUse = buffer; if (bufferToUse == null) { bufferToUse = new StringBuilder(); } bufferToUse.append(TYPE_MARKER).append(ELEMENT_TOKENS_SEPARATOR).append(CODE_BLOCK_MARKER); + if (index > 0) { + bufferToUse.append(ELEMENT_TOKENS_SEPARATOR).append(index); + } return bufferToUse; } } return null; } + + private static boolean isBlockElement(@NotNull PsiElement element) { + PsiElement firstChild = element.getFirstChild(); + PsiElement lastChild = element.getLastChild(); + return firstChild != null && "{".equals(firstChild.getText()) && lastChild != null && "}".equals(lastChild.getText()); + } + + private static int getBlockElementIndex(@NotNull PsiElement element) { + int i = 0; + for (PsiElement sibling : element.getParent().getChildren()) { + if (element.equals(sibling)) { + return i; + } + if (isBlockElement(sibling)) { + i++; + } + } + throw new RuntimeException("Malformed PSI"); + } } |