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

Commit

Permalink
Fix code insertion bug
Browse files Browse the repository at this point in the history
  • Loading branch information
juli1 committed Apr 27, 2022
1 parent 5cee4d5 commit c2dbe5b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginGroup = codiga.io.plugins
pluginName = codiga-jetbrains-plugin
pluginVersion = 1.5.1
pluginVersion = 1.5.2


pluginSinceBuild = 212.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,50 @@ public static int firstPositionToInsert(String code, LanguageEnumeration languag
}

}
if (languageEnumeration == LanguageEnumeration.JAVA) {
if (languageEnumeration == LanguageEnumeration.JAVA || languageEnumeration == LanguageEnumeration.SCALA) {

boolean inComment = false;
for (String line: codeArray) {
final String lineWithoutSpace = line.replaceAll(" ", "");

if (line.startsWith(JAVA_PACKAGE_KEYWORD)) {
start = line.length() + 1;
} else {
break;
start = start + line.length() + 1;
continue;
}
}
}
if (languageEnumeration == LanguageEnumeration.SCALA) {

for (String line: codeArray) {
if (line.startsWith(SCALA_PACKAGE_KEYWORD)) {
start = line.length() + 1;
} else {
break;
/**
* We do not want to add code on top of a comment
*/
if (lineWithoutSpace.startsWith("/*")) {
start = start + line.length() + 1;
inComment = true;
continue;
}
if (lineWithoutSpace.startsWith("*/") && inComment) {
inComment = false;
start = start + line.length() + 1;
continue;
}
if (lineWithoutSpace.startsWith("//")) {
inComment = false;
start = start + line.length() + 1;
continue;
}

if (inComment) {
start = start + line.length() + 1;
continue;
}

break;
}
}
return start;

if (start < code.length()) {
return start;
} else {
return 0;
}
}

public static Optional<String> getKeywordFromLine(String line, int position) {
Expand Down

0 comments on commit c2dbe5b

Please sign in to comment.