or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ast.mdcpd.mdindex.mdlanguage-module.mdmetrics.mdmultifile.mdrules.md

multifile.mddocs/

0

# Multifile Analysis

1

2

Cross-file analysis capabilities using ApexLink for analyzing dependencies and relationships across multiple Apex files in a Salesforce project.

3

4

## Capabilities

5

6

### Multifile Analysis

7

8

Handles cross-file analysis using ApexLink for comprehensive project-wide analysis.

9

10

```java { .api }

11

/**

12

* Handles cross-file analysis using ApexLink

13

* Provides analysis of dependencies and relationships across multiple Apex files

14

*/

15

public class ApexMultifileAnalysis {

16

/**

17

* Check if multifile analysis failed

18

* @return true if analysis failed, false if successful

19

*/

20

public boolean isFailed();

21

22

/**

23

* Get issues for a specific file from multifile analysis

24

* @param fileName - Name of the Apex file to get issues for

25

* @return List of issues found in the specified file

26

*/

27

public List<Issue> getFileIssues(String fileName);

28

}

29

```

30

31

### Internal API Bridge

32

33

Bridge to internal API components for multifile analysis.

34

35

```java { .api }

36

/**

37

* Bridge to internal API components

38

* Provides access to internal multifile analysis functionality

39

*/

40

public class InternalApiBridge {

41

// Internal API access methods

42

}

43

```

44

45

### Issue Representation

46

47

Issues found during multifile analysis.

48

49

```java { .api }

50

/**

51

* Represents an issue found during multifile analysis

52

*/

53

public interface Issue {

54

/** Get issue message */

55

String getMessage();

56

57

/** Get issue severity level */

58

Severity getSeverity();

59

60

/** Get file location where issue occurs */

61

String getFileName();

62

63

/** Get line number where issue occurs */

64

int getLineNumber();

65

66

/** Get issue category */

67

String getCategory();

68

}

69

70

/**

71

* Issue severity levels

72

*/

73

public enum Severity {

74

ERROR, WARNING, INFO

75

}

76

```

77

78

**Usage Examples:**

79

80

```java

81

import net.sourceforge.pmd.lang.apex.multifile.ApexMultifileAnalysis;

82

import net.sourceforge.pmd.lang.apex.ApexLanguageProperties;

83

84

// Configure multifile analysis with Salesforce metadata directory

85

LanguagePropertyBundle properties = apexModule.newPropertyBundle();

86

properties.setProperty(ApexLanguageProperties.MULTIFILE_DIRECTORY, "/path/to/salesforce/project");

87

88

// Create processor with multifile analysis enabled

89

ApexLanguageProcessor processor = apexModule.createProcessor(properties);

90

ApexMultifileAnalysis multifileAnalysis = processor.getMultiFileState();

91

92

// Check if analysis was successful

93

if (multifileAnalysis.isFailed()) {

94

System.out.println("Multifile analysis failed - some cross-file issues may not be detected");

95

} else {

96

System.out.println("Multifile analysis successful");

97

98

// Get issues for specific files

99

List<Issue> classIssues = multifileAnalysis.getFileIssues("MyController.cls");

100

List<Issue> triggerIssues = multifileAnalysis.getFileIssues("AccountTrigger.trigger");

101

102

// Process issues

103

processIssues("MyController.cls", classIssues);

104

processIssues("AccountTrigger.trigger", triggerIssues);

105

}

106

107

private void processIssues(String fileName, List<Issue> issues) {

108

if (issues.isEmpty()) {

109

System.out.println("No multifile issues found in " + fileName);

110

return;

111

}

112

113

System.out.println("Multifile issues in " + fileName + ":");

114

for (Issue issue : issues) {

115

System.out.printf(" [%s] Line %d: %s (Category: %s)%n",

116

issue.getSeverity(),

117

issue.getLineNumber(),

118

issue.getMessage(),

119

issue.getCategory());

120

}

121

}

122

123

// Use in PMD rule that requires multifile context

124

public class CrossFileRule extends AbstractApexRule {

125

@Override

126

public Object visit(ASTUserClass node, Object data) {

127

RuleContext ctx = (RuleContext) data;

128

ApexMultifileAnalysis multifile = ctx.getLanguageProcessor().getMultiFileState();

129

130

if (!multifile.isFailed()) {

131

String fileName = ctx.getFileDisplayName();

132

List<Issue> issues = multifile.getFileIssues(fileName);

133

134

// Check for specific cross-file issues

135

for (Issue issue : issues) {

136

if (issue.getCategory().equals("DEPENDENCY_ISSUE")) {

137

ctx.addViolation(node, "Cross-file dependency issue: " + issue.getMessage());

138

}

139

}

140

}

141

142

return super.visit(node, data);

143

}

144

}

145

```