Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing injecting in constructor #30

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ defaultTasks 'build'
// Basic project information
group = 'net.fabricmc'
archivesBaseName = 'sponge-mixin'
version = buildVersion
version = buildVersion + "+fabric." + fabricBuildVersion

ext.buildNumber = '0'

def ENV = System.getenv()
if (ENV.BUILD_NUMBER) {
version = version + "+build." + "${ENV.BUILD_NUMBER}"
version = version + "-build." + "${ENV.BUILD_NUMBER}"
ext.buildNumber = "${ENV.BUILD_NUMBER}"
} else {
version = version + "-build.local"
ext.buildNumber = '0'
}

// Extended project information
Expand Down Expand Up @@ -156,6 +158,9 @@ dependencies {
modlauncherCompile ('cpw.mods:modlauncher:4.2.0') {
exclude module: 'log4j-core'
}
// Fabric: only exists in runtime elements in gradle module metadata of modlauncher,
// need to declare to compile against explicitly
modlauncherImplementation 'cpw.mods:grossjava9hacks:1.3.+'

// agent
agentCompile configurations.compile
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ buildType=RELEASE
asmVersion=7.2
legacyForgeAsmVersion=5.0.3
modlauncherAsmVersion=6.2
fabricBuildVersion=1
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ public boolean checkPriority(int targetPriority, int mixinPriority) {
* @return restriction level
*/
public RestrictTargetLevel getTargetRestriction(IInjectionPointContext context) {
return RestrictTargetLevel.CONSTRUCTORS_AFTER_DELEGATE; // Fabric change: allow inject in constructors
}

/**
* Returns the target restriction level for this injection point's cancellation for
* {@literal @Inject} annotations. This level defines whether an injection point
* can declare {@code cancellable = true}.
*
* @param context injection-specific context
* @return restriction level
*/
// Fabric addition: prevent cancellation of inject in constructors
public RestrictTargetLevel getCancellationRestriction(IInjectionPointContext context) {
return RestrictTargetLevel.METHODS_ONLY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ protected void addTargetNode(Target target, List<InjectionNode> myNodes, Abstrac
throw new InvalidInjectionException(this.info, String.format("%s selector %s", ip, ex.getMessage()));
}

// Fabric start: prevent cancellation in constructor injections
if (this.cancellable) {
try {
this.checkTargetForNode(target, injectionNode, ip.getCancellationRestriction(this.info));
} catch (InvalidInjectionException ex) {
throw new InvalidInjectionException(this.info, String.format("%s selector (cancellable = true) %s", ip, ex.getMessage()));
}
}
// Fabric end

String id = ip.getId();
if (Strings.isNullOrEmpty(id)) {
continue;
Expand Down