use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.
the class HoverProvider method provideHoverAtom.
/**
* Provide hover for an atom.
* @param magikFile Magik file.
* @param atomNode Atom node hovered on.
* @param builder Builder to add text to.
*/
private void provideHoverAtom(final MagikTypedFile magikFile, final AstNode atomNode, final StringBuilder builder) {
final LocalTypeReasoner reasoner = magikFile.getTypeReasoner();
final ExpressionResult result = reasoner.getNodeTypeSilent(atomNode);
if (result != null) {
LOGGER.debug("Providing hover for node: {}", atomNode.getTokenValue());
final ITypeKeeper typeKeeper = magikFile.getTypeKeeper();
this.buildTypeDoc(typeKeeper, reasoner, atomNode, builder);
}
}
use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper 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.typing.ITypeKeeper in project magik-tools by StevenLooman.
the class HoverProvider method provideHoverMethodInvocation.
/**
* Provide hover for a method invocation.
* @param magikFile Magik file.
* @param hoveredNode Hovered node.
* @param builder Builder to add text to.
*/
private void provideHoverMethodInvocation(final MagikTypedFile magikFile, final AstNode hoveredNode, final StringBuilder builder) {
final AstNode providingNode = hoveredNode.getParent();
final AstNode previousSiblingNode = providingNode.getPreviousSibling();
if (previousSiblingNode != null) {
final MethodInvocationNodeHelper helper = new MethodInvocationNodeHelper(providingNode);
final String methodName = helper.getMethodName();
LOGGER.debug("Providing hover for node: {}, method: {}", previousSiblingNode.getTokenValue(), methodName);
if (methodName != null) {
final ITypeKeeper typeKeeper = magikFile.getTypeKeeper();
final LocalTypeReasoner reasoner = magikFile.getTypeReasoner();
this.buildMethodDoc(typeKeeper, reasoner, previousSiblingNode, methodName, builder);
}
}
}
use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.
the class NewDocTypeExistsTypeCheck method checkDefinitionLoops.
private void checkDefinitionLoops(final NewDocParser newDocParser, final String pakkage) {
// Test @loop types.
final ITypeKeeper typeKeeper = this.getTypeKeeper();
final TypeParser typeParser = new TypeParser(typeKeeper);
newDocParser.getLoopTypeNodes().entrySet().stream().filter(entry -> typeParser.parseTypeString(entry.getValue(), pakkage) == UndefinedType.INSTANCE).forEach(entry -> {
final AstNode typeNode = entry.getKey();
final String typeName = entry.getValue();
final String message = String.format(MESSAGE, typeName);
this.addIssue(typeNode, message);
});
}
use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.
the class NewDocTypeExistsTypeCheck method walkPostProcedureInvocation.
@Override
protected void walkPostProcedureInvocation(final AstNode node) {
if (!DefSlottedExemplarParser.isDefSlottedExemplar(node)) {
return;
}
final ITypeKeeper typeKeeper = this.getTypeKeeper();
final TypeParser typeParser = new TypeParser(typeKeeper);
// Get slot defintions.
final AstNode statementNode = node.getFirstAncestor(MagikGrammar.STATEMENT);
final NewDocParser newDocParser = new NewDocParser(statementNode);
final Map<AstNode, String> slotTypeNodes = newDocParser.getSlotTypeNodes();
final PackageNodeHelper helper = new PackageNodeHelper(node);
final String currentPakkage = helper.getCurrentPackage();
// Test slot types.
slotTypeNodes.entrySet().stream().filter(entry -> {
final AbstractType type = typeParser.parseTypeString(entry.getValue(), currentPakkage);
return type == UndefinedType.INSTANCE;
}).forEach(entry -> {
final AstNode typeNode = entry.getKey();
final String typeName = entry.getValue();
final String message = String.format(MESSAGE, typeName);
this.addIssue(typeNode, message);
});
}
Aggregations