Using Visual Studio for Impact Analysis

In Visual Studio 2005/2008, the most useful tools for impact analysis are:

1)  Find Symbol

2)  Go to definition

3)  Find all references

4)  Call Browser

5)  Class View

We have already described these tools in the Concept Location lab. The premise of impact analysis is that developers located a class/struct/method/field that will change in response to a change request. As opposed to concept location, in impact analysis, developers need to find the full extent of the change, i.e. they need to construct the impact set as the set of all the files/classes/structs/methods/fields that might be affected by the change. The change can propagate through dependencies which are: inheritance, association, method calls.

Impact Analysis starts where concept location ended. The initial impact set contains the class identified during concept location; developers add incrementally potential impacted classes until all the neighbors of the classes in the impact set are visited.

Impact analysis tasks

Change Request 1

Consider the following code fragments of the class FileManager from the file buffer.h. FileManager has a field _nrBufs of type size_t and a method getNrBuffers() that returns the value of _nrBugs. Interestingly, getNrBuffers()returns an int not size_t, which may cause problems. The programmer decides to change the type of getNrBuffers to size_t. Complete tasks T1 and T2.

class FileManager {

public:

………………………………………………………………………………………………………………………… int getNrBuffers()

{

return _nrBufs;

};

private:

…………………………………………………………………………………………………………………………

size_t _nrBufs;

…………………………………………………………………………………………………………………………

};

T1: Use the Call Browser to find the number of clients of getNrBuffers(). Specify the lines of code, name of classes and the name of the file(s) that found. Will these lines change in response to Change Request 1 and how?

Answer: I found 3 clients, 1 file Notepad_plus.cpp. Yes, the lines will changed; the code fragment for(int i = 0; …) will be replaced with for(size_t i = 0;…)

void Notepad_plus::checkDocState()

{

…………………………………………………………………………………………………………………………

for(int i = 0; i < MainFileManager->getNrBuffers(); i++)

…………………………………………………………………………………………………………………………

}

