Validate link in source codeValidate link expectations from the source code. This paragraph will help you find out whether the link is EXPECTED or NOT EXPECTED, based on the source code. - Open the source file containing the caller. and search for references to the object name of the callee.
- If you find a reference to the callee name in the caller source file the link is EXPECTED, except in particular cases where more checks are needed:
Compiled languages : imports and includes If the technology of both caller and callee is one of the following : J2EE, C, C++, .Net then you should wonder : would this code compile? In other words, are all the necessary includes and imports present ? And are all the paths correctly defined ?
J2EE : Links between Java objects Check that the class containing the callee is imported into the caller source file. For example, if you expect a link between method getC() from class A and method makeC() from class B() : class A{
private B myB;
.....
public C getC(){
return myB.makeC();
} |
Then you need to check that either classes B and C belong to the same package as class A, or you have the following lines at the beginning of file A.java: import com.mypackage.B;
import com.myOtherPackage.C; |
If classes B and C do not belong to the same package as class A, or if the imports are not present, then the link is NOT EXPECTED
J2EE : Links from a JSP page If the callee is another JSP file, then you must check that its path is correct in the caller source file. For example: <%@ include file="some/relative/path/other.jsp" %>
<%@ include file="/some/absolute/path/yetAnother.jsp" %> |
Check that the relative path is correct, that is to say that, starting from the folder of the caller source file, there is a file called other.jsp located in <folder_of_the_caller>\some\relative\path Check that the absolute path is correct, considering as root the path defined as Application root path in Cast-MS configuration. Example : if Application root path is defined as S:\Sources\App\webapp then you should check that file S:\Sources\App\webapp\some\absolute\path\yetAnother.jsp exists If the callee is a Javascript method, please check that : The Javascript file containing the Javascript function is included The Javascript file contains the Javascript function The path of the Javascript file is correct
- If any of the above conditions are not true the link is NOT EXPECTED
.NET : Links between C# methods Inside a .Net job, we can analyze many different projects (many csproj files and/or ASP websites). Links are created between objects of 2 different projects only when one of these projects refers the other. If the missing links are between 2 objects then Check if the 2 objects belong to same project or not. Check if the cs files the objects belong to are refered in the same .csproj - If the 2 objects belong to the same project then the link is EXPECTED
- If the 2 objects do not belong to the same project, check if one of the 2 projects refers to the other
- Check the references on each csproj file project
Example: if the 2 projects are called ConfigFileLibrary and AdminFileLibrary If in AdminFileLibrary.csproj file you have reference to ConfigFileLibrary.csproj, as following one, this means that AdminFileLibrary refers the ConfigFileLibrary project. <ItemGroup> <ProjectReference Include="..\testConfigFileLibrary\ConfigFileLibrary.csproj"> <Project> Project1</Project> <Name>testConfigFileLibrary</Name> </ProjectReference> </ItemGroup> - Ensure that reference to the project contains relative path as this oneProjectReference Include="..\testConfigFileLibrary\ConfigFileLibrary.csproj{*}">
The reference should not contain only the project name as <ProjectReference Include="ConfigFileLibrary.csproj"> - If one of the csproj contains a reference to other projects with a relative path, the link is EXPECTED else the link NOT EXPECTED.
C++ : Links between objects Check if the required header files are included in the caller source file. If the code of the caller calls a callee method, then the header file defining the callee should be included, as follows : #include "some/path/to/header/containing/callee_definition.h" |
You have to check that the path of the include file is correct (the file exists), else the link is NOT EXPECTED. There is also a C++ directive which informs the compiler that '.h' file must be included only one time in the C++ source code, it is : "#pragma once". For example, if C++ source file (a.h) contains this directive and this file is included by two other source files (b.cpp and c.cpp), then the C++ analyzer will take into account only the first include directive that it encounter (ex in b.cpp). So a link will be created between the two files (a.h and b.cpp), and all other #include directives will be ignored and no more include link will be created to the file a.h (c.cpp ---> a.h). In this case, the missing links are expected behavior, as the links are NOT EXPECTED
- If you don't find a reference to the callee name in the caller source file, then the link is NOT EXPECTED, except in the following particular cases
Caller belongs to an Object-Oriented technology (J2EE, .Net, C++) : dynamic link by inheritance In such languages, a link is expected if the reference is in an ancestor class or an implemented interface and if the call is in the child class. Example in Java: public interface ICaller{
public static String _TABLE_NAME = "MyTable";
} |
public class Caller implements ICaller{
public int execQuery(){
String query= "select * from " + _TABLE_NAME +";";
connection.executeQuery(query);
....
}
} |
Here, a link is expected between method execQuery and table TABLE_NAME because class Caller inherits interface ICaller, even if the reference is in the interface. So, even if you do not see a reference to the callee in the caller source file, you have to : - Find out the list of ancestors of the caller class: Please refer to How to find out the list of ancestors of a class
- Look for references to the callee in all the source files for each ancestor of your list :
In Java, the source files have the same name as the class or interface they contain: you will find interface IGrandParentInterface in file IGrandParentInterface.java and class Parent in file Parent.java If you find a reference to the callee in the source files, the link is EXPECTED. If not, the link is NOT EXPECTED
- For J2EE: If the caller is a Java method or a Java constructor, and the callee is a Java Class, it may be referred to implicitly by Dependency Injection as in the example
Spring or CDI frameworks. Check whether these frameworks are used in the source code by following How to check whether a framework is used by an application - Find out all the interfaces implemented by the callee by following How to find out the list of ancestors of a class and consider only the interfaces
- Look for references to any of the interface list in the caller source file
- If you find a reference to any of the interface lists in the caller source file then the link is EXPECTED. In this case, also check Spring configuration or CDI configuration in Validate Configuration
- If you don't find a reference, then the link is NOT EXPECTED
|