Skip to content

Commit

Permalink
refactored OvershadowingSubclassFields so you can now suppress the ch…
Browse files Browse the repository at this point in the history
…eck on

individual fields

Fixes #668

MOE_MIGRATED_REVID=161142216
  • Loading branch information
sulku authored and cushon committed Aug 10, 2017
1 parent e3ad8ab commit ca2e796
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Expand Up @@ -66,7 +66,11 @@ public Description matchClass(ClassTree classTree, VisitorState visitorState) {
.stream()
.filter(mem -> mem instanceof VariableTree)
.map(mem -> (VariableTree) mem)
.filter(mem -> !isIgnoredType(mem) && !isStatic(mem))
.filter(
mem ->
!isSuppressed(ASTHelpers.getSymbol(mem))
&& !isIgnoredType(mem)
&& !isStatic(mem))
.collect(toCollection(ArrayList::new));

ClassSymbol classSymbol = ASTHelpers.getSymbol(classTree);
Expand Down
Expand Up @@ -22,19 +22,28 @@
public class OvershadowingSubclassFieldsNegativeCases {
// base class
static class ClassA {
private int varOne;
public int varOne;
}

// subclass with member variables of different names
static class ClassB extends ClassA {
private String varTwo;
private int varThree;
public static int varFour;
public int varFive;
}

// subclass with initialized member variable of different name
static class ClassC extends ClassB {
private String varFour = "Test";

// warning suppressed when overshadowing variable in parent
@SuppressWarnings("OvershadowingSubclassFields")
public int varFive;

// warning suppressed when overshadowing variable in grandparent
@SuppressWarnings("OvershadowingSubclassFields")
public int varOne;
}

// subclass with member *methods* with the same name as superclass member variable -- this is ok
Expand Down
Expand Up @@ -55,10 +55,21 @@ public static class ClassD extends ClassB {
String randTwo;
}

/** ClassF has same variable name as grandparent */
public static class ClassF extends ClassC {
/** ClassE has same variable name as grandparent */
public static class ClassE extends ClassC {
// BUG: Diagnostic contains: Overshadowing variables of superclass causes confusion and errors.
// This variable is overshadowing a variable in superclass: ClassC
public String varTwo;
}

public static class ClassF extends ClassA {
@SuppressWarnings("OvershadowingSubclassFields") // no warning because it's suppressed
public String varThree;
}

public static class ClassG extends ClassF {
// BUG: Diagnostic contains: Overshadowing variables of superclass causes confusion and errors.
// This variable is overshadowing a variable in superclass: ClassF
String varThree;
}
}

0 comments on commit ca2e796

Please sign in to comment.