Skip to content

Commit 3132f6d

Browse files
committed
Strengthen checks when referencing nullable objects.
1 parent a99ae2c commit 3132f6d

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

src/main/kotlin/org/domaframework/doma/intellij/action/sql/JumpToDeclarationFromSqlAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class JumpToDeclarationFromSqlAction : AnAction() {
203203
*/
204204
private fun isNotBindVariable(it: PsiElement) =
205205
(
206-
it.parent.elementType is IFileElementType &&
206+
it.parent?.elementType is IFileElementType &&
207207
it.elementType != SqlTypes.EL_IDENTIFIER &&
208208
it !is SqlElPrimaryExpr &&
209209
!it.isNotWhiteSpace()

src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiDaoMethod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class PsiDaoMethod(
149149
val rootDir = psiProject.getContentRoot(daoFile) ?: return@runReadAction
150150
val sqlFile = File(sqlFilePath)
151151
val sqlFileName = sqlFile.name
152-
val parentDir = "${RESOURCES_PATH}/${sqlFile.parent.replace("\\", "/")}"
152+
val parentDir = "${RESOURCES_PATH}/${sqlFile.parent?.replace("\\", "/")}"
153153
val parenDirPathSpirit = parentDir.split("/").toTypedArray()
154154

155155
WriteCommandAction.runWriteCommandAction(psiProject) {

src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiPatternUtil.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ object PsiPatternUtil {
5959
(element.elementType == SqlTypes.EL_IDENTIFIER && element.prevLeaf()?.text == it) ||
6060
(
6161
element.elementType == TokenType.BAD_CHARACTER &&
62-
element.parent.prevLeafs
63-
.firstOrNull { p -> p.text == it || p.elementType == SqlTypes.BLOCK_COMMENT_START }
62+
element.parent
63+
?.prevLeafs
64+
?.firstOrNull { p -> p.text == it || p.elementType == SqlTypes.BLOCK_COMMENT_START }
6465
?.text == it
6566
)
6667
}
@@ -75,7 +76,11 @@ object PsiPatternUtil {
7576
override fun accepts(
7677
element: PsiElement,
7778
context: ProcessingContext?,
78-
): Boolean = element.containingFile.originalFile.virtualFile.extension == extension
79+
): Boolean =
80+
element.containingFile
81+
?.originalFile
82+
?.virtualFile
83+
?.extension == extension
7984
},
8085
)
8186

@@ -88,7 +93,7 @@ object PsiPatternUtil {
8893
element: PsiElement,
8994
symbol: String,
9095
): String {
91-
val text = originalFile.containingFile.text
96+
val text = originalFile.containingFile?.text ?: " "
9297
val offset = element.textOffset
9398
val builder = StringBuilder()
9499
for (i in offset - 1 downTo 0) {

src/main/kotlin/org/domaframework/doma/intellij/contributor/sql/provider/SqlParameterCompletionProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class SqlParameterCompletionProvider : CompletionProvider<CompletionParameters>(
258258
setFieldsAndMethodsCompletionResultSet(matchFields, matchMethod, result)
259259
return
260260
}
261-
if (top.parent !is PsiFile && top.parent.parent !is PsiDirectory) {
261+
if (top.parent !is PsiFile && top.parent?.parent !is PsiDirectory) {
262262
val staticDirective = top.findNodeParent(SqlTypes.EL_STATIC_FIELD_ACCESS_EXPR)
263263
staticDirective?.let {
264264
topElementType = getElementTypeByStaticFieldAccess(top, it, topText) ?: return

src/main/kotlin/org/domaframework/doma/intellij/formatter/block/SqlBlock.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,16 +580,16 @@ open class SqlBlock(
580580
}
581581

582582
if (child2 is SqlElBlockCommentBlock) {
583-
when (child1) {
583+
return when (child1) {
584584
is SqlElBlockCommentBlock -> {
585-
return SqlCustomSpacingBuilder().getSpacing(child2)
585+
SqlCustomSpacingBuilder().getSpacing(child2)
586586
}
587587

588588
is SqlWhitespaceBlock -> {
589-
return SqlCustomSpacingBuilder().getSpacing(child2)
589+
SqlCustomSpacingBuilder().getSpacing(child2)
590590
}
591591

592-
else -> return SqlCustomSpacingBuilder.normalSpacing
592+
else -> SqlCustomSpacingBuilder.normalSpacing
593593
}
594594
}
595595

src/main/kotlin/org/domaframework/doma/intellij/gutter/sql/SqlLineMakerProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SqlLineMakerProvider : RelatedItemLineMarkerProvider() {
4848
if (!isSupportFileType(file) || isInjectionSqlFile(file)) return
4949
// Display only on the first line
5050
if (e.originalElement?.parent?.originalElement !is PsiFile ||
51-
e.textRange.startOffset != file.textRange.startOffset
51+
e.textRange?.startOffset != file.textRange?.startOffset
5252
) {
5353
return
5454
}
@@ -66,7 +66,7 @@ class SqlLineMakerProvider : RelatedItemLineMarkerProvider() {
6666
identifier.textRange,
6767
getIcon(daoFile.toPsiFile(project)),
6868
getToolTipTitle(daoFile.toPsiFile(project)),
69-
getHandler(daoFile, identifier, file.virtualFile.nameWithoutExtension),
69+
getHandler(daoFile, identifier, file.virtualFile?.nameWithoutExtension ?: ""),
7070
GutterIconRenderer.Alignment.RIGHT,
7171
) {
7272
ArrayList<GotoRelatedItem>()

0 commit comments

Comments
 (0)