Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #19 from snyk/feat/markers-to-outer-file-support
Browse files Browse the repository at this point in the history
feat: markers leading to outer files support
  • Loading branch information
pavel-snyk authored Feb 25, 2021
2 parents ad9d402 + 7c963b9 commit 6aa2abc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/main/java/ai/deepcode/javaclient/core/AnalysisDataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,12 @@ private Map<Object, List<SuggestionForFile>> parseGetAnalysisResponse(
new MyTextRange(marker.getMsg().get(0), marker.getMsg().get(1) + 1);
final List<MyTextRange> positions =
marker.getPos().stream()
.map(it -> parsePosition2MyTextRange(it, file, Collections.emptyMap()))
.map(it -> {
final Object fileForMarker = (it.getFile() == null || it.getFile().isEmpty())
? file
: pdUtils.getFileByDeepcodedPath(it.getFile(), project);
return parsePosition2MyTextRange(it, fileForMarker, Collections.emptyMap());
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
markers.put(msgRange, positions);
Expand Down Expand Up @@ -752,7 +757,8 @@ private MyTextRange parsePosition2MyTextRange(
endRow,
startCol,
endCol,
markers);
markers,
position.getFile());
}

private FileContent createFileContent(Object file) {
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/ai/deepcode/javaclient/core/MyTextRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ public class MyTextRange {
private final int endCol;
// msg range poses in source file
private final Map<MyTextRange, List<MyTextRange>> markers;
private final String file;

MyTextRange(
int start,
int end,
int startRow,
int endRow,
int startCol,
int endCol,
Map<MyTextRange, List<MyTextRange>> markers) {
int start,
int end,
int startRow,
int endRow,
int startCol,
int endCol,
Map<MyTextRange, List<MyTextRange>> markers,
String file) {

this.start = start;
this.end = end;
Expand All @@ -30,10 +32,11 @@ public class MyTextRange {
this.startCol = startCol;
this.endCol = endCol;
this.markers = markers;
this.file = file;
}

MyTextRange(int start, int end) {
this(start, end, -1, -1, -1, -1, Collections.emptyMap());
this(start, end, -1, -1, -1, -1, Collections.emptyMap(), null);
}

public int getStart() {
Expand Down Expand Up @@ -63,4 +66,8 @@ public int getEndCol() {
public Map<MyTextRange, List<MyTextRange>> getMarkers() {
return markers;
}

public String getFile() {
return file;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public String getDeepCodedFilePath(@NotNull Object file) {
@NotNull
protected abstract String getProjectBasedFilePath(@NotNull Object file);

public abstract Object getFileByDeepcodedPath(String path, Object project);

public abstract Object[] getOpenProjects();
// ProjectManager.getInstance().getOpenProjects()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ public class MarkerPosition implements Position {

private List<Integer> rows;
private List<Integer> cols;
private String file;

public MarkerPosition(List<Integer> rows, List<Integer> cols) {
public MarkerPosition(List<Integer> rows, List<Integer> cols, String file) {
super();
this.rows = rows;
this.cols = cols;
this.file = file;
}

@Override
Expand All @@ -25,6 +27,11 @@ public List<Integer> getCols() {

@Override
public String toString() {
return "marker range: rows: " + rows + " cols: " + cols;
return "marker range: rows: " + rows + " cols: " + cols+ " file: " + file;
}

@Override
public String getFile() {
return file;
}
}
4 changes: 4 additions & 0 deletions src/main/java/ai/deepcode/javaclient/responses/Position.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public interface Position {

List<Integer> getCols();

default String getFile() {
return null;
}

@Override
String toString();
}

0 comments on commit 6aa2abc

Please sign in to comment.