use of nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition 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.SlottedExemplarDefinition 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.SlottedExemplarDefinition 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);
});
}
use of nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition in project magik-tools by StevenLooman.
the class DocumentSymbolProvider method convertDefinition.
private DocumentSymbol convertDefinition(final Definition definition) {
final SymbolKind symbolKind = this.symbolKindForDefinition(definition);
final DocumentSymbol documentSymbol = new DocumentSymbol(definition.getName(), symbolKind, Lsp4jConversion.rangeToLsp4j(new Range(definition.getNode())), Lsp4jConversion.rangeToLsp4j(new Range(definition.getNode())));
if (definition instanceof SlottedExemplarDefinition) {
final SlottedExemplarDefinition exemplarDefinition = (SlottedExemplarDefinition) definition;
final List<DocumentSymbol> slotSymbols = this.convertedSlotsFromDefinition(exemplarDefinition);
documentSymbol.setChildren(slotSymbols);
}
return documentSymbol;
}
use of nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition in project magik-tools by StevenLooman.
the class MagikIndexer method handleDefinition.
private void handleDefinition(final Path path, final MagikFile magikFile, final Definition definition) {
if (definition instanceof PackageDefinition) {
final PackageDefinition packageDefinition = (PackageDefinition) definition;
this.handleDefinition(magikFile, packageDefinition);
} else if (definition instanceof IndexedExemplarDefinition) {
final IndexedExemplarDefinition indexedExemplarDefinition = (IndexedExemplarDefinition) definition;
this.handleDefinition(magikFile, indexedExemplarDefinition);
} else if (definition instanceof EnumerationDefinition) {
final EnumerationDefinition enumerationDefinition = (EnumerationDefinition) definition;
this.handleDefinition(magikFile, enumerationDefinition);
} else if (definition instanceof SlottedExemplarDefinition) {
final SlottedExemplarDefinition slottedExemplarDefinition = (SlottedExemplarDefinition) definition;
this.handleDefinition(magikFile, slottedExemplarDefinition);
} else if (definition instanceof MixinDefinition) {
final MixinDefinition mixinDefinition = (MixinDefinition) definition;
this.handleDefinition(magikFile, mixinDefinition);
} else if (definition instanceof MethodDefinition) {
final MethodDefinition methodDefinition = (MethodDefinition) definition;
this.handleDefinition(magikFile, methodDefinition);
} else if (definition instanceof GlobalDefinition) {
final GlobalDefinition globalDefinition = (GlobalDefinition) definition;
this.handleDefinition(magikFile, globalDefinition);
} else if (definition instanceof BinaryOperatorDefinition) {
final BinaryOperatorDefinition binaryOperatorDefinition = (BinaryOperatorDefinition) definition;
this.handleDefinition(magikFile, binaryOperatorDefinition);
}
}
Aggregations