Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
prakanth97 committed Jul 14, 2023
2 parents 5c09a46 + 4e224cd commit 24d343b
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private BLangConstantValue evaluateUnaryOperator(BLangConstantValue value, Opera
try {
switch (kind) {
case ADD:
return new BLangConstantValue(value.value, currentConstSymbol.type);
return new BLangConstantValue(value.value, value.type);
case SUB:
return calculateNegation(value);
case BITWISE_COMPLEMENT:
Expand Down Expand Up @@ -573,6 +573,7 @@ BLangConstantValue constructBLangConstantValueWithExactType(BLangExpression expr
BConstantSymbol constantSymbol, SymbolEnv env,
Stack<String> anonTypeNameSuffixes,
boolean isSourceOnlyAnon) {
this.currentConstSymbol = constantSymbol;
BLangConstantValue value = constructBLangConstantValue(expression);
constantSymbol.value = value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,14 @@ protected JsonElement transformSyntaxNode(Node node) {

nodeJson.add("typeData", symbolJson);

if ((node.kind() == SyntaxKind.BLOCK_STATEMENT || node.kind() == SyntaxKind.FUNCTION_BODY_BLOCK ||
node.kind() == SyntaxKind.SERVICE_DECLARATION) && (this.visibleEpsForEachBlock.size() > 0 ||
this.visibleEpsForModule.size() > 0)) {
boolean isBlockNode = node.kind() == SyntaxKind.BLOCK_STATEMENT
|| node.kind() == SyntaxKind.FUNCTION_BODY_BLOCK
|| node.kind() == SyntaxKind.SERVICE_DECLARATION;
boolean hasVisibleEps = this.visibleEpsForEachBlock.size() > 0
|| this.visibleEpsForClass.size() > 0
|| this.visibleEpsForModule.size() > 0;

if (isBlockNode && hasVisibleEps) {

JsonArray blockEndpoints = new JsonArray();
// Add module level endpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class SyntaxTreeGenTest {
private final Path externalClientInitOnly = TestUtil.RES_DIR.resolve("externalClientInitOnly");
private final Path multiLevelEndpoints = TestUtil.RES_DIR.resolve("multiLevelEndpoints");
private final Path endpointOrder = TestUtil.RES_DIR.resolve("endpointOrder");
private final Path classEndpoint = TestUtil.RES_DIR.resolve("classEndpoint");

@Test(description = "Generate ST for empty bal file.")
public void testEmptyBalST() throws IOException {
Expand Down Expand Up @@ -689,6 +690,42 @@ public void testVisibleEndpointOrder() throws IOException {
"http", "http", "2.8.0", 74, 74, false, true, true, false);
}

@Test(description = "Test visible endpoint defined in Class/Service level")
public void testClassLevelVisibleEndpoint() throws IOException {
Path inputFile = TestUtil.createTempProject(classEndpoint);

BuildProject project = BuildProject.load(inputFile);
Optional<ModuleId> optionalModuleId = project.currentPackage().moduleIds().stream().findFirst();
if (optionalModuleId.isEmpty()) {
Assert.fail("Failed to retrieve the module ID");
}
ModuleId moduleId = optionalModuleId.get();
Module module = project.currentPackage().module(moduleId);
PackageCompilation packageCompilation = project.currentPackage().getCompilation();
SemanticModel semanticModel = packageCompilation.getSemanticModel(moduleId);
Optional<DocumentId> optionalDocumentId = module.documentIds().stream()
.filter(documentId -> module.document(documentId).name().equals("main.bal")).findFirst();
if (optionalDocumentId.isEmpty()) {
Assert.fail("Failed to retrieve the document ID");
}
DocumentId documentId = optionalDocumentId.get();
Document document = module.document(documentId);
JsonElement stJson = DiagramUtil.getSyntaxTreeJSON(document, semanticModel);
Assert.assertTrue(stJson.isJsonObject());

Assert.assertEquals(stJson.getAsJsonObject().get("kind").getAsString(), "ModulePart");
JsonArray members = stJson.getAsJsonObject().get("members").getAsJsonArray();

// Verify user service
JsonObject userService = members.get(0).getAsJsonObject();
JsonObject userPostFunction = userService.get("members").getAsJsonArray().get(2).getAsJsonObject();
JsonArray userPostFunctionVEp = userPostFunction.get("functionBody").getAsJsonObject().get("VisibleEndpoints")
.getAsJsonArray();
Assert.assertEquals(userPostFunctionVEp.size(), 1);
checkClientVisibleEndpoints(userPostFunctionVEp.get(0).getAsJsonObject(), "httpEpS10", "Client", "ballerina",
"http", "http", "2.8.0", 4, 4, false, true, true, false);
}

private void checkClientVisibleEndpoints(JsonObject ep, String varName, String typeName, String orgName,
String packageName, String moduleName, String version, int startLine,
int endLine, boolean isModuleVar, boolean isExternal, boolean isClassField,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "gayanOrg"
name = "EndpintOrder"
version = "0.1.0"
15 changes: 15 additions & 0 deletions misc/diagram-util/src/test/resources/classEndpoint/main.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ballerina/http;

service /user on new http:Listener(9090) {

http:Client httpEpS10;

function init() returns error? {
self.httpEpS10 = check new (url = "");
}

resource function post .() returns error? {

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AnnotationAttachmentNegativeTest {
@BeforeClass
public void setup() {
compileResult = BCompileUtil.compile("test-src/annotations/annot_attachments_negative.bal");
Assert.assertEquals(compileResult.getErrorCount(), 272);
Assert.assertEquals(compileResult.getErrorCount(), 277);
}

@Test
Expand Down Expand Up @@ -507,4 +507,15 @@ public void testInvalidAttachmentsOnEnum() {
validateError(compileResult, index++, "annotation 'v23' is not allowed on type", line += 7, 1);
validateError(compileResult, index, "annotation 'v22' is not allowed on const", line + 2, 5);
}

@Test
public void testInvalidConstAnnotElements() {
int index = 272;
int line = 943;
validateError(compileResult, index++, "expression is not a constant expression", line, 16);
validateError(compileResult, index++, "expression is not a constant expression", line += 7, 17);
validateError(compileResult, index++, "expression is not a constant expression", line += 7, 16);
validateError(compileResult, index++, "expression is not a constant expression", line += 9, 16);
validateError(compileResult, index, "expression is not a constant expression", line + 7, 16);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,30 @@ public void testNonSourceAnnotsWithConstLists() {
Assert.assertEquals(arrList.get(1).value, 2L);
}

@Test
public void testConstAnnots() {
List<? extends AnnotationAttachmentSymbol> attachmentsF1 =
((BTypeDefinitionSymbol) getTypeDefinition(compileResult.getAST().getTypeDefinitions(), "F1").symbol)
.getAnnotations();
Assert.assertEquals(attachmentsF1.size(), 1);
assertAttachmentSymbol(attachmentsF1.get(0), "v29", true, "increment", 2L);
List<? extends AnnotationAttachmentSymbol> attachmentsF2 =
((BTypeDefinitionSymbol) getTypeDefinition(compileResult.getAST().getTypeDefinitions(), "F2").symbol)
.getAnnotations();
Assert.assertEquals(attachmentsF2.size(), 1);
assertAttachmentSymbol(attachmentsF2.get(0), "v29", true, "increment", 1L);
List<? extends AnnotationAttachmentSymbol> attachmentsF3 =
((BTypeDefinitionSymbol) getTypeDefinition(compileResult.getAST().getTypeDefinitions(), "F3").symbol)
.getAnnotations();
Assert.assertEquals(attachmentsF3.size(), 1);
assertAttachmentSymbol(attachmentsF3.get(0), "v29", true, "increment", -1L);
List<? extends AnnotationAttachmentSymbol> attachmentsF4 =
((BTypeDefinitionSymbol) getTypeDefinition(compileResult.getAST().getTypeDefinitions(), "F4").symbol)
.getAnnotations();
Assert.assertEquals(attachmentsF4.size(), 1);
assertAttachmentSymbol(attachmentsF4.get(0), "v29", true, "increment", -2L);
}

private BLangTypeDefinition getTypeDefinition(List<? extends TypeDefinition> typeDefinitions, String name) {
for (TypeDefinition typeDefinition : typeDefinitions) {
BLangTypeDefinition bLangTypeDefinition = (BLangTypeDefinition) typeDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,33 @@ public const annotation record {| int increment = 1; |} v29 on source type;
type Qux record {|
int x;
|};

const int x = 1;

@v29 {
increment: +2
}
type F1 record {|
int x;
|};

@v29 {
increment: +x
}
type F2 record {|
int x;
|};

@v29 {
increment: -x
}
type F3 record {|
int x;
|};

@v29 {
increment: -2
}
type F4 record {|
int x;
|};
Original file line number Diff line number Diff line change
Expand Up @@ -934,3 +934,44 @@ public enum Color5 {
ORANGE,
GREEN
}

public const annotation record {| int increment; |} v25 on source type;

int x = 1;

@v25 {
increment: x + 1
}
type F1 record {|
int x;
|};

@v25 {
increment: -x
}
type F2 record {|
int x;
|};

@v25 {
increment: 1 + 2
}
type F3 record {|
int x;
|};

const int y = 3;

@v25 {
increment: y + 1
}
type F4 record {|
int x;
|};

@v25 {
increment: y + x
}
type F5 record {|
int x;
|};

0 comments on commit 24d343b

Please sign in to comment.