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.missingJavadocTagsOverriding=disabled
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.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=error

View File

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

View File

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

View File

@ -32,10 +32,12 @@ class Base {
}
class Derived extends Base {
@Override
public void foo() {
super.foo();
}
@Override
public String bar(int 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]
*/
@Override
public int getConstant() {
return y;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -76,6 +76,7 @@ public class ConstructorsAndInitializers extends Super {
iX = 55 + 12;
}
@Override
public String toString() {
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() {
final int x = 54;
class FooBar {
@Override
public int hashCode() { return x; }
}
return new FooBar();
@ -53,6 +54,7 @@ public class InnerClasses extends Temp {
static Object anonymousCoward() {
final int x = 5;
return new Object() {
@Override
public int hashCode() { return x; }
};
}
@ -64,6 +66,7 @@ public class InnerClasses extends Temp {
System.out.println(anonymousCoward().hashCode());
final String xx = "crazy";
Outie outie = new Outie("weird") {
@Override
public String toString() {
return "bogus" + x + xx + xxxx;
}

View File

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

View File

@ -45,6 +45,7 @@ public class AnonGeneNullarySimple {
static class StrTripler implements Ops<String> {
@Override
public String nullary() {
String x = "talk about it ";
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
// that calls this one (with casts). no worries about return values.
@Override
public String unary(String x) {
return x + x + x;
}
@Override
public String nullary() {
String x = "talk about it ";
return x+x+x;
@ -66,10 +68,12 @@ public class AnonymousGenerics {
private void doit() {
Ops<String> strQuadrupler = new Ops<String>() {
@Override
public String unary(String x) {
return x+x+x+x;
}
@Override
public String nullary() {
String x = "time to make a move to the global economy ";
return x+x+x+x;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -70,6 +70,7 @@ class VarityTestSuper {
class VarityTestSub extends VarityTestSuper {
@Override
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.missingJavadocTagsOverriding=disabled
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.missingSerialVersion=warning
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)
*/
@Override
@SuppressWarnings("all")
public boolean add(T o) {
if (o == null) {