use of nl.ramsolutions.sw.magik.analysis.definitions.Definition 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 nl.ramsolutions.sw.magik.analysis.definitions.Definition in project magik-tools by StevenLooman.
the class DuplicateMethodInFileCheck method walkPostMagik.
@Override
protected void walkPostMagik(final AstNode node) {
// Test for duplicates.
final Map<String, List<MethodDefinition>> definitions = this.methodDefinitions.stream().collect(Collectors.toMap(MethodDefinition::getName, List::of, (list1, list2) -> Stream.concat(list1.stream(), list2.stream()).collect(Collectors.toList())));
definitions.entrySet().stream().filter(entry -> entry.getValue().size() > 1).flatMap(entry -> entry.getValue().stream()).forEach(definition -> {
AstNode definitionNode = definition.getNode();
this.addIssue(definitionNode, MESSAGE);
});
}
use of nl.ramsolutions.sw.magik.analysis.definitions.Definition in project magik-tools by StevenLooman.
the class DuplicateMethodInFileCheck method walkPostMethodDefinition.
@Override
protected void walkPostMethodDefinition(final AstNode node) {
final MethodDefinitionParser parser = new MethodDefinitionParser(node);
final List<Definition> parsedDefinitions = parser.parseDefinitions();
if (parsedDefinitions.isEmpty()) {
// How does this happen?
return;
}
final MethodDefinition methodDefinition = (MethodDefinition) parsedDefinitions.get(0);
this.methodDefinitions.add(methodDefinition);
}
use of nl.ramsolutions.sw.magik.analysis.definitions.Definition 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.Definition 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