Skip to content

Commit

Permalink
fix: Register all the trigger scopes with the type "CREATE_TRIGGER"
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed May 27, 2024
1 parent d6ab929 commit 600b4ea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Symbol>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 600b4ea

Please sign in to comment.