From 2eaa5fd6b577a4e2ef0ab6986db3c7fa12e718eb Mon Sep 17 00:00:00 2001 From: Maas van den Berg Date: Tue, 17 Nov 2009 18:06:59 +0300 Subject: [PATCH] IDEADEV-41403: only bind additional preceding comments in pass 2 when the declaration does not yet have a "doc comment" --- .../psi/impl/source/parsing/ParseUtil.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/source/parsing/ParseUtil.java b/java/java-impl/src/com/intellij/psi/impl/source/parsing/ParseUtil.java index 0177f4409289..83daa4f650c6 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/parsing/ParseUtil.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/parsing/ParseUtil.java @@ -116,12 +116,18 @@ public class ParseUtil { } }); + // we'll only bind additional preceding comments in pass 2 when the declaration does not yet have a "doc comment" + boolean docCommentBound = false; + Iterator iterator = comments.iterator(); while (iterator.hasNext()) { ASTNode child = iterator.next(); IElementType type = child.getElementType(); if (type == JavaDocElementType.DOC_COMMENT) { - if (bindDocComment((TreeElement)child)) iterator.remove(); + if (bindDocComment((TreeElement)child)) { + iterator.remove(); + docCommentBound = true; + } } // bind "trailing comments" (like "int a; // comment") else if (type == JavaTokenType.END_OF_LINE_COMMENT || type == JavaTokenType.C_STYLE_COMMENT) { @@ -130,10 +136,12 @@ public class ParseUtil { } //pass 2: bind preceding comments (like "// comment \n void f();") - for (ASTNode child : comments) { - if (child.getElementType() == JavaTokenType.END_OF_LINE_COMMENT || child.getElementType() == JavaTokenType.C_STYLE_COMMENT) { - TreeElement next = (TreeElement)TreeUtil.skipElements(child, PRECEDING_COMMENT_OR_SPACE_BIT_SET); - bindPrecedingComment((TreeElement)child, next); + if (!docCommentBound) { + for (ASTNode child : comments) { + if (child.getElementType() == JavaTokenType.END_OF_LINE_COMMENT || child.getElementType() == JavaTokenType.C_STYLE_COMMENT) { + TreeElement next = (TreeElement)TreeUtil.skipElements(child, PRECEDING_COMMENT_OR_SPACE_BIT_SET); + bindPrecedingComment((TreeElement)child, next); + } } } }