Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change compiler plugin error for child node name annotation to warning #526

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "xmldata"
version = "2.6.1"
version = "2.6.2"
authors = ["Ballerina"]
keywords = ["xml", "json"]
repository = "https://github.com/ballerina-platform/module-ballerina-xmldata"
Expand All @@ -15,5 +15,5 @@ graalvmCompatible = true
[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "xmldata-native"
version = "2.6.1"
path = "../native/build/libs/xmldata-native-2.6.1-SNAPSHOT.jar"
version = "2.6.2"
path = "../native/build/libs/xmldata-native-2.6.2-SNAPSHOT.jar"
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 = "xmldata-compiler-plugin"
class = "io.ballerina.stdlib.xmldata.compiler.XmldataCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/xmldata-compiler-plugin-2.6.1-SNAPSHOT.jar"
path = "../compiler-plugin/build/libs/xmldata-compiler-plugin-2.6.2-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ modules = [
[[package]]
org = "ballerina"
name = "xmldata"
version = "2.6.1"
version = "2.6.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "test"}
Expand Down
4 changes: 0 additions & 4 deletions ballerina/tests/from_xml_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,6 @@ type Catering3 record {
}
isolated function testFromXmlWithEmpty4() {
xml allotment = xml `<Allotment3><name>some</name><Catering/></Allotment3>`;
Allotment3 output = {
name: "some",
Catering:{statusCode: ""}
};
Allotment3|error actual = fromXml(allotment, Allotment3);
if (actual is error) {
test:assertTrue(actual.message().includes("missing required field 'Catering.statusCode' of type 'string' " +
Expand Down
6 changes: 3 additions & 3 deletions ballerina/xmldata.bal
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public annotation Attribute on record field;

# Converts a `Map` or `Record` representation to its XML representation.
# Additionally, when converting from a record, the `xmldata:Namespace`, `xmldata:Name`, and `xmldata:Attribute`
# annotations can be used to add `namespaces`, `name of elements', and `attributes` to XML representation.
# annotations can be used to add `namespaces`, `name of elements`, and `attributes` to XML representation.
#
# + mapValue - The `Map` or `Record` representation source to be converted to XML
# + return - XML representation of the given source if the source is
Expand Down Expand Up @@ -391,11 +391,11 @@ returns returnType|Error = @java:Method {

# Converts an XML to its `Map` or `Record` representation.
# Additionally, when converting to a record, XML `namespaces`, `name of elements` and `attributes` can be validated
# through `xmldata:Namespace`, `xmldata:Name` and ``xmldata:Attribute` annotations.
# through `xmldata:Namespace`, `xmldata:Name` and `xmldata:Attribute` annotations.
#
# + xmlValue - The XML source to be converted to a given target type. If the XML elements have a prefix,
# the mapping field names of the record must also have the same prefix.
# + returnType - The `typedesc` of the returned value. this should be either `map` or `record` type.
# + returnType - The `typedesc` of the returned value. this should be either `map` or `record` type
# + return - The given target type representation of the given XML on success,
# else returns an `xmldata:Error`
public isolated function fromXml(xml xmlValue, typedesc<map<anydata>> returnType = <>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void testInvalidUnionType1() {
public void testInvalidChildAnnotation() {
DiagnosticResult diagnosticResult = loadPackage("sample11").getCompilation().diagnosticResult();
List<Diagnostic> errorDiagnosticsList = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR))
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.WARNING))
.collect(Collectors.toList());
Assert.assertEquals(errorDiagnosticsList.size(), 1);
Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(),
Expand All @@ -174,7 +174,7 @@ public void testInvalidChildAnnotation() {
public void testInvalidChildAnnotation1() {
DiagnosticResult diagnosticResult = loadPackage("sample12").getCompilation().diagnosticResult();
List<Diagnostic> errorDiagnosticsList = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR))
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.WARNING))
.collect(Collectors.toList());
Assert.assertEquals(errorDiagnosticsList.size(), 1);
Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// specific language governing permissions and limitations
// under the License.

import ballerina/io;
import ballerina/xmldata;

@xmldata:Name {
Expand Down Expand Up @@ -47,4 +48,6 @@ public function main() returns error? {
xml x1 = xml `<foo><bar>2</bar><car></car></foo>`;
Foo actual = check xmldata:fromXml(x1);
Bar result = check xmldata:fromXml(x1);
io:println(actual);
io:println(result);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.ballerina.tools.diagnostics.DiagnosticSeverity;

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

/**
* Enum class to hold xmldata module diagnostic codes.
Expand All @@ -31,7 +32,7 @@ public enum DiagnosticsCodes {
XMLDATA_102("XMLDATA_102",
"invalid union type: union type does not support multiple non-primitive record types", ERROR),
XMLDATA_103("XMLDATA_103",
"invalid annotation attachment: child record does not allow name annotation", ERROR);
"invalid annotation attachment: child record does not allow name annotation", WARNING);
private final String code;
private final String message;
private final DiagnosticSeverity severity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*/
public class XmldataRecordFieldValidator implements AnalysisTask<SyntaxNodeAnalysisContext> {
private final Map<String, Record> records = new HashMap<>();
private final List<String> recordNamesUsedInFunction = new ArrayList<>();
private final Map<String, Location> recordNamesUsedInFunction = new HashMap<>();
private final List<String> validatedRecords = new ArrayList<>();
private static final String TO_RECORD = "xmldata:toRecord";
private static final String FROM_XML = "xmldata:fromXml";
Expand All @@ -85,9 +85,9 @@ public void perform(SyntaxNodeAnalysisContext ctx) {
processTypeDefinitionNode((TypeDefinitionNode) member);
}
}
for (String recordName : this.recordNamesUsedInFunction) {
if (this.records.containsKey(recordName)) {
validateRecord(ctx, this.records.get(recordName));
for (Map.Entry<String, Location> entry : this.recordNamesUsedInFunction.entrySet()) {
if (this.records.containsKey(entry.getKey())) {
validateRecord(ctx, this.records.get(entry.getKey()), entry.getValue());
}
}
}
Expand Down Expand Up @@ -132,8 +132,8 @@ private boolean isValidFunctionName(ExpressionNode expressionNode) {
private void addRecordName(TypeDescriptorNode typeDescriptor) {
if (typeDescriptor.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE) {
String returnTypeName = ((SimpleNameReferenceNode) typeDescriptor).name().text().trim();
if (!this.recordNamesUsedInFunction.contains(returnTypeName)) {
this.recordNamesUsedInFunction.add(returnTypeName);
if (!this.recordNamesUsedInFunction.containsKey(returnTypeName)) {
this.recordNamesUsedInFunction.put(returnTypeName, typeDescriptor.location());
}
}
}
Expand Down Expand Up @@ -214,7 +214,7 @@ private void processUnionType(UnionTypeDescriptorNode unionTypeDescriptorNode, i
}
}

private void validateRecord(SyntaxNodeAnalysisContext ctx, Record record) {
private void validateRecord(SyntaxNodeAnalysisContext ctx, Record record, Location declarationLocation) {
this.validatedRecords.add(record.getName());
for (Location location : record.getMultipleNonPrimitiveTypeLocations()) {
reportDiagnosticInfo(ctx, location, DiagnosticsCodes.XMLDATA_102);
Expand All @@ -225,9 +225,9 @@ private void validateRecord(SyntaxNodeAnalysisContext ctx, Record record) {
for (String childRecordName : record.getChildRecordNames()) {
if (!this.validatedRecords.contains(childRecordName)) {
Record childRecord = this.records.get(childRecordName);
validateRecord(ctx, childRecord);
if (childRecord.hasNameAnnotation() && !recordNamesUsedInFunction.contains(childRecordName.trim())) {
reportDiagnosticInfo(ctx, childRecord.getLocation(), DiagnosticsCodes.XMLDATA_103);
validateRecord(ctx, childRecord, declarationLocation);
if (childRecord.hasNameAnnotation() && !recordNamesUsedInFunction.containsKey(childRecordName.trim())) {
reportDiagnosticInfo(ctx, declarationLocation, DiagnosticsCodes.XMLDATA_103);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.caching=true
group=io.ballerina.stdlib
version=2.6.1-SNAPSHOT
version=2.6.2-SNAPSHOT
ballerinaLangVersion= 2201.7.0

checkstyleToolVersion=7.8.2
Expand Down
Loading