-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
hypo-asm/hypo-asm-test-data/src/scenario-03/java/scenario03/TestClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package scenario03; | ||
|
||
import java.util.function.IntSupplier; | ||
|
||
// Compiled with JDK 16 | ||
public class TestClass { | ||
|
||
public IntSupplier intSupplier(Inner inner) { | ||
return () -> inner.notSynthetic; | ||
} | ||
|
||
@SuppressWarnings("InnerClassMayBeStatic") | ||
private class Inner { | ||
private int notSynthetic; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
hypo-asm/src/test/java/dev/denwav/hypo/asm/scenarios/Scenario03.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Hypo, an extensible and pluggable Java bytecode analytical model. | ||
* | ||
* Copyright (C) 2021 Kyle Wood (DenWav) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Lesser GNU General Public License as published by | ||
* the Free Software Foundation, version 3 of the License only. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package dev.denwav.hypo.asm.scenarios; | ||
|
||
import dev.denwav.hypo.model.data.FieldData; | ||
import dev.denwav.hypo.model.data.MethodData; | ||
import dev.denwav.hypo.model.data.MethodDescriptor; | ||
import dev.denwav.hypo.model.data.types.ClassType; | ||
import dev.denwav.hypo.model.data.types.PrimitiveType; | ||
import dev.denwav.hypo.test.framework.TestScenarioBase; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@DisplayName("[asm] Scenario 03 - Synthetic members (Java 16)") | ||
public class Scenario03 extends TestScenarioBase { | ||
|
||
@Override | ||
public @NotNull Env env() { | ||
return () -> "scenario-03"; | ||
} | ||
|
||
@Test | ||
@DisplayName("Test expected synthetic members are synthetic") | ||
public void testSyntheticMembers() throws Exception { | ||
final var testClass = this.context().getProvider().findClass("scenario03/TestClass"); | ||
final var inner = this.context().getProvider().findClass("scenario03/TestClass$Inner"); | ||
|
||
final MethodData intSupplierSynth = testClass.method("lambda$intSupplier$0", MethodDescriptor.parseDescriptor("(Lscenario03/TestClass$Inner;)I")); | ||
assertTrue(intSupplierSynth.isSynthetic()); | ||
|
||
final FieldData innerSyntheticOuterThisField = inner.field("this$0", new ClassType("scenario03.TestClass")); | ||
assertTrue(innerSyntheticOuterThisField.isSynthetic()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test declared members are not synthetic") | ||
public void testNonSyntheticMembers() throws Exception { | ||
final var testClass = this.context().getProvider().findClass("scenario03/TestClass"); | ||
final var inner = this.context().getProvider().findClass("scenario03/TestClass$Inner"); | ||
|
||
final MethodData intSupplier = testClass.method("intSupplier", MethodDescriptor.parseDescriptor("(Lscenario03/TestClass$Inner;)Ljava/util/function/IntSupplier;")); | ||
assertFalse(intSupplier.isSynthetic()); | ||
|
||
final FieldData innerDeclaredField = inner.field("notSynthetic", PrimitiveType.INT); | ||
assertFalse(innerDeclaredField.isSynthetic()); | ||
} | ||
} |