Skip to content

Commit 44355cd

Browse files
committed
Fix formatting of channel factories
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent d19284e commit 44355cd

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

modules/nf-lang/src/main/java/nextflow/script/ast/ASTUtils.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.Optional;
2222
import java.util.stream.Stream;
2323

24+
import nextflow.script.dsl.DslScope;
25+
import nextflow.script.dsl.Namespace;
2426
import org.codehaus.groovy.ast.ClassHelper;
2527
import org.codehaus.groovy.ast.ClassNode;
2628
import org.codehaus.groovy.ast.AnnotatedNode;
@@ -179,4 +181,25 @@ public static Optional<AnnotationNode> findAnnotation(AnnotatedNode node, Class
179181
.filter(an -> an.getClassNode().getName().equals(type.getName()))
180182
.findFirst();
181183
}
184+
185+
/**
186+
* Determine whether a class is a DSL scope.
187+
*
188+
* @param cn
189+
* @return
190+
*/
191+
public static boolean isDslScope(ClassNode cn) {
192+
return cn.implementsInterface(ClassHelper.makeCached(DslScope.class));
193+
}
194+
195+
/**
196+
* Determine whether a class is a namespace.
197+
*
198+
* @param cn
199+
* @return
200+
*/
201+
public static boolean isNamespace(ClassNode cn) {
202+
return cn.implementsInterface(ClassHelper.makeCached(Namespace.class));
203+
}
204+
182205
}

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( !isNamespace(receiver.getType()) ) {
288288
appendNewLine();
289289
appendIndent();
290290
}

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)