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