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.")); } }
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 boolean generateNotAllowedKeywordError(Modifiers modifiers, int flags, int flag, String keyword, String error) { if ((flags & flag) == 0) return false; for (KeywordModifier n : modifiers.astKeywords()) { if (keyword.equals(n.astName())) { n.addMessage(error(MODIFIERS_MODIFIER_NOT_ALLOWED, error)); return true; } } return false; }
private boolean generateNotAllowedKeywordError(Modifiers modifiers, int flags, int flag, String keyword, String error) { if ((flags & flag) == 0) return false; for (KeywordModifier n : modifiers.astKeywords()) { if (keyword.equals(n.astName())) { n.addMessage(error(MODIFIERS_MODIFIER_NOT_ALLOWED, error)); return true; } } return false; }
private boolean generateNotAllowedKeywordError(Modifiers modifiers, int flags, int flag, String keyword, String error) { if ((flags & flag) == 0) return false; for (KeywordModifier n : modifiers.astKeywords()) { if (keyword.equals(n.astName())) { n.addMessage(error(MODIFIERS_MODIFIER_NOT_ALLOWED, error)); return true; } } return false; }
public void checkVoidNotLegalJustAboutEverywhere(TypeReference node) { if (!node.isVoid()) return; if (node.astArrayDimensions() > 0) { node.addMessage(error(TYPEREFERENCE_VOID_NOT_ALLOWED, "Array of void type is not legal.")); return; } if (node.upIfReturnTypeToMethodDeclaration() != null) return; if (node.upToClassLiteral() != null) return; node.addMessage(error(TYPEREFERENCE_VOID_NOT_ALLOWED, "The void type is not legal here.")); } }
public void checkVoidNotLegalJustAboutEverywhere(TypeReference node) { if (!node.isVoid()) return; if (node.astArrayDimensions() > 0) { node.addMessage(error(TYPEREFERENCE_VOID_NOT_ALLOWED, "Array of void type is not legal.")); return; } if (node.upIfReturnTypeToMethodDeclaration() != null) return; if (node.upToClassLiteral() != null) return; node.addMessage(error(TYPEREFERENCE_VOID_NOT_ALLOWED, "The void type is not legal here.")); } }
public void checkSwitchStartsWithDefaultOrCase(Switch node) { Block body = node.astBody(); if (body != null) { Statement first = body.astContents().first(); if (first != null && !(first instanceof Case) && !(first instanceof Default)) { node.addMessage(error(SWITCH_DOES_NOT_START_WITH_CASE, "switch statements should start with a default or case statement.")); } } } }
public void checkNotLoneTry(Try node) { if (node.rawCatches().size() == 0 && node.rawFinally() == null) { node.addMessage(error(TRY_LONE_TRY, "try statement with no catches and no finally")); } }
public void varargsAndExtendedDimsDontMix(VariableDefinitionEntry node) { VariableDefinition vd = node.upToVariableDefinition(); if (vd == null) return; if (node.astArrayDimensions() > 0 && vd.astVarargs()) { node.addMessage(error(VARIABLEDEFINITIONENTRY_EXTENDED_DIMENSIONS_NOT_LEGAL, "Extended dimensions are not legal on a varargs declaration.")); } }
public void checkStaticInitializerInNonStaticType(StaticInitializer node) { TypeDeclaration parent = node.upUpToTypeDeclaration(); if (parent != null) { if (!parent.astModifiers().isStatic()) { node.addMessage(error(INITIALIZER_STATIC_IN_NON_STATIC_TYPE, "static initializers are only allowed in top-level or static types declarations.")); } } }
public void checkNotLoneTry(Try node) { if (node.rawCatches().size() == 0 && node.rawFinally() == null) { node.addMessage(error(TRY_LONE_TRY, "try statement with no catches and no finally")); } }
public void varargsAndExtendedDimsDontMix(VariableDefinitionEntry node) { VariableDefinition vd = node.upToVariableDefinition(); if (vd == null) return; if (node.astArrayDimensions() > 0 && vd.astVarargs()) { node.addMessage(error(VARIABLEDEFINITIONENTRY_EXTENDED_DIMENSIONS_NOT_LEGAL, "Extended dimensions are not legal on a varargs declaration.")); } }
private void checkChildOfSwitch(Statement node, String desc) { if (node.getParent() == null) return; Block p = node.upToBlock(); Switch gp = p == null ? null : p.upToSwitch(); boolean genError = false; genError = p == null; genError |= gp == null && p.getParent() != null; if (genError) { node.addMessage(error(STATEMENT_ONLY_LEGAL_IN_SWITCH, desc + " statements are only legal directly inside switch statements.")); } }
public void checkAbstractMembersOnlyInAbstractTypes(MethodDeclaration md) { Modifiers modifiers = md.astModifiers(); if (modifiers == null) return; if (!modifiers.isAbstract()) return; TypeDeclaration parent = md.upUpToTypeDeclaration(); if (parent != null) { Modifiers modifiersOfParent = parent.astModifiers(); if (modifiersOfParent != null && modifiersOfParent.isAbstract()) return; md.addMessage(error(MODIFIERS_ABSTRACT_NOT_ALLOWED, "Abstract methods are only allowed in interfaces and abstract classes")); } }
private void constructorInvocationMustBeFirst(Statement node, String desc) { if (node.getParent() == null) return; Block b = node.upToBlock(); if (b == null || b.upToConstructorDeclaration() == null || b.astContents().first() != node) { node.addMessage(error(CONSTRUCTOR_INVOCATION_NOT_LEGAL_HERE, "Calling " + desc + " must be the first statement in a constructor.")); return; } }
public void checkAbstractMembersOnlyInAbstractTypes(MethodDeclaration md) { Modifiers modifiers = md.astModifiers(); if (modifiers == null) return; if (!modifiers.isAbstract()) return; TypeDeclaration parent = md.upUpToTypeDeclaration(); if (parent != null) { Modifiers modifiersOfParent = parent.astModifiers(); if (modifiersOfParent != null && modifiersOfParent.isAbstract()) return; md.addMessage(error(MODIFIERS_ABSTRACT_NOT_ALLOWED, "Abstract methods are only allowed in interfaces and abstract classes")); } }
private void constructorInvocationMustBeFirst(Statement node, String desc) { if (node.getParent() == null) return; Block b = node.upToBlock(); if (b == null || b.upToConstructorDeclaration() == null || b.astContents().first() != node) { node.addMessage(error(CONSTRUCTOR_INVOCATION_NOT_LEGAL_HERE, "Calling " + desc + " must be the first statement in a constructor.")); return; } }