Skip to content

Commit 71be51b

Browse files
committed
feat: Added an option to be able to see which attributes are actively set on the current level (and hereby which ones are inherited)
1 parent 51e0853 commit 71be51b

24 files changed

+112
-65
lines changed

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultAbstractField.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
import org.apache.plc4x.plugins.codegenerator.types.terms.Term;
2323

2424
import java.util.Map;
25+
import java.util.Set;
2526

2627
public class DefaultAbstractField extends DefaultTypedNamedField implements AbstractField {
2728

28-
public DefaultAbstractField(Map<String, Term> attributes, String name, String comment) {
29-
super(attributes, name, comment);
29+
public DefaultAbstractField(Map<String, Term> attributes, Set<String> currentAttributeNames, String name, String comment) {
30+
super(attributes, currentAttributeNames, name, comment);
3031
}
3132

3233
@Override

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultArrayField.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525

2626
import java.util.Map;
2727
import java.util.Objects;
28+
import java.util.Set;
2829

2930
public class DefaultArrayField extends DefaultTypedNamedField implements ArrayField {
3031

3132
private final LoopType loopType;
3233
private final Term loopExpression;
3334

34-
public DefaultArrayField(Map<String, Term> attributes, String name, LoopType loopType, Term loopExpression, String comment) {
35-
super(attributes, name, comment);
35+
public DefaultArrayField(Map<String, Term> attributes, Set<String> currentAttributeNames, String name, LoopType loopType, Term loopExpression, String comment) {
36+
super(attributes, currentAttributeNames, name, comment);
3637
this.loopType = Objects.requireNonNull(loopType);
3738
this.loopExpression = Objects.requireNonNull(loopExpression);
3839
}

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultAssertField.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323

2424
import java.util.Map;
2525
import java.util.Objects;
26+
import java.util.Set;
2627

2728
public class DefaultAssertField extends DefaultTypedNamedField implements AssertField {
2829

2930
private final Term conditionExpression;
3031

31-
public DefaultAssertField(Map<String, Term> attributes, String name, Term conditionExpression, String comment) {
32-
super(attributes, name, comment);
32+
public DefaultAssertField(Map<String, Term> attributes, Set<String> currentAttributeNames, String name, Term conditionExpression, String comment) {
33+
super(attributes, currentAttributeNames, name, comment);
3334
this.conditionExpression = Objects.requireNonNull(conditionExpression);
3435
}
3536

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultChecksumField.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424

2525
import java.util.Map;
2626
import java.util.Objects;
27+
import java.util.Set;
2728

2829
public class DefaultChecksumField extends DefaultTypedNamedField implements ChecksumField {
2930

3031
private final Term checksumExpression;
3132

32-
public DefaultChecksumField(Map<String, Term> attributes, SimpleTypeReference type, String name, Term checksumExpression, String comment) {
33-
super(attributes, name, comment);
33+
public DefaultChecksumField(Map<String, Term> attributes, Set<String> currentAttributeNames, SimpleTypeReference type, String name, Term checksumExpression, String comment) {
34+
super(attributes, currentAttributeNames, name, comment);
3435
this.checksumExpression = Objects.requireNonNull(checksumExpression);
3536
this.type = type;
3637
}

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultConstField.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424

2525
import java.util.Map;
2626
import java.util.Objects;
27+
import java.util.Set;
2728

2829
public class DefaultConstField extends DefaultTypedNamedField implements ConstField {
2930

3031
private final Literal referenceValue;
3132

32-
public DefaultConstField(Map<String, Term> attributes, String name, Literal referenceValue, String comment) {
33-
super(attributes, name, comment);
33+
public DefaultConstField(Map<String, Term> attributes, Set<String> currentAttributeNames, String name, Literal referenceValue, String comment) {
34+
super(attributes, currentAttributeNames, name, comment);
3435
this.referenceValue = Objects.requireNonNull(referenceValue);
3536
}
3637

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultDiscriminatorField.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
import org.apache.plc4x.plugins.codegenerator.types.terms.Term;
2323

2424
import java.util.Map;
25+
import java.util.Set;
2526

2627
public class DefaultDiscriminatorField extends DefaultTypedNamedField implements DiscriminatorField {
2728

28-
public DefaultDiscriminatorField(Map<String, Term> attributes, String name, String comment) {
29-
super(attributes, name, comment);
29+
public DefaultDiscriminatorField(Map<String, Term> attributes, Set<String> currentAttributeNames, String name, String comment) {
30+
super(attributes, currentAttributeNames, name, comment);
3031
}
3132

3233
@Override

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultEnumField.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424

2525
import java.util.Map;
2626
import java.util.Objects;
27+
import java.util.Set;
2728

2829
public class DefaultEnumField extends DefaultTypedNamedField implements EnumField {
2930

3031
private final String fieldName;
3132

32-
public DefaultEnumField(Map<String, Term> attributes, EnumTypeReference type, String name, String fieldName, String comment) {
33-
super(attributes, name, comment);
33+
public DefaultEnumField(Map<String, Term> attributes, Set<String> currentAttributeNames, EnumTypeReference type, String name, String fieldName, String comment) {
34+
super(attributes, currentAttributeNames, name, comment);
3435
this.fieldName = Objects.requireNonNull(fieldName);
3536
this.type = type;
3637
}

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultField.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,24 @@
2424
import java.util.Map;
2525
import java.util.Objects;
2626
import java.util.Optional;
27+
import java.util.Set;
2728

2829

2930
public abstract class DefaultField {
3031

3132
protected final Map<String, Term> attributes;
33+
protected final Set<String> currentAttributeNames;
3234
protected final String comment;
3335
protected TypeDefinition owner;
3436

35-
protected DefaultField(Map<String, Term> attributes, String comment) {
37+
protected DefaultField(Map<String, Term> attributes, Set<String> currentAttributeNames, String comment) {
3638
this.attributes = Objects.requireNonNull(attributes);
39+
currentAttributeNames.forEach(attributeName -> {
40+
if (!attributes.containsKey(attributeName)) {
41+
throw new IllegalArgumentException("Attribute '" + attributeName + "' is not defined for field " + this);
42+
}
43+
});
44+
this.currentAttributeNames = Objects.requireNonNull(currentAttributeNames);
3745
this.comment = comment;
3846
}
3947

@@ -49,6 +57,14 @@ public void setOwner(TypeDefinition owner) {
4957
this.owner = owner;
5058
}
5159

60+
public Set<String> getAllAttributeNames() {
61+
return attributes.keySet();
62+
}
63+
64+
public Set<String> getCurrentAttributeNames() {
65+
return attributes.keySet();
66+
}
67+
5268
public Optional<Term> getAttribute(String attributeName) {
5369
if (attributes.containsKey(attributeName)) {
5470
return Optional.of(attributes.get(attributeName));

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultImplicitField.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424

2525
import java.util.Map;
2626
import java.util.Objects;
27+
import java.util.Set;
2728

2829
public class DefaultImplicitField extends DefaultTypedNamedField implements ImplicitField {
2930

3031
private final Term serializeExpression;
3132

32-
public DefaultImplicitField(Map<String, Term> attributes, SimpleTypeReference type, String name, Term serializeExpression, String comment) {
33-
super(attributes, name, comment);
33+
public DefaultImplicitField(Map<String, Term> attributes, Set<String> currentAttributeNames, SimpleTypeReference type, String name, Term serializeExpression, String comment) {
34+
super(attributes, currentAttributeNames, name, comment);
3435
this.serializeExpression = Objects.requireNonNull(serializeExpression);
3536
this.type = type;
3637
}

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/model/fields/DefaultManualArrayField.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.util.Map;
2727
import java.util.Objects;
28+
import java.util.Set;
2829

2930
public class DefaultManualArrayField extends DefaultTypedNamedField implements ManualArrayField {
3031

@@ -34,8 +35,8 @@ public class DefaultManualArrayField extends DefaultTypedNamedField implements M
3435
private final Term serializeExpression;
3536
private final Term lengthExpression;
3637

37-
public DefaultManualArrayField(Map<String, Term> attributes, String name, LoopType loopType, Term loopExpression, Term parseExpression, Term serializeExpression, Term lengthExpression, String comment) {
38-
super(attributes, name, comment);
38+
public DefaultManualArrayField(Map<String, Term> attributes, Set<String> currentAttributeNames, String name, LoopType loopType, Term loopExpression, Term parseExpression, Term serializeExpression, Term lengthExpression, String comment) {
39+
super(attributes, currentAttributeNames, name, comment);
3940
this.loopType = Objects.requireNonNull(loopType);
4041
this.loopExpression = Objects.requireNonNull(loopExpression);
4142
this.parseExpression = Objects.requireNonNull(parseExpression);

0 commit comments

Comments
 (0)