Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/main/java/GoblintAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public ProcessResult runCommand(File dirPath) throws IOException, InvalidExitVal
* to let goblint generate the json file with analysis results.
*
* @param file the file on which to run the analysis.
* @return returns true if goblint finished the analyse and json was generated sucessfully, false otherwise
* @return returns true if goblint finished the analysis and json was generated sucessfully, false otherwise
*/
private boolean generateJson(Module file) {
SourceFileModule sourcefile = (SourceFileModule) file;
Expand Down Expand Up @@ -175,14 +175,12 @@ private Collection<GoblintAnalysisResult> readResultsFromJson() {
for (int i = 0; i < resultArray.size(); i++) {
// Deserailize them into GoblintResult objects
GoblintResult goblintResult = gson.fromJson(resultArray.get(i), GoblintResult.class);
// Add sourcefileURL to object for generationg the position
goblintResult.sourcefileURL = this.sourcefileURL;
// Convert GoblintResult object to a list of GoblintAnalysisResults
results.addAll(goblintResult.convert());
}
log.debug("Analysis results read from json");

} catch (JsonIOException | JsonSyntaxException | FileNotFoundException e) {
} catch (JsonIOException | JsonSyntaxException | FileNotFoundException | MalformedURLException e) {
throw new RuntimeException(e);
}

Expand Down
17 changes: 9 additions & 8 deletions src/main/java/GoblintAnalysisResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import magpiebridge.core.AnalysisResult;
import magpiebridge.core.Kind;
import magpiebridge.util.SourceCodeReader;
// import magpiebridge.util.SourceCodeReader;

import org.eclipse.lsp4j.DiagnosticSeverity;

Expand Down Expand Up @@ -89,13 +89,14 @@ public Pair<Position, String> repair() {

@Override
public String code() {
String code;
try {
code = SourceCodeReader.getLinesInString(pos);
} catch (Exception e) {
throw new RuntimeException(e);
}
return code;
// String code;
// try {
// code = SourceCodeReader.getLinesInString(pos);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// return code;
return null;
}

}
34 changes: 10 additions & 24 deletions src/main/java/GoblintResult.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
import com.ibm.wala.util.collections.Pair;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import magpiebridge.util.SourceCodeInfo;
import magpiebridge.util.SourceCodePositionFinder;

public class GoblintResult {

private List<tag> tags = new ArrayList<>();
private String severity;
private multipiece multipiece;
URL sourcefileURL;

public static interface tag {

Expand Down Expand Up @@ -50,8 +46,11 @@ static class multipiece {

static class loc {

private String file;
private int line;
private int column;
private int endLine;
private int endColumn;

}

Expand All @@ -62,27 +61,29 @@ static class pieces {

static class loc {

private String file;
private int line;
private int column;
private int endLine;
private int endColumn;
}
}

}

public List<GoblintAnalysisResult> convert() {
public List<GoblintAnalysisResult> convert() throws MalformedURLException {
List<GoblintAnalysisResult> results = new ArrayList<>();

if (multipiece.group_text == null) {
String message = tags.stream().map(tag -> tag.toString()).collect(Collectors.joining("")) + " " + multipiece.text;
GoblintPosition pos = new GoblintPosition(multipiece.loc.line, multipiece.loc.column - 1, findColumnEnd(multipiece.loc.line, multipiece.loc.column), sourcefileURL);
GoblintPosition pos = new GoblintPosition(multipiece.loc.line, multipiece.loc.endLine, multipiece.loc.column - 1, multipiece.loc.endColumn - 1, new URL("file:" + multipiece.loc.file));
GoblintAnalysisResult result = new GoblintAnalysisResult(pos, message, severity);
results.add(result);
} else {
List<GoblintAnalysisResult> intermresults = new ArrayList<>();
List<multipiece.pieces> pieces = multipiece.pieces;
for (multipiece.pieces piece : pieces) {
GoblintPosition pos = new GoblintPosition(piece.loc.line, piece.loc.column - 1,
findColumnEnd(piece.loc.line, piece.loc.column), sourcefileURL);
GoblintPosition pos = new GoblintPosition(piece.loc.line, piece.loc.endLine, piece.loc.column - 1, piece.loc.endColumn - 1, new URL("file:" + piece.loc.file));
GoblintAnalysisResult result = new GoblintAnalysisResult(pos,
tags.stream().map(tag -> tag.toString()).collect(Collectors.joining("")) + " Group: " + multipiece.group_text,
piece.text, severity);
Expand All @@ -105,20 +106,5 @@ public List<GoblintAnalysisResult> convert() {
return results;
}

public int findColumnEnd(int lineStart, int columnStart) {

// get source code of the specified line
SourceCodeInfo sourceCodeInfo = SourceCodePositionFinder.findCode(new File(sourcefileURL.getPath()), lineStart);
// get the source code substring starting from the relevant assert statement.
// as the source code is given without the leading whitespace, but the column
// numbers take whitespace into account
// the offset must be subtracted from the original starting column which does
// include the leading whitespace
String sourceCode = sourceCodeInfo.code.substring(columnStart - sourceCodeInfo.range.getStart().getCharacter());
// find the index of the next semicolon
int indexOfNextSemicolon = sourceCode.indexOf(";") + 1;

return columnStart + indexOfNextSemicolon;
}

}