forked from uber/NullAway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87ec10d
commit 8646811
Showing
6 changed files
with
193 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 5 additions & 51 deletions
56
nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,16 @@ | ||
package com.uber.nullaway.dataflow; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
import javax.lang.model.element.Element; | ||
|
||
/** | ||
* Represents a (non-root) element of an AccessPath. | ||
* | ||
* <p>This is just a java Element (field, method, etc) in the access-path chain (e.g. f or g() in | ||
* x.f.g()). Plus, optionally, a list of constant arguments, allowing access path elements for | ||
* method calls with constant values (e.g. h(3) or k("STR_KEY") in x.h(3).g().k("STR_KEY")). | ||
*/ | ||
public final class AccessPathElement { | ||
private final Element javaElement; | ||
@Nullable private final ImmutableList<String> constantArguments; | ||
|
||
public AccessPathElement(Element javaElement, List<String> constantArguments) { | ||
this.javaElement = javaElement; | ||
this.constantArguments = ImmutableList.copyOf(constantArguments); | ||
} | ||
|
||
public AccessPathElement(Element javaElement) { | ||
this.javaElement = javaElement; | ||
this.constantArguments = null; | ||
} | ||
|
||
public Element getJavaElement() { | ||
return this.javaElement; | ||
} | ||
public interface AccessPathElement { | ||
Element getJavaElement(); | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof AccessPathElement) { | ||
AccessPathElement otherNode = (AccessPathElement) obj; | ||
return this.javaElement.equals(otherNode.javaElement) | ||
&& Objects.equals(constantArguments, otherNode.constantArguments); | ||
} else { | ||
return false; | ||
} | ||
} | ||
String toString(); | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = javaElement.hashCode(); | ||
result = 31 * result + (constantArguments != null ? constantArguments.hashCode() : 0); | ||
return result; | ||
} | ||
boolean equals(Object obj); | ||
|
||
@Override | ||
public String toString() { | ||
return "APElement{" | ||
+ "javaElement=" | ||
+ javaElement.toString() | ||
+ ", constantArguments=" | ||
+ Arrays.deepToString(constantArguments != null ? constantArguments.toArray() : null) | ||
+ '}'; | ||
} | ||
int hashCode(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
nullaway/src/main/java/com/uber/nullaway/dataflow/ArrayIndexElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.uber.nullaway.dataflow; | ||
|
||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
import javax.lang.model.element.Element; | ||
|
||
public class ArrayIndexElement implements AccessPathElement { | ||
private final Element javaElement; | ||
@Nullable final String index; | ||
|
||
public ArrayIndexElement(Element javaElement, @Nullable String index) { | ||
this.javaElement = javaElement; | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public Element getJavaElement() { | ||
return this.javaElement; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ArrayIndexElement{" + "javaElement=" + javaElement + ", index=" + index + '}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof ArrayIndexElement) { | ||
ArrayIndexElement otherNode = (ArrayIndexElement) obj; | ||
return this.javaElement.equals(otherNode.javaElement) | ||
&& Objects.equals(index, otherNode.index); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = javaElement.hashCode(); | ||
result = 31 * result + (index != null ? index.hashCode() : 0); | ||
return result; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
nullaway/src/main/java/com/uber/nullaway/dataflow/FieldOrMethodCallElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.uber.nullaway.dataflow; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import javax.annotation.Nullable; | ||
import javax.lang.model.element.Element; | ||
|
||
public class FieldOrMethodCallElement implements AccessPathElement { | ||
private final Element javaElement; | ||
@Nullable private final ImmutableList<String> constantArguments; | ||
|
||
public FieldOrMethodCallElement(Element javaElement, List<String> constantArguments) { | ||
this.javaElement = javaElement; | ||
this.constantArguments = ImmutableList.copyOf(constantArguments); | ||
} | ||
|
||
public FieldOrMethodCallElement(Element javaElement) { | ||
this.javaElement = javaElement; | ||
this.constantArguments = null; | ||
} | ||
|
||
@Override | ||
public Element getJavaElement() { | ||
return this.javaElement; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof FieldOrMethodCallElement) { | ||
FieldOrMethodCallElement other = (FieldOrMethodCallElement) obj; | ||
return this.javaElement.equals(other.javaElement) | ||
&& Objects.equals(this.constantArguments, other.constantArguments); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = javaElement.hashCode(); | ||
result = 31 * result + (constantArguments != null ? constantArguments.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FieldOrMethodCallElement{" | ||
+ "javaElement=" | ||
+ javaElement | ||
+ ", constantArguments=" | ||
+ (constantArguments != null ? Arrays.toString(constantArguments.toArray()) : "null") | ||
+ '}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters