Skip to content

Commit

Permalink
Add @nullable annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow-Devil committed Oct 4, 2024
1 parent ddd9696 commit 2e0c066
Show file tree
Hide file tree
Showing 831 changed files with 3,301 additions and 1,153 deletions.
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 Down
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 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 as a complete statement.
Expand All @@ -29,6 +30,7 @@
*/
public class StatementValidator implements Validator {

@Nullable
private Validator nextInValidator;

public StatementValidator() {
Expand Down
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.ballerina.runtime.profiler.util.ProfilerException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -329,6 +330,7 @@ String getBalJarArgs() {
return balJarArgs;
}

@Nullable
private String getFileNameWithoutExtension(String balJarName) {
if (null != balJarName) {
int index = FilenameUtils.indexOfExtension(balJarName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.ballerina.runtime.profiler.Main;
import io.ballerina.runtime.profiler.util.Constants;
import io.ballerina.runtime.profiler.util.ProfilerException;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
Expand Down Expand Up @@ -85,6 +86,7 @@ public void invokeMethods(String debugArg) throws IOException, InterruptedExcept
process.waitFor();
}

@Nullable
public String mainClassFinder(URLClassLoader manifestClassLoader) {
try {
URL manifestURL = manifestClassLoader.findResource("META-INF/MANIFEST.MF");
Expand Down
Loading

0 comments on commit 2e0c066

Please sign in to comment.