Do not mark comment next to reachable child as unreachable

This commit is contained in:
Svetlana Isakova
2014-06-20 19:47:58 +04:00
parent eec6fbb205
commit 8680ff4e88
3 changed files with 31 additions and 1 deletions
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiWhiteSpace
import java.util.ArrayList
import org.jetbrains.jet.lexer.JetTokens
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.PsiComment
trait UnreachableCode {
val elements: Set<JetElement>
@@ -70,7 +71,9 @@ class UnreachableCodeImpl(
}
fun List<PsiElement>.removeReachableElementsWithMeaninglessSiblings(): List<PsiElement> {
fun PsiElement.isMeaningless() = this is PsiWhiteSpace || this.getNode()?.getElementType() == JetTokens.COMMA
fun PsiElement.isMeaningless() = this is PsiWhiteSpace
|| this.getNode()?.getElementType() == JetTokens.COMMA
|| this is PsiComment
val childrenToRemove = HashSet<PsiElement>()
fun collectSiblingsIfMeaningless(elementIndex: Int, direction: Int) {
@@ -0,0 +1,22 @@
package a
fun test1() {
<!UNREACHABLE_CODE!>bar(<!>
11,
todo(),//comment1
<!UNREACHABLE_CODE!>""//comment2
)<!>
}
fun test2() {
<!UNREACHABLE_CODE!>bar(<!>11, todo()/*comment1*/, <!UNREACHABLE_CODE!>""/*comment2*/)<!>
}
fun test3() {
<!UNREACHABLE_CODE!>bar(<!>11, @l(todo()/*comment*/), <!UNREACHABLE_CODE!>"")<!>
}
fun todo() = throw Exception()
fun bar(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>s<!>: String, <!UNUSED_PARAMETER!>a<!>: Any) {}
@@ -1451,6 +1451,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commasAndWhitespaces.kt");
}
@TestMetadata("commentsInDeadCode.kt")
public void testCommentsInDeadCode() throws Exception {
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/commentsInDeadCode.kt");
}
@TestMetadata("deadCallInInvokeCall.kt")
public void testDeadCallInInvokeCall() throws Exception {
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInInvokeCall.kt");