Skip to content

Commit

Permalink
Address review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Mar 19, 2024
1 parent 49d586f commit 4fdfe79
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class ParserConstants {
/**
* Checks if the given function name is restricted.
*
* @param functionName Function name to check.
* @return True if the function name is restricted.
* @param functionName function name to check
* @return <code>true</code> if the function name is restricted. <code>false</code> otherwise
*/
public static boolean isFunctionNameRestricted(String functionName) {
return RESTRICTED_FUNCTION_NAMES.contains(functionName) || functionName.startsWith(WRAPPER_PREFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,22 @@ public List<VariableDeclarationSnippet> createVariableDeclarationSnippets(Node n

// Check if the type descriptor of the variable is 'var' as it is not yet supported.
if (typeDescriptorNode.kind() == SyntaxKind.VAR_TYPE_DESC) {
addErrorDiagnostic("Actions not allowed with a 'var' TypeDescriptor");
addErrorDiagnostic("'var' type is not yet supported for actions. Please specify the exact type.");
return null;
}

boolean hasCheck = nodeKind == SyntaxKind.CHECK_ACTION;
String functionBody = varInitNode.toSourceCode();
String functionDefinition = (hasCheck ? "function() returns error|" :
boolean isCheckAction = nodeKind == SyntaxKind.CHECK_ACTION;
String initAction = varInitNode.toSourceCode();
String functionTypeDesc = (isCheckAction ? "function() returns error|" :
"function() returns ") + typeDescriptorNode;
String functionName = ParserConstants.WRAPPER_PREFIX + varFunctionCount;
String functionString = String.format("%s %s = %s {%s %s = %s; return %s;};", functionDefinition,
functionName, functionDefinition, typeDescriptorNode, bindingPatternNode, functionBody,
String functionVarDecl = String.format("%s %s = %s {%s %s = %s; return %s;};", functionTypeDesc,
functionName, functionTypeDesc, typeDescriptorNode, bindingPatternNode, initAction,
bindingPatternNode);
varNode = (VariableDeclarationNode) NodeParser.parseStatement(functionString);
varNode = (VariableDeclarationNode) NodeParser.parseStatement(functionVarDecl);
newNode = (VariableDeclarationNode) NodeParser.parseStatement(
String.format("%s %s = %s %s();", typeDescriptorNode, bindingPatternNode,
(hasCheck ? "check " : ""), functionName));
(isCheckAction ? "check " : ""), functionName));
}

varFunctionCount += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void testEvaluate(String fileName) throws BallerinaShellException {
ShellCompilation shellCompilation = evaluator.getCompilation(testCase.getCode());
Optional<PackageCompilation> compilation = shellCompilation.getPackageCompilation();

if (compilation.isEmpty() && testCase.getStderr().size() > 0) {
if (compilation.isEmpty() && !testCase.getStderr().isEmpty()) {
for (int i = 0; i < testCase.getStderr().size(); i++) {
Assert.assertEquals(evaluator.diagnostics().get(i).toString(), testCase.getStderr().get(i));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://wso2.com) All Rights Reserved.
* Copyright (c) 2024, WSO2 LLC. (http://wso2.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 4fdfe79

Please sign in to comment.