Search in sources :

Example 1 with ProcedureInvocationNodeHelper

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

the class DefineBinaryOperatorCaseParser method isBinaryOperatorCase.

/**
 * Test if node is a {@code define_binary_operator_case()}.
 * @param node Node to test
 * @return True if node is a {@code define_binary_operator_case()}, false otherwise.
 */
public static boolean isBinaryOperatorCase(final AstNode node) {
    if (!node.is(MagikGrammar.PROCEDURE_INVOCATION)) {
        return false;
    }
    final ProcedureInvocationNodeHelper helper = new ProcedureInvocationNodeHelper(node);
    if (!helper.isProcedureInvocationOf(DEFINE_BINARY_OPERATOR_CASE)) {
        return false;
    }
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    if (argument0Node == null) {
        return false;
    }
    final AstNode argument1Node = argumentsHelper.getArgument(1, MagikGrammar.IDENTIFIER);
    if (argument1Node == null) {
        return false;
    }
    final AstNode argument2Node = argumentsHelper.getArgument(2, MagikGrammar.IDENTIFIER);
    if (argument2Node == null) {
        return false;
    }
    // Anything will do.
    final AstNode argument3Node = argumentsHelper.getArgument(3);
    if (argument3Node == null) {
        return false;
    }
    final String operatorSymbol = argument0Node.getTokenValue();
    return !operatorSymbol.isEmpty();
}
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 2 with ProcedureInvocationNodeHelper

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

the class ExemplarDefinitionVisitor method walkPreProcedureInvocation.

@Override
public void walkPreProcedureInvocation(final AstNode node) {
    final ProcedureInvocationNodeHelper invocationHelper = new ProcedureInvocationNodeHelper(node);
    if (!invocationHelper.isProcedureInvocationOf("def_slotted_exemplar") && !invocationHelper.isProcedureInvocationOf("def_indexed_exemplar") && !invocationHelper.isProcedureInvocationOf("def_enumeration") && !invocationHelper.isProcedureInvocationOf("def_enumeration_from")) {
        return;
    }
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    final AstNode symbolNode = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    if (symbolNode == null) {
        return;
    }
    // exemplar found
    this.count++;
}
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 3 with ProcedureInvocationNodeHelper

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

the class DefSlottedExemplarParser method isDefSlottedExemplar.

/**
 * Test if node is a {@code def_slotted_exemplar()}.
 * @param node Node to test
 * @return True if node is a {@code def_slotted_exemplar()}, false otherwise.
 */
public static boolean isDefSlottedExemplar(final AstNode node) {
    if (!node.is(MagikGrammar.PROCEDURE_INVOCATION)) {
        return false;
    }
    final ProcedureInvocationNodeHelper helper = new ProcedureInvocationNodeHelper(node);
    if (!helper.isProcedureInvocationOf(DEF_SLOTTED_EXEMPLAR)) {
        return false;
    }
    // Some sanity.
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    if (argument0Node == null) {
        return false;
    }
    final AstNode argument1Node = argumentsHelper.getArgument(1, MagikGrammar.SIMPLE_VECTOR);
    return argument1Node != 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 4 with ProcedureInvocationNodeHelper

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

the class DefEnumerationParser method isDefEnumeration.

/**
 * Test if node is a {@code def_enumeration_from}/{@code def_enumeration}.
 * @param node Node to test
 * @return True if node is a {@code def_enumeration_from}/{@code def_enumeration}, false otherwise.
 */
public static boolean isDefEnumeration(final AstNode node) {
    if (!node.is(MagikGrammar.PROCEDURE_INVOCATION)) {
        return false;
    }
    final ProcedureInvocationNodeHelper helper = new ProcedureInvocationNodeHelper(node);
    if (!helper.isProcedureInvocationOf(DEF_ENUMERATION) && !helper.isProcedureInvocationOf(DEF_ENUMERATION_FROM)) {
        return false;
    }
    // Some sanity.
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    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 5 with ProcedureInvocationNodeHelper

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

the class DefIndexedExemplarParser method isDefIndexedExemplar.

/**
 * Test if node is a {@code def_indexed_exemplar()}.
 * @param node Node to test
 * @return True if node is a {@code def_indexed_exemplar()}, false otherwise.
 */
public static boolean isDefIndexedExemplar(final AstNode node) {
    if (!node.is(MagikGrammar.PROCEDURE_INVOCATION)) {
        return false;
    }
    final ProcedureInvocationNodeHelper helper = new ProcedureInvocationNodeHelper(node);
    if (!helper.isProcedureInvocationOf(DEF_INDEXED_EXEMPLAR)) {
        return false;
    }
    // Some sanity.
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    if (argument0Node == null) {
        return false;
    }
    final AstNode argument1Node = argumentsHelper.getArgument(1, MagikGrammar.SIMPLE_VECTOR);
    return argument1Node != 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)7 ArgumentsNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper)7 ProcedureInvocationNodeHelper (nl.ramsolutions.sw.magik.analysis.helpers.ProcedureInvocationNodeHelper)7