this.rowsB.add(pdrB);
this.rowsAll.add(pdrA);
this.rowsAll.add(pdrB);
}
this.rowsAll.add(new BlankRow());
// Imports
Imports importsA = EditorFacade.getInstance().getImports(cfA);
Imports importsB = EditorFacade.getInstance().getImports(cfB);
this.renderer.setImports(importsA, importsB);
Set<String> tsA = importsA.getImports();
Set<String> tsB = importsB.getImports();
Set<String> allOrdered = new TreeSet<String>();
allOrdered.addAll(tsA);
allOrdered.addAll(tsB);
for (String imp : allOrdered) {
ImportDefRow idr = new ImportDefRow(imp);
this.rowsAll.add(idr);
if (!tsA.contains(imp)) {
this.rowsB.add(idr);
}
if (!tsB.contains(imp)) {
this.rowsA.add(idr);
}
}
if (allOrdered.size() > 0) {
this.rowsAll.add(new BlankRow());
/* empty space between imports and class def */
}
// Add some useful information as comments
// Source file name
SourceFileAttribute sfA = cfA.getAttributes().getSourceFileAttribute();
SourceFileAttribute sfB = cfB.getAttributes().getSourceFileAttribute();
if (sfA == null && sfB == null) {
// Add nothing, neither has a source file attribute
} else if (sfA == null || sfB == null) {
// Only one has a source file attribute
if (sfA != null) {
ClassCommentRow sfComment = new ClassCommentRow("SourceFile = " + sfA.getSourceFile());
this.rowsA.add(sfComment);
this.rowsAll.add(sfComment);
}
if (sfB != null) {
ClassCommentRow sfComment = new ClassCommentRow("SourceFile = " + sfB.getSourceFile());
this.rowsB.add(sfComment);
this.rowsAll.add(sfComment);
}
} else {
// Both have source file attributes
if (sfA.getSourceFile().equals(sfB.getSourceFile())) {
ClassCommentRow sfComment = new ClassCommentRow("SourceFile = " + sfA.getSourceFile());
this.rowsAll.add(sfComment);
} else {
ClassCommentRow sfCommentA = new ClassCommentRow("SourceFile = " + sfA.getSourceFile());
this.rowsA.add(sfCommentA);
this.rowsAll.add(sfCommentA);
ClassCommentRow sfCommentB = new ClassCommentRow("SourceFile = " + sfB.getSourceFile());
this.rowsB.add(sfCommentB);
this.rowsAll.add(sfCommentB);
}
}
// Class version
if (cfA.getMajorVersion() == cfB.getMajorVersion()
&& cfA.getMinorVersion() == cfB.getMinorVersion()) {
ClassCommentRow versionComment = new ClassCommentRow("Class Version: " + cfA.getMajorVersion() + "." + cfA.getMinorVersion());
this.rowsAll.add(versionComment);
} else {
ClassCommentRow versionCommentA = new ClassCommentRow("Class Version: " + cfA.getMajorVersion() + "." + cfA.getMinorVersion());
this.rowsA.add(versionCommentA);
ClassCommentRow versionCommentB = new ClassCommentRow("Class Version: " + cfB.getMajorVersion() + "." + cfB.getMinorVersion());
this.rowsB.add(versionCommentB);
this.rowsAll.add(versionCommentA);
this.rowsAll.add(versionCommentB);
}
// Class annotations
/* TODO:
RuntimeInvisibleAnnotationsAttribute annInvisible = cf.getAttributes()
.getRuntimeInvisibleAnnotationsAttribute();
RuntimeVisibleAnnotationsAttribute annVisible = cf.getAttributes()
.getRuntimeVisibleAnnotationsAttribute();
List<Annotation> classAnnotations = new ArrayList<Annotation>();
if (annInvisible != null) {
classAnnotations.addAll(annInvisible.getAnnotations());
}
if (annVisible != null) {
classAnnotations.addAll(annVisible.getAnnotations());
}
for (Annotation annotation : classAnnotations) {
ClassAnnotationDefRow adr = new ClassAnnotationDefRow(annotation);
this.rows.add(adr);
}
*/
List<Interface> interfacesA = cfA.getInterfaces();
List<Interface> interfacesB = cfB.getInterfaces();
boolean interfacesAreEqual = interfacesA.equals(interfacesB);
// Class
if (cfA.getShortClassName().equals(cfB.getShortClassName())
&& cfA.getAccessFlags() == cfB.getAccessFlags()
&& cfA.getSuperClassName().equals(cfB.getSuperClassName())
&& interfacesAreEqual) {
this.rowsAll.add(new ClassDefRow(cfA, true));
} else {
ClassDefRow cdrA = new ClassDefRow(cfA, true);
ClassDefRow cdrB = new ClassDefRow(cfB, true);
this.rowsA.add(cdrA);
this.rowsB.add(cdrB);
this.rowsAll.add(cdrA);
this.rowsAll.add(cdrB);
}
this.rowsAll.add(new BlankRow());
// Fields
// TODO: Constant value compare
Map<String, Field> fieldsA = new HashMap<String, Field>();
for (Field field : cfA.getFields()) {
fieldsA.put(field.getSignatureLine(), field);
}
Map<String, Field> fieldsB = new HashMap<String, Field>();
for (Field field : cfB.getFields()) {
fieldsB.put(field.getSignatureLine(), field);
}
Set<String> allFields = new TreeSet<String>();
allFields.addAll(fieldsA.keySet());
allFields.addAll(fieldsB.keySet());
for (String fieldSignature : allFields) {
// Field annotations
/* TODO
RuntimeInvisibleAnnotationsAttribute fieldAnnInvisible = field
.getAttributes().getRuntimeInvisibleAnnotationsAttribute();
RuntimeVisibleAnnotationsAttribute fieldAnnVisible = field
.getAttributes().getRuntimeVisibleAnnotationsAttribute();
List<Annotation> fieldAnnotations = new ArrayList<Annotation>();
if (fieldAnnInvisible != null) {
fieldAnnotations.addAll(fieldAnnInvisible.getAnnotations());
}
if (fieldAnnVisible != null) {
fieldAnnotations.addAll(fieldAnnVisible.getAnnotations());
}
for (Annotation annotation : fieldAnnotations) {
FieldAnnotationDefRow fadr = new FieldAnnotationDefRow(
annotation);
this.rows.add(fadr);
}
*/
FieldDefRow fdr = null;
Field field = fieldsA.get(fieldSignature);
if (field == null) {
field = fieldsB.get(fieldSignature);
fdr = new FieldDefRow(cfB, field);
this.rowsB.add(fdr);
} else {
fdr = new FieldDefRow(cfA, field);
if (!fieldsB.keySet().contains(fieldSignature)) {
this.rowsA.add(fdr);
}
}
this.rowsAll.add(fdr);
}
if (allFields.size() > 0) {
this.rowsAll.add(new BlankRow());
}
// Methods
Map<String, Method> methodsA = new HashMap<String, Method>();
for (Method method : cfA.getMethods()) {
Descriptor desc = method.getDescriptor();
methodsA.put(desc.getReturn() + method.getName() + " " + desc.getParams(), method);
}
Map<String, Method> methodsB = new HashMap<String, Method>();
for (Method method : cfB.getMethods()) {
Descriptor desc = method.getDescriptor();
methodsB.put(desc.getReturn() + method.getName() + " " + desc.getParams(), method);
}
Set<String> allMethods = new TreeSet<String>();
allMethods.addAll(methodsA.keySet());
allMethods.addAll(methodsB.keySet());
for (String methodTypeNameParams : allMethods) {
Method methodA = methodsA.get(methodTypeNameParams);
Method methodB = methodsB.get(methodTypeNameParams);
if (methodA == null) {
List<EditorRow> methodRows = getMethodRows(cfB, methodB);
this.rowsB.addAll(methodRows);
this.rowsAll.addAll(methodRows);
// method only exists in B
} else if (methodB == null) {
List<EditorRow> methodRows = getMethodRows(cfA, methodA);
this.rowsA.addAll(methodRows);
this.rowsAll.addAll(methodRows);
// method only exists in A
} else {
// method exists in both
addMethodRows(cfA, cfB, methodA, methodB);
}
this.rowsAll.add(new BlankRow());
}
this.rowsAll.add(new ClassDefRow(cfA, false));
this.renderer.setRedSet(this.rowsA);