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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ class GenerateSettersAndGettersAction : FieldBasedAction() {
private val log = LoggerFactory.getLogger(GenerateSettersAndGettersAction::class.java)
}

private fun showErrorMessage(error: Throwable, context: Context?) {
log.error("Unable to generate setters and getters", error)
context ?: return
ThreadUtils.runOnUiThread {
flashError(context.getString(R.string.msg_cannot_generate_setters_getters))
}
}

override fun onGetFields(fields: List<String>, data: ActionData) {

showFieldSelector(fields = fields, data = data, actionId = id, listener = { checkedNames ->
Expand All @@ -76,12 +84,7 @@ class GenerateSettersAndGettersAction : FieldBasedAction() {
_, error,
->
if (error != null) {
log.error("Unable to generate setters and getters", error)
ThreadUtils.runOnUiThread {
flashError(
data[Context::class.java]!!.getString(R.string.msg_cannot_generate_setters_getters)
)
}
showErrorMessage(error, data[Context::class.java])
return@whenComplete
}
}
Expand Down Expand Up @@ -132,8 +135,12 @@ class GenerateSettersAndGettersAction : FieldBasedAction() {
}

ThreadUtils.runOnUiThread {
editor.text.insert(insert.line, insert.column, sb)
editor.formatCodeAsync()
try {
editor.text.insert(insert.line, insert.column, sb)
editor.formatCodeAsync()
} catch (e: StringIndexOutOfBoundsException) {
showErrorMessage(e, data[Context::class.java])
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,19 @@ public static Position insertAtEndOfClass(JavacTask task, CompilationUnitTree ro
) {
SourcePositions pos = Trees.instance(task).getSourcePositions();
LineMap lines = root.getLineMap();

long end = pos.getEndPosition(root, leaf);

if (end < 0) throw new IllegalStateException("Cannot determine class end position");

int line = (int) lines.getLineNumber(end);
int column = (int) lines.getColumnNumber(end);
return new Position(line - 1, column - 2);

if (line <= 0 || column <= 0) {
throw new IllegalStateException("Invalid class end position: line=" + line + ", column=" + column);
}

return new Position(line - 1, Math.max(0, column - 2));
}

private static String printParameters(final ExecutableType method, final MethodTree source) {
Expand Down