Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @Nullable annotations #43393

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6e2fc18
Add @Nullable annotations
Shadow-Devil Oct 4, 2024
3eaf480
Fix spotbugs errors
Shadow-Devil Oct 4, 2024
06d63f9
Fix checkstyle errors
Shadow-Devil Nov 5, 2024
df558e5
Fixup
Shadow-Devil Nov 5, 2024
c5bb91b
Fixup
Shadow-Devil Nov 5, 2024
871d329
Replace duplicate `hasTestablePackage` with `containsTestablePkg`
Shadow-Devil Nov 5, 2024
d89bfd8
Fixup testcase
Shadow-Devil Nov 5, 2024
18c1bdc
Fixup testcase
Shadow-Devil Nov 5, 2024
7981b28
Fixup testcase
Shadow-Devil Nov 5, 2024
5d00477
Merge branch 'master' into nullable-annotations
Shadow-Devil Nov 13, 2024
6296857
Merge remote-tracking branch 'upstream/master' into nullable-annotations
Shadow-Devil Nov 19, 2024
1692d5a
Merge branch 'master' into nullable-annotations
Shadow-Devil Nov 22, 2024
2d25720
Fix compilation error
Shadow-Devil Nov 22, 2024
0cf1f3c
Fix checkstyle
Shadow-Devil Nov 22, 2024
eca0cf6
Fix Checkstyle
Shadow-Devil Nov 25, 2024
68a3eb6
Fix some jballerina integration tests on windows
Shadow-Devil Dec 2, 2024
98b8b62
Fix checkstyle
Shadow-Devil Dec 2, 2024
e91c80e
Fix checkstyle
Shadow-Devil Dec 2, 2024
32138ca
Fix checkstyle
Shadow-Devil Dec 2, 2024
767fbf3
Fix checkstyle
Shadow-Devil Dec 2, 2024
4bef820
Gitignore Dependencies.toml files in integration tests
Shadow-Devil Dec 2, 2024
a0a52c7
Fix checkstyle
Shadow-Devil Dec 2, 2024
40343b4
Merge branch 'master' into nullable-annotations
Shadow-Devil Dec 2, 2024
aaaf92e
Refactor jballerina integration tests to use more Paths instead of St…
Shadow-Devil Dec 3, 2024
6c14120
Fix compilation errors
Shadow-Devil Dec 3, 2024
3942e35
Fix testcases
Shadow-Devil Dec 3, 2024
e0808c1
Fix testcases
Shadow-Devil Dec 3, 2024
d815110
Fix testcases
Shadow-Devil Dec 3, 2024
2882d06
Fix testcases
Shadow-Devil Dec 3, 2024
cdf7d9b
Fix testcases
Shadow-Devil Dec 3, 2024
9c39917
Fix Checkstyle
Shadow-Devil Dec 3, 2024
bfd9500
Fix Spotbugs
Shadow-Devil Dec 4, 2024
9bfe92f
Merge branch 'master' into nullable-annotations
Shadow-Devil Dec 7, 2024
abce447
Merge branch 'master' into nullable-annotations
Shadow-Devil Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.ballerina.shell.Evaluator;
import io.ballerina.shell.EvaluatorBuilder;
import io.ballerina.shell.parser.TrialTreeParser;
import org.jetbrains.annotations.Nullable;

