diff options
author | Sven Gothel <[email protected]> | 2015-04-03 05:00:00 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-04-03 05:00:00 +0200 |
commit | c714666c0f4e19bb9db163f576e28d36cad7df74 (patch) | |
tree | d565732fc2fed9d632c33e7b1fbdf99c74dd239c /api/src/main/java/org/osjava/jardiff/PublicDiffCriteria.java | |
parent | 3bbbf1e62e0643dd7efea0fbf45d6ca1828baf0c (diff) |
Add Delta.CompatChange for binary compatible changes, i.e. change in method throws clause or final field value
Change in method throws clause:
- Tools.isThrowsClauseChange(..)
- <https://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.21>
Change of final field value:
- Tools.isFieldValueChange(..)
- <https://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.9>
Diffstat (limited to 'api/src/main/java/org/osjava/jardiff/PublicDiffCriteria.java')
-rw-r--r-- | api/src/main/java/org/osjava/jardiff/PublicDiffCriteria.java | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/api/src/main/java/org/osjava/jardiff/PublicDiffCriteria.java b/api/src/main/java/org/osjava/jardiff/PublicDiffCriteria.java index 90fb382..6cf25d6 100644 --- a/api/src/main/java/org/osjava/jardiff/PublicDiffCriteria.java +++ b/api/src/main/java/org/osjava/jardiff/PublicDiffCriteria.java @@ -28,6 +28,18 @@ import java.util.Set; */ public class PublicDiffCriteria implements DiffCriteria { + @Override + public boolean equals(final Object arg) { + if (arg == this) { + return true; + } else if ( !(arg instanceof PublicDiffCriteria) ) { + return false; + } + return true; // no states + } + @Override + public String toString() { return "PublicDiffCriteria"; } + /** * Check if a class is valid. * If the class is not synthetic and public, return true. @@ -35,7 +47,7 @@ public class PublicDiffCriteria implements DiffCriteria * @param info Info describing the class. * @return True if the class meets the criteria, false otherwise. */ - public boolean validClass(ClassInfo info) { + public boolean validClass(final ClassInfo info) { return !info.isSynthetic() && info.isPublic(); } @@ -46,7 +58,7 @@ public class PublicDiffCriteria implements DiffCriteria * @param info Info describing the method. * @return True if the method meets the criteria, false otherwise. */ - public boolean validMethod(MethodInfo info) { + public boolean validMethod(final MethodInfo info) { return !info.isSynthetic() && info.isPublic(); } @@ -57,7 +69,7 @@ public class PublicDiffCriteria implements DiffCriteria * @param info Info describing the field. * @return True if the field meets the criteria, false otherwise. */ - public boolean validField(FieldInfo info) { + public boolean validField(final FieldInfo info) { return !info.isSynthetic() && info.isPublic(); } @@ -70,7 +82,7 @@ public class PublicDiffCriteria implements DiffCriteria * @param newInfo Info about the new version of the class. * @return True if the classes differ, false otherwise. */ - public boolean differs(ClassInfo oldInfo, ClassInfo newInfo) { + public boolean differs(final ClassInfo oldInfo, final ClassInfo newInfo) { if (Tools.isClassAccessChange(oldInfo.getAccess(), newInfo.getAccess())) return true; // Yes classes can have a null supername, e.g. java.lang.Object ! @@ -99,20 +111,18 @@ public class PublicDiffCriteria implements DiffCriteria * @param newInfo Info about the new version of the method. * @return True if the methods differ, false otherwise. */ - public boolean differs(MethodInfo oldInfo, MethodInfo newInfo) { - if (Tools.isMethodAccessChange(oldInfo.getAccess(), newInfo.getAccess())) + public boolean differs(final MethodInfo oldInfo, final MethodInfo newInfo) { + if (Tools.isMethodAccessChange(oldInfo.getAccess(), newInfo.getAccess())) { + return true; + } + if (Tools.isThrowsClauseChange(oldInfo.getExceptions(), newInfo.getExceptions())) { + return true; + } + return false; + } + public boolean differsBinary(final MethodInfo oldInfo, final MethodInfo newInfo) { + if (Tools.isMethodAccessChange(oldInfo.getAccess(), newInfo.getAccess())) { return true; - if (oldInfo.getExceptions() == null - || newInfo.getExceptions() == null) { - if (oldInfo.getExceptions() != newInfo.getExceptions()) - return true; - } else { - final Set<String> oldExceptions - = new HashSet(Arrays.asList(oldInfo.getExceptions())); - final Set<String> newExceptions - = new HashSet(Arrays.asList(newInfo.getExceptions())); - if (!oldExceptions.equals(newExceptions)) - return true; } return false; } @@ -126,14 +136,19 @@ public class PublicDiffCriteria implements DiffCriteria * @param newInfo Info about the new version of the field. * @return True if the fields differ, false otherwise. */ - public boolean differs(FieldInfo oldInfo, FieldInfo newInfo) { - if (Tools.isFieldAccessChange(oldInfo.getAccess(), newInfo.getAccess())) + public boolean differs(final FieldInfo oldInfo, final FieldInfo newInfo) { + if (Tools.isFieldAccessChange(oldInfo.getAccess(), newInfo.getAccess())) { return true; - if (oldInfo.getValue() == null || newInfo.getValue() == null) { - if (oldInfo.getValue() != newInfo.getValue()) - return true; - } else if (!oldInfo.getValue().equals(newInfo.getValue())) + } + if (Tools.isFieldValueChange(oldInfo.getValue(), newInfo.getValue())) { return true; + } + return false; + } + public boolean differsBinary(final FieldInfo oldInfo, final FieldInfo newInfo) { + if (Tools.isFieldAccessChange(oldInfo.getAccess(), newInfo.getAccess())) { + return true; + } return false; } } |