Add @Override annotations wherever possible

In the `com.ibm.wala.util` project, configure Eclipse to treat any
future violations of this as errors, not merely warnings.

However, in `com.ibm.wala.cast.java.test.data`, configure Eclipse to
silently ignore missing @Override annotations.  The JLex code in this
project is machine-generated, and we don't have a way to get the
generator to produce @Override annotations.
This commit is contained in:
Ben Liblit 2017-06-27 10:42:05 -05:00 committed by Manu Sridharan
parent 773fa68a3f
commit bb032c9869
25 changed files with 47 additions and 2 deletions

View File

@ -58,7 +58,7 @@ org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=error org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=error

View File

@ -20,8 +20,10 @@ public class AnonymousClass {
Foo f= new Foo() { Foo f= new Foo() {
int value = 3; int value = 3;
@Override
public int getValue() { return value; } public int getValue() { return value; }
@Override
public int getValueBase() { return value - base.intValue(); } public int getValueBase() { return value - base.intValue(); }
}; };
@ -38,6 +40,7 @@ public class AnonymousClass {
int y; int y;
@Override
public abstract int getValue(); public abstract int getValue();
FooImpl(int _y) { FooImpl(int _y) {
@ -45,6 +48,7 @@ public class AnonymousClass {
} }
@Override
public int getValueBase() { public int getValueBase() {
return y + getValue() - base.intValue(); return y + getValue() - base.intValue();
} }
@ -52,6 +56,7 @@ public class AnonymousClass {
Foo f= new FooImpl(-4) { Foo f= new FooImpl(-4) {
@Override
public int getValue() { return 7; } public int getValue() { return 7; }
}; };

View File

@ -22,6 +22,7 @@ public class FunkySupers {
class SubFunkySupers extends FunkySupers { class SubFunkySupers extends FunkySupers {
@Override
int funky(FunkySupers fs) { int funky(FunkySupers fs) {
SubFunkySupers.super.funky(fs); SubFunkySupers.super.funky(fs);
SubFunkySupers.this.funky(fs); SubFunkySupers.this.funky(fs);

View File

@ -32,10 +32,12 @@ class Base {
} }
class Derived extends Base { class Derived extends Base {
@Override
public void foo() { public void foo() {
super.foo(); super.foo();
} }
@Override
public String bar(int x) { public String bar(int x) {
return Integer.toHexString(x); return Integer.toHexString(x);
} }

View File

@ -32,6 +32,7 @@ public class InnerClassLexicalReads {
* 1 return v2:com.ibm.wala.ssa.SymbolTable$1@16b18b6[11:4] -> [11:13] * 1 return v2:com.ibm.wala.ssa.SymbolTable$1@16b18b6[11:4] -> [11:13]
*/ */
@Override
public int getConstant() { public int getConstant() {
return y; return y;
} }

View File

@ -28,6 +28,7 @@ class FooIT1 implements IFoo {
fValue= ch; fValue= ch;
} }
@Override
public char getValue() { public char getValue() {
return fValue; return fValue;
} }

View File

@ -30,6 +30,7 @@ abstract class PrimitiveWrapper {
* @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#equals(java.lang.Object)
*/ */
@Override
abstract public boolean equals(Object o); abstract public boolean equals(Object o);
} }
@ -49,6 +50,7 @@ final class IntWrapper extends PrimitiveWrapper {
* @see com.ibm.miniatur.tests.sequential.PrimitiveWrapper#intValue() * @see com.ibm.miniatur.tests.sequential.PrimitiveWrapper#intValue()
*/ */
@Override
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public int intValue() { public int intValue() {
return val; return val;
@ -59,6 +61,7 @@ final class IntWrapper extends PrimitiveWrapper {
* @see com.ibm.miniatur.tests.sequential.PrimitiveWrapper#setIntValue(int) * @see com.ibm.miniatur.tests.sequential.PrimitiveWrapper#setIntValue(int)
*/ */
@Override
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public void setIntValue(int i) { public void setIntValue(int i) {
this.val = i; this.val = i;
@ -69,6 +72,7 @@ final class IntWrapper extends PrimitiveWrapper {
* @see com.ibm.miniatur.tests.sequential.PrimitiveWrapper#equals(java.lang.Object) * @see com.ibm.miniatur.tests.sequential.PrimitiveWrapper#equals(java.lang.Object)
*/ */
@Override
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public boolean equals(Object o) { public boolean equals(Object o) {
return o instanceof IntWrapper && ((IntWrapper)o).val==val; return o instanceof IntWrapper && ((IntWrapper)o).val==val;

View File

@ -14,6 +14,7 @@ interface ISimpleCalls {
} }
public class SimpleCalls implements ISimpleCalls { public class SimpleCalls implements ISimpleCalls {
@Override
public void helloWorld() { public void helloWorld() {
System.out.println("hello world!"); System.out.println("hello world!");
} }

View File

@ -14,6 +14,7 @@ class R implements Runnable {
R(int i) { this.i = i; } R(int i) { this.i = i; }
@Override
public void run() { public void run() {
return; return;
} }

View File

@ -56,6 +56,7 @@ public class SimpleNames {
final int i = 5; final int i = 5;
new Object() { new Object() {
@Override
public int hashCode() { public int hashCode() {
f = 5; // SimpleNames.this = 5 f = 5; // SimpleNames.this = 5
s = 6; // SimpleNames.s = 6 s = 6; // SimpleNames.s = 6

View File

@ -76,6 +76,7 @@ public class ConstructorsAndInitializers extends Super {
iX = 55 + 12; iX = 55 + 12;
} }
@Override
public String toString() { public String toString() {
return s + " -- from an anon class in " + iX + "," + sX + ": " + ConstructorsAndInitializers.this.s; return s + " -- from an anon class in " + iX + "," + sX + ": " + ConstructorsAndInitializers.this.s;
} }

View File

@ -45,6 +45,7 @@ public class InnerClasses extends Temp {
Object supportLocalBusiness() { Object supportLocalBusiness() {
final int x = 54; final int x = 54;
class FooBar { class FooBar {
@Override
public int hashCode() { return x; } public int hashCode() { return x; }
} }
return new FooBar(); return new FooBar();
@ -53,6 +54,7 @@ public class InnerClasses extends Temp {
static Object anonymousCoward() { static Object anonymousCoward() {
final int x = 5; final int x = 5;
return new Object() { return new Object() {
@Override
public int hashCode() { return x; } public int hashCode() { return x; }
}; };
} }
@ -64,6 +66,7 @@ public class InnerClasses extends Temp {
System.out.println(anonymousCoward().hashCode()); System.out.println(anonymousCoward().hashCode());
final String xx = "crazy"; final String xx = "crazy";
Outie outie = new Outie("weird") { Outie outie = new Outie("weird") {
@Override
public String toString() { public String toString() {
return "bogus" + x + xx + xxxx; return "bogus" + x + xx + xxxx;
} }

View File

@ -96,6 +96,7 @@ public class MethodMadness {
return 13 + x; return 13 + x;
} }
@Override
protected int protectedInteger() { protected int protectedInteger() {
return 233 + x; return 233 + x;
} }

View File

@ -45,6 +45,7 @@ public class AnonGeneNullarySimple {
static class StrTripler implements Ops<String> { static class StrTripler implements Ops<String> {
@Override
public String nullary() { public String nullary() {
String x = "talk about it "; String x = "talk about it ";
return x+x+x; return x+x+x;

View File

@ -49,10 +49,12 @@ public class AnonymousGenerics {
// get erasures for all of those types and make a new method // get erasures for all of those types and make a new method
// that calls this one (with casts). no worries about return values. // that calls this one (with casts). no worries about return values.
@Override
public String unary(String x) { public String unary(String x) {
return x + x + x; return x + x + x;
} }
@Override
public String nullary() { public String nullary() {
String x = "talk about it "; String x = "talk about it ";
return x+x+x; return x+x+x;
@ -66,10 +68,12 @@ public class AnonymousGenerics {
private void doit() { private void doit() {
Ops<String> strQuadrupler = new Ops<String>() { Ops<String> strQuadrupler = new Ops<String>() {
@Override
public String unary(String x) { public String unary(String x) {
return x+x+x+x; return x+x+x+x;
} }
@Override
public String nullary() { public String nullary() {
String x = "time to make a move to the global economy "; String x = "time to make a move to the global economy ";
return x+x+x+x; return x+x+x+x;

View File

@ -43,10 +43,12 @@ public class Cocovariant {
} }
static class B extends A { static class B extends A {
@Override
B foo(String x) { return null; } B foo(String x) { return null; }
} }
static class C extends B { static class C extends B {
@Override
C foo(String x) { return null; } C foo(String x) { return null; }
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -52,6 +52,7 @@ class ConcreteGeneric<Q> implements IGeneric<Q> {
Q x; Q x;
@Override
public Q bar(Q a, Q b) { public Q bar(Q a, Q b) {
x = a; x = a;
if (b.hashCode() == a.hashCode() || b.toString().equals(a.toString())) if (b.hashCode() == a.hashCode() || b.toString().equals(a.toString()))
@ -60,6 +61,7 @@ class ConcreteGeneric<Q> implements IGeneric<Q> {
} }
@Override
public Q foo() { public Q foo() {
return x; return x;
} }
@ -71,6 +73,7 @@ class ConcreteGeneric2<Q> extends ConcreteGeneric<Q> {
y = a; y = a;
} }
@Override
public Q foo() { public Q foo() {
return y; return y;
} }

View File

@ -46,17 +46,20 @@ public class GenericMemberClasses<T>
T x = null; T x = null;
private int localChangeID; private int localChangeID;
@Override
public boolean hasNext() { public boolean hasNext() {
return ( localChangeID == 5 ); return ( localChangeID == 5 );
} }
@Override
public T next() { public T next() {
localChangeID = 5; localChangeID = 5;
return x; return x;
} }
@Override
public void remove() { public void remove() {
} }
} }

View File

@ -48,6 +48,7 @@ public class MoreOverriddenGenerics {
class Sub extends Super<Number> { class Sub extends Super<Number> {
@Override
public Number get() { public Number get() {
return super.get(); return super.get();
} }
@ -55,6 +56,7 @@ public class MoreOverriddenGenerics {
class SubSub extends Sub { class SubSub extends Sub {
@Override
public Long get() { public Long get() {
return new Long(6); return new Long(6);
} }

View File

@ -40,12 +40,16 @@ package javaonepointfive;
public class NotSoSimpleEnums { public class NotSoSimpleEnums {
public enum Direction { public enum Direction {
NORTH("nord") { NORTH("nord") {
@Override
public Direction getOpposite() { return SOUTH; }}, public Direction getOpposite() { return SOUTH; }},
EAST("est") { EAST("est") {
@Override
public Direction getOpposite() { return WEST; }}, public Direction getOpposite() { return WEST; }},
SOUTH("sud") { SOUTH("sud") {
@Override
public Direction getOpposite() { return NORTH; }}, public Direction getOpposite() { return NORTH; }},
WEST("ouest") { WEST("ouest") {
@Override
public Direction getOpposite() { return EAST; }}; public Direction getOpposite() { return EAST; }};
public abstract Direction getOpposite(); public abstract Direction getOpposite();

View File

@ -44,6 +44,7 @@ public class OverridesOnePointFour {
static class Sub implements Super { static class Sub implements Super {
@Override
public Long get() { public Long get() {
return new Long(6); return new Long(6);
} }

View File

@ -47,6 +47,7 @@ public class VarargsCovariant {
static class B extends A { static class B extends A {
@Override
B hello(int... x) { B hello(int... x) {
System.out.println("b hello"); System.out.println("b hello");
return this; return this;

View File

@ -70,6 +70,7 @@ class VarityTestSuper {
class VarityTestSub extends VarityTestSuper { class VarityTestSub extends VarityTestSuper {
@Override
void bar(String... args) {} void bar(String... args) {}
} }

View File

@ -58,7 +58,7 @@ org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=error
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=error org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=error

View File

@ -106,6 +106,7 @@ public class ArraySet<T> extends AbstractSet<T> {
/** /**
* @throws UnsupportedOperationException if this {@link ArraySet} is immutable (optional) * @throws UnsupportedOperationException if this {@link ArraySet} is immutable (optional)
*/ */
@Override
@SuppressWarnings("all") @SuppressWarnings("all")
public boolean add(T o) { public boolean add(T o) {
if (o == null) { if (o == null) {