diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddPrivateQualifierCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddPrivateQualifierCodeAction.java new file mode 100644 index 000000000000..e56ac4064b68 --- /dev/null +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/AddPrivateQualifierCodeAction.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.langserver.codeaction.providers; + +import io.ballerina.compiler.syntax.tree.Node; +import io.ballerina.compiler.syntax.tree.NodeList; +import io.ballerina.compiler.syntax.tree.ObjectFieldNode; +import io.ballerina.compiler.syntax.tree.SyntaxKind; +import io.ballerina.compiler.syntax.tree.Token; +import io.ballerina.tools.diagnostics.Diagnostic; +import org.ballerinalang.annotation.JavaSPIService; +import org.ballerinalang.langserver.codeaction.CodeActionNodeValidator; +import org.ballerinalang.langserver.codeaction.CodeActionUtil; +import org.ballerinalang.langserver.common.constants.CommandConstants; +import org.ballerinalang.langserver.common.utils.PositionUtil; +import org.ballerinalang.langserver.commons.CodeActionContext; +import org.ballerinalang.langserver.commons.codeaction.spi.DiagBasedPositionDetails; +import org.ballerinalang.langserver.commons.codeaction.spi.DiagnosticBasedCodeActionProvider; +import org.eclipse.lsp4j.CodeAction; +import org.eclipse.lsp4j.CodeActionKind; +import org.eclipse.lsp4j.Position; +import org.eclipse.lsp4j.Range; +import org.eclipse.lsp4j.TextEdit; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +/** + * Code Action for adding the private visibility qualifier ƒor an object field. + * + * @since 2201.9.0 + */ +@JavaSPIService("org.ballerinalang.langserver.commons.codeaction.spi.LSCodeActionProvider") +public class AddPrivateQualifierCodeAction implements DiagnosticBasedCodeActionProvider { + + private static final String NAME = "Add private visibility qualifier"; + private static final String DIAGNOSTIC_CODE = "BCE3956"; + + @Override + public boolean validate(Diagnostic diagnostic, DiagBasedPositionDetails positionDetails, + CodeActionContext context) { + return DIAGNOSTIC_CODE.equals(diagnostic.diagnosticInfo().code()) + && CodeActionNodeValidator.validate(context.nodeAtRange()); + } + + @Override + public List getCodeActions(Diagnostic diagnostic, DiagBasedPositionDetails positionDetails, + CodeActionContext context) { + Node cursorNode = positionDetails.matchedNode(); + if (cursorNode.kind() != SyntaxKind.OBJECT_FIELD) { + assert false : "This line is unreachable as the diagnostic is only generated for an object field."; + return Collections.emptyList(); + } + + return Collections.singletonList(CodeActionUtil.createCodeAction( + CommandConstants.ADD_PRIVATE_QUALIFIER, + List.of(getTextEdit((ObjectFieldNode) cursorNode)), + context.fileUri(), + CodeActionKind.QuickFix + )); + } + + private static TextEdit getTextEdit(ObjectFieldNode node) { + String privateKeyword = SyntaxKind.PRIVATE_KEYWORD.stringValue(); + + // Get the line range of the existing visibility qualifier + Optional visibilityQualifier = node.visibilityQualifier(); + if (visibilityQualifier.isPresent()) { + return new TextEdit(PositionUtil.toRange(visibilityQualifier.get().lineRange()), privateKeyword); + } + privateKeyword += " "; + + // Get the start position of the qualifier list + NodeList qualifiers = node.qualifierList(); + if (qualifiers.size() > 0) { + Position position = PositionUtil.toPosition(qualifiers.get(0).lineRange().startLine()); + return new TextEdit(new Range(position, position), privateKeyword); + } + + // Get the start position of the type name + Position position = PositionUtil.toPosition(node.typeName().lineRange().startLine()); + return new TextEdit(new Range(position, position), privateKeyword); + } + + @Override + public String getName() { + return NAME; + } +} diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/MakeVariableImmutableCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/MakeVariableImmutableCodeAction.java new file mode 100644 index 000000000000..2234dbfcb316 --- /dev/null +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/MakeVariableImmutableCodeAction.java @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.langserver.codeaction.providers; + +import io.ballerina.compiler.api.SemanticModel; +import io.ballerina.compiler.api.symbols.ClassFieldSymbol; +import io.ballerina.compiler.api.symbols.Symbol; +import io.ballerina.compiler.api.symbols.SymbolKind; +import io.ballerina.compiler.api.symbols.TypeDescKind; +import io.ballerina.compiler.api.symbols.TypeSymbol; +import io.ballerina.compiler.syntax.tree.Node; +import io.ballerina.compiler.syntax.tree.NonTerminalNode; +import io.ballerina.compiler.syntax.tree.ObjectFieldNode; +import io.ballerina.compiler.syntax.tree.SyntaxKind; +import io.ballerina.tools.diagnostics.Diagnostic; +import io.ballerina.tools.text.LinePosition; +import org.ballerinalang.annotation.JavaSPIService; +import org.ballerinalang.langserver.codeaction.CodeActionNodeValidator; +import org.ballerinalang.langserver.codeaction.CodeActionUtil; +import org.ballerinalang.langserver.common.constants.CommandConstants; +import org.ballerinalang.langserver.common.utils.PositionUtil; +import org.ballerinalang.langserver.commons.CodeActionContext; +import org.ballerinalang.langserver.commons.codeaction.spi.DiagBasedPositionDetails; +import org.ballerinalang.langserver.commons.codeaction.spi.DiagnosticBasedCodeActionProvider; +import org.eclipse.lsp4j.CodeAction; +import org.eclipse.lsp4j.CodeActionKind; +import org.eclipse.lsp4j.Position; +import org.eclipse.lsp4j.Range; +import org.eclipse.lsp4j.TextEdit; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +/** + * Code Action for making a variable immutable. This will ensure that the given variable is both final and readonly. + * + * @since 2201.9.0 + */ +@JavaSPIService("org.ballerinalang.langserver.commons.codeaction.spi.LSCodeActionProvider") +public class MakeVariableImmutableCodeAction implements DiagnosticBasedCodeActionProvider { + + private static final String NAME = "Make variable immutable"; + private static final String DIAGNOSTIC_CODE = "BCE3956"; + + @Override + public boolean validate(Diagnostic diagnostic, DiagBasedPositionDetails positionDetails, + CodeActionContext context) { + return DIAGNOSTIC_CODE.equals(diagnostic.diagnosticInfo().code()) + && CodeActionNodeValidator.validate(context.nodeAtRange()); + } + + @Override + public List getCodeActions(Diagnostic diagnostic, DiagBasedPositionDetails positionDetails, + CodeActionContext context) { + NonTerminalNode cursorNode = positionDetails.matchedNode(); + + // The current implementation of the CA only supports object fields + if (cursorNode.kind() != SyntaxKind.OBJECT_FIELD) { + assert false : "This line is unreachable as the diagnostic is only generated for an object field."; + return Collections.emptyList(); + } + + ObjectFieldNode objectFieldNode = (ObjectFieldNode) cursorNode; + Node typeNode = objectFieldNode.typeName(); + List textEdits = new ArrayList<>(); + + // Check if the type is final + boolean isFinal = objectFieldNode.qualifierList().stream() + .anyMatch(token -> token.kind().equals(SyntaxKind.FINAL_KEYWORD)); + if (!isFinal) { + textEdits.add(getFinalTextEdit(typeNode)); + } + + // Check if the type is readonly + TypeSymbol typeSymbol, readonlyType; + try { + SemanticModel semanticModel = context.currentSemanticModel().orElseThrow(); + readonlyType = semanticModel.types().READONLY; + Symbol symbol = semanticModel.symbol(cursorNode).orElseThrow(); + typeSymbol = getTypeSymbol(symbol).orElseThrow(); + } catch (RuntimeException e) { + assert false : "This line is unreachable because the semantic model cannot be empty, and the type " + + "symbol does not contain errors."; + return Collections.emptyList(); + } + boolean isReadonly = typeSymbol.subtypeOf(readonlyType); + if (!isReadonly) { + textEdits.addAll(getReadonlyTextEdits(typeNode, typeSymbol.typeKind() == TypeDescKind.UNION)); + } + + // Generate and return the code action + return Collections.singletonList(CodeActionUtil.createCodeAction( + String.format(CommandConstants.MAKE_VARIABLE_IMMUTABLE, getTitleText(isFinal, isReadonly)), + textEdits, + context.fileUri(), + CodeActionKind.QuickFix)); + } + + private static Optional getTypeSymbol(Symbol symbol) { + if (symbol.kind() == SymbolKind.CLASS_FIELD) { + return Optional.of(((ClassFieldSymbol) symbol).typeDescriptor()); + } + assert false : "Unconsidered symbol type found: " + symbol.kind(); + return Optional.empty(); + } + + private static TextEdit getFinalTextEdit(Node typeNode) { + LinePosition linePosition = typeNode.lineRange().startLine(); + Position position = PositionUtil.toPosition(linePosition); + String editText = SyntaxKind.FINAL_KEYWORD.stringValue() + " "; + return new TextEdit(new Range(position, position), editText); + } + + private static List getReadonlyTextEdits(Node typeNode, boolean isUnion) { + LinePosition startLinePosition = typeNode.lineRange().startLine(); + LinePosition endLinePosition = typeNode.lineRange().endLine(); + List textEdits = new ArrayList<>(); + + if (isUnion) { + Position startPosition = PositionUtil.toPosition(startLinePosition); + TextEdit startTextEdit = new TextEdit(new Range(startPosition, startPosition), + SyntaxKind.OPEN_PAREN_TOKEN.stringValue()); + textEdits.add(startTextEdit); + } + + Position endPosition = PositionUtil.toPosition(endLinePosition); + String editText = (isUnion ? SyntaxKind.CLOSE_PAREN_TOKEN.stringValue() : "") + " & " + + SyntaxKind.READONLY_KEYWORD.stringValue(); + TextEdit endTextEdit = new TextEdit(new Range(endPosition, endPosition), editText); + textEdits.add(endTextEdit); + + return textEdits; + } + + private static String getTitleText(boolean isFinal, boolean isReadonly) { + StringBuilder result = new StringBuilder(); + + if (!isFinal) { + result.append("'").append(SyntaxKind.FINAL_KEYWORD.stringValue()).append("'"); + } + + if (!isReadonly) { + if (result.length() > 0) { + result.append(" and "); + } + result.append("'").append(SyntaxKind.READONLY_KEYWORD.stringValue()).append("'"); + } + + return result.toString(); + } + + @Override + public String getName() { + return NAME; + } +} diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/CommandConstants.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/CommandConstants.java index eb0f5b0d4613..72216df953e8 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/CommandConstants.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/CommandConstants.java @@ -120,6 +120,10 @@ public class CommandConstants { public static final String CHANGE_PARAM_TYPE_TITLE = "Change parameter '%s' type to '%s'"; + public static final String ADD_PRIVATE_QUALIFIER = "Add private qualifier"; + + public static final String MAKE_VARIABLE_IMMUTABLE = "Add %s to the variable"; + public static final String CREATE_VAR_TYPE_GUARD_TITLE = "Create variable and type guard"; public static final String TYPE_GUARD_TITLE = "Type guard variable '%s'"; diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/AddPrivateQualifierCodeActionTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/AddPrivateQualifierCodeActionTest.java new file mode 100644 index 000000000000..d85d8593ac40 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/AddPrivateQualifierCodeActionTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.langserver.codeaction; + +import org.ballerinalang.langserver.commons.workspace.WorkspaceDocumentException; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.IOException; + +/** + * Test class to test the change isolated field to private code action. + * + * @since 2201.9.0 + */ +public class AddPrivateQualifierCodeActionTest extends AbstractCodeActionTest { + + @Test(dataProvider = "codeaction-data-provider") + @Override + public void test(String config) throws IOException, WorkspaceDocumentException { + super.test(config); + } + + @DataProvider(name = "codeaction-data-provider") + @Override + public Object[][] dataProvider() { + return new Object[][]{ + {"change_field_private1.json"}, + {"change_field_private2.json"}, + {"change_field_private3.json"}, + {"change_field_private4.json"}, + {"change_field_private5.json"}, + {"change_field_private6.json"}, + }; + } + + @Override + public String getResourceDir() { + return "change-field-private"; + } +} diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/MakeVariableImmutableCodeActionTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/MakeVariableImmutableCodeActionTest.java new file mode 100644 index 000000000000..64560f1b1502 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/MakeVariableImmutableCodeActionTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.langserver.codeaction; + +import org.ballerinalang.langserver.commons.workspace.WorkspaceDocumentException; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.io.IOException; + +/** + * Test class to test the converting a variable to immutable code action. + * + * @since 2201.9.0 + */ +public class MakeVariableImmutableCodeActionTest extends AbstractCodeActionTest { + + @Test(dataProvider = "codeaction-data-provider") + @Override + public void test(String config) throws IOException, WorkspaceDocumentException { + super.test(config); + } + + @DataProvider(name = "codeaction-data-provider") + @Override + public Object[][] dataProvider() { + return new Object[][]{ + {"make_variable_immutable1.json"}, + {"make_variable_immutable2.json"}, + {"make_variable_immutable3.json"}, + {"make_variable_immutable4.json"}, + {"make_variable_immutable5.json"}, + {"make_variable_immutable6.json"}, + {"make_variable_immutable7.json"}, + {"make_variable_immutable8.json"}, + {"make_variable_immutable9.json"}, + {"make_variable_immutable10.json"}, + {"make_variable_immutable11.json"}, + {"make_variable_immutable12.json"}, + {"make_variable_immutable13.json"}, + {"make_variable_immutable14.json"}, + {"make_variable_immutable15.json"} + }; + } + + @Override + public String getResourceDir() { + return "make-variable-immutable"; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private1.json b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private1.json new file mode 100644 index 000000000000..1a0adec8efbd --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private1.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 11 + }, + "source": "change_field_private1.bal", + "description": "Change the isolated field to private for a structured type", + "expected": [ + { + "title": "Add private qualifier", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "private " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private2.json new file mode 100644 index 000000000000..e1e4c02e8230 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private2.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 9 + }, + "source": "change_field_private2.bal", + "description": "Change the isolated field to private for a simple type", + "expected": [ + { + "title": "Add private qualifier", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "private " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private3.json b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private3.json new file mode 100644 index 000000000000..0c21fa714fe3 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private3.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 10 + }, + "source": "change_field_private3.bal", + "description": "Change the isolated field to private for a multiline type", + "expected": [ + { + "title": "Add private qualifier", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "private " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private4.json b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private4.json new file mode 100644 index 000000000000..bbab3fd7a862 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private4.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 25 + }, + "source": "change_field_private4.bal", + "description": "Change the isolated field to private for a public type", + "expected": [ + { + "title": "Add private qualifier", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 10 + } + }, + "newText": "private" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private5.json b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private5.json new file mode 100644 index 000000000000..57399d619e04 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private5.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 10 + }, + "source": "change_field_private5.bal", + "description": "Change the isolated field to private for a final type", + "expected": [ + { + "title": "Add private qualifier", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "private " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private6.json b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private6.json new file mode 100644 index 000000000000..d549f3554f94 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/config/change_field_private6.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 2, + "character": 8 + }, + "source": "change_field_private6.bal", + "description": "Change the isolated field to private for a documented type", + "expected": [ + { + "title": "Add private qualifier", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 2, + "character": 4 + } + }, + "newText": "private " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private1.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private1.bal new file mode 100644 index 000000000000..cdba5ab4bc8b --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private1.bal @@ -0,0 +1,8 @@ +isolated service class IsolatedClass { + map isolatedField = { + a: "1", + b: "2", + c: "3" + }; + int i = 32; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private2.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private2.bal new file mode 100644 index 000000000000..ada3bde7365c --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private2.bal @@ -0,0 +1,3 @@ +isolated service class IsolatedClass { + int i = 32; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private3.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private3.bal new file mode 100644 index 000000000000..3133ceac0358 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private3.bal @@ -0,0 +1,6 @@ +isolated service class IsolatedClass { + record {| + int i; + string val; + |} isolatedRec; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private4.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private4.bal new file mode 100644 index 000000000000..2a55b0a6a579 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private4.bal @@ -0,0 +1,7 @@ +isolated service class IsolatedClass { + public final map isolatedField = { + a: "1", + b: "2", + c: "3" + }; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private5.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private5.bal new file mode 100644 index 000000000000..d4d7df6ac1ab --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private5.bal @@ -0,0 +1,3 @@ +isolated service class IsolatedClass { + final string[] strArr = []; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private6.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private6.bal new file mode 100644 index 000000000000..d0e96c7283c5 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/change-field-private/source/change_field_private6.bal @@ -0,0 +1,4 @@ +isolated service class IsolatedClass { + # Documentation + final string[] strArr = []; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable1.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable1.json new file mode 100644 index 000000000000..3d0e19f9d228 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable1.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 7 + }, + "source": "make_variable_immutable1.bal", + "description": "Make immutable of a simple type variable", + "expected": [ + { + "title": "Add 'final' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable10.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable10.json new file mode 100644 index 000000000000..5b2f3e17885e --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable10.json @@ -0,0 +1,43 @@ +{ + "position": { + "line": 7, + "character": 13 + }, + "source": "make_variable_immutable10.bal", + "description": "Make immutable of a object variable", + "expected": [ + { + "title": "Add 'final' and 'readonly' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 7, + "character": 4 + }, + "end": { + "line": 7, + "character": 4 + } + }, + "newText": "final " + }, + { + "range": { + "start": { + "line": 7, + "character": 14 + }, + "end": { + "line": 7, + "character": 14 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable11.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable11.json new file mode 100644 index 000000000000..adc74f997bf5 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable11.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 7, + "character": 10 + }, + "source": "make_variable_immutable11.bal", + "description": "Make immutable of a readonly object", + "expected": [ + { + "title": "Add 'final' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 7, + "character": 4 + }, + "end": { + "line": 7, + "character": 4 + } + }, + "newText": "final " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable12.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable12.json new file mode 100644 index 000000000000..9bdca8934b7f --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable12.json @@ -0,0 +1,43 @@ +{ + "position": { + "line": 1, + "character": 10 + }, + "source": "make_variable_immutable12.bal", + "description": "Make immutable of a variable", + "expected": [ + { + "title": "Add 'final' and 'readonly' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + }, + { + "range": { + "start": { + "line": 1, + "character": 11 + }, + "end": { + "line": 1, + "character": 11 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable13.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable13.json new file mode 100644 index 000000000000..030a22d07c64 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable13.json @@ -0,0 +1,56 @@ +{ + "position": { + "line": 1, + "character": 8 + }, + "source": "make_variable_immutable13.bal", + "description": "Make immutable of a nullable mutable variable", + "expected": [ + { + "title": "Add 'final' and 'readonly' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + }, + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "(" + }, + { + "range": { + "start": { + "line": 1, + "character": 16 + }, + "end": { + "line": 1, + "character": 16 + } + }, + "newText": ") & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable14.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable14.json new file mode 100644 index 000000000000..d35519222bf9 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable14.json @@ -0,0 +1,43 @@ +{ + "position": { + "line": 1, + "character": 11 + }, + "source": "make_variable_immutable14.bal", + "description": "Make immutable of a variable", + "expected": [ + { + "title": "Add 'final' and 'readonly' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 11 + }, + "end": { + "line": 1, + "character": 11 + } + }, + "newText": "final " + }, + { + "range": { + "start": { + "line": 1, + "character": 16 + }, + "end": { + "line": 1, + "character": 16 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable15.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable15.json new file mode 100644 index 000000000000..fff0412c3711 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable15.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 2, + "character": 9 + }, + "source": "make_variable_immutable15.bal", + "description": "Make immutable of a documented public variable", + "expected": [ + { + "title": "Add 'final' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 2, + "character": 4 + } + }, + "newText": "final " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable2.json new file mode 100644 index 000000000000..f8eb57bd3f39 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable2.json @@ -0,0 +1,43 @@ +{ + "position": { + "line": 2, + "character": 12 + }, + "source": "make_variable_immutable2.bal", + "description": "Make immutable of a record variable", + "expected": [ + { + "title": "Add 'final' and 'readonly' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + }, + { + "range": { + "start": { + "line": 4, + "character": 6 + }, + "end": { + "line": 4, + "character": 6 + } + }, + "newText": " & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable3.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable3.json new file mode 100644 index 000000000000..85bb2632dc93 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable3.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 4, + "character": 12 + }, + "source": "make_variable_immutable3.bal", + "description": "Make immutable of a readonly record variable", + "expected": [ + { + "title": "Add 'final' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable4.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable4.json new file mode 100644 index 000000000000..8c4c72db0dce --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable4.json @@ -0,0 +1,56 @@ +{ + "position": { + "line": 1, + "character": 7 + }, + "source": "make_variable_immutable4.bal", + "description": "Make immutable of a union variable", + "expected": [ + { + "title": "Add 'final' and 'readonly' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + }, + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "(" + }, + { + "range": { + "start": { + "line": 1, + "character": 19 + }, + "end": { + "line": 1, + "character": 19 + } + }, + "newText": ") & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable5.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable5.json new file mode 100644 index 000000000000..8845f0254f59 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable5.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 7 + }, + "source": "make_variable_immutable5.bal", + "description": "Make immutable of a union variable", + "expected": [ + { + "title": "Add 'final' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable6.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable6.json new file mode 100644 index 000000000000..e7dc76295015 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable6.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 10 + }, + "source": "make_variable_immutable6.bal", + "description": "Make immutable of a union variable", + "expected": [ + { + "title": "Add 'final' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable7.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable7.json new file mode 100644 index 000000000000..5c55317e89f7 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable7.json @@ -0,0 +1,56 @@ +{ + "position": { + "line": 1, + "character": 14 + }, + "source": "make_variable_immutable7.bal", + "description": "Make immutable of a union variable", + "expected": [ + { + "title": "Add 'final' and 'readonly' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + }, + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "(" + }, + { + "range": { + "start": { + "line": 1, + "character": 21 + }, + "end": { + "line": 1, + "character": 21 + } + }, + "newText": ") & readonly" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable8.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable8.json new file mode 100644 index 000000000000..e49e471a3947 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable8.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 5 + }, + "source": "make_variable_immutable8.bal", + "description": "Make immutable of a singleton variable", + "expected": [ + { + "title": "Add 'final' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable9.json b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable9.json new file mode 100644 index 000000000000..022971cc0850 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/config/make_variable_immutable9.json @@ -0,0 +1,30 @@ +{ + "position": { + "line": 1, + "character": 10 + }, + "source": "make_variable_immutable9.bal", + "description": "Make immutable of a function variable", + "expected": [ + { + "title": "Add 'final' to the variable", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 4 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "newText": "final " + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable1.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable1.bal new file mode 100644 index 000000000000..2d069bd035ce --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable1.bal @@ -0,0 +1,3 @@ +isolated class IsolatedClass { + int i = 2; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable10.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable10.bal new file mode 100644 index 000000000000..258fc9443729 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable10.bal @@ -0,0 +1,13 @@ +type ObjectName object { + int i; + + function name(); +}; + +isolated class IsolatedClass { + ObjectName myObj; + + function init(ObjectName & readonly myObj) { + self.myObj = myObj; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable11.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable11.bal new file mode 100644 index 000000000000..a75a0a159391 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable11.bal @@ -0,0 +1,13 @@ +type ObjectName object { + int i; + + function name(); +} & readonly; + +isolated class IsolatedClass { + ObjectName myObj; + + function init(ObjectName myObj) { + self.myObj = myObj; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable12.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable12.bal new file mode 100644 index 000000000000..744de40de58e --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable12.bal @@ -0,0 +1,7 @@ +isolated class IsolatedClass { + anydata val; + + function init(string val) { + self.val = val; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable13.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable13.bal new file mode 100644 index 000000000000..eef987ab6833 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable13.bal @@ -0,0 +1,3 @@ +isolated class IsolatedClass { + map? mp = {}; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable14.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable14.bal new file mode 100644 index 000000000000..8b0270ba715a --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable14.bal @@ -0,0 +1,3 @@ +isolated class IsolatedClass { + public int[] arr = [2]; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable15.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable15.bal new file mode 100644 index 000000000000..b488214c6d38 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable15.bal @@ -0,0 +1,4 @@ +isolated class IsolatedClass { + # Documented node + int i = 2; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable2.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable2.bal new file mode 100644 index 000000000000..1fbd35bbd1c4 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable2.bal @@ -0,0 +1,10 @@ +isolated class IsolatedClass { + record {| + string id; + int count; + |} rec; + + function init() { + self.rec = {count: 0, id: ""}; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable3.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable3.bal new file mode 100644 index 000000000000..82a21e2431f6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable3.bal @@ -0,0 +1,6 @@ +isolated class IsolatedClass { + record {| + string id; + int count; + |} & readonly rec = {count: 0, id: ""}; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable4.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable4.bal new file mode 100644 index 000000000000..876f982b5597 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable4.bal @@ -0,0 +1,7 @@ +isolated class IsolatedClass { + int|map val; + + function init(int|map & readonly val) { + self.val = val; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable5.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable5.bal new file mode 100644 index 000000000000..67a194f99a58 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable5.bal @@ -0,0 +1,7 @@ +isolated class IsolatedClass { + int|string val; + + function init(int|string val) { + self.val = val; + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable6.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable6.bal new file mode 100644 index 000000000000..bb526b7e3cad --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable6.bal @@ -0,0 +1,3 @@ +isolated class IsolatedClass { + map & readonly|int|boolean val = false; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable7.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable7.bal new file mode 100644 index 000000000000..820d7a16a845 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable7.bal @@ -0,0 +1,7 @@ +isolated class IsolatedClass { + int[]|map val; + + function init(int[]|map val) { + self.val = val.cloneReadOnly(); + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable8.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable8.bal new file mode 100644 index 000000000000..4d125af1e5c7 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable8.bal @@ -0,0 +1,3 @@ +isolated class IsolatedClass { + "Value" val = "Value"; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable9.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable9.bal new file mode 100644 index 000000000000..251748fd6e6f --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/make-variable-immutable/source/make_variable_immutable9.bal @@ -0,0 +1,7 @@ +isolated class IsolatedClass { + function (int i) returns boolean fn; + + function init(function (int i) returns boolean fn) { + self.fn = fn; + } +}