Skip to content

Commit ea8baf2

Browse files
committed
fix issue with traits & auto package declaration
1 parent d8b4ec1 commit ea8baf2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/com/cleanroommc/groovyscript/core/mixin/groovy/ModuleNodeMixin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.cleanroommc.groovyscript.GroovyScript;
44
import com.cleanroommc.groovyscript.api.GroovyLog;
55
import com.cleanroommc.groovyscript.sandbox.FileUtil;
6+
import com.cleanroommc.groovyscript.sandbox.RunConfig;
67
import org.codehaus.groovy.ast.ModuleNode;
78
import org.codehaus.groovy.ast.PackageNode;
89
import org.codehaus.groovy.control.SourceUnit;
@@ -25,6 +26,11 @@ public abstract class ModuleNodeMixin {
2526
public void init(SourceUnit context, CallbackInfo ci) {
2627
// auto set package name
2728
String script = context.getName();
29+
if (!RunConfig.isGroovyFile(script)) {
30+
// probably not a script file
31+
// can happen with traits
32+
return;
33+
}
2834
String rel = FileUtil.relativize(GroovyScript.getScriptPath(), script);
2935
int i = rel.lastIndexOf(File.separatorChar);
3036
if (i >= 0) {
@@ -37,6 +43,11 @@ public void init(SourceUnit context, CallbackInfo ci) {
3743
@Inject(method = "setPackage", at = @At("HEAD"), cancellable = true)
3844
public void setPackage(PackageNode packageNode, CallbackInfo ci) {
3945
if (this.packageNode == null || this.context == null) return;
46+
if (!RunConfig.isGroovyFile(this.context.getName())) {
47+
// probably not a script file
48+
// can happen with traits
49+
return;
50+
}
4051
// package name was already set -> only copy data of new node
4152
String cur = this.packageNode.getName();
4253
String newName = packageNode.getName();

0 commit comments

Comments
 (0)