Main Content

getOrphanLinks

Class: slreq.LinkSet
Namespace: slreq

Get links with invalid source

Since R2024a

Description

orphanLinks = getOrphanLinks(myLinkSet) returns the links in the link set specified by myLinkSet that have an invalid link source. A link source is invalid when it cannot be found in the source artifact.

example

Input Arguments

expand all

Link set, specified as an slreq.LinkSet object.

Output Arguments

expand all

Orphan links, returned as an slreq.Link array.

Examples

expand all

This example shows how to get and delete orphan links.

Load the myAddRequirements requirement set, which contains requirements for a MATLAB® function that adds two inputs and outputs the result.

rs = slreq.load("myAddRequirements");

The myAddRequirements requirement set has incoming links from lines of code in the myAddOrphan MATLAB code file. Get a handle to the link set.

myLinkSet = slreq.find(Type="LinkSet");

Get the orphan links in the link set. Display the number of orphan links.

orphanLinks = getOrphanLinks(myLinkSet);
numOrphanLinks = numel(orphanLinks)
numOrphanLinks = 
1

Delete the orphan links.

count = deleteOrphanLinks(myLinkSet)
count = 
1

Confirm that there are no orphan links.

orphanLinks = getOrphanLinks(myLinkSet)
orphanLinks =

     []

This example shows how to find and repair orphan links.

Load the myAddRequirements requirement set, which contains requirements for a MATLAB® function that adds two inputs and outputs the result.

rs = slreq.load("myAddRequirements");

The myAddRequirements requirement set has incoming links from lines of code in the myAddOrphan MATLAB code file. Get a handle to the link set.

myLinkSet = slreq.find(Type="LinkSet");

Find the orphan links in the link set. Display the number of orphan links.

orphanLinks = getOrphanLinks(myLinkSet);
numOrphanLinks = numel(orphanLinks)
numOrphanLinks = 
1

The source of the orphan link is line 2 in the myAddOrphan MATLAB code file. Get the line range object associated with that line of code.

lineRange = slreq.getTextRange("myAddOrphan.m",2);

Repair the orphan link by using the setSource method.

setSource(orphanLinks(1),lineRange)

Confirm that there are no orphan links.

orphanLinks = getOrphanLinks(myLinkSet)
orphanLinks =

     []

Alternative Functionality

App

Use the Repair Invalid Links dialog box in the Requirements Editor to view the orphan links. For more information, see Resolve Links.

Version History

Introduced in R2024a