Search in sources :

Example 26 with ITypeKeeper

use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.

the class MethodReturnMatchesDocTypedCheck method extractMethodDocResult.

private ExpressionResult extractMethodDocResult(final AstNode node) {
    final PackageNodeHelper packageHelper = new PackageNodeHelper(node);
    final String currentPakkage = packageHelper.getCurrentPackage();
    final NewDocParser docParser = new NewDocParser(node);
    final ITypeKeeper typeKeeper = this.getTypeKeeper();
    final TypeParser typeParser = new TypeParser(typeKeeper);
    final List<AbstractType> docReturnTypes = docParser.getReturnTypes().stream().map(typeStr -> typeParser.parseTypeString(typeStr, currentPakkage)).collect(Collectors.toList());
    return new ExpressionResult(docReturnTypes);
}
Also used : NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) AstNode(com.sonar.sslr.api.AstNode) MethodDefinitionNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper) PackageNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper) NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) Collectors(java.util.stream.Collectors) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) Objects(java.util.Objects) LocalTypeReasoner(nl.ramsolutions.sw.magik.analysis.typing.LocalTypeReasoner) TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) List(java.util.List) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) MagikTypedCheck(nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck) ExpressionResult(nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult) PackageNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper) TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) ExpressionResult(nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)

Example 27 with ITypeKeeper

use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.

the class NewDocTypeExistsTypeCheck method checkDefinitionParameters.

private void checkDefinitionParameters(final NewDocParser newDocParser, final String pakkage) {
    // Test @param types.
    final ITypeKeeper typeKeeper = this.getTypeKeeper();
    final TypeParser typeParser = new TypeParser(typeKeeper);
    newDocParser.getParameterTypeNodes().entrySet().stream().filter(entry -> typeParser.parseTypeString(entry.getValue(), pakkage) == UndefinedType.INSTANCE).forEach(entry -> {
        final AstNode typeNode = entry.getKey();
        final String typeName = entry.getValue();
        final String message = String.format(MESSAGE, typeName);
        this.addIssue(typeNode, message);
    });
}
Also used : TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) AstNode(com.sonar.sslr.api.AstNode) UndefinedType(nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType) DefSlottedExemplarParser(nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) PackageNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper) MagikTypedCheck(nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck) Map(java.util.Map) NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikGrammar(nl.ramsolutions.sw.magik.api.MagikGrammar) TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) AstNode(com.sonar.sslr.api.AstNode)

Example 28 with ITypeKeeper

use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.

the class NewDocTypeExistsTypeCheck method checkDefinitionReturns.

private void checkDefinitionReturns(final NewDocParser newDocParser, final String pakkage) {
    // Test @return types.
    final ITypeKeeper typeKeeper = this.getTypeKeeper();
    final TypeParser typeParser = new TypeParser(typeKeeper);
    newDocParser.getReturnTypeNodes().entrySet().stream().filter(entry -> typeParser.parseTypeString(entry.getValue(), pakkage) == UndefinedType.INSTANCE).forEach(entry -> {
        final AstNode typeNode = entry.getKey();
        final String typeName = entry.getValue();
        final String message = String.format(MESSAGE, typeName);
        this.addIssue(typeNode, message);
    });
}
Also used : TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) AstNode(com.sonar.sslr.api.AstNode) UndefinedType(nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType) DefSlottedExemplarParser(nl.ramsolutions.sw.magik.analysis.definitions.DefSlottedExemplarParser) AbstractType(nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType) PackageNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.PackageNodeHelper) MagikTypedCheck(nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck) Map(java.util.Map) NewDocParser(nl.ramsolutions.sw.magik.parser.NewDocParser) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) MagikGrammar(nl.ramsolutions.sw.magik.api.MagikGrammar) TypeParser(nl.ramsolutions.sw.magik.analysis.typing.TypeParser) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) AstNode(com.sonar.sslr.api.AstNode)

Example 29 with ITypeKeeper

use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.

the class MagikTypedCheck method getTypeKeeper.

/**
 * Get ITypeKeeper.
 * @return ITypeKeeper.
 */
protected ITypeKeeper getTypeKeeper() {
    final MagikFile magikFile = this.getMagikFile();
    if (!(magikFile instanceof MagikTypedFile)) {
        throw new IllegalStateException();
    }
    final MagikTypedFile magikTypedFile = (MagikTypedFile) magikFile;
    final ITypeKeeper typeKeeper = magikTypedFile.getTypeKeeper();
    return new ReadOnlyTypeKeeperAdapter(typeKeeper);
}
Also used : MagikFile(nl.ramsolutions.sw.magik.MagikFile) MagikTypedFile(nl.ramsolutions.sw.magik.MagikTypedFile) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper) ReadOnlyTypeKeeperAdapter(nl.ramsolutions.sw.magik.analysis.typing.ReadOnlyTypeKeeperAdapter)

Example 30 with ITypeKeeper

use of nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper in project magik-tools by StevenLooman.

the class MagikTypedCheck method getTypeOfMethodDefinition.

/**
 * Get type of method definition.
 * @param node METHOD_DEFINITION node.
 * @return
 */
protected AbstractType getTypeOfMethodDefinition(final AstNode node) {
    if (node == null) {
        // This can happen in case of a procedure definition calling a method on _self.
        return UndefinedType.INSTANCE;
    }
    final MethodDefinitionNodeHelper methodDefHelper = new MethodDefinitionNodeHelper(node);
    final GlobalReference globalRef = methodDefHelper.getTypeGlobalReference();
    final ITypeKeeper typeKeeper = this.getTypeKeeper();
    return typeKeeper.getType(globalRef);
}
Also used : GlobalReference(nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference) MethodDefinitionNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper) ITypeKeeper(nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)

Aggregations

ITypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.ITypeKeeper)55 TypeKeeper (nl.ramsolutions.sw.magik.analysis.typing.TypeKeeper)38 Test (org.junit.jupiter.api.Test)34 AbstractType (nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType)20 MagikType (nl.ramsolutions.sw.magik.analysis.typing.types.MagikType)20 MagikTypedCheck (nl.ramsolutions.sw.magik.typedchecks.MagikTypedCheck)18 Position (org.eclipse.lsp4j.Position)17 AstNode (com.sonar.sslr.api.AstNode)14 GlobalReference (nl.ramsolutions.sw.magik.analysis.typing.types.GlobalReference)14 MagikTypedFile (nl.ramsolutions.sw.magik.MagikTypedFile)13 MagikIssue (nl.ramsolutions.sw.magik.checks.MagikIssue)13 Method (nl.ramsolutions.sw.magik.analysis.typing.types.Method)12 ExpressionResult (nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult)9 CompletionItem (org.eclipse.lsp4j.CompletionItem)9 URI (java.net.URI)8 List (java.util.List)8 MethodDefinitionNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.MethodDefinitionNodeHelper)8 LocalTypeReasoner (nl.ramsolutions.sw.magik.analysis.typing.LocalTypeReasoner)8 UndefinedType (nl.ramsolutions.sw.magik.analysis.typing.types.UndefinedType)8 MagikGrammar (nl.ramsolutions.sw.magik.api.MagikGrammar)8