Skip to content

Commit

Permalink
Adding comparison of element content
Browse files Browse the repository at this point in the history
  • Loading branch information
svanteschubert committed Apr 19, 2023
1 parent 5f8bca8 commit be980c5
Show file tree
Hide file tree
Showing 61 changed files with 7,932 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ private void createChangeMessage(Change c){
boolean isFixedDefaultByEnumeration = newEnumerationList.size() == 1;
newEnumerationList.removeAll(c.oldNode.getEnumeration());
if(newEnumerationList.size() > 0){
c.setReportHeader(c.getReportHeader() + "\n\t\t\tadded: " + newEnumerationList.toString());
if(isFixedDefaultByEnumeration) {// if single enumeration (new)
if (c.oldNode.getFixedValue() != null && c.oldNode.getFixedValue().equals(newEnumerationList.get(0))) {
c.setReportHeader(c.getReportHeader() + (" (no semantic change, as new single enumeration value existed as previous fixed default: " + c.newNode.getFixedValue() + ")"));
Expand All @@ -224,6 +225,7 @@ private void createChangeMessage(Change c){
ArrayList<String> oldEnumerationList = new ArrayList<>(c.oldNode.getEnumeration());
boolean wasFixedDefaultByEnumeration = oldEnumerationList.size() == 1;
oldEnumerationList.removeAll(c.newNode.getEnumeration());
c.setReportHeader(c.getReportHeader() + "\n\t\t\tremoved: " + oldEnumerationList.toString());
if(wasFixedDefaultByEnumeration){ // if was a single neumeration (old)
if (c.newNode.getFixedValue() != null && c.newNode.getFixedValue().equals(oldEnumerationList.get(0))) {
c.setReportHeader(c.getReportHeader() + (" (no semantic change, as removed single enumeration value still exists as fixed default: " + c.newNode.getFixedValue() + ")"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ private void createChangeMessage(Change c){
// an enumeration is a restriction of the set of strings
// so there have to be some enumeration earlier and if the new enumeration list is longer (it is an extension)
if((c.oldNode.getEnumeration() != null && c.oldNode.getEnumeration().size() > 0) && newEnumerationList.size() > 0){
getModificationStringBuilder().append("\n\t\tExtended enumeration from " + c.oldNode.getEnumeration() + " to " + c.newNode.getEnumeration());
getModificationStringBuilder().append("\n\t\tExtended enumeration from " + c.oldNode.getEnumeration() + " to " + c.newNode.getEnumeration() +
"\n\t\t\tadded: " + newEnumerationList.toString());
if(isFixedDefaultByEnumeration) {// if single enumeration (new)
if (c.oldNode.getFixedValue() != null && c.oldNode.getFixedValue().equals(newEnumerationList.get(0))) {
getModificationStringBuilder().append(" (no semantic change, as new single enumeration value existed as previous fixed default: " + c.newNode.getFixedValue() + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ private void createChangeMessage(Change c){
// either enumeration old list was longer or did not exist at all
if(oldEnumerationList.size() > 0 || (c.oldNode.getEnumeration() == null || c.oldNode.getEnumeration().size() == 0)){
if(oldEnumerationList.size() > 0){
getModificationStringBuilder().append("\n\t\tNarrowed enumeration from " + c.oldNode.getEnumeration() + " to " + c.newNode.getEnumeration());
getModificationStringBuilder().append("\n\t\tNarrowed enumeration from " + c.oldNode.getEnumeration() + " to " + c.newNode.getEnumeration() +
"\n\t\t\tremoved: " + oldEnumerationList.toString());
}else{
getModificationStringBuilder().append("\n\t\tNew restriction by enumeration from " + c.oldNode.getEnumeration() + " to " + c.newNode.getEnumeration());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.xerces.xs.XSFacet;
import org.apache.xerces.xs.XSMultiValueFacet;
import org.apache.xerces.xs.XSSimpleTypeDefinition;
import org.apache.xerces.xs.XSTypeDefinition;
import org.apache.xerces.xs.*;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -62,7 +59,7 @@ public abstract class AbstractXsdNode implements XsdNode {
protected Integer totalDigits;
protected Integer fractionDigits;
protected short compositor;
protected List<String> enumeration = new ArrayList<>();
protected List<String> enumeration;

protected AbstractXsdNode parent;
protected Change change;
Expand Down Expand Up @@ -178,7 +175,7 @@ public static String getUniversalName(String namespace, String name){
public String getXmlValue() {
if (StringUtils.isNotEmpty(getFixedValue())) {
return getFixedValue();
} else if (CollectionUtils.isNotEmpty(getEnumeration())) {
} else if (getEnumeration() != null && CollectionUtils.isNotEmpty(getEnumeration())) {
return getEnumeration().get(0);
}

Expand All @@ -193,7 +190,7 @@ public String getXmlValue() {
public String getXmlComment() {
String comment = "";

if (CollectionUtils.isNotEmpty(getEnumeration())) {
if (getEnumeration() != null && CollectionUtils.isNotEmpty(getEnumeration())) {
comment += " Possible values: " + getEnumeration();
}
if (StringUtils.isNotEmpty(getPattern())) {
Expand Down Expand Up @@ -228,6 +225,23 @@ protected void loadType(XSTypeDefinition typeDefinition) {
}
*/
this.typeName = typeDefinition.getName();
if(typeDefinition instanceof XSComplexTypeDefinition){
XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition) typeDefinition;
if(complexTypeDefinition.getContentType() == XSComplexTypeDefinition.CONTENTTYPE_SIMPLE){
XSSimpleTypeDefinition st = complexTypeDefinition.getSimpleType();
if(this.enumeration == null){
this.enumeration = new ArrayList<>();
}
this.enumeration = st.getLexicalEnumeration();
}
}else if(typeDefinition instanceof XSSimpleTypeDefinition){
if(this.enumeration == null){
this.enumeration = new ArrayList<>();
}
this.enumeration = ((XSSimpleTypeDefinition)typeDefinition).getLexicalEnumeration();
}else {
System.out.println("This story does not end up!");
}
}

/**
Expand Down Expand Up @@ -323,7 +337,12 @@ protected void loadSimpleType(XSSimpleTypeDefinition simpleType) {

switch (facet.getFacetKind()) {
case XSSimpleTypeDefinition.FACET_ENUMERATION:
this.enumeration.addAll(facet.getLexicalFacetValues());
if(this.enumeration == null){
this.enumeration = new ArrayList<>();
}
// has already being added earlier
assert(this.enumeration.equals(facet.getLexicalFacetValues()));
//this.enumeration.addAll(facet.getLexicalFacetValues());
break;
case XSSimpleTypeDefinition.FACET_PATTERN:
this.pattern = String.join(", ", facet.getLexicalFacetValues());
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/com/compare/xsd/comparison/XsdComparerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public void multiComparisonTest() throws IOException {
String facets2 = XSD_DIR + "facets2.xsd";
String fixedValueVariant1 = XSD_DIR + "fixedValueVariant1.xsd";
String fixedValueVariant2 = XSD_DIR + "fixedValueVariant2.xsd";
String contentChange1 = XSD_DIR + "contentChange1.xsd";
String contentChange2 = XSD_DIR + "contentChange2.xsd";
Boolean compareCorrect = Boolean.TRUE;
// compareCorrect &= compareTwoXsdGrammars(facets1, facets2, TextReport.implementation.ONLY_EXTENSIONS);
// compareTwoXsdGrammars(facets1, facets2, TextReport.implementation.MULTI_LINE_CHANGE);
Expand All @@ -110,6 +112,7 @@ public void multiComparisonTest() throws IOException {
compareCorrect &= compareTwoXsdGrammars(facets2, facets1, reportType);
compareCorrect &= compareTwoXsdGrammars(fixedValueVariant1, fixedValueVariant2, reportType);
compareCorrect &= compareTwoXsdGrammars(fixedValueVariant2, fixedValueVariant1, reportType);
compareCorrect &= compareTwoXsdGrammars(contentChange1, contentChange2, reportType);
}

assertTrue(compareCorrect,"\nRegression test fails as reference was different!\nNote: If the test fails due to a new output (e.g. programming update) copy the new result over the old reference:\n\t" + TARGET_DIR + "\n\t\tto" + "\n\t" + REFERENCES_DIR);
Expand Down
Loading

0 comments on commit be980c5

Please sign in to comment.