Skip to content

Commit

Permalink
Merge pull request #43419 from lochana-chathura/nutcracker-2
Browse files Browse the repository at this point in the history
Sync nutcracker branch with master
  • Loading branch information
lochana-chathura authored Sep 30, 2024
2 parents 41240b5 + 0e984bb commit efc16e5
Show file tree
Hide file tree
Showing 1,555 changed files with 15,842 additions and 16,486 deletions.
35 changes: 24 additions & 11 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@

# See: https://help.github.com/articles/about-codeowners/

* @gimantha

# Components
/compiler/ @sameerajayasoma @hasithaa
/langlib/ @sameerajayasoma @hasithaa
/semtypes/ @sameerajayasoma @hasithaa
/language-server/ @mohanvive @IMS94
/ballerina-shell/ @mohanvive
/compiler/ @sameerajayasoma @hasithaa @gimantha @MaryamZi
/ballerina-shell/ @KavinduZoysa
/build-config/ @keizer619
/bvm/ @warunalakshitha
/observelib/ @nadundesilva
/cli/ @hevayo
/distribution/ @hevayo
/misc/ @hevayo
/project-api/ @hevayo @sameerajayasoma
/cli/ @azinneera
/distribution/ @keizer619
/gradle/ @keizer619
/langlib/ @sameerajayasoma @hasithaa @gimantha @MaryamZi
/semtypes/ @gimantha @MaryamZi
/language-server/ @KavinduZoysa
/misc/ballerina-bindgen/ @warunalakshitha
/misc/compiler-plugins/ @azinneera
/misc/debug-adapter/ @NipunaRanasinghe
/misc/docerina/ @keizer619
/misc/identifier-util/ @warunalakshitha
/misc/json-to-record-converter/ @NipunaRanasinghe
/misc/semver-checker/ @NipunaRanasinghe
/misc/testerina/ @azinneera @Dilhasha
/misc/xml-to-record-converter/ @NipunaRanasinghe
/project-api/ @azinneera @sameerajayasoma
/performance/ @anuruddhal
/tests/ @gimantha @MaryamZi @KavinduZoysa @warunalakshitha @azinneera

