Search in sources :

Example 1 with SlottedExemplarDefinition

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);
}
Also used : NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) Method(nl.ramsolutions.sw.magik.analysis.typing.types.Method) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) AstNode(com.sonar.sslr.api.AstNode) SlottedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition) IndexedType(nl.ramsolutions.sw.magik.analysis.typing.types.IndexedType) LoggerFactory(org.slf4j.LoggerFactory) SlottedType(nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType) Package(nl.ramsolutions.sw.magik.analysis.typing.types.Package) AliasType(nl.ramsolutions.sw.magik.analysis.typing.types.AliasType) IndexedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.IndexedExemplarDefinition) UndefinedType(nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType) EnumerationDefinition(nl.ramsolutions.sw.magik.analysis.definitions.EnumerationDefinition) Map(java.util.Map) URI(java.net.URI) Path(java.nio.file.Path) MagikGrammar(nl.ramsolutions.sw.magik.api.MagikGrammar) EnumSet(java.util.EnumSet) MethodInvocationNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.MethodInvocationNodeHelper) MethodDefinition(nl.ramsolutions.sw.magik.analysis.definitions.MethodDefinition) TypeAnnotationHandler(nl.ramsolutions.sw.magik.analysis.typing.TypeAnnotationHandler) PackageNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ParameterDefinition(nl.ramsolutions.sw.magik.analysis.definitions.ParameterDefinition) GlobalDefinition(nl.ramsolutions.sw.magik.analysis.definitions.GlobalDefinition) HashMap(java.util.HashMap) SelfType(nl.ramsolutions.sw.magik.analysis.typing.types.SelfType) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) HashSet(java.util.HashSet) TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) Location(nl.ramsolutions.sw.magik.analysis.Location) Nullable(javax.annotation.Nullable) GlobalScope(nl.ramsolutions.sw.magik.analysis.scope.GlobalScope) MagikCommentExtractor(nl.ramsolutions.sw.magik.parser.MagikCommentExtractor) GlobalReference(nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference) Token(com.sonar.sslr.api.Token) Slot(nl.ramsolutions.sw.magik.analysis.typing.types.Slot) Logger(org.slf4j.Logger) MagikFile(nl.ramsolutions.sw.magik.MagikFile) IOException(java.io.IOException) Parameter(nl.ramsolutions.sw.magik.analysis.typing.types.Parameter) NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) BinaryOperatorDefinition(nl.ramsolutions.sw.magik.analysis.definitions.BinaryOperatorDefinition) MixinDefinition(nl.ramsolutions.sw.magik.analysis.definitions.MixinDefinition) IntrinsicType(nl.ramsolutions.sw.magik.analysis.typing.types.IntrinsicType) PackageDefinition(nl.ramsolutions.sw.magik.analysis.definitions.PackageDefinition) Paths(java.nio.file.Paths) Definition(nl.ramsolutions.sw.magik.analysis.definitions.Definition) ScopeEntry(nl.ramsolutions.sw.magik.analysis.scope.ScopeEntry) Scope(nl.ramsolutions.sw.magik.analysis.scope.Scope) Collections(java.util.Collections) BinaryOperator(nl.ramsolutions.sw.magik.analysis.typing.BinaryOperator) ExpressionResult(nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult) Path(java.nio.file.Path) SlottedType(nl.ramsolutions.sw.magik.analysis.typing.types.SlottedType) GlobalReference(nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference) AstNode(com.sonar.sslr.api.AstNode) MagikType(nl.ramsolutions.sw.magik.analysis.typing.types.MagikType) SlottedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition)

Example 2 with SlottedExemplarDefinition

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);
    }
}
Also used : SlottedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition) Definition(nl.ramsolutions.sw.magik.analysis.definitions.Definition) SlottedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition) DefSlottedExemplarParser(nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser)

Example 3 with SlottedExemplarDefinition

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);
    });
}
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)

Example 4 with SlottedExemplarDefinition

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;
}
Also used : SymbolKind(org.eclipse.lsp4j.SymbolKind) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) Range(nl.ramsolutions.sw.magik.analysis.Range) SlottedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition)

Example 5 with SlottedExemplarDefinition

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);
    }
}
Also used : PackageDefinition(nl.ramsolutions.sw.magik.analysis.definitions.PackageDefinition) BinaryOperatorDefinition(nl.ramsolutions.sw.magik.analysis.definitions.BinaryOperatorDefinition) IndexedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.IndexedExemplarDefinition) MethodDefinition(nl.ramsolutions.sw.magik.analysis.definitions.MethodDefinition) GlobalDefinition(nl.ramsolutions.sw.magik.analysis.definitions.GlobalDefinition) EnumerationDefinition(nl.ramsolutions.sw.magik.analysis.definitions.EnumerationDefinition) MixinDefinition(nl.ramsolutions.sw.magik.analysis.definitions.MixinDefinition) SlottedExemplarDefinition(nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition)

Aggregations

SlottedExemplarDefinition (nl.ramsolutions.sw.magik.analysis.definitions.SlottedExemplarDefinition)6 Definition (nl.ramsolutions.sw.magik.analysis.definitions.Definition)3 EnumerationDefinition (nl.ramsolutions.sw.magik.analysis.definitions.EnumerationDefinition)3 IndexedExemplarDefinition (nl.ramsolutions.sw.magik.analysis.definitions.IndexedExemplarDefinition)3 MixinDefinition (nl.ramsolutions.sw.magik.analysis.definitions.MixinDefinition)3 PackageDefinition (nl.ramsolutions.sw.magik.analysis.definitions.PackageDefinition)3 AstNode (com.sonar.sslr.api.AstNode)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 BinaryOperatorDefinition (nl.ramsolutions.sw.magik.analysis.definitions.BinaryOperatorDefinition)2 DefSlottedExemplarParser (nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser)2 GlobalDefinition (nl.ramsolutions.sw.magik.analysis.definitions.GlobalDefinition)2 MethodDefinition (nl.ramsolutions.sw.magik.analysis.definitions.MethodDefinition)2 MagikGrammar (nl.ramsolutions.sw.magik.api.MagikGrammar)2 NewDocParser (nl.ramsolutions.sw.magik.parser.NewDocParser)2 Token (com.sonar.sslr.api.Token)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Path (java.nio.file.Path)1