Skip to content

Commit

Permalink
Remove compiler validation logic for annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
hasathcharu committed Mar 11, 2024
1 parent 1e6a5c6 commit 70f3beb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 481 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,30 +418,30 @@ public void validateNillableRelationField() {
testDiagnostic(
diagnostics,
new String[]{
PERSIST_406.getCode(),
PERSIST_406.getCode(),
PERSIST_404.getCode(),
PERSIST_404.getCode(),
PERSIST_405.getCode(),
PERSIST_405.getCode(),
PERSIST_406.getCode()
PERSIST_405.getCode()
},
new String[]{
"1-n relationship does not support nillable relation field",
"1-n relationship does not support nillable relation field",
"1-1 relationship should have at least one relation field nillable " +
"to indicate non-owner of the relationship",
"1-1 relationship should have at least one relation field nillable " +
"to indicate non-owner of the relationship",
"1-1 relationship should have only one nillable relation field",
"1-1 relationship should have only one nillable relation field",
"1-n relationship does not support nillable relation field"
"1-1 relationship should have only one nillable relation field"
},
new String[]{
"(14:4,14:23)",
"(29:4,29:29)",
"(44:4,44:23)",
"(38:4,38:26)",
"(59:4,59:27)",
"(50:4,50:24)",
"(14:4,14:23)"
"(50:4,50:24)"
}
);
}
Expand Down Expand Up @@ -478,16 +478,16 @@ public void validateMandatoryRelationField() {
PERSIST_402.getCode()
},
new String[]{
"the related entity 'Workspace4' does not have the corresponding relation field",
"the related entity 'Building3' does not have the corresponding relation field",
"the related entity 'Workspace' does not have the corresponding relation field",
"the related entity 'Building1' does not have the corresponding relation field",
"the related entity 'Workspace' does not have the corresponding relation field"
"the related entity 'Building3' does not have the corresponding relation field",
"the related entity 'Workspace4' does not have the corresponding relation field"
},
new String[]{
"(68:4,68:27)",
"(58:4,58:24)",
"(8:4,8:27)",
"(27:4,27:23)",
"(8:4,8:27)"
"(58:4,58:24)",
"(68:4,68:27)"
}
);
}
Expand All @@ -506,20 +506,20 @@ public void validateMandatoryMultipleRelationField() {
PERSIST_402.getCode()
},
new String[]{
"the related entity 'Workspace4' does not have the corresponding relation field",
"the related entity 'Building3' does not have the corresponding relation field",
"the related entity 'Building1' does not have the corresponding relation field",
"the related entity 'Building1' does not have the corresponding relation field",
"the related entity 'Workspace' does not have the corresponding relation field",
"the related entity 'Workspace' does not have the corresponding relation field",
"the related entity 'Building1' does not have the corresponding relation field",
"the related entity 'Building1' does not have the corresponding relation field",
"the related entity 'Building3' does not have the corresponding relation field",
"the related entity 'Workspace4' does not have the corresponding relation field"
},
new String[]{
"(75:4,75:28)",
"(64:4,64:27)",
"(8:4,8:27)",
"(9:4,9:24)",
"(28:4,28:23)",
"(29:4,29:23)",
"(8:4,8:27)",
"(9:4,9:24)"
"(64:4,64:27)",
"(75:4,75:28)"
}
);
}
Expand All @@ -536,21 +536,20 @@ public void validatePresenceOfForeignKeyField() {
PERSIST_422.getCode()
},
new String[]{
"the entity should not contain foreign key field 'locationBuildingCode' for relation " +
"'Building2'",
"the entity should not contain foreign key field 'workspacesWorkspaceId' for relation " +
"'Workspace3'",
"the entity should not contain foreign key field 'workspacesWorkspaceId' for relation " +
"'Workspace4'",
"the entity should not contain foreign key field 'buildingBuildingCode' for relation " +
"'Building'",
"the entity should not contain foreign key field " +
"'buildingBuildingCode' for relation 'Building'",
"the entity should not contain foreign key field " +
"'locationBuildingCode' for relation 'Building2'",
"the entity should not contain foreign key field " +
"'workspacesWorkspaceId' for relation 'Workspace3'",
"the entity should not contain foreign key field " +
"'workspacesWorkspaceId' for relation 'Workspace4'"
},
new String[]{
"(15:4,15:32)",
"(22:4,22:32)",
"(42:4,42:33)",
"(66:4,66:33)",
"(15:4,15:32)"

"(66:4,66:33)"
}
);
}
Expand Down Expand Up @@ -605,16 +604,16 @@ public void validateDifferentOwners() {
"All relation between two entities should have a single owner"
},
new String[]{
"(15:4,15:22)",
"(8:4,8:27)",
"(16:4,16:23)",
"(9:4,9:24)",
"(33:4,33:23)",
"(25:4,25:27)",
"(34:4,34:25)",
"(26:4,26:25)",
"(35:4,35:24)",
"(27:4,27:28)",
"(15:4,15:22)",
"(8:4,8:27)",
"(16:4,16:23)",
"(9:4,9:24)",
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,8 @@ public final class Constants {
public static final String EMPTY_STRING = "";
public static final String ARRAY = "[]";
public static final String LS = System.lineSeparator();
public static final String SQL_DB_MAPPING_ANNOTATION_NAME = "sql:Mapping";
public static final String SQL_VARCHAR_MAPPING_ANNOTATION_NAME = "sql:VarChar";
public static final String SQL_CHAR_MAPPING_ANNOTATION_NAME = "sql:Char";
public static final String SQL_DECIMAL_MAPPING_ANNOTATION_NAME = "sql:Decimal";
public static final String SQL_RELATION_MAPPING_ANNOTATION_NAME = "sql:Relation";
public static final String SQL_INDEX_MAPPING_ANNOTATION_NAME = "sql:Index";
public static final String SQL_UNIQUE_INDEX_MAPPING_ANNOTATION_NAME = "sql:UniqueIndex";
public static final String SQL_GENERATED_ANNOTATION_NAME = "sql:Generated";
public static final String ANNOTATION_NAME_FIELD = "name";
public static final String ANNOTATION_NAMES_FIELD = "names";
public static final String ANNOTATION_PRECISION_FIELD = "precision";
public static final String ANNOTATION_REFS_FIELD = "refs";
public static final String ANNOTATION_LENGTH_FIELD = "length";

private Constants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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

/**
* Persist related diagnostic codes.
Expand Down Expand Up @@ -70,77 +69,10 @@ public enum DiagnosticsCodes {
PERSIST_422("PERSIST_422",
"the entity should not contain foreign key field ''{0}'' for relation ''{1}''",
ERROR),
PERSIST_423("PERSIST_423", "invalid use of the `Relation` annotation. " +
"mismatched number of reference keys for relation ''{0}'' in entity ''{1}''." +
" expected {2} but found {3}.",
ERROR),
PERSIST_424("PERSIST_424", "invalid use of the `Relation` annotation. " +
"mismatched key types for the related entity ''{0}''.",
ERROR),
PERSIST_426("PERSIST_426", "invalid use of the `Relation` annotation. " +
"the field ''{0}'' is an array type in a 1-n relationship. " +
"therefore, it cannot have foreign keys.",
ERROR),
PERSIST_427("PERSIST_427", "invalid use of the `Relation` annotation. " +
"the field ''{0}'' is an optional type in a 1-1 relationship. " +
"therefore, it cannot have foreign keys.",
ERROR),
PERSIST_428("PERSIST_428", "invalid use of the `Relation` annotation. " +
"the field ''{0}'' is not found in the entity ''{1}''.",
ERROR),
PERSIST_429("PERSIST_429", "invalid use of the `Relation` annotation. " +
"refs cannot contain duplicates.",
ERROR),
PERSIST_430("PERSIST_430", "invalid use of the `Relation` annotation. " +
"duplicated reference field.",
ERROR),

PERSIST_501("PERSIST_501", "''{0}'' entity must have at least one identity readonly field", ERROR),
PERSIST_502("PERSIST_502", "an identity field cannot be nillable", ERROR),
PERSIST_503("PERSIST_503", "only ''int'', ''string'', ''float'', ''boolean'', ''decimal'' " +
"types are supported as identity fields, found ''{0}''", ERROR),
PERSIST_600("PERSIST_600", "invalid use of the `Mapping` annotation. mapping name cannot be empty.",
ERROR),
PERSIST_601("PERSIST_601", "redundant use of the `Mapping` annotation. mapping name is same as " +
"model definition.", WARNING),
PERSIST_602("PERSIST_602", "invalid use of the `Mapping` annotation. " +
"the `Mapping` annotation cannot be used for relation fields.", ERROR),
PERSIST_604("PERSIST_604", "invalid use of the `''{0}''` annotation. " +
"the `''{0}''` annotation can only be used for ''string'' type.", ERROR),
PERSIST_605("PERSIST_605", "invalid use of `VarChar` and `Char` annotations. " +
"only one of either `VarChar` or `Char` annotations can be used at a time.", ERROR),
PERSIST_606("PERSIST_606", "invalid use of the `Decimal` annotation. " +
"the `Decimal` annotation can only be used for ''decimal'' data type.", ERROR),
PERSIST_607("PERSIST_607", "invalid use of the `''{0}''` annotation. " +
"length cannot be 0.", ERROR),
PERSIST_608("PERSIST_608", "invalid use of the `Decimal` annotation. " +
"precision cannot be 0.", ERROR),
PERSIST_609("PERSIST_609", "invalid use of the `Decimal` annotation. " +
"precision cannot be less than scale.", ERROR),
PERSIST_610("PERSIST_610", "invalid use of the `Mapping` annotation. " +
"duplicate mapping name found.", ERROR),
PERSIST_611("PERSIST_611", "invalid use of the `Index` annotation. " +
"the `Index` annotation cannot be used for relation fields.", ERROR),
PERSIST_612("PERSIST_612", "invalid use of the `UniqueIndex` annotation. " +
"the `UniqueIndex` annotation cannot be used for relation fields.", ERROR),
PERSIST_613("PERSIST_613", "invalid use of the `Index` annotation. " +
"duplicate index names.", ERROR),
PERSIST_614("PERSIST_614", "invalid use of the `UniqueIndex` annotation. " +
"duplicate index names.", ERROR),
PERSIST_615("PERSIST_615", "invalid use of the `Index` annotation. " +
"there cannot be empty index names.", ERROR),
PERSIST_616("PERSIST_616", "invalid use of the `UniqueIndex` annotation. " +
"there cannot be empty index names.", ERROR),
PERSIST_617("PERSIST_617", "invalid use of the `Generated` annotation. " +
"the `Generated` annotation can only be used for ''readonly'' fields.", ERROR),
PERSIST_618("PERSIST_618", "invalid use of the `Generated` annotation. " +
"partial key fields cannot be auto-generated.", ERROR),
PERSIST_619("PERSIST_619", "invalid use of the `Generated` annotation. " +
"a generated field can only be an ''int'' type.", ERROR),
PERSIST_620("PERSIST_620", "invalid use of the `Mapping` annotation. " +
"a mapping name should not conflict with an Entity name", ERROR),
PERSIST_621("PERSIST_621", "invalid use of the `Mapping` annotation. " +
"a mapping name should not conflict with a field name", ERROR),
;

private final String code;
Expand Down
Loading

0 comments on commit 70f3beb

Please sign in to comment.