Skip to content

Commit 4e6577e

Browse files
authored
CE-115 multiple include
1 parent 4ae8646 commit 4e6577e

8 files changed

Lines changed: 155 additions & 12 deletions

File tree

gen/oap/application/plugin/gen/parser/OapParser.java

Lines changed: 21 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grammars/oap.bnf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ module ::=
9292
[]
9393
module_name_pair
9494
( &'enabled' module_enabled )?
95-
( &'include' module_include )?
95+
( &'include' module_include )*
9696
( &'dependsOn' module_depends_on )?
97-
( &'include' module_include )?
97+
( &'include' module_include )*
9898
( &'services' module_services )?
99-
( &'include' module_include )?
99+
( &'include' module_include )*
100100
( &'configurations' module_configurations )? {
101101
pin = 1
102102
recoverWhile=recover_module
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package oap.application.plugin.ref
2+
3+
import com.intellij.codeInspection.LocalInspectionTool
4+
import com.intellij.codeInspection.ProblemHighlightType
5+
import com.intellij.codeInspection.ProblemsHolder
6+
import com.intellij.openapi.project.Project
7+
import com.intellij.psi.PsiElement
8+
import com.intellij.psi.PsiElementVisitor
9+
import com.intellij.psi.stubs.StubIndex
10+
import oap.application.plugin.gen.psi.OapModuleDependsOnName
11+
import oap.application.plugin.psi.ModuleUtils
12+
import oap.application.plugin.stub.OapModuleNameIndex
13+
14+
class ValidParametersInspection : LocalInspectionTool() {
15+
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
16+
return object : PsiElementVisitor() {
17+
override fun visitElement(element: PsiElement) {
18+
if (element is OapModuleDependsOnName) {
19+
// val project: Project = element.project
20+
//
21+
// var allKeys: Collection<String> = StubIndex.getInstance().getAllKeys(OapModuleNameIndex.KEY, project)
22+
//
23+
// val moduleName: String? = element.text
24+
//
25+
// val thisModuleName: String? = ModuleUtils.getModuleName(element.containingFile)
26+
//
27+
// if (thisModuleName != null && thisModuleName == moduleName) {
28+
// holder.registerProblem(
29+
// element,
30+
// "Cycle reference to self",
31+
// ProblemHighlightType.ERROR
32+
// )
33+
// }
34+
//
35+
// if (!allKeys.contains(moduleName)) {
36+
// holder.registerProblem(
37+
// element,
38+
// "Module '${moduleName ?: ""}' not found",
39+
// ProblemHighlightType.ERROR
40+
// )
41+
// }
42+
} else {
43+
super.visitElement(element)
44+
}
45+
}
46+
}
47+
}
48+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
displayName="Required valid module name" groupName="OAP" enabledByDefault="true"
8484
level="ERROR"/>
8585

86+
<localInspection language="OAP"
87+
implementationClass="oap.application.plugin.ref.ValidParametersInspection"
88+
displayName="Required valid parameter name" groupName="OAP" enabledByDefault="true"
89+
level="ERROR"/>
90+
8691
<!-- index -->
8792
<stubIndex implementation="oap.application.plugin.stub.OapModuleNameIndex"/>
8893
<stubIndex implementation="oap.application.plugin.stub.OapModuleServicesServiceIndex"/>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package oap.application.plugin.inspection
2+
3+
import oap.application.plugin.OapFixtureTestCase
4+
import oap.application.plugin.ref.ValidParametersInspection
5+
6+
class OapParametersTest : OapFixtureTestCase() {
7+
protected override fun setUp() {
8+
super.setUp()
9+
10+
myFixture.enableInspections(ValidParametersInspection::class.java)
11+
}
12+
13+
override fun getBasePath(): String {
14+
return "inspection"
15+
}
16+
17+
fun testParameterAsField() {
18+
19+
}
20+
}

src/test/kotlin/oap/application/plugin/parser/OapParserTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class OapParserTest : ParsingTestCase("parser", "oap", OapParserDefinition()) {
4141
fun testInclude() {
4242
doTest(false)
4343
}
44+
fun testInclude2() {
45+
doTest(false)
46+
}
4447

4548
fun testInvalidServices() {
4649
doTest(true)

testdata/parser/Include2.oap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name = Include2
2+
3+
include required("1")
4+
include required("2")
5+
include required("3")
6+
include required("4")
7+
include required("5")

testdata/parser/Include2.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
OAP_FILE
2+
OAP_MODULE_NAME_PAIR
3+
PsiElement(name)('name')
4+
PsiWhiteSpace(' ')
5+
PsiElement(=)('=')
6+
PsiWhiteSpace(' ')
7+
OAP_MODULE_NAME
8+
PsiElement(key_value)('Include2')
9+
PsiWhiteSpace('\n\n')
10+
OAP_MODULE_INCLUDE
11+
PsiElement(include)('include')
12+
PsiWhiteSpace(' ')
13+
PsiElement(required)('required')
14+
PsiElement(()('(')
15+
PsiElement(include_resource_name)('"1"')
16+
PsiElement())(')')
17+
PsiWhiteSpace('\n')
18+
OAP_MODULE_INCLUDE
19+
PsiElement(include)('include')
20+
PsiWhiteSpace(' ')
21+
PsiElement(required)('required')
22+
PsiElement(()('(')
23+
PsiElement(include_resource_name)('"2"')
24+
PsiElement())(')')
25+
PsiWhiteSpace('\n')
26+
OAP_MODULE_INCLUDE
27+
PsiElement(include)('include')
28+
PsiWhiteSpace(' ')
29+
PsiElement(required)('required')
30+
PsiElement(()('(')
31+
PsiElement(include_resource_name)('"3"')
32+
PsiElement())(')')
33+
PsiWhiteSpace('\n')
34+
OAP_MODULE_INCLUDE
35+
PsiElement(include)('include')
36+
PsiWhiteSpace(' ')
37+
PsiElement(required)('required')
38+
PsiElement(()('(')
39+
PsiElement(include_resource_name)('"4"')
40+
PsiElement())(')')
41+
PsiWhiteSpace('\n')
42+
OAP_MODULE_INCLUDE
43+
PsiElement(include)('include')
44+
PsiWhiteSpace(' ')
45+
PsiElement(required)('required')
46+
PsiElement(()('(')
47+
PsiElement(include_resource_name)('"5"')
48+
PsiElement())(')')

0 commit comments

Comments
 (0)