[SCM] UNNAMED PROJECT branch, jh-symbols, updated. 0.36-5-g33af870
Niels Thykier
nthykier at alioth.debian.org
Wed Jul 6 12:58:28 UTC 2011
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "UNNAMED PROJECT".
The branch, jh-symbols has been updated
via 33af870ae42bf1a5f0300e08ce93509782d45c21 (commit)
from 27acb14876246d175f39dd3e3a5b3a139caa18d8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 33af870ae42bf1a5f0300e08ce93509782d45c21
Author: Niels Thykier <niels at thykier.net>
Date: Wed Jul 6 14:34:29 2011 +0200
FIXME: Committed temporary changes
-----------------------------------------------------------------------
Summary of changes:
.../debian/javahelper/symbols/IClassSymbol.java | 8 ++-
src/org/debian/javahelper/symbols/ISymbolDiff.java | 32 ++++---
src/org/debian/javahelper/symbols/Main.java | 60 +++++++++----
.../symbols/internal/BCELLibraryParser.java | 15 +++-
.../javahelper/symbols/internal/ClassSymbol.java | 18 ++++-
.../symbols/internal/SimpleSymbolDifference.java | 32 +++++--
.../internal/SymbolContainerDifference.java | 4 +-
.../javahelper/symbols/internal/SymbolData.java | 52 ++++++++++-
.../javahelper/symbols/internal/SymbolDiffer.java | 92 +++++++++++++++----
9 files changed, 245 insertions(+), 68 deletions(-)
diff --git a/src/org/debian/javahelper/symbols/IClassSymbol.java b/src/org/debian/javahelper/symbols/IClassSymbol.java
index 398ea6b..0bd182c 100644
--- a/src/org/debian/javahelper/symbols/IClassSymbol.java
+++ b/src/org/debian/javahelper/symbols/IClassSymbol.java
@@ -1,11 +1,17 @@
package org.debian.javahelper.symbols;
+import java.util.List;
+
/**
- * Presents a Class symbol, which can contain other symbols.
+ * Presents a Class symbol (or Interface), which can contain other symbols.
*
* @author Niels Thykier
*
*/
public interface IClassSymbol extends ISymbol, ISymbolContainer{
+ public static final String UNKNOWN_CLASS_NAME = "?";
+
+ public String getParentClassName();
+ public List<String> getImplementedInterfaceNames();
}
diff --git a/src/org/debian/javahelper/symbols/ISymbolDiff.java b/src/org/debian/javahelper/symbols/ISymbolDiff.java
index 770412c..cfd1c4f 100644
--- a/src/org/debian/javahelper/symbols/ISymbolDiff.java
+++ b/src/org/debian/javahelper/symbols/ISymbolDiff.java
@@ -7,21 +7,22 @@ public interface ISymbolDiff {
public SymbolDiffStatus getDiffStatus();
/**
- * Returns the "symbol" being diffed if any (see return). The symbol
- * data may refer to the new or the old version or even just a "proxy"
- * symbol (implementation defined).
- * If the real symbol being diffed implements {@link IClassSymbol},
- * then the value returned here must also implement
- * {@link IClassSymbol}.
+ * Returns the new symbol in the diff if any.
*
- * Note that {@link ISymbol#getVersion()} of the returned symbol is
- * not required to make sense and may throw
- * {@link UnsupportedOperationException}
+ * @return The new symbol or <code>null</code>. For {@link SymbolDiffStatus#REMOVED} this
+ * is <code>null</code>, but may also be <code>null</code> in other cases, such as the diff
+ * was between two {@link ILibrarySymbolData} (rather than two symbols)
+ */
+ public ISymbol getNewSymbol();
+
+ /**
+ * Returns the old symbol in the diff if any.
*
- * @return The symbol in consideration; <code>null</code> if
- * this diff is not between two symbols, but two {@link ILibrarySymbolData}.
+ * @return The old symbol or <code>null</code>. For {@link SymbolDiffStatus#ADDED} this
+ * is <code>null</code>, but may also be <code>null</code> in other cases, such as the diff
+ * was between two {@link ILibrarySymbolData} (rather than two symbols)
*/
- public ISymbol getSymbol();
+ public ISymbol getOldSymbol();
public List<ISymbolDiff> getNewSymbols();
public List<ISymbolDiff> getMissingSymbols();
@@ -52,6 +53,13 @@ public interface ISymbolDiff {
* the symbol itself has changed (e.g. it received a
* new sub-symbol or it lost a sub-symbol).
*
+ * This is also used if a {@link IClassSymbol} has
+ * changed its parent-class or which interfaces it has
+ * implemented. In this case, all of its sub-symbols
+ * <i>may</i> be {@link #UNCHANGED}, although it is
+ * much more likely that some sub-symbols has been
+ * added or removed.
+ *
* Note renaming a symbol will be classified as adding
* a new symbol and removing an old one rather than
* "changing" the symbol.
diff --git a/src/org/debian/javahelper/symbols/Main.java b/src/org/debian/javahelper/symbols/Main.java
index f3a7518..8d60889 100644
--- a/src/org/debian/javahelper/symbols/Main.java
+++ b/src/org/debian/javahelper/symbols/Main.java
@@ -14,33 +14,35 @@ public class Main {
public static void main(String[] args) throws Exception {
Factory fac = Factory.newInstance();
ILibrarySymbolData symdata;
+ ILibrarySymbolData usagedata = null;
String out = null;
- if(args.length < 2 || args.length > 5){
- throw new IllegalArgumentException("Usage: gen <library> <pkg> <version> [write-to] || read <symbol>");
+ String usageOut = null;
+ if(args.length < 2 || args.length > 6){
+ throw new IllegalArgumentException("Usage: gen <library> <pkg> <version> [write-to] [usage-to] || read <symbol>");
}
if(args[0].equals("gen")) {
if(args.length < 3){
throw new IllegalArgumentException("Usage: gen <library> <pkg> <version> [write-to]");
}
- if(args.length == 5) {
+ if(args.length >= 5) {
out = args[4];
+ if(args.length == 6) {
+ usageOut = args[5];
+ }
}
ILibraryParser libpar = fac.createLibraryParser();
libpar.parseLibrary(new File(args[1]), args[2], args[3]);
symdata = libpar.getExportedSymbols();
- for(ISymbol sym : libpar.getUsedSymbols().getSymbols()){
- System.out.println(" Uses " + sym.getClassName());
- }
- for(ISymbol sym : libpar.getExportedSymbols().getSymbols()){
- System.out.println(" Exports " + sym.getClassName());
- }
+ usagedata = libpar.getUsedSymbols();
} else if(args[0].equals("read")){
symdata = fac.createSymbolData();
symdata.read(args[1]);
+ } else if(args[0].equals("")){
+ return;
} else if(args[0].equals("diff")){
IDifferenceMaker differ = fac.createDifferenceMaker();
- ILibrarySymbolData oData;
- ILibrarySymbolData nData;
+ ISymbolContainer oData;
+ ISymbolContainer nData;
ISymbolDiff diff;
if(args.length != 3) {
throw new IllegalArgumentException("Usage: diff <org lib/sym-file> <new lib/sym-file>");
@@ -49,17 +51,23 @@ public class Main {
ILibraryParser libpar = fac.createLibraryParser();
libpar.parseLibrary(new File(args[1]), "<pkg>", "0.0");
oData = libpar.getExportedSymbols();
+ } else if(args[1].equals("") || args[1].equals("/dev/null")) {
+ oData = IDifferenceMaker.EMPTY_SYMBOL_CONTAINER;
} else {
- oData = fac.createSymbolData();
- oData.read(args[1]);
+ ILibrarySymbolData d = fac.createSymbolData();
+ oData = d;
+ d.read(args[1]);
}
if(args[2].toLowerCase().endsWith(".jar") || args[2].toLowerCase().endsWith(".zip")){
ILibraryParser libpar = fac.createLibraryParser();
libpar.parseLibrary(new File(args[2]), "<pkg>", "0.0");
nData = libpar.getExportedSymbols();
+ } else if(args[2].equals("") || args[2].equals("/dev/null")) {
+ nData = IDifferenceMaker.EMPTY_SYMBOL_CONTAINER;
} else {
- nData = fac.createSymbolData();
- nData.read(args[2]);
+ ILibrarySymbolData d = fac.createSymbolData();
+ nData = d;
+ d.read(args[2]);
}
diff = differ.diff(oData, nData);
printDiff(diff);
@@ -75,6 +83,10 @@ public class Main {
System.out.println("Writing to: " + out);
symdata.write(out);
}
+ if(usageOut != null && usagedata != null) {
+ System.out.println("Writing usage info to: " + usageOut);
+ usagedata.write(usageOut);
+ }
}
private static void printDiff(ISymbolDiff diff) {
@@ -93,16 +105,30 @@ public class Main {
private static void printDiffList(List<ISymbolDiff> syms, String s, String pre){
for(ISymbolDiff diff : syms){
- ISymbol sym = diff.getSymbol();
+ ISymbol sym = diff.getNewSymbol();
if(sym == null) {
throw new IllegalArgumentException();
}
if(sym.isClassSymbol()){
- System.out.println(s + pre + sym.getClassName() + ":");
+ IClassSymbol cl = sym.asClassSymbol();
+ System.out.println(s + pre + sym.getClassName() + ": " + cl.getParentClassName() + " "+
+ SL2S(cl.getImplementedInterfaceNames()));
printDiff(diff, pre + " ");
} else {
System.out.println(s + pre + sym.getName());
}
}
}
+
+ private static final String SL2S(List<String> l){
+ int i = 0;
+ StringBuilder b = new StringBuilder();
+ for(String s : l){
+ if(i++ > 0) {
+ b.append(',');
+ }
+ b.append(s);
+ }
+ return b.toString();
+ }
}
diff --git a/src/org/debian/javahelper/symbols/internal/BCELLibraryParser.java b/src/org/debian/javahelper/symbols/internal/BCELLibraryParser.java
index 9b2895a..2bc9ac2 100644
--- a/src/org/debian/javahelper/symbols/internal/BCELLibraryParser.java
+++ b/src/org/debian/javahelper/symbols/internal/BCELLibraryParser.java
@@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -30,6 +31,8 @@ public class BCELLibraryParser implements ILibraryParser {
private static final Pattern CLASS_PATTERN = Pattern.compile("\\.class$", Pattern.CASE_INSENSITIVE);
private static final Pattern ANONY_CLASS = Pattern.compile("\\$\\d++$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern DOT_PATTERN = Pattern.compile("\\.", Pattern.CASE_INSENSITIVE);
+
private ILibrarySymbolData exportedSymbols;
private ILibrarySymbolData usedSymbols;
private Map<String, IClassSymbol> exportMap;
@@ -76,7 +79,14 @@ public class BCELLibraryParser implements ILibraryParser {
ConstantPool pool = cfile.getConstantPool();
Constant[] consts = pool.getConstantPool();
ClassSymbol clsym;
- clsym = new ClassSymbol(clname, curVersion);
+ String parent = DOT_PATTERN.matcher(cfile.getSuperclassName()).replaceAll("/");
+ String[] interfaces = cfile.getInterfaceNames();
+ interfaces = Arrays.copyOf(interfaces, interfaces.length);
+ for(int i = 0 ; i < interfaces.length ; i++){
+ interfaces[i] = DOT_PATTERN.matcher(interfaces[i]).replaceAll("/");
+ }
+ clsym = new ClassSymbol(clname, curVersion, parent,
+ interfaces);
useMap.remove(clname);
// Consider non-public/protected or synthetic or anonymous ("$1") classses for private
if(!(cfile.isPublic() || cfile.isProtected()) || cfile.isSynthetic()
@@ -138,7 +148,8 @@ public class BCELLibraryParser implements ILibraryParser {
}
cl = (ClassSymbol)useMap.get(cname);
if(cl == null){
- cl = new ClassSymbol(cname, curVersion);
+ cl = new ClassSymbol(cname, curVersion, IClassSymbol.UNKNOWN_CLASS_NAME,
+ IClassSymbol.UNKNOWN_CLASS_NAME);
useMap.put(cname, cl);
}
cl.addSymbol(symname, curVersion);
diff --git a/src/org/debian/javahelper/symbols/internal/ClassSymbol.java b/src/org/debian/javahelper/symbols/internal/ClassSymbol.java
index 48e4b5a..513e448 100644
--- a/src/org/debian/javahelper/symbols/internal/ClassSymbol.java
+++ b/src/org/debian/javahelper/symbols/internal/ClassSymbol.java
@@ -1,6 +1,7 @@
package org.debian.javahelper.symbols.internal;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -14,9 +15,14 @@ public class ClassSymbol extends SimpleSymbol implements IClassSymbol {
private Map<String, ISymbol> symMap = new HashMap<String, ISymbol>();
private Map<String, ISymbol> privSymMap = new HashMap<String, ISymbol>();
private List<ISymbol> symList = new ArrayList<ISymbol>();
+ private String parent;
+ private List<String> interfaces;
- public ClassSymbol(String clname, String version) {
+
+ public ClassSymbol(String clname, String version, String parent, String... interfaces) {
super(clname, "", version);
+ this.parent = parent;
+ this.interfaces = Collections.unmodifiableList(Arrays.asList(interfaces));
}
@@ -51,4 +57,14 @@ public class ClassSymbol extends SimpleSymbol implements IClassSymbol {
}
return true;
}
+
+
+ public String getParentClassName() {
+ return parent;
+ }
+
+
+ public List<String> getImplementedInterfaceNames() {
+ return interfaces;
+ }
}
diff --git a/src/org/debian/javahelper/symbols/internal/SimpleSymbolDifference.java b/src/org/debian/javahelper/symbols/internal/SimpleSymbolDifference.java
index 81b868c..202b93a 100644
--- a/src/org/debian/javahelper/symbols/internal/SimpleSymbolDifference.java
+++ b/src/org/debian/javahelper/symbols/internal/SimpleSymbolDifference.java
@@ -8,18 +8,30 @@ import org.debian.javahelper.symbols.ISymbolDiff;
public class SimpleSymbolDifference implements ISymbolDiff {
- protected final ISymbol sym;
+ protected final ISymbol newSym;
+ protected final ISymbol oldSym;
protected final SymbolDiffStatus status;
- public SimpleSymbolDifference(ISymbol sym, SymbolDiffStatus status){
- this.sym = sym;
+ public SimpleSymbolDifference(ISymbol oldSym, ISymbol newSym, SymbolDiffStatus status){
+ this.oldSym = oldSym;
+ this.newSym = newSym;
this.status = status;
if(status == null) {
throw new IllegalArgumentException();
}
- if(sym == null && this.getClass() == SimpleSymbolDifference.class) {
- // only allow sym = null if the instance extends SimpleSymbolDifference
- throw new IllegalArgumentException();
+ if(this.getClass() == SimpleSymbolDifference.class){
+ if(oldSym == null && status != SymbolDiffStatus.ADDED){
+ // only allow oldSym to be null if we are an "add" diff
+ throw new IllegalArgumentException();
+ }
+ if(newSym == null && status != SymbolDiffStatus.REMOVED){
+ // only allow newSym to be null if we are an "removed" diff
+ throw new IllegalArgumentException();
+ }
+ if(newSym == null && oldSym == null) {
+ // only allow sym = null if the instance extends SimpleSymbolDifference
+ throw new IllegalArgumentException();
+ }
}
}
@@ -27,8 +39,12 @@ public class SimpleSymbolDifference implements ISymbolDiff {
return status;
}
- public ISymbol getSymbol() {
- return sym;
+ public ISymbol getNewSymbol() {
+ return newSym;
+ }
+
+ public ISymbol getOldSymbol() {
+ return oldSym;
}
public List<ISymbolDiff> getNewSymbols() {
diff --git a/src/org/debian/javahelper/symbols/internal/SymbolContainerDifference.java b/src/org/debian/javahelper/symbols/internal/SymbolContainerDifference.java
index f923044..71177d2 100644
--- a/src/org/debian/javahelper/symbols/internal/SymbolContainerDifference.java
+++ b/src/org/debian/javahelper/symbols/internal/SymbolContainerDifference.java
@@ -13,10 +13,10 @@ public class SymbolContainerDifference extends SimpleSymbolDifference {
protected final List<ISymbolDiff> chgSD;
protected final List<ISymbolDiff> uncSD;
- public SymbolContainerDifference(ISymbol sym, SymbolDiffStatus status,
+ public SymbolContainerDifference(ISymbol oldSym, ISymbol newSym, SymbolDiffStatus status,
List<ISymbolDiff> newSD, List<ISymbolDiff> misSD,
List<ISymbolDiff> chgSD, List<ISymbolDiff> uncSD) {
- super(sym, status);
+ super(oldSym, newSym, status);
if(newSD == null) {
this.newSD = Collections.emptyList();
} else {
diff --git a/src/org/debian/javahelper/symbols/internal/SymbolData.java b/src/org/debian/javahelper/symbols/internal/SymbolData.java
index d76bf44..dbd9ff1 100644
--- a/src/org/debian/javahelper/symbols/internal/SymbolData.java
+++ b/src/org/debian/javahelper/symbols/internal/SymbolData.java
@@ -76,14 +76,25 @@ public class SymbolData implements ILibrarySymbolData {
if(sp[0].endsWith(":")){
// Class name
String cl = sp[0].substring(0, sp[0].length() - 1);
- if(sp.length != 2) {
- throw new IOException("Expected <class-symbol>: <pkg-version> at line " + lineno + " in " + f);
+ String parent = null;
+ String[] inter = new String[]{};
+ String ver;
+ if(sp.length < 2 || sp.length > 4) {
+ throw new IOException("Expected <class-symbol>: [<parent> [<inter>[,<inter2>...]]] <pkg-version> at line " + lineno + " in " + f);
}
+ ver = sp[sp.length - 1];
+ if(sp.length > 2){
+ parent = sp[1];
+ if(sp.length > 3){
+ inter = sp[2].split(",");
+ }
+ }
+
clsym = (ClassSymbol)symbolMap.get(cl);
if(clsym != null) {
- System.err.println("W: " + cl + " appears more than once in " + f);
+ throw new IOException(cl + " appears more than once in " + f);
} else {
- clsym = new ClassSymbol(cl, sp[1]);
+ clsym = new ClassSymbol(cl, ver, parent, inter);
symbolMap.put(cl, clsym);
symbols.add(clsym);
}
@@ -130,7 +141,12 @@ public class SymbolData implements ILibrarySymbolData {
ps.println(libname + " " + provpkgs.get(0));
for(ISymbol s : symbols){
IClassSymbol clsym = s.asClassSymbol();
- ps.println(" " + clsym.getClassName() + ": " + clsym.getVersion());
+ String parent = clsym.getParentClassName();
+ List<String> interfaces = clsym.getImplementedInterfaceNames();
+ if(interfaces.size() == 1 && interfaces.get(0).equals(IClassSymbol.UNKNOWN_CLASS_NAME)){
+ interfaces = Collections.emptyList();
+ }
+ ps.println(genClassLine(clsym.getClassName(), parent, interfaces, clsym.getVersion()));
for(ISymbol sym : clsym.getSymbols()){
ps.println(" " + sym.getName() + " " + sym.getVersion());
}
@@ -145,6 +161,32 @@ public class SymbolData implements ILibrarySymbolData {
write(new File(f));
}
+ private static final String genClassLine(String clname, String parent, List<String> inter, String ver){
+ StringBuilder b = new StringBuilder(3 + clname.length() + ver.length());
+ b.append(" " + clname + ": ");
+ if(inter.size() > 0){
+ if(parent == null) {
+ parent = "java/lang/Object"; // We need an explicit parent in this case
+ }
+ } else if(IClassSymbol.UNKNOWN_CLASS_NAME.equals(parent) || "java/lang/Object".equals(parent)) {
+ parent = null; // We can leave out the parent in this case
+ }
+ if(parent != null) {
+ b.append(parent + " ");
+ }
+ if(inter.size() > 0){
+ int i = 0;
+ for(String s : inter){
+ if(i++ > 0) {
+ b.append(',');
+ }
+ b.append(s);
+ }
+ b.append(' ');
+ }
+ b.append(ver);
+ return b.toString();
+ }
public String getLibraryFilename() {
return libname;
diff --git a/src/org/debian/javahelper/symbols/internal/SymbolDiffer.java b/src/org/debian/javahelper/symbols/internal/SymbolDiffer.java
index bc44aa7..1d2da54 100644
--- a/src/org/debian/javahelper/symbols/internal/SymbolDiffer.java
+++ b/src/org/debian/javahelper/symbols/internal/SymbolDiffer.java
@@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.debian.javahelper.symbols.IClassSymbol;
import org.debian.javahelper.symbols.IDifferenceMaker;
import org.debian.javahelper.symbols.ISymbol;
import org.debian.javahelper.symbols.ISymbolContainer;
@@ -14,10 +15,10 @@ import org.debian.javahelper.symbols.ISymbolDiff.SymbolDiffStatus;
public class SymbolDiffer implements IDifferenceMaker {
public ISymbolDiff diff(ISymbolContainer oData, ISymbolContainer nData){
- return diff(oData, nData, null, null);
+ return diff(oData, nData, null, null, null);
}
- private ISymbolDiff diff(ISymbolContainer oData, ISymbolContainer nData, ISymbol sym, SymbolDiffStatus stat){
+ private ISymbolDiff diff(ISymbolContainer oData, ISymbolContainer nData, ISymbol oldSym, ISymbol newSym, SymbolDiffStatus stat){
if(oData == null || nData == null) {
throw new IllegalArgumentException();
}
@@ -38,9 +39,9 @@ public class SymbolDiffer implements IDifferenceMaker {
if(old == null) {
ISymbolDiff d;
if(i.isClassSymbol()) {
- d = diff(EMPTY_SYMBOL_CONTAINER, i.asClassSymbol(), i, SymbolDiffStatus.ADDED);
+ d = diff(EMPTY_SYMBOL_CONTAINER, i.asClassSymbol(), null, i, SymbolDiffStatus.ADDED);
} else {
- d = new SimpleSymbolDifference(i, SymbolDiffStatus.ADDED);
+ d = new SimpleSymbolDifference(null, i, SymbolDiffStatus.ADDED);
}
newSymbols.add(d);
} else {
@@ -48,9 +49,12 @@ public class SymbolDiffer implements IDifferenceMaker {
// both are simple or both are symbol containers
ISymbolDiff d;
if(old.isClassSymbol()){
- d = diff(old.asClassSymbol(), i.asClassSymbol(), i, null);
+ IClassSymbol ocl = old.asClassSymbol();
+ IClassSymbol ncl = i.asClassSymbol();
+ SymbolDiffStatus st = comClassSym(ocl, ncl);
+ d = diff(ocl, ncl, old, i, st);
} else {
- d = new SimpleSymbolDifference(i, SymbolDiffStatus.UNCHANGED);
+ d = new SimpleSymbolDifference(old, i, SymbolDiffStatus.UNCHANGED);
}
if(d.getDiffStatus() == SymbolDiffStatus.UNCHANGED) {
uncSymbols.add(d);
@@ -61,13 +65,12 @@ public class SymbolDiffer implements IDifferenceMaker {
// only old or i is a class symbol, but not both
ISymbolDiff od;
ISymbolDiff nd;
- System.out.println(" !! " + old.getClassName() +" - " + i.getClassName());
if(old.isClassSymbol()){
- nd = new SimpleSymbolDifference(i, SymbolDiffStatus.ADDED);
- od = diff(old.asClassSymbol(), EMPTY_SYMBOL_CONTAINER, old, SymbolDiffStatus.REMOVED);
+ nd = new SimpleSymbolDifference(null, i, SymbolDiffStatus.ADDED);
+ od = diff(old.asClassSymbol(), EMPTY_SYMBOL_CONTAINER, old, null, SymbolDiffStatus.REMOVED);
} else {
- nd = diff(EMPTY_SYMBOL_CONTAINER, i.asClassSymbol(), i, SymbolDiffStatus.ADDED);
- od = new SimpleSymbolDifference(old, SymbolDiffStatus.REMOVED);
+ nd = diff(EMPTY_SYMBOL_CONTAINER, i.asClassSymbol(), null, i, SymbolDiffStatus.ADDED);
+ od = new SimpleSymbolDifference(old, null, SymbolDiffStatus.REMOVED);
}
missingSymbols.add(od);
newSymbols.add(nd);
@@ -77,18 +80,17 @@ public class SymbolDiffer implements IDifferenceMaker {
for(ISymbol s : oSymMap.values()){
ISymbolDiff d;
if(s.isClassSymbol()) {
- d = diff(s.asClassSymbol(), EMPTY_SYMBOL_CONTAINER, s, SymbolDiffStatus.REMOVED);
+ d = diff(s.asClassSymbol(), EMPTY_SYMBOL_CONTAINER, s, null, SymbolDiffStatus.REMOVED);
} else {
- d = new SimpleSymbolDifference(s, SymbolDiffStatus.REMOVED);
+ d = new SimpleSymbolDifference(s, null, SymbolDiffStatus.REMOVED);
}
missingSymbols.add(d);
}
- if(sym == null) {
- if(nData instanceof ISymbol) {
- sym = (ISymbol)nData;
- } else if(oData instanceof ISymbol){
- sym = (ISymbol)oData;
- }
+ if(newSym == null && nData instanceof ISymbol) {
+ newSym = (ISymbol)nData;
+ }
+ if(oldSym == null && oData instanceof ISymbol){
+ oldSym = (ISymbol)oData;
}
if(stat == null) {
if(missingSymbols.size() + chgSymbols.size() + newSymbols.size() > 0) {
@@ -97,7 +99,57 @@ public class SymbolDiffer implements IDifferenceMaker {
stat = SymbolDiffStatus.UNCHANGED;
}
}
- return new SymbolContainerDifference(sym, stat, newSymbols, missingSymbols, chgSymbols, uncSymbols);
+ return new SymbolContainerDifference(oldSym, newSym, stat, newSymbols, missingSymbols, chgSymbols, uncSymbols);
+ }
+
+ /**
+ * Checks if two class symbols has the same parent and implements the same interfaces
+ * - This does <b>not</b> compare the symbols within them.
+ *
+ * @param ocl The old {@link IClassSymbol}
+ * @param ncl The new {@link IClassSymbol}
+ * @return <code>null</code> if there are no differences, else {@link SymbolDiffStatus#CHANGED}
+ */
+ private static SymbolDiffStatus comClassSym(IClassSymbol ocl, IClassSymbol ncl){
+ String op = ocl.getParentClassName();
+ String np = ncl.getParentClassName();
+ List<String> oit;
+ List<String> nit;
+ Map<String, Boolean> oitMap;
+ if(IClassSymbol.UNKNOWN_CLASS_NAME.equals(np) ||
+ IClassSymbol.UNKNOWN_CLASS_NAME.equals(op)){
+ // "unknown" != "unknown" for all we know
+ return SymbolDiffStatus.CHANGED;
+ }
+ if(op == null) {
+ op = "java/lang/Object";
+ }
+ if(np == null) {
+ np = "java/lang/Object";
+ }
+ if(!op.equals(np)){
+ // parent classes differ
+ return SymbolDiffStatus.CHANGED;
+ }
+ oit = ocl.getImplementedInterfaceNames();
+ nit = ncl.getImplementedInterfaceNames();
+ if(nit.size() != oit.size()) {
+ return SymbolDiffStatus.CHANGED;
+ }
+ oitMap = new HashMap<String, Boolean>(oit.size());
+ for(String oi : oit){
+ oitMap.put(oi, Boolean.TRUE);
+ }
+ for(String ni : nit){
+ Boolean b = oitMap.remove(ni);
+ if(b == null) {
+ return SymbolDiffStatus.CHANGED;
+ }
+ }
+ // At this point, oitMap will be empty due to
+ // oit.size() == nit.size() and the loop above.
+ // - equal so far, return null
+ return null;
}
private static String genHashKey(ISymbol s){
hooks/post-receive
--
UNNAMED PROJECT
More information about the pkg-java-commits
mailing list