Skip to content

Commit

Permalink
Merge pull request #491 from niveathika/update4
Browse files Browse the repository at this point in the history
Remove POSTGRESDB_901 diagnostic hint
  • Loading branch information
niveathika authored Nov 4, 2022
2 parents bc47ff9 + 8260b5a commit 0c6566f
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 265 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- 2201.[0-9]+.x
- update4

jobs:
ubuntu-build:
Expand Down
12 changes: 6 additions & 6 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[package]
org = "ballerinax"
name = "postgresql"
version = "1.6.0"
version = "1.7.0"
authors = ["Ballerina"]
keywords = ["database", "client", "network", "SQL", "RDBMS", "PostgreSQL"]
repository = "https://github.com/ballerina-platform/module-ballerinax-postgresql"
icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.3.0"
distribution = "2201.4.0"

[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "postgresql-native"
version = "1.6.0"
path = "../native/build/libs/postgresql-native-1.6.0-SNAPSHOT.jar"
version = "1.7.0"
path = "../native/build/libs/postgresql-native-1.7.0-SNAPSHOT.jar"

[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "sql-native"
version = "1.6.0"
path = "./lib/sql-native-1.6.0-20221014-221200-0061889.jar"
version = "1.7.0"
path = "./lib/sql-native-1.7.0-20221104-172000-addd057.jar"

[[platform.java11.dependency]]
path = "./lib/postgresql-42.4.1.jar"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "postgresql-compiler-plugin"
class = "io.ballerina.stdlib.postgresql.compiler.PostgreSQLCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/postgresql-compiler-plugin-1.6.0-SNAPSHOT.jar"
path = "../compiler-plugin/build/libs/postgresql-compiler-plugin-1.7.0-SNAPSHOT.jar"
4 changes: 2 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "sql"
version = "1.6.0"
version = "1.7.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -183,7 +183,7 @@ modules = [
[[package]]
org = "ballerinax"
name = "postgresql"
version = "1.6.0"
version = "1.7.0"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "file"},
Expand Down
2 changes: 1 addition & 1 deletion build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["database", "client", "network", "SQL", "RDBMS", "PostgreSQL"]
repository = "https://github.com/ballerina-platform/module-ballerinax-postgresql"
icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.3.0"
distribution = "2201.4.0"

[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

### Changed
- [Remove SQL_901 diagnostic hint](https://github.com/ballerina-platform/ballerina-standard-library/issues/3609)

## [1.6.0]

### Changed
- [Updated API Docs](https://github.com/ballerina-platform/ballerina-standard-library/issues/3463)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import static io.ballerina.stdlib.postgresql.compiler.PostgreSQLDiagnosticsCode.POSTGRESQL_202;
import static io.ballerina.stdlib.postgresql.compiler.PostgreSQLDiagnosticsCode.POSTGRESQL_203;
import static io.ballerina.stdlib.postgresql.compiler.PostgreSQLDiagnosticsCode.POSTGRESQL_204;
import static io.ballerina.stdlib.postgresql.compiler.PostgreSQLDiagnosticsCode.POSTGRESQL_903;
import static io.ballerina.stdlib.postgresql.compiler.PostgreSQLDiagnosticsCode.SQL_101;

/**
Expand All @@ -66,34 +65,6 @@ private Package loadPackage(String path) {
return project.currentPackage();
}

@Test
public void testFunctionHints() {
Package currentPackage = loadPackage("sample1");
PackageCompilation compilation = currentPackage.getCompilation();
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
long availableErrors = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)).count();
Assert.assertEquals(availableErrors, 3);

List<Diagnostic> diagnosticHints = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.HINT))
.collect(Collectors.toList());
long availableHints = diagnosticHints.size();
Assert.assertEquals(availableHints, 3);

DiagnosticInfo hint1 = diagnosticHints.get(0).diagnosticInfo();
Assert.assertEquals(hint1.code(), PostgreSQLDiagnosticsCode.POSTGRESQL_901.getCode());
Assert.assertEquals(hint1.messageFormat(), PostgreSQLDiagnosticsCode.POSTGRESQL_901.getMessage());

DiagnosticInfo hint2 = diagnosticHints.get(1).diagnosticInfo();
Assert.assertEquals(hint2.code(), PostgreSQLDiagnosticsCode.POSTGRESQL_902.getCode());
Assert.assertEquals(hint2.messageFormat(), PostgreSQLDiagnosticsCode.POSTGRESQL_902.getMessage());

DiagnosticInfo hint3 = diagnosticHints.get(2).diagnosticInfo();
Assert.assertEquals(hint3.code(), PostgreSQLDiagnosticsCode.POSTGRESQL_901.getCode());
Assert.assertEquals(hint3.messageFormat(), PostgreSQLDiagnosticsCode.POSTGRESQL_901.getMessage());
}

@Test
public void testSQLConnectionPoolFieldsInNewExpression() {
Package currentPackage = loadPackage("sample2");
Expand Down Expand Up @@ -179,32 +150,6 @@ public void testOutParameterValidations() {
Assert.assertEquals(diagnostic.messageFormat(), POSTGRESQL_204.getMessage());
}

@Test
public void testOutParameterHint() {
Package currentPackage = loadPackage("sample5");
PackageCompilation compilation = currentPackage.getCompilation();
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
List<Diagnostic> errorDiagnosticsList = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR))
.collect(Collectors.toList());
long availableErrors = errorDiagnosticsList.size();

Assert.assertEquals(availableErrors, 1);

List<Diagnostic> hintDiagnosticsList = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.HINT))
.collect(Collectors.toList());
long availableHints = hintDiagnosticsList.size();

Assert.assertEquals(availableHints, 1);

hintDiagnosticsList.forEach(diagnostic -> {
Assert.assertEquals(diagnostic.diagnosticInfo().code(), POSTGRESQL_903.getCode());
Assert.assertEquals(diagnostic.diagnosticInfo().messageFormat(), POSTGRESQL_903.getMessage());
});

}

@Test
public void testOptionsWithVariables() {
Package currentPackage = loadPackage("sample6");
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.ballerina.stdlib.postgresql.compiler.analyzer.InitializerParamAnalyzer;
import io.ballerina.stdlib.postgresql.compiler.analyzer.MethodAnalyzer;
import io.ballerina.stdlib.postgresql.compiler.analyzer.RecordAnalyzer;
import io.ballerina.stdlib.postgresql.compiler.analyzer.RemoteMethodAnalyzer;

import java.util.List;

Expand All @@ -35,7 +34,6 @@ public class PostgreSQLCodeAnalyzer extends CodeAnalyzer {

@Override
public void init(CodeAnalysisContext ctx) {
ctx.addSyntaxNodeAnalysisTask(new RemoteMethodAnalyzer(), SyntaxKind.REMOTE_METHOD_CALL_ACTION);
ctx.addSyntaxNodeAnalysisTask(new InitializerParamAnalyzer(),
List.of(SyntaxKind.IMPLICIT_NEW_EXPRESSION, SyntaxKind.EXPLICIT_NEW_EXPRESSION));
ctx.addSyntaxNodeAnalysisTask(new RecordAnalyzer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.ballerina.tools.diagnostics.DiagnosticSeverity;

import static io.ballerina.tools.diagnostics.DiagnosticSeverity.ERROR;
import static io.ballerina.tools.diagnostics.DiagnosticSeverity.HINT;

/**
* Enum class to hold JDBC module diagnostic codes.
Expand All @@ -40,14 +39,7 @@ public enum PostgreSQLDiagnosticsCode {
POSTGRESQL_201("POSTGRESQL_201", "invalid value: expected value is string", ERROR),
POSTGRESQL_202("POSTGRESQL_202", "invalid value: expected value is either record or string", ERROR),
POSTGRESQL_203("POSTGRESQL_203", "invalid value: expected value is either json or string", ERROR),
POSTGRESQL_204("POSTGRESQL_204", "invalid value: expected value is either xml or string", ERROR),

POSTGRESQL_901("POSTGRESQL_901",
"parameter 'rowType' should be explicitly passed when the return data is ignored", HINT),
POSTGRESQL_902("POSTGRESQL_902",
"parameter 'returnType' should be explicitly passed when the return data is ignored", HINT),
POSTGRESQL_903("POSTGRESQL_903",
"parameter 'typeDesc' should be explicitly passed when the return data is ignored", HINT);
POSTGRESQL_204("POSTGRESQL_204", "invalid value: expected value is either xml or string", ERROR);


private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
import java.util.List;
import java.util.Optional;

import static io.ballerina.stdlib.postgresql.compiler.PostgreSQLDiagnosticsCode.POSTGRESQL_903;
import static org.ballerinalang.util.diagnostic.DiagnosticErrorCode.CANNOT_INFER_TYPE_FOR_PARAM;
import static org.ballerinalang.util.diagnostic.DiagnosticErrorCode.INCOMPATIBLE_TYPE_FOR_INFERRED_TYPEDESC_VALUE;

/**
* Code Analyser for OutParameter get method type validations.
*/
Expand All @@ -51,15 +47,10 @@ public class MethodAnalyzer implements AnalysisTask<SyntaxNodeAnalysisContext> {
public void perform(SyntaxNodeAnalysisContext ctx) {
MethodCallExpressionNode node = (MethodCallExpressionNode) ctx.node();
List<Diagnostic> diagnostics = ctx.semanticModel().diagnostics();
if (!diagnostics.isEmpty()) {
diagnostics.stream()
.filter(diagnostic -> diagnostic.diagnosticInfo().severity() == DiagnosticSeverity.ERROR)
.filter(diagnostic ->
diagnostic.diagnosticInfo().code().equals(CANNOT_INFER_TYPE_FOR_PARAM.diagnosticId()) ||
diagnostic.diagnosticInfo().code().equals(
INCOMPATIBLE_TYPE_FOR_INFERRED_TYPEDESC_VALUE.diagnosticId()))
.filter(diagnostic -> diagnostic.location().lineRange().equals(node.location().lineRange()))
.forEach(diagnostic -> addHint(ctx, node));
for (Diagnostic diagnostic : diagnostics) {
if (diagnostic.diagnosticInfo().severity() == DiagnosticSeverity.ERROR) {
return;
}
}

// Get the object type to validate arguments
Expand Down Expand Up @@ -113,29 +104,4 @@ public void perform(SyntaxNodeAnalysisContext ctx) {
node.arguments().get(0).location()));
}
}


private void addHint(SyntaxNodeAnalysisContext ctx, MethodCallExpressionNode node) {
if (!(Utils.isPostgreSQLObject(ctx, node.expression(), Constants.OUT_PARAMETER_POSTFIX))) {
return;
}
if (isGetMethod(ctx, node)) {
return;
}
ctx.reportDiagnostic(DiagnosticFactory.createDiagnostic(
new DiagnosticInfo(POSTGRESQL_903.getCode(), POSTGRESQL_903.getMessage(), POSTGRESQL_903.getSeverity()),
node.location()));
}

private boolean isGetMethod(SyntaxNodeAnalysisContext ctx, MethodCallExpressionNode node) {
Optional<Symbol> methodSymbol = ctx.semanticModel().symbol(node.methodName());
if (methodSymbol.isEmpty()) {
return true;
}
Optional<String> methodName = methodSymbol.get().getName();
if (methodName.isEmpty()) {
return true;
}
return !methodName.get().equals(Constants.OutParameter.METHOD_NAME);
}
}
Loading

0 comments on commit 0c6566f

Please sign in to comment.