Skip to content

Commit 6a7d8a1

Browse files
committed
Save method overloads in name checker
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent 8de2339 commit 6a7d8a1

6 files changed

Lines changed: 46 additions & 33 deletions

File tree

modules/nf-lang/src/main/java/nextflow/config/control/VariableScopeVisitor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,11 @@ private void checkMethodCall(MethodCallExpression node) {
269269
if( !node.isImplicitThis() )
270270
return;
271271
var name = node.getMethodAsString();
272-
var defNode = vsc.findDslFunction(name, node);
273-
if( defNode != null )
274-
node.putNodeMetaData(ASTNodeMarker.METHOD_TARGET, defNode);
272+
var methods = vsc.findDslFunction(name, node);
273+
if( methods.size() == 1 )
274+
node.putNodeMetaData(ASTNodeMarker.METHOD_TARGET, methods.get(0));
275+
else if( !methods.isEmpty() )
276+
node.putNodeMetaData(ASTNodeMarker.METHOD_OVERLOADS, methods);
275277
else if( !KEYWORDS.contains(name) )
276278
vsc.addError("`" + name + "` is not defined", node.getMethod());
277279
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public enum ASTNodeMarker {
3939
// the verbatim text of a Groovy-style type annotation (ClassNode)
4040
LEGACY_TYPE,
4141

42+
// the list of candidate MethodNode's for a MethodCallExpression
43+
METHOD_OVERLOADS,
44+
4245
// the MethodNode targeted by a MethodCallExpression
4346
METHOD_TARGET,
4447

modules/nf-lang/src/main/java/nextflow/script/control/VariableScopeChecker.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Collections;
1919
import java.util.HashMap;
2020
import java.util.IdentityHashMap;
21+
import java.util.List;
2122
import java.util.Map;
2223
import java.util.Set;
2324

@@ -234,31 +235,42 @@ private static PropertyNode wrapMethodAsVariable(MethodNode mn, String name) {
234235
*
235236
* @param name
236237
* @param node
238+
* @param directive
237239
*/
238-
public MethodNode findDslFunction(String name, ASTNode node) {
240+
public List<MethodNode> findDslFunction(String name, ASTNode node, boolean directive) {
239241
VariableScope scope = currentScope;
240242
while( scope != null ) {
241243
ClassNode cn = scope.getClassScope();
242244
while( cn != null ) {
243-
for( var mn : cn.getMethods() ) {
244-
// built-in functions are methods not annotated as @Constant
245-
if( findAnnotation(mn, Constant.class).isPresent() )
246-
continue;
247-
if( !name.equals(mn.getName()) )
248-
continue;
249-
if( findAnnotation(mn, Deprecated.class).isPresent() )
250-
addParanoidWarning("`" + name + "` is deprecated and will be removed in a future version", node);
251-
return mn;
252-
}
253-
245+
// built-in functions are methods not annotated as @Constant
246+
var methods = cn.getDeclaredMethods(name).stream()
247+
.filter(mn -> !findAnnotation(mn, Constant.class).isPresent())
248+
.toList();
249+
250+
if( methods.size() == 1 && findAnnotation(methods.get(0), Deprecated.class).isPresent() )
251+
addParanoidWarning("`" + name + "` is deprecated and will be removed in a future version", node);
252+
253+
if( !methods.isEmpty() )
254+
return methods;
255+
256+
// directives can only come from the immediate dsl scope
257+
if( directive && scope == currentScope )
258+
return null;
259+
254260
cn = cn.getInterfaces().length > 0
255261
? cn.getInterfaces()[0]
256262
: null;
257263
}
258264
scope = scope.getParent();
259265
}
260266

261-
return includes.get(name);
267+
return includes.containsKey(name)
268+
? List.of(includes.get(name))
269+
: Collections.emptyList();
270+
}
271+
272+
public List<MethodNode> findDslFunction(String name, ASTNode node) {
273+
return findDslFunction(name, node, false);
262274
}
263275

264276
public void addWarning(String message, String tokenText, ASTNode node) {

modules/nf-lang/src/main/java/nextflow/script/control/VariableScopeVisitor.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,11 @@ private MethodCallExpression checkDirective(Statement node, String typeLabel, bo
327327
return null;
328328
}
329329
var name = call.getMethodAsString();
330-
var mn = vsc.findDslFunction(name, call.getMethod());
331-
if( mn != null )
332-
call.putNodeMetaData(ASTNodeMarker.METHOD_TARGET, mn);
330+
var methods = vsc.findDslFunction(name, call, true);
331+
if( methods.size() == 1 )
332+
call.putNodeMetaData(ASTNodeMarker.METHOD_TARGET, methods.get(0));
333+
else if( !methods.isEmpty() )
334+
node.putNodeMetaData(ASTNodeMarker.METHOD_OVERLOADS, methods);
333335
else
334336
vsc.addError("Unrecognized " + typeLabel + " `" + name + "`", node);
335337
return call;
@@ -580,12 +582,16 @@ private void checkMethodCall(MethodCallExpression node) {
580582
if( !node.isImplicitThis() )
581583
return;
582584
var name = node.getMethodAsString();
583-
var mn = vsc.findDslFunction(name, node.getMethod());
584-
if( mn != null ) {
585+
var methods = vsc.findDslFunction(name, node);
586+
if( methods.size() == 1 ) {
587+
var mn = methods.get(0);
585588
if( VariableScopeChecker.isDataflowMethod(mn) )
586589
checkDataflowMethod(node, mn);
587590
node.putNodeMetaData(ASTNodeMarker.METHOD_TARGET, mn);
588591
}
592+
else if( !methods.isEmpty() ) {
593+
node.putNodeMetaData(ASTNodeMarker.METHOD_OVERLOADS, methods);
594+
}
589595
else if( !KEYWORDS.contains(name) ) {
590596
vsc.addError("`" + name + "` is not defined", node.getMethod());
591597
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public interface TaskConfig {
214214
215215
[Read more](https://nextflow.io/docs/latest/reference/process.html#ext)
216216
""")
217-
Map<String,?> getExt();
217+
Map<String,String> getExt();
218218

219219
@Constant("fair")
220220
@Description("""

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static String typeName(ClassNode type) {
129129
builder.append(type.getUnresolvedName());
130130
else if( type.getNodeMetaData(ASTNodeMarker.FULLY_QUALIFIED) != null )
131131
builder.append(type.getName());
132-
else if( hasTypeClass(type) )
132+
else if( type.isResolved() )
133133
builder.append(getName(type.getTypeClass()));
134134
else
135135
builder.append(getName(type.getNameWithoutPackage()));
@@ -154,16 +154,6 @@ private static void genericsTypeNames(GenericsType[] genericsTypes, StringBuilde
154154
}
155155
}
156156

157-
private static boolean hasTypeClass(ClassNode type) {
158-
try {
159-
type.getTypeClass();
160-
return true;
161-
}
162-
catch( GroovyBugError e ) {
163-
return false;
164-
}
165-
}
166-
167157
public static String getName(Class type) {
168158
return getName(type.getSimpleName());
169159
}

0 commit comments

Comments
 (0)