diff --git a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/ScopeImpl.kt b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/ScopeImpl.kt index 0faaa60c..077d097e 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/ScopeImpl.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/ScopeImpl.kt @@ -50,7 +50,7 @@ class ScopeImpl(override val outer: Scope? = null, override val tree: AstNode? = node - override val type: AstNodeType? = tree?.type ?: type + override val type: AstNodeType? = type ?: tree?.type override val symbols = mutableListOf() diff --git a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/SymbolVisitor.kt b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/SymbolVisitor.kt index 239361a8..6c4e6aa9 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/SymbolVisitor.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/SymbolVisitor.kt @@ -190,9 +190,12 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa inheritanceClause.firstChild.type !== PlSqlKeyword.NOT && inheritanceClause.hasDirectChildren(PlSqlKeyword.OVERRIDING) + val nodeType: AstNodeType val identifier = if (node.parent.type == PlSqlGrammar.CREATE_TRIGGER) { + nodeType = PlSqlGrammar.CREATE_TRIGGER node.parent.getFirstChild(PlSqlGrammar.IDENTIFIER_NAME, PlSqlGrammar.UNIT_NAME) } else { + nodeType = node.type node.getFirstChild(PlSqlGrammar.IDENTIFIER_NAME, PlSqlGrammar.UNIT_NAME) } @@ -219,7 +222,8 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa } val symbol = createSymbol(identifier, symbolKind, type) - enterScope(node, autonomousTransaction, exceptionHandler, isOverridingMember, identifier.tokenOriginalValue) + enterScope(node, autonomousTransaction, exceptionHandler, isOverridingMember, identifier.tokenOriginalValue, + nodeType) symbol.innerScope = currentScope } @@ -379,7 +383,8 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa autonomousTransaction: Boolean? = null, exceptionHandler: Boolean? = null, overridingMember: Boolean? = null, - identifier: String? = null) { + identifier: String? = null, + type: AstNodeType? = null) { var autonomous = false var exception = false val isOverridingMember = overridingMember ?: false @@ -398,7 +403,7 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa } } - val scope = ScopeImpl(currentScope, node, node.token, node.lastToken, autonomous, exception, isOverridingMember, identifier) + val scope = ScopeImpl(currentScope, node, node.token, node.lastToken, autonomous, exception, isOverridingMember, identifier, type) symbolTable.addScope(scope) currentScope = scope } diff --git a/zpa-core/src/test/kotlin/org/sonar/plsqlopen/symbols/SymbolVisitorTest.kt b/zpa-core/src/test/kotlin/org/sonar/plsqlopen/symbols/SymbolVisitorTest.kt index 37d1a162..e8ca78ee 100644 --- a/zpa-core/src/test/kotlin/org/sonar/plsqlopen/symbols/SymbolVisitorTest.kt +++ b/zpa-core/src/test/kotlin/org/sonar/plsqlopen/symbols/SymbolVisitorTest.kt @@ -24,6 +24,7 @@ import org.assertj.core.groups.Tuple import org.junit.jupiter.api.Test import org.junit.jupiter.api.io.TempDir import org.sonar.plsqlopen.TestPlSqlVisitorRunner +import org.sonar.plugins.plsqlopen.api.PlSqlGrammar import org.sonar.plugins.plsqlopen.api.symbols.PlSqlType import org.sonar.plugins.plsqlopen.api.symbols.Symbol import org.sonar.plugins.plsqlopen.api.symbols.datatype.NumericDatatype @@ -459,6 +460,7 @@ end; tuple(5, 3)) assertThat(variable.innerScope).isNull() assertThat(variable.scope.identifier).isEqualTo("baz") + assertThat(variable.scope.type).isEqualTo(PlSqlGrammar.CREATE_TRIGGER) } @Test