Skip to content

Commit

Permalink
Merge branch 'ballerina-platform:master' into hashVerification
Browse files Browse the repository at this point in the history
  • Loading branch information
NirashaSewwandi authored Oct 20, 2023
2 parents 977ea99 + 74c138e commit 9ebf127
Show file tree
Hide file tree
Showing 47 changed files with 810 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,8 @@ public enum DiagnosticErrorCode implements DiagnosticCode {
INVALID_QUERY_CONSTRUCT_TYPE("BCE4055", "invalid.error.query.construct.type"),
CANNOT_USE_ALTERNATE_WAIT_ACTION_WITHIN_MULTIPLE_WAIT_ACTION("BCE4056",
"cannot.use.alternate.wait.action.within.multiple.wait.action"),
EXPRESSION_OF_FUTURE_TYPE_EXPECTED("BCE4057", "future.expression.expected")
EXPRESSION_OF_FUTURE_TYPE_EXPECTED("BCE4057", "future.expression.expected"),
INSTANTIATION_ERROR("BCE4058", "instantiation.error")
;

private String diagnosticId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand Down Expand Up @@ -897,6 +898,10 @@ private Executable resolveMethod(Class<?> clazz, String name, Class<?>... paramT
private List<Executable> getExecutables(Class<?> clazz, String methodName, JMethodKind kind) {

if (kind == JMethodKind.CONSTRUCTOR) {
if (Modifier.isAbstract(clazz.getModifiers())) {
throw new JInteropException(DiagnosticErrorCode.INSTANTIATION_ERROR,
"'" + clazz.getName() + "' is abstract, and cannot be instantiated");
}
return Arrays.asList(getConstructors(clazz));
} else {
List<Executable> list = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,9 @@ error.unsupported.primitive.type.reason=\
error.method.signature.not.match=\
'{ballerina/jballerina.java}'METHOD_SIGNATURE_DOES_NOT_MATCH ''{0}''

error.instantiation.error=\
'{ballerina/jballerina.java}'INSTANTIATION_ERROR ''{0}''

error.invalid.attribute.reference=\
invalid attribute reference

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"leadingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
"value": " "
}
],
"trailingMinutiae": [
Expand Down Expand Up @@ -203,7 +203,7 @@
"leadingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
"value": " "
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public function main() {
foo(object {
int i = 1;
});
int i = 1;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

import io.ballerina.compiler.api.SemanticModel;
import io.ballerina.compiler.api.symbols.Symbol;
import io.ballerina.compiler.syntax.tree.ModulePartNode;
import io.ballerina.compiler.syntax.tree.NonTerminalNode;
import io.ballerina.compiler.syntax.tree.SyntaxKind;
import io.ballerina.projects.Document;
import io.ballerina.projects.Module;
import io.ballerina.projects.Project;
import io.ballerina.tools.diagnostics.Location;
import io.ballerina.tools.text.LinePosition;
import io.ballerina.tools.text.TextRange;
import org.ballerinalang.langserver.common.utils.CommonUtil;
import org.ballerinalang.langserver.common.utils.PathUtil;
import org.ballerinalang.langserver.common.utils.PositionUtil;
Expand Down Expand Up @@ -120,7 +122,22 @@ public static Optional<Symbol> getSymbolAtCursor(PositionedOperationContext cont
return Optional.empty();
}

Document document = srcFile.get();
Position position = context.getCursorPosition();
TextRange range = TextRange.from(
document.textDocument().textPositionFrom(PositionUtil.getLinePosition(position)), 0);
NonTerminalNode nonTerminalNode = ((ModulePartNode) document.syntaxTree().rootNode()).findNode(range);
SyntaxKind parentKind = nonTerminalNode.parent().kind();

if (parentKind == SyntaxKind.TYPE_PARAMETER || parentKind == SyntaxKind.STREAM_TYPE_PARAMS) {
if (nonTerminalNode.lineRange().endLine().offset() == position.getCharacter()) {
// When there is a type parameter and cursor is at the end of the type parameter, semantic API does not
// provide the correct symbol. Therefore, here we search for the symbol at (col - 1).
return semanticModel.get().symbol(document,
LinePosition.from(position.getLine(), position.getCharacter() - 1));
}
}

Optional<Symbol> symbolAtCursor = semanticModel.get().symbol(srcFile.get(),
LinePosition.from(position.getLine(), position.getCharacter()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ protected Object[][] testDataProvider() throws IOException {
{"def_annotation_on_obj_func_config1.json", "project"},
{"def_typereference.json", "project"},
{"def_typereference2.json", "project"},
{"def_typereference3.json", "project"}
{"def_typereference3.json", "project"},
{"defProject15.json", "project"},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private Object[][] testDataProvider() {
// Negative/invalid cases
{"rename_keyword_result1.json", "kw"},
{"rename_invalid_token_result1.json", "token"},
{"rename_table_row_type_and_stream_type.json", "Student"},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public Object[][] testDataProvider() {
{"rename_self.json", "this"},
{"rename_invalid_qname_ref.json", "io"},
// {"rename_resource_method_path_segment.json", "path1"} //TODO: Fix #41041

{"rename_table_row_type_parameter1.json", "Student"},
{"rename_table_row_type_parameter2.json", "Student"},
{"rename_table_row_type_parameter3.json", "Student"},
{"rename_stream_type_parameter.json", "Student"},
{"rename_map_type_parameter.json", "Student"},
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"source": {
"file": "projectls/defmodsource6.bal"
},
"position": {
"line": 3,
"character": 19
},
"result": [
{
"range": {
"start": {
"line": 9,
"character": 12
},
"end": {
"line": 9,
"character": 17
}
},
"uri": "projectls/modules/lsmod3/lsmod3.bal"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import projectls.lsmod3;

function foo() {
table<lsmod3:Human> tHuman = table [{id: 1, name: "Jane"}];
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ public function mod3Function1() {

public type MyType lsmod1:MyType;
public type MyType2 MyType;

public type Human record {|
readonly int id;
string name;
|};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"source": {
"file": "main.bal"
},
"position": {
"line": 19,
"character": 23
},
"prepareRename": {
"valid": true
},
"result": {
"changes": {
"modules/module2/types.bal": [{
"range": {
"start": {
"line": 2,
"character": 12
},
"end": {
"line": 2,
"character": 17
}
},
"newText": "Student"
}],
"main.bal": [{
"range": {
"start": {
"line": 18,
"character": 19
},
"end": {
"line": 18,
"character": 24
}
},
"newText": "Student"
}, {
"range": {
"start": {
"line": 19,
"character": 18
},
"end": {
"line": 19,
"character": 23
}
},
"newText": "Student"
}]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"source": {
"file": "rename_map_type_parameter.bal"
},
"position": {
"line": 6,
"character": 14
},
"prepareRename": {
"valid": true
},
"result": {
"changes": {
"rename_map_type_parameter.bal": [
{
"range": {
"start": {
"line": 0,
"character": 5
},
"end": {
"line": 0,
"character": 11
}
},
"newText": "Student"
},
{
"range": {
"start": {
"line": 6,
"character": 8
},
"end": {
"line": 6,
"character": 14
}
},
"newText": "Student"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"source": {
"file": "rename_stream_type_parameter.bal"
},
"position": {
"line": 7,
"character": 17
},
"prepareRename": {
"valid": true
},
"result": {
"changes": {
"rename_stream_type_parameter.bal": [
{
"range": {
"start": {
"line": 0,
"character": 5
},
"end": {
"line": 0,
"character": 11
}
},
"newText": "Student"
},
{
"range": {
"start": {
"line": 6,
"character": 4
},
"end": {
"line": 6,
"character": 10
}
},
"newText": "Student"
},
{
"range": {
"start": {
"line": 7,
"character": 11
},
"end": {
"line": 7,
"character": 17
}
},
"newText": "Student"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"source": {
"file": "rename_table_row_type_parameter1.bal"
},
"position": {
"line": 6,
"character": 16
},
"prepareRename": {
"valid": true
},
"result": {
"changes": {
"rename_table_row_type_parameter1.bal": [
{
"range": {
"start": {
"line": 0,
"character": 5
},
"end": {
"line": 0,
"character": 11
}
},
"newText": "Student"
},
{
"range": {
"start": {
"line": 6,
"character": 10
},
"end": {
"line": 6,
"character": 16
}
},
"newText": "Student"
}
]
}
}
}
Loading

0 comments on commit 9ebf127

Please sign in to comment.