MethodTreeImpl extends JavaTree implements MethodTree { @Override @Nullable public Boolean isOverriding() { if (isStatic() || isPrivate()) { return false; } if (isAnnotatedOverride()) { return true; } if (symbol() == null) { return null; } Symbol.MethodSymbol methodSymbol = symbol().overriddenSymbol(); if (methodSymbol != null) { return methodSymbol.isUnknown() ? null : true; } return false; } MethodTreeImpl(FormalParametersListTreeImpl parameters, @Nullable SyntaxToken defaultToken, @Nullable ExpressionTree defaultValue);  MethodTreeImpl(
    @Nullable TypeTree returnType,
    IdentifierTree simpleName,
    FormalParametersListTreeImpl parameters,
    @Nullable SyntaxToken throwsToken,
    ListTree<TypeTree> throwsClauses,
    @Nullable BlockTree block,
    @Nullable SyntaxToken semicolonToken); MethodTreeImpl complete(TypeTree returnType, IdentifierTree simpleName, SyntaxToken semicolonToken); MethodTreeImpl completeWithTypeParameters(TypeParameterListTreeImpl typeParameters); MethodTreeImpl completeWithModifiers(ModifiersTreeImpl modifiers); @Override Kind kind(); @Override ModifiersTree modifiers(); @Override TypeParameters typeParameters(); @Nullable @Override TypeTree returnType(); @Override IdentifierTree simpleName(); @Nullable @Override SyntaxToken openParenToken(); @Override List<VariableTree> parameters(); @Nullable @Override SyntaxToken closeParenToken(); @Override SyntaxToken throwsToken(); @Override ListTree<TypeTree> throwsClauses(); @Nullable @Override BlockTree block(); @Nullable @Override SyntaxToken semicolonToken(); @Nullable @Override SyntaxToken defaultToken(); @Nullable @Override ExpressionTree defaultValue(); @Override Symbol.MethodSymbol symbol(); @Override void accept(TreeVisitor visitor); @Override int getLine(); @Nullable @Override CFG cfg(); @Override Iterable<Tree> children(); @Override @Nullable Boolean isOverriding(); boolean isAnnotatedOverride(); @Nullable
  public IMethodBinding methodBinding; }
@Test void override_without_annotation_should_be_detected() { CompilationUnitTree cut = createTree("interface T { int m(); } class A implements T { public int m(){return 0;}}"); ClassTree interfaze = (ClassTree) cut.types().get(0); MethodTreeImpl methodInterface = (MethodTreeImpl) interfaze.members().get(0); ClassTree clazz = (ClassTree) cut.types().get(1); MethodTreeImpl methodClazz = (MethodTreeImpl) clazz.members().get(0); assertThat(methodInterface.isOverriding()).isFalse(); assertThat(methodClazz.isOverriding()).isTrue(); }
@Test void override_with_generic_parameters_should_be_detected() throws Exception { CompilationUnitTree cut = createTree("public class ReferenceQueue<T> {\n" + "\n" + " private static class Null extends ReferenceQueue {\n" + " boolean enqueue(Reference r) {\n" + " return false;\n" + " }\n" + " }\n" + " boolean enqueue(Reference<? extends T> r) {}}" + "public abstract class Reference<T> {}"); ClassTree innerClass = (ClassTree) cut.types().get(0); MethodTreeImpl methodInterface = (MethodTreeImpl) ((ClassTree) innerClass.members().get(0)).members().get(0); assertThat(methodInterface.isOverriding()).isTrue(); }
@Test void hiding_of_static_methods() { CompilationUnitTree cut = createTree("class A { static void foo() {} } class B extends A { void foo(){} } "); ClassTree clazz = (ClassTree) cut.types().get(1); MethodTreeImpl methodTree = (MethodTreeImpl) clazz.members().get(0); assertThat(methodTree.isOverriding()).isFalse(); }
@Test void override_from_object_should_be_detected() { MethodTreeImpl method = getUniqueMethod("class A { public String toString(){return \"\";}}"); assertThat(method.isOverriding()).isTrue(); }
@Test void override_unknown() { MethodTreeImpl method = getUniqueMethod("class A extends Unknown { void foo(){}}"); assertThat(method.isOverriding()).isFalse(); }
@Test void static_method_cannot_be_overriden() { assertThat(getUniqueMethod("class A{ static void m(){}}").isOverriding()).isFalse(); }
@Test void private_method_cannot_be_overriden() { assertThat(getUniqueMethod("class A{ private void m(){}}").isOverriding()).isFalse(); }
@Test void override_annotated_method_should_be_overriden() { assertThat(getUniqueMethod("class A{ @Override void m(){}}").isOverriding()).isTrue(); assertThat(getUniqueMethod("class A{ @Foo @Override void m(){}}").isOverriding()).isTrue(); assertThat(getUniqueMethod("class A{ @java.lang.Override void m(){}}").isOverriding()).isTrue(); assertThat(getUniqueMethod("class A{ @cutom.namespace.Override void m(){}}").isOverriding()).isFalse(); assertThat(getUniqueMethod("class A{ @foo.bar.lang.Override void m(){}}").isOverriding()).isFalse(); assertThat(getUniqueMethod("class A{ @foo.lang.Override void m(){}}").isOverriding()).isFalse(); assertThat(getUniqueMethod("class A{ @Foo void m(){}}").isOverriding()).isFalse(); }