Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[yang] show number of assignments in subtree #1298

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/xdev/yang/application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
--><Application applicationName="YangAppGenerator" comment="" factoryVersion="" versionName="1.0.1" xmlVersion="1.1">
--><Application applicationName="YangAppGenerator" comment="" factoryVersion="" versionName="1.0.2" xmlVersion="1.1">
<ApplicationInfo>
<RuntimeContextRequirements>
<RuntimeContextRequirement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.w3c.dom.Document;
import com.gip.xyna.utils.collections.Pair;

import xdev.yang.impl.Constants;
import xdev.yang.impl.YangCapabilityUtils;

import org.yangcentral.yangkit.model.api.stmt.Module;
Expand All @@ -36,6 +38,7 @@

public class DetermineUseCaseAssignments {

private static final Set<String> primitives = Set.of(Constants.TYPE_LEAF, Constants.TYPE_ANYXML);

public List<UseCaseAssignmentTableData> determineUseCaseAssignments(LoadYangAssignmentsData data) {
List<UseCaseAssignmentTableData> result = new ArrayList<UseCaseAssignmentTableData>();
Expand Down Expand Up @@ -67,15 +70,44 @@ public List<UseCaseAssignmentTableData> determineUseCaseAssignments(LoadYangAssi
private void fillValues(Document meta, List<Module> modules, List<UseCaseAssignmentTableData> entries) {
List<UseCaseMapping> mappings = UseCaseMapping.loadMappings(meta);
for (UseCaseAssignmentTableData entry : entries) {
for (UseCaseMapping mapping : mappings) {
if (mapping.getMappingYangPath().equals(entry.getLoadYangAssignmentsData().getTotalYangPath()) &&
mapping.getNamespace().equals(entry.getLoadYangAssignmentsData().getTotalNamespaces())) {
entry.unversionedSetValue(mapping.getValue());
}
}
String totalYangPath = entry.getLoadYangAssignmentsData().getTotalYangPath();
String totalNamespaces = entry.getLoadYangAssignmentsData().getTotalNamespaces();
String totalKeywords = entry.getLoadYangAssignmentsData().getTotalKeywords();
List<MappingPathElement> entryPath = UseCaseMapping.createPathList(totalYangPath, totalNamespaces, totalKeywords);
fillValue(entry, entryPath, mappings);
}
}


private void fillValue(UseCaseAssignmentTableData entry, List<MappingPathElement> entryPath, List<UseCaseMapping> mappings) {
boolean isPrimitive = primitives.contains(entry.getType());
String value = isPrimitive ? getPrimitiveValue(entryPath, mappings) : getContainerValue(entryPath, mappings);
entry.unversionedSetValue(value);
}


private String getPrimitiveValue(List<MappingPathElement> entryPath, List<UseCaseMapping> mappings) {
for (UseCaseMapping mapping : mappings) {
if (MappingPathElement.compareLists(entryPath, mapping.createPathList()) == 0) {
return mapping.getValue();
}
}
return "";
}


private String getContainerValue( List<MappingPathElement> entryPath, List<UseCaseMapping> mappings) {
int subAssignments = 0;
for (UseCaseMapping mapping : mappings) {
if (MappingPathElement.isMoreSpecificPath(entryPath, mapping.createPathList())) {
subAssignments++;
}
}

if (subAssignments > 0) {
return String.format("contains %s assignment%s", subAssignments, subAssignments == 1 ? "" : "s");
}

return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,11 @@ public static int compareLists(List<MappingPathElement> pathList, List<MappingPa
//all entries up to the minimum length are the same
return pathList.size() - otherPathList.size();
}

public static boolean isMoreSpecificPath(List<MappingPathElement> base, List<MappingPathElement> candidate) {
if(candidate.size() < base.size()) {
return false;
}
return compareLists(base, candidate.subList(0, base.size())) == 0;
}
}
Loading