Skip to content

Commit

Permalink
feat: Add firstToken and lastToken to Scope because the "tree" is emp…
Browse files Browse the repository at this point in the history
…ty on the scopes added to the global scope
  • Loading branch information
felipebz committed May 23, 2024
1 parent c7e952d commit 7199edc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ObjectLocator {
val plSqlFile = it.plSqlFile as SonarQubePlSqlFile? ?: return@map null
val identifier = it.identifier ?: return@map null
val type = it.type ?: return@map null
val firstLine = it.tree?.tokenLine ?: return@map null
val lastLine = it.tree?.lastTokenOrNull?.endLine ?: return@map null
val firstLine = it.firstToken?.line ?: return@map null
val lastLine = it.lastToken?.line ?: return@map null
MappedObject(identifier, type, plSqlFile.type(), plSqlFile.path(), plSqlFile.inputFile, firstLine, lastLine)
}.filterNotNull()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.sonar.plsqlopen.symbols

import com.felipebz.flr.api.AstNode
import com.felipebz.flr.api.AstNodeType
import com.felipebz.flr.api.Token
import org.sonar.plugins.plsqlopen.api.PlSqlFile
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar
import org.sonar.plugins.plsqlopen.api.symbols.Scope
Expand All @@ -31,6 +32,8 @@ import kotlin.concurrent.withLock

class ScopeImpl(override val outer: Scope? = null,
node: AstNode? = null,
override val firstToken: Token? = null,
override val lastToken: Token? = null,
override val isAutonomousTransaction: Boolean = false,
override val hasExceptionHandler: Boolean = false,
override val isOverridingMember: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa
private fun declareGlobalSymbols(current: Scope, outer: Scope) {
val scope = ScopeImpl(
outer = outer,
node = null,
firstToken = current.firstToken,
lastToken = current.lastToken,
isAutonomousTransaction = current.isAutonomousTransaction,
hasExceptionHandler = current.hasExceptionHandler,
isOverridingMember = current.isOverridingMember,
Expand Down Expand Up @@ -396,7 +397,7 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa
}
}

val scope = ScopeImpl(currentScope, node, autonomous, exception, isOverridingMember)
val scope = ScopeImpl(currentScope, node, node.token, node.lastToken, autonomous, exception, isOverridingMember)
symbolTable.addScope(scope)
currentScope = scope
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.sonar.plugins.plsqlopen.api.symbols

import com.felipebz.flr.api.AstNode
import com.felipebz.flr.api.AstNodeType
import com.felipebz.flr.api.Token
import org.sonar.plugins.plsqlopen.api.PlSqlFile
import java.util.*

Expand All @@ -37,6 +38,8 @@ interface Scope {
val type: AstNodeType?
val isGlobal: Boolean
val plSqlFile: PlSqlFile?
val firstToken: Token?
val lastToken: Token?

/**
* @param kind of the symbols to look for
Expand Down

0 comments on commit 7199edc

Please sign in to comment.