use of nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser in project magik-tools by StevenLooman.
the class ExemplarSlotCountCheck method walkPreProcedureInvocation.
@Override
protected void walkPreProcedureInvocation(final AstNode node) {
if (!DefSlottedExemplarParser.isDefSlottedExemplar(node)) {
return;
}
final DefSlottedExemplarParser parser = new DefSlottedExemplarParser(node);
final List<Definition> parsedDefinitions = parser.parseDefinitions();
final SlottedExemplarDefinition definition = (SlottedExemplarDefinition) parsedDefinitions.get(0);
final int slotCount = definition.getSlots().size();
if (slotCount > this.maxSlotCount) {
final String message = String.format(MESSAGE, slotCount, this.maxSlotCount);
this.addIssue(node, message);
}
}
use of nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser 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);
});
}
Aggregations