import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -109,6 +110,7 @@ public static class Builder {
private InputStream inputStream;
private OutputStream outputStream;
private long treeParsingTimeoutMs;
@Nullable
private String startFile;
private boolean isDebug;
private boolean isDumb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.gson.Gson;
import io.ballerina.shell.DiagnosticReporter;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -85,6 +86,7 @@ public List<String> getTopicList() {
return topicList;
}

@Nullable
private String readFileAsString(String file) {
String content = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.compiler.syntax.tree.NodeParser;
import io.ballerina.shell.cli.utils.IncompleteInputFinder;
import org.jetbrains.annotations.Nullable;

/**
* Validates user input completes as an expression.
Expand All @@ -29,6 +30,7 @@
*/
public class ExpressionValidator implements Validator {

@Nullable
private Validator nextInValidator;

public ExpressionValidator() {
Expand All @@ -45,6 +47,6 @@ public boolean evaluate(String source) {
IncompleteInputFinder incompleteInputFinder = new IncompleteInputFinder();
Node parsedNode = NodeParser.parseExpression(source);
return !parsedNode.hasDiagnostics() || !parsedNode.apply(incompleteInputFinder)
|| nextInValidator.evaluate(source);
|| (nextInValidator != null && nextInValidator.evaluate(source));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.ballerina.shell.cli.utils.IncompleteInputFinder;
import io.ballerina.tools.text.TextDocument;
import io.ballerina.tools.text.TextDocuments;
import org.jetbrains.annotations.Nullable;

/**
* Validates user input as a complete module member.
Expand All @@ -34,6 +35,7 @@
*/
public class ModuleMemberValidator implements Validator {

@Nullable
private Validator nextInValidator;

public ModuleMemberValidator() {
Expand All @@ -59,11 +61,11 @@ public boolean evaluate(String source) {
// Sample testcase : if (x == y) { x = x + 1; x = x + 1;
if (lastNode.kind() == SyntaxKind.FUNCTION_DEFINITION) {
return !lastNode.hasDiagnostics() || !lastNode.apply(incompleteInputFinder)
|| nextInValidator.evaluate(lastNode.toSourceCode());
|| (nextInValidator != null && nextInValidator.evaluate(lastNode.toSourceCode()));
}
}

return !node.imports().isEmpty() || !parsedNode.hasDiagnostics() || !parsedNode.apply(incompleteInputFinder)
|| nextInValidator.evaluate(source);
|| (nextInValidator != null && nextInValidator.evaluate(source));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.compiler.syntax.tree.NodeParser;
import io.ballerina.shell.cli.utils.IncompleteInputFinder;
import org.jetbrains.annotations.Nullable;

/**
* Validates user input as a complete statement.
Expand All @@ -29,6 +30,7 @@
*/
public class StatementValidator implements Validator {

@Nullable
private Validator nextInValidator;

public StatementValidator() {
Expand All @@ -45,6 +47,6 @@ public boolean evaluate(String source) {
IncompleteInputFinder incompleteInputFinder = new IncompleteInputFinder();
Node parsedNode = NodeParser.parseBlockStatement("{" + source + "}");
return !parsedNode.hasDiagnostics() || !parsedNode.apply(incompleteInputFinder)
|| nextInValidator.evaluate(source);
|| (nextInValidator != null && nextInValidator.evaluate(source));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
requires org.jline;
requires com.google.gson;
requires io.ballerina.tools.api;
requires static org.jetbrains.annotations;

exports io.ballerina.shell.cli;
exports io.ballerina.shell.cli.handlers.help;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.ballerina.shell.snippet.Snippet;
import io.ballerina.shell.snippet.factory.SnippetFactory;
import io.ballerina.shell.utils.StringUtils;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -62,6 +63,7 @@ public void initialize() throws BallerinaShellException {
}
}

@Nullable
@Override
public String evaluate(String source) throws BallerinaShellException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package io.ballerina.shell;

import org.jetbrains.annotations.Nullable;

/**
* Return value after invoking snippet.
* Contains result as an object &amp; exception status related to compilation
Expand All @@ -29,7 +31,7 @@ public class NotebookReturnValue {
private final Object result;
private final Enum<ExceptionStatus> exceptionStatus;

NotebookReturnValue(Object result, Enum<ExceptionStatus> exceptionStatus) {
NotebookReturnValue(@Nullable Object result, Enum<ExceptionStatus> exceptionStatus) {
this.result = result;
this.exceptionStatus = exceptionStatus;
}
Expand All @@ -39,6 +41,7 @@ public class NotebookReturnValue {
this.exceptionStatus = exceptionStatus;
}

@Nullable
public Object getResult() {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package io.ballerina.shell;

import org.jetbrains.annotations.Nullable;

/**
* Shell Compilation class.
* Contains package compilation &amp; exception status related to compilation
Expand All @@ -29,7 +31,7 @@ public class ShellReturnValue {
private final String result;
private final Enum<ExceptionStatus> exceptionStatus;

ShellReturnValue(String result, Enum<ExceptionStatus> exceptionStatus) {
ShellReturnValue(@Nullable String result, Enum<ExceptionStatus> exceptionStatus) {
this.result = result;
this.exceptionStatus = exceptionStatus;
}
Expand All @@ -39,6 +41,7 @@ public class ShellReturnValue {
this.exceptionStatus = exceptionStatus;
}

@Nullable
public String getResult() {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import io.ballerina.shell.utils.Identifier;
import io.ballerina.shell.utils.QuotedImport;
import io.ballerina.shell.utils.StringUtils;
import org.jetbrains.annotations.Nullable;

import java.io.PrintStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -203,6 +204,7 @@ public void reset() {
this.availableModuleDeclarations.clear();
}

@Nullable
@Override
public PackageCompilation getCompilation(Collection<Snippet> newSnippets) throws InvokerException {
if (!this.initialized.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.ballerina.shell.utils.QuotedImport;
import io.ballerina.tools.text.TextDocument;
import io.ballerina.tools.text.TextDocuments;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Modifier;
import java.util.Arrays;
Expand Down Expand Up @@ -133,6 +134,7 @@ public void reset() {
* @param prefix Prefix to search.
* @return The import statement of the prefix.
*/
@Nullable
public String getImport(Identifier prefix) {
QuotedImport quotedImport = this.imports.get(prefix);
if (quotedImport == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.ballerina.shell.invoker.classload.ClassLoadInvoker;
import io.ballerina.shell.rt.InvokerMemory;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -60,9 +61,9 @@ public ClassLoadContext(String contextId,
Collection<String> imports,
Collection<String> moduleDclns,
Collection<VariableContext> varDclns,
Collection<String> newVarNames,
@Nullable Collection<String> newVarNames,
String lastVarDcln,
Collection<StatementContext> lastStmts) {
@Nullable Collection<StatementContext> lastStmts) {
this.lastStmts = Objects.requireNonNullElse(lastStmts, List.of());
this.lastVarDcln = Objects.requireNonNullElse(lastVarDcln, "");
this.contextId = Objects.requireNonNull(contextId);
Expand All @@ -88,8 +89,8 @@ public ClassLoadContext(String contextId,
Collection<String> imports,
Collection<String> moduleDclns,
Collection<VariableContext> varDclns,
Collection<String> newVarNames,
String lastVarDcln) {
@Nullable Collection<String> newVarNames,
@Nullable String lastVarDcln) {
this(contextId, imports, moduleDclns, varDclns, newVarNames, lastVarDcln, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package io.ballerina.shell.snippet;

import org.jetbrains.annotations.Nullable;

/**
* Snippet sub type to further categorize snippets.
*
Expand Down Expand Up @@ -102,6 +104,7 @@ public boolean hasError() {
return error != null;
}

@Nullable
public String getError() {
return error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import io.ballerina.shell.snippet.types.ModuleMemberDeclarationSnippet;
import io.ballerina.shell.snippet.types.StatementSnippet;
import io.ballerina.shell.snippet.types.VariableDeclarationSnippet;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -124,6 +125,7 @@ public class BasicSnippetFactory extends SnippetFactory {
Map.entry(DoStatementNode.class, SnippetSubKind.DO_STATEMENT)
);

@Nullable
@Override
public ImportDeclarationSnippet createImportSnippet(Node node) {
if (node instanceof ImportDeclarationNode importDeclarationNode) {
Expand All @@ -132,6 +134,7 @@ public ImportDeclarationSnippet createImportSnippet(Node node) {
return null;
}

@Nullable
@Override
public List<VariableDeclarationSnippet> createVariableDeclarationSnippets(Node node) {
ModuleVariableDeclarationNode dclnNode;
Expand Down Expand Up @@ -221,6 +224,7 @@ public List<VariableDeclarationSnippet> createVariableDeclarationSnippets(Node n
return snippets;
}

@Nullable
@Override
public ModuleMemberDeclarationSnippet createModuleMemberDeclarationSnippet(Node node)
throws SnippetException {
Expand All @@ -241,6 +245,7 @@ public ModuleMemberDeclarationSnippet createModuleMemberDeclarationSnippet(Node
return null;
}

@Nullable
@Override
public StatementSnippet createStatementSnippet(Node node) throws SnippetException {
if (node instanceof StatementNode) {
Expand All @@ -260,6 +265,7 @@ public StatementSnippet createStatementSnippet(Node node) throws SnippetExceptio
return null;
}

@Nullable
@Override
public ExpressionSnippet createExpressionSnippet(Node node) {
if (node instanceof ExpressionNode expressionNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.ballerina.projects.internal.environment.BallerinaDistribution;
import io.ballerina.projects.internal.environment.DefaultEnvironment;
import io.ballerina.shell.Diagnostic;
import org.jetbrains.annotations.Nullable;
import org.wso2.ballerinalang.compiler.util.Names;

import java.util.ArrayList;
Expand Down Expand Up @@ -79,6 +80,7 @@ public boolean isModuleInDistRepo(String module) {
* @param module input module.
* @return import statement.
*/
@Nullable
public String getImportStatement(String module) {
String importStatement = "import ";
String langModule = LANG + "." + module;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package io.ballerina.shell.utils;

import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
Expand All @@ -31,7 +33,7 @@ public class QuotedImport {
private final String orgName;
private final List<Identifier> moduleNames;

public QuotedImport(String orgName, List<String> moduleNames) {
public QuotedImport(@Nullable String orgName, List<String> moduleNames) {
this.orgName = orgName;
this.moduleNames = moduleNames.stream()
.map(Identifier::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.ballerina.tools.text.LinePosition;
import io.ballerina.tools.text.LineRange;
import io.ballerina.tools.text.TextDocument;
import org.jetbrains.annotations.Nullable;

import java.util.StringJoiner;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -152,7 +153,7 @@ public static String encodeIdentifier(String string) {
* @param object Object to convert.
* @return Converted string.
*/
public static String getExpressionStringValue(Object object) {
public static String getExpressionStringValue(@Nullable Object object) {
return io.ballerina.runtime.api.utils.StringUtils.getExpressionStringValue(object);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
requires io.ballerina.runtime;
requires io.ballerina.identifier;
requires compiler;
requires static org.jetbrains.annotations;

exports io.ballerina.shell.exceptions;
exports io.ballerina.shell.invoker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package io.ballerina.shell.rt;

import org.jetbrains.annotations.Nullable;

import java.util.HashMap;

/**
Expand All @@ -44,6 +46,7 @@ private InvokerMemory() {
* @param name Name of the variables.
* @return The value of the variable.
*/
@Nullable
public static Object recall(String contextId, String name) {
if (memory.containsKey(contextId)) {
return memory.get(contextId).getOrDefault(quoted(name.trim()), null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module io.ballerina.shell.rt {
requires static org.jetbrains.annotations;
exports io.ballerina.shell.rt;
}
Loading
Loading