Skip to content

Commit 26c3b70

Browse files
authored
Merge pull request github#110 from github/smowton/admin/style-fixed
Fix Kotlin style snags
2 parents 4a75e24 + 1101ecf commit 26c3b70

File tree

20 files changed

+2183
-4738
lines changed

20 files changed

+2183
-4738
lines changed

java/kotlin-extractor/src/main/java/com/semmle/extractor/java/PopulateFile.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,22 @@ public static String escapeKey(String s) {
7373
}
7474
}
7575

76-
public Label populateFile(File absoluteFile) {
77-
String databasePath = transformer.fileAsDatabaseString(absoluteFile);
78-
// Ensure the rewritten path is used from now on.
79-
File normalisedFile = new File(databasePath);
80-
Label result = tw.getLabelFor("@\"" + escapeKey(databasePath) + ";sourcefile" + "\"");
81-
KotlinExtractorDbSchemeKt.writeFiles(tw, result, databasePath);
82-
populateParents(normalisedFile, result);
83-
return result;
84-
}
76+
public Label populateFile(File absoluteFile) {
77+
return getFileLabel(absoluteFile, true);
78+
}
79+
80+
public Label getFileLabel(File absoluteFile, boolean populateTables) {
81+
String databasePath = transformer.fileAsDatabaseString(absoluteFile);
82+
Label result = tw.getLabelFor("@\"" + escapeKey(databasePath) + ";sourcefile" + "\"");
83+
// Ensure the rewritten path is used from now on.
84+
85+
if(populateTables) {
86+
KotlinExtractorDbSchemeKt.writeFiles(tw, result, databasePath);
87+
populateParents(new File(databasePath), result);
88+
}
89+
90+
return result;
91+
}
8592

8693
private Label addFolderTuple(String databasePath) {
8794
Label result = tw.getLabelFor("@\"" + escapeKey(databasePath) + ";folder" + "\"");
@@ -104,15 +111,22 @@ private void populateParents(File normalisedFile, Label label) {
104111
KotlinExtractorDbSchemeKt.writeContainerparent(tw, parentLabel, label);
105112
}
106113

107-
public Label relativeFileId(File jarFile, String pathWithinJar) {
114+
public Label relativeFileId(File jarFile, String pathWithinJar) {
115+
return getFileInJarLabel(jarFile, pathWithinJar, true);
116+
}
117+
118+
public Label getFileInJarLabel(File jarFile, String pathWithinJar, boolean populateTables) {
108119
if (pathWithinJar.contains("\\"))
109120
throw new CatastrophicError("Invalid jar path: '" + pathWithinJar + "' should not contain '\\'.");
110121

122+
String databasePath = transformer.fileAsDatabaseString(jarFile);
123+
if(!populateTables)
124+
return tw.getLabelFor("@\"" + databasePath + "/" + pathWithinJar + ";jarFile\"");
125+
111126
Label jarFileId = this.populateFile(jarFile);
112-
Label jarFileLocation = tw.getLocation(jarFileId,0,0,0,0);
113-
KotlinExtractorDbSchemeKt.writeHasLocation(tw, jarFileId, jarFileLocation);
127+
Label jarFileLocation = tw.getLocation(jarFileId, 0, 0, 0, 0);
128+
KotlinExtractorDbSchemeKt.writeHasLocation(tw, jarFileId, jarFileLocation);
114129

115-
String databasePath = transformer.fileAsDatabaseString(jarFile);
116130
StringBuilder fullName = new StringBuilder(databasePath);
117131
String[] split = pathWithinJar.split("/");
118132
Label current = jarFileId;

0 commit comments

Comments
 (0)