From 3f04ea045d6523bd1143f96cac9e8bcd0c20d289 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Mon, 28 Jul 2025 10:38:34 -0500 Subject: [PATCH] Fix formatting of channel factories Signed-off-by: Ben Sherman --- .../nextflow/script/formatter/Formatter.java | 2 +- .../java/nextflow/script/types/Types.java | 22 +++++++++++++++++-- .../formatter/ScriptFormatterTest.groovy | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/modules/nf-lang/src/main/java/nextflow/script/formatter/Formatter.java b/modules/nf-lang/src/main/java/nextflow/script/formatter/Formatter.java index 7f83cd24b1..c907c2bb72 100644 --- a/modules/nf-lang/src/main/java/nextflow/script/formatter/Formatter.java +++ b/modules/nf-lang/src/main/java/nextflow/script/formatter/Formatter.java @@ -284,7 +284,7 @@ public void visitMethodCallExpression(MethodCallExpression node) { visit(receiver); if( inWrappedMethodChain ) { incIndent(); - if( !(receiver instanceof ClassExpression) ) { + if( !nextflow.script.types.Types.isNamespace(receiver.getType()) ) { appendNewLine(); appendIndent(); } diff --git a/modules/nf-lang/src/main/java/nextflow/script/types/Types.java b/modules/nf-lang/src/main/java/nextflow/script/types/Types.java index 84000f0590..77911a4f4d 100644 --- a/modules/nf-lang/src/main/java/nextflow/script/types/Types.java +++ b/modules/nf-lang/src/main/java/nextflow/script/types/Types.java @@ -25,6 +25,7 @@ import groovy.lang.GString; import groovy.lang.Tuple2; import nextflow.script.ast.ASTNodeMarker; +import nextflow.script.dsl.DslScope; import nextflow.script.dsl.Namespace; import nextflow.script.types.shim.ShimType; import org.codehaus.groovy.GroovyBugError; @@ -91,6 +92,24 @@ public static boolean isAssignableFrom(Class target, Class source) { return target.equals(source); } + /** + * Determine whether a class is a DSL scope. + * + * @param cn + */ + public static boolean isDslScope(ClassNode cn) { + return cn.implementsInterface(ClassHelper.makeCached(DslScope.class)); + } + + /** + * Determine whether a class is a namespace. + * + * @param cn + */ + public static boolean isNamespace(ClassNode cn) { + return cn.implementsInterface(ClassHelper.makeCached(Namespace.class)); + } + /** * Given a method node corresponding to a built-in constant, determine * whether the constant is a namespace. @@ -98,8 +117,7 @@ public static boolean isAssignableFrom(Class target, Class source) { * @param mn */ public static boolean isNamespace(MethodNode mn) { - var cn = mn.getReturnType(); - return hasTypeClass(cn) && Namespace.class.isAssignableFrom(cn.getTypeClass()); + return isNamespace(mn.getReturnType()); } /** diff --git a/modules/nf-lang/src/test/groovy/nextflow/script/formatter/ScriptFormatterTest.groovy b/modules/nf-lang/src/test/groovy/nextflow/script/formatter/ScriptFormatterTest.groovy index effbd7311e..4f39d9c446 100644 --- a/modules/nf-lang/src/test/groovy/nextflow/script/formatter/ScriptFormatterTest.groovy +++ b/modules/nf-lang/src/test/groovy/nextflow/script/formatter/ScriptFormatterTest.groovy @@ -341,11 +341,11 @@ class ScriptFormatterTest extends Specification { expect: checkFormat( '''\ - Channel.of( 1, 2, 3 ) + channel.of( 1, 2, 3 ) .multiMap{v->foo:bar:v}.set{result} ''', '''\ - Channel.of(1, 2, 3) + channel.of(1, 2, 3) .multiMap { v -> foo: bar: v } .set { result } '''