use of com.sonar.sslr.api.AstNode 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 com.sonar.sslr.api.AstNode 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 com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.
the class MagikIndexer method handleDefinition.
private void handleDefinition(final MagikFile magikFile, final IndexedExemplarDefinition definition) {
final AstNode node = definition.getNode();
final GlobalReference globalRef = definition.getGlobalReference();
final MagikType type = this.typeKeeper.getType(globalRef) != UndefinedType.INSTANCE ? (MagikType) this.typeKeeper.getType(globalRef) : new IndexedType(globalRef);
this.typeKeeper.addType(type);
final Map<String, String> slots = Collections.emptyMap();
final List<String> parents = definition.getParents();
final MagikType defaultParentType = (MagikType) this.typeKeeper.getType(GlobalReference.of("sw:indexed_format_mixin"));
this.fillType(type, magikFile, node, globalRef.getPakkage(), slots, parents, defaultParentType);
final Path path = Paths.get(magikFile.getUri());
this.indexedTypes.get(path).add(type);
LOGGER.debug("Indexed type: {}", type);
}
use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.
the class MagikIndexer method handleDefinition.
private void handleDefinition(final MagikFile magikFile, final SlottedExemplarDefinition definition) {
final AstNode node = definition.getNode();
final GlobalReference globalRef = definition.getGlobalReference();
final MagikType type = this.typeKeeper.getType(globalRef) instanceof SlottedType ? (MagikType) this.typeKeeper.getType(globalRef) : new SlottedType(globalRef);
this.typeKeeper.addType(type);
final NewDocParser docParser = new NewDocParser(node);
final Map<String, String> slotTypes = docParser.getSlotTypes();
// This needs a default value ("") due to https://bugs.openjdk.java.net/browse/JDK-8148463
final Map<String, String> slots = definition.getSlots().stream().map(SlottedExemplarDefinition.Slot::getName).collect(Collectors.toMap(slotName -> slotName, slotName -> slotTypes.getOrDefault(slotName, "")));
final List<String> parents = definition.getParents();
final MagikType defaultParentType = (MagikType) this.typeKeeper.getType(GlobalReference.of("sw:slotted_format_mixin"));
this.fillType(type, magikFile, node, globalRef.getPakkage(), slots, parents, defaultParentType);
final Path path = Paths.get(magikFile.getUri());
this.indexedTypes.get(path).add(type);
LOGGER.debug("Indexed type: {}", type);
}
use of com.sonar.sslr.api.AstNode 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);
}
}
Aggregations