Skip to content

Commit

Permalink
yang-toole: Fixed simple name type reference inside a group
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner committed Nov 28, 2023
1 parent da7e53a commit 2775519
Showing 1 changed file with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.typefox.yang.yang.Presence;
import io.typefox.yang.yang.SchemaNode;
import io.typefox.yang.yang.Type;
import io.typefox.yang.yang.TypeReference;
import io.typefox.yang.yang.Typedef;
import io.typefox.yang.yang.XpathExpression;

Expand All @@ -45,8 +46,7 @@ public HasStatements(ElementIdentifier id) {

private List<HasStatements> children;
private transient HasStatements parent;



public void addToChildren(HasStatements child) {
if (children == null)
children = newArrayList();
Expand Down Expand Up @@ -147,16 +147,22 @@ public List<HasStatements> getRpcs() {

static public class ValueType {
final String prefix, name;
final transient boolean forceSimpleName;

public ValueType(String prefix, String name) {
this(prefix, name, false);
}

public ValueType(String prefix, String name, boolean forceSimpleName) {
super();
this.prefix = prefix;
this.name = name;
this.forceSimpleName = forceSimpleName;
}

@Override
public String toString() {
return prefix != null ? (prefix + ":" + name) : name;
return (prefix != null && !forceSimpleName) ? (prefix + ":" + name) : name;
}
}

Expand Down Expand Up @@ -277,22 +283,29 @@ private ValueType createValueType(Type typeStatement) {
return new ValueType(null, typeRef.getBuiltin());
}

Typedef typedef = typeRef.getType();
Typedef typeDef = typeRef.getType();
// FIXME use import statement prefix
var typeModule = ProcessorUtility.moduleIdentifier(typedef);
String prefix = Objects.equal(typeModule.name, ProcessorUtility.moduleIdentifier(typeRef).name) ? null
: typeModule.prefix;
return new ValueType(prefix, typedef.getName());
}
/*
private boolean sameParentModule(EObject o1, EObject o2) {
var o1module = EcoreUtil2.getContainerOfType(o1, AbstractModule.class);
if (o1module != null) {
return o1module.equals(EcoreUtil2.getContainerOfType(o2, AbstractModule.class));
var typeModule = ProcessorUtility.moduleIdentifier(typeDef);
var typeRefModule = ProcessorUtility.moduleIdentifier(typeRef);
var sameModule = Objects.equal(typeModule.name, typeRefModule.name);
String prefix = sameModule ? null : typeModule.prefix;

var refText = referenceText(typeRef);
if (prefix != null && refText != null && !refText.equals(prefix + ":" + typeDef.getName())) {
// use reference text if type
return new ValueType(prefix, typeDef.getName(), true);
}
return false;
return new ValueType(prefix, typeDef.getName());
}
*/

private String referenceText(TypeReference typeRef) {
var node = NodeModelUtils.getNode(typeRef);
if(node == null) {
return null;
}
return NodeModelUtils.getTokenText(node);
}

private String serializedXpath(XpathExpression reference) {
// TODO use serializer or implement a an own simple one
ICompositeNode nodeFor = NodeModelUtils.findActualNodeFor(reference);
Expand Down

0 comments on commit 2775519

Please sign in to comment.