use of nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper in project magik-tools by StevenLooman.
the class BreakpointManager method addBreakpoint.
/**
* Add a new breakpoint to self and debugger.
*
* @param source Source.
* @param sourceBreakpoint Source breakpoint.
* @return New magik breakpoint.
* @throws IOException -
* @throws ExecutionException -
* @throws InterruptedException -
*/
MagikBreakpoint addBreakpoint(final Source source, final SourceBreakpoint sourceBreakpoint) throws IOException, InterruptedException, ExecutionException {
int line = sourceBreakpoint.getLine();
final AstNode methodNode = this.getNode(source, line);
final MethodDefinitionNodeHelper helper = new MethodDefinitionNodeHelper(methodNode);
String method = null;
int methodLine = 0;
if (methodNode == null) {
method = "<not_in_method>";
} else {
method = helper.getPakkageExemplarMethodName();
methodLine = methodNode.getTokenLine();
if (methodLine == line) {
line = 0;
}
}
String condition = sourceBreakpoint.getCondition();
return this.createBreakpoint(source, method, line, condition);
}
use of nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper in project magik-tools by StevenLooman.
the class HoverProvider method buildMethodDoc.
/**
* Build hover text for method doc.
* @param typeKeeper TypeKeeper.
* @param reasoner LocalTypeReasoner.
* @param node AstNode, METHOD_INVOCATION.
* @param methodName Name of invoked method.
* @param builder {{StringBuilder}} to fill.
*/
private void buildMethodDoc(final ITypeKeeper typeKeeper, final LocalTypeReasoner reasoner, final AstNode node, final String methodName, final StringBuilder builder) {
// Get type from reasoner.
final ExpressionResult result = reasoner.getNodeType(node);
// We know what self is.
AbstractType type = result.get(0, UndefinedType.INSTANCE);
if (type == SelfType.INSTANCE) {
final AstNode methodDefNode = node.getFirstAncestor(MagikGrammar.METHOD_DEFINITION);
if (methodDefNode == null) {
// This can happen in case of a procedure definition calling a method on _self.
type = UndefinedType.INSTANCE;
} else {
final MethodDefinitionNodeHelper helper = new MethodDefinitionNodeHelper(methodDefNode);
final GlobalReference globalRef = helper.getTypeGlobalReference();
type = typeKeeper.getType(globalRef);
}
}
// Get method info.
final Collection<Method> methods = type.getMethods(methodName);
if (methods.isEmpty()) {
this.buildMethodUnknownDoc(type, methodName, builder);
return;
}
methods.forEach(method -> this.buildMethodSignatureDoc(method, builder));
}
use of nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper in project magik-tools by StevenLooman.
the class HoverProvider method provideHoverMethodDefinition.
/**
* Provide hover for a method definition. Either the exemplar or the method name.
* @param magikFile Magik file.
* @param hoveredNode Hovered node.
* @param builder Builder to add text to.
*/
private void provideHoverMethodDefinition(final MagikTypedFile magikFile, final AstNode hoveredNode, final StringBuilder builder) {
final ITypeKeeper typeKeeper = magikFile.getTypeKeeper();
final AstNode methodDefNode = hoveredNode.getParent();
final MethodDefinitionNodeHelper methodDefHelper = new MethodDefinitionNodeHelper(methodDefNode);
final List<AstNode> identifierNodes = methodDefNode.getChildren(MagikGrammar.IDENTIFIER);
if (hoveredNode == identifierNodes.get(0)) {
// Hovered over exemplar.
final GlobalReference globalRef = methodDefHelper.getTypeGlobalReference();
LOGGER.debug("Providing hover for type: {}", globalRef);
this.buildTypeDoc(typeKeeper, globalRef, builder);
} else if (hoveredNode == identifierNodes.get(1)) {
// Hovered over method name.
final GlobalReference globalRef = methodDefHelper.getTypeGlobalReference();
final String methodName = methodDefHelper.getMethodName();
LOGGER.debug("Providing hover for type: {}, method: {}", globalRef, methodName);
this.buildMethodDoc(typeKeeper, globalRef, methodName, builder);
}
}
use of nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper in project magik-tools by StevenLooman.
the class HoverProvider method buildTypeDoc.
/**
* Build hover text for type doc.
* @param typeKeeper TypeKeeper.
* @param reasoner {{LocalTypeReasoner}} which has reasoned over the AST.
* @param node {{AstNode}} to get info from.
* @param builder {{StringBuilder}} to fill.
*/
private void buildTypeDoc(final ITypeKeeper typeKeeper, final LocalTypeReasoner reasoner, final AstNode node, final StringBuilder builder) {
// Get type from reasoner.
final ExpressionResult result = reasoner.getNodeType(node);
// We know what self is.
AbstractType type = result.get(0, UndefinedType.INSTANCE);
if (type == SelfType.INSTANCE) {
final AstNode methodDefNode = node.getFirstAncestor(MagikGrammar.METHOD_DEFINITION);
if (methodDefNode == null) {
// This can happen in case of a procedure definition calling a method on _self.
type = UndefinedType.INSTANCE;
} else {
final MethodDefinitionNodeHelper methodDefHelper = new MethodDefinitionNodeHelper(methodDefNode);
final GlobalReference globalRef = methodDefHelper.getTypeGlobalReference();
type = typeKeeper.getType(globalRef);
}
}
this.buildTypeSignatureDoc(type, builder);
}
use of nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper in project magik-tools by StevenLooman.
the class LocalTypeReasoner method getMethodOwnerType.
// endregion
private AbstractType getMethodOwnerType(final AstNode node) {
final AstNode methodDefNode = node.getFirstAncestor(MagikGrammar.METHOD_DEFINITION);
if (methodDefNode == null) {
// This can happen in case of a procedure definition calling a method on _self.
return UndefinedType.INSTANCE;
}
final MethodDefinitionNodeHelper helper = new MethodDefinitionNodeHelper(methodDefNode);
final GlobalReference globalRef = helper.getTypeGlobalReference();
return this.typeKeeper.getType(globalRef);
}
Aggregations