Skip to content

Commit

Permalink
Return a better description in some toString methods
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed May 15, 2022
1 parent 94c43b4 commit da49975
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,6 @@ class ScopeImpl(override val outer: Scope? = null,
return true
}

override fun toString() = "Scope{identifier='$identifier', type=$type, path=$path}"
override fun toString() = "${identifier ?: "<unnamed scope>"} type=$type path=$path"

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.sonar.plsqlopen.sslr.TreeImpl
import org.sonar.plugins.plsqlopen.api.symbols.PlSqlType
import org.sonar.plugins.plsqlopen.api.symbols.Symbol
import org.sonar.plugins.plsqlopen.api.symbols.datatype.PlSqlDatatype
import org.sonar.plugins.plsqlopen.api.symbols.datatype.UnknownDatatype

class SemanticAstNode(private val astNode: AstNode) : AstNode(astNode.type, astNode.name, astNode.token) {

Expand Down Expand Up @@ -62,6 +63,14 @@ class SemanticAstNode(private val astNode: AstNode) : AstNode(astNode.type, astN
tokens.joinToString(" ") { it.originalValue }
}

override fun toString(): String {
return super.toString() + if (plSqlDatatype != null && plSqlDatatype !is UnknownDatatype) {
" datatype=$plSqlDatatype"
} else {
""
}
}

init {
super.fromIndex = astNode.fromIndex
super.toIndex = astNode.toIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ open class Symbol(val node: AstNode?,

fun called(name: String) = name.equals(this.name, ignoreCase = true)

override fun toString() = "Symbol{name='$name', kind=$kind, scope=$scope}"
override fun toString() = "$name kind=$kind datatype=$datatype"
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ class AssociativeArrayDatatype(node: AstNode? = null) : PlSqlDatatype {
?: throw IllegalStateException("Associative array must have a nested type")

override fun toString(): String {
return "AssociativeArrayDatatype{nestedType=$nestedType}"
return "AssociativeArray{nestedType=$nestedType}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class BooleanDatatype : PlSqlDatatype {
override val type = PlSqlType.BOOLEAN

override fun toString(): String {
return "BooleanDatatype"
return "Boolean"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CharacterDatatype : PlSqlDatatype {
}

override fun toString(): String {
return "CharacterDatatype{length=$length}"
return "Character{length=$length}"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class DateDatatype : PlSqlDatatype {
override val type = PlSqlType.DATE

override fun toString(): String {
return "DateDatatype"
return "Date"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class ExceptionDatatype : PlSqlDatatype {
override val type = PlSqlType.EXCEPTION

override fun toString(): String {
return "ExceptionDatatype"
return "Exception"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class LobDatatype : PlSqlDatatype {
override val type = PlSqlType.LOB

override fun toString(): String {
return "LobDatatype"
return "Lob"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class NullDatatype : PlSqlDatatype {
override val type = PlSqlType.NULL

override fun toString(): String {
return "NullDatatype"
return "Null"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class NumericDatatype : PlSqlDatatype {
}

override fun toString(): String {
return "NumericDatatype{length=$length, precision=$precision}"
return "Numeric{length=$length, precision=$precision}"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class RecordDatatype : PlSqlDatatype {
override val type = PlSqlType.RECORD

override fun toString(): String {
return "RecordDatatype"
return "Record"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class RowtypeDatatype : PlSqlDatatype {
override val type = PlSqlType.ROWTYPE

override fun toString(): String {
return "RowtypeDatatype"
return "Rowtype"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class UnknownDatatype : PlSqlDatatype {
override val type = PlSqlType.UNKNOWN

override fun toString(): String {
return "UnknownDatatype"
return "Unknown"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ internal class SourceCodeModel(private val configurationModel: ConfigurationMode
private set
lateinit var astNode: AstNode
private set
lateinit var symbolTable: SymbolTable
private set

fun setSourceCode(source: File, charset: Charset) {
astNode = getSemanticNode(configurationModel.parser.parse(source))
Expand All @@ -47,22 +49,23 @@ internal class SourceCodeModel(private val configurationModel: ConfigurationMode
} catch (e: IOException) {
throw RuntimeException(e)
}
loadSymbolTable()
}

fun setSourceCode(sourceCode: String) {
astNode = getSemanticNode(configurationModel.parser.parse(sourceCode))
this.sourceCode = sourceCode
loadSymbolTable()
}

val xml: String
get() = AstXmlPrinter.print(astNode)

val symbolTable: SymbolTable
get() {
val symbolVisitor = SymbolVisitor(DefaultTypeSolver())
symbolVisitor.context = PlSqlVisitorContext(astNode, null, null)
symbolVisitor.init()
symbolVisitor.visitFile(astNode)
return symbolVisitor.symbolTable
}
private fun loadSymbolTable() {
val symbolVisitor = SymbolVisitor(DefaultTypeSolver())
symbolVisitor.context = PlSqlVisitorContext(astNode, null, null)
symbolVisitor.init()
symbolVisitor.visitFile(astNode)
symbolTable = symbolVisitor.symbolTable
}
}

0 comments on commit da49975

Please sign in to comment.