Search in sources :

Example 16 with ArgumentsNodeHelper

use of nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper in project magik-tools by StevenLooman.

the class DefIndexedExemplarParser method parseDefinitions.

/**
 * Parse defitions.
 * @return List of parsed definitions.
 */
@Override
public List<Definition> parseDefinitions() {
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    // Some sanity.
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    if (argument0Node == null) {
        throw new IllegalStateException();
    }
    final AstNode argument1Node = argumentsHelper.getArgument(1, MagikGrammar.SIMPLE_VECTOR);
    if (argument1Node == null) {
        throw new IllegalStateException();
    }
    // Figure statement node.
    final AstNode statementNode = node.getFirstAncestor(MagikGrammar.STATEMENT);
    // Figure pakkage.
    final String pakkage = this.getCurrentPakkage();
    // Figure name.
    final String name = argument0Node.getTokenValue().substring(1);
    // Parents.
    final AstNode argument2Node = argumentsHelper.getArgument(2);
    final List<String> parents = this.extractParents(argument2Node);
    final IndexedExemplarDefinition indexedExemplarDefinition = new IndexedExemplarDefinition(statementNode, pakkage, name, parents);
    return List.of(indexedExemplarDefinition);
}
Also used : ArgumentsNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper) AstNode(com.sonar.sslr.api.AstNode)

Example 17 with ArgumentsNodeHelper

use of nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper in project magik-tools by StevenLooman.

the class DefMixinParser method parseDefinitions.

/**
 * Parse defitions.
 * @return List of parsed definitions.
 */
@Override
public List<Definition> parseDefinitions() {
    final AstNode argumentsNode = this.node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    // Some sanity.
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    if (argument0Node == null) {
        throw new IllegalStateException();
    }
    // Figure statement node.
    final AstNode statementNode = this.node.getFirstAncestor(MagikGrammar.STATEMENT);
    // Figure pakkage.
    final String pakkage = this.getCurrentPakkage();
    // Figure name.
    final String name = argument0Node.getTokenValue().substring(1);
    // Parents.
    final AstNode argument1Node = argumentsHelper.getArgument(1);
    final List<String> parents = this.extractParents(argument1Node);
    final MixinDefinition mixinDefinition = new MixinDefinition(statementNode, pakkage, name, parents);
    return List.of(mixinDefinition);
}
Also used : ArgumentsNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper) AstNode(com.sonar.sslr.api.AstNode)

Example 18 with ArgumentsNodeHelper

use of nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper in project magik-tools by StevenLooman.

the class DefMixinParser method isDefMixin.

/**
 * Test if node is a {@code def_mixin()}.
 * @param node Node to test.
 * @return True if node is a {@code def_mixin()}, false otherwise.
 */
public static boolean isDefMixin(final AstNode node) {
    if (!node.is(MagikGrammar.PROCEDURE_INVOCATION)) {
        return false;
    }
    final ProcedureInvocationNodeHelper helper = new ProcedureInvocationNodeHelper(node);
    if (!helper.isProcedureInvocationOf(DEF_MIXIN)) {
        return false;
    }
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    // Some sanity.
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    return argument0Node != null;
}
Also used : ArgumentsNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper) ProcedureInvocationNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ProcedureInvocationNodeHelper) AstNode(com.sonar.sslr.api.AstNode)

Example 19 with ArgumentsNodeHelper

use of nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper in project magik-tools by StevenLooman.

the class DefPackageParser method isDefPackage.

/**
 * Test if node is a {@code def_package()}.
 * @param node Node to test
 * @return True if node is a {@code def_package()}, false otherwise.
 */
public static boolean isDefPackage(final AstNode node) {
    if (!node.is(MagikGrammar.PROCEDURE_INVOCATION)) {
        return false;
    }
    final ProcedureInvocationNodeHelper helper = new ProcedureInvocationNodeHelper(node);
    if (!helper.isProcedureInvocationOf(DEF_PACKAGE)) {
        return false;
    }
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    // Figure name.
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    return argument0Node != null;
}
Also used : ArgumentsNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper) ProcedureInvocationNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ProcedureInvocationNodeHelper) AstNode(com.sonar.sslr.api.AstNode)

Aggregations

AstNode (com.sonar.sslr.api.AstNode)19 ArgumentsNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper)19 ProcedureInvocationNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.ProcedureInvocationNodeHelper)7 MethodInvocationNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.MethodInvocationNodeHelper)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 ExpressionNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.ExpressionNodeHelper)1 SimpleVectorNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.SimpleVectorNodeHelper)1