Search in sources :

Example 11 with ArgumentsNodeHelper

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

the class DefineSharedConstantParser method parseDefinitions.

/**
 * Parse defitions.
 * @return List of parsed definitions.
 */
public List<Definition> parseDefinitions() {
    // Some sanity.
    final AstNode parentNode = this.node.getParent();
    final AstNode atomNode = parentNode.getFirstChild();
    if (atomNode.isNot(MagikGrammar.ATOM)) {
        throw new IllegalStateException();
    }
    // Assume this is an exemplar.
    final String exemplarName = atomNode.getTokenValue();
    if (exemplarName == null) {
        throw new IllegalStateException();
    }
    final AstNode argumentsNode = this.node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    final AstNode argument2Node = argumentsHelper.getArgument(2, MagikGrammar.SYMBOL);
    if (argument0Node == null || argument2Node == null) {
        throw new IllegalStateException();
    }
    // Figure statement node.
    final AstNode statementNode = this.node.getFirstAncestor(MagikGrammar.STATEMENT);
    // Figure pakkage.
    final String pakkage = this.getCurrentPakkage();
    final String constantNameSymbol = argument0Node.getTokenValue();
    final String constantName = constantNameSymbol.substring(1);
    final Set<MethodDefinition.Modifier> modifiers = new HashSet<>();
    final String isPrivate = argument2Node.getTokenValue();
    if (isPrivate.equals(FLAVOR_PRIVATE) || isPrivate.equals(TRUE)) {
        modifiers.add(MethodDefinition.Modifier.PRIVATE);
    }
    final List<ParameterDefinition> parameters = Collections.emptyList();
    final MethodDefinition methodDefinition = new MethodDefinition(statementNode, pakkage, exemplarName, constantName, modifiers, parameters, null);
    return List.of(methodDefinition);
}
Also used : ArgumentsNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper) AstNode(com.sonar.sslr.api.AstNode) HashSet(java.util.HashSet)

Example 12 with ArgumentsNodeHelper

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

the class DefineSharedVariableParser method isDefineSharedVariable.

/**
 * Test if node is a {@code define_shared_variable()}.
 * @param node Node to test
 * @return True if node is a {@code define_shared_variable()}, false otherwise.
 */
public static boolean isDefineSharedVariable(final AstNode node) {
    final MethodInvocationNodeHelper helper = new MethodInvocationNodeHelper(node);
    if (!helper.isMethodInvocationOf(DEFINE_SHARED_VARIABLE)) {
        return false;
    }
    // Some sanity.
    final AstNode parentNode = node.getParent();
    final AstNode atomNode = parentNode.getFirstChild();
    if (atomNode.isNot(MagikGrammar.ATOM)) {
        return false;
    }
    // Assume this is an exemplar.
    final String exemplarName = atomNode.getTokenValue();
    if (exemplarName == null) {
        return false;
    }
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    final AstNode argument2Node = argumentsHelper.getArgument(2, MagikGrammar.SYMBOL);
    return argument0Node != null && argument2Node != null;
}
Also used : ArgumentsNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper) MethodInvocationNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.MethodInvocationNodeHelper) AstNode(com.sonar.sslr.api.AstNode)

Example 13 with ArgumentsNodeHelper

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

the class DefineSlotAccessParser method isDefineSlotAccess.

/**
 * Test if node is a {@code define_slot_access()}.
 * @param node Node to test
 * @return True if node is a {@code define_slot_access()}, false otherwise.
 */
public static boolean isDefineSlotAccess(final AstNode node) {
    if (node.isNot(MagikGrammar.METHOD_INVOCATION)) {
        return false;
    }
    final MethodInvocationNodeHelper helper = new MethodInvocationNodeHelper(node);
    if (!helper.isMethodInvocationOf(DEFINE_SLOT_ACCESS)) {
        return false;
    }
    final AstNode parentNode = node.getParent();
    final AstNode atomNode = parentNode.getFirstChild();
    if (atomNode.isNot(MagikGrammar.ATOM)) {
        return false;
    }
    final String exemplarName = atomNode.getTokenValue();
    if (exemplarName == null) {
        return false;
    }
    final AstNode argumentsNode = node.getFirstChild(MagikGrammar.ARGUMENTS);
    final ArgumentsNodeHelper argumentsHelper = new ArgumentsNodeHelper(argumentsNode);
    final AstNode argument0Node = argumentsHelper.getArgument(0, MagikGrammar.SYMBOL);
    final AstNode argument1Node = argumentsHelper.getArgument(1, MagikGrammar.SYMBOL);
    return argument0Node != null && argument1Node != null;
}
Also used : ArgumentsNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper) MethodInvocationNodeHelper(nl.ramsolutions.sw.magik.analysis.helpers.MethodInvocationNodeHelper) AstNode(com.sonar.sslr.api.AstNode)

Example 14 with ArgumentsNodeHelper

use of nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper 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 15 with ArgumentsNodeHelper

use of nl.ramsolutions.sw.magik.analysis.helpers.ArgumentsNodeHelper 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)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