11import com .ibm .wala .cast .tree .CAstSourcePositionMap .Position ;
22import com .ibm .wala .util .collections .Pair ;
33
4- import java .io . File ;
4+ import java .net . MalformedURLException ;
55import java .net .URL ;
66import java .util .ArrayList ;
77import java .util .List ;
88import java .util .stream .Collectors ;
99
10- import magpiebridge .util .SourceCodeInfo ;
11- import magpiebridge .util .SourceCodePositionFinder ;
12-
1310public class GoblintResult {
1411
1512 private List <tag > tags = new ArrayList <>();
1613 private String severity ;
1714 private multipiece multipiece ;
18- URL sourcefileURL ;
1915
2016 public static interface tag {
2117
@@ -50,8 +46,11 @@ static class multipiece {
5046
5147 static class loc {
5248
49+ private String file ;
5350 private int line ;
5451 private int column ;
52+ private int endLine ;
53+ private int endColumn ;
5554
5655 }
5756
@@ -62,27 +61,29 @@ static class pieces {
6261
6362 static class loc {
6463
64+ private String file ;
6565 private int line ;
6666 private int column ;
67+ private int endLine ;
68+ private int endColumn ;
6769 }
6870 }
6971
7072 }
7173
72- public List <GoblintAnalysisResult > convert () {
74+ public List <GoblintAnalysisResult > convert () throws MalformedURLException {
7375 List <GoblintAnalysisResult > results = new ArrayList <>();
7476
7577 if (multipiece .group_text == null ) {
7678 String message = tags .stream ().map (tag -> tag .toString ()).collect (Collectors .joining ("" )) + " " + multipiece .text ;
77- GoblintPosition pos = new GoblintPosition (multipiece .loc .line , multipiece .loc .column - 1 , findColumnEnd ( multipiece .loc .line , multipiece .loc .column ), sourcefileURL );
79+ GoblintPosition pos = new GoblintPosition (multipiece .loc .line , multipiece .loc .endLine , multipiece . loc . column - 1 , multipiece .loc .endColumn - 1 , new URL ( "file:" + multipiece .loc .file ) );
7880 GoblintAnalysisResult result = new GoblintAnalysisResult (pos , message , severity );
7981 results .add (result );
8082 } else {
8183 List <GoblintAnalysisResult > intermresults = new ArrayList <>();
8284 List <multipiece .pieces > pieces = multipiece .pieces ;
8385 for (multipiece .pieces piece : pieces ) {
84- GoblintPosition pos = new GoblintPosition (piece .loc .line , piece .loc .column - 1 ,
85- findColumnEnd (piece .loc .line , piece .loc .column ), sourcefileURL );
86+ GoblintPosition pos = new GoblintPosition (piece .loc .line , piece .loc .endLine , piece .loc .column - 1 , piece .loc .endColumn - 1 , new URL ("file:" + piece .loc .file ));
8687 GoblintAnalysisResult result = new GoblintAnalysisResult (pos ,
8788 tags .stream ().map (tag -> tag .toString ()).collect (Collectors .joining ("" )) + " Group: " + multipiece .group_text ,
8889 piece .text , severity );
@@ -105,20 +106,5 @@ public List<GoblintAnalysisResult> convert() {
105106 return results ;
106107 }
107108
108- public int findColumnEnd (int lineStart , int columnStart ) {
109-
110- // get source code of the specified line
111- SourceCodeInfo sourceCodeInfo = SourceCodePositionFinder .findCode (new File (sourcefileURL .getPath ()), lineStart );
112- // get the source code substring starting from the relevant assert statement.
113- // as the source code is given without the leading whitespace, but the column
114- // numbers take whitespace into account
115- // the offset must be subtracted from the original starting column which does
116- // include the leading whitespace
117- String sourceCode = sourceCodeInfo .code .substring (columnStart - sourceCodeInfo .range .getStart ().getCharacter ());
118- // find the index of the next semicolon
119- int indexOfNextSemicolon = sourceCode .indexOf (";" ) + 1 ;
120-
121- return columnStart + indexOfNextSemicolon ;
122- }
123109
124110}
0 commit comments