Skip to content

Commit

Permalink
Update according to review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nizarbenalla committed Jan 23, 2025
1 parent cc7cf7d commit 3493320
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,9 @@ default TypeElement getOutermostTypeElement(Element e) {
* elements.getTypeElement("I"));
* }
*
* @apiNote This method implements the overrides relation as specified in JLS {@jls 8.4.8.1}.
* It may not implement the additional compile-time checks that Java compilers follow,
* specified in JLS {@jls 8.4.8.1} and {@jls 8.4.8.3}. In particular, the additional constraints
* on exception types, return types, and method modifiers do not affect the overriding relation.
* @apiNote It may not implement the additional compile-time checks on exception types,
* return types, and method modifiers specified in JLS {@jls 8.4.8.1} and {@jls 8.4.8.3},
* although implementations of this method are allowed to implement these additional checks.
*
* @param overrider the first method, possible overrider
* @param overridden the second method, possibly being overridden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,42 @@
* questions.
*/

/*
* This file models a few cases where Elements.overrides produces a false
* positive which warrants @apiNote.
*/

// S.java does not compile because it violates the JLS rules for overrides
class S {

public void m() { }
}

// `protected` is a weaker modifier than `public`
class T1 extends S {

protected void m() { }
}

// `package-private` is a weaker modifier than `public`
class T2 extends S {

void m() { }
}

// `private` methods cannot override public method
class T3 extends S {

private void m() { }
}

// return type int is not compatible with void
class T4 extends S {

public int m() { return 0; }
}

// adding a checked exception violates the override rule
class T5 extends S {

public void m() throws Exception { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@

import static javax.lang.model.element.ElementKind.METHOD;

/*
* This test models a few cases where Elements.overrides produces a false
* positive which warrants @apiNote.
*/
public class TestOverrides extends JavacTestingAbstractProcessor {

@Override
Expand All @@ -51,7 +47,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
var tm = mIn(t);
if (!elements.overrides(tm, sm, t))
messager.printError(String.format(
"%s does not override %s from %s", tm, sm, t.getQualifiedName()));
"%s does not override from %s method %s", tm, t.getQualifiedName(),sm));
}
}
return true;
Expand Down

0 comments on commit 3493320

Please sign in to comment.