Skip to content

Commit a78dfb8

Browse files
committed
Fix an alway null warning in CustomConstraintFunctionReference.moduleUriValue.
1 parent b92bacf commit a78dfb8

2 files changed

Lines changed: 15 additions & 32 deletions

File tree

src/lang-xpm/main/uk/co/reecedunn/intellij/plugin/xpm/optree/item/Items.kt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
/*
2-
* Copyright (C) 2021 Reece H. Dunn
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright (C) 2021, 2026 Reece H. Dunn. SPDX-License-Identifier: Apache-2.0
162
package uk.co.reecedunn.intellij.plugin.xpm.optree.item
173

184
import uk.co.reecedunn.intellij.plugin.xdm.types.XdmAttributeNode
@@ -43,6 +29,10 @@ val XdmElementNode.namespaceUri: String?
4329
val XdmElementNode.localName: String?
4430
get() = nodeName?.localName?.data
4531

32+
fun XdmElementNode.getAttribute(ns: String, localName: String): XdmAttributeNode? {
33+
return attributes.find { it.localName == localName && it.namespaceUri == ns }
34+
}
35+
4636
fun XdmElementNode.getAttributeValue(ns: String, localName: String): String? {
4737
return attributes.find { it.localName == localName && it.namespaceUri == ns }?.stringValue
4838
}

src/plugin-marklogic/main/uk/co/reecedunn/intellij/plugin/marklogic/search/options/reference/CustomConstraintFunctionReference.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
/*
2-
* Copyright (C) 2021 Reece H. Dunn
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright (C) 2021, 2026 Reece H. Dunn. SPDX-License-Identifier: Apache-2.0
162
package uk.co.reecedunn.intellij.plugin.marklogic.search.options.reference
173

184
import com.intellij.psi.PsiElement
@@ -26,6 +12,7 @@ import uk.co.reecedunn.intellij.plugin.xdm.types.XdmAttributeNode
2612
import uk.co.reecedunn.intellij.plugin.xdm.types.XdmElementNode
2713
import uk.co.reecedunn.intellij.plugin.xdm.types.element
2814
import uk.co.reecedunn.intellij.plugin.xpm.optree.function.XpmFunctionDeclaration
15+
import uk.co.reecedunn.intellij.plugin.xpm.optree.item.getAttribute
2916
import uk.co.reecedunn.intellij.plugin.xpm.optree.item.getAttributeValue
3017
import uk.co.reecedunn.intellij.plugin.xpm.optree.item.localName
3118
import uk.co.reecedunn.intellij.plugin.xquery.ast.xquery.XQueryDirAttributeValue
@@ -51,15 +38,21 @@ class CustomConstraintFunctionReference(
5138
val moduleNamespace: String?
5239
get() = node.getAttributeValue("", "ns")
5340

54-
@Suppress("MemberVisibilityCanBePrivate")
41+
@Suppress("unused")
5542
val moduleUri: String?
5643
get() = node.getAttributeValue("", "at")
5744

5845
// endregion
5946
// region function reference
6047

6148
private val moduleUriValue: PsiElement?
62-
get() = (moduleUri as? PsiElement)?.children()?.filterIsInstance<XQueryDirAttributeValue>()?.firstOrNull()
49+
get() {
50+
val moduleUriNode = node.getAttribute("", "at")
51+
return (moduleUriNode as? PsiElement)
52+
?.children()
53+
?.filterIsInstance<XQueryDirAttributeValue>()
54+
?.firstOrNull()
55+
}
6356

6457
private val moduleUriReference: PsiReference?
6558
get() = moduleUriValue?.references?.find { it is ModuleUriReference }

0 commit comments

Comments
 (0)