# CODEOWNERS file
/.github/CODEOWNERS @sameerajayasoma @hasithaa @anupama-pathirage @warunalakshitha @mohanvive @manuranga @hevayo
/.github/CODEOWNERS @sameerajayasoma @gimantha @MaryamZi @hasithaa
19 changes: 0 additions & 19 deletions .github/workflows/stale_check.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
*
* @since 2.0.0
*/
public class ReplShellApplication {
public final class ReplShellApplication {

private ReplShellApplication() {
}

/**
* Executes the repl shell.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;

import java.io.PrintWriter;

/**
* Terminal adapter which encapsulates Jline.
*
Expand Down Expand Up @@ -56,10 +58,12 @@ public String readLine(String prefix, String postfix) throws ShellExitException
}
}

@SuppressWarnings("resource")
@Override
public void println(String text) {
lineReader.getTerminal().writer().println(text);
lineReader.getTerminal().writer().flush();
PrintWriter writer = lineReader.getTerminal().writer();
writer.println(text);
writer.flush();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

package io.ballerina.shell.cli.jline.parser;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

/**
* State machine implementation for ballerina parser.
Expand Down Expand Up @@ -65,12 +66,12 @@ public class ParserStateMachine {
CLOSE_PAREN, OPEN_PAREN,
CLOSE_SQ_BR, OPEN_SQ_BR);

private final Stack<Character> stack;
private final Deque<Character> stack;
private ParserState state;

public ParserStateMachine() {
this.state = ParserState.NORMAL;
this.stack = new Stack<>();
this.stack = new ArrayDeque<>();
}

public void feed(char character) {
Expand Down Expand Up @@ -138,9 +139,9 @@ private void normalStateOrAfterOperator(char character) {
case CLOSE_CURLY:
case CLOSE_PAREN:
case CLOSE_SQ_BR:
if (!stack.empty() && OPEN_BRACKETS.get(character).equals(stack.peek())) {
if (!stack.isEmpty() && OPEN_BRACKETS.get(character).equals(stack.peek())) {
stack.pop();
if (!stack.empty() && stack.peek() == BACKTICK) {
if (!stack.isEmpty() && stack.peek() == BACKTICK) {
state = ParserState.IN_TEMPLATE;
}
break;
Expand Down Expand Up @@ -238,7 +239,7 @@ private void inTemplateState(char character) {
state = ParserState.IN_TEMPLATE_AFTER_DOLLAR;
break;
case BACKTICK:
if (!stack.empty() && stack.peek() == BACKTICK) {
if (!stack.isEmpty() && stack.peek() == BACKTICK) {
state = ParserState.NORMAL;
stack.pop();
break;
Expand Down Expand Up @@ -310,6 +311,6 @@ public boolean isIncomplete() {
return true;
}
// Otherwise, all brackets/backticks are closed is completion
return !stack.empty();
return !stack.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
*
* @since 2.0.0
*/
public class FileUtils {
public final class FileUtils {

private static final String SPECIAL_DELIMITER = "\\A";

private FileUtils() {
}

/**
* Reads the file content from the resources.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.ballerina.shell.invoker.classload.context.ClassLoadContext;
import io.ballerina.shell.snippet.Snippet;
import io.ballerina.shell.utils.StringUtils;
import io.ballerina.tools.diagnostics.Diagnostic;
import io.ballerina.tools.diagnostics.DiagnosticSeverity;

import java.io.File;
Expand Down Expand Up @@ -277,7 +278,7 @@ protected PackageCompilation compile(Project project) throws InvokerException {
PackageCompilation packageCompilation = project.currentPackage().getCompilation();
DiagnosticResult diagnosticResult = packageCompilation.diagnosticResult();

for (io.ballerina.tools.diagnostics.Diagnostic diagnostic : diagnosticResult.diagnostics()) {
for (Diagnostic diagnostic : diagnosticResult.diagnostics()) {
DiagnosticSeverity severity = diagnostic.diagnosticInfo().severity();
if (severity == DiagnosticSeverity.ERROR) {
containErrors = true;
Expand Down Expand Up @@ -329,7 +330,7 @@ protected void compileImportStatement(String importStatement) throws InvokerExce
* @return Whether the compilation contains MODULE_NOT_FOUND error.
*/
private boolean containsModuleNotFoundError(PackageCompilation compilation) {
for (io.ballerina.tools.diagnostics.Diagnostic diagnostic : compilation.diagnosticResult().diagnostics()) {
for (Diagnostic diagnostic : compilation.diagnosticResult().diagnostics()) {
if (diagnostic.diagnosticInfo().code().equals(MODULE_NOT_FOUND_CODE)) {
return true;
}
Expand Down Expand Up @@ -435,9 +436,9 @@ protected Object invokeScheduledMethod(ClassLoader classLoader, String className
// Unexpected runtime error
throw new InvokerPanicException(panic);
}
if (result instanceof Throwable) {
if (result instanceof Throwable throwable) {
// Function returned error (panic)
throw new InvokerPanicException((Throwable) result);
throw new InvokerPanicException(throwable);
}
return result;
} catch (ClassNotFoundException e) {
Expand Down Expand Up @@ -512,7 +513,7 @@ private Function<Object[], Object> createInvokerCallback(Method method) {
* @param diagnostic Diagnostic to show.
* @return The string with position highlighted.
*/
private String highlightedDiagnostic(Module module, io.ballerina.tools.diagnostics.Diagnostic diagnostic) {
private String highlightedDiagnostic(Module module, Diagnostic diagnostic) {
Optional<DocumentId> documentId = module.documentIds().stream().findFirst();
Document document = module.document(documentId.orElseThrow());
return StringUtils.highlightDiagnostic(document.textDocument(), diagnostic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,25 +227,23 @@ public PackageCompilation getCompilation(Collection<Snippet> newSnippets) throws
// Others are processed later.
for (Snippet newSnippet : newSnippets) {

if (newSnippet instanceof ImportDeclarationSnippet) {
processImport((ImportDeclarationSnippet) newSnippet);
if (newSnippet instanceof ImportDeclarationSnippet importSnippet) {
processImport(importSnippet);

} else if (newSnippet instanceof VariableDeclarationSnippet) {
VariableDeclarationSnippet varDclnSnippet = (VariableDeclarationSnippet) newSnippet;
} else if (newSnippet instanceof VariableDeclarationSnippet varDclnSnippet) {
variableNames.addAll(varDclnSnippet.names());
variableDeclarations.put(varDclnSnippet, varDclnSnippet.names());

} else if (newSnippet instanceof ModuleMemberDeclarationSnippet) {
ModuleMemberDeclarationSnippet moduleDclnSnippet = (ModuleMemberDeclarationSnippet) newSnippet;
} else if (newSnippet instanceof ModuleMemberDeclarationSnippet moduleDclnSnippet) {
Identifier moduleDeclarationName = moduleDclnSnippet.name();
moduleDeclarations.put(moduleDeclarationName, moduleDclnSnippet);
availableModuleDeclarations.put(moduleDeclarationName, moduleDclnSnippet);
Set<Identifier> usedPrefixes = newSnippet.usedImports().stream()
.map(Identifier::new).collect(Collectors.toSet());
newImports.put(moduleDeclarationName, usedPrefixes);

} else if (newSnippet instanceof ExecutableSnippet) {
executableSnippets.add((ExecutableSnippet) newSnippet);
} else if (newSnippet instanceof ExecutableSnippet executableSnippet) {
executableSnippets.add(executableSnippet);

} else {
throw new UnsupportedOperationException("Unimplemented snippet category.");
Expand Down Expand Up @@ -560,7 +558,7 @@ private Collection<GlobalVariableSymbol> globalVariableSymbols(Project project,
return compilation.getSemanticModel(moduleId).moduleSymbols().stream()
.filter(s -> s instanceof VariableSymbol || s instanceof FunctionSymbol)
.map(GlobalVariableSymbol::fromSymbol)
.collect(Collectors.toList());
.toList();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public static GlobalVariableSymbol fromSymbol(Symbol symbol) {
if (symbol.getName().isEmpty()) {
throw new UnsupportedOperationException("Cannot create a global symbol without name");
}
if (symbol instanceof VariableSymbol) {
return new GlobalVariableSymbol(symbol.getName().get(), ((VariableSymbol) symbol).typeDescriptor());
} else if (symbol instanceof FunctionSymbol) {
return new GlobalVariableSymbol(symbol.getName().get(), ((FunctionSymbol) symbol).typeDescriptor());
if (symbol instanceof VariableSymbol variableSymbol) {
return new GlobalVariableSymbol(symbol.getName().get(), variableSymbol.typeDescriptor());
} else if (symbol instanceof FunctionSymbol functionSymbol) {
return new GlobalVariableSymbol(symbol.getName().get(), functionSymbol.typeDescriptor());
}
throw new UnsupportedOperationException("Symbol type not supported for creating global variable.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Imports that were stored to be able to search with the prefix.
Expand Down Expand Up @@ -364,7 +363,7 @@ private static List<String> getBallerinaKeywords() {
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
.toList();
} catch (ClassNotFoundException e) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @since 2.0.0
*/
public class ParserConstants {
public final class ParserConstants {

public static final String WRAPPER_PREFIX = "__shell_wrapper__";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public Collection<Node> parseDeclarations(String source) throws TreeParserExcept
* Whether the declaration is allowed to be parsed.
*/
private boolean isModuleDeclarationAllowed(ModuleMemberDeclarationNode declarationNode) {
if (declarationNode instanceof FunctionDefinitionNode) {
String functionName = ((FunctionDefinitionNode) declarationNode).functionName().text();
if (declarationNode instanceof FunctionDefinitionNode functionDefinitionNode) {
String functionName = functionDefinitionNode.functionName().text();
if (ParserConstants.isFunctionNameRestricted(functionName)) {
addWarnDiagnostic("Found '" + functionName + "' function in the declarations.\n" +
"Discarded '" + functionName + "' function without loading.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ public Collection<Node> parse(String source) throws ParserTrialFailedException {
ModulePartNode node = tree.rootNode();
NodeList<ModuleMemberDeclarationNode> members = node.members();
Iterator<ImportDeclarationNode> importIterator = node.imports().iterator();
Iterator memberIterator = members.iterator();
Iterator<ModuleMemberDeclarationNode> memberIterator = members.iterator();
while (importIterator.hasNext()) {
nodes.add(importIterator.next());
}
while (memberIterator.hasNext()) {
ModuleMemberDeclarationNode dclnNode = (ModuleMemberDeclarationNode) memberIterator.next();
ModuleMemberDeclarationNode dclnNode = memberIterator.next();
validateModuleDeclaration(dclnNode);
nodes.add(dclnNode);
}
return nodes;
}

private void validateModuleDeclaration(ModuleMemberDeclarationNode declarationNode) {
if (declarationNode instanceof FunctionDefinitionNode) {
String functionName = ((FunctionDefinitionNode) declarationNode).functionName().text();
if (declarationNode instanceof FunctionDefinitionNode functionDefinitionNode) {
String functionName = functionDefinitionNode.functionName().text();
if (ParserConstants.isFunctionNameRestricted(functionName)) {
String message = "Function name " + "'" + functionName + "'" + " not allowed in Ballerina Shell.\n";
throw new InvalidMethodException(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

import io.ballerina.shell.exceptions.PreprocessorException;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.List;
import java.util.Stack;

/**
* Preprocessor to split the input into several statements
Expand Down Expand Up @@ -51,7 +52,7 @@ public Collection<String> process(String input) throws PreprocessorException {
List<String> snippets = new ArrayList<>();
StringBuilder builder = new StringBuilder();

Stack<Character> brackets = new Stack<>();
Deque<Character> brackets = new ArrayDeque<>();

boolean isInBacktickLiteral = false;
boolean isInQuoteLiteral = false;
Expand Down
Loading

0 comments on commit efc16e5

Please sign in to comment.