diff --git a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/DefaultTypeSolver.kt b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/DefaultTypeSolver.kt index 119b4b6a..a09b52c0 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/DefaultTypeSolver.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/symbols/DefaultTypeSolver.kt @@ -35,11 +35,11 @@ open class DefaultTypeSolver { } else if (node.type === PlSqlGrammar.LITERAL) { return solveLiteral(node) } - return UnknownDatatype() + return UnknownDatatype } open fun solveDatatype(node: AstNode, scope: Scope?): PlSqlDatatype { - var type: PlSqlDatatype = UnknownDatatype() + var type: PlSqlDatatype = UnknownDatatype if (node.hasDirectChildren(PlSqlGrammar.CHARACTER_DATAYPE)) { type = CharacterDatatype(node) } else if (node.hasDirectChildren(PlSqlGrammar.NUMERIC_DATATYPE)) { @@ -59,13 +59,13 @@ open class DefaultTypeSolver { type = JsonDatatype() } else { val datatype = node.firstChild - type = scope?.getSymbol(datatype.tokenValue, Symbol.Kind.TYPE)?.datatype ?: UnknownDatatype() + type = scope?.getSymbol(datatype.tokenValue, Symbol.Kind.TYPE)?.datatype ?: UnknownDatatype } return type } open fun solveLiteral(node: AstNode): PlSqlDatatype { - var type: PlSqlDatatype = UnknownDatatype() + var type: PlSqlDatatype = UnknownDatatype if (node.hasDirectChildren(PlSqlGrammar.NULL_LITERAL) || isEmptyString(node)) { type = NullDatatype() } else if (node.hasDirectChildren(PlSqlGrammar.CHARACTER_LITERAL)) { 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 d9d07b1f..6e497df8 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 @@ -204,7 +204,7 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa } val datatype = node.getFirstChildOrNull(PlSqlKeyword.RETURN)?.nextSibling - val type = if (datatype != null) solveType(datatype) else UnknownDatatype() + val type = if (datatype != null) solveType(datatype) else UnknownDatatype val symbolKind = when(node.type) { PlSqlGrammar.CREATE_PROCEDURE -> Symbol.Kind.PROCEDURE PlSqlGrammar.PROCEDURE_DECLARATION -> Symbol.Kind.PROCEDURE @@ -243,7 +243,7 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa } enterScope(node, autonomousTransaction = false, exceptionHandler = false) } else { - val symbol = createSymbol(identifier, Symbol.Kind.PACKAGE, UnknownDatatype()) + val symbol = createSymbol(identifier, Symbol.Kind.PACKAGE, UnknownDatatype) enterScope(node, autonomousTransaction = false, exceptionHandler = false) symbol.innerScope = currentScope } @@ -251,7 +251,7 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa private fun visitCursor(node: AstNode) { val identifier = node.getFirstChild(PlSqlGrammar.IDENTIFIER_NAME) - val symbol = createSymbol(identifier, Symbol.Kind.CURSOR, UnknownDatatype()) + val symbol = createSymbol(identifier, Symbol.Kind.CURSOR, UnknownDatatype) enterScope(node) symbol.innerScope = currentScope } @@ -275,7 +275,7 @@ class SymbolVisitor(private val typeSolver: DefaultTypeSolver, private val globa control.hasDirectChildren(PlSqlGrammar.DYNAMIC_SQL)) { RowtypeDatatype() } else { - UnknownDatatype() + UnknownDatatype } for (declaration in declarations) { diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/squid/SemanticAstNode.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/squid/SemanticAstNode.kt index c6f4ca75..39da3891 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/squid/SemanticAstNode.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/squid/SemanticAstNode.kt @@ -44,7 +44,7 @@ class SemanticAstNode(type: AstNodeType, name: String, token: Token?) : AstNode( (child as SemanticAstNode).symbol = symbol } - var plSqlDatatype: PlSqlDatatype = UnknownDatatype() + var plSqlDatatype: PlSqlDatatype = UnknownDatatype get() = this.symbol?.datatype ?: field val plSqlType: PlSqlType diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/symbols/Symbol.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/symbols/Symbol.kt index 5a749df8..a8935670 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/symbols/Symbol.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/symbols/Symbol.kt @@ -50,7 +50,7 @@ open class Symbol(val node: AstNode?, val type: PlSqlType = datatype?.type ?: PlSqlType.UNKNOWN - val datatype: PlSqlDatatype = datatype ?: UnknownDatatype() + val datatype: PlSqlDatatype = datatype ?: UnknownDatatype val modifiers: List get() = Collections.unmodifiableList(internalModifiers) diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/symbols/datatype/UnknownDatatype.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/symbols/datatype/UnknownDatatype.kt index e6cc8d90..8f1f44e8 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/symbols/datatype/UnknownDatatype.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/symbols/datatype/UnknownDatatype.kt @@ -21,7 +21,7 @@ package org.sonar.plugins.plsqlopen.api.symbols.datatype import org.sonar.plugins.plsqlopen.api.symbols.PlSqlType -class UnknownDatatype : PlSqlDatatype { +object UnknownDatatype : PlSqlDatatype { override val type = PlSqlType.UNKNOWN override val name: String? = null diff --git a/zpa-core/src/test/kotlin/org/sonar/plsqlopen/symbols/SymbolTableImplTest.kt b/zpa-core/src/test/kotlin/org/sonar/plsqlopen/symbols/SymbolTableImplTest.kt index b8019568..1bff928a 100644 --- a/zpa-core/src/test/kotlin/org/sonar/plsqlopen/symbols/SymbolTableImplTest.kt +++ b/zpa-core/src/test/kotlin/org/sonar/plsqlopen/symbols/SymbolTableImplTest.kt @@ -71,7 +71,7 @@ class SymbolTableImplTest { val scope = ScopeImpl(null, newAstNodeForTest("scope"), isAutonomousTransaction = false, hasExceptionHandler = false) val symbolTable = SymbolTableImpl() - val symbol = symbolTable.declareSymbol(node, Kind.CURSOR, scope, UnknownDatatype()) + val symbol = symbolTable.declareSymbol(node, Kind.CURSOR, scope, UnknownDatatype) assertThat(symbolTable.symbols.find { it.declaration == node }).isEqualTo(symbol) assertThat(symbolTable.symbols.find { it.declaration == node2 }).isNull() @@ -84,7 +84,7 @@ class SymbolTableImplTest { val scope = ScopeImpl(null, newAstNodeForTest("scope"), isAutonomousTransaction = false, hasExceptionHandler = false) val symbolTable = SymbolTableImpl() - symbolTable.declareSymbol(node, Kind.CURSOR, scope, UnknownDatatype()) + symbolTable.declareSymbol(node, Kind.CURSOR, scope, UnknownDatatype) assertThat(symbolTable.symbols.find { it.declaration == node }?.scope).isEqualTo(scope) assertThat(symbolTable.symbols.find { it.declaration == node2 }?.scope).isNull() @@ -97,8 +97,8 @@ class SymbolTableImplTest { val node = newAstNodeForTest("foo") val symbolTable = SymbolTableImpl() - val symbol1 = symbolTable.declareSymbol(node, Kind.CURSOR, scope, UnknownDatatype()) - val symbol2 = symbolTable.declareSymbol(node, Kind.VARIABLE, scope, UnknownDatatype()) + val symbol1 = symbolTable.declareSymbol(node, Kind.CURSOR, scope, UnknownDatatype) + val symbol2 = symbolTable.declareSymbol(node, Kind.VARIABLE, scope, UnknownDatatype) assertThat(symbolTable.symbols.filter { it.kind == Kind.CURSOR }).containsExactly(symbol1) assertThat(symbolTable.symbols.filter { it.kind == Kind.VARIABLE }).containsExactly(symbol2) @@ -113,8 +113,8 @@ class SymbolTableImplTest { val node2 = newAstNodeForTest("FOO") val symbolTable = SymbolTableImpl() - val symbol1 = symbolTable.declareSymbol(node1, Kind.CURSOR, scope, UnknownDatatype()) - val symbol2 = symbolTable.declareSymbol(node2, Kind.VARIABLE, scope, UnknownDatatype()) + val symbol1 = symbolTable.declareSymbol(node1, Kind.CURSOR, scope, UnknownDatatype) + val symbol2 = symbolTable.declareSymbol(node2, Kind.VARIABLE, scope, UnknownDatatype) assertThat(symbolTable.symbols.filter { it.name.equals("foo", ignoreCase = true) }).containsExactly(symbol1, symbol2) assertThat(symbolTable.symbols.filter { it.name.equals("bar", ignoreCase = true) }).isEmpty()