bool Notepad_plus::dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix) {

…………………………………………………………………………………………………………………………

for(int i = 0; i < MainFileManager->getNrBuffers(); i++) {

Buffer * docbuf = MainFileManager->getBufferByIndex(i);

…………………………………………………………………………………………………………………………

}

LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {

…………………………………………………………………………………………………………………………

case WM_REMOVE_USERLANG:

{

TCHAR name[256];

lstrcpy(name, (TCHAR *)lParam);

//loop through buffers and reset the language (L_USER, TEXT("")) if (L_USER, name)

Buffer * buf;

for(int i = 0; i < MainFileManager->getNrBuffers(); i++) {

buf = MainFileManager->getBufferByIndex(i);

if (buf->getLangType() == L_USER & !lstrcmp(buf->getUserDefineLangName(), name))

buf->setLangType(L_USER, TEXT(""));

}

return TRUE;

}

…………………………………………………………………………………………………………………………

case WM_RENAME_USERLANG:

{

TCHAR oldName[256];

TCHAR newName[256];

lstrcpy(oldName, (TCHAR *)lParam);

lstrcpy(newName, (TCHAR *)wParam);

//loop through buffers and reset the language (L_USER, newName) if (L_USER, oldName)

Buffer * buf;

for(int i = 0; i < MainFileManager->getNrBuffers(); i++) {

buf = MainFileManager->getBufferByIndex(i);

if (buf->getLangType() == L_USER & !lstrcmp(buf->getUserDefineLangName(), oldName))

buf->setLangType(L_USER, newName);

}

return TRUE;

}

…………………………………………………………………………………………………………………………

}

T2: Using Find All References and Find Symbol tools can you find additional code in Notepad++ that will be impacted by the change? Name the files, methods and specify the lines of code that you find.

Answer: There is no additional code impacted.

Change Request 2

In WinMerge, consider the change request: “add an ignore swapped lines option to WinMerge’s edit view”. Concept location ended in the CDiffWrapper class, where two new methods, void ToggleIgnoreSwappedLines() and bool GetIgnoreSwappedLinesStatus()

T3. In Visual Studio, right click on the name of the struct FoundInfo (colored in yellow above) and using Find All Reference tool specify the files, classes/structs, and the lines of code resulted.

Answer:

class Finder findreplacedlg.cpp(435): FoundInfo Finder::EmptyFoundInfo(0, 0, 0, TEXT(""));

class Finder findreplacedlg.cpp(490): const FoundInfo fInfo = *(_pMainFoundInfos->begin() + lno);

struct FoundInfo findreplacedlg.h(43): struct FoundInfo {

class Finder findreplacedlg.h(160): void add(FoundInfo fi, SearchResultMarking mi, const TCHAR* foundline, int lineNb) {

class Finder findreplacedlg.h(207): std::vector<FoundInfo>* _pOldFoundInfos;

class Finder findreplacedlg.h(242): std::vector<FoundInfo> _foundInfos1;

class Finder findreplacedlg.h(243): std::vector<FoundInfo> _foundInfos2;

class Finder findreplacedlg.h(244): std::vector<FoundInfo>* _pMainFoundInfos;

class Finder findreplacedlg.h(260): static FoundInfo EmptyFoundInfo

T4. In Visual Studio, right click on the name of the constructor FoundInfo (colored in red above) and using Find All Reference tool specify the files, classes, and the lines of code that will be impacted by the change. What is the difference between the results of T3 and T4?

Answer:

Class FindReplaceDlg findreplacedlg.cpp(1512): _pFinder->add(FoundInfo(targetStart, targetEnd, docLength, fileName), srm, line.c_str(), lineNumber + 1);

struct FoundInfo findreplacedlg.h(44): FoundInfo(int start, int end, int size, const TCHAR *fullPath)

class Finder findreplacedlg.cpp(435): FoundInfo Finder::EmptyFoundInfo(0, 0, 0, TEXT(""));

class Finder findreplacedlg.cpp(490): const FoundInfo fInfo = *(_pMainFoundInfos->begin() + lno);

struct FoundInfo findreplacedlg.h(43): struct FoundInfo {

class Finder findreplacedlg.h(160): void add(FoundInfo fi, SearchResultMarking mi, const TCHAR* foundline, int lineNb) {

class Finder findreplacedlg.h(207): std::vector<FoundInfo>* _pOldFoundInfos;

class Finder findreplacedlg.h(242): std::vector<FoundInfo> _foundInfos1;

class Finder findreplacedlg.h(243): std::vector<FoundInfo> _foundInfos2;

class Finder findreplacedlg.h(244): std::vector<FoundInfo>* _pMainFoundInfos;

class Finder findreplacedlg.h(260): static FoundInfo EmptyFoundInfo

The first 2 lines were not reported in T3. The first line belongs to the class FindReplaceDlg, not included in T3.

T5. Construct the impact set for Change request 2. List all the files visited following the table template in the appendix. Specify the tools used and justify your decisions.

Answer:

# / Files / Tool used / Impacted / Comments
1 / FindReplaceDialog.h / Class View / Yes / Concept was located in FoundInfo struct. The file also contains the classes Finder and FindReplaceDialog
2 / FindReplaceDialog.cpp / Find All References / Yes / The class Finder will be affected by the change
3 / SmartHighlighter.cpp / Call Browser / Yes / The processRange method needs a new parameter – file length. SmartHighlighter uses the this method in the method highlightView
4 / SmartHighlighter.h / Go To Definition / Yes / The definition of the method highlightView needs to be changed
5 / ScintillaEditView.cpp / Find All References / No / Making sure the change do not propagate further
6 / NotePad_plus.cpp / Find All References / No / Neighbor of the class FindReplaceDlg
7 / ToolBar.h / Class View / No / Neighbor of the class FindReplaceDlg
8 / DockingDlgInterface / Class View / No / Neighbor of the class Finder


T6. Using Class View tool, draw all the classes and structs visited during T3. Mark the classes and structs of the impact set with an empty comment box.

Answer:

Figure 1. Classes visited for T5. The classes in the impact set are drawn with a yellow rectangle

Change Request 3

In WinMerge, consider the change request: “add an ignore swapped lines option to WinMerge’s edit view”. Concept location ended in the CDiffWrapper class, where two new methods, void ToggleIgnoreSwappedLines and bool GetIgnoreSwappedLinesStatus will be added

T7. Construct the impact set and name all types of dependencies considered. List all the files visited following the table template in the appendix. Specify the tools used and justify your decisions.

Answer:

# / Class Name / Tool Used / Impacted / Comments
1 / CDiffWrapper / Concept Location / Yes / Will need logic to test for swapped lines.
2 / CMergeDoc / Class View
Code Inspection / Yes / Impacted if swapped lines were in the difflist, but to be ignored. Not impacted at all if swapped lines do not appear in the difflist
3 / DiffList / Code Inspection / Yes / Will need added member function to delete an item out of the difflist
4 / CMergeEditView / Class View
Code Inspection / Yes / Impacted by the menu change to toggle the ignore function but not impacted by changes to difflist
5 / CMergeDoc / Code Inspection / Yes / Will need a member data of type bool to store the current state of the ignore toggle
6 / CMergeDoc / Class View
Find-in-File
Code Inspection / No / Used to gauge impact of just ignoring differences in difflist rather than not including them. This class would be impacted by displaying incorrect data.
7 / CLocationView / Class View
Find-in-file search for m_diffList.GetSize() / No / This class would be impacted if the change used ignoring items already in the difflist

T8: Using the Class View tool, draw all the classes and structs visited during T7. Mark the classes and structs of the impact set with an empty comment box.

Answer:

Figure 2. Classes visited for T7. The classes in the impact set have a yellow rectangle

Appendix

Use the following table template for T5 and T7:

# / Files / Tool used / Impacted / Comments
1
2
3
4
5
6
7
8