aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/main/java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-05-13 16:06:10 +0200
committerSven Gothel <[email protected]>2014-05-13 23:05:54 +0200
commitd44d189bfd816a9936ae20d8582ec8475c830189 (patch)
tree1a7d899e4996fe3edb0401fe5910d06e636a69f2 /api/src/main/java
parent8989dfc820b14c25ef7d9cb4bad8e265719c5ef3 (diff)
AbstractInfo: Add generic access to signature and descriptor ; Dumper: More info (access, desc + sig), allow passing PrintStream
Diffstat (limited to 'api/src/main/java')
-rw-r--r--api/src/main/java/org/osjava/jardiff/AbstractInfo.java76
-rw-r--r--api/src/main/java/org/osjava/jardiff/ClassInfo.java41
-rw-r--r--api/src/main/java/org/osjava/jardiff/FieldInfo.java30
-rw-r--r--api/src/main/java/org/osjava/jardiff/MethodInfo.java26
-rwxr-xr-xapi/src/main/java/org/semver/Dumper.java80
5 files changed, 153 insertions, 100 deletions
diff --git a/api/src/main/java/org/osjava/jardiff/AbstractInfo.java b/api/src/main/java/org/osjava/jardiff/AbstractInfo.java
index bf892e6..ea69829 100644
--- a/api/src/main/java/org/osjava/jardiff/AbstractInfo.java
+++ b/api/src/main/java/org/osjava/jardiff/AbstractInfo.java
@@ -26,13 +26,13 @@ import org.objectweb.asm.Opcodes;
public abstract class AbstractInfo
{
/**
- * The string used to represent a class, method or field with public
+ * The string used to represent a class, method or field with public
* access.
*/
public final String ACCESS_PUBLIC = "public";
-
+
/**
- * The string used to represent a class, method or field with protected
+ * The string used to represent a class, method or field with protected
* access.
*/
public final String ACCESS_PROTECTED = "protected";
@@ -55,12 +55,12 @@ public abstract class AbstractInfo
* The access flags for this class, method or field.
*/
private final int access;
-
+
/**
* The internal name of this class, method or field.
*/
private final String name;
-
+
/**
* Construct a new AbstractInfo with the specified access and name.
*
@@ -71,7 +71,21 @@ public abstract class AbstractInfo
this.access = access;
this.name = name;
}
-
+
+ /**
+ * Get the descriptor
+ *
+ * @return The descriptor.
+ */
+ public abstract String getDesc();
+
+ /**
+ * Get the signature
+ *
+ * @return The signature.
+ */
+ public abstract String getSignature();
+
/**
* Get the access flags for this class, method or field.
*
@@ -80,7 +94,7 @@ public abstract class AbstractInfo
public final int getAccess() {
return access;
}
-
+
/**
* Get the internal name of this class, method or field.
*
@@ -89,7 +103,7 @@ public abstract class AbstractInfo
public final String getName() {
return name;
}
-
+
/**
* Test if this class, method or field is public.
*
@@ -98,7 +112,7 @@ public abstract class AbstractInfo
public final boolean isPublic() {
return (access & Opcodes.ACC_PUBLIC) != 0;
}
-
+
/**
* Test if this class, method or field is protected.
*
@@ -107,17 +121,17 @@ public abstract class AbstractInfo
public final boolean isProtected() {
return (access & Opcodes.ACC_PROTECTED) != 0;
}
-
+
/**
* Test if this class, method or field is package private.
*
* @return true if it is package private.
*/
public final boolean isPackagePrivate() {
- return (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED |
+ return (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED |
Opcodes.ACC_PRIVATE)) == 0;
}
-
+
/**
* Test if this class, method or field is private.
*
@@ -126,7 +140,7 @@ public abstract class AbstractInfo
public final boolean isPrivate() {
return (access & Opcodes.ACC_PRIVATE) != 0;
}
-
+
/**
* Test if this class, method or field is abstract.
*
@@ -135,7 +149,7 @@ public abstract class AbstractInfo
public final boolean isAbstract() {
return (access & Opcodes.ACC_ABSTRACT) != 0;
}
-
+
/**
* Test if this class, method or field is annotation
*
@@ -144,7 +158,7 @@ public abstract class AbstractInfo
public final boolean isAnnotation() {
return (access & Opcodes.ACC_ANNOTATION) != 0;
}
-
+
/**
* Test if this class, method or field is a bridge
*
@@ -153,7 +167,7 @@ public abstract class AbstractInfo
public final boolean isBridge() {
return (access & Opcodes.ACC_BRIDGE) != 0;
}
-
+
/**
* Test if this class, method or field is deprecated.
*
@@ -162,7 +176,7 @@ public abstract class AbstractInfo
public final boolean isDeprecated() {
return (access & Opcodes.ACC_DEPRECATED) != 0;
}
-
+
/**
* Test if this class, method or field is an enum.
*
@@ -171,7 +185,7 @@ public abstract class AbstractInfo
public final boolean isEnum() {
return (access & Opcodes.ACC_ENUM) != 0;
}
-
+
/**
* Test if this class, method or field is final.
*
@@ -180,7 +194,7 @@ public abstract class AbstractInfo
public final boolean isFinal() {
return (access & Opcodes.ACC_FINAL) != 0;
}
-
+
/**
* Test if this class, method or field is an interface.
*
@@ -189,7 +203,7 @@ public abstract class AbstractInfo
public final boolean isInterface() {
return (access & Opcodes.ACC_INTERFACE) != 0;
}
-
+
/**
* Test if this class, method or field is native.
*
@@ -198,7 +212,7 @@ public abstract class AbstractInfo
public final boolean isNative() {
return (access & Opcodes.ACC_NATIVE) != 0;
}
-
+
/**
* Test if this class, method or field is static.
*
@@ -207,7 +221,7 @@ public abstract class AbstractInfo
public final boolean isStatic() {
return (access & Opcodes.ACC_STATIC) != 0;
}
-
+
/**
* Test if this class, method or field is string.
*
@@ -216,7 +230,7 @@ public abstract class AbstractInfo
public final boolean isStrict() {
return (access & Opcodes.ACC_STRICT) != 0;
}
-
+
/**
* Test if this class, method or field is super.
*
@@ -225,7 +239,7 @@ public abstract class AbstractInfo
public final boolean isSuper() {
return (access & Opcodes.ACC_SUPER) != 0;
}
-
+
/**
* Test if this class, method or field is synchronized.
*
@@ -234,7 +248,7 @@ public abstract class AbstractInfo
public final boolean isSynchronized() {
return (access & Opcodes.ACC_SYNCHRONIZED) != 0;
}
-
+
/**
* Test if this class, method or field is synthetic.
*
@@ -243,7 +257,7 @@ public abstract class AbstractInfo
public final boolean isSynthetic() {
return (access & Opcodes.ACC_SYNTHETIC) != 0;
}
-
+
/**
* Test if this class or field is transient.
* If this flag is set on a method it means something different.
@@ -254,7 +268,7 @@ public abstract class AbstractInfo
return !(this instanceof MethodInfo) &&
((access & Opcodes.ACC_TRANSIENT) != 0);
}
-
+
/**
* Test if this method is varargs.
* If this flag is set on a class or field it means something different.
@@ -264,19 +278,19 @@ public abstract class AbstractInfo
* @return true if it is varargs.
*/
public final boolean isVarargs() {
- return (this instanceof MethodInfo) &&
+ return (this instanceof MethodInfo) &&
((access & Opcodes.ACC_VARARGS) != 0);
}
-
+
/**
* Test if this class, method or field is volatile.
- *
+ *
* @return true if it is volatile.
*/
public final boolean isVolatile() {
return (access & Opcodes.ACC_VOLATILE) != 0;
}
-
+
/**
* Retrieve the access level for this class, method or field.
*
diff --git a/api/src/main/java/org/osjava/jardiff/ClassInfo.java b/api/src/main/java/org/osjava/jardiff/ClassInfo.java
index 5058048..a92aae9 100644
--- a/api/src/main/java/org/osjava/jardiff/ClassInfo.java
+++ b/api/src/main/java/org/osjava/jardiff/ClassInfo.java
@@ -27,36 +27,36 @@ public final class ClassInfo extends AbstractInfo
/**
* The classfile version number.
*/
- private int version;
+ private final int version;
/**
* The class signature.
*/
- private String signature;
+ private final String signature;
/**
* The internal classname of the superclass.
*/
- private String supername;
+ private final String supername;
/**
* An array of names of internal classnames of interfaces implemented
* by the class.
*/
- private String[] interfaces;
+ private final String[] interfaces;
/**
- * A map of method signature to MethodInfo, for the methods provided
+ * A map of method signature to MethodInfo, for the methods provided
* by this class.
*/
- private Map<String, MethodInfo> methodMap;
+ private final Map<String, MethodInfo> methodMap;
/**
- * A map of field signature to FieldInfo, for the fields provided by
+ * A map of field signature to FieldInfo, for the fields provided by
* this class.
*/
- private Map<String, FieldInfo> fieldMap;
-
+ private final Map<String, FieldInfo> fieldMap;
+
/**
* Create a new classinfo.
*
@@ -80,7 +80,7 @@ public final class ClassInfo extends AbstractInfo
this.methodMap = methodMap;
this.fieldMap = fieldMap;
}
-
+
/**
* Get the class file version.
*
@@ -89,16 +89,17 @@ public final class ClassInfo extends AbstractInfo
public final int getVersion() {
return version;
}
-
- /**
- * Get the class signature.
- *
- * @return the class signature
- */
+
+ @Override
+ public final String getDesc() {
+ return null;
+ }
+
+ @Override
public final String getSignature() {
return signature;
}
-
+
/**
* Get the internal name of the superclass.
*
@@ -107,7 +108,7 @@ public final class ClassInfo extends AbstractInfo
public final String getSupername() {
return supername;
}
-
+
/**
* Get the internal names of the interfaces implemented by this class
*
@@ -116,7 +117,7 @@ public final class ClassInfo extends AbstractInfo
public final String[] getInterfaces() {
return interfaces;
}
-
+
/**
* Get the map of method signatures to methods.
*
@@ -125,7 +126,7 @@ public final class ClassInfo extends AbstractInfo
public final Map<String, MethodInfo> getMethodMap() {
return methodMap;
}
-
+
/**
* Get the map of field signatures to fields.
*
diff --git a/api/src/main/java/org/osjava/jardiff/FieldInfo.java b/api/src/main/java/org/osjava/jardiff/FieldInfo.java
index bf7f53e..ef86ea7 100644
--- a/api/src/main/java/org/osjava/jardiff/FieldInfo.java
+++ b/api/src/main/java/org/osjava/jardiff/FieldInfo.java
@@ -26,18 +26,18 @@ public final class FieldInfo extends AbstractInfo
/**
* The field descriptor for this field.
*/
- private String desc;
-
+ private final String desc;
+
/**
* The signature for this field.
*/
- private String signature;
-
+ private final String signature;
+
/**
* The initial value of this field.
*/
- private Object value;
-
+ private final Object value;
+
/**
* Create a new FieldInfo
*
@@ -54,25 +54,17 @@ public final class FieldInfo extends AbstractInfo
this.signature = signature;
this.value = value;
}
-
- /**
- * Get the descriptor for this FieldInfo.
- *
- * @return The field descriptor.
- */
+
+ @Override
public final String getDesc() {
return desc;
}
-
- /**
- * Get the signature for this fieldinfo.
- *
- * @return The signature.
- */
+
+ @Override
public final String getSignature() {
return signature;
}
-
+
/**
* Get the initial value for this fieldinfo
*
diff --git a/api/src/main/java/org/osjava/jardiff/MethodInfo.java b/api/src/main/java/org/osjava/jardiff/MethodInfo.java
index b7ac46b..0a59c60 100644
--- a/api/src/main/java/org/osjava/jardiff/MethodInfo.java
+++ b/api/src/main/java/org/osjava/jardiff/MethodInfo.java
@@ -26,18 +26,18 @@ public final class MethodInfo extends AbstractInfo
/**
* The method descriptor.
*/
- private String desc;
+ private final String desc;
/**
* The signature of the method.
*/
- private String signature;
+ private final String signature;
/**
* An array of the exceptions thrown by this method.
*/
- private String[] exceptions;
-
+ private final String[] exceptions;
+
/**
* Create a new MethodInfo with the specified parameters.
*
@@ -53,25 +53,17 @@ public final class MethodInfo extends AbstractInfo
this.signature = signature;
this.exceptions = exceptions;
}
-
- /**
- * Get the descriptor for the method.
- *
- * @return the descriptor
- */
+
+ @Override
public final String getDesc() {
return desc;
}
-
- /**
- * Get the signature for the method.
- *
- * @return the signature
- */
+
+ @Override
public final String getSignature() {
return signature;
}
-
+
/**
* Get the array of exceptions which can be thrown by the method.
*
diff --git a/api/src/main/java/org/semver/Dumper.java b/api/src/main/java/org/semver/Dumper.java
index a226bcc..a60f87b 100755
--- a/api/src/main/java/org/semver/Dumper.java
+++ b/api/src/main/java/org/semver/Dumper.java
@@ -16,6 +16,7 @@
*/
package org.semver;
+import java.io.PrintStream;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -28,13 +29,13 @@ import org.semver.Delta.Change;
/**
*
* Helper methods to dump {@link Delta}.
- *
+ *
*/
-public final class Dumper {
+public class Dumper {
private Dumper() {
}
-
+
protected static String extractActionType(final Difference difference) {
final String actionType = difference.getClass().getSimpleName();
return actionType.endsWith("e")?actionType+"d":actionType+"ed";
@@ -48,9 +49,9 @@ public final class Dumper {
protected static String extractDetails(final Difference difference) {
if (difference instanceof Change) {
final Change change = (Change) difference;
- return extractDetails(difference.getInfo())+" "+extractAccessDetails(difference.getInfo(), change.getModifiedInfo());
+ return extractDetails(difference.getInfo())+", access "+extractAccessDetails(difference.getInfo(), change.getModifiedInfo());
} else {
- return extractDetails(difference.getInfo());
+ return extractDetails(difference.getInfo())+", access "+extractAccessDetails(difference.getInfo());
}
}
@@ -58,10 +59,16 @@ public final class Dumper {
final StringBuilder builder = new StringBuilder();
if (!(info instanceof ClassInfo)) {
builder.append(info.getName());
+ if( null != info.getSignature() ) {
+ builder.append(", sig ").append(info.getSignature());
+ }
+ if( null != info.getDesc() ) {
+ builder.append(", desc ").append(info.getDesc());
+ }
}
return builder.toString();
}
-
+
protected static void accumulateAccessDetails(final String access, final boolean previousAccess, final boolean currentAccess, final List<String> added, final List<String> removed) {
if (previousAccess != currentAccess) {
if (previousAccess) {
@@ -71,7 +78,7 @@ public final class Dumper {
}
}
}
-
+
protected static String extractAccessDetails(final AbstractInfo previousInfo, final AbstractInfo currentInfo) {
final List<String> added = new LinkedList<String>();
final List<String> removed = new LinkedList<String>();
@@ -105,28 +112,75 @@ public final class Dumper {
details.append("removed: ");
for (final String access : removed) {
details.append(access).append(" ");
- }
+ }
+ }
+ return details.toString().trim();
+ }
+
+ protected static void accumulateAccessDetails(final String access, final boolean hasAccess, final List<String> accessList) {
+ if (hasAccess) {
+ accessList.add(access);
+ }
+ }
+
+ protected static String extractAccessDetails(final AbstractInfo info) {
+ final List<String> accessList = new LinkedList<String>();
+ accumulateAccessDetails("abstract", info.isAbstract(), accessList);
+ accumulateAccessDetails("annotation", info.isAnnotation(), accessList);
+ accumulateAccessDetails("bridge", info.isBridge(), accessList);
+ accumulateAccessDetails("enum", info.isEnum(), accessList);
+ accumulateAccessDetails("final", info.isFinal(), accessList);
+ accumulateAccessDetails("interface", info.isInterface(), accessList);
+ accumulateAccessDetails("native", info.isNative(), accessList);
+ accumulateAccessDetails("package-private", info.isPackagePrivate(), accessList);
+ accumulateAccessDetails("private", info.isPrivate(), accessList);
+ accumulateAccessDetails("protected", info.isProtected(), accessList);
+ accumulateAccessDetails("public", info.isPublic(), accessList);
+ accumulateAccessDetails("static", info.isStatic(), accessList);
+ accumulateAccessDetails("strict", info.isStrict(), accessList);
+ accumulateAccessDetails("super", info.isSuper(), accessList);
+ accumulateAccessDetails("synchronized", info.isSynchronized(), accessList);
+ accumulateAccessDetails("synthetic", info.isSynthetic(), accessList);
+ accumulateAccessDetails("transcient", info.isTransient(), accessList);
+ accumulateAccessDetails("varargs", info.isVarargs(), accessList);
+ accumulateAccessDetails("volatile", info.isVolatile(), accessList);
+ final StringBuilder details = new StringBuilder();
+ if (!accessList.isEmpty()) {
+ for (final String access : accessList) {
+ details.append(access).append(" ");
+ }
}
return details.toString().trim();
}
/**
- *
+ *
* Dumps on {@link System#out} all differences.
- *
+ *
* @param differences
*/
public static void dump(final Delta delta) {
+ dump(delta, System.out);
+ }
+
+ /**
+ *
+ * Dumps on <code>out</code> all differences.
+ *
+ * @param differences
+ * @param out
+ */
+ public static void dump(final Delta delta, final PrintStream out) {
final List<Difference> sortedDifferences = new LinkedList<Difference>(delta.getDifferences());
Collections.sort(sortedDifferences);
String currentClassName = "";
for (final Difference difference : sortedDifferences) {
if (!currentClassName.equals(difference.getClassName())) {
- System.out.println("Class "+difference.getClassName());
+ out.println("Class "+difference.getClassName());
}
- System.out.println(" "+extractActionType(difference)+" "+extractInfoType(difference.getInfo())+" "+extractDetails(difference));
+ out.println(" "+extractActionType(difference)+" "+extractInfoType(difference.getInfo())+" "+extractDetails(difference));
currentClassName = difference.getClassName();
}
}
-
+
}