Skip to content

Commit 3f04ea0

Browse files
committed
Fix formatting of channel factories
Signed-off-by: Ben Sherman <[email protected]>
1 parent c3f397e commit 3f04ea0

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

modules/nf-lang/src/main/java/nextflow/script/formatter/Formatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void visitMethodCallExpression(MethodCallExpression node) {
284284
visit(receiver);
285285
if( inWrappedMethodChain ) {
286286
incIndent();
287-
if( !(receiver instanceof ClassExpression) ) {
287+
if( !nextflow.script.types.Types.isNamespace(receiver.getType()) ) {
288288
appendNewLine();
289289
appendIndent();
290290
}

modules/nf-lang/src/main/java/nextflow/script/types/Types.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import groovy.lang.GString;
2626
import groovy.lang.Tuple2;
2727
import nextflow.script.ast.ASTNodeMarker;
28+
import nextflow.script.dsl.DslScope;
2829
import nextflow.script.dsl.Namespace;
2930
import nextflow.script.types.shim.ShimType;
3031
import org.codehaus.groovy.GroovyBugError;
@@ -91,15 +92,32 @@ public static boolean isAssignableFrom(Class target, Class source) {
9192
return target.equals(source);
9293
}
9394

95+
/**
96+
* Determine whether a class is a DSL scope.
97+
*
98+
* @param cn
99+
*/
100+
public static boolean isDslScope(ClassNode cn) {
101+
return cn.implementsInterface(ClassHelper.makeCached(DslScope.class));
102+
}
103+
104+
/**
105+
* Determine whether a class is a namespace.
106+
*
107+
* @param cn
108+
*/
109+
public static boolean isNamespace(ClassNode cn) {
110+
return cn.implementsInterface(ClassHelper.makeCached(Namespace.class));
111+
}
112+
94113
/**
95114
* Given a method node corresponding to a built-in constant, determine
96115
* whether the constant is a namespace.
97116
*
98117
* @param mn
99118
*/
100119
public static boolean isNamespace(MethodNode mn) {
101-
var cn = mn.getReturnType();
102-
return hasTypeClass(cn) && Namespace.class.isAssignableFrom(cn.getTypeClass());
120+
return isNamespace(mn.getReturnType());
103121
}
104122

105123
/**

modules/nf-lang/src/test/groovy/nextflow/script/formatter/ScriptFormatterTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ class ScriptFormatterTest extends Specification {
341341
expect:
342342
checkFormat(
343343
'''\
344-
Channel.of( 1, 2, 3 )
344+
channel.of( 1, 2, 3 )
345345
.multiMap{v->foo:bar:v}.set{result}
346346
''',
347347
'''\
348-
Channel.of(1, 2, 3)
348+
channel.of(1, 2, 3)
349349
.multiMap { v -> foo: bar: v }
350350
.set { result }
351351
'''

0 commit comments

Comments
 (0)