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 3 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
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ group = 'net.fabricmc'
archivesBaseName = 'sponge-mixin'
version = buildVersion

ext.buildNumber = '0'
ext.buildNumber = '571428'
liach marked this conversation as resolved.
Show resolved Hide resolved

def ENV = System.getenv()
if (ENV.BUILD_NUMBER) {
Expand Down Expand Up @@ -156,6 +156,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
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