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 2 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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ dependencies {
modlauncherCompile ('cpw.mods:modlauncher:4.2.0') {
exclude module: 'log4j-core'
}
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,18 @@ public boolean checkPriority(int targetPriority, int mixinPriority) {
* @return restriction level
*/
public RestrictTargetLevel getTargetRestriction(IInjectionPointContext context) {
return RestrictTargetLevel.CONSTRUCTORS_AFTER_DELEGATE;
}

/**
* 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
*/
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,14 @@ protected void addTargetNode(Target target, List<InjectionNode> myNodes, Abstrac
throw new InvalidInjectionException(this.info, String.format("%s selector %s", ip, ex.getMessage()));
}

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()));
}
}

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