From 9a1b6c9a69deaf3788c1999d0cc84ce109d485c7 Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Mon, 16 Dec 2024 20:57:40 +0100 Subject: [PATCH 1/2] setup basic publishing to paper repo --- .github/renovate.json | 19 -------------- .github/workflows/build-prs.yml | 24 ----------------- .github/workflows/deploy-snapshot.yml | 29 +++++++++++++++++++++ .github/workflows/deploy.yml | 33 ++++++++++++++++++++++++ .github/workflows/publish-jcc.yml | 20 --------------- .github/workflows/publish-prs.yml | 29 --------------------- .github/workflows/release.yml | 29 --------------------- .github/workflows/test.yml | 22 ++++++++++++++++ api/build.gradle | 14 ---------- build.gradle | 34 ------------------------ build.gradle.kts | 37 +++++++++++++++++++++++++++ cli/build.gradle | 13 ---------- gradle.properties | 2 ++ 13 files changed, 123 insertions(+), 182 deletions(-) delete mode 100644 .github/renovate.json delete mode 100644 .github/workflows/build-prs.yml create mode 100644 .github/workflows/deploy-snapshot.yml create mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/publish-jcc.yml delete mode 100644 .github/workflows/publish-prs.yml delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml delete mode 100644 build.gradle create mode 100644 build.gradle.kts diff --git a/.github/renovate.json b/.github/renovate.json deleted file mode 100644 index 063c921..0000000 --- a/.github/renovate.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "github>neoforged/actions:renovate_preset" - ], - "packageRules": [ - { - "matchDatasources": [ - "maven" - ], - "registryUrls": [ - "https://www.jetbrains.com/intellij-repository/releases/" - ], - "matchPackageNames": [ - "/^com\\.jetbrains\\.intellij/" - ] - } - ] -} diff --git a/.github/workflows/build-prs.yml b/.github/workflows/build-prs.yml deleted file mode 100644 index 082c182..0000000 --- a/.github/workflows/build-prs.yml +++ /dev/null @@ -1,24 +0,0 @@ -# File generated by the GradleUtils `setupGitHubActionsWorkflows` task, avoid modifying it directly -# The template can be found at https://github.com/neoforged/GradleUtils/blob/72be0f55ce3f6e91f89cfd7847143b9ef1dcc3e9/src/actionsTemplate/resources/.github/workflows/build-prs.yml - -name: Build and test PRs - -on: - pull_request: - types: - - synchronize - - opened - - ready_for_review - - reopened - push: - branches: - - 'feature/**' - workflow_dispatch: - -jobs: - build: - uses: neoforged/actions/.github/workflows/build-prs.yml@main - with: - java: 17 - gradle_tasks: test - jar_compatibility: false diff --git a/.github/workflows/deploy-snapshot.yml b/.github/workflows/deploy-snapshot.yml new file mode 100644 index 0000000..532901c --- /dev/null +++ b/.github/workflows/deploy-snapshot.yml @@ -0,0 +1,29 @@ +name: Deploy Snapshot +on: + push: + branches: [ 'main' ] + +jobs: + deploy: + name: Deploy Snapshot + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'temurin' + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + - name: Get project version + id: get_version + shell: bash + run: | + project_version=$(./gradlew -q --console=plain printVersion --no-daemon) + echo version=$project_version >> $GITHUB_OUTPUT + - name: Deploy snapshot version + if: endsWith(steps.get_version.outputs.version, '-SNAPSHOT') + run: ./gradlew publish --no-daemon --stacktrace + env: + ORG_GRADLE_PROJECT_paperUsername: ${{ secrets.DEPLOY_USER }} + ORG_GRADLE_PROJECT_paperPassword: ${{ secrets.DEPLOY_PASS }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..0ce60e7 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,33 @@ +name: Deploy +on: + push: + tags: [ 'v*' ] + +jobs: + deploy: + name: Deploy + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'temurin' + - uses: gradle/wrapper-validation-action@v2 + - uses: gradle/gradle-build-action@v2 + name: Deploy release + with: + arguments: build publish --no-daemon --stacktrace + env: + ORG_GRADLE_PROJECT_paperUsername: ${{ secrets.DEPLOY_USER }} + ORG_GRADLE_PROJECT_paperPassword: ${{ secrets.DEPLOY_PASS }} + - name: Parse tag + id: vars + run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT + - name: Create release and changelog + uses: MC-Machinations/auto-release-changelog@v1.1.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + title: restamp ${{ steps.vars.outputs.tag }} + files: | + build/libs/*.jar diff --git a/.github/workflows/publish-jcc.yml b/.github/workflows/publish-jcc.yml deleted file mode 100644 index b2d6028..0000000 --- a/.github/workflows/publish-jcc.yml +++ /dev/null @@ -1,20 +0,0 @@ -# File generated by the GradleUtils `setupGitHubActionsWorkflows` task, avoid modifying it directly -# The template can be found at https://github.com/neoforged/GradleUtils/blob/72be0f55ce3f6e91f89cfd7847143b9ef1dcc3e9/src/actionsTemplate/resources/.github/workflows/publish-jcc.yml - -name: Publish PR JCC output - -on: - workflow_run: - workflows: [Build and test PRs] - types: - - completed - -jobs: - publish-jcc: - if: false # Option not enabled when the workflows were generated - uses: neoforged/actions/.github/workflows/publish-jcc.yml@main - with: - beta_version_pattern: .* # Change this line if there's a clear point at which a version no longer accepts breaking changes - secrets: - JCC_GH_APP_ID: ${{ secrets.JCC_GH_APP_ID }} - JCC_GH_APP_KEY: ${{ secrets.JCC_GH_APP_KEY }} diff --git a/.github/workflows/publish-prs.yml b/.github/workflows/publish-prs.yml deleted file mode 100644 index 9bb92b4..0000000 --- a/.github/workflows/publish-prs.yml +++ /dev/null @@ -1,29 +0,0 @@ -# File generated by the GradleUtils `setupGitHubActionsWorkflows` task, avoid modifying it directly -# The template can be found at https://github.com/neoforged/GradleUtils/blob/72be0f55ce3f6e91f89cfd7847143b9ef1dcc3e9/src/actionsTemplate/resources/.github/workflows/publish-prs.yml - -name: Publish PRs to GitHub Packages - -on: - workflow_run: - workflows: [Build and test PRs] - types: - - completed - issue_comment: - types: - - edited - pull_request_target: - types: - - opened - -permissions: - packages: write - -jobs: - publish-prs: - if: true - uses: neoforged/actions/.github/workflows/publish-prs.yml@main - with: - artifact_base_path: net/neoforged/jst/ - secrets: - PR_PUBLISHING_GH_APP_ID: ${{ secrets.PR_PUBLISHING_GH_APP_ID }} - PR_PUBLISHING_GH_APP_KEY: ${{ secrets.PR_PUBLISHING_GH_APP_KEY }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 6d9f4a3..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,29 +0,0 @@ -# File generated by the GradleUtils `setupGitHubActionsWorkflows` task, avoid modifying it directly -# The template can be found at https://github.com/neoforged/GradleUtils/blob/72be0f55ce3f6e91f89cfd7847143b9ef1dcc3e9/src/actionsTemplate/resources/.github/workflows/release.yml - -name: Release - -on: - push: - branches: [ "main" ] - -permissions: - contents: read - statuses: write - -jobs: - release: - uses: neoforged/actions/.github/workflows/gradle-publish.yml@main - with: - java: 17 - pre_gradle_tasks: test - gradle_tasks: publish closeAndReleaseSonatypeStagingRepository - secrets: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - MAVEN_USER: ${{ secrets.MAVEN_USER }} - MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - SONATYPE_USER: ${{ secrets.SONATYPE_USER }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - GPG_SUBKEY: ${{ secrets.GPG_SUBKEY }} - GPG_SUBKEY_ID: ${{ secrets.GPG_SUBKEY_ID }} - GPG_SUBKEY_PASSWORD: ${{ secrets.GPG_SUBKEY_PASSWORD }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..34b52e9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: Test +on: + push: + branches: [ "**" ] + pull_request: + +jobs: + test: + # Only run on PRs if the source branch is on someone else's repo + if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }} + name: Test + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'temurin' + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + - name: Execute Gradle build + run: ./gradlew build --no-daemon --stacktrace diff --git a/api/build.gradle b/api/build.gradle index cc03fd5..712d06e 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -1,16 +1,8 @@ -import net.neoforged.gradleutils.PomUtilsExtension plugins { id 'java-library' - id 'maven-publish' - id 'net.neoforged.gradleutils' } -group = 'net.neoforged.jst' - -gradleutils { - setupSigning(project: project, signAllPublications: true) -} java { withSourcesJar() withJavadocJar() @@ -31,13 +23,7 @@ publishing { pom { name = 'JST API' description = 'The JavaSourceTransformer API' - rootProject.pomUtils.githubRepo(it, 'JavaSourceTransformer') - rootProject.pomUtils.neoForgedDeveloper(it) - rootProject.pomUtils.license(it, PomUtilsExtension.License.LGPL_v2) } } } - repositories { - maven gradleutils.publishingMaven - } } diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 1d0102a..0000000 --- a/build.gradle +++ /dev/null @@ -1,34 +0,0 @@ -plugins { - id 'java' - id 'maven-publish' - id 'net.neoforged.gradleutils' -} - -group = "net.neoforged.jst" -gradleutils { - setupCentralPublishing() - version { - branches.suffixBranch() - } -} -project.version = gradleutils.version - -println "Version ${project.version}" - -subprojects { - group = rootProject.group - version = rootProject.version - - apply plugin : "java" - - java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } - } - - // ensure everything uses UTF-8 and not some random codepage chosen by gradle - tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..5cf25cf --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,37 @@ +plugins { + `java-library` + `maven-publish` +} + +java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + +tasks.jar { + manifest { + attributes("Implementation-Version" to project.version) + } +} + +publishing { + repositories { + val url = if (project.version.toString().endsWith("-SNAPSHOT")) { + "https://repo.papermc.io/repository/maven-snapshots/" + } else { + "https://repo.papermc.io/repository/maven-releases/" + } + maven(url) { + credentials(PasswordCredentials::class) + name = "paper" + } + } + + publications.create("maven") { + artifactId = "jst" + from(components["java"]) + } +} + +tasks.register("printVersion") { + doFirst { + println(version) + } +} diff --git a/cli/build.gradle b/cli/build.gradle index a59db0d..bef2452 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -1,10 +1,7 @@ -import net.neoforged.gradleutils.PomUtilsExtension plugins { id 'java' id 'com.github.johnrengelman.shadow' - id 'maven-publish' - id 'net.neoforged.gradleutils' } group = 'net.neoforged.jst' @@ -15,7 +12,6 @@ jar { } } -gradleutils.setupSigning(project: project, signAllPublications: true) java { withSourcesJar() withJavadocJar() @@ -95,9 +91,6 @@ publishing { pom { name = 'JST CLI' description = 'The JavaSourceTransformer CLI' - rootProject.pomUtils.githubRepo(it, 'JavaSourceTransformer') - rootProject.pomUtils.neoForgedDeveloper(it) - rootProject.pomUtils.license(it, PomUtilsExtension.License.LGPL_v2) } } // This publication only contains the shaded standalone jar @@ -111,13 +104,7 @@ publishing { pom { name = 'JST CLI bundle' description = 'The JavaSourceTransformer CLI bundle, containing all builtin plugins shadowed' - rootProject.pomUtils.githubRepo(it, 'JavaSourceTransformer') - rootProject.pomUtils.neoForgedDeveloper(it) - rootProject.pomUtils.license(it, PomUtilsExtension.License.LGPL_v2) } } } - repositories { - maven gradleutils.publishingMaven - } } diff --git a/gradle.properties b/gradle.properties index 6e777aa..c662a82 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,5 @@ +group=io.papermc.jst +version=1.0.68-SNAPSHOT intellij_version=233.11799.300 jetbrains_annotations_version=24.1.0 From 7b55b32c11d44ad3569bf501207c4d93b0faf323 Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Tue, 17 Dec 2024 20:46:20 -0500 Subject: [PATCH 2/2] Flag to inherit access transformers on methods (#1) Useful for modifying methods exposed by types with a lot of children to avoid specifying them all. --- README.md | 3 ++ .../AccessTransformersTransformer.java | 14 +++++- .../accesstransformers/ApplyATsVisitor.java | 49 ++++++++++++++++--- .../methods_inheritance/accesstransformer.cfg | 1 + .../methods_inheritance/expected/Child.java | 6 +++ .../expected/Grandchild.java | 6 +++ .../methods_inheritance/expected/Parent.java | 5 ++ .../methods_inheritance/source/Child.java | 6 +++ .../source/Grandchild.java | 6 +++ .../methods_inheritance/source/Parent.java | 5 ++ .../accesstransformer.cfg | 1 + .../expected/Child.java | 6 +++ .../expected/Grandchild.java | 6 +++ .../expected/Parent.java | 5 ++ .../methods_no_inheritance/source/Child.java | 6 +++ .../source/Grandchild.java | 6 +++ .../methods_no_inheritance/source/Parent.java | 5 ++ .../net/neoforged/jst/tests/EmbeddedTest.java | 20 +++++++- 18 files changed, 146 insertions(+), 10 deletions(-) create mode 100644 tests/data/accesstransformer/methods_inheritance/accesstransformer.cfg create mode 100644 tests/data/accesstransformer/methods_inheritance/expected/Child.java create mode 100644 tests/data/accesstransformer/methods_inheritance/expected/Grandchild.java create mode 100644 tests/data/accesstransformer/methods_inheritance/expected/Parent.java create mode 100644 tests/data/accesstransformer/methods_inheritance/source/Child.java create mode 100644 tests/data/accesstransformer/methods_inheritance/source/Grandchild.java create mode 100644 tests/data/accesstransformer/methods_inheritance/source/Parent.java create mode 100644 tests/data/accesstransformer/methods_no_inheritance/accesstransformer.cfg create mode 100644 tests/data/accesstransformer/methods_no_inheritance/expected/Child.java create mode 100644 tests/data/accesstransformer/methods_no_inheritance/expected/Grandchild.java create mode 100644 tests/data/accesstransformer/methods_no_inheritance/expected/Parent.java create mode 100644 tests/data/accesstransformer/methods_no_inheritance/source/Child.java create mode 100644 tests/data/accesstransformer/methods_no_inheritance/source/Grandchild.java create mode 100644 tests/data/accesstransformer/methods_no_inheritance/source/Parent.java diff --git a/README.md b/README.md index 7550448..c6ff7ba 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,9 @@ Plugin - parchment Plugin - accesstransformers --access-transformer= + --access-transformer-inherit-method + Whether or not access transformers on methods should be inherited from + parent types --access-transformer-validation= The level of validation to use for ats --enable-accesstransformers diff --git a/accesstransformers/src/main/java/net/neoforged/jst/accesstransformers/AccessTransformersTransformer.java b/accesstransformers/src/main/java/net/neoforged/jst/accesstransformers/AccessTransformersTransformer.java index c70f4fb..76452b7 100644 --- a/accesstransformers/src/main/java/net/neoforged/jst/accesstransformers/AccessTransformersTransformer.java +++ b/accesstransformers/src/main/java/net/neoforged/jst/accesstransformers/AccessTransformersTransformer.java @@ -25,6 +25,12 @@ public class AccessTransformersTransformer implements SourceTransformer { @CommandLine.Option(names = "--access-transformer-validation", description = "The level of validation to use for ats") public AccessTransformerValidation validation = AccessTransformerValidation.LOG; + @CommandLine.Option( + names = "--access-transformer-inherit-method", + description = "Whether or not access transformers on methods should be inherited from parent types" + ) + public boolean inheritMethodAccessTransformers = false; + private AccessTransformerFiles ats; private Map pendingATs; private Logger logger; @@ -64,7 +70,13 @@ public boolean afterRun(TransformContext context) { @Override public void visitFile(PsiFile psiFile, Replacements replacements) { - var visitor = new ApplyATsVisitor(ats, replacements, pendingATs, logger); + var visitor = new ApplyATsVisitor( + ats, + replacements, + pendingATs, + this.inheritMethodAccessTransformers, + logger + ); visitor.visitFile(psiFile); if (visitor.errored) { errored = true; diff --git a/accesstransformers/src/main/java/net/neoforged/jst/accesstransformers/ApplyATsVisitor.java b/accesstransformers/src/main/java/net/neoforged/jst/accesstransformers/ApplyATsVisitor.java index 2cfce18..923247a 100644 --- a/accesstransformers/src/main/java/net/neoforged/jst/accesstransformers/ApplyATsVisitor.java +++ b/accesstransformers/src/main/java/net/neoforged/jst/accesstransformers/ApplyATsVisitor.java @@ -14,7 +14,6 @@ import com.intellij.psi.PsiRecursiveElementVisitor; import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.util.ClassUtil; -import com.intellij.psi.util.PsiClassUtil; import net.neoforged.accesstransformer.parser.AccessTransformerFiles; import net.neoforged.accesstransformer.parser.Target; import net.neoforged.accesstransformer.parser.Transformation; @@ -46,12 +45,20 @@ class ApplyATsVisitor extends PsiRecursiveElementVisitor { private final AccessTransformerFiles ats; private final Replacements replacements; private final Map pendingATs; + private final boolean inheritMethodATs; private final Logger logger; boolean errored = false; - public ApplyATsVisitor(AccessTransformerFiles ats, Replacements replacements, Map pendingATs, Logger logger) { + public ApplyATsVisitor( + AccessTransformerFiles ats, + Replacements replacements, + Map pendingATs, + boolean inheritMethodATs, + Logger logger + ) { this.ats = ats; this.replacements = replacements; + this.inheritMethodATs = inheritMethodATs; this.logger = logger; this.pendingATs = pendingATs; } @@ -61,7 +68,25 @@ public void visitElement(@NotNull PsiElement element) { if (element instanceof PsiClass psiClass) { if (psiClass.getQualifiedName() != null) { String className = ClassUtil.getJVMClassName(psiClass); - if (!ats.containsClassTarget(className)) { + boolean shouldBeSkipped = !ats.containsClassTarget(className); + + // Classes may need changing that are not in the source at set. + // Check if any of this classe's parents are in the source at set first to potentially inherit their ATs. + if (shouldBeSkipped && this.inheritMethodATs) { + for ( + PsiClass parentType = psiClass.getSuperClass(); + parentType != null; + parentType = parentType.getSuperClass() + ) { + if (this.ats.containsClassTarget(ClassUtil.getJVMClassName(parentType))) { + // Process class as we inherit method ATs and we found *some* AT. + // Heuristic isn't perfect, but the alternative would be scanning *all* method targets for the parent owning type. + shouldBeSkipped = false; + break; + } + } + } + if (shouldBeSkipped) { // Skip this class and its children, but not the inner classes for (PsiClass innerClass : psiClass.getInnerClasses()) { visitElement(innerClass); @@ -106,10 +131,20 @@ public void visitElement(@NotNull PsiElement element) { apply(pendingATs.remove(new Target.FieldTarget(className, field.getName())), field, cls); } } else if (element instanceof PsiMethod method) { - final var cls = method.getContainingClass(); - if (cls != null && cls.getQualifiedName() != null) { - String className = ClassUtil.getJVMClassName(cls); - apply(pendingATs.remove(method(className, method)), method, cls); + final var owningType = method.getContainingClass(); + if (owningType != null) { + // Locate transformation by searching owning type and its parents. + // Remove if this is AT is defined for its immediate owning type. + Transformation foundTransformation = this.pendingATs.remove(method(ClassUtil.getJVMClassName(owningType), method)); + PsiClass definedForSuperType = owningType; + for (; + this.inheritMethodATs && foundTransformation == null && definedForSuperType != null && definedForSuperType.getQualifiedName() != null; + definedForSuperType = definedForSuperType.getSuperClass() + ) { + foundTransformation = this.ats.getAccessTransformers().get(method(ClassUtil.getJVMClassName(definedForSuperType), method)); + } + + apply(foundTransformation, method, owningType); } } diff --git a/tests/data/accesstransformer/methods_inheritance/accesstransformer.cfg b/tests/data/accesstransformer/methods_inheritance/accesstransformer.cfg new file mode 100644 index 0000000..a6a2ef9 --- /dev/null +++ b/tests/data/accesstransformer/methods_inheritance/accesstransformer.cfg @@ -0,0 +1 @@ +public Parent flag()Z diff --git a/tests/data/accesstransformer/methods_inheritance/expected/Child.java b/tests/data/accesstransformer/methods_inheritance/expected/Child.java new file mode 100644 index 0000000..8057da2 --- /dev/null +++ b/tests/data/accesstransformer/methods_inheritance/expected/Child.java @@ -0,0 +1,6 @@ +class Child extends Parent { + @Override + public boolean flag() { + return true; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_inheritance/expected/Grandchild.java b/tests/data/accesstransformer/methods_inheritance/expected/Grandchild.java new file mode 100644 index 0000000..9c42ae0 --- /dev/null +++ b/tests/data/accesstransformer/methods_inheritance/expected/Grandchild.java @@ -0,0 +1,6 @@ +class Grandchild extends Child { + @Override + public boolean flag() { + return false; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_inheritance/expected/Parent.java b/tests/data/accesstransformer/methods_inheritance/expected/Parent.java new file mode 100644 index 0000000..ed8b47f --- /dev/null +++ b/tests/data/accesstransformer/methods_inheritance/expected/Parent.java @@ -0,0 +1,5 @@ +class Parent { + public boolean flag() { + return false; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_inheritance/source/Child.java b/tests/data/accesstransformer/methods_inheritance/source/Child.java new file mode 100644 index 0000000..66a5567 --- /dev/null +++ b/tests/data/accesstransformer/methods_inheritance/source/Child.java @@ -0,0 +1,6 @@ +class Child extends Parent { + @Override + protected boolean flag() { + return true; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_inheritance/source/Grandchild.java b/tests/data/accesstransformer/methods_inheritance/source/Grandchild.java new file mode 100644 index 0000000..f55e09b --- /dev/null +++ b/tests/data/accesstransformer/methods_inheritance/source/Grandchild.java @@ -0,0 +1,6 @@ +class Grandchild extends Child { + @Override + protected boolean flag() { + return false; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_inheritance/source/Parent.java b/tests/data/accesstransformer/methods_inheritance/source/Parent.java new file mode 100644 index 0000000..7d8caad --- /dev/null +++ b/tests/data/accesstransformer/methods_inheritance/source/Parent.java @@ -0,0 +1,5 @@ +class Parent { + protected boolean flag() { + return false; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_no_inheritance/accesstransformer.cfg b/tests/data/accesstransformer/methods_no_inheritance/accesstransformer.cfg new file mode 100644 index 0000000..a6a2ef9 --- /dev/null +++ b/tests/data/accesstransformer/methods_no_inheritance/accesstransformer.cfg @@ -0,0 +1 @@ +public Parent flag()Z diff --git a/tests/data/accesstransformer/methods_no_inheritance/expected/Child.java b/tests/data/accesstransformer/methods_no_inheritance/expected/Child.java new file mode 100644 index 0000000..66a5567 --- /dev/null +++ b/tests/data/accesstransformer/methods_no_inheritance/expected/Child.java @@ -0,0 +1,6 @@ +class Child extends Parent { + @Override + protected boolean flag() { + return true; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_no_inheritance/expected/Grandchild.java b/tests/data/accesstransformer/methods_no_inheritance/expected/Grandchild.java new file mode 100644 index 0000000..f55e09b --- /dev/null +++ b/tests/data/accesstransformer/methods_no_inheritance/expected/Grandchild.java @@ -0,0 +1,6 @@ +class Grandchild extends Child { + @Override + protected boolean flag() { + return false; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_no_inheritance/expected/Parent.java b/tests/data/accesstransformer/methods_no_inheritance/expected/Parent.java new file mode 100644 index 0000000..ed8b47f --- /dev/null +++ b/tests/data/accesstransformer/methods_no_inheritance/expected/Parent.java @@ -0,0 +1,5 @@ +class Parent { + public boolean flag() { + return false; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_no_inheritance/source/Child.java b/tests/data/accesstransformer/methods_no_inheritance/source/Child.java new file mode 100644 index 0000000..66a5567 --- /dev/null +++ b/tests/data/accesstransformer/methods_no_inheritance/source/Child.java @@ -0,0 +1,6 @@ +class Child extends Parent { + @Override + protected boolean flag() { + return true; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_no_inheritance/source/Grandchild.java b/tests/data/accesstransformer/methods_no_inheritance/source/Grandchild.java new file mode 100644 index 0000000..f55e09b --- /dev/null +++ b/tests/data/accesstransformer/methods_no_inheritance/source/Grandchild.java @@ -0,0 +1,6 @@ +class Grandchild extends Child { + @Override + protected boolean flag() { + return false; + } +} \ No newline at end of file diff --git a/tests/data/accesstransformer/methods_no_inheritance/source/Parent.java b/tests/data/accesstransformer/methods_no_inheritance/source/Parent.java new file mode 100644 index 0000000..7d8caad --- /dev/null +++ b/tests/data/accesstransformer/methods_no_inheritance/source/Parent.java @@ -0,0 +1,5 @@ +class Parent { + protected boolean flag() { + return false; + } +} \ No newline at end of file diff --git a/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java b/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java index 082c293..0beb39d 100644 --- a/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java +++ b/tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java @@ -1,5 +1,6 @@ package net.neoforged.jst.tests; +import com.intellij.util.ArrayUtil; import net.neoforged.jst.cli.Main; import org.assertj.core.util.CanIgnoreReturnValue; import org.junit.jupiter.api.BeforeEach; @@ -286,6 +287,16 @@ void testImplicitConstructors() throws Exception { void testIllegal() throws Exception { runATTest("illegal"); } + + @Test + void testMethodsNoInheritance() throws Exception { + runATTest("methods_no_inheritance"); + } + + @Test + void testMethodsInheritance() throws Exception { + runATTest("methods_inheritance", "--access-transformer-inherit-method"); + } } @Nested @@ -350,10 +361,15 @@ protected final void runInterfaceInjectionTest(String testDirName, Path tempDir, } } - protected final void runATTest(String testDirName) throws Exception { + protected final void runATTest(String testDirName, final String... extraArgs) throws Exception { testDirName = "accesstransformer/" + testDirName; var atPath = testDataRoot.resolve(testDirName).resolve("accesstransformer.cfg"); - runTest(testDirName, txt -> txt.replace(atPath.toAbsolutePath().toString(), "{atpath}"), "--enable-accesstransformers", "--access-transformer", atPath.toString()); + runTest(testDirName, txt -> txt.replace(atPath.toAbsolutePath().toString(), "{atpath}"), ArrayUtil.mergeArrays( + new String[]{ + "--enable-accesstransformers", "--access-transformer", atPath.toString() + }, + extraArgs + )); } protected final void runParchmentTest(String testDirName, String mappingsFilename) throws Exception {