private void checkDeclarationsAsDirectChild(Node n, Node c) { if (c instanceof VariableDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Variable declarations only make sense in the context of a block.")); } if (c instanceof TypeDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Type declarations only make sense in the context of a block or other type.")); } }
private void checkDeclarationsAsDirectChild(Node n, Node c) { if (c instanceof VariableDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Variable declarations only make sense in the context of a block.")); } if (c instanceof TypeDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Type declarations only make sense in the context of a block or other type.")); } }
private void checkDeclarationsAsDirectChild(Node n, Node c) { if (c instanceof VariableDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Variable declarations only make sense in the context of a block.")); } if (c instanceof TypeDeclaration) { c.addMessage(error(DECLARATION_NOT_ALLOWED, "Type declarations only make sense in the context of a block or other type.")); } }
@Override public boolean visitParseArtefact(Node node) { StringBuilder errorName = new StringBuilder(); boolean first = true; for (char c : node.getClass().getSimpleName().toCharArray()) { if (first) { errorName.append(c); first = false; continue; } if (Character.isUpperCase(c)) errorName.append(" ").append(Character.toLowerCase(c)); else errorName.append(c); } node.addMessage(error(PARSEARTEFACT, "parse artefact remained in node tree")); return !recursing; } }
@Override public boolean visitParseArtefact(Node node) { StringBuilder errorName = new StringBuilder(); boolean first = true; for (char c : node.getClass().getSimpleName().toCharArray()) { if (first) { errorName.append(c); first = false; continue; } if (Character.isUpperCase(c)) errorName.append(" ").append(Character.toLowerCase(c)); else errorName.append(c); } node.addMessage(error(PARSEARTEFACT, "parse artefact remained in node tree")); return !recursing; } }
@Override public boolean visitParseArtefact(Node node) { StringBuilder errorName = new StringBuilder(); boolean first = true; for (char c : node.getClass().getSimpleName().toCharArray()) { if (first) { errorName.append(c); first = false; continue; } if (Character.isUpperCase(c)) errorName.append(" ").append(Character.toLowerCase(c)); else errorName.append(c); } node.addMessage(error(PARSEARTEFACT, "parse artefact remained in node tree")); return !recursing; } }
private void initializersMustCompleteNormally(Node rawBlock) { if (!(rawBlock instanceof Block)) return; for (Node s : ((Block)rawBlock).rawContents()) { if (s instanceof Throw) s.addMessage(error(INITIALIZERS_INITIALIZER_MUST_COMPLETE_NORMALLY, "Initializers may not contain throws statements.")); if (s instanceof Return) s.addMessage(error(INITIALIZERS_INITIALIZER_MUST_COMPLETE_NORMALLY, "Initializers may not contain return statements.")); } }
private void initializersMustCompleteNormally(Node rawBlock) { if (!(rawBlock instanceof Block)) return; for (Node s : ((Block)rawBlock).rawContents()) { if (s instanceof Throw) s.addMessage(error(INITIALIZERS_INITIALIZER_MUST_COMPLETE_NORMALLY, "Initializers may not contain throws statements.")); if (s instanceof Return) s.addMessage(error(INITIALIZERS_INITIALIZER_MUST_COMPLETE_NORMALLY, "Initializers may not contain return statements.")); } }
private void initializersMustCompleteNormally(Node rawBlock) { if (!(rawBlock instanceof Block)) return; for (Node s : ((Block)rawBlock).rawContents()) { if (s instanceof Throw) s.addMessage(error(INITIALIZERS_INITIALIZER_MUST_COMPLETE_NORMALLY, "Initializers may not contain throws statements.")); if (s instanceof Return) s.addMessage(error(INITIALIZERS_INITIALIZER_MUST_COMPLETE_NORMALLY, "Initializers may not contain return statements.")); } }
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; }
private void checkForUnreachables(Statement n) { Block b = n.upToBlock(); if (b == null) return; boolean found = false; for (Node s : b.rawContents()) { if (found) { s.addMessage(error(STATEMENT_UNREACHABLE, "Unreachable code")); return; } if (s == n) found = true; } } }
private void checkForUnreachables(Statement n) { Block b = n.upToBlock(); if (b == null) return; boolean found = false; for (Node s : b.rawContents()) { if (found) { s.addMessage(error(STATEMENT_UNREACHABLE, "Unreachable code")); return; } if (s == n) found = true; } } }
private void checkForUnreachables(Statement n) { Block b = n.upToBlock(); if (b == null) return; boolean found = false; for (Node s : b.rawContents()) { if (found) { s.addMessage(error(STATEMENT_UNREACHABLE, "Unreachable code")); return; } if (s == n) found = true; } } }
static void checkVarDefIsSimple(Node node, Node rawVarDef, String descriptionOfOuter, String descriptionOfRelation) { if (!(rawVarDef instanceof VariableDefinition)) return; switch (((VariableDefinition)rawVarDef).rawVariables().size()) { case 0: return; case 1: break; default: rawVarDef.addMessage(error(VARIABLEDEFINITION_ONLY_ONE, String.format("%s can only declare one %s variable", descriptionOfOuter, descriptionOfRelation))); } for (VariableDefinitionEntry entry : ((VariableDefinition)rawVarDef).astVariables()) { if (entry.rawInitializer() != null) entry.addMessage(error(VARIABLEDEFINITIONENTRY_INITIALIZER_NOT_ALLOWED, String.format( "%s can only declare %s variables without an initializer", descriptionOfOuter, descriptionOfRelation))); } } }
static void checkVarDefIsSimple(Node node, Node rawVarDef, String descriptionOfOuter, String descriptionOfRelation) { if (!(rawVarDef instanceof VariableDefinition)) return; switch (((VariableDefinition)rawVarDef).rawVariables().size()) { case 0: return; case 1: break; default: rawVarDef.addMessage(error(VARIABLEDEFINITION_ONLY_ONE, String.format("%s can only declare one %s variable", descriptionOfOuter, descriptionOfRelation))); } for (VariableDefinitionEntry entry : ((VariableDefinition)rawVarDef).astVariables()) { if (entry.rawInitializer() != null) entry.addMessage(error(VARIABLEDEFINITIONENTRY_INITIALIZER_NOT_ALLOWED, String.format( "%s can only declare %s variables without an initializer", descriptionOfOuter, descriptionOfRelation))); } } }
static void checkVarDefIsSimple(Node node, Node rawVarDef, String descriptionOfOuter, String descriptionOfRelation) { if (!(rawVarDef instanceof VariableDefinition)) return; switch (((VariableDefinition)rawVarDef).rawVariables().size()) { case 0: return; case 1: break; default: rawVarDef.addMessage(error(VARIABLEDEFINITION_ONLY_ONE, String.format("%s can only declare one %s variable", descriptionOfOuter, descriptionOfRelation))); } for (VariableDefinitionEntry entry : ((VariableDefinition)rawVarDef).astVariables()) { if (entry.rawInitializer() != null) entry.addMessage(error(VARIABLEDEFINITIONENTRY_INITIALIZER_NOT_ALLOWED, String.format( "%s can only declare %s variables without an initializer", descriptionOfOuter, descriptionOfRelation))); } } }
private void checkStaticChain(Modifiers modifiers) { if (!modifiers.isStatic()) return; Node p = modifiers.getParent(); while (p != null) { if (p instanceof CompilationUnit) return; if (p instanceof TypeDeclaration) { Modifiers pMods = ((TypeDeclaration)p).astModifiers(); if (!pMods.isStatic()) { modifiers.getParent().addMessage(error(MODIFIERS_STATIC_CHAIN, "This declaration is (effectively) static; static declarations or only legal in top-level and static declarations.")); } } p = p.getParent(); } }
private void checkStaticChain(Modifiers modifiers) { if (!modifiers.isStatic()) return; Node p = modifiers.getParent(); while (p != null) { if (p instanceof CompilationUnit) return; if (p instanceof TypeDeclaration) { Modifiers pMods = ((TypeDeclaration)p).astModifiers(); if (!pMods.isStatic()) { modifiers.getParent().addMessage(error(MODIFIERS_STATIC_CHAIN, "This declaration is (effectively) static; static declarations or only legal in top-level and static declarations.")); } } p = p.getParent(); } }
private void checkStaticChain(Modifiers modifiers) { if (!modifiers.isStatic()) return; Node p = modifiers.getParent(); while (p != null) { if (p instanceof CompilationUnit) return; if (p instanceof TypeDeclaration) { Modifiers pMods = ((TypeDeclaration)p).astModifiers(); if (!pMods.isStatic()) { modifiers.getParent().addMessage(error(MODIFIERS_STATIC_CHAIN, "This declaration is (effectively) static; static declarations or only legal in top-level and static declarations.")); } } p = p.getParent(); } }