Search in sources :

Example 1 with ITypeKeeper

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);
    }
}
Also used : ExpressionResult(nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult) LocalTypeReasoner(nl.ramsolutions.sw.magik.analysis.typing.LocalTypeReasoner) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)

Example 2 with ITypeKeeper

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);
    }
}
Also used : GlobalReference(nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference) MethodDefinitionNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) AstNode(com.sonar.sslr.api.AstNode)

Example 3 with ITypeKeeper

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);
        }
    }
}
Also used : LocalTypeReasoner(nl.ramsolutions.sw.magik.analysis.typing.LocalTypeReasoner) AstNode(com.sonar.sslr.api.AstNode) MethodInvocationNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.MethodInvocationNodeHelper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)

Example 4 with ITypeKeeper

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);
    });
}
Also used : TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) AstNode(com.sonar.sslr.api.AstNode) UndefinedType(nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType) DefSlottedExemplarParser(nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) PackageNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper) MagikTypedCheck(nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck) Map(java.util.Map) NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikGrammar(nl.ramsolutions.sw.magik.api.MagikGrammar) TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) AstNode(com.sonar.sslr.api.AstNode)

Example 5 with ITypeKeeper

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);
    });
}
Also used : NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) AstNode(com.sonar.sslr.api.AstNode) UndefinedType(nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType) DefSlottedExemplarParser(nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) PackageNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper) MagikTypedCheck(nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck) Map(java.util.Map) NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikGrammar(nl.ramsolutions.sw.magik.api.MagikGrammar) PackageNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper) TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) AstNode(com.sonar.sslr.api.AstNode)

Aggregations

ITypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)55 TypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper)38 Test (org.junit.jupiter.api.Test)34 AbstractType (nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType)20 MagikType (nl.ramsolutions.sw.magik.analysis.typing.types.MagikType)20 MagikTypedCheck (nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck)18 Position (org.eclipse.lsp4j.Position)17 AstNode (com.sonar.sslr.api.AstNode)14 GlobalReference (nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference)14 MagikTypedFile (nl.ramsolutions.sw.magik.MagikTypedFile)13 MagikIssue (nl.ramsolutions.sw.magik.checks.MagikIssue)13 Method (nl.ramsolutions.sw.magik.analysis.typing.types.Method)12 ExpressionResult (nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult)9 CompletionItem (org.eclipse.lsp4j.CompletionItem)9 URI (java.net.URI)8 List (java.util.List)8 MethodDefinitionNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper)8 LocalTypeReasoner (nl.ramsolutions.sw.magik.analysis.typing.LocalTypeReasoner)8 UndefinedType (nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType)8 MagikGrammar (nl.ramsolutions.sw.magik.api.MagikGrammar)8