Skip to content

Commit 195533f

Browse files
committed
fix a space issue for lizardReport
1 parent 44b4e27 commit 195533f

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

sonar-swift-plugin/src/main/java/com/backelite/sonarqube/swift/complexity/LizardReportParser.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ private void updateIndexes(NodeList nodeList) {
9696
if (node.getNodeType() == Node.ELEMENT_NODE) {
9797
Element element = (Element) node;
9898
String label = element.getTextContent();
99-
if(LINE_COUNT_LABEL.equalsIgnoreCase(label))
99+
if (LINE_COUNT_LABEL.equalsIgnoreCase(label))
100100
lineCountIndex = i;
101-
else if(CYCLOMATIC_COMPLEXITY_LABEL.equalsIgnoreCase(label))
101+
else if (CYCLOMATIC_COMPLEXITY_LABEL.equalsIgnoreCase(label))
102102
cyclomaticComplexityIndex = i;
103-
else if(FUNCTION_COUNT_LABEL.equalsIgnoreCase(label))
103+
else if (FUNCTION_COUNT_LABEL.equalsIgnoreCase(label))
104104
functionCountIndex = i;
105105
}
106106
}
@@ -115,17 +115,18 @@ private void parseMeasure(String type, NodeList itemList) {
115115

116116
NodeList values = itemElement.getElementsByTagName(VALUE);
117117
if (FILE_MEASURE.equalsIgnoreCase(type)) {
118-
addComplexityFileMeasures(name,values);
118+
addComplexityFileMeasures(name, values);
119119
} else if (FUNCTION_MEASURE.equalsIgnoreCase(type)) {
120-
addComplexityFunctionMeasures(new SwiftFunction(name),values);
120+
addComplexityFunctionMeasures(new SwiftFunction(name), values);
121121
}
122122
}
123123
}
124124
}
125125

126126
private void addComplexityFileMeasures(String fileName, NodeList values) {
127+
LOGGER.debug("File measures for {}",fileName);
127128
FilePredicate fp = context.fileSystem().predicates().hasRelativePath(fileName);
128-
if(!context.fileSystem().hasFiles(fp)){
129+
if (!context.fileSystem().hasFiles(fp)) {
129130
LOGGER.warn("file not included in sonar {}", fileName);
130131
return;
131132
}
@@ -153,6 +154,7 @@ private void addComplexityFileMeasures(String fileName, NodeList values) {
153154
}
154155

155156
private void addComplexityFunctionMeasures(SwiftFunction component, NodeList values) {
157+
LOGGER.debug("Function measures for {}",component.key);
156158
int complexity = Integer.parseInt(values.item(cyclomaticComplexityIndex).getTextContent());
157159
context.<Integer>newMeasure()
158160
.on(component)
@@ -175,13 +177,21 @@ private static class SwiftFunction implements InputModule {
175177
private int lineNumber;
176178

177179
public SwiftFunction(String name) {
178-
String[] vals = name.split(" ");
179-
if(vals.length >= 3){
180-
this.name = vals[0].substring(0,vals[0].indexOf("("));
181-
this.file = vals[2].substring(0,vals[2].lastIndexOf(":"));
182-
this.lineNumber = Integer.parseInt(vals[2].substring(vals[2].lastIndexOf(":")+1));
183-
this.key = file.substring(0,file.lastIndexOf('.')+1)+name;
184-
}else{
180+
String[] vals = name.split(" at ");
181+
if (vals.length == 2) {
182+
this.name = vals[0].replaceAll("\\W","");
183+
184+
if (vals[1].contains(":")) {
185+
String[] sp = vals[1].split(":");
186+
this.file = sp[0].substring(0,sp[0].lastIndexOf("."));
187+
this.lineNumber = Integer.parseInt(sp[1]);
188+
} else {
189+
this.file = vals[1];
190+
this.lineNumber = 0;
191+
}
192+
193+
this.key = String.format("%s.%s:%d", this.file, this.name, this.lineNumber);
194+
} else {
185195
this.key = name;
186196
}
187197
}
@@ -191,15 +201,15 @@ public String key() {
191201
return key;
192202
}
193203

194-
public String getName(){
204+
public String getName() {
195205
return name;
196206
}
197207

198-
public String getFile(){
208+
public String getFile() {
199209
return file;
200210
}
201211

202-
public int getLineNumber(){
212+
public int getLineNumber() {
203213
return lineNumber;
204214
}
205215

0 commit comments

Comments
 (0)