-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80a3d41
commit 6167503
Showing
18 changed files
with
249 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/icu/windea/pls/lang/expression/complex/ParadoxDefineReferenceExpression.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package icu.windea.pls.lang.expression.complex | ||
|
||
import com.intellij.openapi.util.* | ||
import icu.windea.pls.* | ||
import icu.windea.pls.config.configGroup.* | ||
import icu.windea.pls.config.* | ||
import icu.windea.pls.core.collections.* | ||
import icu.windea.pls.lang.expression.complex.nodes.* | ||
|
||
/** | ||
* 定义引用表达式。对应的CWT规则类型为[CwtDataTypes.DefineReference]。 | ||
* | ||
* 语法: | ||
* | ||
* ```bnf | ||
* database_object_expression ::= database_object_type ":" database_object (":" swapped_database_object)? | ||
* database_object_type ::= TOKEN //predefined by CWT Config (see database_object_types.cwt) | ||
* database_object ::= TOKEN //predefined by CWT Config (see database_object_types.cwt) | ||
* swapped_database_object ::= TOKEN //predefined by CWT Config (see database_object_types.cwt) | ||
* ``` | ||
* | ||
* 示例: | ||
* | ||
* * `define:NPortrait|GRACEFUL_AGING_START` | ||
*/ | ||
class ParadoxDefineReferenceExpression private constructor( | ||
override val text: String, | ||
override val rangeInExpression: TextRange, | ||
override val nodes: List<ParadoxComplexExpressionNode>, | ||
override val configGroup: CwtConfigGroup | ||
) : ParadoxComplexExpression.Base() { | ||
override val errors by lazy { validate() } | ||
|
||
companion object Resolver { | ||
fun resolve(expressionString: String, range: TextRange, configGroup: CwtConfigGroup): ParadoxDefineReferenceExpression? { | ||
if (expressionString.isEmpty()) return null | ||
|
||
val incomplete = PlsStates.incompleteComplexExpression.get() ?: false | ||
|
||
val nodes = mutableListOf<ParadoxComplexExpressionNode>() | ||
val expression = ParadoxDefineReferenceExpression(expressionString, range, nodes, configGroup) | ||
////TODO 1.3.25 | ||
return expression | ||
} | ||
|
||
private fun ParadoxDefineReferenceExpression.validate(): List<ParadoxComplexExpressionError> { | ||
val errors = mutableListOf<ParadoxComplexExpressionError>() | ||
var malformed = false | ||
for (node in nodes) { | ||
if (node.text.isEmpty()) { | ||
malformed = true | ||
break | ||
} | ||
} | ||
if (malformed) { | ||
errors += ParadoxComplexExpressionErrors.malformedDefineReferenceExpression(rangeInExpression, text) | ||
} | ||
return errors.pinned { it.isMalformedError() } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ea/pls/lang/inspections/script/expression/IncorrectDefineReferenceExpressionInspection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package icu.windea.pls.lang.inspections.script.expression | ||
|
||
import com.intellij.codeInspection.* | ||
import com.intellij.openapi.progress.* | ||
import com.intellij.openapi.util.* | ||
import com.intellij.psi.* | ||
import com.intellij.ui.dsl.builder.* | ||
import icu.windea.pls.* | ||
import icu.windea.pls.config.* | ||
import icu.windea.pls.lang.* | ||
import icu.windea.pls.lang.expression.complex.* | ||
import icu.windea.pls.lang.util.* | ||
import icu.windea.pls.script.psi.* | ||
import javax.swing.* | ||
|
||
/** | ||
* 不正确的[ParadoxDefineReferenceExpression]的检查。 | ||
* | ||
* @property reportsUnresolved 是否报告无法解析的引用。 | ||
*/ | ||
class IncorrectDefineReferenceExpressionInspection : LocalInspectionTool() { | ||
@JvmField | ||
var reportsUnresolved = true | ||
|
||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { | ||
if (!shouldCheckFile(holder.file)) return PsiElementVisitor.EMPTY_VISITOR | ||
val configGroup = getConfigGroup(holder.project, selectGameType(holder.file)) | ||
return object : PsiElementVisitor() { | ||
override fun visitElement(element: PsiElement) { | ||
ProgressManager.checkCanceled() | ||
if (element is ParadoxScriptStringExpressionElement) visitStringExpressionElement(element) | ||
} | ||
|
||
private fun visitStringExpressionElement(element: ParadoxScriptStringExpressionElement) { | ||
val config = ParadoxExpressionManager.getConfigs(element).firstOrNull() ?: return | ||
val dataType = config.expression.type | ||
if (dataType != CwtDataTypes.DefineReference) return | ||
val value = element.value | ||
val textRange = TextRange.create(0, value.length) | ||
val expression = ParadoxDefineReferenceExpression.resolve(value, textRange, configGroup) ?: return | ||
handleErrors(element, expression) | ||
} | ||
|
||
private fun handleErrors(element: ParadoxScriptStringExpressionElement, expression: ParadoxDefineReferenceExpression) { | ||
expression.errors.forEach { error -> handleError(element, error) } | ||
expression.processAllNodes { node -> node.getUnresolvedError(element)?.let { error -> handleError(element, error) }.let { true } } | ||
} | ||
|
||
private fun handleError(element: ParadoxScriptStringExpressionElement, error: ParadoxComplexExpressionError) { | ||
if (!reportsUnresolved && error.isUnresolvedError()) return | ||
holder.registerExpressionError(error, element) | ||
} | ||
} | ||
} | ||
|
||
private fun shouldCheckFile(file: PsiFile): Boolean { | ||
if (selectRootFile(file) == null) return false | ||
return true | ||
} | ||
|
||
override fun createOptionsPanel(): JComponent { | ||
return panel { | ||
//reportsUnresolved | ||
row { | ||
checkBox(PlsBundle.message("inspection.script.incorrectExpression.option.reportsUnresolved")) | ||
.bindSelected(::reportsUnresolved) | ||
.actionListener { _, component -> reportsUnresolved = component.isSelected } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.