Search in sources :

Example 1 with Slot

use of nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition.Slot in project magik-tools by StevenLooman.

the class NewDocCheck method walkPostProcedureInvocation.

@Override
protected void walkPostProcedureInvocation(AstNode node) {
    if (!DefSlottedExemplarParser.isDefSlottedExemplar(node)) {
        return;
    }
    // Get slot defintions.
    final AstNode statementNode = node.getFirstAncestor(MagikGrammar.STATEMENT);
    final NewDocParser newDocParser = new NewDocParser(statementNode);
    final Map<String, AstNode> docSlotNameNodes = newDocParser.getSlotNameNodes();
    final DefSlottedExemplarParser parser = new DefSlottedExemplarParser(node);
    final List<Definition> definitions = parser.parseDefinitions();
    final SlottedExemplarDefinition exemplarDefinition = (SlottedExemplarDefinition) definitions.get(0);
    final List<Slot> slots = exemplarDefinition.getSlots();
    final Map<String, Slot> slotNames = slots.stream().collect(Collectors.toMap(Slot::getName, slot -> slot));
    // Compare parameters.
    docSlotNameNodes.entrySet().stream().filter(entry -> !slotNames.containsKey(entry.getKey())).forEach(entry -> {
        final String docName = entry.getKey();
        final AstNode docNode = entry.getValue();
        final String message = String.format(MESSAGE_SLOT_UNKNOWN, docName);
        this.addIssue(docNode, message);
    });
    slotNames.entrySet().stream().filter(entry -> !docSlotNameNodes.containsKey(entry.getKey())).forEach(entry -> {
        final String docName = entry.getKey();
        final AstNode docNode = entry.getValue().getNode();
        final String message = String.format(MESSAGE_SLOT_MISSING, docName);
        this.addIssue(docNode, message);
    });
}
Also used : NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) AstNode(com.sonar.sslr.api.AstNode) Slot(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition.Slot) MagikCheck(nl.ramsolutions.sw.magik.checks.MagikCheck) DefSlottedExemplarParser(nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser) SlottedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition) MethodDefinitionNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper) NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) Collectors(java.util.stream.Collectors) List(java.util.List) Definition(nl.ramsolutions.sw.magik.analysis.definitions.Definition) Map(java.util.Map) ProcedureDefinitionNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ProcedureDefinitionNodeHelper) Rule(org.sonar.check.Rule) MagikGrammar(nl.ramsolutions.sw.magik.api.MagikGrammar) SlottedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition) Definition(nl.ramsolutions.sw.magik.analysis.definitions.Definition) Slot(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition.Slot) AstNode(com.sonar.sslr.api.AstNode) SlottedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition) DefSlottedExemplarParser(nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser)

Aggregations

AstNode (com.sonar.sslr.api.AstNode)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 DefSlottedExemplarParser (nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser)1 Definition (nl.ramsolutions.sw.magik.analysis.definitions.Definition)1 SlottedExemplarDefinition (nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition)1 Slot (nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition.Slot)1 MethodDefinitionNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper)1 ProcedureDefinitionNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.ProcedureDefinitionNodeHelper)1 MagikGrammar (nl.ramsolutions.sw.magik.api.MagikGrammar)1 MagikCheck (nl.ramsolutions.sw.magik.checks.MagikCheck)1 NewDocParser (nl.ramsolutions.sw.magik.parser.NewDocParser)1 Rule (org.sonar.check.Rule)1