Skip to content

Commit

Permalink
Fix line filtering: cannot remove line, if it was previously used
Browse files Browse the repository at this point in the history
  • Loading branch information
zuevmaxim committed Jun 21, 2024
1 parent ae16d8e commit 6c4d33d
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ private void tryRemoveLine() {
@Override
public void visitLineNumber(int line, Label start) {
tryRemoveLine();
myState = -1;
// do not remove lines that are previously used
myState = myContext.getLineData(line) == null ? -1 : 0;
myCurrentLine = line;
super.visitLineNumber(line, start);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ private void tryRemoveLine() {
@Override
public void visitLineNumber(int line, Label start) {
tryRemoveLine();
myState = -1;
// do not remove lines that are previously used
myState = myContext.getLineData(line) == null ? -1 : 0;
myCurrentLine = line;
super.visitLineNumber(line, start);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ public void visitInsn(int opcode) {
@Override
public void visitLineNumber(int line, Label start) {
tryRemoveLine();
boolean lineExists = myContext.getLineData(line) != null;
super.visitLineNumber(line, start);
myCurrentLine = line;
if (myState == State.USER_CODE) {
if (lineExists) {
// do not remove lines that are previously used
myState = State.USER_CODE;
} else if (myState == State.USER_CODE) {
myState = State.INITIAL;
} else if (myState == State.TRY_START_USER) {
myState = State.TRY_START;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ public void visitInsn(int opcode) {
@Override
public void visitLineNumber(int line, Label start) {
tryRemoveLine();
// do not remove lines that are previously used
myState = myContext.getLineData(line) == null ? State.INITIAL : State.USER_CODE;
super.visitLineNumber(line, start);
myCurrentLine = line;
myState = State.INITIAL;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ private void tryRemoveLine() {
public void visitLineNumber(int line, Label start) {
myCandidates.put(myCurrentLine, myHasInstructions ? -1 : myState);
tryRemoveLine();
// do not remove lines that are previously used
myHasInstructions = myContext.getLineData(line) != null;
super.visitLineNumber(line, start);
myCurrentLine = line;

int previousState = myCandidates.get(myCurrentLine);
myState = previousState == 0 ? 1 : previousState;
myHasInstructions = false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ private void tryRemoveLine() {
@Override
public void visitLineNumber(int line, Label start) {
tryRemoveLine();
// do not remove lines that are previously used
myHasInstructions = myContext.getLineData(line) != null;
super.visitLineNumber(line, start);
myCurrentLine = line;
myState = State.INITIAL;
myHasInstructions = false;
myJumpsToRemove = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static void main(String[] args) throws IOException {

private static void test1() {
var y = new AutoCloseableImpl(); // coverage: FULL
try (y) {
System.out.println("action"); // coverage: FULL
try (y) { // coverage: FULL
System.out.println("action"); // coverage: FULL
}
System.out.println(); // coverage: FULL
}
Expand Down
38 changes: 38 additions & 0 deletions test-kotlin/test-sources11/src/testData/compose/inline/test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2000-2024 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package testData.compose.inline

import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.runDesktopComposeUiTest

@Composable
inline fun Greeting(name: String) {
Text( // coverage: FULL
text = "Hello $name!" // coverage: FULL
)
}

@OptIn(ExperimentalTestApi::class)
fun main() {
runDesktopComposeUiTest { // coverage: FULL
setContent { // coverage: FULL
Greeting("xx") // coverage: FULL
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ internal class Jdk11CoverageRunTest(override val coverage: Coverage, override va
@Test
fun testComposeDefaultArgs() = test("compose.defaultArgs")

@Test
fun testComposeInline() = test("compose.inline")

@Test
fun testComposeSynthetic() = test("compose.synthetic")

Expand Down

0 comments on commit 6c4d33d

Please sign in to comment.