Skip to content

Commit

Permalink
Fix hover hint for getter fields
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <[email protected]>
  • Loading branch information
bentsherman committed Nov 23, 2024
1 parent f80cc91 commit 390a0c0
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import nextflow.script.ast.FeatureFlagNode;
import nextflow.script.ast.IncludeVariable;
import nextflow.script.dsl.Constant;
import nextflow.script.dsl.Description;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.FieldNode;
Expand All @@ -42,6 +44,8 @@
import org.codehaus.groovy.ast.expr.VariableExpression;
import org.codehaus.groovy.ast.stmt.BlockStatement;

import static nextflow.script.ast.ASTHelpers.*;

/**
* Utility methods for querying an AST.
*
Expand Down Expand Up @@ -170,10 +174,30 @@ public static ClassNode getTypeOfNode(ASTNode node, ASTNodeCache ast) {
}

private static FieldNode getFieldFromExpression(PropertyExpression node, ASTNodeCache ast) {
var classNode = getTypeOfNode(node.getObjectExpression(), ast);
if( classNode == null )
var cn = getTypeOfNode(node.getObjectExpression(), ast);
if( cn == null )
return null;
return classNode.getField(node.getPropertyAsString());
var name = node.getPropertyAsString();
var result = cn.getField(name);
if( result != null )
return result;
return cn.getMethods().stream()
.filter((mn) -> {
if( !mn.isPublic() )
return false;
var an = findAnnotation(mn, Constant.class);
if( !an.isPresent() )
return false;
return name.equals(an.get().getMember("value").getText());
})
.map((mn) -> {
var fn = new FieldNode(name, 0xF, mn.getReturnType(), mn.getDeclaringClass(), null);
findAnnotation(mn, Description.class).ifPresent((an) -> {
fn.addAnnotation(an);
});
return fn;
})
.findFirst().orElse(null);
}

/**
Expand Down

0 comments on commit 390a0c0

Please sign in to comment.