/** * Checks if a given child is syntactically valid; you specify exactly what is required for this to hold in the parameters. * This method will recursively call {@link #checkSyntacticValidity()} on the child. * * @param node The node responsible for the check. * @param child The actual child node object that will be checked. * @param name The name of this node. For example, in a binary operation, {@code "left side"}. * @param mandatory If this node not being there (being {@code null}) is a problem or acceptable. * @param typeAssertion If the node exists, it must be an instance of this type. */ void checkChildValidity(Node node, Node child, String name, boolean mandatory, Class<?> typeAssertion) { verifyNodeRelation(node, child, name, mandatory, typeAssertion); }
public static boolean verifyNodeRelation(Node parent, Node child, String name, boolean mandatory, Class<?> typeAssertion) { String typeAssertionName = typeAssertion.getSimpleName().toLowerCase(); boolean typeAssertionVowel = startsWithVowel(typeAssertionName); if (child == null) { if (mandatory) { parent.addMessage(error(NODE_MISSING_MANDATORY_CHILD, String.format("Missing %s %s", name, typeAssertion.getSimpleName().toLowerCase()))); return false; } } else { if (!typeAssertion.isInstance(child)) { String actualName = child.getClass().getSimpleName(); child.addMessage(error(NODE_CHILD_TYPE_INCORRECT, String.format( "%s isn't a%s %s but a%s %s", name, typeAssertionVowel ? "n" : "", typeAssertionName, startsWithVowel(actualName) ? "n" : "", actualName))); return false; } } return true; }
public static boolean verifyNodeRelation(Node parent, Node child, String name, boolean mandatory, Class<?> typeAssertion) { String typeAssertionName = typeAssertion.getSimpleName().toLowerCase(); boolean typeAssertionVowel = startsWithVowel(typeAssertionName); if (child == null) { if (mandatory) { parent.addMessage(error(NODE_MISSING_MANDATORY_CHILD, String.format("Missing %s %s", name, typeAssertion.getSimpleName().toLowerCase()))); return false; } } else { if (!typeAssertion.isInstance(child)) { String actualName = child.getClass().getSimpleName(); child.addMessage(error(NODE_CHILD_TYPE_INCORRECT, String.format( "%s isn't a%s %s but a%s %s", name, typeAssertionVowel ? "n" : "", typeAssertionName, startsWithVowel(actualName) ? "n" : "", actualName))); return false; } } return true; }
/** * Checks if a given child is syntactically valid; you specify exactly what is required for this to hold in the parameters. * This method will recursively call {@link #checkSyntacticValidity()} on the child. * * @param node The node responsible for the check. * @param child The actual child node object that will be checked. * @param name The name of this node. For example, in a binary operation, {@code "left side"}. * @param mandatory If this node not being there (being {@code null}) is a problem or acceptable. * @param typeAssertion If the node exists, it must be an instance of this type. */ void checkChildValidity(Node node, Node child, String name, boolean mandatory, Class<?> typeAssertion) { verifyNodeRelation(node, child, name, mandatory, typeAssertion); }
public static boolean verifyNodeRelation(Node parent, Node child, String name, boolean mandatory, Class<?> typeAssertion) { String typeAssertionName = typeAssertion.getSimpleName().toLowerCase(); boolean typeAssertionVowel = startsWithVowel(typeAssertionName); if (child == null) { if (mandatory) { parent.addMessage(error(NODE_MISSING_MANDATORY_CHILD, String.format("Missing %s %s", name, typeAssertion.getSimpleName().toLowerCase()))); return false; } } else { if (!typeAssertion.isInstance(child)) { String actualName = child.getClass().getSimpleName(); child.addMessage(error(NODE_CHILD_TYPE_INCORRECT, String.format( "%s isn't a%s %s but a%s %s", name, typeAssertionVowel ? "n" : "", typeAssertionName, startsWithVowel(actualName) ? "n" : "", actualName))); return false; } } return true; }
/** * Checks if a given child is syntactically valid; you specify exactly what is required for this to hold in the parameters. * This method will recursively call {@link #checkSyntacticValidity()} on the child. * * @param node The node responsible for the check. * @param child The actual child node object that will be checked. * @param name The name of this node. For example, in a binary operation, {@code "left side"}. * @param mandatory If this node not being there (being {@code null}) is a problem or acceptable. * @param typeAssertion If the node exists, it must be an instance of this type. */ void checkChildValidity(Node node, Node child, String name, boolean mandatory, Class<?> typeAssertion) { verifyNodeRelation(node, child, name, mandatory, typeAssertion); }