Do not mark comment next to reachable child as unreachable
This commit is contained in:
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiWhiteSpace
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import org.jetbrains.jet.lexer.JetTokens
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
|
import com.intellij.psi.PsiComment
|
||||||
|
|
||||||
trait UnreachableCode {
|
trait UnreachableCode {
|
||||||
val elements: Set<JetElement>
|
val elements: Set<JetElement>
|
||||||
@@ -70,7 +71,9 @@ class UnreachableCodeImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun List<PsiElement>.removeReachableElementsWithMeaninglessSiblings(): List<PsiElement> {
|
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>()
|
val childrenToRemove = HashSet<PsiElement>()
|
||||||
fun collectSiblingsIfMeaningless(elementIndex: Int, direction: Int) {
|
fun collectSiblingsIfMeaningless(elementIndex: Int, direction: Int) {
|
||||||
|
|||||||
+22
@@ -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");
|
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")
|
@TestMetadata("deadCallInInvokeCall.kt")
|
||||||
public void testDeadCallInInvokeCall() throws Exception {
|
public void testDeadCallInInvokeCall() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInInvokeCall.kt");
|
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCallInInvokeCall.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user