From 6e2fc184b85e6c1d9c279a0fae9161cecad01208 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Fri, 4 Oct 2024 19:15:19 +0200 Subject: [PATCH 01/12] Add @Nullable annotations --- .../shell/cli/BShellConfiguration.java | 2 + .../cli/handlers/help/BbeTopicsProvider.java | 2 + .../jline/validator/ExpressionValidator.java | 2 + .../validator/ModuleMemberValidator.java | 2 + .../jline/validator/StatementValidator.java | 2 + .../shell-cli/src/main/java/module-info.java | 1 + .../io/ballerina/shell/EvaluatorImpl.java | 2 + .../ballerina/shell/NotebookReturnValue.java | 5 +- .../io/ballerina/shell/ShellReturnValue.java | 5 +- .../invoker/classload/ClassLoadInvoker.java | 2 + .../invoker/classload/ImportsManager.java | 2 + .../classload/context/ClassLoadContext.java | 9 +- .../shell/snippet/SnippetSubKind.java | 3 + .../snippet/factory/BasicSnippetFactory.java | 6 + .../ballerina/shell/utils/ModuleImporter.java | 2 + .../ballerina/shell/utils/QuotedImport.java | 4 +- .../io/ballerina/shell/utils/StringUtils.java | 3 +- .../shell-core/src/main/java/module-info.java | 1 + .../io/ballerina/shell/rt/InvokerMemory.java | 3 + .../shell-rt/src/main/java/module-info.java | 1 + .../ballerina/runtime/profiler/Profiler.java | 2 + .../codegen/ProfilerMethodWrapper.java | 2 + .../src/main/java/module-info.java | 1 + .../java/io/ballerina/runtime/api/Future.java | 4 +- .../java/io/ballerina/runtime/api/Module.java | 4 +- .../io/ballerina/runtime/api/Runtime.java | 19 +- .../runtime/api/async/StrandMetadata.java | 4 +- .../runtime/api/creators/ErrorCreator.java | 12 +- .../runtime/api/creators/TypeCreator.java | 16 +- .../runtime/api/creators/ValueCreator.java | 9 +- .../runtime/api/types/Parameter.java | 4 +- .../io/ballerina/runtime/api/types/Type.java | 3 + .../runtime/api/utils/JsonUtils.java | 5 + .../runtime/api/utils/StringUtils.java | 6 + .../ballerina/runtime/api/values/BArray.java | 5 +- .../io/ballerina/runtime/api/values/BMap.java | 3 +- .../ballerina/runtime/api/values/BValue.java | 3 +- .../runtime/internal/BalRuntime.java | 8 +- .../internal/BallerinaXmlSerializer.java | 3 + .../runtime/internal/CloneUtils.java | 3 + .../runtime/internal/FloatUtils.java | 2 + .../runtime/internal/JsonInternalUtils.java | 13 +- .../runtime/internal/JsonParser.java | 14 +- .../runtime/internal/StateMachine.java | 17 ++ .../runtime/internal/TableOmDataSource.java | 3 +- .../runtime/internal/TableUtils.java | 3 +- .../runtime/internal/TypeChecker.java | 33 ++-- .../runtime/internal/TypeConverter.java | 13 +- .../runtime/internal/ValueConverter.java | 4 + .../runtime/internal/XmlFactory.java | 7 +- .../runtime/internal/XmlTreeBuilder.java | 2 + .../runtime/internal/cli/CliSpec.java | 3 +- .../internal/configurable/ConfigResolver.java | 2 + .../internal/configurable/VariableKey.java | 3 +- .../configurable/providers/ConfigDetails.java | 4 +- .../providers/cli/CliProvider.java | 5 +- .../providers/env/EnvVarProvider.java | 5 +- .../providers/toml/ConfigValueCreator.java | 2 + .../providers/toml/ModuleInfo.java | 3 +- .../providers/toml/TomlProvider.java | 5 + .../configurable/providers/toml/Utils.java | 4 + .../diagnostics/RuntimeDiagnostic.java | 2 + .../RuntimeDiagnosticLocation.java | 3 + .../diagnostics/RuntimeDiagnosticLog.java | 5 +- .../runtime/internal/launch/LaunchUtils.java | 2 + .../runtime/internal/regexp/TreeBuilder.java | 2 + .../internal/regexp/TreeTraverser.java | 3 + .../internal/scheduling/AsyncUtils.java | 3 +- .../internal/scheduling/Scheduler.java | 21 +- .../runtime/internal/scheduling/Strand.java | 14 +- .../internal/scheduling/WDChannels.java | 10 +- .../scheduling/WorkerDataChannel.java | 8 + .../internal/types/BAnnotatableType.java | 3 +- .../runtime/internal/types/BAnyType.java | 3 + .../runtime/internal/types/BAnydataType.java | 3 + .../runtime/internal/types/BErrorType.java | 3 + .../runtime/internal/types/BFiniteType.java | 3 + .../runtime/internal/types/BFunctionType.java | 5 + .../runtime/internal/types/BFutureType.java | 3 + .../runtime/internal/types/BHandleType.java | 3 + .../internal/types/BIntersectionType.java | 3 +- .../runtime/internal/types/BIteratorType.java | 3 + .../runtime/internal/types/BJsonType.java | 2 + .../runtime/internal/types/BMapType.java | 3 +- .../runtime/internal/types/BNullType.java | 3 + .../runtime/internal/types/BObjectType.java | 2 + .../runtime/internal/types/BReadonlyType.java | 3 + .../runtime/internal/types/BRecordType.java | 5 +- .../runtime/internal/types/BStreamType.java | 6 +- .../runtime/internal/types/BTupleType.java | 6 +- .../runtime/internal/types/BType.java | 3 +- .../runtime/internal/types/BUnionType.java | 5 +- .../internal/types/BXmlAttributesType.java | 3 + .../runtime/internal/types/BXmlType.java | 2 + .../runtime/internal/util/StringUtils.java | 8 +- .../internal/values/AbstractArrayValue.java | 2 + .../internal/values/AbstractObjectValue.java | 2 + .../internal/values/ArrayValueImpl.java | 9 +- .../values/AttributeMapValueImpl.java | 2 + .../internal/values/BmpStringValue.java | 3 + .../runtime/internal/values/DecimalValue.java | 3 +- .../runtime/internal/values/ErrorValue.java | 7 +- .../runtime/internal/values/FPValue.java | 3 +- .../runtime/internal/values/FutureValue.java | 5 +- .../runtime/internal/values/HandleValue.java | 4 +- .../values/ListInitialValueEntry.java | 3 +- .../runtime/internal/values/MapValueImpl.java | 7 +- .../internal/values/NonBmpStringValue.java | 3 + .../internal/values/ReadOnlyUtils.java | 2 + .../internal/values/RegExpDisjunction.java | 3 +- .../runtime/internal/values/RegExpValue.java | 3 +- .../runtime/internal/values/StreamValue.java | 4 +- .../internal/values/TableValueImpl.java | 10 +- .../internal/values/TupleValueImpl.java | 3 + .../internal/values/TypedescValueImpl.java | 3 +- .../runtime/internal/values/ValueCreator.java | 6 +- .../runtime/internal/values/XmlItem.java | 9 +- .../internal/values/XmlNonElementItem.java | 10 +- .../runtime/internal/values/XmlQName.java | 4 +- .../runtime/internal/values/XmlSequence.java | 8 +- .../runtime/internal/values/XmlValue.java | 2 + .../runtime/observability/ObserveUtils.java | 4 +- .../observability/metrics/MetricId.java | 4 +- .../observability/metrics/MetricRegistry.java | 2 + .../observability/metrics/Snapshot.java | 4 +- .../metrics/StatisticConfig.java | 5 +- .../runtime/observability/tracer/BSpan.java | 3 +- .../transactions/TransactionLocalContext.java | 7 +- .../TransactionResourceManager.java | 2 + .../src/main/java/module-info.java | 1 + .../io/ballerina/cli/cmd/CommandUtil.java | 36 ++-- .../java/io/ballerina/cli/cmd/DocCommand.java | 2 + .../io/ballerina/cli/cmd/ProfileCommand.java | 4 + .../io/ballerina/cli/cmd/PullCommand.java | 5 +- .../io/ballerina/cli/cmd/PushCommand.java | 4 +- .../io/ballerina/cli/cmd/TestCommand.java | 3 +- .../cli/launcher/CustomToolClassLoader.java | 3 + .../ballerina/cli/launcher/LauncherUtils.java | 2 + .../cli/task/CreateExecutableTask.java | 4 +- .../cli/task/CreateTestExecutableTask.java | 3 + .../io/ballerina/cli/utils/FileUtils.java | 2 + .../cli/utils/GraalVMCompatibilityUtils.java | 10 +- .../io/ballerina/cli/utils/NativeUtils.java | 2 + .../io/ballerina/cli/utils/TestUtils.java | 7 +- .../src/main/java/module-info.java | 1 + .../src/main/java/module-info.java | 1 + .../central/client/CentralAPIClient.java | 20 +- .../ballerinalang/central/client/Utils.java | 9 +- .../model/PackageNameResolutionRequest.java | 6 +- .../model/PackageNameResolutionResponse.java | 5 +- .../api/impl/BallerinaSemanticModel.java | 2 + .../api/impl/EnvironmentResolver.java | 4 +- .../compiler/api/impl/ExpectedTypeFinder.java | 4 +- .../api/impl/LangLibFunctionBinder.java | 4 +- .../compiler/api/impl/LangLibrary.java | 3 +- .../compiler/api/impl/NodeFinder.java | 5 +- .../compiler/api/impl/ReferenceFinder.java | 3 +- .../compiler/api/impl/SymbolFactory.java | 7 + .../compiler/api/impl/SymbolFinder.java | 6 +- .../compiler/api/impl/TypeParamFinder.java | 2 + .../compiler/api/impl/TypeParamResolver.java | 4 +- .../api/impl/symbols/AbstractTypeSymbol.java | 4 +- .../impl/symbols/BallerinaConstantSymbol.java | 2 + .../symbols/BallerinaParameterSymbol.java | 8 +- .../api/impl/symbols/BallerinaSymbol.java | 9 +- .../BallerinaTypeReferenceTypeSymbol.java | 2 + .../api/impl/symbols/TypesFactory.java | 8 +- .../builders/BallerinaArrayTypeBuilder.java | 2 + .../builders/BallerinaErrorTypeBuilder.java | 2 + .../BallerinaFunctionTypeBuilder.java | 8 + .../builders/BallerinaFutureTypeBuilder.java | 3 + .../builders/BallerinaMapTypeBuilder.java | 3 + .../builders/BallerinaObjectTypeBuilder.java | 2 + .../builders/BallerinaRecordTypeBuilder.java | 3 + .../BallerinaSingletonTypeBuilder.java | 3 + .../builders/BallerinaStreamTypeBuilder.java | 3 + .../builders/BallerinaTableTypeBuilder.java | 3 + .../builders/BallerinaTupleTypeBuilder.java | 3 + .../BallerinaTypeDescTypeBuilder.java | 3 + .../builders/BallerinaXMLTypeBuilder.java | 3 + .../compiler/api/impl/util/SymbolUtils.java | 2 + .../ballerina/projects/BalToolsManifest.java | 9 +- .../io/ballerina/projects/BalaWriter.java | 3 + .../io/ballerina/projects/BuildOptions.java | 30 +-- .../java/io/ballerina/projects/BuildTool.java | 9 +- .../projects/CodeGeneratorResult.java | 3 +- .../projects/CodeModifierResult.java | 3 +- .../io/ballerina/projects/ConfigReader.java | 4 +- .../ballerina/projects/DependencyGraph.java | 7 +- .../projects/DependencyManifest.java | 15 +- .../ballerina/projects/DocumentContext.java | 4 + .../io/ballerina/projects/DocumentId.java | 4 +- .../io/ballerina/projects/EmitResult.java | 4 +- .../ballerina/projects/JBallerinaBackend.java | 4 + .../java/io/ballerina/projects/Module.java | 3 + .../io/ballerina/projects/ModuleConfig.java | 6 +- .../io/ballerina/projects/ModuleContext.java | 7 +- .../io/ballerina/projects/ModuleName.java | 6 +- .../io/ballerina/projects/NullBackend.java | 9 + .../java/io/ballerina/projects/Package.java | 10 +- .../io/ballerina/projects/PackageConfig.java | 11 +- .../io/ballerina/projects/PackageContext.java | 15 +- .../ballerina/projects/PackageDescriptor.java | 11 +- .../ballerina/projects/PackageManifest.java | 27 +-- .../io/ballerina/projects/PackageName.java | 4 +- .../io/ballerina/projects/PackageOrg.java | 3 +- .../ballerina/projects/PackageResolution.java | 3 +- .../io/ballerina/projects/PackageVersion.java | 4 +- .../io/ballerina/projects/ResourceConfig.java | 4 +- .../java/io/ballerina/projects/Settings.java | 3 +- .../environment/ModuleLoadRequest.java | 5 +- .../environment/PackageMetadataResponse.java | 7 +- .../environment/ResolutionResponse.java | 3 +- .../internal/BalToolsManifestBuilder.java | 2 + .../projects/internal/BalaFiles.java | 9 +- .../projects/internal/BlendedManifest.java | 2 + .../internal/DependencyManifestBuilder.java | 6 +- .../internal/ImportModuleResponse.java | 4 +- .../projects/internal/ManifestBuilder.java | 22 ++- .../projects/internal/ManifestUtils.java | 2 + .../projects/internal/ModuleData.java | 4 +- .../projects/internal/ModuleResolver.java | 7 +- .../internal/PackageConfigCreator.java | 3 +- .../projects/internal/PackageData.java | 13 +- .../PackageDependencyGraphBuilder.java | 2 + .../projects/internal/ProjectFiles.java | 2 + .../internal/ProvidedResourceConfig.java | 3 +- .../projects/internal/ResolutionEngine.java | 4 +- .../projects/internal/SettingsBuilder.java | 2 + .../bala/adaptors/JsonCollectionsAdaptor.java | 2 + .../bala/adaptors/JsonStringsAdaptor.java | 2 + .../internal/configschema/TypeConverter.java | 2 + .../internal/model/BalToolDescriptor.java | 7 +- .../projects/internal/model/BuildJson.java | 3 +- .../model/CompilerPluginDescriptor.java | 8 +- .../adaptors/JsonCollectionsAdaptor.java | 2 + .../model/adaptors/JsonStringsAdaptor.java | 2 + .../AbstractPackageRepository.java | 5 +- .../repositories/FileSystemRepository.java | 4 +- .../repositories/MavenPackageRepository.java | 8 +- .../CodeActionExecutionContextImpl.java | 7 +- .../projects/util/BuildToolUtils.java | 5 +- .../io/ballerina/projects/util/FileUtils.java | 3 + .../ballerina/projects/util/ProjectUtils.java | 16 +- .../src/main/java/module-info.java | 1 + .../model/elements/AttachPoint.java | 3 + .../model/elements/MarkdownDocAttachment.java | 7 +- .../model/elements/PackageID.java | 7 +- .../model/tree/OperatorKind.java | 3 + .../AggregatedPackageRepository.java | 3 + .../HierarchicalPackageRepository.java | 3 + .../fs/GeneralFSPackageRepository.java | 5 +- .../spi/SystemPackageRepositoryProvider.java | 2 + .../ballerinalang/toml/model/Dependency.java | 2 + .../toml/model/DependencyMetadata.java | 9 +- .../ballerinalang/toml/util/PathUtils.java | 3 + .../toml/util/SingletonStack.java | 3 + .../util/diagnostic/DiagnosticLog.java | 3 +- .../compiler/BIRPackageSymbolEnter.java | 8 +- .../compiler/FileSystemProgramDirectory.java | 2 + .../compiler/FileSystemProjectDirectory.java | 2 + .../ballerinalang/compiler/PackageCache.java | 2 + .../compiler/SourceDirectoryManager.java | 3 + .../ballerinalang/compiler/bir/BIRGen.java | 16 +- .../ballerinalang/compiler/bir/BIRGenEnv.java | 9 +- .../compiler/bir/codegen/JvmCastGen.java | 2 + .../compiler/bir/codegen/JvmCodeGenUtil.java | 4 +- .../compiler/bir/codegen/JvmErrorGen.java | 2 + .../bir/codegen/JvmObservabilityGen.java | 29 +-- .../compiler/bir/codegen/JvmPackageGen.java | 8 +- .../bir/codegen/JvmTerminatorGen.java | 5 +- .../compiler/bir/codegen/JvmTypeGen.java | 5 +- .../bir/codegen/interop/AnnotationProc.java | 5 + .../bir/codegen/interop/JInterop.java | 2 + .../bir/codegen/interop/JMethodResolver.java | 4 + .../codegen/interop/ParamTypeConstraint.java | 4 +- .../bir/codegen/methodgen/FrameClassGen.java | 3 +- .../bir/codegen/methodgen/InitMethodGen.java | 4 +- .../bir/codegen/methodgen/LambdaGen.java | 3 +- .../bir/codegen/methodgen/MethodGen.java | 8 +- .../bir/codegen/methodgen/MethodGenUtils.java | 3 +- .../bir/codegen/model/JIConstructorCall.java | 3 + .../bir/codegen/model/JIMethodCLICall.java | 3 +- .../bir/codegen/model/JIMethodCall.java | 5 +- .../compiler/bir/codegen/model/JMethod.java | 5 +- .../codegen/model/JMethodCallInstruction.java | 3 +- .../optimizer/LargeMethodOptimizer.java | 5 +- .../codegen/split/values/JvmRecordGen.java | 3 +- .../bir/model/BIRAbstractInstruction.java | 2 + .../compiler/bir/model/BIRNode.java | 50 +++-- .../compiler/bir/model/BIRNonTerminator.java | 14 +- .../compiler/bir/model/BIROperand.java | 4 +- .../compiler/bir/model/BIRTerminator.java | 29 +-- .../bir/optimizer/BIRBasicBlockOptimizer.java | 3 +- .../compiler/bir/optimizer/BIROptimizer.java | 3 +- .../optimizer/BIRRecordValueOptimizer.java | 3 + .../bir/writer/BIRInstructionWriter.java | 3 +- .../compiler/bir/writer/CPEntry.java | 3 +- .../compiler/desugar/ASTBuilderUtil.java | 49 ++--- .../compiler/desugar/AnnotationDesugar.java | 6 + .../compiler/desugar/ClassClosureDesugar.java | 12 +- .../compiler/desugar/ClosureDesugar.java | 8 +- .../compiler/desugar/ClosureGenerator.java | 6 +- .../compiler/desugar/ConstantPropagation.java | 3 + .../desugar/DeclarativeAuthDesugar.java | 2 + .../compiler/desugar/Desugar.java | 84 +++++--- .../compiler/desugar/MockDesugar.java | 8 + .../compiler/desugar/QueryDesugar.java | 9 +- .../compiler/diagnostic/BLangDiagnostic.java | 3 +- .../diagnostic/BLangDiagnosticLocation.java | 5 +- .../diagnostic/BLangDiagnosticLog.java | 17 +- .../diagnostic/CompilerBadSadDiagnostic.java | 2 + .../compiler/packaging/Patten.java | 3 +- .../compiler/packaging/repo/BinaryRepo.java | 3 +- .../compiler/packaging/repo/HomeRepo.java | 3 +- .../compiler/packaging/repo/NonSysRepo.java | 3 +- .../compiler/packaging/repo/ObjRepo.java | 3 +- .../compiler/packaging/repo/PathBalaRepo.java | 8 +- .../packaging/repo/ProjectSourceRepo.java | 3 +- .../compiler/parser/BLangNodeBuilder.java | 49 +++-- .../compiler/parser/NodeCloner.java | 4 + .../semantics/analyzer/CodeAnalyzer.java | 10 +- .../analyzer/ConstantTypeChecker.java | 19 +- .../analyzer/ConstantValueResolver.java | 20 +- .../semantics/analyzer/DataflowAnalyzer.java | 16 +- .../analyzer/DocumentationAnalyzer.java | 6 +- .../semantics/analyzer/IsolationAnalyzer.java | 25 +-- .../analyzer/MainFunctionValidator.java | 7 +- .../semantics/analyzer/QueryTypeChecker.java | 3 + .../analyzer/ReachabilityAnalyzer.java | 3 +- .../semantics/analyzer/SemanticAnalyzer.java | 13 +- .../semantics/analyzer/SymbolEnter.java | 11 +- .../semantics/analyzer/SymbolResolver.java | 7 +- .../semantics/analyzer/TypeChecker.java | 32 +-- .../semantics/analyzer/TypeParamAnalyzer.java | 6 +- .../semantics/analyzer/TypeResolver.java | 7 +- .../compiler/semantics/analyzer/Types.java | 29 ++- .../cyclefind/GlobalVariableRefAnalyzer.java | 3 + .../compiler/semantics/model/Scope.java | 3 +- .../compiler/semantics/model/SymbolEnv.java | 14 +- .../symbols/BAnnotationAttachmentSymbol.java | 5 +- .../model/symbols/BAttachedFunction.java | 3 +- .../model/symbols/BConstantSymbol.java | 10 +- .../model/symbols/BErrorTypeSymbol.java | 5 +- .../model/symbols/BInvokableSymbol.java | 6 +- .../model/symbols/BInvokableTypeSymbol.java | 6 +- .../model/symbols/BOperatorSymbol.java | 3 +- .../model/symbols/BPackageSymbol.java | 4 +- .../model/symbols/BRecordTypeSymbol.java | 5 +- .../model/symbols/BResourceFunction.java | 3 +- .../model/symbols/BServiceSymbol.java | 7 +- .../model/symbols/BTypeDefinitionSymbol.java | 2 + .../semantics/model/symbols/BTypeSymbol.java | 5 +- .../semantics/model/symbols/BVarSymbol.java | 11 +- .../model/symbols/BXMLAttributeSymbol.java | 2 + .../semantics/model/symbols/BXMLNSSymbol.java | 4 +- .../semantics/model/symbols/Symbols.java | 68 ++++--- .../semantics/model/types/BAnyType.java | 7 +- .../semantics/model/types/BAnydataType.java | 3 +- .../semantics/model/types/BArrayType.java | 6 +- .../semantics/model/types/BErrorType.java | 3 +- .../semantics/model/types/BField.java | 3 +- .../semantics/model/types/BFiniteType.java | 3 +- .../semantics/model/types/BFutureType.java | 5 +- .../semantics/model/types/BHandleType.java | 3 +- .../model/types/BIntersectionType.java | 3 +- .../semantics/model/types/BInvokableType.java | 8 +- .../semantics/model/types/BMapType.java | 6 +- .../semantics/model/types/BObjectType.java | 2 + .../model/types/BParameterizedType.java | 4 +- .../semantics/model/types/BReadonlyType.java | 5 +- .../semantics/model/types/BRecordType.java | 7 +- .../semantics/model/types/BStreamType.java | 4 +- .../semantics/model/types/BTableType.java | 7 +- .../semantics/model/types/BTupleType.java | 14 +- .../compiler/semantics/model/types/BType.java | 10 +- .../semantics/model/types/BTypeIdSet.java | 4 + .../model/types/BTypeReferenceType.java | 3 +- .../semantics/model/types/BTypedescType.java | 3 +- .../semantics/model/types/BUnionType.java | 12 +- .../semantics/model/types/BXMLType.java | 6 +- .../compiler/tree/BLangAnnotation.java | 3 +- .../compiler/tree/BLangConstantValue.java | 3 +- .../compiler/tree/BLangErrorVariable.java | 2 + .../compiler/tree/BLangInvokableNode.java | 2 + .../tree/BLangMarkdownDocumentation.java | 4 + .../compiler/tree/BLangNode.java | 7 +- .../compiler/tree/BLangPackage.java | 2 + .../compiler/tree/BLangService.java | 3 + .../compiler/tree/BLangVariable.java | 4 +- .../tree/OCEDynamicEnvironmentData.java | 3 + .../tree/clauses/BLangInputClause.java | 2 + .../tree/expressions/BLangBinaryExpr.java | 2 + .../BLangCollectContextInvocation.java | 2 + .../tree/expressions/BLangConstant.java | 2 + .../tree/expressions/BLangExpression.java | 2 + .../expressions/BLangFieldBasedAccess.java | 2 + .../expressions/BLangIndexBasedAccess.java | 3 +- .../tree/expressions/BLangInvocation.java | 2 + .../tree/expressions/BLangLambdaFunction.java | 2 + .../tree/expressions/BLangLiteral.java | 3 + .../tree/expressions/BLangQueryAction.java | 2 + .../tree/expressions/BLangQueryExpr.java | 3 + .../tree/expressions/BLangRecordLiteral.java | 3 + .../tree/expressions/BLangTupleVarRef.java | 2 + .../expressions/BLangXMLElementFilter.java | 8 +- .../expressions/BLangXMLNavigationAccess.java | 2 + .../tree/expressions/BLangXMLQName.java | 3 + .../statements/BLangCompoundAssignment.java | 2 + .../tree/statements/BLangForeach.java | 4 + .../compiler/tree/statements/BLangRetry.java | 2 + .../tree/statements/BLangTransaction.java | 2 + .../compiler/tree/statements/BLangWhile.java | 2 + .../compiler/tree/types/BLangErrorType.java | 2 + .../compiler/tree/types/BLangStreamType.java | 2 + .../compiler/util/CompilerContext.java | 4 +- .../compiler/util/ImmutableTypeCloner.java | 32 ++- .../ballerinalang/compiler/util/Name.java | 4 +- .../compiler/util/ProjectDirs.java | 2 + .../compiler/util/TypeDefBuilderHelper.java | 24 +-- .../ballerinalang/compiler/util/Unifier.java | 15 +- .../wso2/ballerinalang/util/RepoUtils.java | 2 + .../diagnostics/SyntaxDiagnostic.java | 2 + .../internal/parser/AbstractLexer.java | 4 +- .../internal/parser/AbstractParser.java | 7 +- .../parser/AbstractParserErrorHandler.java | 4 + .../internal/parser/BallerinaParser.java | 182 +++++++++++++----- .../parser/BallerinaParserErrorHandler.java | 3 +- .../internal/parser/DocumentationParser.java | 4 +- .../internal/parser/RegExpParser.java | 7 +- .../compiler/internal/parser/Result.java | 3 + .../internal/parser/SyntaxErrors.java | 5 +- .../compiler/internal/parser/TokenReader.java | 2 + .../compiler/internal/parser/XMLParser.java | 3 + .../parser/incremental/HybridNode.java | 7 +- .../parser/incremental/HybridNodeStorage.java | 3 + .../parser/incremental/HybridNodes.java | 4 + .../parser/incremental/HybridTokenReader.java | 2 + .../parser/incremental/IncrementalParser.java | 2 + .../parser/incremental/NodePointer.java | 3 +- .../UnmodifiedSubtreeSupplier.java | 2 + .../parser/tree/STAbstractNodeFactory.java | 2 + .../compiler/internal/parser/tree/STNode.java | 5 +- .../internal/parser/tree/STNodeFactory.java | 129 +++++++------ .../internal/parser/tree/STNodeReplacer.java | 3 + .../parser/tree/STNodeTransformer.java | 3 + .../internal/parser/tree/STTreeModifier.java | 3 + .../parser/utils/ConditionalExprResolver.java | 2 + .../internal/syntax/ExternalTreeNodeList.java | 2 + .../internal/syntax/NodeReplacer.java | 3 + .../syntax/tree/AbstractNodeFactory.java | 2 + .../tree/AnnotationAttachPointNode.java | 2 + .../tree/AnnotationDeclarationNode.java | 6 + .../compiler/syntax/tree/AnnotationNode.java | 2 + .../syntax/tree/ArrayDimensionNode.java | 2 + .../tree/BallerinaNameReferenceNode.java | 2 + .../syntax/tree/ByteArrayLiteralNode.java | 2 + .../compiler/syntax/tree/ChildNodeList.java | 2 + .../syntax/tree/ClassDefinitionNode.java | 4 + .../tree/ClientResourceAccessActionNode.java | 4 + .../syntax/tree/ConstantDeclarationNode.java | 4 + .../syntax/tree/DefaultableParameterNode.java | 2 + .../compiler/syntax/tree/DoStatementNode.java | 4 +- .../syntax/tree/EnumDeclarationNode.java | 4 + .../compiler/syntax/tree/EnumMemberNode.java | 4 + .../syntax/tree/ErrorBindingPatternNode.java | 2 + .../tree/ErrorConstructorExpressionNode.java | 2 + .../syntax/tree/ErrorMatchPatternNode.java | 2 + .../tree/ExpressionFunctionBodyNode.java | 2 + .../compiler/syntax/tree/FlushActionNode.java | 2 + .../syntax/tree/ForEachStatementNode.java | 4 +- .../syntax/tree/FunctionBodyBlockNode.java | 3 + .../syntax/tree/FunctionDefinitionNode.java | 4 +- .../syntax/tree/FunctionSignatureNode.java | 4 +- .../tree/FunctionTypeDescriptorNode.java | 2 + .../syntax/tree/IfElseStatementNode.java | 4 +- .../tree/ImplicitNewExpressionNode.java | 2 + .../syntax/tree/ImportDeclarationNode.java | 3 + .../tree/IncludedRecordParameterNode.java | 2 + .../compiler/syntax/tree/JoinClauseNode.java | 2 + .../syntax/tree/ListenerDeclarationNode.java | 4 + .../syntax/tree/LockStatementNode.java | 2 + .../syntax/tree/MarkdownCodeBlockNode.java | 2 + .../compiler/syntax/tree/MatchClauseNode.java | 2 + .../syntax/tree/MatchStatementNode.java | 2 + .../compiler/syntax/tree/MetadataNode.java | 2 + .../syntax/tree/MethodDeclarationNode.java | 2 + .../compiler/syntax/tree/Minutiae.java | 3 +- .../compiler/syntax/tree/MinutiaeList.java | 3 +- .../tree/ModuleVariableDeclarationNode.java | 5 + .../ModuleXMLNamespaceDeclarationNode.java | 3 + .../tree/NamedWorkerDeclarationNode.java | 6 +- .../compiler/syntax/tree/NodeFactory.java | 73 +++---- .../compiler/syntax/tree/NodeTransformer.java | 3 + .../compiler/syntax/tree/NonTerminalNode.java | 4 +- .../tree/ObjectConstructorExpressionNode.java | 2 + .../compiler/syntax/tree/ObjectFieldNode.java | 5 + .../syntax/tree/OnFailClauseNode.java | 2 + .../compiler/syntax/tree/OrderKeyNode.java | 2 + .../tree/ParameterizedTypeDescriptorNode.java | 2 + .../syntax/tree/QueryConstructTypeNode.java | 2 + .../syntax/tree/QueryExpressionNode.java | 3 + .../syntax/tree/ReAtomQuantifierNode.java | 2 + .../syntax/tree/ReBracedQuantifierNode.java | 2 + .../syntax/tree/ReCapturingGroupsNode.java | 2 + ...ReCharSetRangeNoDashWithReCharSetNode.java | 2 + .../tree/ReCharSetRangeWithReCharSetNode.java | 2 + .../syntax/tree/ReCharacterClassNode.java | 3 + .../syntax/tree/ReFlagsOnOffNode.java | 3 + .../syntax/tree/ReQuantifierNode.java | 2 + .../tree/ReUnicodeGeneralCategoryNode.java | 2 + .../compiler/syntax/tree/RecordFieldNode.java | 8 +- .../tree/RecordFieldWithDefaultValueNode.java | 3 + .../syntax/tree/RecordTypeDescriptorNode.java | 2 + .../syntax/tree/RequiredParameterNode.java | 2 + .../tree/ResourcePathParameterNode.java | 3 + .../syntax/tree/RestParameterNode.java | 2 + .../syntax/tree/RetryStatementNode.java | 4 + .../syntax/tree/ReturnStatementNode.java | 2 + .../syntax/tree/RollbackStatementNode.java | 2 + .../syntax/tree/ServiceDeclarationNode.java | 4 + .../syntax/tree/SpecificFieldNode.java | 4 + .../syntax/tree/StreamTypeDescriptorNode.java | 2 + .../syntax/tree/StreamTypeParamsNode.java | 3 + .../compiler/syntax/tree/SyntaxTree.java | 5 +- .../tree/TableConstructorExpressionNode.java | 2 + .../syntax/tree/TableTypeDescriptorNode.java | 2 + .../syntax/tree/TemplateExpressionNode.java | 2 + .../syntax/tree/TransactionStatementNode.java | 2 + .../compiler/syntax/tree/TreeModifier.java | 7 +- .../syntax/tree/TypeCastParamNode.java | 4 +- .../syntax/tree/TypeDefinitionNode.java | 3 + .../syntax/tree/VariableDeclarationNode.java | 4 + .../syntax/tree/WhileStatementNode.java | 4 +- .../tree/XMLNamespaceDeclarationNode.java | 3 + .../src/main/java/module-info.java | 1 + .../tools/diagnostics/DiagnosticInfo.java | 4 +- .../java/io/ballerina/tools/text/LineMap.java | 3 + .../io/ballerina/tools/text/LineRange.java | 4 +- .../src/main/java/module-info.java | 1 + .../ExternalNodeVisitorTarget.java | 2 + .../InternalNodeTransformerTarget.java | 2 + .../InternalNodeVisitorTarget.java | 2 + .../nodevisitor/NodeTransformerTarget.java | 2 + .../src/main/java/module-info.java | 1 + gradle/libs.versions.toml | 2 + .../src/main/groovy/javaProject.gradle | 2 + .../src/main/java/module-info.java | 1 + .../ballerinalang/langlib/java/JavaUtils.java | 2 + .../ballerinalang/langlib/java/ToString.java | 2 + .../src/main/java/module-info.java | 1 + .../langlib/internal/GetAttribute.java | 2 + .../internal/GetElementNameNilLifting.java | 2 + .../langlib/internal/SelectDescendants.java | 2 + .../langlib/internal/WorkerChannels.java | 2 + .../lang.array/src/main/java/module-info.java | 1 + .../ballerinalang/langlib/array/IndexOf.java | 2 + .../langlib/array/LastIndexOf.java | 2 + .../org/ballerinalang/langlib/array/Next.java | 2 + .../lang.error/src/main/java/module-info.java | 1 + .../langlib/error/StackTrace.java | 10 + .../lang.map/src/main/java/module-info.java | 1 + .../org/ballerinalang/langlib/map/Next.java | 2 + .../src/main/java/module-info.java | 1 + .../ballerinalang/langlib/regexp/Find.java | 5 + .../ballerinalang/langlib/regexp/Matches.java | 3 + .../src/main/java/module-info.java | 1 + .../ballerinalang/langlib/string/Next.java | 2 + .../lang.table/src/main/java/module-info.java | 1 + .../org/ballerinalang/langlib/table/Next.java | 2 + .../src/main/java/module-info.java | 1 + .../langlib/typedesc/TypeIds.java | 3 + .../lang.value/src/main/java/module-info.java | 1 + .../langlib/value/FromBalString.java | 2 + .../langlib/value/FromJsonDecimalString.java | 2 + .../langlib/value/FromJsonFloatString.java | 2 + .../langlib/value/FromJsonString.java | 2 + .../lang.xml/src/main/java/module-info.java | 1 + .../org/ballerinalang/langlib/xml/Copy.java | 2 + .../ballerinalang/langlib/xml/Elements.java | 2 + .../langlib/xml/GetElementName.java | 2 + .../langlib/xml/GetItemType.java | 2 + .../ballerinalang/langlib/xml/GetName.java | 2 + .../langlib/xml/GetTextValue.java | 2 + .../org/ballerinalang/langlib/xml/Map.java | 2 + .../org/ballerinalang/langlib/xml/Next.java | 2 + .../org/ballerinalang/langlib/xml/Select.java | 2 + .../langlib/xml/SelectDescendants.java | 2 + .../org/ballerinalang/langlib/xml/Slice.java | 2 + .../org/ballerinalang/langlib/xml/Strip.java | 2 + .../src/main/java/module-info.java | 1 + .../langserver/commons/SignatureContext.java | 3 +- .../spi/BallerinaCompletionProvider.java | 4 +- .../src/main/java/module-info.java | 1 + .../langserver/LSClientCapabilitiesImpl.java | 5 +- .../langserver/LSClientLogger.java | 6 +- .../langserver/LSPackageLoader.java | 3 +- .../DiagBasedPositionDetailsImpl.java | 3 +- .../RangeBasedPositionDetailsImpl.java | 10 +- .../codeaction/ScopedSymbolFinder.java | 3 + .../ExtractToLocalVarCodeAction.java | 2 + .../ChangeParameterTypeCodeAction.java | 2 + .../command/docs/DocAttachmentInfo.java | 5 +- .../command/docs/DocumentationGenerator.java | 3 +- .../executors/ReportFeatureUsageExecutor.java | 2 + .../FunctionCallExpressionTypeFinder.java | 4 +- .../langserver/common/ImportsAcceptor.java | 4 +- .../langserver/common/utils/CommonUtil.java | 3 +- .../common/utils/FunctionGenerator.java | 3 +- .../langserver/common/utils/NameUtil.java | 4 +- .../langserver/common/utils/PathUtil.java | 3 +- .../langserver/common/utils/SymbolUtil.java | 3 +- .../FunctionCompletionItemBuilder.java | 12 +- .../builder/TypeCompletionItemBuilder.java | 3 +- .../providers/AbstractCompletionProvider.java | 3 +- .../context/ImportDeclarationNodeContext.java | 3 +- .../util/RegexpCompletionProvider.java | 3 +- .../BallerinaCompletionContextImpl.java | 2 + .../BallerinaDefinitionContextImpl.java | 2 + .../contexts/CompletionContextImpl.java | 3 +- .../langserver/contexts/ContextBuilder.java | 4 +- .../DocumentSymbolResolver.java | 3 +- .../AbstractExtendedLanguageServer.java | 2 + .../connector/BallerinaRecordResponse.java | 3 +- .../ballerina/document/ASTModification.java | 3 +- .../document/BallerinaTreeModifyUtil.java | 6 +- .../visitor/UnusedSymbolsVisitor.java | 4 +- .../packages/PackageComponentsRequest.java | 2 + .../packages/PackageMetadataRequest.java | 2 + .../symbol/ResolvedTypeForExpression.java | 3 +- .../symbol/ResolvedTypeForSymbol.java | 3 +- .../symbol/TypeFromExpressionRequest.java | 2 + .../symbol/TypeFromSymbolRequest.java | 2 + .../semantictokens/SemanticTokensVisitor.java | 3 +- .../signature/SignatureHelpUtil.java | 2 + .../LSFeatureUsageTelemetryEvent.java | 4 +- .../workspace/BallerinaWorkspaceManager.java | 2 + .../bindgen/model/JConstructor.java | 3 +- .../bindgen/utils/BindgenEnv.java | 3 +- .../bindgen/utils/BindgenFileGenerator.java | 6 +- .../bindgen/utils/BindgenMvnResolver.java | 7 +- .../bindgen/utils/BindgenNodeFactory.java | 11 +- .../bindgen/utils/BindgenTreeModifier.java | 3 + .../bindgen/utils/ChildFirstClassLoader.java | 3 + .../src/main/java/module-info.java | 1 + .../AIDataMapperCodeActionUtil.java | 6 +- .../datamapper/utils/HttpClientRequest.java | 3 + .../src/main/java/module-info.java | 1 + .../PackageSemanticAnalyzerPlugin.java | 3 +- .../src/main/java/module-info.java | 1 + .../debugadapter/BallerinaStackFrame.java | 4 + .../debugadapter/ExecutionContext.java | 4 + .../debugadapter/JBallerinaDebugServer.java | 10 +- .../debugadapter/SuspendedContext.java | 4 + .../completion/util/CompletionUtil.java | 8 +- .../config/ClientAttachConfigHolder.java | 3 + .../config/ClientConfigHolder.java | 2 + .../evaluation/BExpressionValue.java | 4 +- .../evaluation/EvaluationException.java | 4 +- .../evaluation/EvaluationImportResolver.java | 4 +- .../evaluation/EvaluatorBuilder.java | 3 + .../evaluation/engine/Evaluator.java | 3 +- .../engine/InvocationArgProcessor.java | 10 +- .../ExpressionAsProgramEvaluator.java | 2 + .../MethodCallExpressionEvaluator.java | 5 +- .../expression/NewExpressionEvaluator.java | 6 +- .../engine/invokable/JvmMethod.java | 2 + .../validator/SerialExpressionValidator.java | 3 + .../jdi/LocalVariableProxyImpl.java | 3 + .../debugadapter/jdi/StackFrameProxyImpl.java | 10 + .../jdi/StringReferenceProxyImpl.java | 2 + .../jdi/ThreadReferenceProxyImpl.java | 4 + .../jdi/VirtualMachineProxyImpl.java | 11 +- .../debugadapter/runner/BProgramRunner.java | 3 +- .../debugadapter/utils/OSUtils.java | 3 + .../debugadapter/utils/PackageUtils.java | 2 + .../variable/BCompoundVariable.java | 2 + .../variable/BSimpleVariable.java | 2 + .../variable/DebugVariableException.java | 4 +- .../variable/VariableFactory.java | 2 + .../debugadapter/variable/VariableUtils.java | 4 + .../debugadapter/variable/types/BMap.java | 3 + .../debugadapter/variable/types/BNil.java | 3 +- .../debugadapter/variable/types/BRecord.java | 4 + .../debugadapter/variable/types/BTable.java | 10 +- .../src/main/java/module-info.java | 1 + .../debugadapter/runtime/DebuggerRuntime.java | 3 + .../src/main/java/module-info.java | 1 + .../connector/generator/GeneratorUtils.java | 4 + .../connector/models/connector/Connector.java | 3 +- .../connector/models/connector/Function.java | 8 +- .../connector/models/connector/Type.java | 13 +- .../connector/models/connector/TypeInfo.java | 3 +- .../models/connector/types/RecordType.java | 3 +- .../models/connector/types/TableType.java | 3 +- misc/docerina/src/main/java/module-info.java | 1 + .../docgen/generator/model/Annotation.java | 3 +- .../generator/model/AnnotationAttachment.java | 3 +- .../docgen/generator/model/BClass.java | 2 + .../docgen/generator/model/BType.java | 4 +- .../docgen/generator/model/Construct.java | 2 + .../docgen/generator/model/Error.java | 3 +- .../docgen/generator/model/MapType.java | 3 +- .../docgen/generator/model/TableType.java | 3 +- .../docgen/generator/model/Type.java | 10 +- .../src/main/java/module-info.java | 1 + .../formatter/cli/FormatUtil.java | 6 +- .../src/main/java/module-info.java | 1 + .../formatter/core/Formatter.java | 3 +- .../formatter/core/FormattingEnv.java | 3 +- .../core/FormattingTreeModifier.java | 19 +- .../java/io/ballerina/identifier/Utils.java | 6 +- .../src/main/java/module-info.java | 1 + .../jsonmapper/JsonToRecordMapper.java | 24 ++- .../diagnostic/DiagnosticMessage.java | 9 +- .../JsonToRecordMapperDiagnostic.java | 3 +- .../src/main/java/module-info.java | 1 + .../service/BalShellGetResultResponse.java | 3 + .../src/main/java/module-info.java | 1 + .../converters/JsonToRecordConverter.java | 5 +- .../converters/JsonToRecordRequest.java | 7 +- .../src/main/java/module-info.java | 1 + .../component/ActionInvocationNode.java | 3 +- .../io/ballerina/component/EndPointNode.java | 3 +- .../ballerina/component/ForStatementNode.java | 3 + .../ballerina/component/IfStatementNode.java | 4 + .../java/io/ballerina/component/Node.java | 4 +- .../ReturningActionInvocationNode.java | 5 +- .../java/io/ballerina/utils/ParserUtil.java | 4 + .../src/main/java/module-info.java | 1 + .../ballerinalang/maven/MavenResolver.java | 3 +- .../src/main/java/module-info.java | 1 + .../extension/defaultimpl/DefaultCounter.java | 3 +- .../semver/checker/SemverChecker.java | 3 +- .../comparator/DocumentationComparator.java | 3 +- .../comparator/DumbNodeComparator.java | 5 +- .../comparator/DumbNodeListComparator.java | 8 +- .../checker/comparator/ParamComparator.java | 2 + .../semver/checker/diff/ClassDiff.java | 3 +- .../semver/checker/diff/EnumDiff.java | 3 +- .../semver/checker/diff/FunctionDiff.java | 3 +- .../checker/diff/ModuleConstantDiff.java | 3 +- .../semver/checker/diff/ModuleDiff.java | 3 +- .../semver/checker/diff/ModuleVarDiff.java | 4 +- .../semver/checker/diff/NodeDiffBuilder.java | 4 +- .../semver/checker/diff/NodeDiffImpl.java | 4 +- .../semver/checker/diff/NodeListDiffImpl.java | 3 + .../semver/checker/diff/ObjectFieldDiff.java | 3 +- .../semver/checker/diff/ServiceDiff.java | 3 +- .../checker/diff/TypeDefinitionDiff.java | 3 +- .../semver/checker/util/DiffUtils.java | 5 +- .../semver/checker/util/SemverUtils.java | 3 +- .../src/main/java/module-info.java | 1 + .../segment/NodeFactorySegment.java | 4 +- .../src/main/java/module-info.java | 1 + .../src/main/java/module-info.java | 1 + ...terinaSystemPackageRepositoryProvider.java | 3 +- .../core/MockAnnotationProcessor.java | 9 +- .../testerina/core/TestProcessor.java | 9 +- .../testerina/natives/mock/FunctionMock.java | 10 +- .../natives/mock/GenericMockObjectValue.java | 12 ++ .../testerina/natives/mock/MockRegistry.java | 6 +- .../testerina/natives/mock/ObjectMock.java | 14 ++ .../src/main/java/module-info.java | 1 + .../test/runtime/entity/CoverageReport.java | 5 +- .../PartialCoverageModifiedCounter.java | 3 +- .../entity/PartialCoverageModifiedLine.java | 3 +- .../test/runtime/util/CodeCoverageUtils.java | 3 +- .../test/runtime/util/TesterinaUtils.java | 5 +- .../main/java/io/ballerina/toml/api/Toml.java | 7 +- .../diagnostics/SyntaxDiagnostic.java | 2 + .../toml/internal/parser/AbstractLexer.java | 2 + .../toml/internal/parser/AbstractParser.java | 2 + .../parser/AbstractParserErrorHandler.java | 4 + .../toml/internal/parser/SyntaxErrors.java | 5 +- .../toml/internal/parser/TokenReader.java | 2 + .../toml/internal/parser/TomlLexer.java | 2 + .../toml/internal/parser/TomlParser.java | 12 ++ .../parser/tree/STAbstractNodeFactory.java | 2 + .../toml/internal/parser/tree/STNode.java | 5 +- .../internal/parser/tree/STNodeReplacer.java | 3 + .../parser/tree/STNodeTransformer.java | 3 + .../internal/parser/tree/STTreeModifier.java | 3 + .../internal/syntax/ExternalTreeNodeList.java | 2 + .../toml/internal/syntax/NodeReplacer.java | 3 + .../toml/semantic/ast/TomlKeyNode.java | 3 +- .../toml/semantic/ast/TomlTransformer.java | 4 + .../semantic/diagnostics/TomlDiagnostic.java | 2 + .../toml/syntax/tree/AbstractNodeFactory.java | 2 + .../toml/syntax/tree/ChildNodeList.java | 2 + .../syntax/tree/LiteralStringLiteralNode.java | 2 + .../ballerina/toml/syntax/tree/Minutiae.java | 3 +- .../toml/syntax/tree/MinutiaeList.java | 3 +- .../toml/syntax/tree/NodeFactory.java | 3 +- .../toml/syntax/tree/NodeParser.java | 4 + .../toml/syntax/tree/NodeTransformer.java | 3 + .../toml/syntax/tree/NonTerminalNode.java | 4 +- .../toml/syntax/tree/NumericLiteralNode.java | 2 + .../toml/syntax/tree/StringLiteralNode.java | 2 + .../toml/syntax/tree/SyntaxTree.java | 5 +- .../toml/syntax/tree/TreeModifier.java | 5 +- .../toml/validator/SampleNodeGenerator.java | 13 +- .../toml/validator/schema/AbstractSchema.java | 4 +- .../toml/validator/schema/ArraySchema.java | 3 +- .../toml/validator/schema/BooleanSchema.java | 5 +- .../toml/validator/schema/NumericSchema.java | 6 +- .../toml/validator/schema/Schema.java | 8 +- .../validator/schema/SchemaDeserializer.java | 15 +- .../toml/validator/schema/StringSchema.java | 7 +- .../src/main/java/module-info.java | 1 + .../XMLToRecordConverter.java | 7 +- .../XMLToRecordRequest.java | 4 +- .../diagnostic/DiagnosticMessage.java | 9 +- .../XMLToRecordConverterDiagnostic.java | 3 +- .../src/main/java/module-info.java | 1 + .../badsad/BadSadCompilerPlugin20.java | 3 +- .../src/main/java/module-info.java | 1 + .../diagnosticutils/DiagnosticUtils.java | 3 +- .../src/main/java/module-info.java | 1 + .../org/ballerinalang/test/BCompileUtil.java | 2 + .../test/agent/server/RouteTable.java | 3 +- .../test/context/BMainInstance.java | 29 +-- .../test/context/BServerInstance.java | 21 +- .../test/util/HttpClientRequest.java | 16 +- .../ballerinalang/test/util/HttpResponse.java | 4 +- .../test/utils/BallerinaTestDebugPoint.java | 9 +- .../debugger/test/utils/DebugHitListener.java | 2 + .../debugger/test/utils/DebugTestRunner.java | 4 + .../utils/client/connection/Callback.java | 4 +- .../ProcessStreamConnectionProvider.java | 3 + .../SocketStreamConnectionProvider.java | 3 + 831 files changed, 3301 insertions(+), 1153 deletions(-) diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/BShellConfiguration.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/BShellConfiguration.java index 9a7f6ccd8299..b0666efb8983 100644 --- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/BShellConfiguration.java +++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/BShellConfiguration.java @@ -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; @@ -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; diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/handlers/help/BbeTopicsProvider.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/handlers/help/BbeTopicsProvider.java index a72413ff08ff..81bd922f15a6 100644 --- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/handlers/help/BbeTopicsProvider.java +++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/handlers/help/BbeTopicsProvider.java @@ -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; @@ -85,6 +86,7 @@ public List getTopicList() { return topicList; } + @Nullable private String readFileAsString(String file) { String content = null; try { diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ExpressionValidator.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ExpressionValidator.java index ef03b39a90ae..0de762496f18 100644 --- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ExpressionValidator.java +++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ExpressionValidator.java @@ -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. @@ -29,6 +30,7 @@ */ public class ExpressionValidator implements Validator { + @Nullable private Validator nextInValidator; public ExpressionValidator() { diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ModuleMemberValidator.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ModuleMemberValidator.java index 4541589cbc95..f10ba28dde35 100644 --- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ModuleMemberValidator.java +++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ModuleMemberValidator.java @@ -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. @@ -34,6 +35,7 @@ */ public class ModuleMemberValidator implements Validator { + @Nullable private Validator nextInValidator; public ModuleMemberValidator() { diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/StatementValidator.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/StatementValidator.java index 32cf83f05dc0..f0a223d1b03e 100644 --- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/StatementValidator.java +++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/StatementValidator.java @@ -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. @@ -29,6 +30,7 @@ */ public class StatementValidator implements Validator { + @Nullable private Validator nextInValidator; public StatementValidator() { diff --git a/ballerina-shell/modules/shell-cli/src/main/java/module-info.java b/ballerina-shell/modules/shell-cli/src/main/java/module-info.java index 8c6253a55669..c89d3faf2366 100644 --- a/ballerina-shell/modules/shell-cli/src/main/java/module-info.java +++ b/ballerina-shell/modules/shell-cli/src/main/java/module-info.java @@ -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; diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/EvaluatorImpl.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/EvaluatorImpl.java index ec9673a2aa13..a50793b29acd 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/EvaluatorImpl.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/EvaluatorImpl.java @@ -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; @@ -62,6 +63,7 @@ public void initialize() throws BallerinaShellException { } } + @Nullable @Override public String evaluate(String source) throws BallerinaShellException { try { diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/NotebookReturnValue.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/NotebookReturnValue.java index 03ba6e276e0e..4dd5ae9eee1c 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/NotebookReturnValue.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/NotebookReturnValue.java @@ -18,6 +18,8 @@ package io.ballerina.shell; +import org.jetbrains.annotations.Nullable; + /** * Return value after invoking snippet. * Contains result as an object & exception status related to compilation @@ -29,7 +31,7 @@ public class NotebookReturnValue { private final Object result; private final Enum exceptionStatus; - NotebookReturnValue(Object result, Enum exceptionStatus) { + NotebookReturnValue(@Nullable Object result, Enum exceptionStatus) { this.result = result; this.exceptionStatus = exceptionStatus; } @@ -39,6 +41,7 @@ public class NotebookReturnValue { this.exceptionStatus = exceptionStatus; } + @Nullable public Object getResult() { return result; } diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/ShellReturnValue.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/ShellReturnValue.java index e79530cf3551..6a8503c4a4a4 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/ShellReturnValue.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/ShellReturnValue.java @@ -18,6 +18,8 @@ package io.ballerina.shell; +import org.jetbrains.annotations.Nullable; + /** * Shell Compilation class. * Contains package compilation & exception status related to compilation @@ -29,7 +31,7 @@ public class ShellReturnValue { private final String result; private final Enum exceptionStatus; - ShellReturnValue(String result, Enum exceptionStatus) { + ShellReturnValue(@Nullable String result, Enum exceptionStatus) { this.result = result; this.exceptionStatus = exceptionStatus; } @@ -39,6 +41,7 @@ public class ShellReturnValue { this.exceptionStatus = exceptionStatus; } + @Nullable public String getResult() { return result; } diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/ClassLoadInvoker.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/ClassLoadInvoker.java index 4617ea0bf74d..3973e5eb8a8f 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/ClassLoadInvoker.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/ClassLoadInvoker.java @@ -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; @@ -203,6 +204,7 @@ public void reset() { this.availableModuleDeclarations.clear(); } + @Nullable @Override public PackageCompilation getCompilation(Collection newSnippets) throws InvokerException { if (!this.initialized.get()) { diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/ImportsManager.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/ImportsManager.java index 829c6d9c635a..a5e28a0d2c10 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/ImportsManager.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/ImportsManager.java @@ -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; @@ -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) { diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/context/ClassLoadContext.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/context/ClassLoadContext.java index d1d78bf4ca06..15e59df83db2 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/context/ClassLoadContext.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/classload/context/ClassLoadContext.java @@ -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; @@ -60,9 +61,9 @@ public ClassLoadContext(String contextId, Collection imports, Collection moduleDclns, Collection varDclns, - Collection newVarNames, + @Nullable Collection newVarNames, String lastVarDcln, - Collection lastStmts) { + @Nullable Collection lastStmts) { this.lastStmts = Objects.requireNonNullElse(lastStmts, List.of()); this.lastVarDcln = Objects.requireNonNullElse(lastVarDcln, ""); this.contextId = Objects.requireNonNull(contextId); @@ -88,8 +89,8 @@ public ClassLoadContext(String contextId, Collection imports, Collection moduleDclns, Collection varDclns, - Collection newVarNames, - String lastVarDcln) { + @Nullable Collection newVarNames, + @Nullable String lastVarDcln) { this(contextId, imports, moduleDclns, varDclns, newVarNames, lastVarDcln, null); } diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/snippet/SnippetSubKind.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/snippet/SnippetSubKind.java index 405838a8ec4d..a3f657ea109c 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/snippet/SnippetSubKind.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/snippet/SnippetSubKind.java @@ -18,6 +18,8 @@ package io.ballerina.shell.snippet; +import org.jetbrains.annotations.Nullable; + /** * Snippet sub type to further categorize snippets. * @@ -102,6 +104,7 @@ public boolean hasError() { return error != null; } + @Nullable public String getError() { return error; } diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/snippet/factory/BasicSnippetFactory.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/snippet/factory/BasicSnippetFactory.java index 15377f6db441..48ef161a20e9 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/snippet/factory/BasicSnippetFactory.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/snippet/factory/BasicSnippetFactory.java @@ -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; @@ -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) { @@ -132,6 +134,7 @@ public ImportDeclarationSnippet createImportSnippet(Node node) { return null; } + @Nullable @Override public List createVariableDeclarationSnippets(Node node) { ModuleVariableDeclarationNode dclnNode; @@ -221,6 +224,7 @@ public List createVariableDeclarationSnippets(Node n return snippets; } + @Nullable @Override public ModuleMemberDeclarationSnippet createModuleMemberDeclarationSnippet(Node node) throws SnippetException { @@ -241,6 +245,7 @@ public ModuleMemberDeclarationSnippet createModuleMemberDeclarationSnippet(Node return null; } + @Nullable @Override public StatementSnippet createStatementSnippet(Node node) throws SnippetException { if (node instanceof StatementNode) { @@ -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) { diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/ModuleImporter.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/ModuleImporter.java index e7184dc9e272..68c08d558886 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/ModuleImporter.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/ModuleImporter.java @@ -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; @@ -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; diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/QuotedImport.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/QuotedImport.java index e4aeb69475bd..4e9f598d1a76 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/QuotedImport.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/QuotedImport.java @@ -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; @@ -31,7 +33,7 @@ public class QuotedImport { private final String orgName; private final List moduleNames; - public QuotedImport(String orgName, List moduleNames) { + public QuotedImport(@Nullable String orgName, List moduleNames) { this.orgName = orgName; this.moduleNames = moduleNames.stream() .map(Identifier::new) diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/StringUtils.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/StringUtils.java index 5cc82527c6a6..d9961751cfbb 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/StringUtils.java +++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/utils/StringUtils.java @@ -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; @@ -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); } diff --git a/ballerina-shell/modules/shell-core/src/main/java/module-info.java b/ballerina-shell/modules/shell-core/src/main/java/module-info.java index 03c768fd9a36..e1495afd5cb7 100644 --- a/ballerina-shell/modules/shell-core/src/main/java/module-info.java +++ b/ballerina-shell/modules/shell-core/src/main/java/module-info.java @@ -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; diff --git a/ballerina-shell/modules/shell-rt/src/main/java/io/ballerina/shell/rt/InvokerMemory.java b/ballerina-shell/modules/shell-rt/src/main/java/io/ballerina/shell/rt/InvokerMemory.java index 676a57420a1d..d60a4193ea4d 100644 --- a/ballerina-shell/modules/shell-rt/src/main/java/io/ballerina/shell/rt/InvokerMemory.java +++ b/ballerina-shell/modules/shell-rt/src/main/java/io/ballerina/shell/rt/InvokerMemory.java @@ -18,6 +18,8 @@ package io.ballerina.shell.rt; +import org.jetbrains.annotations.Nullable; + import java.util.HashMap; /** @@ -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); diff --git a/ballerina-shell/modules/shell-rt/src/main/java/module-info.java b/ballerina-shell/modules/shell-rt/src/main/java/module-info.java index 2c7fc7cd70a5..c03f5e2334e9 100644 --- a/ballerina-shell/modules/shell-rt/src/main/java/module-info.java +++ b/ballerina-shell/modules/shell-rt/src/main/java/module-info.java @@ -1,3 +1,4 @@ module io.ballerina.shell.rt { + requires static org.jetbrains.annotations; exports io.ballerina.shell.rt; } diff --git a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/Profiler.java b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/Profiler.java index 2f35ad7a84ec..1f282b1f14ca 100644 --- a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/Profiler.java +++ b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/Profiler.java @@ -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; @@ -329,6 +330,7 @@ String getBalJarArgs() { return balJarArgs; } + @Nullable private String getFileNameWithoutExtension(String balJarName) { if (null != balJarName) { int index = FilenameUtils.indexOfExtension(balJarName); diff --git a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java index 58b59c1b97e4..dae40aa5e0e3 100644 --- a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java +++ b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java @@ -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; @@ -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"); diff --git a/bvm/ballerina-profiler/src/main/java/module-info.java b/bvm/ballerina-profiler/src/main/java/module-info.java index 15468516fdd5..3e8fdb6467b0 100644 --- a/bvm/ballerina-profiler/src/main/java/module-info.java +++ b/bvm/ballerina-profiler/src/main/java/module-info.java @@ -4,4 +4,5 @@ requires io.ballerina.runtime; requires io.ballerina.identifier; requires com.google.gson; + requires static org.jetbrains.annotations; } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Future.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Future.java index c853eba37eaf..287e15758f2b 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Future.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Future.java @@ -18,6 +18,8 @@ package io.ballerina.runtime.api; +import org.jetbrains.annotations.Nullable; + /** * A future that will resume the underling strand when completed. * @@ -25,5 +27,5 @@ */ public abstract class Future { - public abstract void complete(Object returnValue); + public abstract void complete(@Nullable Object returnValue); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Module.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Module.java index 4573b76c3d0e..ddc66f74a8d4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Module.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Module.java @@ -17,6 +17,8 @@ */ package io.ballerina.runtime.api; +import org.jetbrains.annotations.Nullable; + import java.util.Objects; import static io.ballerina.runtime.api.constants.RuntimeConstants.ANON_ORG; @@ -46,7 +48,7 @@ public Module(String org, String name, String majorVersion, boolean isTestPkg) { hashCode = Objects.hash(org, name, majorVersion); } - public Module(String org, String name, String majorVersion) { + public Module(@Nullable String org, @Nullable String name, @Nullable String majorVersion) { this(org, name, majorVersion, false); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Runtime.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Runtime.java index 186331ad0e6d..c9d7957abbbb 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Runtime.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/Runtime.java @@ -26,6 +26,7 @@ import io.ballerina.runtime.internal.BalRuntime; import io.ballerina.runtime.internal.scheduling.Scheduler; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -95,9 +96,10 @@ public static Runtime from(Module module) { * This method needs to be called if object.getType().isIsolated() or * object.getType().isIsolated(methodName) returns false. */ - public abstract BFuture invokeMethodAsyncSequentially(BObject object, String methodName, String strandName, - StrandMetadata metadata, Callback callback, Map properties, - Type returnType, Object... args); + public abstract BFuture invokeMethodAsyncSequentially( + BObject object, String methodName, @Nullable String strandName, + @Nullable StrandMetadata metadata, Callback callback, @Nullable Map properties, + Type returnType, Object... args); /** * Invoke Object method asynchronously and concurrently. Caller needs to ensure that no data race is possible for @@ -118,9 +120,10 @@ public abstract BFuture invokeMethodAsyncSequentially(BObject object, String met * This method needs to be called if both object.getType().isIsolated() and * object.getType().isIsolated(methodName) returns true. */ - public abstract BFuture invokeMethodAsyncConcurrently(BObject object, String methodName, String strandName, - StrandMetadata metadata, Callback callback, Map properties, - Type returnType, Object... args); + public abstract BFuture invokeMethodAsyncConcurrently( + BObject object, String methodName, @Nullable String strandName, + @Nullable StrandMetadata metadata, @Nullable Callback callback, @Nullable Map properties, + Type returnType, Object... args); /** * Invoke Object method asynchronously. This will schedule the function and block the strand. @@ -171,8 +174,8 @@ public abstract BFuture invokeMethodAsync(BObject object, String methodName, Str * object.getType().isIsolated(methodName) returns true. */ @Deprecated - public abstract Object invokeMethodAsync(BObject object, String methodName, String strandName, - StrandMetadata metadata, Callback callback, Object... args); + public abstract Object invokeMethodAsync(BObject object, String methodName, @Nullable String strandName, + @Nullable StrandMetadata metadata, Callback callback, Object... args); public abstract void registerListener(BObject listener); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/async/StrandMetadata.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/async/StrandMetadata.java index 26384fd48bbe..4ce1b4025ac5 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/async/StrandMetadata.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/async/StrandMetadata.java @@ -17,6 +17,8 @@ */ package io.ballerina.runtime.api.async; +import org.jetbrains.annotations.Nullable; + /** * Holds metadata of a Ballerina strand. * @@ -50,7 +52,7 @@ public class StrandMetadata { */ private final String parentFunctionName; - public StrandMetadata(String moduleOrg, String moduleName, String moduleVersion, String typeName, + public StrandMetadata(String moduleOrg, String moduleName, String moduleVersion, @Nullable String typeName, String parentFunctionName) { this.moduleOrg = moduleOrg; this.moduleName = moduleName; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/ErrorCreator.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/ErrorCreator.java index 386a27c17b7d..7c5569aec843 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/ErrorCreator.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/ErrorCreator.java @@ -32,6 +32,7 @@ import io.ballerina.runtime.internal.values.MapValueImpl; import io.ballerina.runtime.internal.values.MappingInitialValueEntry; import io.ballerina.runtime.internal.values.ValueCreator; +import org.jetbrains.annotations.Nullable; /** * Class @{@link ErrorCreator} provides APIs to create ballerina error instances. @@ -62,7 +63,7 @@ public static BError createError(BString message) { * @param details error details * @return new error */ - public static BError createError(BString message, BMap details) { + public static BError createError(BString message, @Nullable BMap details) { details = RuntimeUtils.validateErrorDetails(details); return new ErrorValue(message, details); } @@ -108,7 +109,8 @@ message, createError(StringUtils.fromString(throwable.getMessage())), * @param details error details * @return new error */ - public static BError createError(Type type, BString message, BError cause, BMap details) { + public static BError createError(Type type, BString message, @Nullable BError cause, + @Nullable BMap details) { details = RuntimeUtils.validateErrorDetails(details); ((BErrorType) type).setDetailType(TypeChecker.getType(details)); return new ErrorValue(type, message, cause, details); @@ -160,8 +162,8 @@ public static BError createError(Throwable error) { * @return error value * @throws BError if given error type is not defined in the ballerina module. */ - public static BError createError(Module module, String errorTypeName, - BString message, BError cause, BMap details) throws BError { + public static BError createError(Module module, String errorTypeName, BString message, @Nullable BError cause, + @Nullable BMap details) throws BError { details = RuntimeUtils.validateErrorDetails(details); ValueCreator valueCreator = ValueCreator.getValueCreator(ValueCreator.getLookupKey(module, false)); try { @@ -204,7 +206,7 @@ public static BError createDistinctError(String typeIdName, Module typeIdPkg, BS */ @Deprecated public static BError createDistinctError(String typeIdName, Module typeIdPkg, BString message, - BMap details) { + @Nullable BMap details) { details = RuntimeUtils.validateErrorDetails(details); return new ErrorValue(new BErrorType(TypeConstants.ERROR, PredefinedTypes.TYPE_ERROR.getPackage(), TypeChecker .getType(details)), message, null, details, typeIdName, typeIdPkg); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/TypeCreator.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/TypeCreator.java index b041914300b6..3b8b980b19c4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/TypeCreator.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/TypeCreator.java @@ -45,6 +45,7 @@ import io.ballerina.runtime.internal.types.BTupleType; import io.ballerina.runtime.internal.types.BUnionType; import io.ballerina.runtime.internal.types.BXmlType; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.List; @@ -132,7 +133,8 @@ public static TupleType createTupleType(List typeList, int typeFlags) { * @param readonly whether immutable * @return the new tuple type */ - public static TupleType createTupleType(List typeList, Type restType, int typeFlags, boolean readonly) { + public static TupleType createTupleType( + List typeList, @Nullable Type restType, int typeFlags, boolean readonly) { return new BTupleType(typeList, restType, typeFlags, readonly); } @@ -239,9 +241,9 @@ public static RecordType createRecordType(String typeName, Module module, long f * @param typeFlags flags associated with the type * @return the new record type */ - public static RecordType createRecordType(String typeName, Module module, long flags, Map fields, - Type restFieldType, - boolean sealed, int typeFlags) { + public static RecordType createRecordType( + String typeName, @Nullable Module module, long flags, Map fields, + @Nullable Type restFieldType, boolean sealed, int typeFlags) { return new BRecordType(typeName, module, flags, fields, restFieldType, sealed, typeFlags); } @@ -409,7 +411,7 @@ public static ErrorType createErrorType(String typeName, Module module, Type det * @param flags flags * @return new field */ - public static Field createField(Type fieldType, String fieldName, long flags) { + public static Field createField(@Nullable Type fieldType, @Nullable String fieldName, long flags) { return new BField(fieldType, fieldName, flags); } @@ -421,7 +423,7 @@ public static Field createField(Type fieldType, String fieldName, long flags) { * @param readonly whether immutable * @return new table type */ - public static TableType createTableType(Type constraint, String[] fieldNames, boolean readonly) { + public static TableType createTableType(Type constraint, @Nullable String[] fieldNames, boolean readonly) { return new BTableType(constraint, fieldNames, readonly); } @@ -514,7 +516,7 @@ public static FiniteType createFiniteType(String typeName) { * @param typeFlags type flags * @return new finite type */ - public static FiniteType createFiniteType(String typeName, Set values, int typeFlags) { + public static FiniteType createFiniteType(@Nullable String typeName, Set values, int typeFlags) { return new BFiniteType(typeName, values, typeFlags); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/ValueCreator.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/ValueCreator.java index 2ae086cf7621..11aeed2e7b7b 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/ValueCreator.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/creators/ValueCreator.java @@ -67,6 +67,7 @@ import io.ballerina.runtime.internal.values.XmlItem; import io.ballerina.runtime.internal.values.XmlQName; import io.ballerina.runtime.internal.values.XmlSequence; +import org.jetbrains.annotations.Nullable; import java.io.InputStream; import java.math.BigDecimal; @@ -777,7 +778,7 @@ public static BMap createMapValue(MapType mapType, BMapInitialV * @param value value * @return key field entry */ - public static BMapInitialValueEntry createKeyFieldEntry(Object key, Object value) { + public static BMapInitialValueEntry createKeyFieldEntry(Object key, @Nullable Object value) { return new MappingInitialValueEntry.KeyValueEntry(key, value); } @@ -797,7 +798,7 @@ public static BMapInitialValueEntry createSpreadFieldEntry(BMap mappingVal * @param value value * @return list initial value entry */ - public static BListInitialValueEntry createListInitialValueEntry(Object value) { + public static BListInitialValueEntry createListInitialValueEntry(@Nullable Object value) { return new ListInitialValueEntry.ExpressionEntry(value); } @@ -857,7 +858,7 @@ public static BMap createRecordValue(Module packageId, String r * @throws BError if given record type is not defined in the ballerina module. */ public static BMap createRecordValue(Module packageId, String recordTypeName, - Map valueMap) throws BError { + @Nullable Map valueMap) throws BError { valueMap = RuntimeUtils.validateBMapValues(valueMap); return ValueUtils.createRecordValue(packageId, recordTypeName, valueMap); } @@ -948,7 +949,7 @@ public static BObject createObjectValue(Module packageId, String objectTypeName, * @param value object value * @return handle value for given object value */ - public static BHandle createHandleValue(Object value) { + public static BHandle createHandleValue(@Nullable Object value) { return new HandleValue(value); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Parameter.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Parameter.java index 3a93275de3cd..e7b2e05ebf26 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Parameter.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Parameter.java @@ -18,6 +18,8 @@ package io.ballerina.runtime.api.types; +import org.jetbrains.annotations.Nullable; + /** * {@code Parameter} represents the parameter of a function in ballerina. * @@ -29,7 +31,7 @@ public class Parameter { public final String defaultFunctionName; public Type type; - public Parameter(String name, boolean isDefault, String defaultFunctionName, Type type) { + public Parameter(String name, boolean isDefault, @Nullable String defaultFunctionName, Type type) { this.name = name; this.isDefault = isDefault; this.defaultFunctionName = defaultFunctionName; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java index 40d87dbe9175..3e99c8ef832d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java @@ -18,6 +18,7 @@ package io.ballerina.runtime.api.types; import io.ballerina.runtime.api.Module; +import org.jetbrains.annotations.Nullable; /** * {@code Type} represents a type in Ballerina. @@ -49,6 +50,7 @@ default void setCachedReferredType(Type type) { * * @return Referred type of the type */ + @Nullable default Type getCachedReferredType() { return null; } @@ -70,6 +72,7 @@ default void setCachedImpliedType(Type type) { * * @return Implied type of the type */ + @Nullable default Type getCachedImpliedType() { return null; } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/JsonUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/JsonUtils.java index e0f6b1d6ed55..8a0a23d2c652 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/JsonUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/JsonUtils.java @@ -41,6 +41,7 @@ import io.ballerina.runtime.internal.errors.ErrorCodes; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.values.ErrorValue; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.InputStream; @@ -214,6 +215,7 @@ public static BMap convertJSONToRecord(Object record, Structure * @return If the conversion is successes this will return JSON object. * @throws BError If conversion fails. */ + @Nullable public static Object convertJSON(Object source, Type targetType) throws BError { return JsonInternalUtils.convertJSON(source, targetType); } @@ -285,6 +287,7 @@ public static void serialize(Object json, Writer writer) throws BError { * @param value source value * @return json value */ + @Nullable public static Object convertToJson(Object value) { return convertToJsonType(value, new ArrayList<>()); } @@ -298,11 +301,13 @@ public static Object convertToJson(Object value) { * @return json value * @deprecated use {@link #convertToJson(Object)} instead. */ + @Nullable @Deprecated(since = "2201.6.0", forRemoval = true) public static Object convertToJson(Object value, List unresolvedValues) { return convertToJsonType(value, unresolvedValues); } + @Nullable private static Object convertToJsonType(Object value, List unresolvedValues) { Type jsonType = PredefinedTypes.TYPE_JSON; if (value == null) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/StringUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/StringUtils.java index 44e6f75ab783..9e11013a8f84 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/StringUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/StringUtils.java @@ -32,6 +32,8 @@ import io.ballerina.runtime.internal.values.BmpStringValue; import io.ballerina.runtime.internal.values.MapValueImpl; import io.ballerina.runtime.internal.values.NonBmpStringValue; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.Nullable; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; @@ -104,6 +106,8 @@ public static BString getStringAt(BString s, long index) { return StringUtils.fromString(String.valueOf(Character.toChars(s.getCodePoint((int) index)))); } + @Nullable + @Contract("null -> null; !null -> new") public static BString fromString(String s) { if (s == null) { return null; @@ -204,6 +208,7 @@ public static String getExpressionStringValue(Object value, BLink parent) { * @return Ballerina value represented by Ballerina expression syntax * @throws BError for any parsing error */ + @Nullable public static Object parseExpressionStringValue(String value) throws BError { try { return parseExpressionStringVal(value, null); @@ -222,6 +227,7 @@ public static Object parseExpressionStringValue(String value) throws BError { * @throws BError for any parsing error * @deprecated use {@link #parseExpressionStringValue(String)} instead. */ + @Nullable @Deprecated(since = "2201.6.0", forRemoval = true) public static Object parseExpressionStringValue(String value, BLink parent) throws BError { return parseExpressionStringVal(value, parent); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BArray.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BArray.java index efc1e70cb995..02cac9be4590 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BArray.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BArray.java @@ -18,6 +18,7 @@ package io.ballerina.runtime.api.values; import io.ballerina.runtime.api.types.Type; +import org.jetbrains.annotations.Nullable; /** *

@@ -98,7 +99,7 @@ public interface BArray extends BRefValue, BCollection { * @param index array index * @param value value to be added */ - void add(long index, Object value); + void add(long index, @Nullable Object value); /** * Add int value to the given array index. @@ -149,7 +150,7 @@ public interface BArray extends BRefValue, BCollection { * Append value to the existing array. * @param value value to be appended */ - void append(Object value); + void append(@Nullable Object value); /** * Reverse an array. diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BMap.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BMap.java index 1eb65cc3fab8..a734c888e161 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BMap.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BMap.java @@ -18,6 +18,7 @@ package io.ballerina.runtime.api.values; import io.ballerina.runtime.api.types.Type; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Map; @@ -63,7 +64,7 @@ public interface BMap extends BRefValue, BCollection { * {@code key}. (A {@code null} return can also indicate that the map previously associated * {@code null} with {@code key}, if the implementation supports {@code null} values.) */ - V put(K key, V value); + V put(K key, @Nullable V value); /** * Removes the mapping for a key from this map if it is present (optional operation). Returns the value diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BValue.java index 82a8bdac0a59..bef8cbd24711 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/values/BValue.java @@ -18,6 +18,7 @@ package io.ballerina.runtime.api.values; import io.ballerina.runtime.api.types.Type; +import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -49,7 +50,7 @@ public interface BValue { */ Object frozenCopy(Map refs); - String stringValue(BLink parent); + String stringValue(@Nullable BLink parent); default String informalStringValue(BLink parent) { return toString(); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java index e721fbc45b07..2611e3ebd675 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java @@ -45,6 +45,7 @@ import io.ballerina.runtime.internal.values.FutureValue; import io.ballerina.runtime.internal.values.ObjectValue; import io.ballerina.runtime.internal.values.ValueCreator; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -74,7 +75,7 @@ public class BalRuntime extends Runtime { private boolean moduleStopped = false; private Thread schedulerThread = null; - public BalRuntime(Scheduler scheduler, Module module) { + public BalRuntime(Scheduler scheduler, @Nullable Module module) { this.scheduler = scheduler; this.module = module; } @@ -163,6 +164,7 @@ public void stop() { * This method needs to be called if object.getType().isIsolated() or * object.getType().isIsolated(methodName) returns false. */ + @Nullable @Override public BFuture invokeMethodAsyncSequentially(BObject object, String methodName, String strandName, StrandMetadata metadata, @@ -212,6 +214,7 @@ public void notifyFailure(BError error) { * This method needs to be called if both object.getType().isIsolated() and * object.getType().isIsolated(methodName) returns true. */ + @Nullable @Override public BFuture invokeMethodAsyncConcurrently(BObject object, String methodName, String strandName, StrandMetadata metadata, @@ -267,10 +270,11 @@ public void notifyFailure(BError error) { * We can decide the object method isolation if and only if both object.getType().isIsolated() and * object.getType().isIsolated(methodName) returns true. */ + @Nullable @Override @Deprecated public BFuture invokeMethodAsync(BObject object, String methodName, String strandName, StrandMetadata metadata, - Callback callback, Map properties, + Callback callback, @Nullable Map properties, Type returnType, Object... args) { try { validateArgs(object, methodName); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BallerinaXmlSerializer.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BallerinaXmlSerializer.java index cdce109da43a..70e5104103fc 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BallerinaXmlSerializer.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BallerinaXmlSerializer.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.internal.values.XmlPi; import io.ballerina.runtime.internal.values.XmlSequence; import io.ballerina.runtime.internal.values.XmlText; +import org.jetbrains.annotations.Nullable; import java.io.CharArrayWriter; import java.io.OutputStream; @@ -213,6 +214,7 @@ private void writeElement(XmlItem xmlValue) throws XMLStreamException { this.parentNSSet.pop(); } + @Nullable private String setDefaultNamespace(Map nsPrefixMap, QName qName, HashSet currentNSLevel) throws XMLStreamException { boolean elementNSUsageFoundInAttribute = false; @@ -276,6 +278,7 @@ private void writeStartElement(QName qName, Map nsPrefixMap, Has } } + @Nullable private String getXmlNsUriPrefix(Map nsPrefixMap, String uri) { for (Map.Entry entry : nsPrefixMap.entrySet()) { if (entry.getValue().equals(uri)) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/CloneUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/CloneUtils.java index 3a41e8eefb85..48bba4043f5f 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/CloneUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/CloneUtils.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BRefValue; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.List; @@ -49,6 +50,7 @@ private CloneUtils() {} * @param value The value on which the function is invoked * @return String value of the value */ + @Nullable public static Object cloneValue(Object value) { if (value == null) { return null; @@ -68,6 +70,7 @@ public static Object cloneValue(Object value) { * @param value The value on which the function is invoked * @return String value of the value */ + @Nullable public static Object cloneReadOnly(Object value) { if (value == null) { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/FloatUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/FloatUtils.java index ac1af0ccb240..ec06482882db 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/FloatUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/FloatUtils.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; /** * Common utility methods used for float operations. @@ -31,6 +32,7 @@ public final class FloatUtils { private FloatUtils() { } + @Nullable public static BString getBStringIfInfiniteOrNaN(double x) { if (Double.isInfinite(x) || Double.isNaN(x)) { return StringUtils.fromString(StringUtils.getStringValue(x)); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java index f056abddc30d..0ccc2f9a2077 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java @@ -51,6 +51,7 @@ import io.ballerina.runtime.internal.values.MapValue; import io.ballerina.runtime.internal.values.MapValueImpl; import io.ballerina.runtime.internal.values.MappingInitialValueEntry; +import org.jetbrains.annotations.Nullable; import java.math.BigDecimal; import java.util.ArrayList; @@ -96,7 +97,8 @@ public static boolean hasElement(Object json, String elementName) { * @param bArray {@link ArrayValue} to be converted to JSON * @return JSON representation of the provided bArray */ - public static ArrayValue convertArrayToJSON(BArray bArray) { + @Nullable + public static ArrayValue convertArrayToJSON(@Nullable BArray bArray) { if (bArray == null) { return null; } @@ -122,7 +124,8 @@ public static ArrayValue convertArrayToJSON(BArray bArray) { * @param targetType the target JSON type to be convert to * @return JSON representation of the provided array */ - public static Object convertMapToJSON(BMap map, JsonType targetType) { + @Nullable + public static Object convertMapToJSON(@Nullable BMap map, JsonType targetType) { if (map == null) { return null; } @@ -144,6 +147,7 @@ public static Object convertMapToJSON(BMap map, JsonType targetType) * @return Element of the JSON for the provided key, if the JSON is object type. Error if not an object or nil * if the object does not have the key. */ + @Nullable public static Object getElementOrNil(Object json, BString elementName) { return getMappingElement(json, elementName, true); } @@ -156,6 +160,7 @@ public static Object getElementOrNil(Object json, BString elementName) { * @return Element of the JSON for the provided key, if the JSON is object type. Error if not an object or does * not have the key. */ + @Nullable public static Object getElement(Object json, BString elementName) { return getMappingElement(json, elementName, false); } @@ -168,6 +173,7 @@ public static Object getElement(Object json, BString elementName) { * @param returnNilOnMissingKey Whether to return nil on missing key instead of error * @return Element of JSON having the provided name, if the JSON is object type. Null otherwise. */ + @Nullable private static Object getMappingElement(Object json, BString elementName, boolean returnNilOnMissingKey) { if (!isJSONObject(json)) { return ErrorCreator.createError(JSON_OPERATION_ERROR, @@ -311,6 +317,7 @@ public static MapValueImpl convertJSONToRecord(Object json, Str return bStruct; } + @Nullable public static Object convertJSON(Object jsonValue, Type targetType) { targetType = TypeUtils.getImpliedType(targetType); Type matchingType; @@ -385,6 +392,7 @@ public static ArrayValue getKeys(Object json) { return new ArrayValueImpl(keys, false); } + @Nullable public static Object convertUnionTypeToJSON(Object source, JsonType targetType) { if (source == null) { return null; @@ -421,6 +429,7 @@ public static void remove(Object json, BString fieldName) { ((MapValueImpl) json).remove(fieldName); } + @Nullable public static BError getErrorIfUnmergeable(Object j1, Object j2, List visitedPairs) { if (j1 == null || j2 == null) { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonParser.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonParser.java index 80a73363a64d..fd1f8a375f5d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonParser.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonParser.java @@ -56,6 +56,7 @@ import io.ballerina.runtime.internal.values.ReadOnlyUtils; import io.ballerina.runtime.internal.values.TableValueImpl; import io.ballerina.runtime.internal.values.TupleValueImpl; +import org.jetbrains.annotations.Nullable; import java.io.BufferedInputStream; import java.io.IOException; @@ -244,6 +245,7 @@ private static ParserException getConversionError(Type targetType, String inputV return new ParserException("value '" + inputValue + "' cannot be converted to '" + targetType + "'"); } + @Nullable private static Object convertValues(Type targetType, String inputValue) throws ParserException { return switch (targetType.getTag()) { case TypeTags.INT_TAG, TypeTags.SIGNED32_INT_TAG, TypeTags.SIGNED16_INT_TAG, @@ -277,6 +279,7 @@ private static int convertToByte(Type targetType, String inputValue) throws Pars } } + @Nullable private static Object convertToNull(Type targetType, String inputValue) throws ParserException { if (inputValue.charAt(0) == 'n' && StateMachine.NULL.equals(inputValue)) { return null; @@ -644,6 +647,7 @@ private void handleCurrentJsonNodeForArray() throws ParserException { */ protected static class FieldNameState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { char ch; @@ -695,6 +699,7 @@ private static void processFieldNameValue(StateMachine sm) throws ParserExceptio */ protected static class StringFieldValueState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -767,6 +772,7 @@ private static Type getFieldType(StateMachine sm, BRecordType targetType) { */ protected static class StringArrayElementState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -835,6 +841,7 @@ private static void processQuoteCharacter(StateMachine sm) throws ParserExceptio */ protected static class StringValueState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -878,6 +885,7 @@ private static void processStringValue(StateMachine sm) throws ParserException { } + @Nullable private static Object getNonStringValueAsJson(String str) throws ParserException { if (str.indexOf('.') >= 0) { return getFloatingPointValue(str); @@ -1003,7 +1011,7 @@ private void processArrayType(String str, ArrayType referredType) throws ParserE } @Override - void setValueToJsonType(ValueType type, Object value) { + void setValueToJsonType(ValueType type, @Nullable Object value) { switch (type) { case ARRAY_ELEMENT: ArrayValueImpl arrayValue = (ArrayValueImpl) this.currentJsonNode; @@ -1019,10 +1027,11 @@ void setValueToJsonType(ValueType type, Object value) { } } - private static Object convert(Object value, Type targetType) { + private static Object convert(@Nullable Object value, Type targetType) { return convert(value, targetType, new HashSet<>()); } + @Nullable private static Object convert(Object value, Type targetType, Set unresolvedValues) { if (value == null) { @@ -1089,6 +1098,7 @@ private static Object handleDefaultConversion(Object value, Type targetType, Typ throw createConversionError(value, targetType); } + @Nullable private static Object handleNullConversion(Type targetType) { if (TypeUtils.getImpliedType(targetType).isNilable()) { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/StateMachine.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/StateMachine.java index c605927b1e28..9779cc7ac4fe 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/StateMachine.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/StateMachine.java @@ -22,6 +22,7 @@ import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BError; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.Reader; @@ -74,6 +75,7 @@ public abstract class StateMachine { static final State STRING_FIELD_UNICODE_HEX_PROCESSING_STATE = new StringFieldUnicodeHexProcessingState(); static final State STRING_VALUE_UNICODE_HEX_PROCESSING_STATE = new StringValueUnicodeHexProcessingState(); + @Nullable protected Object currentJsonNode = null; protected final Deque nodesStack = new ArrayDeque<>(); protected final Deque fieldNames = new ArrayDeque<>(); @@ -193,6 +195,7 @@ public interface State { */ private static class DocumentStartState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { char ch; @@ -231,6 +234,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class DocumentEndState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { char ch; @@ -254,6 +258,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class FirstFieldReadyState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { char ch; @@ -284,6 +289,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class FirstArrayElementReadyState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -322,6 +328,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class NonFirstFieldReadyState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -350,6 +357,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class NonFirstArrayElementReadyState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -398,6 +406,7 @@ public void processFieldName() { */ private static class EndFieldNameState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -425,6 +434,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class FieldValueReadyState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -463,6 +473,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class NonStringFieldValueState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -502,6 +513,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class NonStringArrayElementState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -541,6 +553,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class NonStringValueState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -569,6 +582,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class FieldEndState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -598,6 +612,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws P */ private static class ArrayElementEndState implements State { + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -677,6 +692,7 @@ private abstract static class UnicodeHexProcessingState implements State { protected abstract State getSourceState(StateMachine sm); + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; @@ -762,6 +778,7 @@ private abstract static class EscapedCharacterProcessingState implements State { protected abstract State getSourceState(StateMachine sm); + @Nullable @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws ParserException { State state = null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TableOmDataSource.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TableOmDataSource.java index 0178af2e19b5..ba232c434490 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TableOmDataSource.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TableOmDataSource.java @@ -34,6 +34,7 @@ import io.ballerina.runtime.internal.values.TableValue; import io.ballerina.runtime.internal.values.TupleValueImpl; import org.apache.axiom.om.ds.AbstractPushOMDataSource; +import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -58,7 +59,7 @@ public class TableOmDataSource extends AbstractPushOMDataSource { private final String rootWrapper; private final String rowWrapper; - public TableOmDataSource(TableValue table, String rootWrapper, String rowWrapper) { + public TableOmDataSource(TableValue table, @Nullable String rootWrapper, @Nullable String rowWrapper) { this.table = table; this.rootWrapper = rootWrapper != null ? rootWrapper : DEFAULT_ROOT_WRAPPER; this.rowWrapper = rowWrapper != null ? rowWrapper : DEFAULT_ROW_WRAPPER; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TableUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TableUtils.java index cd4bade3c1c5..62dd701e9238 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TableUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TableUtils.java @@ -29,6 +29,7 @@ import io.ballerina.runtime.internal.values.MapValue; import io.ballerina.runtime.internal.values.RegExpValue; import io.ballerina.runtime.internal.values.TableValue; +import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -53,7 +54,7 @@ private TableUtils() { * @param parent Node linking to the parent object of 'obj' * @return The hash value */ - public static Long hash(Object obj, Node parent) { + public static Long hash(Object obj, @Nullable Node parent) { long result = 0; if (obj == null) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java index cc3e8e8fdc1c..7ee60e1c0d3e 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java @@ -81,6 +81,7 @@ import io.ballerina.runtime.internal.values.XmlSequence; import io.ballerina.runtime.internal.values.XmlText; import io.ballerina.runtime.internal.values.XmlValue; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -278,7 +279,7 @@ public static boolean anyToJBoolean(Object sourceVal) { * @param targetType type to be test against * @return true if the value belongs to the given type, false otherwise */ - public static boolean checkIsType(Object sourceVal, Type targetType) { + public static boolean checkIsType(@Nullable Object sourceVal, Type targetType) { return checkIsType(null, sourceVal, getType(sourceVal), targetType); } @@ -291,7 +292,8 @@ public static boolean checkIsType(Object sourceVal, Type targetType) { * @param targetType type to be test against * @return true if the value belongs to the given type, false otherwise */ - public static boolean checkIsType(List errors, Object sourceVal, Type sourceType, Type targetType) { + public static boolean checkIsType( + @Nullable List errors, Object sourceVal, Type sourceType, Type targetType) { if (checkIsType(sourceVal, sourceType, targetType, null)) { return true; } @@ -317,7 +319,7 @@ public static boolean checkIsType(List errors, Object sourceVal, Type so * @param targetType type to check the shape against * @return true if the value has the same shape as the given type; false otherwise */ - public static boolean checkIsLikeType(Object sourceValue, Type targetType) { + public static boolean checkIsLikeType(@Nullable Object sourceValue, Type targetType) { return checkIsLikeType(sourceValue, targetType, false); } @@ -345,7 +347,7 @@ public static boolean isSameType(Type sourceType, Type targetType) { return sourceType == targetType || sourceType.equals(targetType); } - public static Type getType(Object value) { + public static Type getType(@Nullable Object value) { if (value == null) { return TYPE_NULL; } else if (value instanceof Number) { @@ -523,6 +525,7 @@ private static boolean isXMLSequenceRefEqual(XmlSequence lhsValue, XmlSequence r * @param value Value * @return type desc associated with the value */ + @Nullable public static TypedescValue getTypedesc(Object value) { Type type = TypeChecker.getType(value); if (type == null) { @@ -544,6 +547,7 @@ public static TypedescValue getTypedesc(Object value) { * @param annotTag The annot-tag-reference * @return the annotation value if present, nil else */ + @Nullable public static Object getAnnotValue(TypedescValue typedescValue, BString annotTag) { Type describingType = typedescValue.getDescribingType(); if (!(describingType instanceof BAnnotatableType annotatableType)) { @@ -564,7 +568,7 @@ public static boolean checkIsType(Type sourceType, Type targetType) { } @Deprecated - public static boolean checkIsType(Type sourceType, Type targetType, List unresolvedTypes) { + public static boolean checkIsType(Type sourceType, Type targetType, @Nullable List unresolvedTypes) { // First check whether both types are the same. if (sourceType == targetType || (sourceType.getTag() == targetType.getTag() && sourceType.equals(targetType))) { return true; @@ -662,7 +666,7 @@ public static boolean checkIsType(Type sourceType, Type targetType, List unresolvedTypes) { + @Nullable List unresolvedTypes) { sourceType = getImpliedType(sourceType); targetType = getImpliedType(targetType); @@ -970,6 +974,7 @@ private static boolean checkIsTableType(Type sourceType, BTableType targetType, return Arrays.equals(srcTableType.getFieldNames(), targetType.getFieldNames()); } + @Nullable static BField getTableConstraintField(Type constraintType, String fieldName) { switch (constraintType.getTag()) { case TypeTags.RECORD_TYPE_TAG: @@ -1617,7 +1622,7 @@ private static boolean checkObjectEquivalency(Type sourceType, BObjectType targe return checkObjectEquivalency(null, sourceType, targetType, unresolvedTypes); } - private static boolean checkObjectEquivalency(Object sourceVal, Type sourceType, BObjectType targetType, + private static boolean checkObjectEquivalency(@Nullable Object sourceVal, Type sourceType, BObjectType targetType, List unresolvedTypes) { sourceType = getImpliedType(sourceType); if (sourceType.getTag() != TypeTags.OBJECT_TYPE_TAG && sourceType.getTag() != TypeTags.SERVICE_TAG) { @@ -2110,9 +2115,9 @@ private static boolean checkIsNeverTypeOrStructureTypeWithARequiredNeverMember(T * @param varName variable name to identify the parent of a record field * @return True if the value confirms to the provided type. False, otherwise. */ - private static boolean checkIsLikeType(List errors, Object sourceValue, Type targetType, + private static boolean checkIsLikeType(@Nullable List errors, Object sourceValue, Type targetType, List unresolvedValues, - boolean allowNumericConversion, String varName) { + boolean allowNumericConversion, @Nullable String varName) { Type sourceType = getType(sourceValue); if (checkIsType(sourceType, targetType, new ArrayList<>())) { return true; @@ -2135,9 +2140,10 @@ private static boolean checkIsLikeType(List errors, Object sourceValue, * @param varName variable name to identify the parent of a record field * @return True if the value confirms to the provided type. False, otherwise. */ - private static boolean checkIsLikeOnValue(List errors, Object sourceValue, Type sourceType, Type targetType, - List unresolvedValues, boolean allowNumericConversion, - String varName) { + private static boolean checkIsLikeOnValue( + @Nullable List errors, Object sourceValue, Type sourceType, Type targetType, + List unresolvedValues, boolean allowNumericConversion, + @Nullable String varName) { int sourceTypeTag = sourceType.getTag(); int targetTypeTag = targetType.getTag(); @@ -2706,7 +2712,7 @@ private static boolean checkIsLikeRecordType(Object sourceValue, BRecordType tar return returnVal; } - private static void addErrorMessage(int initialErrorCount, String errorMessage, List errors) { + private static void addErrorMessage(int initialErrorCount, String errorMessage, @Nullable List errors) { if ((errors != null) && (errors.size() <= MAX_TYPECAST_ERROR_COUNT) && ((errors.size() - initialErrorCount) == 0)) { errors.add(errorMessage); @@ -3271,6 +3277,7 @@ private static boolean containsElement(Set valueSpace, String e) { return false; } + @Nullable public static Object handleAnydataValues(Object sourceVal, Type targetType) { if (sourceVal != null && !(sourceVal instanceof Number) && !(sourceVal instanceof BString) && !(sourceVal instanceof Boolean) && !(sourceVal instanceof BValue)) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java index 82f3ffbdb370..715338bf02db 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java @@ -56,6 +56,7 @@ import io.ballerina.runtime.internal.values.DecimalValue; import io.ballerina.runtime.internal.values.MapValueImpl; import io.ballerina.runtime.internal.values.RegExpValue; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -237,7 +238,8 @@ static boolean isConvertibleToFloatingPointTypes(Object value) { }; } - public static Type getConvertibleType(Object inputValue, Type targetType, String varName, + @Nullable + public static Type getConvertibleType(@Nullable Object inputValue, Type targetType, @Nullable String varName, Set unresolvedValues, List errors, boolean allowNumericConversion) { @@ -305,6 +307,7 @@ public static Type getConvertibleType(Object inputValue, Type targetType, String return null; } + @Nullable private static Type getConvertibleTypeForJsonType(Object inputValue, Type targetJsonType, boolean allowNumericConversion) { if (!TypeChecker.checkIsLikeType(inputValue, targetJsonType, allowNumericConversion)) { @@ -326,8 +329,9 @@ private static boolean isStringConvertibleToTargetXmlType(Object inputValue, Typ return TypeChecker.checkIsLikeType(xmlValue, targetType); } + @Nullable public static Type getConvertibleTypeInTargetUnionType(Object inputValue, BUnionType targetUnionType, - String varName, List errors, + @Nullable String varName, List errors, Set unresolvedValues, boolean allowNumericConversion) { List memberTypes = targetUnionType.getMemberTypes(); @@ -351,6 +355,7 @@ public static Type getConvertibleTypeInTargetUnionType(Object inputValue, BUnion return null; } + @Nullable private static Type getConvertibleStructuredTypeInUnion(Object inputValue, String varName, List errors, Set unresolvedValues, boolean allowNumericConversion, List memberTypes) { @@ -378,8 +383,9 @@ private static Type getConvertibleStructuredTypeInUnion(Object inputValue, Strin return null; } + @Nullable public static Type getConvertibleFiniteType(Object inputValue, BFiniteType targetFiniteType, - String varName, List errors, + @Nullable String varName, List errors, Set unresolvedValues, boolean allowNumericConversion) { // only the first matching type is returned. if (targetFiniteType.valueSpace.size() == 1) { @@ -1183,6 +1189,7 @@ private static boolean isFloatWithinIntRange(double doubleValue) { return doubleValue < BINT_MAX_VALUE_DOUBLE_RANGE_MAX && doubleValue > BINT_MIN_VALUE_DOUBLE_RANGE_MIN; } + @Nullable public static Type resolveMatchingTypeForUnion(Object value, Type targetUnionType) { if (value == null && targetUnionType.isNilable()) { return PredefinedTypes.TYPE_NULL; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueConverter.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueConverter.java index d29f432d9712..9ad55f17fdb7 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueConverter.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/ValueConverter.java @@ -55,6 +55,7 @@ import io.ballerina.runtime.internal.values.ReadOnlyUtils; import io.ballerina.runtime.internal.values.TableValueImpl; import io.ballerina.runtime.internal.values.TupleValueImpl; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -80,10 +81,12 @@ public static Object convert(Object value, BTypedesc t) { return convert(value, t.getDescribingType()); } + @Nullable public static Object convert(Object value, Type targetType) { return convert(value, targetType, new HashSet<>()); } + @Nullable private static Object convert(Object value, Type targetType, Set unresolvedValues) { if (value == null) { @@ -224,6 +227,7 @@ private static BMap convertToRecord(BMap map, Set unresolvedValues, Type restFieldType, Map targetTypeField, Map.Entry entry) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/XmlFactory.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/XmlFactory.java index 096f3c8f40c6..6ee49b91da0c 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/XmlFactory.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/XmlFactory.java @@ -38,6 +38,7 @@ import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMXMLBuilderFactory; import org.apache.axiom.om.util.StAXParserConfiguration; +import org.jetbrains.annotations.Nullable; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -240,7 +241,8 @@ public static BXml tableToXML(TableValueImpl table) { * @return XMLValue Element type XMLValue */ @Deprecated - public static XmlValue createXMLElement(BXmlQName startTagName, BXmlQName endTagName, String defaultNsUri) { + public static XmlValue createXMLElement( + BXmlQName startTagName, BXmlQName endTagName, @Nullable String defaultNsUri) { if (!isEqual(startTagName.getLocalName(), endTagName.getLocalName()) || !isEqual(startTagName.getUri(), endTagName.getUri()) || !isEqual(startTagName.getPrefix(), endTagName.getPrefix())) { @@ -259,7 +261,7 @@ public static XmlValue createXMLElement(BXmlQName startTagName, BXmlQName endTag * @return XMLValue Element type XMLValue */ @Deprecated - public static XmlValue createXMLElement(BXmlQName startTagName, String defaultNsUri) { + public static XmlValue createXMLElement(BXmlQName startTagName, @Nullable String defaultNsUri) { return createXMLElement(startTagName, defaultNsUri, false); } @@ -491,6 +493,7 @@ public static OMElement stringToOM(String xmlFragment) { * @param xmlFragment the well-formed XML fragment * @return The OMElement created out of the string XML fragment. */ + @Nullable private static OMElement stringToOM(OMFactory omFactory, String xmlFragment) { return xmlFragment != null ? OMXMLBuilderFactory diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/XmlTreeBuilder.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/XmlTreeBuilder.java index 922215fee5c4..71a4b269eb28 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/XmlTreeBuilder.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/XmlTreeBuilder.java @@ -29,6 +29,7 @@ import io.ballerina.runtime.internal.values.XmlQName; import io.ballerina.runtime.internal.values.XmlSequence; import io.ballerina.runtime.internal.values.XmlText; +import org.jetbrains.annotations.Nullable; import java.io.Reader; import java.io.StringReader; @@ -103,6 +104,7 @@ private void handleXMLStreamException(Exception e) { throw ErrorCreator.createError(StringUtils.fromString(XmlFactory.PARSE_ERROR_PREFIX + reason)); } + @Nullable public BXml parse() { boolean readNext = false; int next; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/cli/CliSpec.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/cli/CliSpec.java index 4f6bd7ebd631..52ee9465a02d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/cli/CliSpec.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/cli/CliSpec.java @@ -31,6 +31,7 @@ import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -47,7 +48,7 @@ public class CliSpec { private final List mainArgs; private final String[] args; - public CliSpec(Option option, Operand[] operands, String... args) { + public CliSpec(@Nullable Option option, Operand[] operands, String... args) { this.option = option; this.operands = operands; this.args = args; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/ConfigResolver.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/ConfigResolver.java index 2261fe6e8895..9203e9f55a5e 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/ConfigResolver.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/ConfigResolver.java @@ -27,6 +27,7 @@ import io.ballerina.runtime.internal.configurable.exceptions.ConfigException; import io.ballerina.runtime.internal.diagnostics.RuntimeDiagnosticLog; import io.ballerina.runtime.internal.errors.ErrorCodes; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -98,6 +99,7 @@ private Optional getConfigValue(Module module, VariableKey key) { return Optional.empty(); } + @Nullable private Function> getValueFunction(Module module, VariableKey key, Type type) { switch (type.getTag()) { case TypeTags.NULL_TAG: diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/VariableKey.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/VariableKey.java index 57409ff79a26..db3075abaa04 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/VariableKey.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/VariableKey.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.Module; import io.ballerina.runtime.api.types.Type; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -45,7 +46,7 @@ public VariableKey(Module module, String variable, Type type, boolean isRequired this(module, variable, type, null, isRequired); } - public VariableKey(Module module, String variable, Type type, String location, boolean isRequired) { + public VariableKey(Module module, String variable, Type type, @Nullable String location, boolean isRequired) { this.module = module; this.variable = variable; this.type = type; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/ConfigDetails.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/ConfigDetails.java index 38fe56a341e8..d6db56002e3f 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/ConfigDetails.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/ConfigDetails.java @@ -18,6 +18,8 @@ package io.ballerina.runtime.internal.configurable.providers; +import org.jetbrains.annotations.Nullable; + import java.nio.file.Path; /** @@ -30,7 +32,7 @@ public class ConfigDetails { public final Path[] paths; public final String configContent; - public ConfigDetails(Path[] paths, String configContent) { + public ConfigDetails(Path[] paths, @Nullable String configContent) { this.paths = paths; this.configContent = configContent; } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/cli/CliProvider.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/cli/CliProvider.java index 003998ff95d3..19f0d5a07553 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/cli/CliProvider.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/cli/CliProvider.java @@ -35,6 +35,7 @@ import io.ballerina.runtime.internal.types.BFiniteType; import io.ballerina.runtime.internal.types.BIntersectionType; import io.ballerina.runtime.internal.types.BUnionType; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -306,7 +307,7 @@ private CliArg getCliArg(Module module, VariableKey variableKey) { } private CliArg checkAmbiguitiesAndGetCliArg(VariableKey variableKey, String key, String moduleKey, - String rootOrgValue, String rootModuleValue) { + @Nullable String rootOrgValue, String rootModuleValue) { if (rootOrgValue == null && rootModuleValue == null) { return markAndGetCliArg(key, variableKey, null); } @@ -329,7 +330,7 @@ private CliArg checkAmbiguitiesAndGetCliArg(VariableKey variableKey, String key, } - private CliArg markAndGetCliArg(String key, VariableKey variableKey, String value) { + private CliArg markAndGetCliArg(String key, VariableKey variableKey, @Nullable String value) { // Handle cli args and module ambiguities VariableKey existingKey = markedCliKeyVariableMap.get(key); if (existingKey != null) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/env/EnvVarProvider.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/env/EnvVarProvider.java index 78cc5992c94f..f37e8cc95437 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/env/EnvVarProvider.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/env/EnvVarProvider.java @@ -33,6 +33,7 @@ import io.ballerina.runtime.internal.types.BFiniteType; import io.ballerina.runtime.internal.types.BIntersectionType; import io.ballerina.runtime.internal.types.BUnionType; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Locale; @@ -287,7 +288,7 @@ private static String getRefinedEnvVarKey(String key) { } private EnvVar checkAmbiguitiesAndGetEnvVar(VariableKey variableKey, String key, String moduleKey, - String rootOrgValue, String rootModuleValue) { + @Nullable String rootOrgValue, String rootModuleValue) { if (rootOrgValue == null && rootModuleValue == null) { return markAndGetEnvVar(key, variableKey, null); } @@ -310,7 +311,7 @@ private EnvVar checkAmbiguitiesAndGetEnvVar(VariableKey variableKey, String key, throw new ConfigException(CONFIG_ENV_VARS_AMBIGUITY, variableKey.variable, errorString); } - private EnvVar markAndGetEnvVar(String key, VariableKey variableKey, String value) { + private EnvVar markAndGetEnvVar(String key, VariableKey variableKey, @Nullable String value) { // Handle env vars and module ambiguities VariableKey existingKey = visitedEnvVariableMap.get(key); if (existingKey != null) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ConfigValueCreator.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ConfigValueCreator.java index 7c2c7164b131..b8761523ca1f 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ConfigValueCreator.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ConfigValueCreator.java @@ -56,6 +56,7 @@ import io.ballerina.toml.semantic.ast.TomlTableNode; import io.ballerina.toml.semantic.ast.TomlValueNode; import io.ballerina.toml.semantic.ast.TopLevelNode; +import org.jetbrains.annotations.Nullable; import java.math.BigDecimal; import java.util.ArrayList; @@ -349,6 +350,7 @@ private BMap createMapValue(TomlNode tomlValue, MapType mapType return ValueCreator.createMapValue(mapType, keyValueEntries); } + @Nullable private Object createUnionValue(TomlNode tomlValue, BUnionType unionType) { Object balValue = Utils.getBalValueFromToml(tomlValue, new HashSet<>(), unionType, new HashSet<>(), ""); Type convertibleType = TypeConverter.getConvertibleType(balValue, unionType, null, new HashSet<>(), diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ModuleInfo.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ModuleInfo.java index 26ecdfb6971b..f1e5efba8cfa 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ModuleInfo.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/ModuleInfo.java @@ -19,6 +19,7 @@ package io.ballerina.runtime.internal.configurable.providers.toml; import io.ballerina.runtime.api.Module; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.HashSet; @@ -64,7 +65,7 @@ boolean containsModule(String nodeName) { return moduleNames.contains(nodeName); } - Module getModuleFromName(String nodeName) { + @Nullable Module getModuleFromName(String nodeName) { for (Module entry : moduleSet) { if (entry.getName().equals(nodeName)) { return entry; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java index 949ebf33b0d1..e622c7bf12ce 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java @@ -58,6 +58,7 @@ import io.ballerina.toml.semantic.ast.TomlValueNode; import io.ballerina.toml.semantic.ast.TopLevelNode; import io.ballerina.tools.text.LineRange; +import org.jetbrains.annotations.Nullable; import java.math.BigDecimal; import java.util.ArrayList; @@ -449,6 +450,7 @@ private void validateTupleValue(TomlNode value, String variableName, TupleType t } } + @Nullable private Object getPrimitiveTomlValue(Module module, VariableKey key) { TomlNode tomlValue = getBasicTomlValue(module, key); if (tomlValue == null) { @@ -457,6 +459,7 @@ private Object getPrimitiveTomlValue(Module module, VariableKey key) { return ((TomlBasicValueNode) tomlValue).getValue(); } + @Nullable private TomlNode getBasicTomlValue(Module module, VariableKey key) { String variableName = key.variable; List moduleTomlNodes = getModuleTomlNodes(module, key); @@ -568,6 +571,7 @@ private void throwInvalidSubModuleError(Toml toml, Module module, String variabl } } + @Nullable private TomlNode getErrorNode(Toml toml, String moduleName, String orgModuleKey, String variableName) { // check for toml key-value error nodes Optional valueNode = toml.get(moduleName); @@ -639,6 +643,7 @@ private void validatePrimitiveValue(TomlNode tomlValue, String variableName, Typ validateSimpleValue(variableName, type, value); } + @Nullable private Object validateAndGetFiniteValue(TomlNode tomlValue, String variableName, BFiniteType type) { visitedNodes.add(tomlValue); Object balValue = Utils.getFiniteBalValue(tomlValue, visitedNodes, type, invalidTomlLines, diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/Utils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/Utils.java index 86d2615bc0b5..d2bf7fd4e707 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/Utils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/Utils.java @@ -59,6 +59,7 @@ import io.ballerina.toml.semantic.ast.TopLevelNode; import io.ballerina.tools.text.LinePosition; import io.ballerina.tools.text.LineRange; +import org.jetbrains.annotations.Nullable; import java.math.BigDecimal; import java.util.List; @@ -101,6 +102,7 @@ static Object getTomlTypeString(TomlNode tomlNode) { }; } + @Nullable static Object getBalValueFromToml(TomlNode tomlNode, Set visitedNodes, BUnionType unionType, Set invalidTomlLines, String variableName) { visitedNodes.add(tomlNode); @@ -214,6 +216,7 @@ static LineRange getOneBasedLineRange(LineRange lineRange) { LinePosition.from(lineRange.endLine().line() + 1, lineRange.endLine().offset() + 1)); } + @Nullable public static Type getTypeFromTomlValue(TomlNode tomlNode) { return switch (tomlNode.kind()) { case STRING -> PredefinedTypes.TYPE_STRING; @@ -371,6 +374,7 @@ static boolean containsMapType(List memberTypes) { return false; } + @Nullable public static Object getFiniteBalValue(TomlNode tomlNode, Set visitedNodes, BFiniteType finiteType, Set invalidTomlLines, String variableName) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnostic.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnostic.java index 868927bce53a..adbb8d5aee4a 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnostic.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnostic.java @@ -23,6 +23,7 @@ import io.ballerina.tools.diagnostics.DiagnosticProperty; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -60,6 +61,7 @@ public String message() { return ErrorHelper.getErrorMessage(diagnosticInfo.messageFormat(), args).getValue(); } + @Nullable @Override public List> properties() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnosticLocation.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnosticLocation.java index 243ae95b2fb5..32083be89059 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnosticLocation.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnosticLocation.java @@ -20,6 +20,7 @@ import io.ballerina.tools.diagnostics.Location; import io.ballerina.tools.text.LineRange; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; /** * Represent the location of a diagnostic at runtime. @@ -34,11 +35,13 @@ public RuntimeDiagnosticLocation(String location) { this.location = location; } + @Nullable @Override public LineRange lineRange() { return null; } + @Nullable @Override public TextRange textRange() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnosticLog.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnosticLog.java index 7b08579ffd2e..ea5ad4294bd0 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnosticLog.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/diagnostics/RuntimeDiagnosticLog.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.internal.errors.ErrorCodes; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.LinkedList; @@ -38,14 +39,14 @@ public class RuntimeDiagnosticLog { private int warnCount = 0; - public void error(ErrorCodes errorCode, String location, Object... args) { + public void error(ErrorCodes errorCode, @Nullable String location, Object... args) { errorCount += 1; DiagnosticInfo diagnosticInfo = new DiagnosticInfo(errorCode.diagnosticId(), errorCode.messageKey(), DiagnosticSeverity.ERROR); diagnosticList.add(new RuntimeDiagnostic(diagnosticInfo, location, args)); } - public void warn(ErrorCodes errorCode, String location, Object... args) { + public void warn(ErrorCodes errorCode, @Nullable String location, Object... args) { warnCount += 1; DiagnosticInfo diagnosticInfo = new DiagnosticInfo(errorCode.diagnosticId(), errorCode.messageKey(), DiagnosticSeverity.WARNING); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java index d7c8f54b025b..a1b4c66d7661 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java @@ -32,6 +32,7 @@ import io.ballerina.runtime.internal.diagnostics.RuntimeDiagnosticLog; import io.ballerina.runtime.internal.troubleshoot.StrandDump; import io.ballerina.runtime.internal.util.RuntimeUtils; +import org.jetbrains.annotations.Nullable; import sun.misc.Signal; import java.io.File; @@ -142,6 +143,7 @@ public static ConfigDetails getConfigurationDetails() { return new ConfigDetails(paths.toArray(new Path[0]), configContent); } + @Nullable private static String populateConfigDetails(List paths, Map envVars) { if (envVars.containsKey(CONFIG_FILES_ENV_VARIABLE)) { String[] configPathList = envVars.get(CONFIG_FILES_ENV_VARIABLE).split(File.pathSeparator); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/regexp/TreeBuilder.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/regexp/TreeBuilder.java index dfc830b92229..2e6318fa77e4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/regexp/TreeBuilder.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/regexp/TreeBuilder.java @@ -37,6 +37,7 @@ import io.ballerina.runtime.internal.values.RegExpSequence; import io.ballerina.runtime.internal.values.RegExpTerm; import io.ballerina.runtime.internal.values.RegExpValue; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -421,6 +422,7 @@ private String readCharacterClassEnd() { ErrorCodes.REGEXP_MISSING_CLOSE_BRACKET.messageKey())); } + @Nullable private RegExpQuantifier readOptionalQuantifier() { Token nextToken = peek(); return switch (nextToken.kind) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/regexp/TreeTraverser.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/regexp/TreeTraverser.java index d2ffe5841a35..bf17bf645a8c 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/regexp/TreeTraverser.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/regexp/TreeTraverser.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.internal.errors.ErrorCodes; import io.ballerina.runtime.internal.errors.ErrorHelper; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; @@ -31,6 +32,7 @@ public class TreeTraverser { private final CharReader reader; + @Nullable private ParserMode mode; private final ArrayDeque modeStack = new ArrayDeque<>(); @@ -40,6 +42,7 @@ public TreeTraverser(CharReader charReader) { this.modeStack.add(this.mode); } + @Nullable public Token nextToken() { return switch (this.mode) { case RE_DISJUNCTION -> readTokenInReDisjunction(); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java index 945f60e47513..b7bca9188ae2 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java @@ -38,6 +38,7 @@ import io.ballerina.runtime.internal.types.BServiceType; import io.ballerina.runtime.internal.values.FutureValue; import io.ballerina.runtime.internal.values.ValueCreator; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -130,7 +131,7 @@ public void notifyFailure(BError error) { * @param returnValueSupplier Suppler used to set the final return value for the parent function invocation. * @param scheduler The scheduler for invoking functions */ - public static void invokeFunctionPointerAsyncIteratively(BFunctionPointer func, String strandName, + public static void invokeFunctionPointerAsyncIteratively(BFunctionPointer func, @Nullable String strandName, StrandMetadata metadata, int noOfIterations, Supplier argsSupplier, Consumer futureResultConsumer, diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java index a2d081f95ff9..873376a8957c 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java @@ -30,6 +30,7 @@ import io.ballerina.runtime.internal.util.RuntimeUtils; import io.ballerina.runtime.internal.values.ChannelDetails; import io.ballerina.runtime.internal.values.FutureValue; +import org.jetbrains.annotations.Nullable; import java.io.PrintStream; import java.util.HashMap; @@ -208,9 +209,10 @@ public FutureValue scheduleToObjectGroup(Object[] params, Function * @param metadata meta data of new strand * @return Reference to the scheduled task */ - public FutureValue schedule(Object[] params, Function function, Strand parent, Callback callback, - Map properties, Type returnType, String strandName, - StrandMetadata metadata) { + public FutureValue schedule( + Object[] params, Function function, @Nullable Strand parent, @Nullable Callback callback, + @Nullable Map properties, @Nullable Type returnType, @Nullable String strandName, + @Nullable StrandMetadata metadata) { FutureValue future = createFuture(parent, callback, properties, returnType, strandName, metadata); return schedule(params, function, future); } @@ -226,8 +228,8 @@ public FutureValue schedule(Object[] params, Function function, Str * @param metadata meta data of new strand * @return Reference to the scheduled task */ - public FutureValue schedule(Object[] params, Function function, Strand parent, Callback callback, - String strandName, StrandMetadata metadata) { + public FutureValue schedule(Object[] params, Function function, @Nullable Strand parent, Callback callback, + String strandName, @Nullable StrandMetadata metadata) { FutureValue future = createFuture(parent, callback, null, PredefinedTypes.TYPE_NULL, strandName, metadata); return schedule(params, function, future); } @@ -350,7 +352,7 @@ private void run() { /** * Processes the item after executing for notifying blocked items etc. */ - private void postProcess(SchedulerItem item, Object result, Throwable panic) { + private void postProcess(SchedulerItem item, @Nullable Object result, @Nullable Throwable panic) { switch (item.getState()) { case BLOCK_AND_YIELD: item.future.strand.lock(); @@ -507,15 +509,16 @@ private void addToRunnableList(SchedulerItem item, ItemGroup group) { group.unlock(); } - public FutureValue createFuture(Strand parent, Callback callback, Map properties, - Type constraint, String name, StrandMetadata metadata) { + public FutureValue createFuture( + @Nullable Strand parent, @Nullable Callback callback, @Nullable Map properties, + @Nullable Type constraint, @Nullable String name, @Nullable StrandMetadata metadata) { Strand newStrand = new Strand(name, metadata, this, parent, properties, parent != null ? parent.currentTrxContext : null); CURRENT_STRANDS.put(newStrand.getId(), newStrand); return createFuture(parent, callback, constraint, newStrand); } - private FutureValue createFuture(Strand parent, Callback callback, Type constraint, Strand newStrand) { + private FutureValue createFuture(@Nullable Strand parent, Callback callback, Type constraint, Strand newStrand) { FutureValue future = new FutureValue(newStrand, callback, constraint); future.strand.frames = new Stack<>(); return future; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java index f107be50f6e8..2f969de69e4d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java @@ -31,6 +31,7 @@ import io.ballerina.runtime.internal.values.FutureValue; import io.ballerina.runtime.internal.values.MapValue; import io.ballerina.runtime.transactions.TransactionLocalContext; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -66,9 +67,11 @@ public class Strand { private final String name; private final StrandMetadata metadata; + @Nullable public Stack frames; public int resumeIndex; public int functionInvocation; + @Nullable public Object returnValue; public BError panic; public Scheduler scheduler; @@ -82,15 +85,17 @@ public class Strand { public int acquiredLockCount; SchedulerItem schedulerItem; - List waitingContexts; + @Nullable List waitingContexts; WaitContext waitContext; ItemGroup strandGroup; private Map globalProps; + @Nullable public TransactionLocalContext currentTrxContext; public Stack trxContexts; private State state; private final ReentrantLock strandLock; + @Nullable public BMap workerReceiveMap = null; public int channelCount = 0; @@ -127,7 +132,7 @@ public Strand(String name, StrandMetadata metadata, Scheduler scheduler, Strand } } public Strand(String name, StrandMetadata metadata, Scheduler scheduler, Strand parent, - Map properties, TransactionLocalContext currentTrxContext) { + Map properties, @Nullable TransactionLocalContext currentTrxContext) { this(name, metadata, scheduler, parent, properties); if (currentTrxContext != null) { this.trxContexts = parent.trxContexts; @@ -210,6 +215,7 @@ public void setCurrentTransactionContext(TransactionLocalContext ctx) { globalProps.putIfAbsent(CURRENT_TRANSACTION_CONTEXT_PROPERTY, this.currentTrxContext); } + @Nullable public ErrorValue handleFlush(ChannelDetails[] channels) throws Throwable { try { if (flushDetail == null) { @@ -517,8 +523,10 @@ public static class FlushDetail { public ChannelDetails[] flushChannels; public int flushedCount; public Lock flushLock; + @Nullable public ErrorValue result; public boolean inProgress; + @Nullable public Throwable panic; public FlushDetail(ChannelDetails[] flushChannels) { @@ -539,7 +547,7 @@ public static class WaitResult { public boolean done; public Object result; - public WaitResult(boolean done, Object result) { + public WaitResult(boolean done, @Nullable Object result) { this.done = done; this.result = result; } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/WDChannels.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/WDChannels.java index f00a5c9a40b3..b71759124438 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/WDChannels.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/WDChannels.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.internal.ErrorUtils; import io.ballerina.runtime.internal.values.ChannelDetails; import io.ballerina.runtime.internal.values.ErrorValue; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -60,6 +61,7 @@ public synchronized WorkerDataChannel getWorkerDataChannel(String name) { return channel; } + @Nullable public Object receiveDataMultipleChannels(Strand strand, ReceiveField[] receiveFields, Type targetType) throws Throwable { if (strand.workerReceiveMap == null) { @@ -95,6 +97,7 @@ private void checkAndPopulateResult(Strand strand, ReceiveField field, Object re ++strand.channelCount; } + @Nullable private Object clearResultCache(Strand strand, ReceiveField[] receiveFields) { if (strand.channelCount != receiveFields.length) { return null; @@ -122,6 +125,7 @@ public Object receiveDataAlternateChannels(Strand strand, String[] channels) thr return processResulAndError(strand, channels, result, allChannelsClosed); } + @Nullable private Object handleResultForOpenChannel(Strand strand, String[] channels, WorkerDataChannel channel) throws Throwable { Object result = channel.tryTakeData(strand, true); @@ -138,14 +142,16 @@ private Object handleResultForOpenChannel(Strand strand, String[] channels, Work return result; } - private static Object getResultValue(Object result) { + private static Object getResultValue(@Nullable Object result) { if (result instanceof WorkerDataChannel.WorkerResult workerResult) { return workerResult.value; } return result; } - private Object processResulAndError(Strand strand, String[] channels, Object result, boolean allChannelsClosed) { + @Nullable + private Object processResulAndError( + Strand strand, String[] channels, @Nullable Object result, boolean allChannelsClosed) { if (result == null) { if (errors.size() == channels.length) { result = errors.get(errors.size() - 1); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/WorkerDataChannel.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/WorkerDataChannel.java index c4ada8ee3efa..d61fb0c3dedf 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/WorkerDataChannel.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/WorkerDataChannel.java @@ -19,6 +19,7 @@ import io.ballerina.runtime.internal.ErrorUtils; import io.ballerina.runtime.internal.values.ErrorValue; +import org.jetbrains.annotations.Nullable; import java.util.LinkedList; import java.util.Queue; @@ -35,10 +36,14 @@ */ public class WorkerDataChannel { + @Nullable private Strand receiver; + @Nullable private WaitingSender waitingSender; + @Nullable private WaitingSender flushSender; private ErrorValue error; + @Nullable private Throwable panic; private int senderCounter; private int receiverCounter; @@ -134,6 +139,7 @@ public void close() { * @return error if receiver already in error state, else null * @throws Throwable panic */ + @Nullable public Object syncSendData(Object data, Strand strand) throws Throwable { try { acquireChannelLock(); @@ -187,6 +193,7 @@ public Object tryTakeData(Strand strand) throws Throwable { return tryTakeData(strand, false); } + @Nullable public Object tryTakeData(Strand strand, boolean isMultiple) throws Throwable { try { acquireChannelLock(); @@ -289,6 +296,7 @@ public void setReceiveError(ErrorValue error) { * @return error or null * @throws Throwable panic */ + @Nullable public ErrorValue flushChannel(Strand strand) throws Throwable { acquireChannelLock(); try { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnnotatableType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnnotatableType.java index a3ceb4253798..37a24200d998 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnnotatableType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnnotatableType.java @@ -23,6 +23,7 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; import java.util.LinkedHashMap; @@ -35,7 +36,7 @@ public abstract class BAnnotatableType extends BType implements AnnotatableType protected BMap annotations = ValueCreator.createMapValue(); - BAnnotatableType(String typeName, Module pkg, Class valueClass) { + BAnnotatableType(@Nullable String typeName, @Nullable Module pkg, Class valueClass) { super(typeName, pkg, valueClass); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnyType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnyType.java index 6c9dfbbd046f..447d808e4c6f 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnyType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnyType.java @@ -26,6 +26,7 @@ import io.ballerina.runtime.api.types.IntersectionType; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.internal.values.RefValue; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -56,11 +57,13 @@ public BAnyType(String typeName, Module pkg, boolean readonly) { } } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnydataType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnydataType.java index 7d006df8e080..a96069aa564d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnydataType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BAnydataType.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.types.AnydataType; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.internal.values.RefValue; +import org.jetbrains.annotations.Nullable; /** * {@code BAnydataType} represents the data types in Ballerina. @@ -59,11 +60,13 @@ public BAnydataType(BUnionType unionType, String typeName, boolean readonly) { } } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BErrorType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BErrorType.java index 59cf32500a3d..a86c2f21c819 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BErrorType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BErrorType.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.types.IntersectionType; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.internal.values.ErrorValue; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -52,11 +53,13 @@ public void setTypeIdSet(BTypeIdSet typeIdSet) { this.typeIdSet = typeIdSet; } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFiniteType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFiniteType.java index 3ca2ae443844..01201aa6afda 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFiniteType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFiniteType.java @@ -23,6 +23,7 @@ import io.ballerina.runtime.api.types.FiniteType; import io.ballerina.runtime.internal.TypeChecker; import io.ballerina.runtime.internal.values.RefValue; +import org.jetbrains.annotations.Nullable; import java.util.Iterator; import java.util.LinkedHashSet; @@ -57,6 +58,7 @@ public BFiniteType(String typeName, String originalName, Set values, int this.originalName = originalName; } + @Nullable @Override public V getZeroValue() { if (valueSpace.stream().anyMatch(val -> val == null || TypeChecker.getType(val).isNilable())) { @@ -90,6 +92,7 @@ public String getName() { return this.originalName; } + @Nullable @Override public V getEmptyValue() { if (valueSpace.stream().anyMatch(val -> val == null || TypeChecker.getType(val).isNilable())) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFunctionType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFunctionType.java index 9916e0ba4da4..e47fb78d085f 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFunctionType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFunctionType.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.types.FunctionType; import io.ballerina.runtime.api.types.Parameter; import io.ballerina.runtime.api.types.Type; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -36,8 +37,10 @@ public class BFunctionType extends BAnnotatableType implements FunctionType { public Type restType; + @Nullable public Type retType; public long flags; + @Nullable public Parameter[] parameters; public BFunctionType(Module pkg) { @@ -86,11 +89,13 @@ public Type getReturnParameterType() { return retType; } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFutureType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFutureType.java index df747fc1865c..e2c94cb00406 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFutureType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFutureType.java @@ -23,6 +23,7 @@ import io.ballerina.runtime.api.types.FutureType; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.internal.TypeChecker; +import org.jetbrains.annotations.Nullable; /** * {@code BFutureType} represents a future value in Ballerina. @@ -52,11 +53,13 @@ public Type getConstrainedType() { return constraint; } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BHandleType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BHandleType.java index 89b5482936bf..04c6c85fd534 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BHandleType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BHandleType.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.types.HandleType; import io.ballerina.runtime.internal.values.RefValue; +import org.jetbrains.annotations.Nullable; /** * {@code BHandleType} represents a handle type in Ballerina. @@ -39,11 +40,13 @@ public BHandleType(String typeName, Module pkg) { super(typeName, pkg, RefValue.class); } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BIntersectionType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BIntersectionType.java index c2112f4a4578..cefe36b3c6e4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BIntersectionType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BIntersectionType.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.types.IntersectableReferenceType; import io.ballerina.runtime.api.types.IntersectionType; import io.ballerina.runtime.api.types.Type; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -60,7 +61,7 @@ public BIntersectionType(Module pkg, Type[] constituentTypes, Type effectiveType this.effectiveType = effectiveType; } - public BIntersectionType(Module pkg, Type[] constituentTypes, IntersectableReferenceType effectiveType, + public BIntersectionType(@Nullable Module pkg, Type[] constituentTypes, IntersectableReferenceType effectiveType, int typeFlags, boolean readonly) { this(TypeConstants.INTERSECTION_TNAME, pkg, constituentTypes, typeFlags, readonly); this.effectiveType = effectiveType; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BIteratorType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BIteratorType.java index 13d870f510b6..5571b17c201b 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BIteratorType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BIteratorType.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.types.IteratorType; import io.ballerina.runtime.internal.values.IteratorValue; +import org.jetbrains.annotations.Nullable; /** * {@code BIteratorType} represents the type of iterator in ballerina. @@ -33,11 +34,13 @@ public BIteratorType(String typeName, Module pkg) { super(typeName, pkg, IteratorValue.class); } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BJsonType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BJsonType.java index 382a5d4b66f8..5272ae1699b3 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BJsonType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BJsonType.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.types.JsonType; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.internal.values.MapValueImpl; +import org.jetbrains.annotations.Nullable; /** * {@code BJSONType} represents a JSON value. @@ -73,6 +74,7 @@ public BJsonType(BUnionType unionType, String typeName, boolean readonly) { } + @Nullable @Override public V getZeroValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMapType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMapType.java index c69aaa56c144..0d5e220b198b 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMapType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMapType.java @@ -27,6 +27,7 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.internal.values.MapValueImpl; import io.ballerina.runtime.internal.values.ReadOnlyUtils; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -67,7 +68,7 @@ public BMapType(String typeName, Type constraint, Module pkg) { this(typeName, constraint, pkg, false); } - public BMapType(String typeName, Type constraint, Module pkg, boolean readonly) { + public BMapType(String typeName, Type constraint, @Nullable Module pkg, boolean readonly) { super(typeName, pkg, MapValueImpl.class); this.constraint = readonly ? ReadOnlyUtils.getReadOnlyType(constraint) : constraint; this.readonly = readonly; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BNullType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BNullType.java index 702133228119..1ad9e17db372 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BNullType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BNullType.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.Module; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.types.NullType; +import org.jetbrains.annotations.Nullable; /** * {@code BNullType} represents the type of a {@code NullLiteral}. @@ -38,11 +39,13 @@ public BNullType(String typeName, Module pkg) { super(typeName, pkg, null); } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BObjectType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BObjectType.java index a4e609158587..1fb9085823ce 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BObjectType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BObjectType.java @@ -34,6 +34,7 @@ import io.ballerina.runtime.internal.ValueUtils; import io.ballerina.runtime.internal.scheduling.Scheduler; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Array; import java.util.ArrayList; @@ -99,6 +100,7 @@ public String getAnnotationKey() { return Utils.decodeIdentifier(this.typeName); } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BReadonlyType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BReadonlyType.java index 8fb84c638a1e..42c2543c1507 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BReadonlyType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BReadonlyType.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.types.ReadonlyType; import io.ballerina.runtime.internal.values.RefValue; +import org.jetbrains.annotations.Nullable; /** * {@code BReadonlyType} represents the shapes that have their read-only bit on. @@ -33,11 +34,13 @@ public BReadonlyType(String typeName, Module pkg) { super(typeName, pkg, RefValue.class); } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BRecordType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BRecordType.java index 27b9286de00e..87798b5657b8 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BRecordType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BRecordType.java @@ -37,6 +37,7 @@ import io.ballerina.runtime.internal.values.MapValue; import io.ballerina.runtime.internal.values.MapValueImpl; import io.ballerina.runtime.internal.values.ReadOnlyUtils; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.HashSet; @@ -88,8 +89,8 @@ public BRecordType(String typeName, String internalName, Module pkg, long flags, * @param sealed flag to indicate whether the record is sealed * @param typeFlags flags associated with the type */ - public BRecordType(String typeName, Module pkg, long flags, Map fields, Type restFieldType, - boolean sealed, int typeFlags) { + public BRecordType(String typeName, @Nullable Module pkg, long flags, Map fields, + @Nullable Type restFieldType, boolean sealed, int typeFlags) { super(typeName, pkg, flags, MapValueImpl.class); this.sealed = sealed; this.typeFlags = typeFlags; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BStreamType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BStreamType.java index 049ba7f16452..71dee9f7c9e4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BStreamType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BStreamType.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.types.StreamType; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.internal.values.StreamValue; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -46,7 +47,7 @@ public class BStreamType extends BType implements StreamType { * @param completionType the type which indicates the completion of the stream * @param pkgPath package path */ - public BStreamType(String typeName, Type constraint, Type completionType, Module pkgPath) { + public BStreamType(String typeName, Type constraint, Type completionType, @Nullable Module pkgPath) { super(typeName, pkgPath, StreamValue.class); this.constraint = constraint; this.completionType = completionType; @@ -71,7 +72,7 @@ public BStreamType(Type constraint, Type completionType) { * @deprecated use {@link #BStreamType(String, Type, Type, Module)} instead. */ @Deprecated - public BStreamType(String typeName, Type constraint, Module pkgPath) { + public BStreamType(String typeName, Type constraint, @Nullable Module pkgPath) { this(typeName, constraint, PredefinedTypes.TYPE_NULL, pkgPath); } @@ -101,6 +102,7 @@ public V getZeroValue() { return (V) new StreamValue(this); } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BTupleType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BTupleType.java index 21fb42a59f92..54685ebf7cf3 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BTupleType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BTupleType.java @@ -26,6 +26,7 @@ import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.internal.values.ReadOnlyUtils; import io.ballerina.runtime.internal.values.TupleValueImpl; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -41,6 +42,7 @@ public class BTupleType extends BAnnotatableType implements TupleType { private List tupleTypes; + @Nullable private Type restType; private int typeFlags; private final boolean readonly; @@ -68,7 +70,7 @@ public BTupleType(List typeList, int typeFlags) { this(typeList, null, typeFlags, false, false); } - public BTupleType(List typeList, Type restType, int typeFlags, boolean readonly) { + public BTupleType(List typeList, @Nullable Type restType, int typeFlags, boolean readonly) { this(typeList, restType, typeFlags, false, readonly); } @@ -80,7 +82,7 @@ public BTupleType(List typeList, Type restType, int typeFlags, boolean rea * @param typeFlags flags associated with the type * @param readonly whether immutable */ - public BTupleType(List typeList, Type restType, int typeFlags, boolean isCyclic, boolean readonly) { + public BTupleType(List typeList, @Nullable Type restType, int typeFlags, boolean isCyclic, boolean readonly) { super(null, null, Object.class); if (readonly) { this.resolvingReadonly = true; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java index 5d2aba9ddc8f..013eca1eb458 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.internal.TypeChecker; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -45,7 +46,7 @@ public abstract class BType implements Type { private Type cachedReferredType = null; private Type cachedImpliedType = null; - protected BType(String typeName, Module pkg, Class valueClass) { + protected BType(@Nullable String typeName, @Nullable Module pkg, @Nullable Class valueClass) { this.typeName = typeName; this.pkg = pkg; this.valueClass = valueClass; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BUnionType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BUnionType.java index 3f957eac231a..1a36e1fdbcce 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BUnionType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BUnionType.java @@ -28,6 +28,7 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.internal.TypeChecker; import io.ballerina.runtime.internal.values.ReadOnlyUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -130,7 +131,7 @@ public BUnionType(String name, Module pkg, int typeFlags, boolean isCyclic, long this(new ArrayList<>(0), name, pkg, typeFlags, isCyclic, flags); } - protected BUnionType(String typeName, Module pkg, boolean readonly, Class valueClass) { + protected BUnionType(String typeName, @Nullable Module pkg, boolean readonly, Class valueClass) { super(typeName, pkg, valueClass); this.readonly = readonly; } @@ -299,6 +300,7 @@ private List getReadOnlyTypes(Type[] memberTypes) { return readOnlyTypes; } + @Nullable @Override public V getZeroValue() { if (isNilable() || memberTypes.stream().anyMatch(Type::isNilable)) { @@ -314,6 +316,7 @@ public V getZeroValue() { } } + @Nullable @Override public V getEmptyValue() { if (isNilable() || memberTypes.stream().anyMatch(Type::isNilable)) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BXmlAttributesType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BXmlAttributesType.java index d9edf897051a..5974c829b712 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BXmlAttributesType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BXmlAttributesType.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.Module; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.types.XmlAttributesType; +import org.jetbrains.annotations.Nullable; /** * {@code BXMLAttributesType} represents the type of an xml-attribute-map in ballerina. @@ -38,11 +39,13 @@ public BXmlAttributesType(String typeName, Module pkg) { super(typeName, pkg, null); } + @Nullable @Override public V getZeroValue() { return null; } + @Nullable @Override public V getEmptyValue() { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BXmlType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BXmlType.java index c48c9d085594..23f3bc11a131 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BXmlType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BXmlType.java @@ -26,6 +26,7 @@ import io.ballerina.runtime.internal.values.ReadOnlyUtils; import io.ballerina.runtime.internal.values.XmlSequence; import io.ballerina.runtime.internal.values.XmlValue; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -38,6 +39,7 @@ public class BXmlType extends BType implements XmlType { private final int tag; + @Nullable public Type constraint; private final boolean readonly; private IntersectionType immutableType; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/util/StringUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/util/StringUtils.java index fa44bae7cf50..50c01bb3b395 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/util/StringUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/util/StringUtils.java @@ -39,6 +39,7 @@ import io.ballerina.runtime.internal.values.DecimalValue; import io.ballerina.runtime.internal.values.MapValueImpl; import io.ballerina.runtime.internal.values.ObjectValue; +import org.jetbrains.annotations.Nullable; import static io.ballerina.runtime.api.utils.StringUtils.fromString; @@ -61,7 +62,7 @@ private StringUtils() {} * @param parent The link to the parent node * @return String value of the value */ - public static String getStringVal(Object value, BLink parent) { + public static String getStringVal(Object value, @Nullable BLink parent) { if (value == null) { return ""; } @@ -108,7 +109,7 @@ public static String getStringVal(Object value, BLink parent) { * @param parent The link to the parent node * @return String value of the value in expression style */ - public static String getExpressionStringVal(Object value, BLink parent) { + public static String getExpressionStringVal(Object value, @Nullable BLink parent) { if (value == null) { return "()"; } @@ -167,7 +168,8 @@ public static String getExpressionStringVal(Object value, BLink parent) { * @return Ballerina value represented by Ballerina expression syntax * @throws BError for any parsing error */ - public static Object parseExpressionStringVal(String value, BLink parent) throws BError { + @Nullable + public static Object parseExpressionStringVal(String value, @Nullable BLink parent) throws BError { String exprValue = value.trim(); int endIndex = exprValue.length() - 1; if (exprValue.equals("()")) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AbstractArrayValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AbstractArrayValue.java index ab80640c69d0..442acb051390 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AbstractArrayValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AbstractArrayValue.java @@ -27,6 +27,7 @@ import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.types.BTupleType; import io.ballerina.runtime.internal.types.BUnionType; +import org.jetbrains.annotations.Nullable; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -289,6 +290,7 @@ static class ArrayIterator implements IteratorValue { this.length = value.size(); } + @Nullable @Override public Object next() { long cursor = this.cursor++; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AbstractObjectValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AbstractObjectValue.java index 07d20399f30d..cc1235dfc239 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AbstractObjectValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AbstractObjectValue.java @@ -35,6 +35,7 @@ import io.ballerina.runtime.internal.errors.ErrorCodes; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.types.BObjectType; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.List; @@ -194,6 +195,7 @@ public BTypedesc getTypedesc() { return typedesc; } + @Nullable private String getStringValue(Object value) { if (value == null) { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ArrayValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ArrayValueImpl.java index e983854997ef..1b7d590f6786 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ArrayValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ArrayValueImpl.java @@ -41,6 +41,7 @@ import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.errors.ErrorReasons; import io.ballerina.runtime.internal.types.BArrayType; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.OutputStream; @@ -85,6 +86,7 @@ public class ArrayValueImpl extends AbstractArrayValue { private byte[] byteValues; private double[] floatValues; private BString[] bStringValues; + @Nullable private BTypedesc typedesc; // ------------------------ Constructors ------------------------------------------------------------------- @@ -276,7 +278,8 @@ public ArrayValueImpl(Type type, BListInitialValueEntry[] initialValues, Typedes this(type, ((ArrayType) TypeUtils.getImpliedType(type)).getSize(), initialValues, typedescValue); } - public ArrayValueImpl(Type type, long size, BListInitialValueEntry[] initialValues, TypedescValue typedescValue) { + public ArrayValueImpl(Type type, long size, BListInitialValueEntry[] initialValues, + @Nullable TypedescValue typedescValue) { this.type = type; this.arrayType = (ArrayType) TypeUtils.getImpliedType(type); this.elementType = arrayType.getElementType(); @@ -465,7 +468,7 @@ public BString getBString(long index) { * @param value value to be added */ @Override - public void add(long index, Object value) { + public void add(long index, @Nullable Object value) { handleImmutableArrayValue(); addRefValue(index, value); } @@ -739,7 +742,7 @@ public void unshift(Object[] values) { } @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { StringJoiner sj = new StringJoiner(","); switch (this.elementReferredType.getTag()) { case TypeTags.INT_TAG: diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AttributeMapValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AttributeMapValueImpl.java index ea3b593194ef..e0482582d6ee 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AttributeMapValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/AttributeMapValueImpl.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.internal.XmlValidator; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.types.BMapType; +import org.jetbrains.annotations.Nullable; import javax.xml.XMLConstants; @@ -115,6 +116,7 @@ void setAttribute(String localName, String namespaceUri, String prefix, String v } } + @Nullable private BString insertValue(BString keyBStr, BString value, boolean onInitialization) { String key = keyBStr.getValue(); String localName = ""; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/BmpStringValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/BmpStringValue.java index 38f3b6603f78..a7ae15434040 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/BmpStringValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/BmpStringValue.java @@ -19,6 +19,7 @@ package io.ballerina.runtime.internal.values; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; /** * Represent ballerina strings containing only unicode basic multilingual plane characters. @@ -56,12 +57,14 @@ public BString concat(BString str) { return new BmpStringValue(this.value + str.getValue()); } + @Nullable @Override public Long indexOf(BString str, int fromIndex) { long index = value.indexOf(str.getValue(), fromIndex); return index >= 0 ? index : null; } + @Nullable @Override public Long lastIndexOf(BString str, int fromIndex) { long index = value.lastIndexOf(str.getValue(), fromIndex); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/DecimalValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/DecimalValue.java index 2771264baf37..45432fc28ddb 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/DecimalValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/DecimalValue.java @@ -29,6 +29,7 @@ import io.ballerina.runtime.internal.errors.ErrorCodes; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.errors.ErrorReasons; +import org.jetbrains.annotations.Nullable; import java.math.BigDecimal; import java.math.MathContext; @@ -195,7 +196,7 @@ public Object frozenCopy(Map refs) { * @param parent The link to the parent node */ @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { if (this.valueKind != DecimalValueKind.OTHER) { return this.valueKind.getValue(); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ErrorValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ErrorValue.java index dd534b85352e..6b4a6e3980c9 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ErrorValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ErrorValue.java @@ -35,6 +35,7 @@ import io.ballerina.runtime.internal.TypeChecker; import io.ballerina.runtime.internal.types.BErrorType; import io.ballerina.runtime.internal.types.BTypeIdSet; +import org.jetbrains.annotations.Nullable; import java.io.PrintStream; import java.io.PrintWriter; @@ -92,7 +93,7 @@ public ErrorValue(BString message, Object details) { message, null, details); } - public ErrorValue(Type type, BString message, BError cause, Object details) { + public ErrorValue(Type type, BString message, @Nullable BError cause, Object details) { super(message); this.type = type; this.message = message; @@ -100,7 +101,7 @@ public ErrorValue(Type type, BString message, BError cause, Object details) { this.details = details; } - public ErrorValue(Type type, BString message, BError cause, Object details, + public ErrorValue(Type type, BString message, @Nullable BError cause, Object details, String typeIdName, Module typeIdPkg) { super(message); this.type = type; @@ -113,7 +114,7 @@ public ErrorValue(Type type, BString message, BError cause, Object details, } @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { CycleUtils.Node linkParent = new CycleUtils.Node(this, parent); if (isEmptyDetail()) { return "error" + getModuleNameToString() + "(" + ((StringValue) message).informalStringValue(linkParent) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/FPValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/FPValue.java index beedcc984d45..49f3f798719c 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/FPValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/FPValue.java @@ -26,6 +26,7 @@ import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.runtime.internal.scheduling.AsyncUtils; import io.ballerina.runtime.internal.scheduling.Scheduler; +import org.jetbrains.annotations.Nullable; import java.util.Map; import java.util.function.Consumer; @@ -53,7 +54,7 @@ public class FPValue implements BFunctionPointer, RefValue { public String strandName; @Deprecated - public FPValue(Function function, Type type, String strandName, boolean isConcurrent) { + public FPValue(Function function, Type type, @Nullable String strandName, boolean isConcurrent) { this.function = function; this.type = type; this.strandName = strandName; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/FutureValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/FutureValue.java index 44a9c34da136..cb637e839677 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/FutureValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/FutureValue.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.internal.scheduling.Strand; import io.ballerina.runtime.internal.types.BFutureType; import io.ballerina.runtime.internal.util.StringUtils; +import org.jetbrains.annotations.Nullable; import java.util.Map; import java.util.StringJoiner; @@ -58,14 +59,14 @@ public class FutureValue implements BFuture, RefValue { Type type; @Deprecated - public FutureValue(Strand strand, Callback callback, Type constraint) { + public FutureValue(@Nullable Strand strand, @Nullable Callback callback, @Nullable Type constraint) { this.strand = strand; this.callback = callback; this.type = new BFutureType(constraint); } @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { StringJoiner sj = new StringJoiner(",", "{", "}"); sj.add("isDone:" + isDone); if (isDone) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/HandleValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/HandleValue.java index 42f5ce5c100f..5047da4ae354 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/HandleValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/HandleValue.java @@ -22,6 +22,7 @@ import io.ballerina.runtime.api.values.BHandle; import io.ballerina.runtime.api.values.BLink; import io.ballerina.runtime.api.values.BTypedesc; +import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -40,7 +41,7 @@ public class HandleValue implements BHandle, RefValue { private final Object value; private BTypedesc typedesc; - public HandleValue(Object value) { + public HandleValue(@Nullable Object value) { this.value = value; } @@ -63,6 +64,7 @@ public String expressionStringValue(BLink parent) { return stringValue(parent); } + @Nullable @Override public String toString() { return value != null ? value.toString() : null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ListInitialValueEntry.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ListInitialValueEntry.java index 68d4f6d0f2df..3655674ed1fc 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ListInitialValueEntry.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ListInitialValueEntry.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BListInitialValueEntry; +import org.jetbrains.annotations.Nullable; /** * Represents an initial value entry in a list constructor expression. @@ -37,7 +38,7 @@ public static class ExpressionEntry extends ListInitialValueEntry { public Object value; - public ExpressionEntry(Object value) { + public ExpressionEntry(@Nullable Object value) { this.value = value; } } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java index 53b0e46f92f2..16e3497b3ef1 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java @@ -48,6 +48,7 @@ import io.ballerina.runtime.internal.types.BRecordType; import io.ballerina.runtime.internal.types.BTupleType; import io.ballerina.runtime.internal.types.BUnionType; +import org.jetbrains.annotations.Nullable; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -95,6 +96,7 @@ public class MapValueImpl extends LinkedHashMap implements RefValue, CollectionValue, MapValue, BMap { + @Nullable private BTypedesc typedesc; private Type type; private Type referredType; @@ -288,7 +290,7 @@ public Object merge(BMap v2, boolean checkMergeability) { * previously associated {@code null} with {@code key}.) */ @Override - public V put(K key, V value) { + public V put(K key, @Nullable V value) { if (!type.isReadOnly()) { return putValue(key, value); } @@ -524,7 +526,7 @@ public Object frozenCopy(Map refs) { } @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { StringJoiner sj = new StringJoiner(","); for (Map.Entry kvEntry : this.entrySet()) { K key = kvEntry.getKey(); @@ -719,6 +721,7 @@ public Type getIteratorNextReturnType() { * This makes it easier to extend the operations without affecting the * common behaviors such as error handling. */ + @Nullable protected V putValue(K key, V value) { return super.put(key, value); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/NonBmpStringValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/NonBmpStringValue.java index 2210dfa05257..c337eab51ce7 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/NonBmpStringValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/NonBmpStringValue.java @@ -19,6 +19,7 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -79,6 +80,7 @@ public int[] getSurrogates() { return surrogates.clone(); } + @Nullable @Override public Long indexOf(BString str, int fromIndex) { int offset = getOffset(fromIndex); @@ -95,6 +97,7 @@ public Long indexOf(BString str, int fromIndex) { return index; } + @Nullable @Override public Long lastIndexOf(BString str, int fromIndex) { int offset = getOffset(fromIndex); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ReadOnlyUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ReadOnlyUtils.java index 9b46eba3d30c..089ac5a48d23 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ReadOnlyUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ReadOnlyUtils.java @@ -46,6 +46,7 @@ import io.ballerina.runtime.internal.types.BTypeReferenceType; import io.ballerina.runtime.internal.types.BUnionType; import io.ballerina.runtime.internal.types.BXmlType; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -118,6 +119,7 @@ public static Type setImmutableTypeAndGetEffectiveType(Type type, Set unre return setImmutableIntersectionType(type, unresolvedTypes).getEffectiveType(); } + @Nullable private static Type getAvailableImmutableType(Type type) { if (type.isReadOnly() || TypeChecker.isInherentlyImmutableType(type)) { return type; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpDisjunction.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpDisjunction.java index 54cde1be1df8..1a02ca263f43 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpDisjunction.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpDisjunction.java @@ -18,6 +18,7 @@ package io.ballerina.runtime.internal.values; import io.ballerina.runtime.api.values.BLink; +import org.jetbrains.annotations.Nullable; import java.util.StringJoiner; @@ -49,7 +50,7 @@ public Object[] getRegExpSeqList() { } @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { StringJoiner terms = new StringJoiner(""); for (Object t : this.seqList) { if (t == null) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpValue.java index da45d3856a1e..d646ba38ff5e 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpValue.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.values.BLink; import io.ballerina.runtime.api.values.BRegexpValue; import io.ballerina.runtime.api.values.BTypedesc; +import org.jetbrains.annotations.Nullable; import java.util.Map; import java.util.Objects; @@ -52,7 +53,7 @@ public RegExpDisjunction getRegExpDisjunction() { } @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { return this.regExpDisjunction.stringValue(parent); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StreamValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StreamValue.java index bf0eb2d4a2ca..6f26b714ac3d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StreamValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StreamValue.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.runtime.internal.IteratorUtils; import io.ballerina.runtime.internal.types.BStreamType; +import org.jetbrains.annotations.Nullable; import java.util.Map; import java.util.UUID; @@ -46,6 +47,7 @@ public class StreamValue implements RefValue, BStream { private final Type constraintType; private final Type completionType; private Type iteratorNextReturnType; + @Nullable private final BObject iteratorObj; @@ -93,7 +95,7 @@ public Type getIteratorNextReturnType() { * @param parent The link to the parent node */ @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { return getType().toString(); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TableValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TableValueImpl.java index 305586506362..05dcdaf1b972 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TableValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TableValueImpl.java @@ -46,6 +46,7 @@ import io.ballerina.runtime.internal.types.BTupleType; import io.ballerina.runtime.internal.types.BTypeReferenceType; import io.ballerina.runtime.internal.types.BUnionType; +import org.jetbrains.annotations.Nullable; import java.util.AbstractMap; import java.util.ArrayList; @@ -104,6 +105,7 @@ public class TableValueImpl implements TableValue { private boolean nextKeySupported; private final Map nativeData = new HashMap<>(); + @Nullable private BTypedesc typedesc; public TableValueImpl(TableType tableType) { @@ -127,7 +129,7 @@ public TableValueImpl(Type type, ArrayValue data, ArrayValue fieldNames) { this.type = type; } - public TableValueImpl(TableType tableType, ArrayValue data, ArrayValue fieldNames) { + public TableValueImpl(TableType tableType, @Nullable ArrayValue data, ArrayValue fieldNames) { this(tableType); if (this.fieldNames == null) { this.fieldNames = fieldNames.getStringArray(); @@ -373,7 +375,7 @@ public void freezeDirect() { } @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { Iterator>> itr = values.entrySet().iterator(); return createStringValueDataEntry(itr, parent); } @@ -426,6 +428,7 @@ private String createExpressionStringValueDataEntry(Iterator> entryList = entries.get(TableUtils.hash(key, null)); @@ -710,6 +715,7 @@ private V updateExistingEntry(K key, V data, Map.Entry entry, Long hash) { return data; } + @Nullable @Override public V remove(K key) { keyValues.remove(key); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java index 922b1ce59a21..f50ae6bf3d54 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java @@ -37,6 +37,7 @@ import io.ballerina.runtime.internal.errors.ErrorCodes; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.errors.ErrorReasons; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.OutputStream; @@ -73,6 +74,7 @@ public class TupleValueImpl extends AbstractArrayValue { Object[] refValues; private final int minSize; private final boolean hasRestElement; // cached value for ease of access + @Nullable private BTypedesc typedesc; private TypedescValueImpl inherentType; // ------------------------ Constructors ------------------------------------------------------------------- @@ -512,6 +514,7 @@ public boolean isEmpty() { return this.size == 0; } + @Nullable @Override public BArray slice(long startIndex, long endIndex) { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java index 39dc6347600a..0f2bd46e46e5 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java @@ -30,6 +30,7 @@ import io.ballerina.runtime.internal.scheduling.Strand; import io.ballerina.runtime.internal.types.BAnnotatableType; import io.ballerina.runtime.internal.types.BTypedescType; +import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -108,7 +109,7 @@ public Object instantiate(Strand s, BInitialValueEntry[] initialValues) { } @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { return "typedesc " + describingType.toString(); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java index b61540d7beaa..8cb2f702ddbb 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java @@ -26,6 +26,7 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.internal.scheduling.Scheduler; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -102,8 +103,9 @@ public static boolean containsValueCreator(String key) { public abstract MapValue createRecordValue(String recordTypeName) throws BError; - public abstract BObject createObjectValue(String objectTypeName, Scheduler scheduler, Strand parent, - Map properties, Object[] args) throws BError; + public abstract BObject createObjectValue( + String objectTypeName, @Nullable Scheduler scheduler, @Nullable Strand parent, + @Nullable Map properties, Object[] args) throws BError; public abstract BError createErrorValue(String errorTypeName, BString message, BError cause, Object details) throws BError; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java index 10d35118e3a2..6e2c6ef147fd 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java @@ -36,6 +36,7 @@ import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMException; import org.apache.axiom.om.OMNode; +import org.jetbrains.annotations.Nullable; import java.io.ByteArrayOutputStream; import java.lang.ref.WeakReference; @@ -466,9 +467,10 @@ public String toString() { * {@inheritDoc} * @param parent The link to the parent node */ + @Nullable @Override @Deprecated - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BallerinaXmlSerializer ballerinaXMLSerializer = new BallerinaXmlSerializer(outputStream); @@ -559,7 +561,8 @@ protected void setAttributesOnInitialization(BMap attributes) } @Override - protected void setAttributeOnInitialization(String localName, String namespace, String prefix, String value) { + protected void setAttributeOnInitialization( + String localName, @Nullable String namespace, @Nullable String prefix, String value) { attributes.setAttribute(localName, namespace, prefix, value, true); } @@ -713,7 +716,7 @@ public boolean equals(Object o, Set visitedValues) { } private interface SetAttributeFunction { - void set(String localName, String namespace, String prefix, String value); + void set(String localName, @Nullable String namespace, @Nullable String prefix, String value); } public static XmlItem createXMLItemWithDefaultNSAttribute(QName name, boolean readonly, String defaultNsUri) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlNonElementItem.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlNonElementItem.java index 8a404e5b755e..493cdb53d4d4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlNonElementItem.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlNonElementItem.java @@ -30,6 +30,7 @@ import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNode; +import org.jetbrains.annotations.Nullable; import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; @@ -57,16 +58,19 @@ public String getItemType() { return getNodeType().value(); } + @Nullable @Override public String getElementName() { return null; } + @Nullable @Override public BString getAttribute(String localName, String namespace) { return null; } + @Nullable @Override public BString getAttribute(String localName, String namespace, String prefix) { return null; @@ -77,6 +81,7 @@ public void setAttribute(String localName, String namespace, String prefix, Stri } + @Nullable @Override public MapValue getAttributesMap() { return null; @@ -92,6 +97,7 @@ public BXml elements() { return new XmlSequence(); } + @Nullable @Override public BXml elements(String qname) { return null; @@ -124,6 +130,7 @@ public BXml strip() { @Override public abstract XmlNodeType getNodeType(); + @Nullable @Override public BXml slice(long startIndex, long endIndex) { return null; @@ -190,8 +197,9 @@ public Void next() { }; } + @Nullable @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BallerinaXmlSerializer ballerinaXMLSerializer = new BallerinaXmlSerializer(outputStream); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlQName.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlQName.java index d4cc801acc11..15f323706408 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlQName.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlQName.java @@ -23,6 +23,7 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.runtime.api.values.BXmlQName; +import org.jetbrains.annotations.Nullable; import java.util.Map; import java.util.Objects; @@ -42,6 +43,7 @@ public final class XmlQName implements RefValue, BXmlQName { private String localName; + @Nullable private String uri; private String prefix; private BTypedesc typedesc = null; @@ -100,7 +102,7 @@ public String toString() { } @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { return (uri == null || uri.isEmpty()) ? localName : '{' + uri + '}' + localName; } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java index f024b023c122..ce6550ca6633 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java @@ -36,6 +36,7 @@ import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.types.BArrayType; import io.ballerina.runtime.internal.types.BUnionType; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashSet; @@ -155,6 +156,7 @@ public String getTextValue() { /** * {@inheritDoc} */ + @Nullable @Override public BString getAttribute(String localName, String namespace) { if (isSingleton()) { @@ -167,6 +169,7 @@ public BString getAttribute(String localName, String namespace) { /** * {@inheritDoc} */ + @Nullable @Override public BString getAttribute(String localName, String namespace, String prefix) { if (isSingleton()) { @@ -193,6 +196,7 @@ public void setAttribute(String localName, String namespace, String prefix, Stri /** * {@inheritDoc} */ + @Nullable @Override public MapValue getAttributesMap() { if (isSingleton()) { @@ -443,6 +447,7 @@ public Object value() { /** * {@inheritDoc} */ + @Nullable @Override public String toString() { try { @@ -457,8 +462,9 @@ public String toString() { * {@inheritDoc} * @param parent The link to the parent node */ + @Nullable @Override - public String stringValue(BLink parent) { + public String stringValue(@Nullable BLink parent) { try { StringBuilder sb = new StringBuilder(); for (BXml child : children) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlValue.java index 23443629ca47..f5e6144f7a7f 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlValue.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlValue.java @@ -29,6 +29,7 @@ import io.ballerina.runtime.api.values.BXmlQName; import io.ballerina.runtime.internal.BallerinaXmlSerializer; import io.ballerina.runtime.internal.IteratorUtils; +import org.jetbrains.annotations.Nullable; import java.io.OutputStream; import java.util.List; @@ -56,6 +57,7 @@ public abstract class XmlValue implements RefValue, BXml, CollectionValue { Type type = PredefinedTypes.TYPE_XML; + @Nullable protected BTypedesc typedesc; protected Type iteratorNextReturnType; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObserveUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObserveUtils.java index 759bf3f0210b..905723c89f9e 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObserveUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObserveUtils.java @@ -30,6 +30,7 @@ import io.ballerina.runtime.internal.values.ErrorValue; import io.ballerina.runtime.observability.tracer.BSpan; import io.opentelemetry.api.common.Attributes; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -100,7 +101,7 @@ public final class ObserveUtils { private ObserveUtils() { } - private static T readConfig(VariableKey specificKey, VariableKey inheritedKey, T defaultValue) { + private static T readConfig(VariableKey specificKey, @Nullable VariableKey inheritedKey, T defaultValue) { T value; if (ConfigMap.containsKey(specificKey)) { value = (T) ConfigMap.get(specificKey); @@ -449,6 +450,7 @@ public static void logMessageToActiveSpan(String logLevel, Supplier logM * @param env current env * @return observer context of the current frame */ + @Nullable public static ObserverContext getObserverContextOfCurrentFrame(Environment env) { if (!enabled) { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricId.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricId.java index 822170a1a97e..351d61e75d2b 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricId.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricId.java @@ -17,6 +17,8 @@ */ package io.ballerina.runtime.observability.metrics; +import org.jetbrains.annotations.Nullable; + import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -37,7 +39,7 @@ public MetricId(String name, String description, List tags) { this(name, description, tags != null ? new HashSet<>(tags) : null); } - public MetricId(String name, String description, Set tags) { + public MetricId(String name, String description, @Nullable Set tags) { if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Name is required."); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricRegistry.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricRegistry.java index 04a5ef722aab..dcaac9e0808c 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricRegistry.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricRegistry.java @@ -18,6 +18,7 @@ package io.ballerina.runtime.observability.metrics; import io.ballerina.runtime.observability.metrics.spi.MetricProvider; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -141,6 +142,7 @@ private M getOrCreate(MetricId id, Class metricClass, Supp } } + @Nullable private M readMetric(MetricId metricId, Class metricClass) { Metric existingMetrics = lookup(metricId); if (existingMetrics != null) { diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/Snapshot.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/Snapshot.java index 828034a42bf8..f081bcbaf0e4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/Snapshot.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/Snapshot.java @@ -17,6 +17,8 @@ */ package io.ballerina.runtime.observability.metrics; +import org.jetbrains.annotations.Nullable; + import java.time.Duration; import java.util.Arrays; @@ -36,7 +38,7 @@ public class Snapshot { private final PercentileValue[] percentileValues; public Snapshot(Duration timeWindow, double min, double mean, double stdDev, double max, - PercentileValue[] percentileValues) { + @Nullable PercentileValue[] percentileValues) { this.timeWindow = timeWindow; this.min = min; this.mean = mean; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/StatisticConfig.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/StatisticConfig.java index 7242e0fe2a2e..47a325f24603 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/StatisticConfig.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/StatisticConfig.java @@ -17,6 +17,8 @@ */ package io.ballerina.runtime.observability.metrics; +import org.jetbrains.annotations.Nullable; + import java.time.Duration; import java.util.Arrays; import java.util.Objects; @@ -61,6 +63,7 @@ private StatisticConfig() { * @return Percentiles to compute and publish. * @see Builder#percentiles(double...) */ + @Nullable public double[] getPercentiles() { return percentiles != null ? Arrays.copyOf(percentiles, percentiles.length) : null; } @@ -114,7 +117,7 @@ public static class Builder { * @param percentiles Percentiles to compute and publish. * @return This builder. */ - public Builder percentiles(double... percentiles) { + public Builder percentiles(@Nullable double... percentiles) { percentiles = Objects.requireNonNull(percentiles, "percentiles array should not be null."); if (percentiles.length == 0) { throw new IllegalArgumentException("percentiles array should not be empty."); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java index 8350ce227bb4..825cbe9ccbd0 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java @@ -36,6 +36,7 @@ import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.context.propagation.TextMapSetter; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.HashMap; @@ -80,7 +81,7 @@ private BSpan(Tracer tracer, Span span) { this.span = span; } - private static BSpan start(Tracer tracer, Context parentContext, String operationName, boolean isClient) { + private static BSpan start(Tracer tracer, @Nullable Context parentContext, String operationName, boolean isClient) { SpanBuilder builder = tracer.spanBuilder(operationName); if (parentContext != null) { builder.setParent(parentContext); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java index bcebf965ab05..21760d1a4db4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; import java.nio.ByteBuffer; import java.util.ArrayDeque; @@ -47,12 +48,14 @@ public class TransactionLocalContext { private static final TransactionResourceManager TRANSACTION_RESOURCE_MANAGER = TransactionResourceManager.getInstance(); private boolean isResourceParticipant; + @Nullable private Object rollbackOnlyError; private Object transactionData; private final BArray transactionId; private boolean isTransactional; - private TransactionLocalContext(String globalTransactionId, String url, String protocol, Object infoRecord) { + private TransactionLocalContext(String globalTransactionId, String url, String protocol, + @Nullable Object infoRecord) { this.globalTransactionId = globalTransactionId; this.url = url; this.protocol = protocol; @@ -211,6 +214,7 @@ public void markFailure() { transactionFailure.push(TransactionFailure.at(-1)); } + @Nullable public TransactionFailure getAndClearFailure() { if (transactionFailure.isEmpty()) { return null; @@ -220,6 +224,7 @@ public TransactionFailure getAndClearFailure() { return failure; } + @Nullable public TransactionFailure getFailure() { if (transactionFailure.isEmpty()) { return null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java index aaa870d8298e..4de77b94faec 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java @@ -30,6 +30,7 @@ import io.ballerina.runtime.internal.scheduling.Scheduler; import io.ballerina.runtime.internal.scheduling.Strand; import io.ballerina.runtime.internal.util.RuntimeUtils; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -659,6 +660,7 @@ public void notifyLocalParticipantFailure(String gTransactionId, String blockId) } } + @Nullable public Object getTransactionRecord(BArray xid) { synchronized (transactionInfoMap) { if (transactionInfoMap.containsKey(ByteBuffer.wrap(xid.getBytes()))) { diff --git a/bvm/ballerina-runtime/src/main/java/module-info.java b/bvm/ballerina-runtime/src/main/java/module-info.java index 32a43bd94043..3dabcbb0bddf 100644 --- a/bvm/ballerina-runtime/src/main/java/module-info.java +++ b/bvm/ballerina-runtime/src/main/java/module-info.java @@ -18,6 +18,7 @@ requires java.naming; requires io.ballerina.identifier; requires jdk.unsupported; + requires static org.jetbrains.annotations; // API exports exports io.ballerina.runtime.api; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java index 7e2025aa2346..0c8ab7c73fe7 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java @@ -49,6 +49,7 @@ import org.ballerinalang.central.client.CentralClientConstants; import org.ballerinalang.central.client.exceptions.CentralClientException; import org.ballerinalang.central.client.exceptions.PackageAlreadyExistsException; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.util.RepoUtils; import java.io.FileInputStream; @@ -156,7 +157,7 @@ public static void initJarFs() { * @param usage usage if any * @param help if the help message should be printed */ - public static void printError(PrintStream stream, String error, String usage, boolean help) { + public static void printError(PrintStream stream, String error, @Nullable String usage, boolean help) { stream.println("ballerina: " + error); if (null != usage) { @@ -393,6 +394,7 @@ private static Path updateModuleDirectoryNaming(Path includePath, Path balaPath, * * @param template template name */ + @Nullable static Path findBalaTemplate(String template, Path balaCache) { String packageName = findPkgName(template); String orgName = findOrg(template); @@ -422,35 +424,31 @@ public static void initPackageFromCentral(Path balaCache, Path projectPath, Stri } catch (PackageAlreadyExistsException e) { if (version == null) { List packageVersions = getPackageVersions(pkgCacheParent); - PackageVersion latest = findLatest(packageVersions); - if (latest == null) { - // This is not supposed to execute - throw createLauncherException("unable to find package in the filesystem cache." + - " This is an unexpected error : " + e.getMessage()); - } + PackageVersion latest = findLatest(packageVersions).orElseThrow( + // This is not supposed to execute + () -> createLauncherException("unable to find package in the filesystem cache." + + " This is an unexpected error : " + e.getMessage())); version = latest.toString(); } } catch (CentralClientException e) { errStream.println("Warning: Unable to pull the package from Ballerina Central: " + e.getMessage()); if (findBalaTemplate(template, balaCache) == null) { List packageVersions = getPackageVersions(pkgCacheParent); - PackageVersion latest = findLatest(packageVersions); - if (latest == null) { - throw createLauncherException("template not found in filesystem cache."); - } + PackageVersion latest = findLatest(packageVersions).orElseThrow( + () -> createLauncherException("template not found in filesystem cache.")); version = latest.toString(); } } if (version == null) { List packageVersions = getPackageVersions(pkgCacheParent); - PackageVersion latest = findLatest(packageVersions); - version = Objects.requireNonNull(latest).toString(); + PackageVersion latest = findLatest(packageVersions).orElseThrow(); + version = latest.toString(); } applyTemplate(orgName, templatePackageName, version, packageName, projectPath, balaCache, filesInDir); } - private static void pullPackageFromRemote(String orgName, String packageName, String version, Path destination) - throws CentralClientException { + private static void pullPackageFromRemote(String orgName, String packageName, @Nullable String version, + Path destination) throws CentralClientException { String supportedPlatform = Arrays.stream(JvmTarget.values()) .map(JvmTarget::code) .collect(Collectors.joining(",")); @@ -794,6 +792,7 @@ public static String findOrg(String template) { * @param template template name * @return version - version of the module */ + @Nullable public static String findPkgVersion(String template) { String[] orgSplit = template.split("/"); String packagePart = (orgSplit.length > 1) ? orgSplit[1] : ""; @@ -999,15 +998,16 @@ private static void initToolPackage(Path path, String packageName) throws IOExce Files.writeString(balToolToml, balToolManifest); } - private static PackageVersion findLatest(List packageVersions) { + @Nullable + private static Optional findLatest(List packageVersions) { if (packageVersions.isEmpty()) { - return null; + return Optional.empty(); } PackageVersion latestVersion = packageVersions.get(0); for (PackageVersion pkgVersion : packageVersions) { latestVersion = getLatest(latestVersion, pkgVersion); } - return latestVersion; + return Optional.of(latestVersion); } private static PackageVersion getLatest(PackageVersion v1, PackageVersion v2) { diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/DocCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/DocCommand.java index 6ae7ef87396b..5ed2435f9bc5 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/DocCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/DocCommand.java @@ -33,6 +33,7 @@ import io.ballerina.projects.repos.TempDirCompilationCache; import io.ballerina.projects.util.ProjectConstants; import org.ballerinalang.docgen.docs.BallerinaDocGenerator; +import org.jetbrains.annotations.Nullable; import picocli.CommandLine; import java.io.IOException; @@ -53,6 +54,7 @@ public class DocCommand implements BLauncherCmd { private final PrintStream outStream; private final PrintStream errStream; private Path projectPath; + @Nullable private Path outputPath; private final boolean exitWhenFinish; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java index bcf270755634..20f31c22a666 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ProfileCommand.java @@ -35,6 +35,7 @@ import io.ballerina.projects.directory.BuildProject; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.util.ProjectConstants; +import org.jetbrains.annotations.Nullable; import picocli.CommandLine; import java.io.PrintStream; @@ -166,6 +167,7 @@ private String[] getArgumentsFromArgList() { return args; } + @Nullable private Project loadProject(BuildOptions buildOptions) { if (FileUtils.hasExtension(this.projectPath)) { return loadSingleFileProject(buildOptions); @@ -174,6 +176,7 @@ private Project loadProject(BuildOptions buildOptions) { } } + @Nullable private Project loadSingleFileProject(BuildOptions buildOptions) { try { return SingleFileProject.load(this.projectPath, buildOptions); @@ -183,6 +186,7 @@ private Project loadSingleFileProject(BuildOptions buildOptions) { } } + @Nullable private Project loadBuildProject(BuildOptions buildOptions) { try { return BuildProject.load(this.projectPath, buildOptions); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PullCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PullCommand.java index 07be37fcec5f..737ea48cf3c2 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PullCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PullCommand.java @@ -37,6 +37,7 @@ import org.ballerinalang.central.client.exceptions.PackageAlreadyExistsException; import org.ballerinalang.maven.bala.client.MavenResolverClient; import org.ballerinalang.maven.bala.client.MavenResolverClientException; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; @@ -49,6 +50,7 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import static io.ballerina.cli.cmd.Constants.PULL_COMMAND; @@ -87,6 +89,7 @@ public class PullCommand implements BLauncherCmd { @CommandLine.Option(names = "--debug", hidden = true) private String debugPort; + @Nullable @CommandLine.Option(names = "--repository") private String repositoryName; @@ -262,7 +265,7 @@ private String pullFromCentral(Settings settings, String orgName, String package private void pullFromMavenRepo(Settings settings, String orgName, String packageName, String version) { Repository targetRepository = null; for (Repository repository : settings.getRepositories()) { - if (repositoryName.equals(repository.id())) { + if (Objects.equals(repositoryName, repository.id())) { targetRepository = repository; break; } diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java index e1c14d6cf94c..ca05e39a83d6 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java @@ -42,6 +42,7 @@ import org.ballerinalang.central.client.exceptions.NoPackageException; import org.ballerinalang.maven.bala.client.MavenResolverClient; import org.ballerinalang.maven.bala.client.MavenResolverClientException; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; @@ -117,7 +118,7 @@ public PushCommand(Path userDir, PrintStream outStream, PrintStream errStream, b this.exitWhenFinish = exitWhenFinish; } - public PushCommand(Path userDir, PrintStream outStream, PrintStream errStream, boolean exitWhenFinish, + public PushCommand(@Nullable Path userDir, PrintStream outStream, PrintStream errStream, boolean exitWhenFinish, Path balaPath) { this.userDir = userDir; this.outStream = outStream; @@ -564,6 +565,7 @@ private static boolean isPackageAvailableInRemote(DependencyManifest.Package pkg * @param balaOutputDir bala output directory * @return matching bala file path */ + @Nullable private static Path findBalaFile(PackageName pkgName, PackageOrg orgName, Path balaOutputDir) { Path balaFilePath = null; File[] balaFiles = new File(balaOutputDir.toString()).listFiles(); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java index 8240f19b876b..1bead39e1058 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/TestCommand.java @@ -37,6 +37,7 @@ import io.ballerina.projects.directory.BuildProject; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.util.ProjectConstants; +import org.jetbrains.annotations.Nullable; import picocli.CommandLine; import java.io.PrintStream; @@ -97,7 +98,7 @@ public TestCommand() { } TestCommand(Path projectPath, PrintStream outStream, PrintStream errStream, boolean exitWhenFinish, - Boolean testReport, Boolean coverage, String coverageFormat, + Boolean testReport, Boolean coverage, @Nullable String coverageFormat, Boolean optimizeDependencyCompilation) { this.projectPath = projectPath; this.outStream = outStream; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java index 55085f587b37..9f82e85b571e 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java @@ -18,6 +18,8 @@ package io.ballerina.cli.launcher; +import org.jetbrains.annotations.Nullable; + import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; @@ -41,6 +43,7 @@ public CustomToolClassLoader(URL[] urls, ClassLoader parent) { system = getSystemClassLoader(); } + @Nullable @Override protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { Class loadedClass = findLoadedClass(name); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java index 5514f45bc55a..ed4cf89852b7 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java @@ -23,6 +23,7 @@ import io.ballerina.projects.BalToolsToml; import io.ballerina.projects.internal.BalToolsManifestBuilder; import io.ballerina.runtime.api.values.BError; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; @@ -108,6 +109,7 @@ public static void printLauncherException(BLauncherException e, PrintStream outS errorMessages.forEach(outStream::println); } + @Nullable static String makeFirstLetterLowerCase(String s) { if (s == null) { return null; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java index e803670114a9..973e483d007f 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java @@ -30,6 +30,7 @@ import io.ballerina.projects.ProjectException; import io.ballerina.projects.ProjectKind; import io.ballerina.projects.internal.model.Target; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -54,7 +55,8 @@ public class CreateExecutableTask implements Task { private Target target; private final boolean isHideTaskOutput; - public CreateExecutableTask(PrintStream out, String output, Target target, boolean isHideTaskOutput) { + public CreateExecutableTask(PrintStream out, @Nullable String output, @Nullable Target target, + boolean isHideTaskOutput) { this.out = out; this.target = target; this.isHideTaskOutput = isHideTaskOutput; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateTestExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateTestExecutableTask.java index 64ab0d001343..226e01242abf 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateTestExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateTestExecutableTask.java @@ -170,6 +170,9 @@ private void standaloneFatJarGeneration(Project project, JBallerinaBackend jBall for (ModuleDescriptor moduleDescriptor : project.currentPackage().moduleDependencyGraph().toTopologicallySortedList()) { Module module = project.currentPackage().module(moduleDescriptor.name()); + if (module == null) { + throw createLauncherException("module not found: " + moduleDescriptor.name()); + } testExecDependencies.addAll(jBallerinaBackend.jarResolver() .getJarFilePathsRequiredForTestExecution(module.moduleName()) ); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/FileUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/FileUtils.java index 552a6d71566e..652416be0586 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/FileUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/FileUtils.java @@ -21,6 +21,7 @@ import io.ballerina.toml.api.Toml; import io.ballerina.toml.validator.TomlValidator; import io.ballerina.toml.validator.schema.Schema; +import org.jetbrains.annotations.Nullable; import java.io.BufferedReader; import java.io.FileNotFoundException; @@ -47,6 +48,7 @@ private FileUtils() { * @param filePath Path of the file. * @return File name without extension. */ + @Nullable public static String getFileNameWithoutExtension(Path filePath) { Path fileName = filePath.getFileName(); if (null != fileName) { diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java index 83ac291c8730..f1162595088b 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java @@ -23,6 +23,7 @@ import io.ballerina.projects.PackageManifest; import io.ballerina.projects.ResolvedPackageDependency; import io.ballerina.projects.util.ProjectUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -61,12 +62,14 @@ private static String otherPlatformGraalvmCompatibleVerified(String target, return ""; } + @Nullable private static Boolean isAllPlatformDepsGraalvmCompatible(Map platforms) { Boolean isAllDepsGraalvmCompatible = true; for (PackageManifest.Platform platform: platforms.values()) { - if (platform.isPlatfromDepsGraalvmCompatible() == null) { + Boolean graalvmCompatible = platform.graalvmCompatible(); + if (graalvmCompatible == null) { isAllDepsGraalvmCompatible = null; - } else if (!platform.isPlatfromDepsGraalvmCompatible()) { + } else if (!graalvmCompatible) { return false; } } @@ -80,6 +83,7 @@ private static Boolean isAllPlatformDepsGraalvmCompatible(Map getMethodSet(Class qualifiedTestClass) { return methodSet; } + @Nullable private static Class validateClassExistance(TestSuite testSuite, String qualifiedTestClassName) { List testExecutionDependencies = testSuite.getTestExecutionDependencies(); ClassLoader classLoader = AccessController.doPrivileged( diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java index 08a85132a2ed..b43f3a83cf8d 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java @@ -47,6 +47,7 @@ import org.jacoco.core.analysis.ISourceFileCoverage; import org.jacoco.core.data.ExecutionData; import org.jacoco.core.data.SessionInfo; +import org.jetbrains.annotations.Nullable; import java.io.BufferedReader; import java.io.File; @@ -242,6 +243,7 @@ public static Path getReportToolsPath() { * @return ModuleStatus object * @throws IOException if file does not exist */ + @Nullable public static ModuleStatus loadModuleStatusFromFile(Path statusJsonPath) throws IOException { File statusJsonFile = new File(statusJsonPath.toUri()); if (!statusJsonFile.isFile()) { @@ -300,6 +302,9 @@ public static boolean createTestSuitesForProject(Project project, Target target, for (ModuleDescriptor moduleDescriptor : project.currentPackage().moduleDependencyGraph().toTopologicallySortedList()) { Module module = project.currentPackage().module(moduleDescriptor.name()); + if (module == null) { + throw new IllegalStateException("Module is not found in the package: " + moduleDescriptor.name()); + } ModuleName moduleName = module.moduleName(); TestSuite suite = testProcessor.testSuite(module).orElse(null); @@ -378,7 +383,7 @@ public static String getJacocoAgentJarPath() { * @param userDir User directory for the out of memory heap dump * @return List of command arguments to be used */ - public static List getInitialCmdArgs(String javaCommand, String userDir) { + public static List getInitialCmdArgs(@Nullable String javaCommand, @Nullable String userDir) { List cmdArgs = new ArrayList<>(); if (javaCommand == null) { diff --git a/cli/ballerina-cli/src/main/java/module-info.java b/cli/ballerina-cli/src/main/java/module-info.java index a39930fa7717..ddc1862d4291 100644 --- a/cli/ballerina-cli/src/main/java/module-info.java +++ b/cli/ballerina-cli/src/main/java/module-info.java @@ -27,4 +27,5 @@ requires org.objectweb.asm; requires org.apache.commons.io; requires maven.resolver; + requires static org.jetbrains.annotations; } diff --git a/cli/central-client/src/main/java/module-info.java b/cli/central-client/src/main/java/module-info.java index 0bdea9c4c93d..3dd63d465818 100644 --- a/cli/central-client/src/main/java/module-info.java +++ b/cli/central-client/src/main/java/module-info.java @@ -12,4 +12,5 @@ requires org.apache.commons.io; requires okhttp3; requires okio; + requires static org.jetbrains.annotations; } diff --git a/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java b/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java index 0e4b688ec97c..36e7aa483224 100644 --- a/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java +++ b/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java @@ -50,6 +50,7 @@ import org.ballerinalang.central.client.model.ToolResolutionCentralRequest; import org.ballerinalang.central.client.model.ToolResolutionCentralResponse; import org.ballerinalang.central.client.model.ToolSearchResult; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.PrintStream; @@ -177,8 +178,8 @@ public CentralAPIClient(String baseUrl, Proxy proxy, String accessToken) { this.maxRetries = MAX_RETRY; } - public CentralAPIClient(String baseUrl, Proxy proxy, String accessToken, boolean verboseEnabled, int maxRetries, - PrintStream outStream) { + public CentralAPIClient(String baseUrl, @Nullable Proxy proxy, String accessToken, boolean verboseEnabled, + int maxRetries, PrintStream outStream) { this.outStream = outStream; this.baseUrl = baseUrl; this.proxy = proxy; @@ -507,7 +508,7 @@ public void pushPackage(Path balaPath, String org, String name, String version, * @param isBuild If build option is enabled or not. * @throws CentralClientException Central Client exception. */ - public void pullPackage(String org, String name, String version, Path packagePathInBalaCache, + public void pullPackage(String org, String name, @Nullable String version, Path packagePathInBalaCache, String supportedPlatform, String ballerinaVersion, boolean isBuild) throws CentralClientException { int retryCount = 0; @@ -1531,6 +1532,7 @@ public JsonObject getConnector(String id, String supportedPlatform, String balle * @return Connector. * @throws CentralClientException Central Client exception. */ + @Nullable public JsonObject getConnector(ConnectorInfo connector, String supportedPlatform, String ballerinaVersion) throws CentralClientException { Optional body = Optional.empty(); @@ -1819,7 +1821,7 @@ public JsonObject getTrigger(String id, String supportedPlatform, String balleri * @param responseBody error message * @throws CentralClientException with unauthorized error message */ - private void handleUnauthorizedResponse(String org, Optional body, String responseBody) + private void handleUnauthorizedResponse(String org, Optional body, @Nullable String responseBody) throws CentralClientException { if (body.isPresent()) { Optional contentType = Optional.ofNullable(body.get().contentType()); @@ -1841,7 +1843,7 @@ private void handleUnauthorizedResponse(String org, Optional body, * @param responseBody error message * @throws CentralClientException with unauthorized error message */ - private void handleUnauthorizedResponse(Optional body, String responseBody) + private void handleUnauthorizedResponse(Optional body, @Nullable String responseBody) throws CentralClientException { if (body.isPresent()) { Optional contentType = Optional.ofNullable(body.get().contentType()); @@ -1863,7 +1865,7 @@ private void handleUnauthorizedResponse(Optional body, String resp * @param responseBody response body * @throws CentralClientException with unauthorized error message */ - private void handleUnauthorizedResponse(MediaType mediaType, String responseBody) + private void handleUnauthorizedResponse(@Nullable MediaType mediaType, String responseBody) throws CentralClientException { Optional contentType = Optional.ofNullable(mediaType); StringBuilder message = new StringBuilder("unauthorized access token. " + @@ -1875,7 +1877,7 @@ private void handleUnauthorizedResponse(MediaType mediaType, String responseBody throw new CentralClientException(message.toString()); } - private void logResponseVerbose(Response response, String bodyContent) { + private void logResponseVerbose(Response response, @Nullable String bodyContent) { if (this.verboseEnabled) { Optional body = Optional.ofNullable(response.body()); this.outStream.println("< HTTP " + response.code() + " " + response.message()); @@ -1922,6 +1924,7 @@ class CustomRetryInterceptor implements Interceptor { this.maxRetries = maxRetry; } + @Nullable @Override public Response intercept(Chain chain) throws IOException { int retryCount = 0; @@ -1944,7 +1947,8 @@ public Response intercept(Chain chain) throws IOException { return response; } - private void logRetryVerbose(Response response, String bodyContent, Request request, int retryCount) { + private void logRetryVerbose(Response response, @Nullable String bodyContent, Request request, + int retryCount) { if (verboseEnabled) { Optional body = Optional.ofNullable(response.body()); outStream.println("< HTTP " + response.code() + " " + response.message()); diff --git a/cli/central-client/src/main/java/org/ballerinalang/central/client/Utils.java b/cli/central-client/src/main/java/org/ballerinalang/central/client/Utils.java index 59a6fe0c5b90..e1dc0eeecccc 100644 --- a/cli/central-client/src/main/java/org/ballerinalang/central/client/Utils.java +++ b/cli/central-client/src/main/java/org/ballerinalang/central/client/Utils.java @@ -37,6 +37,7 @@ import org.apache.commons.io.FileUtils; import org.ballerinalang.central.client.exceptions.CentralClientException; import org.ballerinalang.central.client.exceptions.PackageAlreadyExistsException; +import org.jetbrains.annotations.Nullable; import java.io.BufferedWriter; import java.io.File; @@ -114,9 +115,9 @@ public enum RequestMethod { * @param logFormatter log formatter */ public static void createBalaInHomeRepo(Response balaDownloadResponse, Path pkgPathInBalaCache, String pkgOrg, - String pkgName, boolean isNightlyBuild, String deprecationMsg, - String newUrl, String contentDisposition, PrintStream outStream, - LogFormatter logFormatter, String trueDigest) + String pkgName, boolean isNightlyBuild, @Nullable String deprecationMsg, + String newUrl, String contentDisposition, @Nullable PrintStream outStream, + LogFormatter logFormatter, String trueDigest) throws CentralClientException { long responseContentLength = 0; @@ -443,7 +444,7 @@ private static String getPlatformFromBala(String balaName, String packageName, S } private static void extractBala(Path balaFilePath, Path balaFileDestPath, String trueDigest, String packageName, - PrintStream outStream) + @Nullable PrintStream outStream) throws IOException, CentralClientException { Files.createDirectories(balaFileDestPath); URI zipURI = URI.create("jar:" + balaFilePath.toUri().toString()); diff --git a/cli/central-client/src/main/java/org/ballerinalang/central/client/model/PackageNameResolutionRequest.java b/cli/central-client/src/main/java/org/ballerinalang/central/client/model/PackageNameResolutionRequest.java index 3b4ab165a5fd..a0b593a3c7e2 100644 --- a/cli/central-client/src/main/java/org/ballerinalang/central/client/model/PackageNameResolutionRequest.java +++ b/cli/central-client/src/main/java/org/ballerinalang/central/client/model/PackageNameResolutionRequest.java @@ -18,6 +18,8 @@ package org.ballerinalang.central.client.model; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.List; @@ -67,8 +69,8 @@ public String version() { List possiblePackages; PackageResolutionRequest.Mode mode; - Module(String organization, String moduleName, List possiblePackages, - PackageResolutionRequest.Mode mode) { + Module(String organization, String moduleName, @Nullable List possiblePackages, + @Nullable PackageResolutionRequest.Mode mode) { this.organization = organization; this.moduleName = moduleName; this.possiblePackages = possiblePackages; diff --git a/cli/central-client/src/main/java/org/ballerinalang/central/client/model/PackageNameResolutionResponse.java b/cli/central-client/src/main/java/org/ballerinalang/central/client/model/PackageNameResolutionResponse.java index 67c29a9d1116..7794c47e1574 100644 --- a/cli/central-client/src/main/java/org/ballerinalang/central/client/model/PackageNameResolutionResponse.java +++ b/cli/central-client/src/main/java/org/ballerinalang/central/client/model/PackageNameResolutionResponse.java @@ -17,6 +17,8 @@ */ package org.ballerinalang.central.client.model; +import org.jetbrains.annotations.Nullable; + import java.util.List; /** @@ -86,7 +88,8 @@ public void setReason(String reason) { this.reason = reason; } - public Module(String organization, String moduleName, String version, String packageName, String reason) { + public Module(String organization, String moduleName, String version, @Nullable String packageName, + @Nullable String reason) { this.organization = organization; this.moduleName = moduleName; this.version = version; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/BallerinaSemanticModel.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/BallerinaSemanticModel.java index 73bf9e881f9b..accd587b2511 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/BallerinaSemanticModel.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/BallerinaSemanticModel.java @@ -42,6 +42,7 @@ import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLocation; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.model.Scope; @@ -301,6 +302,7 @@ public List references(Document sourceDocument, return getReferences(symbolAtCursor, node, withDefinition); } + @Nullable private BSymbol findSymbolAtCursorPosition(Document sourceDocument, LinePosition linePosition) { Optional sourceCompilationUnit = getCompilationUnit(sourceDocument); if (sourceCompilationUnit.isEmpty()) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/EnvironmentResolver.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/EnvironmentResolver.java index a39cc3746b01..27042c3a10f7 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/EnvironmentResolver.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/EnvironmentResolver.java @@ -304,8 +304,8 @@ && isNarrowerEnclosure(exprFuncBody.getPosition())) { @Override public void visit(BLangSimpleVariableDef varDefNode) { - boolean isFuture = varDefNode.getVariable().expr != null - && varDefNode.getVariable().expr.getBType() instanceof BFutureType; + BLangExpression expr = varDefNode.getVariable().expr; + boolean isFuture = expr != null && expr.getBType() instanceof BFutureType; if (isFuture) { return; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java index c19429826ce3..7c49201c0e7b 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java @@ -473,7 +473,7 @@ public Optional transform(ExplicitNewExpressionNode node) { instanceof BInvokableSymbol)) { List params = ((BInvokableSymbol) (((BLangInvocation) ((BLangTypeInit) bLangNode). initInvocation).symbol)).params; - if (params.isEmpty()) { + if (params == null || params.isEmpty()) { throw new IllegalStateException(); } @@ -525,7 +525,7 @@ public Optional transform(ImplicitNewExpressionNode node) { } List params = ((BInvokableSymbol) initInvocation.symbol).params; - if (params.isEmpty()) { + if (params == null || params.isEmpty()) { throw new IllegalStateException(); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibFunctionBinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibFunctionBinder.java index 1118cbb37226..d6e4705b830b 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibFunctionBinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibFunctionBinder.java @@ -19,6 +19,7 @@ package io.ballerina.compiler.api.impl; import org.ballerinalang.model.symbols.AnnotationAttachmentSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableTypeSymbol; @@ -62,7 +63,7 @@ public LangLibFunctionBinder(CompilerContext context) { * @param boundType The type to bind the type param to * @return The type param resolved lang lib function symbol */ - public BInvokableSymbol cloneAndBind(BInvokableSymbol original, BType type, BType boundType) { + public BInvokableSymbol cloneAndBind(BInvokableSymbol original, BType type, @Nullable BType boundType) { if (boundType == null || original.params.isEmpty()) { return original; } @@ -89,6 +90,7 @@ public BInvokableSymbol cloneAndBind(BInvokableSymbol original, BType type, BTyp return duplicate; } + @Nullable private BVarSymbol createNewVarSymbol(BVarSymbol param, BType boundType, TypeParamResolver resolver) { // The following null check is required since this method is also used for duplicating the rest param symbols. if (param == null) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibrary.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibrary.java index 98dd7af33a89..3cded240cd79 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibrary.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/LangLibrary.java @@ -24,6 +24,7 @@ import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.Scope; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; @@ -139,7 +140,7 @@ private String getLangLibName(BType type) { } private void populateMethodList(List list, Map langLib, BType type, - BType boundTypeParam) { + @Nullable BType boundTypeParam) { for (BInvokableSymbol symbol : langLib.values()) { String name = symbol.getOriginalName().getValue(); BInvokableSymbol duplicate = methodBinder.cloneAndBind(symbol, type, boundTypeParam); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/NodeFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/NodeFinder.java index e9d5e5346fe3..d0e3717dca1d 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/NodeFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/NodeFinder.java @@ -27,6 +27,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangAnnotation; import org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment; import org.wso2.ballerinalang.compiler.tree.BLangBlockFunctionBody; @@ -218,6 +219,7 @@ class NodeFinder extends BaseVisitor { private LineRange range; + @Nullable private BLangNode enclosingNode; private BLangNode enclosingContainer; private final boolean allowExprStmts; @@ -253,6 +255,7 @@ BLangNode lookupEnclosingContainer(BLangCompilationUnit compilationUnit, LineRan return this.enclosingContainer; } + @Nullable private BLangNode lookupTopLevelNodes(List nodes, LineRange range) { this.range = range; this.enclosingNode = null; @@ -286,7 +289,7 @@ private void lookupNodes(List nodes) { } } - private void lookupNode(BLangNode node) { + private void lookupNode(@Nullable BLangNode node) { if (node == null) { return; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java index c1d1b313f4d5..f93eb5ab7803 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java @@ -27,6 +27,7 @@ import org.ballerinalang.model.tree.Node; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLocation; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BResourceFunction; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BResourcePathSegmentSymbol; @@ -1520,7 +1521,7 @@ private void visitNamedArgWithoutAddingSymbol(List arg } } - private boolean addIfSameSymbol(BSymbol symbol, Location location) { + private boolean addIfSameSymbol(@Nullable BSymbol symbol, Location location) { if (symbol != null && this.targetSymbol.name.equals(symbol.name) && this.targetSymbol.pkgID.equals(symbol.pkgID) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/SymbolFactory.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/SymbolFactory.java index b91b0c6824c4..393b6073564a 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/SymbolFactory.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/SymbolFactory.java @@ -60,6 +60,7 @@ import org.ballerinalang.model.symbols.AnnotationAttachmentSymbol; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; @@ -145,6 +146,7 @@ public static SymbolFactory getInstance(CompilerContext context) { * @param name symbol name * @return generated compiled symbol */ + @Nullable public Symbol getBCompiledSymbol(BSymbol symbol, String name) { if (symbol == null) { @@ -413,16 +415,19 @@ private boolean isReadonlyIntersectionArrayType(BType type) { return false; } + @Nullable public BallerinaRecordFieldSymbol createRecordFieldSymbol(BVarSymbol symbol) { BField bField = getBField(symbol); return bField != null ? new BallerinaRecordFieldSymbol(this.context, bField) : null; } + @Nullable public BallerinaObjectFieldSymbol createObjectFieldSymbol(BVarSymbol symbol) { BField bField = getBField(symbol); return bField != null ? new BallerinaObjectFieldSymbol(this.context, bField) : null; } + @Nullable public BallerinaClassFieldSymbol createClassFieldSymbol(BVarSymbol symbol) { BField bField = getBField(symbol); return bField != null ? new BallerinaClassFieldSymbol(this.context, bField) : null; @@ -449,6 +454,7 @@ public BallerinaWorkerSymbol createWorkerSymbol(BWorkerSymbol symbol, String nam * @param kind The kind of the parameter * @return {@link ParameterSymbol} generated parameter */ + @Nullable public ParameterSymbol createBallerinaParameter(BVarSymbol symbol, ParameterKind kind) { if (symbol == null) { return null; @@ -630,6 +636,7 @@ public BallerinaConstantSymbol createConstantSymbol(BConstantSymbol constantSymb return symbolBuilder.build(); } + @Nullable private BallerinaConstantValue createConstantValue(BLangConstantValue constantValue) { if (constantValue == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/SymbolFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/SymbolFinder.java index 948f17dc73d5..39b0477297b3 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/SymbolFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/SymbolFinder.java @@ -31,6 +31,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BResourcePathSegmentSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.tree.BLangAnnotation; @@ -244,9 +245,10 @@ class SymbolFinder extends BaseVisitor { private LinePosition cursorPos; + @Nullable private BSymbol symbolAtCursor; - BSymbol lookup(BLangCompilationUnit unit, LinePosition cursorPos) { + @Nullable BSymbol lookup(BLangCompilationUnit unit, LinePosition cursorPos) { this.cursorPos = cursorPos; this.symbolAtCursor = null; @@ -1830,7 +1832,7 @@ && setEnclosingNode(pathSymbol, expr.pos)) { } } - private boolean setEnclosingNode(BSymbol symbol, Location pos) { + private boolean setEnclosingNode(@Nullable BSymbol symbol, Location pos) { if (PositionUtil.withinBlock(this.cursorPos, pos)) { this.symbolAtCursor = symbol; return true; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamFinder.java index b11ed6ebfe97..7da8b53ce734 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamFinder.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.api.impl; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BAttachedFunction; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BObjectTypeSymbol; @@ -73,6 +74,7 @@ public class TypeParamFinder implements TypeVisitor { * @param type The type to look for the type param in * @return Returns the type param if there is one, else returns null */ + @Nullable public BType find(BType type) { if (type == null || this.visited.contains(type)) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamResolver.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamResolver.java index 9deeb9007caf..2e351df60b61 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamResolver.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamResolver.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.symbols.AnnotationAttachmentSymbol; import org.ballerinalang.model.symbols.SymbolKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BAttachedFunction; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol; @@ -377,7 +378,8 @@ private boolean isTypeParam(BType type) { return type == this.typeParam; } - private BVarSymbol createNewVarSymbol(BVarSymbol symbol, BType newType) { + @Nullable + private BVarSymbol createNewVarSymbol(BVarSymbol symbol, @Nullable BType newType) { if (symbol == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/AbstractTypeSymbol.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/AbstractTypeSymbol.java index ff392b6d7f3d..58209bf38120 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/AbstractTypeSymbol.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/AbstractTypeSymbol.java @@ -24,6 +24,7 @@ import io.ballerina.compiler.api.symbols.TypeDescKind; import io.ballerina.compiler.api.symbols.TypeSymbol; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; @@ -48,7 +49,7 @@ public abstract class AbstractTypeSymbol implements TypeSymbol { private final TypeDescKind typeDescKind; private final BType bType; - public AbstractTypeSymbol(CompilerContext context, TypeDescKind typeDescKind, BType bType) { + public AbstractTypeSymbol(CompilerContext context, @Nullable TypeDescKind typeDescKind, BType bType) { this.context = context; this.typeDescKind = typeDescKind; this.bType = bType; @@ -77,6 +78,7 @@ public SymbolKind kind() { return SymbolKind.TYPE; } + @Nullable @Override public Location location() { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaConstantSymbol.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaConstantSymbol.java index 4ce757e082fc..90d34571cf33 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaConstantSymbol.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaConstantSymbol.java @@ -27,6 +27,7 @@ import io.ballerina.compiler.api.symbols.Qualifier; import io.ballerina.compiler.api.symbols.TypeDescKind; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.util.CompilerContext; import org.wso2.ballerinalang.util.Flags; @@ -119,6 +120,7 @@ public T apply(SymbolTransformer transformer) { return transformer.transform(this); } + @Nullable private String stringValueOf(BallerinaConstantValue value) { if (value == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaParameterSymbol.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaParameterSymbol.java index ade4e3125d97..63650a1d15d1 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaParameterSymbol.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaParameterSymbol.java @@ -24,6 +24,7 @@ import io.ballerina.compiler.api.symbols.ParameterSymbol; import io.ballerina.compiler.api.symbols.Qualifier; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.util.CompilerContext; @@ -47,9 +48,10 @@ public class BallerinaParameterSymbol extends BallerinaSymbol implements Paramet private final TypeSymbol typeDescriptor; private final ParameterKind paramKind; - public BallerinaParameterSymbol(String parameterName, TypeSymbol typeDescriptor, List qualifiers, - List annots, List annotAttachments, - ParameterKind paramKind, BVarSymbol symbol, CompilerContext context) { + public BallerinaParameterSymbol(@Nullable String parameterName, TypeSymbol typeDescriptor, + List qualifiers, List annots, + List annotAttachments, ParameterKind paramKind, + BVarSymbol symbol, CompilerContext context) { super(parameterName, PARAMETER, symbol, context); // TODO: Add the metadata this.typeDescriptor = typeDescriptor; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaSymbol.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaSymbol.java index 2c30110360ff..762f48b97af2 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaSymbol.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaSymbol.java @@ -27,6 +27,7 @@ import io.ballerina.tools.diagnostics.Location; import io.ballerina.tools.text.LineRange; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLocation; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; @@ -52,7 +53,7 @@ public class BallerinaSymbol implements Symbol { private ModuleSymbol module; private boolean moduleEvaluated; - protected BallerinaSymbol(String name, SymbolKind symbolKind, BSymbol symbol, CompilerContext context) { + protected BallerinaSymbol(@Nullable String name, SymbolKind symbolKind, BSymbol symbol, CompilerContext context) { this.name = name; this.symbolKind = symbolKind; this.context = context; @@ -121,7 +122,7 @@ public Optional getLocation() { } @Override - public boolean nameEquals(String name) { + public boolean nameEquals(@Nullable String name) { Optional symbolName = this.getName(); if (symbolName.isEmpty() || name == null) { return false; @@ -170,7 +171,7 @@ public BSymbol getInternalSymbol() { return this.internalSymbol; } - Documentation getDocAttachment(BSymbol symbol) { + @Nullable Documentation getDocAttachment(BSymbol symbol) { return symbol == null ? null : new BallerinaDocumentation(symbol.markdownDocumentation); } @@ -210,7 +211,7 @@ protected abstract static class SymbolBuilder> { * @param bSymbol symbol to evaluate * @param context context of the compilation */ - public SymbolBuilder(String name, SymbolKind symbolKind, BSymbol bSymbol, CompilerContext context) { + public SymbolBuilder(@Nullable String name, SymbolKind symbolKind, BSymbol bSymbol, CompilerContext context) { this.name = name; this.ballerinaSymbolKind = symbolKind; this.bSymbol = bSymbol; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaTypeReferenceTypeSymbol.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaTypeReferenceTypeSymbol.java index e68a1d5e22fd..b83ff89514b5 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaTypeReferenceTypeSymbol.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaTypeReferenceTypeSymbol.java @@ -28,6 +28,7 @@ import io.ballerina.compiler.api.symbols.TypeSymbol; import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.Scope; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.semantics.model.types.BParameterizedType; @@ -198,6 +199,7 @@ private boolean isAnonOrg(ModuleID moduleID) { return ANON_ORG.equals(moduleID.orgName()); } + @Nullable private BType getReferredType(BType type) { if (type == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/TypesFactory.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/TypesFactory.java index 3c0705554eda..85d84e9dc4a9 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/TypesFactory.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/TypesFactory.java @@ -24,6 +24,7 @@ import io.ballerina.compiler.api.symbols.XMLTypeSymbol; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BClassSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableTypeSymbol; @@ -148,12 +149,12 @@ public TypeSymbol getTypeDescriptor(BType bType, BSymbol tSymbol) { * @param rawTypeOnly Whether to convert the type descriptor to type reference or keep the raw type * @return {@link TypeSymbol} generated */ - public TypeSymbol getTypeDescriptor(BType bType, BSymbol tSymbol, boolean rawTypeOnly) { + public TypeSymbol getTypeDescriptor(BType bType, @Nullable BSymbol tSymbol, boolean rawTypeOnly) { return getTypeDescriptor(bType, tSymbol, rawTypeOnly, true, false); } - TypeSymbol getTypeDescriptor(BType bType, BSymbol tSymbol, boolean rawTypeOnly, boolean getOriginalType, - boolean typeRefFromIntersectType) { + @Nullable TypeSymbol getTypeDescriptor(BType bType, @Nullable BSymbol tSymbol, boolean rawTypeOnly, + boolean getOriginalType, boolean typeRefFromIntersectType) { if (bType == null) { return null; } @@ -312,6 +313,7 @@ public boolean isTypeReference(BType bType, BSymbol tSymbol, boolean rawTypeOnly || tSymbol.kind == SymbolKind.ENUM || isCustomError(tSymbol); } + @Nullable public static TypeDescKind getTypeDescKind(TypeKind bTypeKind) { return switch (bTypeKind) { case ANY -> TypeDescKind.ANY; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaArrayTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaArrayTypeBuilder.java index 72702a3e9105..a53ead13e352 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaArrayTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaArrayTypeBuilder.java @@ -23,6 +23,7 @@ import io.ballerina.compiler.api.impl.symbols.TypesFactory; import io.ballerina.compiler.api.symbols.ArrayTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag; @@ -45,6 +46,7 @@ public class BallerinaArrayTypeBuilder implements TypeBuilder.ARRAY { private final TypesFactory typesFactory; private final SymbolTable symTable; + @Nullable private TypeSymbol type; private int size = -1; private BArrayState state = BArrayState.OPEN; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaErrorTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaErrorTypeBuilder.java index 179cb64da617..9143f604be59 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaErrorTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaErrorTypeBuilder.java @@ -26,6 +26,7 @@ import io.ballerina.compiler.api.symbols.RecordTypeSymbol; import io.ballerina.compiler.api.symbols.TypeDescKind; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BErrorTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag; @@ -46,6 +47,7 @@ public class BallerinaErrorTypeBuilder implements TypeBuilder.ERROR { private final TypesFactory typesFactory; private final SymbolTable symTable; + @Nullable private TypeSymbol typeParam; public BallerinaErrorTypeBuilder(CompilerContext context) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaFunctionTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaFunctionTypeBuilder.java index 178519d7121a..3b368aed9ed7 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaFunctionTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaFunctionTypeBuilder.java @@ -27,6 +27,7 @@ import io.ballerina.compiler.api.symbols.ParameterKind; import io.ballerina.compiler.api.symbols.ParameterSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; @@ -59,7 +60,9 @@ public class BallerinaFunctionTypeBuilder implements TypeBuilder.FUNCTION { private final TypesFactory typesFactory; private final SymbolTable symTable; private final List parameterSymbols = new ArrayList<>(); + @Nullable private ParameterSymbol restParam; + @Nullable private TypeSymbol returnTypeSymbol; public BallerinaFunctionTypeBuilder(CompilerContext context) { @@ -116,6 +119,7 @@ public FunctionTypeSymbol build() { return functionTypeSymbol; } + @Nullable private BVarSymbol getRestParamSymbol(ParameterSymbol restParam, BType restType) { if (restParam == null) { return null; @@ -130,6 +134,7 @@ private BVarSymbol getRestParamSymbol(ParameterSymbol restParam, BType restType) return null; } + @Nullable private BType getRestType(ParameterSymbol restParam) { if (restParam == null) { return null; @@ -194,8 +199,11 @@ private BType getReturnBType(TypeSymbol returnTypeSymbol) { public class ParameterBuilder implements PARAMETER_BUILDER { private final SymbolFactory symbolFactory; + @Nullable private String name; + @Nullable private TypeSymbol type; + @Nullable private ParameterKind kind; private ParameterBuilder(CompilerContext context) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaFutureTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaFutureTypeBuilder.java index 073cf34788a8..b667b2f1aa4a 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaFutureTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaFutureTypeBuilder.java @@ -23,6 +23,7 @@ import io.ballerina.compiler.api.impl.symbols.TypesFactory; import io.ballerina.compiler.api.symbols.FutureTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag; @@ -45,6 +46,7 @@ public class BallerinaFutureTypeBuilder implements TypeBuilder.FUTURE { private final TypesFactory typesFactory; private final SymbolTable symTable; + @Nullable private TypeSymbol typeParam; public BallerinaFutureTypeBuilder(CompilerContext context) { @@ -71,6 +73,7 @@ public FutureTypeSymbol build() { return futureTypeSymbol; } + @Nullable private BType getBType(TypeSymbol typeSymbol) { if (typeSymbol == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaMapTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaMapTypeBuilder.java index a97976f1a1e8..9706e1626ed5 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaMapTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaMapTypeBuilder.java @@ -23,6 +23,7 @@ import io.ballerina.compiler.api.impl.symbols.TypesFactory; import io.ballerina.compiler.api.symbols.MapTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag; @@ -43,6 +44,7 @@ public class BallerinaMapTypeBuilder implements TypeBuilder.MAP { private final TypesFactory typesFactory; private final SymbolTable symTable; + @Nullable private TypeSymbol typeParam; public BallerinaMapTypeBuilder(CompilerContext context) { @@ -71,6 +73,7 @@ public MapTypeSymbol build() { return mapTypeSymbol; } + @Nullable private BType getBType(TypeSymbol typeSymbol) { if (typeSymbol == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaObjectTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaObjectTypeBuilder.java index ed7387eab7c7..a3ffa9a8a998 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaObjectTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaObjectTypeBuilder.java @@ -27,6 +27,7 @@ import io.ballerina.compiler.api.symbols.TypeReferenceTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; import org.ballerinalang.model.elements.Flag; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BAttachedFunction; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol; @@ -220,6 +221,7 @@ private BType getBType(TypeSymbol typeSymbol) { throw new IllegalArgumentException("Invalid type provided"); } + @Nullable private BType getTypeInclusionBType(TypeSymbol typeSymbol) { if (typeSymbol != null) { if (typeSymbol instanceof AbstractTypeSymbol abstractTypeSymbol) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaRecordTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaRecordTypeBuilder.java index 33c88117390f..b4f7420dd29b 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaRecordTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaRecordTypeBuilder.java @@ -25,6 +25,7 @@ import io.ballerina.compiler.api.symbols.TypeReferenceTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; import org.ballerinalang.model.elements.Flag; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BRecordTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; @@ -51,6 +52,7 @@ public class BallerinaRecordTypeBuilder implements TypeBuilder.RECORD { private final TypesFactory typesFactory; private final SymbolTable symTable; + @Nullable private TypeSymbol restField; private final List recordFieldList = new ArrayList<>(); private final List typeInclusions = new ArrayList<>(); @@ -243,6 +245,7 @@ private List getTypeInclusions(List typeInclusio return typeInclusionList; } + @Nullable private BType getBType(TypeSymbol typeSymbol) { if (typeSymbol != null) { if (typeSymbol instanceof AbstractTypeSymbol abstractTypeSymbol) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaSingletonTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaSingletonTypeBuilder.java index 148ebbed813b..2663313de43f 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaSingletonTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaSingletonTypeBuilder.java @@ -23,6 +23,7 @@ import io.ballerina.compiler.api.impl.symbols.TypesFactory; import io.ballerina.compiler.api.symbols.SingletonTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag; @@ -47,7 +48,9 @@ public class BallerinaSingletonTypeBuilder implements TypeBuilder.SINGLETON { private final TypesFactory typesFactory; private final SymbolTable symTable; + @Nullable private TypeSymbol valueTypeSymbol; + @Nullable private Object value; public BallerinaSingletonTypeBuilder(CompilerContext context) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaStreamTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaStreamTypeBuilder.java index e71fc54136c9..52ebf8219e0b 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaStreamTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaStreamTypeBuilder.java @@ -23,6 +23,7 @@ import io.ballerina.compiler.api.impl.symbols.TypesFactory; import io.ballerina.compiler.api.symbols.StreamTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag; @@ -43,7 +44,9 @@ public class BallerinaStreamTypeBuilder implements TypeBuilder.STREAM { private final TypesFactory typesFactory; private final SymbolTable symTable; + @Nullable private TypeSymbol valueType; + @Nullable private TypeSymbol completionType; public BallerinaStreamTypeBuilder(CompilerContext context) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTableTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTableTypeBuilder.java index 18af7c102770..1962cfc03089 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTableTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTableTypeBuilder.java @@ -28,6 +28,7 @@ import io.ballerina.compiler.api.symbols.TypeDescKind; import io.ballerina.compiler.api.symbols.TypeReferenceTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; @@ -61,6 +62,7 @@ public class BallerinaTableTypeBuilder implements TypeBuilder.TABLE { private final TypesFactory typesFactory; private final SymbolTable symTable; private final Types types; + @Nullable private TypeSymbol rowType; private final List keyTypes = new ArrayList<>(); private final List fieldNames = new ArrayList<>(); @@ -242,6 +244,7 @@ private boolean isValidRowRecordType(BRecordType rowBType) { return false; } + @Nullable private BType getBType(TypeSymbol typeSymbol) { if (typeSymbol != null) { if (typeSymbol instanceof AbstractTypeSymbol abstractTypeSymbol diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTupleTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTupleTypeBuilder.java index 9b401688b982..57dd93f0010c 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTupleTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTupleTypeBuilder.java @@ -24,6 +24,7 @@ import io.ballerina.compiler.api.symbols.TupleTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; @@ -49,6 +50,7 @@ public class BallerinaTupleTypeBuilder implements TypeBuilder.TUPLE { private final TypesFactory typesFactory; private final SymbolTable symTable; private final List memberTypes = new ArrayList<>(); + @Nullable private TypeSymbol restType; public BallerinaTupleTypeBuilder(CompilerContext context) { @@ -106,6 +108,7 @@ private BType getMemberType(TypeSymbol memberType) { return symTable.noType; } + @Nullable private BType getRestType(TypeSymbol restType) { return restType instanceof AbstractTypeSymbol abstractTypeSymbol ? abstractTypeSymbol.getBType() : null; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTypeDescTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTypeDescTypeBuilder.java index d387090e8562..babc0cf4a4fe 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTypeDescTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaTypeDescTypeBuilder.java @@ -24,6 +24,7 @@ import io.ballerina.compiler.api.symbols.TypeDescTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag; @@ -43,6 +44,7 @@ public class BallerinaTypeDescTypeBuilder implements TypeBuilder.TYPEDESC { private final TypesFactory typesFactory; private final SymbolTable symTable; + @Nullable private TypeSymbol typeParam; public BallerinaTypeDescTypeBuilder(CompilerContext context) { @@ -70,6 +72,7 @@ public TypeDescTypeSymbol build() { return typeDescTypeSymbol; } + @Nullable private BType getBType(TypeSymbol typeSymbol) { if (typeSymbol != null) { if (typeSymbol instanceof AbstractTypeSymbol abstractTypeSymbol) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaXMLTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaXMLTypeBuilder.java index fb7749b97aea..e07103d057d0 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaXMLTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaXMLTypeBuilder.java @@ -26,6 +26,7 @@ import io.ballerina.compiler.api.symbols.TypeSymbol; import io.ballerina.compiler.api.symbols.UnionTypeSymbol; import io.ballerina.compiler.api.symbols.XMLTypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -52,6 +53,7 @@ public class BallerinaXMLTypeBuilder implements TypeBuilder.XML { private final TypesFactory typesFactory; private final SymbolTable symTable; + @Nullable private TypeSymbol typeParam; private final Map checkedTypeRefs = new HashMap<>(); @@ -90,6 +92,7 @@ public XMLTypeSymbol build() { return xmlTypeSymbol; } + @Nullable private BType getBType(TypeSymbol typeSymbol) { if (typeSymbol != null) { if (isValidTypeParam(typeSymbol)) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/util/SymbolUtils.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/util/SymbolUtils.java index dcef4293e015..fe209155ee7f 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/util/SymbolUtils.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/util/SymbolUtils.java @@ -31,6 +31,7 @@ import io.ballerina.compiler.api.symbols.TypeSymbol; import io.ballerina.compiler.api.symbols.VariableSymbol; import io.ballerina.identifier.Utils; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType; import org.wso2.ballerinalang.compiler.semantics.model.types.BMapType; import org.wso2.ballerinalang.compiler.semantics.model.types.BStreamType; @@ -84,6 +85,7 @@ public static Optional getTypeDescriptor(Symbol symbol) { * @param type The input BType for which the bound type is to be retrieved. * @return The bound type based on the kind of the input BType. Returns null if the kind is not supported. */ + @Nullable public static BType getTypeParamBoundType(BType type) { return switch (type.getKind()) { case MAP -> ((BMapType) type).constraint; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java index 8cf67d265bba..343816cfc4e9 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -45,7 +47,8 @@ public Map>> tools() { return tools; } - public void addTool(String id, String org, String name, String version, Boolean active, String repository) { + public void addTool(String id, String org, String name, String version, Boolean active, + @Nullable String repository) { if (!tools.containsKey(id)) { tools.put(id, new HashMap<>()); } @@ -59,7 +62,7 @@ public void addTool(String id, String org, String name, String version, Boolean tools.get(id).get(version).put(repository, new Tool(id, org, name, version, active, repository)); } - public Optional getTool(String id, String version, String repository) { + public Optional getTool(String id, String version, @Nullable String repository) { if (tools.containsKey(id) && tools.get(id).containsKey(version)) { return Optional.ofNullable(tools.get(id).get(version).get(repository)); } @@ -110,7 +113,7 @@ public static class Tool { private Boolean active; private final String repository; - public Tool(String id, String org, String name, String version, Boolean active, String repository) { + public Tool(String id, String org, String name, String version, Boolean active, @Nullable String repository) { this.id = id; this.org = org; this.name = name; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalaWriter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalaWriter.java index 0d5e8ca23d67..781aaab087ec 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalaWriter.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalaWriter.java @@ -37,6 +37,7 @@ import io.ballerina.tools.text.TextDocuments; import org.apache.commons.compress.utils.IOUtils; import org.ballerinalang.compiler.BLangCompilerException; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.util.RepoUtils; import java.io.ByteArrayInputStream; @@ -229,6 +230,7 @@ private void setGraalVMCompatibilityProperty(PackageJson packageJson, PackageMan } } + @Nullable private static Boolean isAllPlatformDepsGraalvmCompatible(Map platforms) { Boolean isAllDepsGraalvmCompatible = true; for (PackageManifest.Platform platform: platforms.values()) { @@ -539,6 +541,7 @@ protected abstract Optional addPlatformLibs(ZipOutputStream balaOutpu // Following function was put in to handle a bug in windows zipFileSystem // Refer https://bugs.openjdk.java.net/browse/JDK-8195141 + @Nullable private String convertPathSeperator(Path file) { if (file == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildOptions.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildOptions.java index 709140908558..e5aa7ec1ecfe 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildOptions.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildOptions.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.util.Objects; /** @@ -294,17 +296,17 @@ public BuildOptionsBuilder disableSyntaxTreeCaching(Boolean value) { return this; } - public BuildOptionsBuilder setTestReport(Boolean value) { + public BuildOptionsBuilder setTestReport(@Nullable Boolean value) { testReport = value; return this; } - public BuildOptionsBuilder setCodeCoverage(Boolean value) { + public BuildOptionsBuilder setCodeCoverage(@Nullable Boolean value) { codeCoverage = value; return this; } - public BuildOptionsBuilder setDumpBuildTime(Boolean value) { + public BuildOptionsBuilder setDumpBuildTime(@Nullable Boolean value) { dumpBuildTime = value; return this; } @@ -319,17 +321,17 @@ public BuildOptionsBuilder setSticky(Boolean value) { return this; } - public BuildOptionsBuilder setListConflictedClasses(Boolean value) { + public BuildOptionsBuilder setListConflictedClasses(@Nullable Boolean value) { compilationOptionsBuilder.setListConflictedClasses(value); return this; } - public BuildOptionsBuilder setOffline(Boolean value) { + public BuildOptionsBuilder setOffline(@Nullable Boolean value) { compilationOptionsBuilder.setOffline(value); return this; } - public BuildOptionsBuilder setGraalVMBuildOptions(String value) { + public BuildOptionsBuilder setGraalVMBuildOptions(@Nullable String value) { graalVMBuildOptions = value; return this; } @@ -345,12 +347,12 @@ public BuildOptionsBuilder setExperimental(Boolean value) { return this; } - public BuildOptionsBuilder setObservabilityIncluded(Boolean value) { + public BuildOptionsBuilder setObservabilityIncluded(@Nullable Boolean value) { compilationOptionsBuilder.setObservabilityIncluded(value); return this; } - public BuildOptionsBuilder setCloud(String value) { + public BuildOptionsBuilder setCloud(@Nullable String value) { compilationOptionsBuilder.setCloud(value); return this; } @@ -390,29 +392,29 @@ public BuildOptionsBuilder setExportOpenAPI(Boolean value) { return this; } - public BuildOptionsBuilder setExportComponentModel(Boolean value) { + public BuildOptionsBuilder setExportComponentModel(@Nullable Boolean value) { compilationOptionsBuilder.setExportComponentModel(value); exportComponentModel = value; return this; } - public BuildOptionsBuilder setEnableCache(Boolean value) { + public BuildOptionsBuilder setEnableCache(@Nullable Boolean value) { compilationOptionsBuilder.setEnableCache(value); enableCache = value; return this; } - public BuildOptionsBuilder setNativeImage(Boolean value) { + public BuildOptionsBuilder setNativeImage(@Nullable Boolean value) { nativeImage = value; return this; } - public BuildOptionsBuilder setRemoteManagement(Boolean value) { + public BuildOptionsBuilder setRemoteManagement(@Nullable Boolean value) { compilationOptionsBuilder.setRemoteManagement(value); return this; } - public BuildOptionsBuilder setShowDependencyDiagnostics(Boolean value) { + public BuildOptionsBuilder setShowDependencyDiagnostics(@Nullable Boolean value) { showDependencyDiagnostics = value; return this; } @@ -423,7 +425,7 @@ public BuildOptionsBuilder setShowDependencyDiagnostics(Boolean value) { * @param value true or false (default) * @return BuildOptionsBuilder instance */ - public BuildOptionsBuilder setOptimizeDependencyCompilation(Boolean value) { + public BuildOptionsBuilder setOptimizeDependencyCompilation(@Nullable Boolean value) { compilationOptionsBuilder.setOptimizeDependencyCompilation(value); return this; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildTool.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildTool.java index 851d096ef1a1..2b6e5b4afde9 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildTool.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BuildTool.java @@ -19,6 +19,7 @@ package io.ballerina.projects; import io.ballerina.toml.semantic.diagnostics.TomlNodeLocation; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -56,10 +57,10 @@ private BuildTool( */ public static BuildTool from( BuildToolId id, - PackageOrg org, - PackageName name, - PackageVersion version, - TomlNodeLocation location) { + @Nullable PackageOrg org, + @Nullable PackageName name, + @Nullable PackageVersion version, + @Nullable TomlNodeLocation location) { return new BuildTool(id, org, name, version, location); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeGeneratorResult.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeGeneratorResult.java index c4dcb3929b6e..c2748e9a68b1 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeGeneratorResult.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeGeneratorResult.java @@ -19,6 +19,7 @@ import io.ballerina.projects.internal.DefaultDiagnosticResult; import io.ballerina.tools.diagnostics.Diagnostic; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Optional; @@ -33,7 +34,7 @@ public class CodeGeneratorResult { private final Package updatedPkg; private final DiagnosticResult diagnostics; - CodeGeneratorResult(Package updatedPkg, Collection diagnostics) { + CodeGeneratorResult(@Nullable Package updatedPkg, Collection diagnostics) { this.updatedPkg = updatedPkg; this.diagnostics = new DefaultDiagnosticResult(diagnostics); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeModifierResult.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeModifierResult.java index c51d8f1dd078..9e9d00d4972d 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeModifierResult.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeModifierResult.java @@ -19,6 +19,7 @@ import io.ballerina.projects.internal.DefaultDiagnosticResult; import io.ballerina.tools.diagnostics.Diagnostic; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Optional; @@ -33,7 +34,7 @@ public class CodeModifierResult { private final Package updatedPkg; private final DiagnosticResult diagnostics; - CodeModifierResult(Package updatedPkg, Collection diagnostics) { + CodeModifierResult(@Nullable Package updatedPkg, Collection diagnostics) { this.updatedPkg = updatedPkg; this.diagnostics = new DefaultDiagnosticResult(diagnostics); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ConfigReader.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ConfigReader.java index fc35b719b2de..abb1ac3352ce 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ConfigReader.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ConfigReader.java @@ -33,6 +33,7 @@ import io.ballerina.projects.configurations.ConfigModuleDetails; import io.ballerina.projects.configurations.ConfigVariable; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.Scope; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; @@ -192,7 +193,7 @@ private static void getConfigs(Module module, } private static void getConfigVars(Module module, Collection scopeEntries, - Set validConfigs, List configVariables) { + @Nullable Set validConfigs, List configVariables) { for (Scope.ScopeEntry entry : scopeEntries) { BSymbol symbol = entry.symbol; // Filter configurable variables @@ -298,6 +299,7 @@ private static String getDescriptionValue(BVarSymbol symbol, Module module) { * @param syntaxTreeMap Syntax tree map for the specific module * @return Relevant syntax tree node for the variable */ + @Nullable private static Node getVariableNode(int position, Map syntaxTreeMap) { for (Map.Entry syntaxTreeEntry : syntaxTreeMap.entrySet()) { if (syntaxTreeEntry.getValue().containsModulePart()) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DependencyGraph.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DependencyGraph.java index 9bfe85bf9466..d694c263e618 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DependencyGraph.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DependencyGraph.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -40,6 +42,7 @@ public class DependencyGraph { private final T rootNode; private final Map> dependencies; + @Nullable private List topologicallySortedNodes; private Set> cyclicDependencies; @@ -57,7 +60,7 @@ public static DependencyGraph from(Map> dependencies) { return new DependencyGraph<>(null, dependencies); } - private DependencyGraph(T rootNode, Map> dependencies) { + private DependencyGraph(@Nullable T rootNode, Map> dependencies) { this.rootNode = rootNode; this.dependencies = Collections.unmodifiableMap(dependencies); } @@ -242,7 +245,7 @@ public static class DependencyGraphBuilder { private final T rootNode; private final Map> dependenciesMap; - private DependencyGraphBuilder(T rootNode, Map> dependencies) { + private DependencyGraphBuilder(@Nullable T rootNode, Map> dependencies) { this.rootNode = rootNode; this.dependenciesMap = dependencies; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DependencyManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DependencyManifest.java index d8e52df5882c..8beeddd86546 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DependencyManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DependencyManifest.java @@ -21,6 +21,7 @@ import io.ballerina.projects.internal.DefaultDiagnosticResult; import io.ballerina.projects.internal.PackageContainer; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; @@ -59,16 +60,16 @@ private DependencyManifest(String dependenciesTomlVersion, } } - public static DependencyManifest from(String dependenciesTomlVersion, - SemanticVersion distributionVersion, + public static DependencyManifest from(@Nullable String dependenciesTomlVersion, + @Nullable SemanticVersion distributionVersion, List dependencies, - List tools, + List tools, DiagnosticResult diagnostics) { return new DependencyManifest(dependenciesTomlVersion, distributionVersion, dependencies, tools, diagnostics); } - public static DependencyManifest from(String dependenciesTomlVersion, - SemanticVersion distributionVersion, + public static DependencyManifest from(@Nullable String dependenciesTomlVersion, + @Nullable SemanticVersion distributionVersion, List dependencies, List tools) { return new DependencyManifest(dependenciesTomlVersion, distributionVersion, dependencies, tools, @@ -131,7 +132,7 @@ public Package(PackageName packageName, PackageOrg packageOrg, PackageVersion ve this.modules = Collections.emptyList(); } - public Package(PackageName packageName, PackageOrg packageOrg, PackageVersion version, String scope, + public Package(PackageName packageName, PackageOrg packageOrg, PackageVersion version, @Nullable String scope, boolean transitive, List dependencies, List modules, Location location) { this.packageName = packageName; this.packageOrg = packageOrg; @@ -154,7 +155,7 @@ public Package(PackageName packageName, PackageOrg packageOrg, PackageVersion ve this.modules = Collections.emptyList(); } - public Package(PackageName packageName, PackageOrg packageOrg, PackageVersion version, String scope, + public Package(PackageName packageName, PackageOrg packageOrg, PackageVersion version, @Nullable String scope, boolean transitive, List dependencies, List modules) { this.packageName = packageName; this.packageOrg = packageOrg; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java index c219679275d7..e1ec1b989b0a 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java @@ -29,6 +29,7 @@ import io.ballerina.tools.text.TextDocuments; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.tree.SourceKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangNodeBuilder; import org.wso2.ballerinalang.compiler.parser.NodeCloner; @@ -51,13 +52,16 @@ class DocumentContext { // TODO This constant should not be here private static final String IDENTIFIER_LITERAL_PREFIX = "'"; + @Nullable private SyntaxTree syntaxTree; private TextDocument textDocument; + @Nullable private Set moduleLoadRequests; private BLangCompilationUnit compilationUnit; private NodeCloner nodeCloner; private final DocumentId documentId; private final String name; + @Nullable private String content; private final boolean disableSyntaxTree; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentId.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentId.java index 29589ff5b4b3..4e39b999103a 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentId.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentId.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.util.Objects; import java.util.UUID; @@ -36,7 +38,7 @@ private DocumentId(UUID id, String documentPath, ModuleId moduleId) { this.moduleId = moduleId; } - public static DocumentId create(String documentPath, ModuleId moduleId) { + public static DocumentId create(String documentPath, @Nullable ModuleId moduleId) { return new DocumentId(UUID.randomUUID(), documentPath, moduleId); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/EmitResult.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/EmitResult.java index 8f1df0b1116c..691d3f934646 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/EmitResult.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/EmitResult.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.nio.file.Path; /** @@ -30,7 +32,7 @@ public class EmitResult { private final DiagnosticResult diagnostics; private final Path generatedArtifact; - EmitResult(boolean success, DiagnosticResult diagnostics, Path generatedArtifact) { + EmitResult(boolean success, DiagnosticResult diagnostics, @Nullable Path generatedArtifact) { this.success = success; this.diagnostics = diagnostics; this.generatedArtifact = generatedArtifact; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java index 8f70836d10e2..17e48ba7e47c 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java @@ -37,6 +37,7 @@ import org.ballerinalang.maven.MavenResolver; import org.ballerinalang.maven.Utils; import org.ballerinalang.maven.exceptions.MavenResolverException; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.codegen.CodeGenerator; import org.wso2.ballerinalang.compiler.bir.codegen.CompiledJarFile; import org.wso2.ballerinalang.compiler.bir.codegen.interop.InteropValidator; @@ -419,6 +420,7 @@ public List conflictedJars() { } // TODO Can we move this method to Module.displayName() + @Nullable private String getJarFileName(ModuleContext moduleContext) { String jarName; if (moduleContext.project().kind() == ProjectKind.SINGLE_FILE_PROJECT) { @@ -916,6 +918,7 @@ private void addConflictedJars(JarLibrary jarLibrary, HashMap emitResultDiagnostics } } + @Nullable private PlatformLibrary codeGeneratedResourcesLibrary(PackageId packageId, PlatformLibraryScope scope) { Package pkg = packageCache.getPackageOrThrow(packageId); CompilationCache compilationCache = pkg.project().projectEnvironmentContext().getService( diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Module.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Module.java index f686084bef85..fd2302553c77 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Module.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Module.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.util.Collection; import java.util.Comparator; import java.util.HashSet; @@ -176,6 +178,7 @@ public static class Modifier { private final List dependencies; private final Package packageInstance; private final Project project; + @Nullable private MdDocumentContext moduleMdContext; private Modifier(Module oldModule) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleConfig.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleConfig.java index 2898d66560f2..da2bc1bb0e66 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleConfig.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleConfig.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.util.List; import java.util.Optional; @@ -52,7 +54,7 @@ public static ModuleConfig from(ModuleId moduleId, ModuleDescriptor moduleDescriptor, List srcDocs, List testSrcDocs, - DocumentConfig moduleMd, + @Nullable DocumentConfig moduleMd, List dependencies) { return new ModuleConfig(moduleId, moduleDescriptor, srcDocs, testSrcDocs, moduleMd, dependencies); } @@ -97,11 +99,13 @@ public Optional moduleMd() { return Optional.ofNullable(this.moduleMd); } + @Nullable @Deprecated(since = "2201.10.0", forRemoval = true) public List resources() { return null; } + @Nullable @Deprecated(since = "2201.10.0", forRemoval = true) public List testResources() { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java index 73b0754c448d..7f0427b971b9 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java @@ -30,6 +30,7 @@ import org.ballerinalang.model.TreeBuilder; import org.ballerinalang.model.elements.Flag; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.BIRPackageSymbolEnter; import org.wso2.ballerinalang.compiler.PackageCache; import org.wso2.ballerinalang.compiler.bir.writer.BIRBinaryWriter; @@ -82,6 +83,7 @@ class ModuleContext { private final List moduleDescDependencies; private Set moduleDependencies; + @Nullable private BLangPackage bLangPackage; private BPackageSymbol bPackageSymbol; private byte[] birBytes = new byte[0]; @@ -96,7 +98,7 @@ class ModuleContext { boolean isDefaultModule, Map srcDocContextMap, Map testDocContextMap, - MdDocumentContext moduleMd, + @Nullable MdDocumentContext moduleMd, List moduleDescDependencies) { this.project = project; this.moduleId = moduleId; @@ -276,7 +278,7 @@ ModuleCompilationState currentCompilationState() { return moduleCompState; } - void setCompilationState(ModuleCompilationState moduleCompState) { + void setCompilationState(@Nullable ModuleCompilationState moduleCompState) { this.moduleCompState = moduleCompState; } @@ -484,6 +486,7 @@ private static boolean shouldGenerateBir(ModuleContext moduleContext, CompilerCo && moduleContext.project().buildOptions().enableCache(); } + @Nullable private static ByteArrayOutputStream generateBIR(ModuleContext moduleContext, CompilerContext compilerContext) { if (!shouldGenerateBir(moduleContext, compilerContext)) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleName.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleName.java index 4b597457daac..5d04fbf72a92 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleName.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleName.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.util.Objects; /** @@ -29,7 +31,7 @@ public class ModuleName { private final PackageName packageName; private final String moduleNamePart; - private ModuleName(PackageName packageName, String moduleNamePart) { + private ModuleName(PackageName packageName, @Nullable String moduleNamePart) { this.packageName = packageName; this.moduleNamePart = moduleNamePart; } @@ -39,7 +41,7 @@ public static ModuleName from(PackageName packageName) { return new ModuleName(packageName, null); } - public static ModuleName from(PackageName packageName, String moduleNamePart) { + public static ModuleName from(PackageName packageName, @Nullable String moduleNamePart) { if (moduleNamePart != null && moduleNamePart.isEmpty()) { throw new IllegalArgumentException("moduleNamePart should be a non-empty string or null"); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/NullBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/NullBackend.java index f20ab67a0489..1e9fe05cb0cc 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/NullBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/NullBackend.java @@ -19,6 +19,7 @@ import io.ballerina.projects.environment.ProjectEnvironment; import io.ballerina.projects.internal.DefaultDiagnosticResult; import io.ballerina.tools.diagnostics.Diagnostic; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.CompilerContext; import java.util.ArrayList; @@ -57,36 +58,43 @@ private static void performBIRGen(PackageCompilation compilation, NullBackend nu } + @Nullable @Override public Collection platformLibraryDependencies(PackageId packageId) { return null; } + @Nullable @Override public Collection platformLibraryDependencies(PackageId packageId, PlatformLibraryScope scope) { return null; } + @Nullable @Override public PlatformLibrary codeGeneratedLibrary(PackageId packageId, ModuleName moduleName) { return null; } + @Nullable @Override public PlatformLibrary codeGeneratedTestLibrary(PackageId packageId, ModuleName moduleName) { return null; } + @Nullable @Override public PlatformLibrary codeGeneratedResourcesLibrary(PackageId packageId) { return null; } + @Nullable @Override public PlatformLibrary runtimeLibrary() { return null; } + @Nullable @Override public TargetPlatform targetPlatform() { return null; @@ -96,6 +104,7 @@ public TargetPlatform targetPlatform() { public void performCodeGen(ModuleContext moduleContext, CompilationCache compilationCache) { } + @Nullable @Override public String libraryFileExtension() { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java index d6f6b9d6d46b..6f5d9f8f808d 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java @@ -8,6 +8,7 @@ import io.ballerina.projects.util.ProjectUtils; import io.ballerina.tools.diagnostics.Diagnostic; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.PackageCache; import org.wso2.ballerinalang.compiler.util.CompilerContext; @@ -122,11 +123,12 @@ public Iterable modules() { return new ModuleIterable(moduleList); } - public Module module(ModuleId moduleId) { + public Module module(@Nullable ModuleId moduleId) { // TODO Should we throw an error if the moduleId is not present return this.moduleMap.computeIfAbsent(moduleId, this.populateModuleFunc); } + @Nullable public Module module(ModuleName moduleName) { for (Module module : this.moduleMap.values()) { if (module.moduleName().equals(moduleName)) { @@ -444,11 +446,17 @@ public static class Modifier { private final Project project; private final DependencyGraph dependencyGraph; private final CompilationOptions compilationOptions; + @Nullable private TomlDocumentContext ballerinaTomlContext; + @Nullable private TomlDocumentContext dependenciesTomlContext; + @Nullable private TomlDocumentContext cloudTomlContext; + @Nullable private TomlDocumentContext compilerPluginTomlContext; + @Nullable private TomlDocumentContext balToolTomlContext; + @Nullable private MdDocumentContext packageMdContext; private final Map resourceContextMap; private final Map testResourceContextMap; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageConfig.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageConfig.java index 9ea7569e8574..1dda0d593895 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageConfig.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageConfig.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.nio.file.Path; import java.util.Collection; import java.util.List; @@ -120,10 +122,10 @@ public static PackageConfig from(PackageId packageId, } public static PackageConfig from(PackageId packageId, Path path, PackageManifest packageManifest, - DependencyManifest dependencyManifest, DocumentConfig ballerinaToml, - DocumentConfig dependenciesToml, DocumentConfig cloudToml, - DocumentConfig compilerPluginToml, DocumentConfig balToolToml, - DocumentConfig packageMd, List moduleConfigs, + DependencyManifest dependencyManifest, @Nullable DocumentConfig ballerinaToml, + @Nullable DocumentConfig dependenciesToml, @Nullable DocumentConfig cloudToml, + @Nullable DocumentConfig compilerPluginToml, @Nullable DocumentConfig balToolToml, + @Nullable DocumentConfig packageMd, List moduleConfigs, DependencyGraph packageDependencyGraph, boolean disableSyntaxTree, List resources, List testResources) { @@ -177,6 +179,7 @@ public Optional balToolToml() { return Optional.ofNullable(balToolToml); } + @Nullable public CompilationOptions compilationOptions() { return null; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java index a646004e8ffd..4a3736dd675d 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java @@ -20,6 +20,7 @@ import io.ballerina.projects.DependencyGraph.DependencyGraphBuilder; import io.ballerina.projects.PackageResolution.DependencyResolution; import io.ballerina.projects.internal.model.CompilerPluginDescriptor; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; @@ -76,12 +77,12 @@ class PackageContext { PackageId packageId, PackageManifest packageManifest, DependencyManifest dependencyManifest, - TomlDocumentContext ballerinaTomlContext, - TomlDocumentContext dependenciesTomlContext, - TomlDocumentContext cloudTomlContext, - TomlDocumentContext compilerPluginTomlContext, - TomlDocumentContext balToolTomlContext, - MdDocumentContext packageMdContext, + @Nullable TomlDocumentContext ballerinaTomlContext, + @Nullable TomlDocumentContext dependenciesTomlContext, + @Nullable TomlDocumentContext cloudTomlContext, + @Nullable TomlDocumentContext compilerPluginTomlContext, + @Nullable TomlDocumentContext balToolTomlContext, + @Nullable MdDocumentContext packageMdContext, CompilationOptions compilationOptions, Map moduleContextMap, DependencyGraph pkgDescDependencyGraph, @@ -205,7 +206,7 @@ ModuleContext moduleContext(ModuleId moduleId) { return moduleContextMap.get(moduleId); } - ModuleContext moduleContext(ModuleName moduleName) { + @Nullable ModuleContext moduleContext(ModuleName moduleName) { for (ModuleContext moduleContext : moduleContextMap.values()) { if (moduleContext.moduleName().equals(moduleName)) { return moduleContext; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageDescriptor.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageDescriptor.java index 7038cff9273d..8a26e6601b50 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageDescriptor.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageDescriptor.java @@ -18,6 +18,7 @@ package io.ballerina.projects; import io.ballerina.projects.util.ProjectUtils; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -40,8 +41,8 @@ public class PackageDescriptor implements Comparable { private PackageDescriptor(PackageOrg packageOrg, PackageName packageName, - PackageVersion packageVersion, - String repository) { + @Nullable PackageVersion packageVersion, + @Nullable String repository) { this.packageName = packageName; this.packageOrg = packageOrg; this.repository = repository; @@ -54,7 +55,7 @@ private PackageDescriptor(PackageOrg packageOrg, private PackageDescriptor(PackageOrg packageOrg, PackageName packageName, PackageVersion packageVersion, - String repository, Boolean isDeprecated, String deprecationMsg) { + @Nullable String repository, Boolean isDeprecated, String deprecationMsg) { this.packageName = packageName; this.packageOrg = packageOrg; this.repository = repository; @@ -69,12 +70,12 @@ public static PackageDescriptor from(PackageOrg packageOrg, PackageName packageN } public static PackageDescriptor from(PackageOrg packageOrg, PackageName packageName, - PackageVersion packageVersion) { + @Nullable PackageVersion packageVersion) { return new PackageDescriptor(packageOrg, packageName, packageVersion, null); } public static PackageDescriptor from(PackageOrg packageOrg, PackageName packageName, - PackageVersion packageVersion, String repository) { + @Nullable PackageVersion packageVersion, @Nullable String repository) { return new PackageDescriptor(packageOrg, packageName, packageVersion, repository); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java index 9c31d3f47e7d..538e73769ba6 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java @@ -24,6 +24,7 @@ import io.ballerina.toml.semantic.ast.TomlTableNode; import io.ballerina.toml.semantic.diagnostics.TomlNodeLocation; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -85,8 +86,8 @@ private PackageManifest(PackageDescriptor packageDesc, } private PackageManifest(PackageDescriptor packageDesc, - CompilerPluginDescriptor compilerPluginDesc, - BalToolDescriptor balToolDesc, + @Nullable CompilerPluginDescriptor compilerPluginDesc, + @Nullable BalToolDescriptor balToolDesc, Map platforms, List dependencies, Map otherEntries, @@ -192,8 +193,8 @@ public static PackageManifest from(PackageDescriptor packageDesc) { } public static PackageManifest from(PackageDescriptor packageDesc, - CompilerPluginDescriptor compilerPluginDesc, - BalToolDescriptor balToolDesc, + @Nullable CompilerPluginDescriptor compilerPluginDesc, + @Nullable BalToolDescriptor balToolDesc, Map platforms, List dependencies) { return new PackageManifest(packageDesc, compilerPluginDesc, balToolDesc, platforms, dependencies, @@ -201,8 +202,8 @@ public static PackageManifest from(PackageDescriptor packageDesc, } public static PackageManifest from(PackageDescriptor packageDesc, - CompilerPluginDescriptor compilerPluginDesc, - BalToolDescriptor balToolDesc, + @Nullable CompilerPluginDescriptor compilerPluginDesc, + @Nullable BalToolDescriptor balToolDesc, Map platforms, List dependencies, Map otherEntries, @@ -224,8 +225,8 @@ public static PackageManifest from(PackageDescriptor packageDesc, } public static PackageManifest from(PackageDescriptor packageDesc, - CompilerPluginDescriptor compilerPluginDesc, - BalToolDescriptor balToolDescriptor, + @Nullable CompilerPluginDescriptor compilerPluginDesc, + @Nullable BalToolDescriptor balToolDescriptor, Map platforms, List dependencies, List license, @@ -348,7 +349,7 @@ public Platform(List> dependencies) { } public Platform(List> dependencies, List> repositories, - Boolean graalvmCompatible) { + @Nullable Boolean graalvmCompatible) { if (dependencies != null) { this.dependencies = Collections.unmodifiableList(dependencies); } else { @@ -374,6 +375,7 @@ public Boolean graalvmCompatible() { return graalvmCompatible; } + @Nullable public Boolean isPlatfromDepsGraalvmCompatible() { Boolean overallGraalvmCompatibility = true; for (Map dependency : dependencies) { @@ -418,7 +420,7 @@ public Dependency(PackageName packageName, PackageOrg packageOrg, PackageVersion } public Dependency(PackageName packageName, PackageOrg packageOrg, PackageVersion version, - String repository, Location location) { + @Nullable String repository, Location location) { this.packageName = packageName; this.packageOrg = packageOrg; this.version = version; @@ -438,6 +440,7 @@ public PackageVersion version() { return version; } + @Nullable public String repository() { return repository; } @@ -461,8 +464,8 @@ public static class Tool { private final Toml optionsToml; private final boolean hasErrorDiagnostic; - public Tool(Field type, Field id, Field filePath, Field targetModule, Toml optionsToml, - TomlTableNode optionsTable, boolean hasErrorDiagnostic) { + public Tool(Field type, Field id, Field filePath, Field targetModule, @Nullable Toml optionsToml, + @Nullable TomlTableNode optionsTable, boolean hasErrorDiagnostic) { this.type = type; this.id = id; this.filePath = filePath; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageName.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageName.java index c8d32269f465..b5781a61d3fb 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageName.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageName.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.util.Objects; /** @@ -32,7 +34,7 @@ private PackageName(String packageNameStr) { this.packageNameStr = packageNameStr; } - public static PackageName from(String packageNameStr) { + public static PackageName from(@Nullable String packageNameStr) { // TODO Check whether the packageName is a valid Ballerina identifier return new PackageName(packageNameStr); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageOrg.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageOrg.java index c5f4d3ec40e2..a0587fce7ff4 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageOrg.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageOrg.java @@ -18,6 +18,7 @@ package io.ballerina.projects; import io.ballerina.projects.util.ProjectConstants; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -37,7 +38,7 @@ private PackageOrg(String packageOrgStr) { this.packageOrgStr = packageOrgStr; } - public static PackageOrg from(String packageNameStr) { + public static PackageOrg from(@Nullable String packageNameStr) { if (BALLERINA_ORG_NAME.equals(packageNameStr)) { return BALLERINA_ORG; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageResolution.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageResolution.java index c59091c276ba..f7eb0d7666b8 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageResolution.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageResolution.java @@ -46,6 +46,7 @@ import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.util.RepoUtils; @@ -622,7 +623,7 @@ private boolean isNewUpdateDistribution(SemanticVersion prevDistributionVersion, && currentDistributionVersion.minor() > prevDistributionVersion.minor(); } - private void addOlderSLUpdateDistributionDiagnostic(SemanticVersion prevDistributionVersion, + private void addOlderSLUpdateDistributionDiagnostic(@Nullable SemanticVersion prevDistributionVersion, SemanticVersion currentDistributionVersion) { String currentVersionForDiagnostic = String.valueOf(currentDistributionVersion.minor()); if (currentDistributionVersion.patch() != 0) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageVersion.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageVersion.java index b9a08c46534c..4ef3ace0aa55 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageVersion.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageVersion.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.util.Objects; import static io.ballerina.projects.util.ProjectConstants.BUILTIN_PACKAGE_VERSION_STR; @@ -39,7 +41,7 @@ private PackageVersion(SemanticVersion version) { this.version = version; } - public static PackageVersion from(String versionString) { + public static PackageVersion from(@Nullable String versionString) { // TODO Check whether the packageOrg is a valid Ballerina identifier return PackageVersion.from(SemanticVersion.from(versionString)); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ResourceConfig.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ResourceConfig.java index a78e095b8614..3e4ca52e8e0c 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ResourceConfig.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ResourceConfig.java @@ -18,6 +18,8 @@ package io.ballerina.projects; +import org.jetbrains.annotations.Nullable; + import java.nio.file.Path; /** @@ -33,7 +35,7 @@ public class ResourceConfig { private final String name; private final byte[] content; - protected ResourceConfig(DocumentId documentId, Path path, String name, byte[] content) { + protected ResourceConfig(DocumentId documentId, @Nullable Path path, String name, byte[] content) { this.documentId = documentId; this.path = path; this.name = name; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Settings.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Settings.java index 8ce563094bf0..cde947680590 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Settings.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Settings.java @@ -24,6 +24,7 @@ import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.text.LinePosition; import io.ballerina.tools.text.LineRange; +import org.jetbrains.annotations.Nullable; import java.util.Collections; @@ -38,7 +39,7 @@ public class Settings { private final Repository[] repositories; private final DiagnosticResult diagnostics; - private Settings(Proxy proxy, Central central, DiagnosticResult diagnostics, Repository[] repositories) { + private Settings(Proxy proxy, Central central, DiagnosticResult diagnostics, @Nullable Repository[] repositories) { this.proxy = proxy; this.central = central; this.diagnostics = diagnostics; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/ModuleLoadRequest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/ModuleLoadRequest.java index 6fa685bb2ade..24bbed340fcb 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/ModuleLoadRequest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/ModuleLoadRequest.java @@ -21,6 +21,7 @@ import io.ballerina.projects.PackageDependencyScope; import io.ballerina.projects.PackageOrg; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.Objects; @@ -50,7 +51,7 @@ public ModuleLoadRequest(PackageOrg orgName, this.locations = Collections.emptySet(); } - public ModuleLoadRequest(PackageOrg orgName, + public ModuleLoadRequest(@Nullable PackageOrg orgName, String moduleName, PackageDependencyScope scope, DependencyResolutionType dependencyResolvedType, @@ -62,7 +63,7 @@ public ModuleLoadRequest(PackageOrg orgName, this.locations = Collections.singleton(location); } - public ModuleLoadRequest(PackageOrg orgName, + public ModuleLoadRequest(@Nullable PackageOrg orgName, String moduleName, PackageDependencyScope scope, DependencyResolutionType dependencyResolvedType, diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/PackageMetadataResponse.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/PackageMetadataResponse.java index fd2392950d29..d3d0bd926f7e 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/PackageMetadataResponse.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/PackageMetadataResponse.java @@ -19,6 +19,7 @@ import io.ballerina.projects.DependencyGraph; import io.ballerina.projects.PackageDescriptor; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -34,8 +35,8 @@ public class PackageMetadataResponse { private final ResolutionResponse.ResolutionStatus resolutionStatus; private PackageMetadataResponse(ResolutionRequest packageLoadRequest, - PackageDescriptor resolvedDescriptor, - DependencyGraph dependencyGraph, + @Nullable PackageDescriptor resolvedDescriptor, + @Nullable DependencyGraph dependencyGraph, ResolutionResponse.ResolutionStatus resolutionStatus) { this.packageLoadRequest = packageLoadRequest; this.packageDescriptor = resolvedDescriptor; @@ -50,7 +51,7 @@ public static PackageMetadataResponse from(ResolutionRequest packageLoadRequest, packageLoadRequest, resolvedDescriptor, dependencyGraph, ResolutionResponse.ResolutionStatus.RESOLVED); } - public static PackageMetadataResponse createUnresolvedResponse(ResolutionRequest packageLoadRequest) { + public static PackageMetadataResponse createUnresolvedResponse(@Nullable ResolutionRequest packageLoadRequest) { return new PackageMetadataResponse( packageLoadRequest, null, null, ResolutionResponse.ResolutionStatus.UNRESOLVED); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/ResolutionResponse.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/ResolutionResponse.java index 77f3486c1ed1..9d3ec3b81cd5 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/ResolutionResponse.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/environment/ResolutionResponse.java @@ -19,6 +19,7 @@ import io.ballerina.projects.Package; import io.ballerina.projects.PackageDescriptor; +import org.jetbrains.annotations.Nullable; /** * {@code ResolutionResponse} is used to return a response to a given {@code PackageLoadRequest}. @@ -43,7 +44,7 @@ private ResolutionResponse(ResolutionStatus resolutionStatus, } public static ResolutionResponse from(ResolutionStatus resolutionStatus, - Package resolvedPackage, + @Nullable Package resolvedPackage, ResolutionRequest resolutionRequest) { return new ResolutionResponse(resolutionStatus, resolvedPackage, resolutionRequest, resolutionRequest.packageDescriptor()); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalToolsManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalToolsManifestBuilder.java index daca246ac75c..b79c5f88a6ec 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalToolsManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalToolsManifestBuilder.java @@ -33,6 +33,7 @@ import io.ballerina.toml.semantic.ast.TopLevelNode; import io.ballerina.toml.validator.TomlValidator; import io.ballerina.toml.validator.schema.Schema; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.HashMap; @@ -159,6 +160,7 @@ private Map>> getTools() return tools; } + @Nullable private String getStringValueFromToolNode(TomlTableNode pkgNode, String key) { TopLevelNode topLevelNode = pkgNode.entries().get(key); if (topLevelNode == null) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalaFiles.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalaFiles.java index 466ba29d1736..ebd8dc71a3cf 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalaFiles.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalaFiles.java @@ -40,6 +40,7 @@ import io.ballerina.projects.internal.model.PackageJson; import io.ballerina.projects.util.ProjectConstants; import io.ballerina.projects.util.ProjectUtils; +import org.jetbrains.annotations.Nullable; import java.io.BufferedReader; import java.io.FileReader; @@ -149,6 +150,7 @@ private static void validatePackageJson(PackageJson packageJson, Path balaPath) } } + @Nullable public static DocumentData loadDocument(Path documentFilePath) { if (Files.notExists(documentFilePath)) { return null; @@ -319,6 +321,7 @@ private static PackageManifest createPackageManifestFromBalaDir(Path balrPath) { return getPackageManifest(packageJson, compilerPluginJson, balToolJson, getDeprecationMsg(balrPath)); } + @Nullable private static String getDeprecationMsg(Path balaPath) { Path deprecateFilePath = balaPath.resolve(DEPRECATED_META_FILE_NAME); if (Files.exists(deprecateFilePath)) { @@ -461,9 +464,9 @@ private static void setBalToolDependencyPaths(BalToolJson balToolJson, Path bala balToolJson.setDependencyPaths(dependencyLibPaths); } - private static PackageManifest getPackageManifest(PackageJson packageJson, - Optional compilerPluginJson, - Optional balToolJson, String deprecationMsg) { + private static PackageManifest getPackageManifest( + PackageJson packageJson, Optional compilerPluginJson, Optional balToolJson, + @Nullable String deprecationMsg) { PackageDescriptor pkgDesc; if (deprecationMsg != null) { pkgDesc = PackageDescriptor.from(PackageOrg.from(packageJson.getOrganization()), diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java index 1ceb0d473c30..117b71e932ba 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java @@ -32,6 +32,7 @@ import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -313,6 +314,7 @@ public boolean isFromCustomRepository() { return (this.repository() != null) && (!REPOSITORY_LOCAL.repositoryName.equals(repository.repositoryName)); } + @Nullable public String repository() { return !REPOSITORY_NOT_SPECIFIED.repositoryName.equals(this.repository.repositoryName) ? this.repository.repositoryName : null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/DependencyManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/DependencyManifestBuilder.java index db383cc6e2fb..a8d06f37b439 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/DependencyManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/DependencyManifestBuilder.java @@ -45,6 +45,7 @@ import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.ArrayList; @@ -99,7 +100,7 @@ private DependencyManifestBuilder(TomlDocument dependenciesToml, } } - public static DependencyManifestBuilder from(TomlDocument dependenciesToml, + public static DependencyManifestBuilder from(@Nullable TomlDocument dependenciesToml, PackageDescriptor packageDescriptor) { return new DependencyManifestBuilder(dependenciesToml, packageDescriptor); } @@ -181,6 +182,7 @@ private void validateDependenciesTomlAgainstSchema(String schemaName) { } } + @Nullable private String getDependenciesTomlVersion() { if (dependenciesToml.isEmpty()) { // When Dependencies.toml does not exists, we consider it is in the latest toml version @@ -204,6 +206,7 @@ private String getDependenciesTomlVersion() { return null; } + @Nullable private SemanticVersion getDistributionVersion() { if (dependenciesToml.isEmpty()) { return null; @@ -395,6 +398,7 @@ private List getPackagesFromOldBallerinaToml() { return packages; } + @Nullable private String getStringValueFromDependencyNode(TomlTableNode pkgNode, String key) { TopLevelNode topLevelNode = pkgNode.entries().get(key); if (topLevelNode == null) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ImportModuleResponse.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ImportModuleResponse.java index ef418e774ae4..3e0598755592 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ImportModuleResponse.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ImportModuleResponse.java @@ -19,6 +19,7 @@ import io.ballerina.projects.PackageDescriptor; import io.ballerina.projects.environment.ResolutionResponse; +import org.jetbrains.annotations.Nullable; /** * Represents a resolved imported module. @@ -31,7 +32,7 @@ public class ImportModuleResponse { private final ImportModuleRequest importModuleRequest; private final ResolutionResponse.ResolutionStatus resolutionStatus; - private ImportModuleResponse(PackageDescriptor packageDescriptor, + private ImportModuleResponse(@Nullable PackageDescriptor packageDescriptor, ImportModuleRequest importModuleRequest, ResolutionResponse.ResolutionStatus status) { this.packageDescriptor = packageDescriptor; @@ -59,6 +60,7 @@ public ImportModuleRequest importModuleRequest() { return importModuleRequest; } + @Nullable public PackageDescriptor packageDescriptor() { return packageDescriptor; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index adb0c4068395..e6e82572c782 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -52,6 +52,7 @@ import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import org.ballerinalang.compiler.CompilerOptionName; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.nio.file.Files; @@ -135,9 +136,9 @@ private ManifestBuilder(TomlDocument ballerinaToml, this.buildOptions = parseBuildOptions(); } - public static ManifestBuilder from(TomlDocument ballerinaToml, - TomlDocument compilerPluginToml, - TomlDocument balToolToml, + public static ManifestBuilder from(@Nullable TomlDocument ballerinaToml, + @Nullable TomlDocument compilerPluginToml, + @Nullable TomlDocument balToolToml, Path projectPath) { return new ManifestBuilder(ballerinaToml, compilerPluginToml, balToolToml, projectPath); } @@ -448,6 +449,7 @@ private void validateIconPathForPng(String icon, TomlTableNode pkgNode) { } } + @Nullable private BuildOptions parseBuildOptions() { TomlTableNode tomlTableNode = ballerinaToml.toml().rootNode(); return setBuildOptions(tomlTableNode); @@ -513,6 +515,7 @@ private Map getPlatforms(TopLevelNode platform return platforms; } + @Nullable private PackageManifest.Platform getRepositoryPlatform(TopLevelNode dependencyNode) { PackageManifest.Platform platform = null; if (dependencyNode.kind() == TomlType.TABLE_ARRAY) { @@ -540,6 +543,7 @@ private PackageManifest.Platform getRepositoryPlatform(TopLevelNode dependencyNo return platform; } + @Nullable private PackageManifest.Platform getDependencyPlatform(TopLevelNode dependencyNode) { PackageManifest.Platform platform = null; if (dependencyNode.kind() == TomlType.TABLE_ARRAY) { @@ -591,6 +595,7 @@ private PackageManifest.Platform getDependencyPlatform(TopLevelNode dependencyNo return platform; } + @Nullable private PackageManifest.Platform getGraalvmCompatibilityPlatform(TopLevelNode graalvmCompatibleNode) { if (graalvmCompatibleNode.kind() == TomlType.KEY_VALUE) { TomlKeyValueNode keyValueNode = ((TomlKeyValueNode) graalvmCompatibleNode); @@ -656,6 +661,7 @@ private void reportDiagnostic(TopLevelNode tomlTableNode, tomlTableNode.addDiagnostic(tomlDiagnostic); } + @Nullable private BuildOptions setBuildOptions(TomlTableNode tomlTableNode) { TopLevelNode topLevelBuildOptionsNode = tomlTableNode.entries().get("build-options"); if (topLevelBuildOptionsNode == null || topLevelBuildOptionsNode.kind() != TomlType.TABLE) { @@ -724,6 +730,7 @@ private BuildOptions setBuildOptions(TomlTableNode tomlTableNode) { return buildOptionsBuilder.build(); } + @Nullable private Boolean getBooleanFromBuildOptionsTableNode(TomlTableNode tableNode, String key) { TopLevelNode topLevelNode = tableNode.entries().get(key); if (topLevelNode == null || topLevelNode.kind() == TomlType.NONE) { @@ -741,6 +748,7 @@ private Boolean getBooleanFromBuildOptionsTableNode(TomlTableNode tableNode, Str return null; } + @Nullable private String getStringFromBuildOptionsTableNode(TomlTableNode tableNode, String key) { TopLevelNode topLevelNode = tableNode.entries().get(key); if (topLevelNode == null || topLevelNode.kind() == TomlType.NONE) { @@ -792,6 +800,7 @@ private boolean getTrueFromBuildOptionsTableNode(TomlTableNode tableNode, String return true; } + @Nullable public static String getStringValueFromTomlTableNode(TomlTableNode tomlTableNode, String key) { TopLevelNode topLevelNode = tomlTableNode.entries().get(key); if (topLevelNode == null || topLevelNode.kind() == TomlType.NONE) { @@ -835,6 +844,7 @@ private List getStringArrayFromPackageNode(TomlTableNode pkgNode, String return elements; } + @Nullable private String getStringValueFromPlatformEntry(TomlTableNode pkgNode, String key) { TopLevelNode topLevelNode = pkgNode.entries().get(key); if (topLevelNode == null || topLevelNode.kind() == TomlType.NONE) { @@ -843,6 +853,7 @@ private String getStringValueFromPlatformEntry(TomlTableNode pkgNode, String key return getStringFromTomlTableNode(topLevelNode); } + @Nullable private Boolean getBooleanValueFromPlatformEntry(TomlTableNode pkgNode, String key) { TopLevelNode topLevelNode = pkgNode.entries().get(key); if (topLevelNode == null || topLevelNode.kind() == TomlType.NONE) { @@ -851,6 +862,7 @@ private Boolean getBooleanValueFromPlatformEntry(TomlTableNode pkgNode, String k return getBooleanFromTomlTableNode(topLevelNode); } + @Nullable private String getStringValueFromDependencyNode(TomlTableNode pkgNode, String key) { TopLevelNode topLevelNode = pkgNode.entries().get(key); if (topLevelNode == null) { @@ -893,6 +905,7 @@ private PackageManifest.Tool.Field getValueFromPreBuildToolNode(TomlTableNode to return new PackageManifest.Tool.Field(null, toolNode.location()); } + @Nullable private Toml getToml(TomlTableNode toolNode, String key) { TopLevelNode topLevelNode = toolNode.entries().get(key); if (topLevelNode == null) { @@ -905,7 +918,8 @@ private Toml getToml(TomlTableNode toolNode, String key) { return new Toml(optionsNode); } - private boolean providedPlatformDependencyIsValid(String artifactId, String groupId, String version) { + private boolean providedPlatformDependencyIsValid( + @Nullable String artifactId, @Nullable String groupId, @Nullable String version) { return artifactId != null && !artifactId.isEmpty() && groupId != null && !groupId.isEmpty() && version != null && !version.isEmpty(); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestUtils.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestUtils.java index e72747296f28..deeaf4e4c325 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestUtils.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestUtils.java @@ -27,6 +27,7 @@ import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.text.LinePosition; import io.ballerina.tools.text.LineRange; +import org.jetbrains.annotations.Nullable; /** * Utilities for creating manifests. @@ -50,6 +51,7 @@ static String convertDiagnosticToString(Diagnostic diagnostic) { oneBasedLineRange.fileName() + ":" + oneBasedLineRange + "] " + diagnostic.message(); } + @Nullable public static String getStringFromTomlTableNode(TopLevelNode topLevelNode) { if (topLevelNode.kind() != null && topLevelNode.kind() == TomlType.KEY_VALUE) { TomlKeyValueNode keyValueNode = (TomlKeyValueNode) topLevelNode; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleData.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleData.java index 4829807c6ffd..3387a97dce81 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleData.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleData.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects.internal; +import org.jetbrains.annotations.Nullable; + import java.nio.file.Path; import java.util.List; import java.util.Optional; @@ -52,7 +54,7 @@ public static ModuleData from(Path path, String moduleName, List srcDocuments, List testSrcDocuments, - DocumentData moduleMd) { + @Nullable DocumentData moduleMd) { return new ModuleData(path, moduleName, srcDocuments, testSrcDocuments, moduleMd); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleResolver.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleResolver.java index 4c0d610cfd9e..1046fbd660eb 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleResolver.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleResolver.java @@ -29,6 +29,7 @@ import io.ballerina.projects.environment.ResolutionResponse; import io.ballerina.projects.util.ProjectConstants; import io.ballerina.projects.util.ProjectUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -227,6 +228,7 @@ private void resolveModuleLoadRequest(ModuleLoadRequest moduleLoadRequest, responseMap.put(importModuleRequest, new ImportModuleResponse(pkgDesc, importModuleRequest)); } + @Nullable private PackageDescriptor findHierarchicalModule(String moduleName, PackageOrg packageOrg, Collection possiblePkgNames) { @@ -248,6 +250,7 @@ private PackageDescriptor findHierarchicalModule(String moduleName, * @param packageName Possible package name * @return PackageDescriptor or null */ + @Nullable private PackageDescriptor findHierarchicalModule(String moduleName, PackageOrg packageOrg, PackageName packageName) { @@ -259,6 +262,7 @@ private PackageDescriptor findHierarchicalModule(String moduleName, return findModuleInBlendedManifest(moduleName, packageOrg, packageName); } + @Nullable private PackageDescriptor findModuleInRootPackage(String moduleName, PackageOrg packageOrg, PackageName packageName) { @@ -277,6 +281,7 @@ private boolean isRootPackage(PackageOrg pkgOrg, PackageName pkgName) { pkgName.equals(rootPkgDesc.name()); } + @Nullable private PackageDescriptor findModuleInBlendedManifest(String moduleName, PackageOrg packageOrg, PackageName packageName) { @@ -296,7 +301,7 @@ private PackageOrg getPackageOrg(ModuleLoadRequest moduleLoadRequest) { private PackageDescriptor createPkgDesc(PackageOrg packageOrg, PackageName packageName, - BlendedManifest.Dependency blendedDep) { + @Nullable BlendedManifest.Dependency blendedDep) { if (blendedDep != null && blendedDep.isFromLocalRepository()) { return PackageDescriptor.from(packageOrg, packageName, blendedDep.version(), ProjectConstants.LOCAL_REPOSITORY_NAME); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageConfigCreator.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageConfigCreator.java index b9b527f00681..71ecf2a540a7 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageConfigCreator.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageConfigCreator.java @@ -36,6 +36,7 @@ import io.ballerina.projects.ResourceConfig; import io.ballerina.projects.TomlDocument; import io.ballerina.projects.util.ProjectConstants; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.ArrayList; @@ -254,7 +255,7 @@ private static List getDocumentConfigs(ModuleId moduleId, List otherModules, - DocumentData ballerinaToml, - DocumentData dependenciesToml, - DocumentData cloudToml, - DocumentData compilerPluginToml, - DocumentData balToolToml, - DocumentData packageMd, + @Nullable DocumentData ballerinaToml, + @Nullable DocumentData dependenciesToml, + @Nullable DocumentData cloudToml, + @Nullable DocumentData compilerPluginToml, + @Nullable DocumentData balToolToml, + @Nullable DocumentData packageMd, List resources, List testResources) { return new PackageData(packagePath, defaultModule, otherModules, DependencyGraph.emptyGraph(), diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDependencyGraphBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDependencyGraphBuilder.java index 5677f676cbe9..22aeef1518f2 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDependencyGraphBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDependencyGraphBuilder.java @@ -32,6 +32,7 @@ import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -384,6 +385,7 @@ private NodeStatus getNodeStatus(Vertex vertex, } } + @Nullable private PackageDescriptor handleDependencyConflict(DependencyNode newPkgDep, DependencyNode existingPkgDep) { PackageDescriptor newPkgDesc = newPkgDep.pkgDesc(); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectFiles.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectFiles.java index 088ea516029d..3ee29d83db94 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectFiles.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectFiles.java @@ -25,6 +25,7 @@ import io.ballerina.projects.exceptions.InvalidBalaException; import io.ballerina.projects.util.ProjectConstants; import io.ballerina.projects.util.ProjectUtils; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -297,6 +298,7 @@ private static List loadTestDocuments(Path dirPath) { } } + @Nullable public static DocumentData loadDocument(Path documentFilePath) { if (Files.notExists(documentFilePath)) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProvidedResourceConfig.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProvidedResourceConfig.java index bf499d3df630..84e2aa2b82a4 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProvidedResourceConfig.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProvidedResourceConfig.java @@ -21,6 +21,7 @@ import io.ballerina.projects.DocumentId; import io.ballerina.projects.ResourceConfig; import io.ballerina.projects.util.ProjectConstants; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.Locale; @@ -39,7 +40,7 @@ public class ProvidedResourceConfig extends ResourceConfig { public static final String OS = System.getProperty("os.name").toLowerCase(Locale.getDefault()); - private ProvidedResourceConfig(DocumentId documentId, Path path, String name, byte[] content) { + private ProvidedResourceConfig(DocumentId documentId, Path path, String name, @Nullable byte[] content) { super(documentId, path, name, content); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ResolutionEngine.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ResolutionEngine.java index 73713023da59..cdd168a0cef8 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ResolutionEngine.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ResolutionEngine.java @@ -36,6 +36,7 @@ import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -351,8 +352,9 @@ private void addErrorNodesToGraph(List errorNodes) { * @param blendedDep the dependency recorded in either Dependencies.toml or Ballerina.toml * @return ResolutionRequest resolution request for the unresolved node */ + @Nullable private ResolutionRequest getRequestForUnresolvedNode(DependencyNode unresolvedNode, - BlendedManifest.Dependency blendedDep) { + @Nullable BlendedManifest.Dependency blendedDep) { if (blendedDep == null) { return ResolutionRequest.from(unresolvedNode.pkgDesc(), unresolvedNode.scope(), unresolvedNode.resolutionType(), resolutionOptions.packageLockingMode()); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/SettingsBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/SettingsBuilder.java index fefc484a176a..dba214ee1c2e 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/SettingsBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/SettingsBuilder.java @@ -36,6 +36,7 @@ import io.ballerina.toml.validator.TomlValidator; import io.ballerina.toml.validator.schema.Schema; import io.ballerina.tools.diagnostics.Diagnostic; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.ArrayList; @@ -207,6 +208,7 @@ private int getIntValueFromProxyNode(TomlTableNode pkgNode, String key, int defa return value; } + @Nullable private String getStringFromTomlTableNode(TopLevelNode topLevelNode) { if (topLevelNode.kind() == TomlType.KEY_VALUE) { TomlKeyValueNode keyValueNode = (TomlKeyValueNode) topLevelNode; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/bala/adaptors/JsonCollectionsAdaptor.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/bala/adaptors/JsonCollectionsAdaptor.java index 45ec2e5391be..b8af35b995ac 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/bala/adaptors/JsonCollectionsAdaptor.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/bala/adaptors/JsonCollectionsAdaptor.java @@ -22,6 +22,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Type; import java.util.Collection; @@ -33,6 +34,7 @@ */ public class JsonCollectionsAdaptor implements JsonSerializer> { + @Nullable @Override public JsonElement serialize(Collection src, Type typeOfSrc, JsonSerializationContext context) { if (src == null || src.isEmpty()) { // exclusion is made here diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/bala/adaptors/JsonStringsAdaptor.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/bala/adaptors/JsonStringsAdaptor.java index 77b91dbb3fa7..db885e516043 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/bala/adaptors/JsonStringsAdaptor.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/bala/adaptors/JsonStringsAdaptor.java @@ -22,6 +22,7 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Type; @@ -32,6 +33,7 @@ */ public class JsonStringsAdaptor implements JsonSerializer { + @Nullable @Override public JsonElement serialize(String src, Type typeOfSrc, JsonSerializationContext context) { if (src == null || src.isEmpty()) { // exclusion is made here diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java index 17cdd218c171..8a65b8b65c41 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java @@ -19,6 +19,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -60,6 +61,7 @@ public class TypeConverter { // Stores already visited complex types against the type name private final Map visitedTypeMap = new HashMap<>(); + @Nullable private VisitedType getVisitedType(String typeName) { if (visitedTypeMap.containsKey(typeName)) { return visitedTypeMap.get(typeName); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/BalToolDescriptor.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/BalToolDescriptor.java index b2c6b8003158..bbbdf2a01113 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/BalToolDescriptor.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/BalToolDescriptor.java @@ -26,6 +26,7 @@ import io.ballerina.toml.semantic.ast.TomlTableNode; import io.ballerina.toml.semantic.ast.TomlValueNode; import io.ballerina.toml.semantic.ast.TopLevelNode; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.nio.file.FileSystems; @@ -52,7 +53,7 @@ public class BalToolDescriptor { private final BalToolDescriptor.Tool tool; private final List dependencies; - private BalToolDescriptor(BalToolDescriptor.Tool tool, List dependencies) { + private BalToolDescriptor(@Nullable BalToolDescriptor.Tool tool, List dependencies) { this.tool = tool; this.dependencies = dependencies; } @@ -96,7 +97,7 @@ public List getBalToolDependencies() { public static class Tool { private String id; - Tool(String id) { + Tool(@Nullable String id) { this.id = id; } @@ -152,6 +153,7 @@ private static List getDependencies(TomlTableNode return dependencies; } + @Nullable private static String getToolID(TomlTableNode tomlTableNode) { TomlTableNode toolNode = (TomlTableNode) tomlTableNode.entries().get(TOOL); if (toolNode != null && toolNode.kind() != TomlType.NONE && toolNode.kind() == TomlType.TABLE) { @@ -163,6 +165,7 @@ private static String getToolID(TomlTableNode tomlTableNode) { return null; } + @Nullable private static String getStringFromTomlTableNode(TopLevelNode topLevelNode) { if (topLevelNode != null && topLevelNode.kind() == TomlType.KEY_VALUE) { TomlKeyValueNode keyValueNode = (TomlKeyValueNode) topLevelNode; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/BuildJson.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/BuildJson.java index 7eb69982bd39..c82387cc02c6 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/BuildJson.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/BuildJson.java @@ -19,6 +19,7 @@ package io.ballerina.projects.internal.model; import com.google.gson.annotations.SerializedName; +import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -77,7 +78,7 @@ public String distributionVersion() { return distributionVersion; } - public void setDistributionVersion(String distributionVersion) { + public void setDistributionVersion(@Nullable String distributionVersion) { this.distributionVersion = distributionVersion; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/CompilerPluginDescriptor.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/CompilerPluginDescriptor.java index 693990b375c6..82dfe0ab6b78 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/CompilerPluginDescriptor.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/CompilerPluginDescriptor.java @@ -26,6 +26,7 @@ import io.ballerina.toml.semantic.ast.TomlTableNode; import io.ballerina.toml.semantic.ast.TomlValueNode; import io.ballerina.toml.semantic.ast.TopLevelNode; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -43,7 +44,7 @@ public class CompilerPluginDescriptor { private final Plugin plugin; private final List dependencies; - private CompilerPluginDescriptor(Plugin plugin, List dependencies) { + private CompilerPluginDescriptor(@Nullable Plugin plugin, List dependencies) { this.plugin = plugin; this.dependencies = dependencies; } @@ -89,7 +90,7 @@ public static class Plugin { private String id; private String className; - Plugin(String id, String className) { + Plugin(@Nullable String id, @Nullable String className) { this.id = id; this.className = className; } @@ -145,6 +146,7 @@ private static List getDependencies(TomlTableNode tomlTableNode) { return dependencies; } + @Nullable private static String getPluginID(TomlTableNode tomlTableNode) { TomlTableNode pluginNode = (TomlTableNode) tomlTableNode.entries().get("plugin"); if (pluginNode != null && pluginNode.kind() != TomlType.NONE && pluginNode.kind() == TomlType.TABLE) { @@ -156,6 +158,7 @@ private static String getPluginID(TomlTableNode tomlTableNode) { return null; } + @Nullable private static String getPluginClass(TomlTableNode tomlTableNode) { TomlTableNode pluginNode = (TomlTableNode) tomlTableNode.entries().get("plugin"); if (pluginNode != null && pluginNode.kind() != TomlType.NONE && pluginNode.kind() == TomlType.TABLE) { @@ -167,6 +170,7 @@ private static String getPluginClass(TomlTableNode tomlTableNode) { return null; } + @Nullable private static String getStringFromTomlTableNode(TopLevelNode topLevelNode) { if (topLevelNode != null && topLevelNode.kind() == TomlType.KEY_VALUE) { TomlKeyValueNode keyValueNode = (TomlKeyValueNode) topLevelNode; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/adaptors/JsonCollectionsAdaptor.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/adaptors/JsonCollectionsAdaptor.java index 7cb5481b538d..34a5a8fa70a0 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/adaptors/JsonCollectionsAdaptor.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/adaptors/JsonCollectionsAdaptor.java @@ -22,6 +22,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Type; import java.util.Collection; @@ -33,6 +34,7 @@ */ public class JsonCollectionsAdaptor implements JsonSerializer> { + @Nullable @Override public JsonElement serialize(Collection src, Type typeOfSrc, JsonSerializationContext context) { if (src == null || src.isEmpty()) { // exclusion is made here diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/adaptors/JsonStringsAdaptor.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/adaptors/JsonStringsAdaptor.java index 77bc5da8bb5a..b3aadd7bec95 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/adaptors/JsonStringsAdaptor.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/model/adaptors/JsonStringsAdaptor.java @@ -22,6 +22,7 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Type; @@ -32,6 +33,7 @@ */ public class JsonStringsAdaptor implements JsonSerializer { + @Nullable @Override public JsonElement serialize(String src, Type typeOfSrc, JsonSerializationContext context) { if (src == null || src.isEmpty()) { // exclusion is made here diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/AbstractPackageRepository.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/AbstractPackageRepository.java index f9c59655922a..753029ca4b35 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/AbstractPackageRepository.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/AbstractPackageRepository.java @@ -32,6 +32,7 @@ import io.ballerina.projects.internal.ImportModuleRequest; import io.ballerina.projects.internal.ImportModuleResponse; import io.ballerina.projects.util.ProjectUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -78,7 +79,7 @@ public Collection getPackageNames(Collection getPackageVersions(PackageOrg org, PackageName name, - PackageVersion version); + @Nullable PackageVersion version); protected abstract DependencyGraph getDependencyGraph(PackageOrg org, PackageName name, @@ -145,6 +146,7 @@ private ImportModuleResponse getImportModuleLoadResponse(ImportModuleRequest imp return ImportModuleResponse.createUnresolvedResponse(importModuleRequest); } + @Nullable private ImportModuleResponse getImportModuleResponse(ImportModuleRequest importModuleRequest, PackageName packageName, List packageVersions) { @@ -183,6 +185,7 @@ private PackageMetadataResponse createMetadataResponse(ResolutionRequest resolut return PackageMetadataResponse.from(resolutionRequest, resolvedDescriptor, dependencyGraph); } + @Nullable protected PackageVersion findLatest(List packageVersions) { if (packageVersions.isEmpty()) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/FileSystemRepository.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/FileSystemRepository.java index 79a236328616..42b334fe5e9f 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/FileSystemRepository.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/FileSystemRepository.java @@ -39,6 +39,7 @@ import io.ballerina.projects.util.FileUtils; import io.ballerina.projects.util.ProjectConstants; import io.ballerina.projects.util.ProjectUtils; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.util.RepoUtils; import java.io.File; @@ -207,7 +208,8 @@ public Map> getPackages() { } @Override - protected List getPackageVersions(PackageOrg org, PackageName name, PackageVersion version) { + protected List getPackageVersions(PackageOrg org, PackageName name, + @Nullable PackageVersion version) { List versions = new ArrayList<>(); try { Path balaPackagePath = bala.resolve(org.value()).resolve(name.value()); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/MavenPackageRepository.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/MavenPackageRepository.java index 638fce6e91df..c891456a0574 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/MavenPackageRepository.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/MavenPackageRepository.java @@ -36,6 +36,7 @@ import org.apache.commons.io.FileUtils; import org.ballerinalang.maven.bala.client.MavenResolverClient; import org.ballerinalang.maven.bala.client.MavenResolverClientException; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.util.RepoUtils; import java.io.BufferedReader; @@ -66,7 +67,7 @@ public class MavenPackageRepository extends AbstractPackageRepository { public MavenPackageRepository(Environment environment, Path cacheDirectory, String distributionVersion, - MavenResolverClient client, String repoLocation) { + @Nullable MavenResolverClient client, @Nullable String repoLocation) { this.fileSystemCache = new FileSystemRepository(environment, cacheDirectory, distributionVersion); this.client = client; this.repoLocation = repoLocation; @@ -130,7 +131,7 @@ public boolean isPackageExists(PackageOrg org, // This method should be called before calling other methods public boolean isPackageExists(PackageOrg org, PackageName name, - PackageVersion version, boolean offline) { + @Nullable PackageVersion version, boolean offline) { boolean isPackageExist = this.fileSystemCache.isPackageExists(org, name, version); if (!isPackageExist && !offline) { return getPackageFromRemoteRepo(org.value(), name.value(), version.value().toString()); @@ -139,7 +140,8 @@ public boolean isPackageExists(PackageOrg org, } @Override - protected List getPackageVersions(PackageOrg org, PackageName name, PackageVersion version) { + protected List getPackageVersions( + PackageOrg org, PackageName name, @Nullable PackageVersion version) { if (version == null) { return Collections.emptyList(); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/plugins/codeaction/CodeActionExecutionContextImpl.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/plugins/codeaction/CodeActionExecutionContextImpl.java index fd98c7959a84..26a0a9b51a2c 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/plugins/codeaction/CodeActionExecutionContextImpl.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/plugins/codeaction/CodeActionExecutionContextImpl.java @@ -18,6 +18,7 @@ import io.ballerina.compiler.api.SemanticModel; import io.ballerina.projects.Document; import io.ballerina.tools.text.LinePosition; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.List; @@ -43,9 +44,9 @@ public List arguments() { return this.arguments; } - public static CodeActionExecutionContextImpl from(String fileUri, Path filePath, LinePosition cursorPosition, - Document document, SemanticModel semanticModel, - List arguments) { + public static CodeActionExecutionContextImpl from( + String fileUri, Path filePath, @Nullable LinePosition cursorPosition, Document document, + SemanticModel semanticModel, List arguments) { return new CodeActionExecutionContextImpl(fileUri, filePath, cursorPosition, document, semanticModel, arguments); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/BuildToolUtils.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/BuildToolUtils.java index 0d68e70e11e6..6feed819518d 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/BuildToolUtils.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/BuildToolUtils.java @@ -34,6 +34,7 @@ import io.ballerina.tools.diagnostics.DiagnosticCode; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.util.RepoUtils; import java.io.IOException; @@ -82,7 +83,8 @@ public static TomlDiagnostic getBuildToolCommandNotFoundDiagnostic(String comman * @param toolId tool id of the build tool * @return diagnostic */ - public static TomlDiagnostic getCannotResolveBuildToolDiagnostic(String toolId, TomlNodeLocation location) { + public static TomlDiagnostic getCannotResolveBuildToolDiagnostic(String toolId, + @Nullable TomlNodeLocation location) { String message = "Build tool '" + toolId + "' cannot be resolved"; DiagnosticInfo diagnosticInfo = new DiagnosticInfo( ProjectDiagnosticErrorCode.BUILD_TOOL_NOT_FOUND.diagnosticId(), @@ -258,6 +260,7 @@ public static Path getCentralBalaDirPath() { * @param toolEntries tool entries in Ballerina.toml * @return location of the first tool entry */ + @Nullable public static TomlNodeLocation getFirstToolEntryLocation(String toolId, List toolEntries) { for (PackageManifest.Tool toolEntry : toolEntries) { if (toolEntry.type().value().equals(toolId)) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/FileUtils.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/FileUtils.java index 4ee6c4eaa9ce..6853d679ed2a 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/FileUtils.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/FileUtils.java @@ -17,6 +17,8 @@ */ package io.ballerina.projects.util; +import org.jetbrains.annotations.Nullable; + import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -72,6 +74,7 @@ private FileUtils() { * @param filePath Path of the file. * @return File name without extension. */ + @Nullable public static String getFileNameWithoutExtension(String filePath) { Path fileName = Path.of(filePath).getFileName(); if (null != fileName) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectUtils.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectUtils.java index da43638ffb7d..4cc9cdf9f062 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectUtils.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectUtils.java @@ -57,6 +57,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.apache.commons.compress.archivers.zip.ZipFile; import org.ballerinalang.compiler.BLangCompilerException; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.util.Lists; import org.wso2.ballerinalang.util.RepoUtils; @@ -328,6 +329,7 @@ public static String getValidateUnderscoreError(String name, String packageOrMod * @param filePath project path * @return project root */ + @Nullable public static Path findProjectRoot(Path filePath) { if (filePath != null) { filePath = filePath.toAbsolutePath().normalize(); @@ -449,7 +451,7 @@ public static String getBalaName(PackageManifest pkgDesc) { ); } - public static String getBalaName(String org, String pkgName, String version, String platform) { + public static String getBalaName(String org, String pkgName, String version, @Nullable String platform) { // ---.bala if (platform == null || platform.isEmpty()) { platform = "any"; @@ -466,7 +468,7 @@ public static String getBalaName(String org, String pkgName, String version, Str * @param platform version, null converts to `any` * @return relative bala path */ - public static Path getRelativeBalaPath(String org, String pkgName, String version, String platform) { + public static Path getRelativeBalaPath(String org, String pkgName, String version, @Nullable String platform) { // ---.bala if (platform == null || platform.isEmpty()) { platform = "any"; @@ -634,6 +636,7 @@ private static boolean isCopiedOrExcludedEntry(String entryName, HashSet * @param module Module instance * @return the name of the thin jar */ + @Nullable public static String getJarFileName(Module module) { String jarName; if (module.packageInstance().manifest().org().anonymous()) { @@ -706,6 +709,7 @@ public static boolean isModuleExist(Path projectPath, String moduleName) { * @param proxy toml model proxy * @return proxy */ + @Nullable public static Proxy initializeProxy(io.ballerina.projects.internal.model.Proxy proxy) { if (proxy != null && !"".equals(proxy.host()) && proxy.port() > 0) { InetSocketAddress proxyInet = new InetSocketAddress(proxy.host(), proxy.port()); @@ -844,7 +848,7 @@ public static String getDependenciesTomlContent(List pkgDependencies } private static void addDependencyContent(StringBuilder content, String org, String name, String version, - String scope, List dependencies, + @Nullable String scope, List dependencies, List modules) { content.append("[[package]]\n"); content.append("org = \"").append(org).append("\"\n"); @@ -909,6 +913,7 @@ private static void addToolDependencyContent( content.append("version = \"").append(version).append("\"\n"); } + @Nullable private static String getDependencyScope(PackageDependencyScope scope) { if (scope == PackageDependencyScope.TEST_ONLY) { return "testOnly"; @@ -1338,7 +1343,7 @@ public static boolean getSticky(Project project) { * @return compatible versions */ public static List getVersionsInCompatibleRange( - SemanticVersion minVersion, + @Nullable SemanticVersion minVersion, List versions, CompatibleRange compatibleRange) { if (compatibleRange.equals(CompatibleRange.LATEST)) { @@ -1365,7 +1370,8 @@ public static List getVersionsInCompatibleRange( * @param packageLockingMode locking mode of the project * @return compatible range */ - public static CompatibleRange getCompatibleRange(SemanticVersion version, PackageLockingMode packageLockingMode) { + public static CompatibleRange getCompatibleRange(@Nullable SemanticVersion version, + PackageLockingMode packageLockingMode) { if (version == null) { return CompatibleRange.LATEST; } diff --git a/compiler/ballerina-lang/src/main/java/module-info.java b/compiler/ballerina-lang/src/main/java/module-info.java index bf773acd7296..e838672e67f0 100644 --- a/compiler/ballerina-lang/src/main/java/module-info.java +++ b/compiler/ballerina-lang/src/main/java/module-info.java @@ -19,6 +19,7 @@ requires io.ballerina.identifier; requires java.semver; requires maven.resolver; + requires static org.jetbrains.annotations; exports io.ballerina.compiler.api; exports io.ballerina.compiler.api.symbols; exports io.ballerina.compiler.api.symbols.resourcepath; diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/AttachPoint.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/AttachPoint.java index 7a891256c294..d19f54b89276 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/AttachPoint.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/AttachPoint.java @@ -17,6 +17,8 @@ */ package org.ballerinalang.model.elements; +import org.jetbrains.annotations.Nullable; + /** * {@code AttachPoint} represents annotation attach point in ballerina. * @@ -127,6 +129,7 @@ private AttachPoint(Point point, boolean source) { this.source = source; } + @Nullable public static AttachPoint getAttachmentPoint(String value, boolean source) { for (Point point : Point.values()) { if (point.value.equals(value)) { diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/MarkdownDocAttachment.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/MarkdownDocAttachment.java index 43a9293905da..287e2f193765 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/MarkdownDocAttachment.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/MarkdownDocAttachment.java @@ -18,6 +18,8 @@ package org.ballerinalang.model.elements; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.List; @@ -28,9 +30,12 @@ */ public class MarkdownDocAttachment { + @Nullable public String description; public List parameters; + @Nullable public String returnValueDescription; + @Nullable public String deprecatedDocumentation; public List deprecatedParams; @@ -47,7 +52,7 @@ public static class Parameter { public String name; public String description; - public Parameter(String name, String description) { + public Parameter(@Nullable String name, @Nullable String description) { this.name = name; this.description = description; } diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/PackageID.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/PackageID.java index 3c2f49be0890..711617db0154 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/PackageID.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/elements/PackageID.java @@ -17,6 +17,7 @@ */ package org.ballerinalang.model.elements; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Name; import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.util.Lists; @@ -109,7 +110,7 @@ public class PackageID { public Name sourceFileName = null; public String sourceRoot = null; - public PackageID(Name orgName, List nameComps, Name version) { + public PackageID(@Nullable Name orgName, List nameComps, Name version) { this.orgName = orgName; this.nameComps = nameComps; this.name = new Name( @@ -121,7 +122,7 @@ public PackageID(Name orgName, List nameComps, Name version) { this.version = version; } - public PackageID(Name orgName, Name pkgName, Name name, Name version, Name sourceFileName) { + public PackageID(Name orgName, Name pkgName, Name name, Name version, @Nullable Name sourceFileName) { this.orgName = orgName; this.name = name; this.pkgName = pkgName; @@ -144,7 +145,7 @@ public PackageID(Name orgName, Name name, Name version, Name sourceFileName) { this.sourceFileName = sourceFileName; } - public PackageID(Name orgName, Name pkgName, Name name, Name version, Name sourceFileName, + public PackageID(Name orgName, Name pkgName, Name name, Name version, @Nullable Name sourceFileName, boolean isTestPkg, boolean skipTest) { this.orgName = orgName; this.name = name; diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/tree/OperatorKind.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/tree/OperatorKind.java index ce77150bc3fe..74470a3a0668 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/tree/OperatorKind.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/model/tree/OperatorKind.java @@ -17,6 +17,8 @@ */ package org.ballerinalang.model.tree; +import org.jetbrains.annotations.Nullable; + /** * Binary and Unary Operator Kind. * @@ -77,6 +79,7 @@ public String toString() { return opValue; } + @Nullable public static OperatorKind valueFrom(String opValue) { for (OperatorKind operatorKind : OperatorKind.values()) { if (operatorKind.opValue.equals(opValue)) { diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/AggregatedPackageRepository.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/AggregatedPackageRepository.java index 51c8f4f76572..781063e16c4a 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/AggregatedPackageRepository.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/AggregatedPackageRepository.java @@ -18,6 +18,7 @@ package org.ballerinalang.repository; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.LinkedHashSet; @@ -44,6 +45,7 @@ public List getRepositories() { return repos; } + @Nullable @Override public PackageEntity loadPackage(PackageID pkgId) { PackageEntity result = null; @@ -56,6 +58,7 @@ public PackageEntity loadPackage(PackageID pkgId) { return result; } + @Nullable @Override public PackageEntity loadPackage(PackageID pkgId, String entryName) { PackageEntity result = null; diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/HierarchicalPackageRepository.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/HierarchicalPackageRepository.java index 57fe121e415a..deb99da82cc3 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/HierarchicalPackageRepository.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/HierarchicalPackageRepository.java @@ -18,6 +18,7 @@ package org.ballerinalang.repository; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import java.util.LinkedHashSet; import java.util.Set; @@ -50,6 +51,7 @@ public HierarchicalPackageRepository(PackageRepository systemRepo, PackageReposi public abstract Set lookupPackageIDs(int maxDepth); + @Nullable @Override public PackageEntity loadPackage(PackageID pkgId) { PackageEntity result = null; @@ -68,6 +70,7 @@ public PackageEntity loadPackage(PackageID pkgId) { return result; } + @Nullable @Override public PackageEntity loadPackage(PackageID pkgId, String entryName) { PackageEntity result = null; diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/fs/GeneralFSPackageRepository.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/fs/GeneralFSPackageRepository.java index 102347a2794e..815c520b971d 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/fs/GeneralFSPackageRepository.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/fs/GeneralFSPackageRepository.java @@ -24,6 +24,7 @@ import org.ballerinalang.repository.PackageEntity; import org.ballerinalang.repository.PackageRepository; import org.ballerinalang.repository.PackageSource; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Name; import org.wso2.ballerinalang.compiler.util.Names; @@ -53,7 +54,7 @@ public class GeneralFSPackageRepository implements PackageRepository { protected Path basePath; private final Name orgName; - public GeneralFSPackageRepository(Path basePath, Name orgName) { + public GeneralFSPackageRepository(Path basePath, @Nullable Name orgName) { this.basePath = basePath; this.orgName = orgName; } @@ -62,6 +63,7 @@ public GeneralFSPackageRepository(Path basePath) { this(basePath, null); } + @Nullable protected PackageSource lookupPackageSource(PackageID pkgID) { Path path; @@ -81,6 +83,7 @@ protected PackageSource lookupPackageSource(PackageID pkgID) { return new FSPackageSource(pkgID, path); } + @Nullable protected PackageSource lookupPackageSource(PackageID pkgID, String entryName) { Path path = this.generatePathOld(pkgID); if (!Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) { diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/spi/SystemPackageRepositoryProvider.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/spi/SystemPackageRepositoryProvider.java index b62fed8f6b4d..b66d067fc7af 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/spi/SystemPackageRepositoryProvider.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/spi/SystemPackageRepositoryProvider.java @@ -18,6 +18,7 @@ package org.ballerinalang.spi; import org.ballerinalang.repository.PackageRepository; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.packaging.repo.Repo; import java.net.URI; @@ -31,6 +32,7 @@ */ public interface SystemPackageRepositoryProvider { + @Nullable static URI getClassUri(Object obj) { try { return obj.getClass().getProtectionDomain().getCodeSource().getLocation().toURI(); diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Dependency.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Dependency.java index 80e7ae5b67ef..0e1f27372523 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Dependency.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Dependency.java @@ -19,6 +19,7 @@ package org.ballerinalang.toml.model; import org.ballerinalang.compiler.BLangCompilerException; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -29,6 +30,7 @@ public class Dependency { private String moduleID; private DependencyMetadata metadata; + @Nullable public String getModuleID() { return moduleID == null ? null : moduleID.replaceAll("^\"|\"$", ""); } diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java index 7069d859b74e..154c7f854f53 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java @@ -18,8 +18,10 @@ package org.ballerinalang.toml.model; import org.ballerinalang.toml.util.PathUtils; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; +import java.util.Optional; /** * Defines dependency object fields. The same object will be used to define patches. @@ -53,11 +55,12 @@ public void setVersion(String version) { * * @return location of the dependency */ - public Path getPath() { + @Nullable + public Optional getPath() { if (PathUtils.getPath(this.path) == null) { - return null; + return Optional.empty(); } - return Path.of(PathUtils.getPath(this.path)); + return Optional.of(Path.of(PathUtils.getPath(this.path))); } /** diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/util/PathUtils.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/util/PathUtils.java index 956e39a6026b..7ad25da2173c 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/util/PathUtils.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/util/PathUtils.java @@ -17,6 +17,8 @@ */ package org.ballerinalang.toml.util; +import org.jetbrains.annotations.Nullable; + import java.util.Locale; /** @@ -30,6 +32,7 @@ public final class PathUtils { private PathUtils() { } + @Nullable public static String getPath(String path) { if (path != null) { if (OS.contains("win")) { diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/util/SingletonStack.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/util/SingletonStack.java index fa07d4c10afb..541091dca243 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/util/SingletonStack.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/util/SingletonStack.java @@ -17,6 +17,8 @@ */ package org.ballerinalang.toml.util; +import org.jetbrains.annotations.Nullable; + /** * This class can be used to handle a singleton content with one element. * @@ -24,6 +26,7 @@ * @since 0.964 */ public class SingletonStack { + @Nullable private T content; /** diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/util/diagnostic/DiagnosticLog.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/util/diagnostic/DiagnosticLog.java index 5d249769c4bd..e9b11ed0f86b 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/util/diagnostic/DiagnosticLog.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/util/diagnostic/DiagnosticLog.java @@ -21,6 +21,7 @@ import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; /** * A {@code DiagnosticLog} provides a way for the Ballerina compiler @@ -57,7 +58,7 @@ public interface DiagnosticLog { * @param message the message */ void logDiagnostic(DiagnosticSeverity severity, - ModuleDescriptor moduleDescriptor, + @Nullable ModuleDescriptor moduleDescriptor, Location location, CharSequence message); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java index 97e943698e19..0f9d4d10e0d7 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java @@ -29,6 +29,7 @@ import org.ballerinalang.model.symbols.SymbolOrigin; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.types.ConstrainedType; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.writer.CPEntry; import org.wso2.ballerinalang.compiler.bir.writer.CPEntry.ByteCPEntry; import org.wso2.ballerinalang.compiler.bir.writer.CPEntry.FloatCPEntry; @@ -138,10 +139,12 @@ public class BIRPackageSymbolEnter { private final Names names; private final TypeParamAnalyzer typeParamAnalyzer; private final Types types; + @Nullable private BIRTypeReader typeReader; private BIRPackageSymbolEnv env; private List structureTypes; // TODO find a better way + @Nullable private BStructureTypeSymbol currentStructure = null; private final LinkedList compositeStack = new LinkedList<>(); @@ -319,6 +322,7 @@ private CPEntry[] readConstantPool(DataInputStream dataInStream) throws IOExcept return constantPool; } + @Nullable private CPEntry readCPEntry(DataInputStream dataInStream, CPEntry[] constantPool, CPEntry.Type cpEntryType, int i) throws IOException { @@ -657,6 +661,7 @@ private void readAndSetParamDocumentation(DataInputStream inputStream, List getConverter() { return new PathConverter(programDirPath); } + @Nullable private String getTopLevelDirNameInPackage(CompilerOutputEntry.Kind kind, FileSystem fs) { return switch (kind) { case SRC, BIR, OBJ -> kind.getValue(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/FileSystemProjectDirectory.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/FileSystemProjectDirectory.java index 2d5293d969a6..d69c931f594b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/FileSystemProjectDirectory.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/FileSystemProjectDirectory.java @@ -20,6 +20,7 @@ import org.ballerinalang.compiler.BLangCompilerException; import org.ballerinalang.repository.CompiledPackage; import org.ballerinalang.repository.CompilerOutputEntry; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.FileUtils; import org.wso2.ballerinalang.compiler.util.ProjectDirConstants; import org.wso2.ballerinalang.compiler.util.ProjectDirs; @@ -206,6 +207,7 @@ private void addCompilerOutputEntry(FileSystem fs, CompilerOutputEntry outputEnt Files.copy(outputEntry.getInputStream(), destPath, StandardCopyOption.REPLACE_EXISTING); } + @Nullable private String getTopLevelDirNameInPackage(Kind kind, FileSystem fs) { return switch (kind) { case SRC, BIR, OBJ -> kind.getValue(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/PackageCache.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/PackageCache.java index 146c3f5a4353..333f4fc64e6d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/PackageCache.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/PackageCache.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol; import org.wso2.ballerinalang.compiler.tree.BLangPackage; import org.wso2.ballerinalang.compiler.util.CompilerContext; @@ -105,6 +106,7 @@ public BPackageSymbol getSymbol(PackageID packageID) { return getSymbol(packageID.toString()); } + @Nullable public BPackageSymbol getSymbol(String bvmAlias) { String[] packageElements = bvmAlias.split(Names.VERSION_SEPARATOR.value); Map versionMap = packageSymbolMap.get(packageElements[0]); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/SourceDirectoryManager.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/SourceDirectoryManager.java index 50688607dae6..67c266a890ce 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/SourceDirectoryManager.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/SourceDirectoryManager.java @@ -25,6 +25,7 @@ import org.ballerinalang.toml.exceptions.TomlException; import org.ballerinalang.toml.model.Manifest; import org.ballerinalang.toml.parser.ManifestProcessor; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.CompilerContext; import org.wso2.ballerinalang.compiler.util.CompilerOptions; import org.wso2.ballerinalang.compiler.util.Name; @@ -110,6 +111,7 @@ private Manifest getManifest() { return manifest; } + @Nullable public PackageID getPackageID(String sourcePackage) { List sourceFileNames = this.sourceDirectory.getSourceFileNames(); Name orgName = getOrgName(this.manifest); @@ -140,6 +142,7 @@ public SourceDirectory getSourceDirectory() { // private methods + @Nullable private SourceDirectory initializeAndGetSourceDirectory(CompilerContext context) { try { SourceDirectory srcDirectory = context.get(SourceDirectory.class); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java index 9d74da3a22a2..112146e0341d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java @@ -33,6 +33,7 @@ import org.ballerinalang.model.tree.OperatorKind; import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.model.BIRNode; import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRAnnotation; import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRAnnotationAttachment; @@ -325,6 +326,7 @@ private boolean listenerDeclarationFound(List globalVars) { return false; } + @Nullable private BLangFunction getMainFunction(BLangPackage pkgNode) { for (BLangFunction funcNode : pkgNode.functions) { if (CompilerUtils.isMainFunction(funcNode)) { @@ -775,7 +777,7 @@ private BIRBasicBlock beginBreakableBlock(BLangBlockStmt.FailureBreakMode mode) return blockEndBB; } - private void endBreakableBlock(BIRBasicBlock blockEndBB) { + private void endBreakableBlock(@Nullable BIRBasicBlock blockEndBB) { this.env.unlockVars.pop(); if (this.env.enclBB.terminator == null) { this.env.enclBB.terminator = new BIRTerminator.GOTO(null, blockEndBB, this.currentScope); @@ -860,6 +862,7 @@ private String getFieldName(String funcName, String typeName) { return splitNames[splitNames.length - 1]; } + @Nullable private BType getRecordTargetType(String funcName) { if (!funcName.contains(RECORD_DELIMITER)) { return null; @@ -908,7 +911,7 @@ private void addParam(BIRFunction birFunc, BVarSymbol paramSymbol, Location pos) addParam(birFunc, paramSymbol, null, pos, paramSymbol.getAnnotations()); } - private void addParam(BIRFunction birFunc, BVarSymbol paramSymbol, BLangExpression defaultValExpr, + private void addParam(BIRFunction birFunc, BVarSymbol paramSymbol, @Nullable BLangExpression defaultValExpr, Location pos, List annots) { boolean isPathParam = paramSymbol.kind == SymbolKind.PATH_PARAMETER || paramSymbol.kind == SymbolKind.PATH_REST_PARAMETER; @@ -961,6 +964,7 @@ private void addRequiredParam(BIRFunction birFunc, BVarSymbol paramSymbol, Locat this.env.symbolVarMap.put(paramSymbol, birVarDcl); } + @Nullable private PackageID getPackageIdForBoundMethod(BLangLambdaFunction lambdaExpr, String funcName) { if (!funcName.startsWith("$anon$method$delegate$")) { return null; @@ -1469,6 +1473,7 @@ public void visit(BLangReturn astReturnStmt) { } } + @Nullable private BLangDiagnosticLocation getFunctionLastLinePos() { if (this.env.enclFunc.pos == null) { return null; @@ -2302,7 +2307,7 @@ private void visitTypedesc(Location pos, BType type, BIROperand annotations) { visitTypedesc(pos, type, Collections.emptyList(), annotations); } - private void visitTypedesc(Location pos, BType type, List varDcls, BIROperand annotations) { + private void visitTypedesc(Location pos, BType type, List varDcls, @Nullable BIROperand annotations) { BIRVariableDcl tempVarDcl = new BIRVariableDcl(symTable.typeDesc, this.env.nextLocalVarId(names), VarScope.FUNCTION, VarKind.TEMP); BIRGenEnv env = this.env; @@ -2860,7 +2865,7 @@ private BType getEffectiveObjectType(BType objType) { return objType; } - private BIROperand generateStringLiteral(String value) { + private BIROperand generateStringLiteral(@Nullable String value) { BLangLiteral prefixLiteral = (BLangLiteral) TreeBuilder.createLiteralExpression(); prefixLiteral.value = value; @@ -3055,6 +3060,7 @@ private List getBIRAnnotAttachmentsForASTAnnotAttachmen return annotationAttachments; } + @Nullable private BIROperand getAnnotations(BTypeSymbol typeSymbol, BIRGenEnv env) { if (typeSymbol == null || typeSymbol.annotations == null) { return null; @@ -3069,7 +3075,7 @@ private BIRVariableDcl getAnnotations(BVarSymbol annotations, BIRGenEnv env) { return globalVarMap.get(annotations); } - private void addReturnBB(Location pos) { + private void addReturnBB(@Nullable Location pos) { if (this.env.returnBB == null) { BIRBasicBlock returnBB = new BIRBasicBlock(this.env.nextBBId()); addToTrapStack(returnBB); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenEnv.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenEnv.java index 9cf1bb8eafa0..33e6eaa725e1 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenEnv.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenEnv.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir; import org.ballerinalang.model.tree.BlockNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRBasicBlock; import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRFunction; import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRLockDetailsHolder; @@ -43,7 +44,7 @@ class BIRGenEnv { BIRPackage enclPkg; - BIRFunction enclFunc; + @Nullable BIRFunction enclFunc; List enclBasicBlocks; @@ -53,8 +54,8 @@ class BIRGenEnv { private int currentLocalVarId = -1; private int currentLambdaVarId = -1; - BIRBasicBlock enclBB; - BIROperand targetOperand; + @Nullable BIRBasicBlock enclBB; + @Nullable BIROperand targetOperand; BIRBasicBlock enclLoopBB; BIRBasicBlock enclLoopEndBB; BIRBasicBlock enclOnFailEndBB; @@ -72,7 +73,7 @@ class BIRGenEnv { // This is the basic block that contains the return instruction for the current function. // A function can have only one basic block that has a return instruction. - BIRBasicBlock returnBB; + @Nullable BIRBasicBlock returnBB; // This is to hold whether a NewArray or NewStructure instruction is being constructed int isInArrayOrStructure = 0; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCastGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCastGen.java index d9a5a619fb5d..2a4d3d73dcbf 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCastGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCastGen.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen; import org.ballerinalang.compiler.BLangCompilerException; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.wso2.ballerinalang.compiler.bir.codegen.internal.BIRVarToJVMIndexMap; @@ -1164,6 +1165,7 @@ private void checkCast(MethodVisitor mv, BType targetType) { mv.visitMethodInsn(INVOKESTATIC, TYPE_CHECKER, "checkCast", CHECK_CAST, false); } + @Nullable static String getTargetClass(BType targetType) { targetType = JvmCodeGenUtil.getImpliedType(targetType); if (TypeTags.isXMLTypeTag(targetType.tag)) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java index 9d98ea87c7f0..c1b628ff46fb 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java @@ -24,6 +24,7 @@ import org.ballerinalang.compiler.BLangCompilerException; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; @@ -489,7 +490,7 @@ public static boolean isBallerinaBuiltinModule(String orgName, String moduleName public static BirScope getLastScopeFromBBInsGen(MethodVisitor mv, LabelGenerator labelGen, JvmInstructionGen instGen, int localVarOffset, String funcName, BIRNode.BIRBasicBlock bb, - Set visitedScopesSet, BirScope lastScope) { + Set visitedScopesSet, @Nullable BirScope lastScope) { int insCount = bb.instructions.size(); for (int i = 0; i < insCount; i++) { @@ -639,6 +640,7 @@ public static boolean needNoTypeGeneration(int bTypeTag) { * @return the implied type if provided with a type reference type or an intersection type, * else returns the original type */ + @Nullable public static BType getImpliedType(BType type) { if (type == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmErrorGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmErrorGen.java index c77ba0bd9e8f..3ee7897c6d0a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmErrorGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmErrorGen.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.wso2.ballerinalang.compiler.bir.codegen.internal.BIRVarToJVMIndexMap; @@ -61,6 +62,7 @@ public JvmErrorGen(MethodVisitor mv, BIRVarToJVMIndexMap indexMap, JvmInstructio this.jvmInstructionGen = jvmInstructionGen; } + @Nullable private BIRNode.BIRErrorEntry findErrorEntry(List errors, BIRNode.BIRBasicBlock currentBB) { for (BIRNode.BIRErrorEntry err : errors) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmObservabilityGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmObservabilityGen.java index 8802fa06e368..c2c0040ffca0 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmObservabilityGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmObservabilityGen.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.elements.Flag; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.PackageCache; import org.wso2.ballerinalang.compiler.bir.codegen.model.JIMethodCall; import org.wso2.ballerinalang.compiler.bir.codegen.model.JMethodCallInstruction; @@ -323,7 +324,8 @@ private void populatePredecessorMap(List basicBlocks) { * @param attachedTypeDef The type definition to which the function was attached to or null * @param pkg The package containing the function */ - private void rewriteAsyncInvocations(BIRFunction func, BIRTypeDefinition attachedTypeDef, BIRPackage pkg) { + private void rewriteAsyncInvocations( + BIRFunction func, @Nullable BIRTypeDefinition attachedTypeDef, BIRPackage pkg) { PackageID packageID = pkg.packageID; Name org = new Name(Utils.decodeIdentifier(packageID.orgName.getValue())); Name module = new Name(Utils.decodeIdentifier(packageID.name.getValue())); @@ -451,9 +453,10 @@ private void rewriteAsyncInvocations(BIRFunction func, BIRTypeDefinition attache * @param isMainEntryPoint True if the function is the main entry point * @param isWorker True if the function was a worker */ - private void rewriteObservableFunctionBody(BIRFunction func, BIRPackage pkg, BIRTypeDefinition attachedTypeDef, - String functionName, String serviceName, boolean isResource, - boolean isRemote, boolean isMainEntryPoint, boolean isWorker) { + private void rewriteObservableFunctionBody( + BIRFunction func, BIRPackage pkg, @Nullable BIRTypeDefinition attachedTypeDef, + String functionName, @Nullable String serviceName, boolean isResource, + boolean isRemote, boolean isMainEntryPoint, boolean isWorker) { // Injecting observe start call at the start of the function body { BIRBasicBlock startBB = func.basicBlocks.get(0); // Every non-abstract function should have function body @@ -710,7 +713,7 @@ private void rewriteObservableFunctionInvocations(BIRFunction func, BIRPackage p * @param originalInsPosition The source code position of the invocation */ private void injectStartResourceObservationCall(BIRFunction func, BIRBasicBlock observeStartBB, String serviceName, - String resourcePathOrFunction, String resourceAccessor, + String resourcePathOrFunction, @Nullable String resourceAccessor, boolean isResource, boolean isRemote, BIRPackage pkg, Location originalInsPosition) { BIROperand serviceNameOperand = generateGlobalConstantOperand(pkg, symbolTable.stringType, serviceName); @@ -749,7 +752,7 @@ private void injectStartResourceObservationCall(BIRFunction func, BIRBasicBlock * @param originalInsPosition The source code position of the invocation */ private void injectStartCallableObservationCall(BIRFunction func, BIRBasicBlock observeStartBB, - Location desugaredInsLocation, boolean isRemote, + @Nullable Location desugaredInsLocation, boolean isRemote, boolean isMainEntryPoint, boolean isWorker, BIROperand objectOperand, String action, BIRPackage pkg, Location originalInsPosition) { @@ -784,7 +787,7 @@ private void injectStartCallableObservationCall(BIRFunction func, BIRBasicBlock * @param uniqueId A unique ID to identify the check error call */ private void injectCheckErrorCalls(BIRFunction func, BIRBasicBlock errorCheckBB, BIRBasicBlock isErrorBB, - BIRBasicBlock noErrorBB, Location pos, BIROperand valueOperand, + BIRBasicBlock noErrorBB, @Nullable Location pos, BIROperand valueOperand, String uniqueId) { BIROperand isErrorOperand = tempLocalVarsMap.get(uniqueId + "$isError"); addLocalVarIfAbsent(func, isErrorOperand.variableDcl); @@ -802,7 +805,7 @@ private void injectCheckErrorCalls(BIRFunction func, BIRBasicBlock errorCheckBB, * @param errorOperand Operand for passing the error * @param uniqueId A unique ID to identify the check error call */ - private void injectReportErrorCall(BIRFunction func, BIRBasicBlock errorReportBB, Location pos, + private void injectReportErrorCall(BIRFunction func, BIRBasicBlock errorReportBB, @Nullable Location pos, BIROperand errorOperand, String uniqueId) { BIROperand castedErrorOperand = tempLocalVarsMap.get(uniqueId + "$castedError"); addLocalVarIfAbsent(func, castedErrorOperand.variableDcl); @@ -825,7 +828,7 @@ private void injectReportErrorCall(BIRFunction func, BIRBasicBlock errorReportBB * @param observeEndBB The basic block to which the stop observation call should be injected * @param pos The position of all instructions, variables declarations, terminators, etc. */ - private void injectStopObservationCall(BIRBasicBlock observeEndBB, Location pos) { + private void injectStopObservationCall(BIRBasicBlock observeEndBB, @Nullable Location pos) { JIMethodCall observeEndCallTerminator = new JIMethodCall(pos); observeEndCallTerminator.invocationType = INVOKESTATIC; observeEndCallTerminator.jClassName = OBSERVE_UTILS; @@ -844,8 +847,9 @@ private void injectStopObservationCall(BIRBasicBlock observeEndBB, Location pos) * @param errorOperand Operand for passing the error * @param uniqueId A unique ID to identify the check error call */ - private void injectStopObservationWithErrorCall(BIRFunction func, BIRBasicBlock observeEndBB, Location pos, - BIROperand errorOperand, String uniqueId) { + private void injectStopObservationWithErrorCall( + BIRFunction func, BIRBasicBlock observeEndBB, @Nullable Location pos, + BIROperand errorOperand, String uniqueId) { BIROperand castedErrorOperand = tempLocalVarsMap.get(uniqueId + "$castedError"); addLocalVarIfAbsent(func, castedErrorOperand.variableDcl); TypeCast errorCastInstruction = new TypeCast(pos, castedErrorOperand, errorOperand, symbolTable.errorType, @@ -869,7 +873,8 @@ private void injectStopObservationWithErrorCall(BIRFunction func, BIRBasicBlock * @param constantValue The constant value which should end up being passed in the operand * @return The generated operand which will pass the constant */ - private BIROperand generateGlobalConstantOperand(BIRPackage pkg, BType constantType, Object constantValue) { + private BIROperand generateGlobalConstantOperand( + BIRPackage pkg, BType constantType, @Nullable Object constantValue) { return compileTimeConstants.computeIfAbsent(constantValue, k -> { PackageID pkgId = pkg.packageID; Name name = new Name("$observabilityConst" + constantIndex++); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java index f6316475a157..55c0e26fbd45 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassTooLargeException; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.FieldVisitor; @@ -115,11 +116,11 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MODULE_INIT_CLASS_NAME; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MODULE_STARTED; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MODULE_START_ATTEMPTED; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.PARENT_MODULE_START_ATTEMPTED; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MODULE_STOP_METHOD; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MODULE_TYPES_CLASS_NAME; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.NO_OF_DEPENDANT_MODULES; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.OBJECT; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.PARENT_MODULE_START_ATTEMPTED; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.SERVICE_EP_AVAILABLE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TEST_EXECUTE_METHOD; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.VALUE_CREATOR; @@ -346,6 +347,7 @@ public static BIRFunctionWrapper getFunctionWrapper(BIRFunction currentFunc, Pac return new BIRFunctionWrapper(packageID, currentFunc, moduleClass, jvmMethodDescription); } + @Nullable private static BIRFunction findFunction(BIRNode parentNode, String funcName) { BIRFunction func; if (parentNode instanceof BIRTypeDefinition typeDef) { @@ -360,6 +362,7 @@ private static BIRFunction findFunction(BIRNode parentNode, String funcName) { return func; } + @Nullable private static BIRFunction findFunction(List functions, String funcName) { for (BIRFunction func : functions) { @@ -780,6 +783,7 @@ private void removeSourceAnnotationTypeDefs(List typeDefs) { typeDefs.removeIf(def -> Symbols.isFlagOn(def.flags, Flags.SOURCE_ANNOTATION)); } + @Nullable private BIRFunction getMainFunction(BIRPackage module) { BIRFunction mainFunc = null; if (module.packageID.skipTests) { @@ -788,6 +792,7 @@ private BIRFunction getMainFunction(BIRPackage module) { return mainFunc; } + @Nullable private BIRFunction getTestExecuteFunction(BIRPackage module) { BIRFunction testExecuteFunc = null; if (!module.packageID.skipTests) { @@ -796,6 +801,7 @@ private BIRFunction getTestExecuteFunction(BIRPackage module) { return testExecuteFunc; } + @Nullable private BIRFunction getFunction(BIRPackage module, String funcName) { BIRFunction function = null; for (BIRFunction birFunc : module.functions) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTerminatorGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTerminatorGen.java index 27938d6c9f82..beccb7be3ff2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTerminatorGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTerminatorGen.java @@ -21,6 +21,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.compiler.BLangCompilerException; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -129,7 +130,6 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.LOCK_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MAKE_CONCAT_WITH_CONSTANTS; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MAP; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.MODULE_INITIALIZER; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MODULE_INIT_CLASS_NAME; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.OBJECT; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.PANIC_FIELD; @@ -190,6 +190,7 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.LOAD_JOBJECT_TYPE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.LOCK; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.MAP_PUT; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.MODULE_INITIALIZER; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.MULTIPLE_RECEIVE_CALL; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.PANIC_IF_IN_LOCK; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.PASS_OBJECT_RETURN_OBJECT; @@ -731,7 +732,7 @@ private void genHandlingBlockedOnExternal(int localVarOffset, Label blockedOnExt mv.visitLabel(panicLabel); } - private void storeReturnFromCallIns(BIRNode.BIRVariableDcl lhsOpVarDcl) { + private void storeReturnFromCallIns(@Nullable BIRNode.BIRVariableDcl lhsOpVarDcl) { if (lhsOpVarDcl != null) { this.storeToVar(lhsOpVarDcl); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java index e6d31db01347..dc1650210c77 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; @@ -479,7 +480,7 @@ public void loadType(MethodVisitor mv, BType bType) { mv.visitFieldInsn(GETSTATIC, PREDEFINED_TYPES, typeFieldName, loadTypeClass(bType)); } - private String loadTypeClass(BType bType) { + private String loadTypeClass(@Nullable BType bType) { bType = JvmCodeGenUtil.getImpliedType(bType); if (bType == null || bType.tag == TypeTags.NIL) { return LOAD_NULL_TYPE; @@ -894,7 +895,7 @@ protected void loadFunctionPathParameters(MethodVisitor mv, BInvokableTypeSymbol populateFunctionParameters(mv, invokableSymbol, params); } - private void populateFunctionParameters(MethodVisitor mv, BInvokableTypeSymbol invokableSymbol, + private void populateFunctionParameters(MethodVisitor mv, @Nullable BInvokableTypeSymbol invokableSymbol, List params) { mv.visitLdcInsn((long) params.size()); mv.visitInsn(L2I); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/AnnotationProc.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/AnnotationProc.java index bba8a1a8a9b1..928782c30579 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/AnnotationProc.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/AnnotationProc.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen.interop; import org.ballerinalang.compiler.BLangCompilerException; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.codegen.model.JType; import org.wso2.ballerinalang.compiler.bir.model.BIRNode; import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRAnnotationAttachment; @@ -53,6 +54,7 @@ public final class AnnotationProc { private AnnotationProc() { } + @Nullable static InteropValidationRequest getInteropAnnotValue(BIRFunction birFunc) { BIRAnnotationAttachment annotAttach = getInteropAnnotAttachment(birFunc); @@ -64,6 +66,7 @@ static InteropValidationRequest getInteropAnnotValue(BIRFunction birFunc) { return createJInteropValidationRequest(annotTagRef, annotAttach, birFunc); } + @Nullable private static BIRAnnotationAttachment getInteropAnnotAttachment(BIRFunction birFunc) { for (BIRAnnotationAttachment annotationAttachment : birFunc.annotAttachments) { @@ -126,6 +129,7 @@ private static InteropValidationRequest createJFieldValidationRequest(String ann birFunc.type, getFieldMethodFromAnnotTag(annotTagRef)); } + @Nullable private static List buildParamTypeConstraints(BIRNode.ConstValue annotValue) { if (annotValue == null) { return null; @@ -155,6 +159,7 @@ private static List buildParamTypeConstraints(BIRNode.ConstValue annotVal return constraints; } + @Nullable private static Object getLiteralValueFromAnnotValue(BIRNode.ConstValue annotValue) { if (annotValue == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JInterop.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JInterop.java index fdd34827b364..47915b99365f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JInterop.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JInterop.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen.interop; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.codegen.exceptions.JInteropException; import org.wso2.ballerinalang.compiler.bir.codegen.model.JMethodKind; import org.wso2.ballerinalang.compiler.bir.codegen.model.JType; @@ -88,6 +89,7 @@ static JType getJType(Class jTypeClass) { return jRefType; } + @Nullable static ParamTypeConstraint[] buildParamTypeConstraints(List javaTypeConstraints, ClassLoader classLoader) { if (javaTypeConstraints == null) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java index 29c69a942619..4514b6ea2c8a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java @@ -33,6 +33,7 @@ import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.runtime.api.values.BXml; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.codegen.JvmCodeGenUtil; import org.wso2.ballerinalang.compiler.bir.codegen.exceptions.JInteropException; import org.wso2.ballerinalang.compiler.bir.codegen.model.JMethod; @@ -887,6 +888,7 @@ private JMethod resolveExactMethod(Class clazz, String name, JMethodKind kind } } + @Nullable private Executable tryResolveExactWithBalEnv(Class[] paramTypes, Class clazz, String name) { Class[] paramTypesWithBalEnv = new Class[paramTypes.length + 1]; System.arraycopy(paramTypes, 0, paramTypesWithBalEnv, 1, paramTypes.length); @@ -960,6 +962,7 @@ private JMethod resolveMatchingMethod(JMethodRequest jMethodRequest, List clazz, Class... paramTypes) { try { @@ -969,6 +972,7 @@ private Executable resolveConstructor(Class clazz, Class... paramTypes) { } } + @Nullable private Executable resolveMethod(Class clazz, String name, Class... paramTypes) { try { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/ParamTypeConstraint.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/ParamTypeConstraint.java index 60abfd4c2717..7371ee9c606f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/ParamTypeConstraint.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/ParamTypeConstraint.java @@ -17,6 +17,8 @@ */ package org.wso2.ballerinalang.compiler.bir.codegen.interop; +import org.jetbrains.annotations.Nullable; + /** * This class represents constraint for a single Java method parameter and this is used in resolving a * Java method for Ballerina external functions. @@ -29,7 +31,7 @@ class ParamTypeConstraint { private final Class constraint; - ParamTypeConstraint(Class constraint) { + ParamTypeConstraint(@Nullable Class constraint) { this.constraint = constraint; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/FrameClassGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/FrameClassGen.java index 3a116ac0efba..cdc497068118 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/FrameClassGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/FrameClassGen.java @@ -19,6 +19,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen.methodgen; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Opcodes; @@ -71,7 +72,7 @@ public void generateFrameClasses(BIRNode.BIRPackage pkg, JarEntries pkgEntries) private void generateFrameClassForFunction(PackageID packageID, BIRNode.BIRFunction func, JarEntries pkgEntries, - BType attachedType) { + @Nullable BType attachedType) { String frameClassName = MethodGenUtils.getFrameClassName(JvmCodeGenUtil.getPackageName(packageID), func.name.value, attachedType); ClassWriter cw = new BallerinaClassWriter(COMPUTE_FRAMES); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/InitMethodGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/InitMethodGen.java index 4393d2ae2c46..81404fb51a26 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/InitMethodGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/InitMethodGen.java @@ -20,6 +20,7 @@ import io.ballerina.identifier.Utils; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -161,7 +162,7 @@ public void generateLambdaForPackageInit(ClassWriter cw, BIRNode.BIRPackage pkg, public void generateLambdaForModuleExecuteFunction(ClassWriter cw, String initClass, JvmCastGen jvmCastGen, BIRNode.BIRFunction mainFunc, - BIRNode.BIRFunction testExecuteFunc) { + @Nullable BIRNode.BIRFunction testExecuteFunc) { String lambdaFuncName = LAMBDA_PREFIX + MODULE_EXECUTE_METHOD + "$"; MethodVisitor mv = visitFunction(cw, lambdaFuncName); mv.visitCode(); @@ -517,6 +518,7 @@ private BIRTerminator.FPCall getFPCallForDefaultParameter(BInvokableSymbol defau thenBB, null, workerDerivative); } + @Nullable private BIRNode.BIRGlobalVariableDcl getDefaultFuncFPGlobalVar(Name name, List globalVars) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/LambdaGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/LambdaGen.java index db6a0d634707..f10ea134468d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/LambdaGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/LambdaGen.java @@ -21,6 +21,7 @@ import io.ballerina.identifier.Utils; import org.ballerinalang.compiler.BLangCompilerException; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -497,7 +498,7 @@ private void populateLambdaReturnType(BIRInstruction ins, LambdaDetails lambdaDe } private static class LambdaDetails { - BType lhsType; + @Nullable BType lhsType; PackageID packageID; String funcName; boolean isExternFunction; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java index 003e3869bb48..92d6ceec70d2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java @@ -21,6 +21,7 @@ import io.ballerina.identifier.Utils; import org.ballerinalang.compiler.BLangCompilerException; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -118,9 +119,9 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MODULE_INIT_CLASS_NAME; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MODULE_STARTED; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.MODULE_START_ATTEMPTED; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.PARENT_MODULE_START_ATTEMPTED; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.NO_OF_DEPENDANT_MODULES; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.OBJECT_SELF_INSTANCE; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.PARENT_MODULE_START_ATTEMPTED; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STACK; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRAND; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRAND_CLASS; @@ -175,7 +176,7 @@ public MethodGen(JvmPackageGen jvmPackageGen, Types types) { this.types = types; } - public void generateMethod(BIRFunction birFunc, ClassWriter cw, BIRPackage birModule, BType attachedType, + public void generateMethod(BIRFunction birFunc, ClassWriter cw, BIRPackage birModule, @Nullable BType attachedType, String moduleClassName, JvmTypeGen jvmTypeGen, JvmCastGen jvmCastGen, JvmConstantsGen jvmConstantsGen, AsyncDataCollector asyncDataCollector) { if (JvmCodeGenUtil.isExternFunc(birFunc)) { @@ -606,7 +607,8 @@ private int[] toIntArray(List states) { void generateBasicBlocks(MethodVisitor mv, LabelGenerator labelGen, JvmErrorGen errorGen, JvmInstructionGen instGen, JvmTerminatorGen termGen, BIRFunction func, int returnVarRefIndex, int stateVarIndex, int yieldLocationVarIndex, int yieldStatusVarIndex, int loopVarIndex, - int invocationVarIndex, int localVarOffset, BIRPackage module, BType attachedType, + int invocationVarIndex, int localVarOffset, BIRPackage module, + @Nullable BType attachedType, String moduleClassName, Label loopLabel) { String funcName = func.name.value; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGenUtils.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGenUtils.java index 57aab825ef70..f1962960fe07 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGenUtils.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGenUtils.java @@ -20,6 +20,7 @@ import io.ballerina.identifier.Utils; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.MethodVisitor; import org.wso2.ballerinalang.compiler.bir.codegen.JvmCodeGenUtil; import org.wso2.ballerinalang.compiler.bir.codegen.internal.AsyncDataCollector; @@ -130,7 +131,7 @@ public static void callSetDaemonStrand(MethodVisitor mv) { private MethodGenUtils() { } - static String getFrameClassName(String pkgName, String funcName, BType attachedType) { + static String getFrameClassName(String pkgName, String funcName, @Nullable BType attachedType) { String frameClassName = pkgName + FRAME_CLASS_PREFIX; if (isValidType(attachedType)) { frameClassName += JvmCodeGenUtil.toNameString(attachedType) + "_"; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIConstructorCall.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIConstructorCall.java index f72d810ed0b4..f66403ce5b50 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIConstructorCall.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIConstructorCall.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen.model; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.model.BIROperand; import org.wso2.ballerinalang.compiler.bir.model.BIRVisitor; @@ -30,6 +31,7 @@ */ public class JIConstructorCall extends JTerminator { + @Nullable public BIROperand receiver; public List args; public List resourcePathArgs; @@ -38,6 +40,7 @@ public class JIConstructorCall extends JTerminator { public String jMethodVMSig; public String name; public boolean varArgExist; + @Nullable public JType varArgType; public JIConstructorCall(Location pos) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIMethodCLICall.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIMethodCLICall.java index 64ff85ff715a..18ac9f418c9b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIMethodCLICall.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIMethodCLICall.java @@ -19,6 +19,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen.model; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.model.BIROperand; import java.util.List; @@ -36,7 +37,7 @@ public class JIMethodCLICall extends JTerminator { public String name; public List defaultFunctionArgs; - public JIMethodCLICall(Location pos) { + public JIMethodCLICall(@Nullable Location pos) { super(pos); this.jTermKind = JTermKind.JI_METHOD_CLI_CALL; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIMethodCall.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIMethodCall.java index fddbba24ae82..9f476e149ed6 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIMethodCall.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JIMethodCall.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen.model; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.model.BIROperand; import org.wso2.ballerinalang.compiler.bir.model.BIRVisitor; @@ -30,11 +31,13 @@ */ public class JIMethodCall extends JTerminator { + @Nullable public BIROperand receiver; public List args; public List resourcePathArgs; public List functionArgs; public boolean varArgExist; + @Nullable public JType varArgType; public String jClassName; public String jMethodVMSig; @@ -42,7 +45,7 @@ public class JIMethodCall extends JTerminator { public int invocationType; public boolean isInternal = false; - public JIMethodCall(Location pos) { + public JIMethodCall(@Nullable Location pos) { super(pos); this.jTermKind = JTermKind.JI_METHOD_CALL; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JMethod.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JMethod.java index ef718ee89cc6..9dcdff321b1c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JMethod.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JMethod.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen.model; import io.ballerina.runtime.api.Environment; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.codegen.JvmCodeGenUtil; import org.wso2.ballerinalang.compiler.bir.codegen.exceptions.JInteropException; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; @@ -48,14 +49,14 @@ public class JMethod { public boolean hasBundledPathParams = false; public boolean hasBundledFunctionParams = false; - private JMethod(JMethodKind kind, Executable executable, BType receiverType) { + private JMethod(@Nullable JMethodKind kind, @Nullable Executable executable, @Nullable BType receiverType) { this.kind = kind; this.method = executable; this.receiverType = receiverType; } - public static JMethod build(JMethodKind kind, Executable executable, BType receiverType) { + public static JMethod build(JMethodKind kind, Executable executable, @Nullable BType receiverType) { return new JMethod(kind, executable, receiverType); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JMethodCallInstruction.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JMethodCallInstruction.java index db30b95ed3d7..6bb0dfb68787 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JMethodCallInstruction.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/model/JMethodCallInstruction.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen.model; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.model.BIROperand; import org.wso2.ballerinalang.compiler.bir.model.BIRVisitor; @@ -36,7 +37,7 @@ public class JMethodCallInstruction extends JInstruction { public String name; public int invocationType; - public JMethodCallInstruction(Location pos) { + public JMethodCallInstruction(@Nullable Location pos) { super(pos); jKind = JInsKind.CALL; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/optimizer/LargeMethodOptimizer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/optimizer/LargeMethodOptimizer.java index 20aa3d646e15..ad3fc9f2738e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/optimizer/LargeMethodOptimizer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/optimizer/LargeMethodOptimizer.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.BIRGenUtils; import org.wso2.ballerinalang.compiler.bir.codegen.model.JInstruction; import org.wso2.ballerinalang.compiler.bir.codegen.model.JLargeArrayInstruction; @@ -1914,7 +1915,7 @@ private BIRFunction createNewBIRFuncForSplitInBB(Name funcName, BIRNonTerminator return birFunc; } - private void rectifyVarKindsAndTerminators(BIRFunction birFunction, BIRVariableDcl selfVarDcl, + private void rectifyVarKindsAndTerminators(BIRFunction birFunction, @Nullable BIRVariableDcl selfVarDcl, BIRBasicBlock returnBB) { Map funcArgsWithName = new HashMap<>(); for (BIRFunctionParameter parameter : birFunction.parameters) { @@ -1964,7 +1965,7 @@ private void setInsRhsOperands(BIRVariableDcl selfVarDcl, Map operandList, + private static void populateNewRHSOperands(@Nullable BIRVariableDcl variableDcl, List operandList, Map newRhsOperands, BIROperand rhsOperand) { if (!newRhsOperands.containsKey(rhsOperand.variableDcl)) { BIROperand newOperand = new BIROperand(variableDcl); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/values/JvmRecordGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/values/JvmRecordGen.java index eb068a30663c..3c94d263f2bc 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/values/JvmRecordGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/split/values/JvmRecordGen.java @@ -19,6 +19,7 @@ package org.wso2.ballerinalang.compiler.bir.codegen.split.values; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -898,7 +899,7 @@ private boolean checkIfValueIsJReferenceType(BType bType) { private void createBasicTypeGetMethod(ClassWriter cw, Map fields, String className, JvmCastGen jvmCastGen, TypeKind basicType, String methodName, - String methodDesc, boolean boxed, String boxedTypeDesc) { + String methodDesc, boolean boxed, @Nullable String boxedTypeDesc) { List sortedFields = getSortedFields(fields, basicType); if (sortedFields.isEmpty()) { return; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRAbstractInstruction.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRAbstractInstruction.java index 084b3c5b8172..ea21bae50e5b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRAbstractInstruction.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRAbstractInstruction.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.model; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; /** * Abstract instruction with an lhs-operand. @@ -27,6 +28,7 @@ public abstract class BIRAbstractInstruction extends BIRNode implements BIRInstruction { public InstructionKind kind; + @Nullable public BIROperand lhsOp; public BirScope scope; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java index 088ec5e6289c..23373c74867a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.elements.MarkdownDocAttachment; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.semantics.model.types.NamedNode; @@ -43,7 +44,7 @@ public abstract class BIRNode { public final Location pos; - protected BIRNode(Location pos) { + protected BIRNode(@Nullable Location pos) { this.pos = pos; } @@ -99,7 +100,7 @@ public void accept(BIRVisitor visitor) { public static class BIRImportModule extends BIRNode { public final PackageID packageID; - public BIRImportModule(Location pos, Name org, Name name, Name version) { + public BIRImportModule(@Nullable Location pos, Name org, Name name, Name version) { super(pos); packageID = new PackageID(org, name, version); } @@ -162,12 +163,12 @@ public BIRVariableDcl(Location pos, BType type, Name name, Name originalName, Va this.jvmVarName = name.value.replace("%", "_"); } - public BIRVariableDcl(Location pos, BType type, Name name, VarScope scope, - VarKind kind, String metaVarName) { + public BIRVariableDcl(@Nullable Location pos, @Nullable BType type, Name name, VarScope scope, + VarKind kind, @Nullable String metaVarName) { this(pos, type, name, name, scope, kind, metaVarName); } - public BIRVariableDcl(BType type, Name name, VarScope scope, VarKind kind) { + public BIRVariableDcl(BType type, Name name, @Nullable VarScope scope, VarKind kind) { this(null, type, name, scope, kind, null); } @@ -211,7 +212,7 @@ public static class BIRParameter extends BIRNode { public long flags; public List annotAttachments; - public BIRParameter(Location pos, Name name, long flags) { + public BIRParameter(@Nullable Location pos, Name name, long flags) { super(pos); this.name = name; this.flags = flags; @@ -238,8 +239,9 @@ public static class BIRGlobalVariableDcl extends BIRVariableDcl { public SymbolOrigin origin; public List annotAttachments; - public BIRGlobalVariableDcl(Location pos, long flags, BType type, PackageID pkgId, Name name, Name originalName, - VarScope scope, VarKind kind, String metaVarName, SymbolOrigin origin) { + public BIRGlobalVariableDcl(@Nullable Location pos, long flags, BType type, @Nullable PackageID pkgId, + Name name, Name originalName, VarScope scope, VarKind kind, String metaVarName, + SymbolOrigin origin) { super(pos, type, name, originalName, scope, kind, metaVarName); this.flags = flags; this.pkgId = pkgId; @@ -268,8 +270,8 @@ public BIRFunctionParameter(Location pos, BType type, Name name, this.hasDefaultExpr = hasDefaultExpr; } - public BIRFunctionParameter(Location pos, BType type, Name name, VarScope scope, VarKind kind, - String metaVarName, boolean hasDefaultExpr, boolean isPathParameter) { + public BIRFunctionParameter(@Nullable Location pos, BType type, Name name, VarScope scope, VarKind kind, + @Nullable String metaVarName, boolean hasDefaultExpr, boolean isPathParameter) { this(pos, type, name, scope, kind, metaVarName, hasDefaultExpr); this.isPathParameter = isPathParameter; } @@ -321,6 +323,7 @@ public static class BIRFunction extends BIRDocumentableNode implements NamedNode /** * Receiver. This is an optional field. */ + @Nullable public BIRVariableDcl receiver; /** @@ -340,23 +343,28 @@ public static class BIRFunction extends BIRDocumentableNode implements NamedNode * entries are allocated for function arguments. The rest are for user-defined local variables and * temporary variables. */ + @Nullable public List localVars; + @Nullable public BIRVariableDcl returnVariable; /** * Variable used for parameters of this function. */ + @Nullable public List parameters; /** * List of basic blocks in this function. */ + @Nullable public List basicBlocks; /** * List of error entries in this function. */ + @Nullable public List errorTable; /** @@ -367,18 +375,24 @@ public static class BIRFunction extends BIRDocumentableNode implements NamedNode /** * List of channels this worker interacts. */ + @Nullable public ChannelDetails[] workerChannels; + @Nullable public List annotAttachments; + @Nullable public List returnTypeAnnots; + @Nullable public Set dependentGlobalVars = new TreeSet<>(); // Below fields will only be available on resource functions // TODO: consider creating a sub class for resource functions issue: #36964 + @Nullable public List pathParams; + @Nullable public BIRVariableDcl restPathParam; public List resourcePath; @@ -420,8 +434,8 @@ public BIRFunction(Location pos, Name name, Name originalName, long flags, Symbo this.dependentGlobalVars = dependentGlobalVars; } - public BIRFunction(Location pos, Name name, Name originalName, long flags, BInvokableType type, Name workerName, - int sendInsCount, SymbolOrigin origin) { + public BIRFunction(@Nullable Location pos, Name name, Name originalName, long flags, BInvokableType type, + Name workerName, int sendInsCount, SymbolOrigin origin) { super(pos); this.name = name; this.originalName = originalName; @@ -439,8 +453,8 @@ public BIRFunction(Location pos, Name name, Name originalName, long flags, BInvo this.origin = origin; } - public BIRFunction(Location pos, Name name, long flags, BInvokableType type, Name workerName, - int sendInsCount, SymbolOrigin origin) { + public BIRFunction(@Nullable Location pos, Name name, long flags, BInvokableType type, + @Nullable Name workerName, int sendInsCount, SymbolOrigin origin) { this(pos, name, name, flags, type, workerName, sendInsCount, origin); } @@ -478,6 +492,7 @@ public static class BIRBasicBlock extends BIRNode { public int number; public Name id; public List instructions; + @Nullable public BIRTerminator terminator; public static final String BIR_BASIC_BLOCK_PREFIX = "bb"; @@ -539,6 +554,7 @@ public static class BIRTypeDefinition extends BIRDocumentableNode implements Nam public SymbolOrigin origin; + @Nullable public List annotAttachments; /** @@ -963,9 +979,9 @@ public static class BIRServiceDeclaration extends BIRDocumentableNode { public SymbolOrigin origin; public long flags; - public BIRServiceDeclaration(List attachPoint, String attachPointLiteral, List listenerTypes, - Name generatedName, Name associatedClassName, BType type, SymbolOrigin origin, - long flags, Location location) { + public BIRServiceDeclaration(@Nullable List attachPoint, @Nullable String attachPointLiteral, + List listenerTypes, Name generatedName, Name associatedClassName, + BType type, SymbolOrigin origin, long flags, Location location) { super(location); this.attachPoint = attachPoint; this.attachPointLiteral = attachPointLiteral; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java index d33d3eba6ad2..38d436613dc6 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java @@ -19,6 +19,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.SchedulerPolicy; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; @@ -52,7 +53,7 @@ public BIRNonTerminator(Location pos, InstructionKind kind) { public static class Move extends BIRNonTerminator implements BIRAssignInstruction { public BIROperand rhsOp; - public Move(Location pos, BIROperand fromOperand, BIROperand toOperand) { + public Move(@Nullable Location pos, BIROperand fromOperand, BIROperand toOperand) { super(pos, InstructionKind.MOVE); this.rhsOp = fromOperand; this.lhsOp = toOperand; @@ -171,7 +172,7 @@ public static class ConstantLoad extends BIRNonTerminator implements BIRAssignIn public Object value; public BType type; - public ConstantLoad(Location pos, Object value, BType type, BIROperand lhsOp) { + public ConstantLoad(@Nullable Location pos, Object value, BType type, BIROperand lhsOp) { super(pos, InstructionKind.CONST_LOAD); this.value = value; this.type = type; @@ -274,6 +275,7 @@ public void setRhsOperands(BIROperand[] operands) { public static class NewInstance extends BIRNonTerminator { public final boolean isExternalDef; public final PackageID externalPackageId; + @Nullable public BIRTypeDefinition def; public final String objectName; public final BType expectedType; @@ -337,8 +339,8 @@ public NewArray(Location location, BType type, BIROperand lhsOp, BIROperand size this.values = values; } - public NewArray(Location location, BType type, BIROperand lhsOp, BIROperand typedescOp, BIROperand sizeOp, - List values) { + public NewArray(Location location, BType type, BIROperand lhsOp, @Nullable BIROperand typedescOp, + BIROperand sizeOp, List values) { this(location, type, lhsOp, sizeOp, values); this.typedescOp = typedescOp; } @@ -494,7 +496,7 @@ public static class TypeCast extends BIRNonTerminator { public BType type; public boolean checkTypes; - public TypeCast(Location location, BIROperand lhsOp, BIROperand rhsOp, BType castType, + public TypeCast(@Nullable Location location, BIROperand lhsOp, @Nullable BIROperand rhsOp, BType castType, boolean checkTypes) { super(location, InstructionKind.TYPE_CAST); this.lhsOp = lhsOp; @@ -564,7 +566,7 @@ public static class TypeTest extends BIRNonTerminator { public BIROperand rhsOp; public BType type; - public TypeTest(Location pos, BType type, BIROperand lhsOp, BIROperand rhsOp) { + public TypeTest(@Nullable Location pos, BType type, BIROperand lhsOp, @Nullable BIROperand rhsOp) { super(pos, InstructionKind.TYPE_TEST); this.type = type; this.lhsOp = lhsOp; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIROperand.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIROperand.java index 6070e0046e7f..bf6a0d18ee4f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIROperand.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIROperand.java @@ -17,6 +17,8 @@ */ package org.wso2.ballerinalang.compiler.bir.model; +import org.jetbrains.annotations.Nullable; + /** * {@code BIROperand} represents an operand in an instruction. * @@ -26,7 +28,7 @@ public class BIROperand extends BIRNode { public BIRVariableDcl variableDcl; - public BIROperand(BIRVariableDcl variableDcl) { + public BIROperand(@Nullable BIRVariableDcl variableDcl) { super(null); this.variableDcl = variableDcl; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRTerminator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRTerminator.java index 7f02777d0943..df3c1b0965a2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRTerminator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRTerminator.java @@ -20,6 +20,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.elements.Flag; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; @@ -58,12 +59,12 @@ public static class GOTO extends BIRTerminator { public BIRBasicBlock targetBB; - public GOTO(Location pos, BIRBasicBlock targetBB) { + public GOTO(@Nullable Location pos, BIRBasicBlock targetBB) { super(pos, InstructionKind.GOTO); this.targetBB = targetBB; } - public GOTO(Location pos, + public GOTO(@Nullable Location pos, BIRBasicBlock targetBB, BirScope scope) { this(pos, targetBB); @@ -106,13 +107,13 @@ public static class Call extends BIRTerminator implements BIRAssignInstruction { public List calleeAnnotAttachments; public Set calleeFlags; - public Call(Location pos, + public Call(@Nullable Location pos, InstructionKind kind, boolean isVirtual, PackageID calleePkg, Name name, List args, - BIROperand lhsOp, + @Nullable BIROperand lhsOp, BIRBasicBlock thenBB, List calleeAnnotAttachments, Set calleeFlags) { @@ -133,7 +134,7 @@ public Call(Location pos, PackageID calleePkg, Name name, List args, - BIROperand lhsOp, + @Nullable BIROperand lhsOp, BIRBasicBlock thenBB, List calleeAnnotAttachments, Set calleeFlags, @@ -231,14 +232,14 @@ public FPCall(Location pos, this.scope = scope; } - public FPCall(Location pos, + public FPCall(@Nullable Location pos, InstructionKind kind, - BIROperand fp, + @Nullable BIROperand fp, List args, BIROperand lhsOp, boolean isAsync, BIRBasicBlock thenBB, - BirScope scope, + @Nullable BirScope scope, boolean workerDerivative) { this(pos, kind, fp, args, lhsOp, isAsync, thenBB, scope); this.workerDerivative = workerDerivative; @@ -282,7 +283,7 @@ public BIRBasicBlock[] getNextBasicBlocks() { */ public static class Return extends BIRTerminator { - public Return(Location pos) { + public Return(@Nullable Location pos) { super(pos, InstructionKind.RETURN); } @@ -319,17 +320,17 @@ public static class Branch extends BIRTerminator { public BIRBasicBlock trueBB; public BIRBasicBlock falseBB; - public Branch(Location pos, BIROperand op, BIRBasicBlock trueBB, BIRBasicBlock falseBB) { + public Branch(@Nullable Location pos, BIROperand op, BIRBasicBlock trueBB, BIRBasicBlock falseBB) { super(pos, InstructionKind.BRANCH); this.op = op; this.trueBB = trueBB; this.falseBB = falseBB; } - public Branch(Location pos, + public Branch(@Nullable Location pos, BIROperand op, BIRBasicBlock trueBB, - BIRBasicBlock falseBB, + @Nullable BIRBasicBlock falseBB, BirScope scope) { this(pos, op, trueBB, falseBB); this.scope = scope; @@ -460,7 +461,7 @@ public Unlock(Location pos, BIRBasicBlock unlockBB) { this.unlockBB = unlockBB; } - public Unlock(Location pos, BIRBasicBlock unlockBB, BirScope scope) { + public Unlock(@Nullable Location pos, BIRBasicBlock unlockBB, BirScope scope) { this(pos, unlockBB); this.scope = scope; } @@ -497,7 +498,7 @@ public static class Panic extends BIRTerminator { public BIROperand errorOp; - public Panic(Location pos, BIROperand errorOp) { + public Panic(@Nullable Location pos, BIROperand errorOp) { super(pos, InstructionKind.PANIC); this.errorOp = errorOp; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRBasicBlockOptimizer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRBasicBlockOptimizer.java index a53698cbc86a..678c62c35a94 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRBasicBlockOptimizer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRBasicBlockOptimizer.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.optimizer; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.BIRGenUtils; import org.wso2.ballerinalang.compiler.bir.model.BIRNode; import org.wso2.ballerinalang.compiler.bir.model.BIRNode.BIRBasicBlock; @@ -42,7 +43,7 @@ public class BIRBasicBlockOptimizer extends BIRVisitor { private BIROptimizer.OptimizerEnv env; private final Map> predecessorMap = new HashMap<>(); - public void optimizeNode(BIRNode node, BIROptimizer.OptimizerEnv env) { + public void optimizeNode(BIRNode node, @Nullable BIROptimizer.OptimizerEnv env) { if (node == null) { return; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIROptimizer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIROptimizer.java index 61a755adf31f..b3a48ec5c4b2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIROptimizer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIROptimizer.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.optimizer; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.codegen.model.JLargeArrayInstruction; import org.wso2.ballerinalang.compiler.bir.codegen.model.JLargeMapInstruction; import org.wso2.ballerinalang.compiler.bir.codegen.model.JMethodCallInstruction; @@ -241,7 +242,7 @@ public void visit(BIRPackage birPackage) { birPackage.functions.forEach(func -> this.optimizeNode(func, this.env)); } - public void optimizeNode(BIRNode node, OptimizerEnv env) { + public void optimizeNode(BIRNode node, @Nullable OptimizerEnv env) { if (node == null) { return; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRRecordValueOptimizer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRRecordValueOptimizer.java index 5b1f5c0e8e7d..503d7579127c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRRecordValueOptimizer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRRecordValueOptimizer.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.bir.optimizer; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.model.BIRNode; import org.wso2.ballerinalang.compiler.bir.model.BIRNonTerminator; import org.wso2.ballerinalang.compiler.bir.model.BIROperand; @@ -52,6 +53,7 @@ public class BIRRecordValueOptimizer extends BIRVisitor { private final List recordOperandList = new ArrayList<>(); private final Map recordOperandTypeMap = new HashMap<>(); + @Nullable private BIRNode.BIRBasicBlock lastBB = null; private BIRNode.BIRFunction currentFunction = null; private List newBBs = new ArrayList<>(); @@ -210,6 +212,7 @@ private void resetBasicBlock(BIRNode.BIRBasicBlock basicBlock) { fpRemoved = false; } + @Nullable private BIRNode.BIRFunction getDefaultBIRFunction(String funcName) { for (BIRNode.BIRFunction func : moduleFunctions) { if (func.name.value.equals(funcName)) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/writer/BIRInstructionWriter.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/writer/BIRInstructionWriter.java index 856fae393e8c..90b4e63971b5 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/writer/BIRInstructionWriter.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/writer/BIRInstructionWriter.java @@ -21,6 +21,7 @@ import io.netty.buffer.ByteBuf; import org.ballerinalang.compiler.BLangCompilerException; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.codegen.model.JLargeArrayInstruction; import org.wso2.ballerinalang.compiler.bir.codegen.model.JLargeMapInstruction; import org.wso2.ballerinalang.compiler.bir.codegen.model.JMethodCallInstruction; @@ -737,7 +738,7 @@ private void addCpAndWriteString(String string) { buf.writeInt(addStringCPEntry(string)); } - private int addStringCPEntry(String value) { + private int addStringCPEntry(@Nullable String value) { return BIRWriterUtils.addStringCPEntry(value, this.cp); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/writer/CPEntry.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/writer/CPEntry.java index cac4d86e6eff..fc647e28123b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/writer/CPEntry.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/writer/CPEntry.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.bir.writer; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import java.util.Objects; @@ -141,7 +142,7 @@ public int hashCode() { public static class StringCPEntry extends CPEntry { public String value; - public StringCPEntry(String value) { + public StringCPEntry(@Nullable String value) { super(Type.CP_ENTRY_STRING); this.value = value; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java index d36bb7fe379e..23d0022c47cc 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ASTBuilderUtil.java @@ -27,6 +27,7 @@ import org.ballerinalang.model.tree.OperatorKind; import org.ballerinalang.model.tree.statements.StatementNode; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.Scope; @@ -212,11 +213,13 @@ public void accept(BLangNodeVisitor visitor) { public void accept(BLangNodeAnalyzer analyzer, T props) { } + @Nullable @Override public R apply(BLangNodeTransformer modifier, T props) { return null; } + @Nullable @Override public NodeKind getKind() { return null; @@ -243,9 +246,9 @@ static BLangIf createIfStmt(Location pos, BlockNode target) { } static BLangIf createIfElseStmt(Location pos, - BLangExpression conditionExpr, + @Nullable BLangExpression conditionExpr, BLangBlockStmt thenBody, - BLangStatement elseStmt) { + @Nullable BLangStatement elseStmt) { final BLangIf ifNode = (BLangIf) TreeBuilder.createIfElseStatementNode(); ifNode.pos = pos; ifNode.expr = conditionExpr; @@ -326,7 +329,7 @@ static BLangReturn createReturnStmt(Location pos, BlockNode target) { return returnStmt; } - public static BLangReturn createNilReturnStmt(Location pos, BType nilType) { + public static BLangReturn createNilReturnStmt(@Nullable Location pos, BType nilType) { final BLangReturn returnStmt = (BLangReturn) TreeBuilder.createReturnNode(); returnStmt.pos = pos; returnStmt.expr = createLiteral(pos, nilType, Names.NIL_VALUE); @@ -366,7 +369,7 @@ static BLangBlockFunctionBody createBlockFunctionBody(Location pos, List requiredArgs, SymbolResolver symResolver) { + static BLangInvocation createInvocationExprForMethod(Location pos, @Nullable BInvokableSymbol invokableSymbol, + List requiredArgs, + SymbolResolver symResolver) { return createInvocationExprMethod(pos, invokableSymbol, requiredArgs, new ArrayList<>(), symResolver); } - static BLangInvocation createInvocationExprMethod(Location pos, BInvokableSymbol invokableSymbol, + static BLangInvocation createInvocationExprMethod(@Nullable Location pos, BInvokableSymbol invokableSymbol, List requiredArgs, List restArgs, SymbolResolver symResolver) { final BLangInvocation invokeLambda = (BLangInvocation) TreeBuilder.createInvocationNode(); @@ -524,11 +528,11 @@ static BLangSimpleVarRef createVariableRef(Location pos, BSymbol varSymbol) { return varRef; } - public static BLangSimpleVariable createVariable(Location pos, - String name, + public static BLangSimpleVariable createVariable(@Nullable Location pos, + @Nullable String name, BType type, - BLangExpression expr, - BVarSymbol varSymbol) { + @Nullable BLangExpression expr, + @Nullable BVarSymbol varSymbol) { final BLangSimpleVariable varNode = (BLangSimpleVariable) TreeBuilder.createSimpleVariableNode(); varNode.pos = pos; varNode.name = createIdentifier(pos, name); @@ -613,7 +617,7 @@ static BLangBinaryExpr createBinaryExpr(Location pos, BLangExpression rhsExpr, BType type, OperatorKind opKind, - BOperatorSymbol symbol) { + @Nullable BOperatorSymbol symbol) { final BLangBinaryExpr binaryExpr = (BLangBinaryExpr) TreeBuilder.createBinaryExpressionNode(); binaryExpr.pos = pos; binaryExpr.lhsExpr = lhsExpr; @@ -650,7 +654,7 @@ static BLangIsLikeExpr createIsLikeExpr(Location pos, BLangExpression expr, BLan return isLikeExpr; } - static BLangLiteral createLiteral(Location pos, BType type, Object value) { + static BLangLiteral createLiteral(Location pos, BType type, @Nullable Object value) { final BLangLiteral literal = (BLangLiteral) TreeBuilder.createLiteralExpression(); literal.pos = pos; literal.value = value; @@ -733,7 +737,7 @@ static BLangTypeInit createEmptyTypeInit(Location pos, BType type) { return objectInitNode; } - public static BLangIdentifier createIdentifier(Location pos, String value) { + public static BLangIdentifier createIdentifier(@Nullable Location pos, String value) { final BLangIdentifier node = (BLangIdentifier) TreeBuilder.createIdentifierNode(); node.pos = pos; if (value != null) { @@ -771,7 +775,7 @@ public static BLangIndexBasedAccess createIndexAccessExpr(BLangExpression varRef return fieldAccessExpr; } - public static BLangFunction createInitFunctionWithNilReturn(Location pos, String name, Name suffix) { + public static BLangFunction createInitFunctionWithNilReturn(@Nullable Location pos, String name, Name suffix) { BLangValueType typeNode = (BLangValueType) TreeBuilder.createValueTypeNode(); typeNode.pos = pos; typeNode.typeKind = TypeKind.NIL; @@ -818,7 +822,7 @@ static BLangServiceConstructorExpr createServiceConstructor(BLangService service return constExpr; } - public static BLangSimpleVariable createReceiver(Location pos, BType type) { + public static BLangSimpleVariable createReceiver(@Nullable Location pos, BType type) { BLangSimpleVariable receiver = (BLangSimpleVariable) TreeBuilder.createSimpleVariableNode(); receiver.pos = pos; IdentifierNode identifier = createIdentifier(pos, Names.SELF.getValue()); @@ -1002,7 +1006,7 @@ static BLangMatchStatement createMatchStatement(BLangExpression expr, Location p } static BLangMatchClause createMatchClause(BLangExpression matchExpr, BLangBlockStmt blockStmt, - BLangExpression matchGuardExpr, BLangMatchPattern... patterns) { + @Nullable BLangExpression matchGuardExpr, BLangMatchPattern... patterns) { BLangMatchClause matchClause = (BLangMatchClause) TreeBuilder.createMatchClause(); matchClause.expr = matchExpr; matchClause.blockStmt = blockStmt; @@ -1014,6 +1018,7 @@ static BLangMatchClause createMatchClause(BLangExpression matchExpr, BLangBlockS return matchClause; } + @Nullable static BLangMatchGuard createMatchGuard(BLangExpression expr) { if (expr == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/AnnotationDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/AnnotationDesugar.java index 79b4af59f064..fc0770096a60 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/AnnotationDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/AnnotationDesugar.java @@ -32,6 +32,7 @@ import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.ConstantValueResolver; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; @@ -376,6 +377,7 @@ private String generateServiceHashCode(BLangClassDefinition serviceClass) { return String.format("%d", Objects.hash(serviceName, moduleId, lineRange)); } + @Nullable private BLangLambdaFunction defineAnnotations(BLangClassDefinition classDef, BLangPackage pkgNode, SymbolEnv env, PackageID pkgID, BSymbol owner) { BLangFunction function = null; @@ -566,6 +568,7 @@ private List getAnnotationList(AnnotatableNode node) .toList(); } + @Nullable private BLangLambdaFunction defineAnnotations(List annAttachments, BLangPackage pkgNode, SymbolEnv env, @@ -588,6 +591,7 @@ private BLangLambdaFunction defineAnnotations(List an return addReturnAndDefineLambda(function, mapLiteral, pkgNode, env, pkgID, owner); } + @Nullable private BLangLambdaFunction defineAnnotations(BLangTypeDefinition typeDef, BLangPackage pkgNode, SymbolEnv env, PackageID pkgID, BSymbol owner) { BLangFunction function = null; @@ -624,6 +628,7 @@ private BLangLambdaFunction defineAnnotations(BLangTypeDefinition typeDef, BLang return addReturnAndDefineLambda(function, mapLiteral, pkgNode, env, pkgID, owner); } + @Nullable public BLangLambdaFunction defineFieldAnnotations(List fields, Location pos, BLangPackage pkgNode, SymbolEnv env, PackageID pkgID, BSymbol owner) { @@ -658,6 +663,7 @@ public BLangLambdaFunction defineFieldAnnotations(List fiel return lambdaFunction; } + @Nullable private BLangLambdaFunction defineAnnotations(BLangFunction bLangFunction, BLangPackage pkgNode, SymbolEnv env, PackageID pkgID, BSymbol owner) { BLangFunction function = null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClassClosureDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClassClosureDesugar.java index 08d64bea1b74..4485f5303706 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClassClosureDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClassClosureDesugar.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; @@ -176,8 +177,11 @@ public class ClassClosureDesugar extends BLangNodeVisitor { private static final BVarSymbol CLOSURE_MAP_NOT_FOUND; private final int blockClosureMapCount = 1; + @Nullable private BLangClassDefinition classDef; + @Nullable private BLangNode result; + @Nullable private SymbolEnv env; private final SymbolTable symTable; @@ -217,7 +221,7 @@ public void visit(BLangPackage pkgNode) { } private void createClosureMapUpdateExpression(BLangClassDefinition classDef, - BVarSymbol blockMap, + @Nullable BVarSymbol blockMap, BVarSymbol classMapSymbol) { OCEDynamicEnvironmentData oceEnvData = classDef.oceEnvData; @@ -373,6 +377,7 @@ private BLangAssignment createAssignmentToClosureMap(BLangSimpleVariableDef varD return ASTBuilderUtil.createAssignmentStmt(varDefNode.pos, accessExpr, varDefNode.var.expr); } + @Nullable private BVarSymbol createMapSymbolIfAbsent(BLangNode node, int closureMapCount) { NodeKind kind = node.getKind(); return switch (kind) { @@ -730,6 +735,7 @@ public void visit(BLangSimpleVarRef varRefExpr) { classDef.oceEnvData.desugaredClosureVars.add(varRefExpr); } + @Nullable private BVarSymbol getVarMapSymbol(BVarSymbol symbol) { BVarSymbol mapSymbol = null; if (classDef.oceEnvData.closureFuncSymbols.contains(symbol)) { @@ -985,7 +991,7 @@ private BVarSymbol createMapSymbol(String mapName, SymbolEnv symbolEnv) { * @param varRefExpr closure variable reference to be updated * @param mapSymbol map symbol to be used */ - private void updateClosureVars(BLangSimpleVarRef varRefExpr, BVarSymbol mapSymbol) { + private void updateClosureVars(BLangSimpleVarRef varRefExpr, @Nullable BVarSymbol mapSymbol) { BVarSymbol selfSymbol = classDef.generatedInitFunction.receiver.symbol; BLangSimpleVarRef.BLangLocalVarRef localSelfVarRef = new BLangSimpleVarRef.BLangLocalVarRef(selfSymbol); localSelfVarRef.setBType(classDef.getBType()); @@ -1331,6 +1337,7 @@ public void visit(BLangMarkdownDocumentation bLangMarkdownDocumentation) { } // Rewrite methods + @Nullable @SuppressWarnings("unchecked") private E rewrite(E node, SymbolEnv env) { if (node == null) { @@ -1348,6 +1355,7 @@ private E rewrite(E node, SymbolEnv env) { return (E) resultNode; } + @Nullable @SuppressWarnings("unchecked") private E rewriteExpr(E node) { if (node == null) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureDesugar.java index 36c7f958a3b5..dcb942c83105 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureDesugar.java @@ -24,6 +24,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.Scope; @@ -207,6 +208,7 @@ public class ClosureDesugar extends BLangNodeVisitor { private SymbolResolver symResolver; private final SymbolTable symTable; private SymbolEnv env; + @Nullable private BLangNode result; private final Types types; private final Desugar desugar; @@ -328,7 +330,7 @@ private void createClosureMapUpdateExpression(BLangClassDefinition classDef, } // TODO: filter out only the needed variables, otherwise OCE has indrect access to all block level - private void addClosureMapToInit(BLangClassDefinition classDef, BVarSymbol mapSymbol) { + private void addClosureMapToInit(BLangClassDefinition classDef, @Nullable BVarSymbol mapSymbol) { OCEDynamicEnvironmentData oceData = classDef.oceEnvData; @@ -762,6 +764,7 @@ private BLangAssignment createAssignmentToClosureMap(BLangSimpleVariableDef varD return ASTBuilderUtil.createAssignmentStmt(varDefNode.pos, accessExpr, varDefNode.var.expr); } + @Nullable private BVarSymbol findClosureMapSymbol(int absoluteLevel) { SymbolEnv symbolEnv = env; while (symbolEnv.node.getKind() != NodeKind.PACKAGE) { @@ -773,6 +776,7 @@ private BVarSymbol findClosureMapSymbol(int absoluteLevel) { throw new IllegalStateException("Failed to find the closure symbol defined scope"); } + @Nullable private BVarSymbol createMapSymbolIfAbsent(BLangNode node, int closureMapCount) { NodeKind kind = node.getKind(); return switch (kind) { @@ -2142,6 +2146,7 @@ public void visit(BLangMarkdownDocumentation bLangMarkdownDocumentation) { } // Rewrite methods + @Nullable @SuppressWarnings("unchecked") private E rewrite(E node, SymbolEnv env) { if (node == null) { @@ -2176,6 +2181,7 @@ private E rewriteExpr(E node, SymbolEnv env) { return (E) resultNode; } + @Nullable @SuppressWarnings("unchecked") private E rewriteExpr(E node) { if (node == null) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java index 5d091d631269..dc2a868b1dd4 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java @@ -25,6 +25,7 @@ import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.Scope; @@ -230,6 +231,7 @@ public class ClosureGenerator extends BLangNodeVisitor { private Queue annotationClosureReferences; private final SymbolTable symTable; private SymbolEnv env; + @Nullable private BLangNode result; private final SymbolResolver symResolver; private final AnnotationDesugar annotationDesugar; @@ -1789,8 +1791,9 @@ public void visit(BLangMarkdownDocumentation bLangMarkdownDocumentation) { // Rewrite methods + @Nullable @SuppressWarnings("unchecked") - private E rewrite(E node, SymbolEnv env) { + private E rewrite(@Nullable E node, SymbolEnv env) { if (node == null) { return null; } @@ -1822,6 +1825,7 @@ private List rewrite(List nodeList, SymbolEnv env) { return nodeList; } + @Nullable @SuppressWarnings("unchecked") private E rewriteExpr(E node) { if (node == null) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ConstantPropagation.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ConstantPropagation.java index 1cb329d9089e..8e1f22e3555b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ConstantPropagation.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ConstantPropagation.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; import org.ballerinalang.model.tree.statements.VariableDefinitionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BConstantSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; @@ -200,6 +201,7 @@ public class ConstantPropagation extends BLangNodeVisitor { private static final CompilerContext.Key CONSTANT_PROPAGATION_KEY = new CompilerContext.Key<>(); + @Nullable private BLangNode result; private final Types types; @@ -1274,6 +1276,7 @@ public void visit(BLangReFlagExpression reFlagExpression) { result = reFlagExpression; } + @Nullable @SuppressWarnings("unchecked") E rewrite(E node) { if (node == null) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/DeclarativeAuthDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/DeclarativeAuthDesugar.java index 2b8533ea8cf3..3670266b85a2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/DeclarativeAuthDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/DeclarativeAuthDesugar.java @@ -19,6 +19,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.tree.NodeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; @@ -187,6 +188,7 @@ void addAuthDesugarFunctionInvocation(BLangFunction functionNode, SymbolEnv env, result.var.symbol = resultSymbol; } + @Nullable private BPackageSymbol getPackageSymbol(SymbolEnv env, String packageName) { // This resolves the package symbol when the code have an import relevant to the particular service for (BLangImportPackage pkg : env.enclPkg.imports) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java index b3542dff2c94..fdddbe690a0f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java @@ -39,6 +39,7 @@ import org.ballerinalang.model.tree.types.TypeNode; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.BLangCompilerConstants; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLocation; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.parser.NodeCloner; @@ -396,6 +397,7 @@ public class Desugar extends BLangNodeVisitor { private final Types types; private Names names; private final ServiceDesugar serviceDesugar; + @Nullable private BLangNode result; private final NodeCloner nodeCloner; private final SemanticAnalyzer semanticAnalyzer; @@ -406,6 +408,7 @@ public class Desugar extends BLangNodeVisitor { private final LargeMethodSplitter largeMethodSplitter; public Deque enclLocks = new ArrayDeque<>(); + @Nullable private BLangOnFailClause onFailClause; private boolean shouldReturnErrors; private int transactionBlockCount; @@ -433,13 +436,16 @@ public class Desugar extends BLangNodeVisitor { // Safe navigation related variables private Deque matchStmtStack = new ArrayDeque<>(); Deque accessExprStack = new ArrayDeque<>(); + @Nullable private BLangMatchClause successClause; + @Nullable private BLangAssignment safeNavigationAssignment; static boolean isJvmTarget = false; private Map> globalVariablesDependsOn; private final List matchStmtsForPattern = new ArrayList<>(); private final Map declaredVarDef = new HashMap<>(); + @Nullable private List inlineXMLNamespaces; private Map stmtsToBePropagatedToQuery = new HashMap<>(); // Reuse the strand annotation in isolated workers and start action @@ -612,6 +618,7 @@ private void addRequiredParamsToGeneratedInitFunction(BLangFunction initFunction } } + @Nullable private BLangExpression createRequiredParamExpr(BLangExpression expr) { if (expr == null) { return null; @@ -1699,7 +1706,7 @@ public void visit(BLangErrorVariableDef varDefNode) { * */ private void createVarDefStmts(BLangTupleVariable parentTupleVariable, BLangBlockStmt parentBlockStmt, - BVarSymbol tupleVarSymbol, BLangIndexBasedAccess parentIndexAccessExpr) { + BVarSymbol tupleVarSymbol, @Nullable BLangIndexBasedAccess parentIndexAccessExpr) { final List memberVars = parentTupleVariable.memberVariables; for (int index = 0; index < memberVars.size(); index++) { @@ -1774,7 +1781,7 @@ private void createVarDefStmts(BLangTupleVariable parentTupleVariable, BLangBloc * */ private void createVarDefStmts(BLangRecordVariable parentRecordVariable, BLangBlockStmt parentBlockStmt, - BVarSymbol recordVarSymbol, BLangIndexBasedAccess parentIndexAccessExpr) { + BVarSymbol recordVarSymbol, @Nullable BLangIndexBasedAccess parentIndexAccessExpr) { List variableList = parentRecordVariable.variableList; for (BLangRecordVariableKeyValue recordFieldKeyValue : variableList) { @@ -1872,7 +1879,8 @@ private void createVarDefStmts(BLangRecordVariable parentRecordVariable, BLangBl * The var def statements are created by creating the reason() and detail() builtin methods. */ private void createVarDefStmts(BLangErrorVariable parentErrorVariable, BLangBlockStmt parentBlockStmt, - BVarSymbol errorVariableSymbol, BLangIndexBasedAccess parentIndexBasedAccess) { + BVarSymbol errorVariableSymbol, + @Nullable BLangIndexBasedAccess parentIndexBasedAccess) { BVarSymbol convertedErrorVarSymbol; if (parentIndexBasedAccess != null) { @@ -2208,6 +2216,7 @@ private BLangExpression createErrorDetailVar(BLangErrorVariable.BLangErrorDetail return detailEntryVar; } + @Nullable private BLangExpression constructStringTemplateConcatExpression(List exprs) { BLangExpression concatExpr = null; BLangExpression currentExpr; @@ -2247,7 +2256,7 @@ private BLangInvocation getToStringInvocationOnExpr(BLangExpression expression) // TODO: Move the logic on binding patterns to a seperate class private BLangInvocation generateErrorDetailBuiltinFunction(Location pos, BVarSymbol errorVarySymbol, - BLangIndexBasedAccess parentIndexBasedAccess) { + @Nullable BLangIndexBasedAccess parentIndexBasedAccess) { BLangExpression onExpr = parentIndexBasedAccess != null ? parentIndexBasedAccess : ASTBuilderUtil.createVariableRef(pos, errorVarySymbol); @@ -2255,9 +2264,9 @@ private BLangInvocation generateErrorDetailBuiltinFunction(Location pos, BVarSym return createLangLibInvocationNode(ERROR_DETAIL_FUNCTION_NAME, onExpr, new ArrayList<>(), null, pos); } - private BLangInvocation generateErrorMessageBuiltinFunction(Location pos, BType reasonType, - BVarSymbol errorVarSymbol, - BLangIndexBasedAccess parentIndexBasedAccess) { + private BLangInvocation generateErrorMessageBuiltinFunction( + Location pos, BType reasonType, BVarSymbol errorVarSymbol, + @Nullable BLangIndexBasedAccess parentIndexBasedAccess) { BLangExpression onExpr; if (parentIndexBasedAccess != null) { onExpr = parentIndexBasedAccess; @@ -2269,7 +2278,7 @@ private BLangInvocation generateErrorMessageBuiltinFunction(Location pos, BType private BLangInvocation generateErrorCauseLanglibFunction(Location pos, BType causeType, BVarSymbol errorVarSymbol, - BLangIndexBasedAccess parentIndexBasedAccess) { + @Nullable BLangIndexBasedAccess parentIndexBasedAccess) { BLangExpression onExpr; if (parentIndexBasedAccess != null) { onExpr = parentIndexBasedAccess; @@ -2472,7 +2481,7 @@ private BTupleType getStringAnyTupleType() { */ private void createSimpleVarDefStmt(BLangSimpleVariable simpleVariable, BLangBlockStmt parentBlockStmt, BLangLiteral indexExpr, BVarSymbol tupleVarSymbol, - BLangIndexBasedAccess parentArrayAccessExpr) { + @Nullable BLangIndexBasedAccess parentArrayAccessExpr) { Name varName = names.fromIdNode(simpleVariable.name); if (varName == Names.IGNORE) { @@ -2667,7 +2676,8 @@ private BLangInvocation createLengthInvocation(Location pos, BLangExpression col * */ private void createVarRefAssignmentStmts(BLangTupleVarRef parentTupleVariable, BLangBlockStmt parentBlockStmt, - BVarSymbol tupleVarSymbol, BLangIndexBasedAccess parentIndexAccessExpr) { + BVarSymbol tupleVarSymbol, + @Nullable BLangIndexBasedAccess parentIndexAccessExpr) { final List expressions = parentTupleVariable.expressions; for (int index = 0; index < expressions.size(); index++) { @@ -2741,7 +2751,7 @@ private void createVarRefAssignmentStmts(BLangTupleVarRef parentTupleVariable, B */ private void createAssignmentStmt(BLangExpression accessibleExpression, BLangBlockStmt parentBlockStmt, BLangExpression indexExpr, BVarSymbol tupleVarSymbol, - BLangIndexBasedAccess parentArrayAccessExpr) { + @Nullable BLangIndexBasedAccess parentArrayAccessExpr) { if (accessibleExpression.getKind() == NodeKind.SIMPLE_VARIABLE_REF) { Name varName = names.fromIdNode(((BLangSimpleVarRef) accessibleExpression).variableName); @@ -2766,7 +2776,7 @@ private BLangExpression createIndexBasedAccessExpr(BType varType, Location varLocation, BLangExpression indexExpr, BVarSymbol tupleVarSymbol, - BLangIndexBasedAccess parentExpr) { + @Nullable BLangIndexBasedAccess parentExpr) { BLangIndexBasedAccess arrayAccess = ASTBuilderUtil.createIndexBasesAccessExpr(varLocation, symTable.anyType, tupleVarSymbol, indexExpr); @@ -2830,7 +2840,8 @@ public void visit(BLangErrorDestructure errorDestructure) { } private void createVarRefAssignmentStmts(BLangRecordVarRef parentRecordVarRef, BLangBlockStmt parentBlockStmt, - BVarSymbol recordVarSymbol, BLangIndexBasedAccess parentIndexAccessExpr) { + BVarSymbol recordVarSymbol, + @Nullable BLangIndexBasedAccess parentIndexAccessExpr) { final List variableRefList = parentRecordVarRef.recordRefFields; for (BLangRecordVarRefKeyValue varRefKeyValue : variableRefList) { BLangExpression expression = varRefKeyValue.variableReference; @@ -2925,7 +2936,8 @@ private void createVarRefAssignmentStmts(BLangRecordVarRef parentRecordVarRef, B } private void createVarRefAssignmentStmts(BLangErrorVarRef parentErrorVarRef, BLangBlockStmt parentBlockStmt, - BVarSymbol errorVarySymbol, BLangIndexBasedAccess parentIndexAccessExpr) { + BVarSymbol errorVarySymbol, + @Nullable BLangIndexBasedAccess parentIndexAccessExpr) { if (parentErrorVarRef.message != null && names.fromIdNode(((BLangSimpleVarRef) parentErrorVarRef.message).variableName) != Names.IGNORE) { BLangAssignment message = ASTBuilderUtil.createAssignmentStmt(parentBlockStmt.pos, parentBlockStmt); @@ -3311,6 +3323,7 @@ BLangInvocation createRetryManagerShouldRetryInvocation(Location location, return shouldRetryInvocation; } + @Nullable private BAttachedFunction getShouldRetryFunc(BVarSymbol retryManagerSymbol) { BObjectTypeSymbol typeSymbol = (BObjectTypeSymbol) retryManagerSymbol.type.tsymbol; for (BAttachedFunction bAttachedFunction : typeSymbol.attachedFuncs) { @@ -3724,6 +3737,7 @@ private BLangIf createIfElseStmtFromMatchPattern(BLangMatchPattern matchPattern, return ASTBuilderUtil.createIfElseStmt(pos, condition, successBody, null); } + @Nullable private BLangExpression createConditionForMatchPattern(BLangMatchPattern matchPattern, BLangSimpleVarRef matchExprVarRef) { NodeKind patternKind = matchPattern.getKind(); @@ -3855,6 +3869,7 @@ private BLangExpression createConditionForListBindingPattern(BLangListBindingPat return statementExpression; } + @Nullable private BLangExpression createConditionForListMemberPattern(int index, BLangBindingPattern bindingPattern, BLangSimpleVariableDef tempCastVarDef, BLangBlockStmt blockStmt, BType type, @@ -3870,6 +3885,7 @@ private BLangExpression createConditionForListMemberPattern(int index, BLangBind return createVarCheckCondition(bindingPattern, tempVarRef); } + @Nullable private BLangExpression createVarCheckCondition(BLangBindingPattern bindingPattern, BLangSimpleVarRef varRef) { NodeKind bindingPatternKind = bindingPattern.getKind(); return switch (bindingPatternKind) { @@ -3956,6 +3972,7 @@ private BLangExpression createVarCheckConditionForListBindingPattern(BLangListBi return statementExpression; } + @Nullable private BLangExpression createConditionForVarBindingPatternMatchPattern(BLangVarBindingPatternMatchPattern varBindingPatternMatchPattern, BLangSimpleVarRef matchExprVarRef) { @@ -4263,6 +4280,7 @@ private BLangExpression createConditionForListMatchPattern(BLangListMatchPattern return statementExpression; } + @Nullable private BLangExpression createConditionForListMemberPattern(int index, BLangMatchPattern listMemberMatchPattern, BLangSimpleVariableDef tempCastVarDef, BLangBlockStmt blockStmt, BType type, @@ -4401,6 +4419,7 @@ private BLangExpression createConditionForFieldMatchPatterns(List args, - BType retType, - Location pos) { + BLangExpression onExpr, + List args, + @Nullable BType retType, + Location pos) { BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode(); invocationNode.pos = pos; BLangIdentifier name = (BLangIdentifier) TreeBuilder.createIdentifierNode(); @@ -9239,8 +9266,9 @@ private BLangExpression visitCloneReadonly(BLangExpression expr, BType lhsType) return types.addConversionExprIfRequired(cloneInvok, lhsType); } + @Nullable @SuppressWarnings("unchecked") - E rewrite(E node, SymbolEnv env) { + E rewrite(@Nullable E node, SymbolEnv env) { if (node == null) { return null; } @@ -9261,6 +9289,7 @@ E rewrite(E node, SymbolEnv env) { return (E) resultNode; } + @Nullable @SuppressWarnings("unchecked") E rewriteExpr(E node) { if (node == null) { @@ -9285,6 +9314,7 @@ E rewriteExpr(E node) { return (E) resultNode; } + @Nullable @SuppressWarnings("unchecked") E rewrite(E statement, SymbolEnv env) { if (statement == null) { @@ -9621,7 +9651,8 @@ private void reorderArguments(BLangInvocation iExpr) { iExpr.restArgs = new ArrayList(1) {{ add(stmtExpression); }}; } - private void reorderNamedArgs(BLangInvocation iExpr, BInvokableSymbol invokableSymbol, BLangExpression varargRef) { + private void reorderNamedArgs(BLangInvocation iExpr, BInvokableSymbol invokableSymbol, + @Nullable BLangExpression varargRef) { List args = new ArrayList<>(); Map namedArgs = new LinkedHashMap<>(); iExpr.requiredArgs.stream() @@ -9716,7 +9747,7 @@ private void reorderNamedArgs(BLangInvocation iExpr, BInvokableSymbol invokableS private void setFieldsForIncRecordLiterals(Map namedArgs, List incRecordLiterals, - BLangRecordLiteral incRecordParamAllowAdditionalFields) { + @Nullable BLangRecordLiteral incRecordParamAllowAdditionalFields) { for (String name : namedArgs.keySet()) { boolean isAdditionalField = true; BLangNamedArgsExpression expr = (BLangNamedArgsExpression) namedArgs.get(name); @@ -9909,8 +9940,8 @@ private BLangRecordTypeNode createRecordTypeNode(BLangErrorVariable errorVariabl return TypeDefBuilderHelper.createRecordTypeNode(fieldList, detailType, errorVariable.pos); } - private BType createDetailType(List detail, - BLangSimpleVariable restDetail, int errorNo, Location pos) { + private BType createDetailType(@Nullable List detail, + @Nullable BLangSimpleVariable restDetail, int errorNo, Location pos) { BRecordType detailRecordType = createAnonRecordType(pos); if (restDetail == null) { @@ -10190,7 +10221,7 @@ private boolean isMapJson(BType originalType, boolean fromMap) { || ((originalType.tag == TypeTags.JSON) && fromMap); } - private void pushToMatchStatementStack(BLangMatchStatement matchStmt, BLangMatchClause successClause, + private void pushToMatchStatementStack(BLangMatchStatement matchStmt, @Nullable BLangMatchClause successClause, Location pos) { this.matchStmtStack.push(matchStmt); if (this.successClause != null) { @@ -10524,6 +10555,7 @@ protected boolean isMappingOrObjectConstructorOrObjInit(BLangExpression expressi }; } + @Nullable private BType getRestType(BInvokableSymbol invokableSymbol) { if (invokableSymbol != null && invokableSymbol.restParam != null) { return invokableSymbol.restParam.type; @@ -10531,6 +10563,7 @@ private BType getRestType(BInvokableSymbol invokableSymbol) { return null; } + @Nullable private BType getRestType(BLangFunction function) { if (function != null && function.restParam != null) { return function.restParam.getBType(); @@ -10538,6 +10571,7 @@ private BType getRestType(BLangFunction function) { return null; } + @Nullable private BVarSymbol getRestSymbol(BLangFunction function) { if (function != null && function.restParam != null) { return function.restParam.symbol; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java index f7432f8b63ea..66fac7555406 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.TreeBuilder; import org.ballerinalang.model.tree.IdentifierNode; import org.ballerinalang.model.tree.TopLevelNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.model.Scope; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; @@ -74,7 +75,9 @@ public class MockDesugar { private final SymbolTable symTable; private final SymbolResolver symResolver; private BLangPackage bLangPackage; + @Nullable private BLangFunction originalFunction; + @Nullable private BInvokableSymbol importFunction; private String mockFnObjectName; private final String testPackageSymbol = "ballerina/test"; @@ -175,6 +178,7 @@ private BLangFunction generateMockFunction(String functionName) { return generatedMock; } + @Nullable private BLangFunction getOriginalFunction(String functionName) { List functionList = bLangPackage.getFunctions(); for (BLangFunction function : functionList) { @@ -185,6 +189,7 @@ private BLangFunction getOriginalFunction(String functionName) { return null; } + @Nullable private BInvokableSymbol getImportFunction(String functionName, String packageName) { BInvokableSymbol bInvokableSymbol = getInvokableSymbol(functionName, packageName, this.bLangPackage.getImports()); @@ -197,6 +202,7 @@ private BInvokableSymbol getImportFunction(String functionName, String packageNa return bInvokableSymbol; } + @Nullable private BInvokableSymbol getInvokableSymbol(String functionName, String packageName, List importList) { // Loop through each BLangImportPackage @@ -238,6 +244,7 @@ private List generateImportRequiredParams() { return bLangSimpleVariables; } + @Nullable private BLangSimpleVariable generateRestParam() { BLangSimpleVariable bLangSimpleVariable = null; @@ -444,6 +451,7 @@ private BLangInvocation generateBLangInvocation() { } // This function synthesizes the Ballerina equivalent of : `MockHandler()` + @Nullable private BInvokableSymbol getMockHandlerInvokableSymbol() { List packageList = bLangPackage.getTestablePkg().getImports(); for (BLangImportPackage importPackage : packageList) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java index e114284e819d..72a2a2633a18 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java @@ -28,6 +28,7 @@ import org.ballerinalang.model.tree.statements.VariableDefinitionNode; import org.ballerinalang.model.tree.types.TypeNode; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; @@ -243,6 +244,7 @@ public class QueryDesugar extends BLangNodeVisitor { private static final Name QUERY_PIPELINE_DISTINCT_ERROR_NAME = new Name("CompleteEarlyError"); private static final Name QUERY_DISTINCT_UNION_ERROR_NAME = new Name("QueryErrorTypes"); private static final CompilerContext.Key QUERY_DESUGAR_KEY = new CompilerContext.Key<>(); + @Nullable private BLangExpression onConflictExpr; private BVarSymbol currentFrameSymbol; private BLangBlockFunctionBody currentQueryLambdaBody; @@ -259,6 +261,7 @@ public class QueryDesugar extends BLangNodeVisitor { private boolean withinQuery = false; private boolean withinLambdaOrArrowFunc = false; private HashSet checkedErrorList; + @Nullable private BLangNode result; private QueryDesugar(CompilerContext context) { @@ -1143,7 +1146,7 @@ private BLangLambdaFunction createActionLambda(Location pos) { */ private BLangLambdaFunction createLambdaFunction(Location pos, TypeNode returnType, - BLangReturn returnNode, + @Nullable BLangReturn returnNode, boolean isPassthrough) { // function(_Frame frame) ... and ref to frame BType frameType = getFrameTypeSymbol().type; @@ -1218,7 +1221,7 @@ private BLangVariableReference getStreamFunctionVariableRef(BLangBlockStmt block */ private BLangVariableReference getStreamFunctionVariableRef(BLangBlockStmt blockStmt, Name functionName, - BType type, + @Nullable BType type, List requiredArgs, Location pos) { String name = getNewVarName(); @@ -2802,7 +2805,7 @@ private void acceptNode(BLangNode node) { node.accept(this); } - E rewrite(E node) { + @Nullable E rewrite(E node) { if (node == null) { return null; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnostic.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnostic.java index cac6cfa33dd8..9996abf9ae48 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnostic.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnostic.java @@ -22,6 +22,7 @@ import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticProperty; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Collections; @@ -47,7 +48,7 @@ public BLangDiagnostic(Location location, String msg, DiagnosticInfo diagnosticI } public BLangDiagnostic(Location location, String msg, DiagnosticInfo diagnosticInfo, - DiagnosticCode diagnosticCode, List> properties) { + @Nullable DiagnosticCode diagnosticCode, List> properties) { this.location = location; this.msg = msg; this.diagnosticInfo = diagnosticInfo; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnosticLocation.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnosticLocation.java index cdeedcecc5fe..179e994abca4 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnosticLocation.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnosticLocation.java @@ -21,6 +21,7 @@ import io.ballerina.tools.text.LinePosition; import io.ballerina.tools.text.LineRange; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -41,8 +42,8 @@ public BLangDiagnosticLocation(String filePath, int startLine, int endLine, int this(filePath, startLine, endLine, startColumn, endColumn, 0, 0); } - public BLangDiagnosticLocation(String filePath, int startLine, int endLine, int startColumn, int endColumn, - int startOffset, int length) { + public BLangDiagnosticLocation(@Nullable String filePath, int startLine, int endLine, int startColumn, + int endColumn, int startOffset, int length) { this.filePath = filePath; this.startLine = startLine; this.endLine = endLine; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnosticLog.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnosticLog.java index 8e4b5940b486..1c52433107e0 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnosticLog.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/BLangDiagnosticLog.java @@ -30,6 +30,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.util.diagnostic.DiagnosticLog; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.PackageCache; import org.wso2.ballerinalang.compiler.diagnostic.properties.BCollectionProperty; import org.wso2.ballerinalang.compiler.diagnostic.properties.BNumericProperty; @@ -97,7 +98,7 @@ public void setCurrentPackageId(PackageID packageID) { * @param code Error code * @param args Parameters associated with the error */ - public void error(Location location, DiagnosticCode code, Object... args) { + public void error(@Nullable Location location, DiagnosticCode code, Object... args) { String msg = formatMessage(ERROR_PREFIX, code, args); reportDiagnostic((ModuleDescriptor) null, code, location, msg, DiagnosticSeverity.ERROR, args); } @@ -192,9 +193,9 @@ public void logDiagnostic(DiagnosticSeverity severity, PackageID pkgId, Location @Override public void logDiagnostic(DiagnosticSeverity severity, - ModuleDescriptor moduleDescriptor, - Location location, - CharSequence message) { + @Nullable ModuleDescriptor moduleDescriptor, + Location location, + CharSequence message) { reportDiagnostic(moduleDescriptor, null, location, message.toString(), severity, new Object[] {}); } @@ -219,8 +220,8 @@ private String formatMessage(String prefix, DiagnosticCode code, Object[] args) return MessageFormat.format(msgKey, args); } - private void reportDiagnostic(ModuleDescriptor moduleDescriptor, DiagnosticCode diagnosticCode, Location location, - String msg, DiagnosticSeverity severity, Object[] args) { + private void reportDiagnostic(@Nullable ModuleDescriptor moduleDescriptor, @Nullable DiagnosticCode diagnosticCode, + Location location, String msg, DiagnosticSeverity severity, Object[] args) { PackageID pkgId = null; if (moduleDescriptor != null) { pkgId = new PackageID(new Name(moduleDescriptor.org().value()), @@ -230,8 +231,8 @@ private void reportDiagnostic(ModuleDescriptor moduleDescriptor, DiagnosticCode reportDiagnostic(pkgId, diagnosticCode, location, msg, severity, args); } - private void reportDiagnostic(PackageID packageID, DiagnosticCode diagnosticCode, Location location, - String msg, DiagnosticSeverity severity, Object[] args) { + private void reportDiagnostic(@Nullable PackageID packageID, @Nullable DiagnosticCode diagnosticCode, + Location location, String msg, DiagnosticSeverity severity, Object[] args) { if (severity == DiagnosticSeverity.ERROR) { this.errorCount++; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/CompilerBadSadDiagnostic.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/CompilerBadSadDiagnostic.java index 29049e20dba1..8fe0bdd98b4e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/CompilerBadSadDiagnostic.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/diagnostic/CompilerBadSadDiagnostic.java @@ -23,6 +23,7 @@ import io.ballerina.tools.diagnostics.DiagnosticProperty; import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -71,6 +72,7 @@ public String message() { return msg; } + @Nullable @Override public List> properties() { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/Patten.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/Patten.java index fad11018d77c..2b7adf2380d8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/Patten.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/Patten.java @@ -3,6 +3,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.repository.CompilerInput; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.packaging.converters.Converter; import org.wso2.ballerinalang.compiler.packaging.converters.StringConverter; @@ -59,7 +60,7 @@ public static Part path(String... path) { return new Part(path); } - public Stream convert(Converter converter, PackageID packageID) { + public Stream convert(Converter converter, @Nullable PackageID packageID) { Stream aggregate = Stream.of(converter.start()); for (Part part : parts) { if (part == LATEST_VERSION_DIR) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/BinaryRepo.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/BinaryRepo.java index 9d4c759689e2..38dc756460af 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/BinaryRepo.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/BinaryRepo.java @@ -2,6 +2,7 @@ import org.ballerinalang.compiler.CompilerPhase; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.packaging.Patten; import org.wso2.ballerinalang.compiler.packaging.Patten.Part; import org.wso2.ballerinalang.compiler.packaging.converters.Converter; @@ -25,7 +26,7 @@ public BinaryRepo(Path pathToHiddenDir, CompilerPhase compilerPhase) { this(pathToHiddenDir, Path.of(ProjectDirConstants.DOT_BALLERINA_REPO_DIR_NAME), compilerPhase); } - public BinaryRepo(ZipConverter converter, CompilerPhase compilerPhase) { + public BinaryRepo(@Nullable ZipConverter converter, CompilerPhase compilerPhase) { this.converter = converter; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/HomeRepo.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/HomeRepo.java index 187eb95c94cc..11eca6fa2183 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/HomeRepo.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/HomeRepo.java @@ -1,6 +1,7 @@ package org.wso2.ballerinalang.compiler.packaging.repo; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.packaging.Patten; import org.wso2.ballerinalang.compiler.packaging.converters.Converter; import org.wso2.ballerinalang.compiler.packaging.converters.PathConverter; @@ -11,7 +12,7 @@ * Calculate path pattens for home repo. */ public class HomeRepo extends NonSysRepo { - public HomeRepo(Converter converter) { + public HomeRepo(@Nullable Converter converter) { super(converter); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/NonSysRepo.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/NonSysRepo.java index 63c25ae2052a..ae830e44f95a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/NonSysRepo.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/NonSysRepo.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.packaging.repo; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.packaging.Patten; import org.wso2.ballerinalang.compiler.packaging.converters.Converter; @@ -32,7 +33,7 @@ public abstract class NonSysRepo implements Repo { private final Converter converter; - public NonSysRepo(Converter converter) { + public NonSysRepo(@Nullable Converter converter) { this.converter = converter; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/ObjRepo.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/ObjRepo.java index 5f16d7534a4b..ee03fe224193 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/ObjRepo.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/ObjRepo.java @@ -1,6 +1,7 @@ package org.wso2.ballerinalang.compiler.packaging.repo; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.packaging.Patten; import org.wso2.ballerinalang.compiler.packaging.converters.Converter; import org.wso2.ballerinalang.compiler.packaging.converters.PathConverter; @@ -11,7 +12,7 @@ * Calculate bala path pattens in project. */ public class ObjRepo extends NonSysRepo { - public ObjRepo(Converter converter) { + public ObjRepo(@Nullable Converter converter) { super(converter); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java index 00f24176b842..5d5956c109ae 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java @@ -66,7 +66,7 @@ public Patten calculate(PackageID moduleID) { this.manifest.getDependencies().stream() .filter(dep -> dep.getOrgName().equals(moduleID.orgName.value) && dep.getModuleName().equals(moduleID.name.value) && - null != dep.getMetadata().getPath()) + dep.getMetadata().getPath().isPresent()) .findFirst(); // if dependency is not found in toml @@ -75,18 +75,18 @@ public Patten calculate(PackageID moduleID) { } Dependency dep = tomlDependency.get(); - Path balaPath = dep.getMetadata().getPath(); + Path balaPath = dep.getMetadata().getPath().orElseThrow(); // if bala file does not exists if (Files.notExists(balaPath)) { throw new BLangCompilerException("bala file for dependency [" + dep.getModuleID() + "] does not exists: " + - dep.getMetadata().getPath().toAbsolutePath().normalize()); + dep.getMetadata().getPath().orElseThrow().toAbsolutePath().normalize()); } // if bala file is not a file if (!Files.isRegularFile(balaPath)) { throw new BLangCompilerException("bala file for dependency [" + dep.getModuleID() + "] is not a file: " + - dep.getMetadata().getPath().toAbsolutePath().normalize()); + dep.getMetadata().getPath().orElseThrow().toAbsolutePath().normalize()); } // update version of the dependency from the current(root) project diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/ProjectSourceRepo.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/ProjectSourceRepo.java index 5be54c01d05b..f0c22e2523e0 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/ProjectSourceRepo.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/ProjectSourceRepo.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.toml.model.Manifest; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.packaging.Patten; import org.wso2.ballerinalang.compiler.packaging.converters.Converter; import org.wso2.ballerinalang.compiler.packaging.converters.PathConverter; @@ -34,7 +35,7 @@ public class ProjectSourceRepo extends NonSysRepo { private final boolean testEnabled; private final Manifest manifest; - public ProjectSourceRepo(Converter converter, Manifest manifest, boolean testEnabled) { + public ProjectSourceRepo(@Nullable Converter converter, Manifest manifest, boolean testEnabled) { super(converter); this.testEnabled = testEnabled; this.manifest = manifest; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/BLangNodeBuilder.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/BLangNodeBuilder.java index 6acdf0aaf800..279ab153cb60 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/BLangNodeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/BLangNodeBuilder.java @@ -284,6 +284,7 @@ import org.ballerinalang.model.tree.statements.VariableDefinitionNode; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.PackageCache; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLocation; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; @@ -542,6 +543,7 @@ public class BLangNodeBuilder extends NodeTransformer { private final PackageID packageID; private final String currentCompUnitName; + @Nullable private BLangCompilationUnit currentCompilationUnit; private final BLangAnonymousModelHelper anonymousModelHelper; private final BLangMissingNodesHelper missingNodesHelper; @@ -586,15 +588,18 @@ public BLangNode transform(IdentifierToken identifierToken) { return this.createIdentifier(getPosition(identifierToken), identifierToken); } + @Nullable private Optional getDocumentationString(Optional metadataNode) { return metadataNode.map(MetadataNode::documentationString).orElse(null); } + @Nullable private NodeList getAnnotations(Optional metadataNode) { return metadataNode.map(MetadataNode::annotations).orElse(null); } - private Location getPosition(Node node) { + @Nullable + private Location getPosition(@Nullable Node node) { if (node == null) { return null; } @@ -611,6 +616,7 @@ private Location getPosition(Node node) { textRange.length()); } + @Nullable private Location getPosition(Node startNode, Node endNode) { if (startNode == null || endNode == null) { return null; @@ -623,6 +629,7 @@ private Location getPosition(Node startNode, Node endNode) { startPos.offset(), endPos.offset(), startNodeTextRange.startOffset(), length); } + @Nullable private Location getPositionWithoutMetadata(Node node) { if (node == null) { return null; @@ -795,7 +802,7 @@ private BLangFunction createResourceFunctionNode(IdentifierToken accessorName, NodeList qualifierList, NodeList relativeResourcePath, FunctionSignatureNode methodSignature, - FunctionBodyNode functionBody) { + @Nullable FunctionBodyNode functionBody) { BLangResourceFunction bLFunction = (BLangResourceFunction) TreeBuilder.createResourceFunctionNode(); @@ -1089,7 +1096,7 @@ private BLangUserDefinedType deSugarTypeAsUserDefType(BLangType toIndirect) { return createUserDefinedType(pos, (BLangIdentifier) TreeBuilder.createIdentifierNode(), bLTypeDef.name); } - private BLangTypeDefinition createTypeDefinitionWithTypeNode(BLangType toIndirect, String originalName) { + private BLangTypeDefinition createTypeDefinitionWithTypeNode(BLangType toIndirect, @Nullable String originalName) { Location pos = toIndirect.pos; BLangTypeDefinition bLTypeDef = (BLangTypeDefinition) TreeBuilder.createTypeDefinition(); @@ -1564,8 +1571,9 @@ public BLangNode transform(FunctionDefinitionNode funcDefNode) { return bLFunction; } - private BLangFunction createFunctionNode(IdentifierToken funcName, NodeList qualifierList, - FunctionSignatureNode functionSignature, FunctionBodyNode functionBody) { + private BLangFunction createFunctionNode( + IdentifierToken funcName, NodeList qualifierList, + FunctionSignatureNode functionSignature, @Nullable FunctionBodyNode functionBody) { BLangFunction bLFunction = (BLangFunction) TreeBuilder.createFunctionNode(); @@ -2347,6 +2355,7 @@ private void populateArgsInvocation(NewExpressionNode expression, BLangInvocatio } } + @Nullable private Iterator getArgumentNodesIterator(NewExpressionNode expression) { Iterator argumentsIter = null; @@ -5463,7 +5472,7 @@ private void populateFuncSignature(BLangFunction bLFunction, FunctionSignatureNo } private BLangUnaryExpr createBLangUnaryExpr(Location location, - OperatorKind operatorKind, + @Nullable OperatorKind operatorKind, BLangExpression expr) { BLangUnaryExpr bLUnaryExpr = (BLangUnaryExpr) TreeBuilder.createUnaryExpressionNode(); bLUnaryExpr.pos = location; @@ -5472,7 +5481,7 @@ private BLangUnaryExpr createBLangUnaryExpr(Location location, return bLUnaryExpr; } - private BLangExpression createExpression(Node expression) { + private BLangExpression createExpression(@Nullable Node expression) { return (BLangExpression) createActionOrExpression(expression); } @@ -5653,7 +5662,7 @@ public BLangNode transform(ReBracedQuantifierNode reBracedQuantifierNode) { return createStringLiteral(quantifier, getPosition(reBracedQuantifierNode)); } - private void checkValidityOfOccurrences(String lhsValue, String rhsValue, Location pos) { + private void checkValidityOfOccurrences(String lhsValue, String rhsValue, @Nullable Location pos) { if (Long.parseLong(lhsValue) > Long.parseLong(rhsValue)) { dlog.error(pos, DiagnosticErrorCode.INVALID_QUANTIFIER_MINIMUM); } @@ -5984,8 +5993,9 @@ private BLangSimpleVariable createSimpleVar(Token name, Node type, NodeList annotations) { + private BLangSimpleVariable createSimpleVar( + @Nullable Token name, Node typeName, @Nullable Node initializer, + @Nullable Token visibilityQualifier, NodeList annotations) { BLangSimpleVariable bLSimpleVar = (BLangSimpleVariable) TreeBuilder.createSimpleVariableNode(); bLSimpleVar.setName(this.createIdentifier(name)); bLSimpleVar.name.pos = getPosition(name); @@ -6023,11 +6033,11 @@ private boolean isDeclaredWithVar(Node typeNode) { return false; } - private BLangIdentifier createIdentifier(Token token) { + private BLangIdentifier createIdentifier(@Nullable Token token) { return createIdentifier(getPosition(token), token); } - private BLangIdentifier createIdentifier(Location pos, Token token) { + private BLangIdentifier createIdentifier(@Nullable Location pos, @Nullable Token token) { return createIdentifier(pos, token, false); } @@ -6047,7 +6057,7 @@ private BLangIdentifier createIdentifier(Location pos, Token token, boolean isXM return createIdentifier(pos, identifierName); } - private BLangIdentifier createIdentifier(Location pos, String value) { + private BLangIdentifier createIdentifier(@Nullable Location pos, @Nullable String value) { return createIdentifier(pos, value, value); } @@ -6250,7 +6260,8 @@ private BLangLiteral createStringLiteral(String value, Location pos) { return strLiteral; } - private BLangType createTypeNode(Node type) { + @Nullable + private BLangType createTypeNode(@Nullable Node type) { if (type instanceof BuiltinSimpleNameReferenceNode || type.kind() == SyntaxKind.NIL_TYPE_DESC) { return createBuiltInTypeNode(type); } else if (type.kind() == SyntaxKind.QUALIFIED_NAME_REFERENCE || type.kind() == SyntaxKind.IDENTIFIER_TOKEN) { @@ -6279,6 +6290,7 @@ private BLangType createTypeNode(Node type) { return (BLangType) type.apply(this); } + @Nullable private BLangType createBuiltInTypeNode(Node type) { String typeText; if (type.kind() == SyntaxKind.NIL_TYPE_DESC) { @@ -6373,6 +6385,7 @@ private BLangIdentifier[] createBLangNameReference(Node node) { return new BLangIdentifier[]{pkgAlias, name}; } + @Nullable private BLangMarkdownDocumentation createMarkdownDocumentationAttachment(Optional markdownDocumentationNode) { if (markdownDocumentationNode == null || !markdownDocumentationNode.isPresent()) { return null; @@ -6651,6 +6664,7 @@ private DocumentationReferenceType stringToRefType(String refTypeName) { }; } + @Nullable private Object getIntegerLiteral(Node literal, String nodeValue) { SyntaxKind literalTokenKind = ((BasicLiteralNode) literal).literalToken().kind(); if (literalTokenKind == SyntaxKind.DECIMAL_INTEGER_LITERAL_TOKEN) { @@ -6859,7 +6873,7 @@ private BLangListConstructorSpreadOpExpr createSpreadMemberExpr(Node expr, Locat return spreadOpExpr; } - private boolean withinByteRange(Object num) { + private boolean withinByteRange(@Nullable Object num) { if (num instanceof Long l) { return l <= 255 && l >= 0; } @@ -6872,6 +6886,7 @@ private class SimpleVarBuilder { private boolean isDeclaredWithVar; private final Set flags = new HashSet<>(); private boolean isFinal; + @Nullable private ExpressionNode expr; private Location pos; @@ -6905,7 +6920,7 @@ public SimpleVarBuilder with(Token token) { return this; } - public SimpleVarBuilder setTypeByNode(Node typeName) { + public SimpleVarBuilder setTypeByNode(@Nullable Node typeName) { this.isDeclaredWithVar = typeName == null || typeName.kind() == SyntaxKind.VAR_TYPE_DESC; if (typeName == null) { return this; @@ -6940,7 +6955,7 @@ public SimpleVarBuilder isListenerVar() { return this; } - public SimpleVarBuilder setVisibility(Token visibilityQualifier) { + public SimpleVarBuilder setVisibility(@Nullable Token visibilityQualifier) { if (visibilityQualifier != null) { if (visibilityQualifier.kind() == SyntaxKind.PRIVATE_KEYWORD) { this.flags.add(Flag.PRIVATE); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/NodeCloner.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/NodeCloner.java index 75db8cf2452f..a437c29f9a47 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/NodeCloner.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/NodeCloner.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.model.tree.statements.VariableDefinitionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.tree.BLangAnnotation; import org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment; @@ -282,6 +283,7 @@ public synchronized BLangCompilationUnit cloneCUnit(BLangCompilationUnit source) return clone; } + @Nullable public T cloneNode(T source) { if (source == null) { @@ -300,6 +302,7 @@ public T cloneNode(T source) { return (T) result; } + @Nullable private List cloneList(List nodes) { if (nodes == null) { @@ -313,6 +316,7 @@ private List cloneList(List nodes) { return cloneList; } + @Nullable @SuppressWarnings("unchecked") private T clone(T source) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java index a3920e3d2720..fb0df0287245 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java @@ -33,6 +33,7 @@ import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; import org.ballerinalang.util.diagnostic.DiagnosticHintCode; import org.ballerinalang.util.diagnostic.DiagnosticWarningCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.semantics.model.Scope; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; @@ -364,7 +365,7 @@ public void analyzeNode(BLangNode node, AnalyzerData data) { data.env = prevEnv; } - private void analyzeTypeNode(BLangType node, AnalyzerData data) { + private void analyzeTypeNode(@Nullable BLangType node, AnalyzerData data) { if (node == null) { return; @@ -615,7 +616,7 @@ public void visit(BLangTransaction transactionNode, AnalyzerData data) { analyseOnFailClause(onFailExists, transactionNode.onFailClause, data); } - private void analyzeOnFailClause(BLangOnFailClause onFailClause, AnalyzerData data) { + private void analyzeOnFailClause(@Nullable BLangOnFailClause onFailClause, AnalyzerData data) { if (onFailClause != null) { analyzeNode(onFailClause, data); } @@ -1085,6 +1086,7 @@ private HashMap getConstValue(BLangConstPattern constPattern) { return constValAndType; } + @Nullable private Object getConstValueFromFiniteType(BFiniteType type) { if (type.getValueSpace().size() == 1) { BLangExpression expr = type.getValueSpace().iterator().next(); @@ -3917,6 +3919,7 @@ private void handleWaitAction(WorkerActionSystem workerActionSystem, BLangNode c } } + @Nullable private BSymbol getWorkerSymbol(BLangWaitForAllExpr.BLangWaitKeyValue keyValuePair) { BLangExpression value = keyValuePair.getValue(); if (value != null && value.getKind() == NodeKind.SIMPLE_VARIABLE_REF) { @@ -3964,7 +3967,7 @@ private boolean isWorkerFromFunction(SymbolEnv functionEnv, Name workerName) { return isWorkerFromFunction(functionEnv.enclEnv, workerName); } - private boolean isWorkerSymbol(BSymbol symbol) { + private boolean isWorkerSymbol(@Nullable BSymbol symbol) { return symbol != null && (symbol.flags & Flags.WORKER) == Flags.WORKER; } @@ -4350,6 +4353,7 @@ private void validateInvocationInMatchGuard(BLangInvocation invocation) { } } + @Nullable private BLangExpression getMatchedExprIfCalledInMatchGuard(BLangInvocation invocation) { BLangNode prevParent = invocation; BLangNode parent = invocation.parent; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java index 19b37c0e15c3..b0d3e7691b4b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java @@ -28,6 +28,7 @@ import org.ballerinalang.model.tree.expressions.RecordLiteralNode; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.parser.NodeCloner; @@ -1435,6 +1436,7 @@ private BSymbol getUnaryOpSymbol(BLangUnaryExpr unaryExpr, BType type, AnalyzerD return symbol; } + @Nullable private Object calculateSingletonValue(BFiniteType lhs, BFiniteType rhs, OperatorKind kind, BType type, AnalyzerData data) { // Calculate the value for the binary operation. @@ -1496,6 +1498,7 @@ private Object getValue(BLangLiteral lhsLiteral) { return value; } + @Nullable private Object evaluateUnaryOperator(BFiniteType finiteType, BType type, OperatorKind kind, AnalyzerData data) { // Calculate the value for the unary operation. BLangLiteral lhsLiteral = (BLangLiteral) finiteType.getValueSpace().iterator().next(); @@ -1525,6 +1528,7 @@ private Object evaluateUnaryOperator(BFiniteType finiteType, BType type, Operato return null; } + @Nullable private Object calculateBitWiseOp(Object lhs, Object rhs, BiFunction func, BType type, AnalyzerData data) { if (Types.getImpliedType(type).tag == TypeTags.INT) { @@ -1535,6 +1539,7 @@ private Object calculateBitWiseOp(Object lhs, Object rhs, BiFunction calculateNegationForInt(value, data); @@ -1679,6 +1690,7 @@ private Object calculateNegation(Object value, BType type, AnalyzerData data) { }; } + @Nullable private Object calculateBitWiseComplement(Object value, BType type) { Object result = null; if (Types.getImpliedType(type).tag == TypeTags.INT) { @@ -1687,6 +1699,7 @@ private Object calculateBitWiseComplement(Object value, BType type) { return result; } + @Nullable private Object calculateBooleanComplement(Object value, BType type) { Object result = null; if (Types.getImpliedType(type).tag == TypeTags.BOOLEAN) { @@ -1921,7 +1934,7 @@ public BType getTypeOfHexFloatingPointLiteral(BLangLiteral literalExpr, Object l return symTable.floatType; } - private BType getFiniteType(Object value, BConstantSymbol constantSymbol, Location pos, BType type) { + private BType getFiniteType(Object value, BConstantSymbol constantSymbol, @Nullable Location pos, BType type) { return switch (type.tag) { case TypeTags.INT, TypeTags.FLOAT, @@ -2496,6 +2509,7 @@ public void visit(BHandleType bHandleType) { } } + @Nullable public BLangConstantValue getConstantValue(BType type) { // Obtain the constant value using its type. BType refType = Types.getImpliedType(type); @@ -2556,7 +2570,7 @@ public static ResolveConstantExpressionType getInstance(CompilerContext context) return resolveConstantExpressionType; } - public BType resolveConstExpr(BLangExpression expr, BType expType, AnalyzerData data) { + public BType resolveConstExpr(BLangExpression expr, @Nullable BType expType, AnalyzerData data) { return resolveConstExpr(expr, data.env, expType, DiagnosticErrorCode.INCOMPATIBLE_TYPES, data); } @@ -2696,6 +2710,7 @@ public void visit(BLangRecordLiteral recordLiteral, AnalyzerData data) { } } + @Nullable private BType getResolvedFieldType(Object targetKey, BType resolvedType) { BRecordType recordType = (BRecordType) ((resolvedType.tag == TypeTags.INTERSECTION) ? ((BIntersectionType) resolvedType).effectiveType : resolvedType); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantValueResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantValueResolver.java index b929c95ad4fe..e3a386072b75 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantValueResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantValueResolver.java @@ -29,6 +29,7 @@ import org.ballerinalang.model.tree.expressions.RecordLiteralNode; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.semantics.model.Scope; @@ -98,6 +99,7 @@ public class ConstantValueResolver extends BLangNodeVisitor { private static final CompilerContext.Key CONSTANT_VALUE_RESOLVER_KEY = new CompilerContext.Key<>(); private BConstantSymbol currentConstSymbol; + @Nullable private BLangConstantValue result; private final BLangDiagnosticLog dlog; private Location currentPos; @@ -309,7 +311,8 @@ public void visit(BLangUnaryExpr unaryExpr) { this.result = evaluateUnaryOperator(value, unaryExpr.operator); } - private BLangConstantValue calculateConstValue(BLangConstantValue lhs, BLangConstantValue rhs, OperatorKind kind) { + private BLangConstantValue calculateConstValue(@Nullable BLangConstantValue lhs, @Nullable BLangConstantValue rhs, + OperatorKind kind) { if (lhs == null || rhs == null || lhs.value == null || rhs.value == null) { // This is a compilation error. // This is to avoid NPE exceptions in sub-sequent validations. @@ -353,7 +356,7 @@ private BLangConstantValue calculateConstValue(BLangConstantValue lhs, BLangCons return new BLangConstantValue(null, this.currentConstSymbol.type); } - private BLangConstantValue evaluateUnaryOperator(BLangConstantValue value, OperatorKind kind) { + private BLangConstantValue evaluateUnaryOperator(@Nullable BLangConstantValue value, OperatorKind kind) { if (value == null || value.value == null) { // This is a compilation error. // This is to avoid NPE exceptions in sub-sequent validations. @@ -575,10 +578,10 @@ BLangConstantValue constructBLangConstantValueWithExactType(BLangExpression expr return constructBLangConstantValueWithExactType(expression, constantSymbol, env, new ArrayDeque<>(), false); } - BLangConstantValue constructBLangConstantValueWithExactType(BLangExpression expression, - BConstantSymbol constantSymbol, SymbolEnv env, - Deque anonTypeNameSuffixes, - boolean isSourceOnlyAnon) { + @Nullable BLangConstantValue constructBLangConstantValueWithExactType(BLangExpression expression, + BConstantSymbol constantSymbol, SymbolEnv env, + Deque anonTypeNameSuffixes, + boolean isSourceOnlyAnon) { this.currentConstSymbol = constantSymbol; BLangConstantValue value = constructBLangConstantValue(expression); constantSymbol.value = value; @@ -595,6 +598,7 @@ BLangConstantValue constructBLangConstantValueWithExactType(BLangExpression expr return value; } + @Nullable private BLangConstantValue constructBLangConstantValue(BLangExpression node) { if (!node.typeChecked) { return null; @@ -707,6 +711,7 @@ private BFiniteType createFiniteType(BConstantSymbol constantSymbol, BLangExpres return finiteType; } + @Nullable private BType checkType(BLangExpression expr, BConstantSymbol constantSymbol, Object value, BType type, Location pos, SymbolEnv env) { if (expr != null && expr.getKind() == NodeKind.SIMPLE_VARIABLE_REF && @@ -808,6 +813,7 @@ private void createTypeDefinition(BRecordType type, Location pos, SymbolEnv env) createdTypeDefinitions.put(type.tsymbol, typeDefinition); } + @Nullable private BLangTypeDefinition findTypeDefinition(List typeDefinitionArrayList, String name) { for (int i = typeDefinitionArrayList.size() - 1; i >= 0; i--) { BLangTypeDefinition typeDefinition = typeDefinitionArrayList.get(i); @@ -825,6 +831,7 @@ private void addAssociatedTypeDefinition(BLangConstant constant, BIntersectionTy constant.associatedTypeDefinition = typeDefinition; } + @Nullable private BType createRecordType(BLangExpression expr, BConstantSymbol constantSymbol, Object value, Location pos, SymbolEnv env) { if (expr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) { @@ -967,6 +974,7 @@ private boolean populateRecordFields(BLangExpression expr, BConstantSymbol const return true; } + @Nullable private BType createTupleType(BLangExpression expr, BConstantSymbol constantSymbol, Location pos, Object constValue, SymbolEnv env) { if (expr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java index 61f0b0af8994..290e626be196 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DataflowAnalyzer.java @@ -30,6 +30,7 @@ import org.ballerinalang.model.tree.types.TypeNode; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; import org.ballerinalang.util.diagnostic.DiagnosticWarningCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.semantics.analyzer.cyclefind.GlobalVariableRefAnalyzer; import org.wso2.ballerinalang.compiler.semantics.model.Scope; @@ -936,14 +937,14 @@ public void visit(BLangWhile whileNode) { } } - private void createUninitializedVarsForOnFailClause(BLangOnFailClause onFailClause) { + private void createUninitializedVarsForOnFailClause(@Nullable BLangOnFailClause onFailClause) { if (onFailClause != null) { this.enclosingOnFailClause.push(onFailClause); this.possibleFailureUnInitVars.put(onFailClause, copyUninitializedVars()); } } - private void updateUnInitVarsForOnFailClause(Map uninitializedVars) { + private void updateUnInitVarsForOnFailClause(@Nullable Map uninitializedVars) { if (isOnFailEnclosed()) { this.possibleFailureUnInitVars.put(this.enclosingOnFailClause.peek(), uninitializedVars); } @@ -960,7 +961,7 @@ public void visit(BLangDo doNode) { analyzeStmtWithOnFail(doNode.body, doNode.onFailClause); } - private void analyzeStmtWithOnFail(BLangBlockStmt blockStmt, BLangOnFailClause onFailClause) { + private void analyzeStmtWithOnFail(BLangBlockStmt blockStmt, @Nullable BLangOnFailClause onFailClause) { createUninitializedVarsForOnFailClause(onFailClause); BranchResult doResult = analyzeBranch(blockStmt, env); this.uninitializedVars = doResult.uninitializedVars; @@ -1977,7 +1978,7 @@ private boolean isVariableOrConstant(BSymbol symbol) { * @param dependent dependent. * @param provider object which provides a value. */ - private void addDependency(BSymbol dependent, BSymbol provider) { + private void addDependency(@Nullable BSymbol dependent, BSymbol provider) { if (provider == null || dependent == null || dependent.pkgID != provider.pkgID) { return; } @@ -2557,6 +2558,7 @@ private Map copyOnFailUninitializedVars(BLangOnFailClause o return new LinkedHashMap<>(this.possibleFailureUnInitVars.get(onFailClause)); } + @Nullable private Map getPossibleFailureUnInitVars() { if (isOnFailEnclosed()) { return this.possibleFailureUnInitVars.get(this.enclosingOnFailClause.peek()); @@ -2564,7 +2566,7 @@ private Map getPossibleFailureUnInitVars() { return null; } - private void analyzeNode(BLangNode node, SymbolEnv env) { + private void analyzeNode(@Nullable BLangNode node, SymbolEnv env) { SymbolEnv prevEnv = this.env; this.env = env; if (node != null) { @@ -2951,6 +2953,7 @@ private boolean isFunctionOrMethodDefinedInCurrentModule(BSymbol owner, SymbolEn return owner == getEnclPkgSymbol(env); } + @Nullable private BPackageSymbol getEnclPkgSymbol(SymbolEnv env) { BLangPackage enclPkg = env.enclPkg; @@ -2979,7 +2982,8 @@ private static class BranchResult { boolean possibleFailureReached; - BranchResult(Map uninitializedVars, Map possibleFailureUnInitVars, + BranchResult(Map uninitializedVars, + @Nullable Map possibleFailureUnInitVars, boolean flowTerminated, boolean possibleFailureReached, boolean definiteFailureReached) { this.uninitializedVars = uninitializedVars; this.possibleFailureUnInitVars = possibleFailureUnInitVars; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DocumentationAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DocumentationAnalyzer.java index 8be47bd45013..3b9c164b9bec 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DocumentationAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/DocumentationAnalyzer.java @@ -26,6 +26,7 @@ import org.ballerinalang.model.tree.SimpleVariableNode; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.diagnostic.DiagnosticWarningCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; @@ -431,7 +432,7 @@ private BSymbol resolveFullyQualifiedSymbol(Location location, SymbolEnv env, St private void validateParameters(DocumentableNode documentableNode, List actualParameters, - BLangSimpleVariable restParam, + @Nullable BLangSimpleVariable restParam, DiagnosticCode undocumentedParameter, DiagnosticCode noSuchParameter, DiagnosticCode parameterAlreadyDefined) { BLangMarkdownDocumentation documentation = documentableNode.getMarkdownDocumentationAttachment(); @@ -503,7 +504,8 @@ private void validateNoParameters(DocumentableNode documentableNode) { DiagnosticWarningCode.NO_SUCH_DOCUMENTABLE_PARAMETER, parameter)); } - private void validateReturnParameter(DocumentableNode documentableNode, BLangNode node, boolean isExpected) { + private void validateReturnParameter(DocumentableNode documentableNode, @Nullable BLangNode node, + boolean isExpected) { BLangMarkdownDocumentation documentationAttachment = documentableNode.getMarkdownDocumentationAttachment(); if (documentationAttachment == null) { return; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/IsolationAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/IsolationAnalyzer.java index 298891dc56c8..80ac33d3cf69 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/IsolationAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/IsolationAnalyzer.java @@ -30,6 +30,7 @@ import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; import org.ballerinalang.util.diagnostic.DiagnosticHintCode; import org.ballerinalang.util.diagnostic.DiagnosticWarningCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLocation; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; @@ -2541,8 +2542,9 @@ private void analyzeVarArgIsolatedness(BLangInvocation invocationExpr, BLangRest } } - private void handleNonExplicitlyIsolatedArgForIsolatedParam(BLangInvocation invocationExpr, BLangExpression expr, - boolean expectsIsolation, BType type, Location pos) { + private void handleNonExplicitlyIsolatedArgForIsolatedParam( + BLangInvocation invocationExpr, @Nullable BLangExpression expr, boolean expectsIsolation, BType type, + Location pos) { if (Symbols.isFlagOn(type.flags, Flags.ISOLATED)) { return; } @@ -2572,7 +2574,7 @@ private void handleNonExplicitlyIsolatedArgForIsolatedParam(BLangInvocation invo } } - private boolean isInIsolatedFunction(BLangInvokableNode enclInvokable) { + private boolean isInIsolatedFunction(@Nullable BLangInvokableNode enclInvokable) { if (enclInvokable == null) { // TODO: 14/11/20 This feels hack-y but cannot think of a different approach without a class variable // maintaining isolated-ness. @@ -2718,10 +2720,10 @@ private boolean isIsolatedExpression(BLangExpression expression, boolean logErro private boolean isIsolatedExpression(BLangExpression expression, boolean logErrors, boolean visitRestOnError, List nonIsolatedExpressions, boolean inferring, - Set publiclyExposedObjectTypes, - List classDefinitions, - List moduleLevelVariables, - Set unresolvedSymbols) { + @Nullable Set publiclyExposedObjectTypes, + @Nullable List classDefinitions, + @Nullable List moduleLevelVariables, + @Nullable Set unresolvedSymbols) { BType type = expression.getBType(); if (type != null && @@ -3354,7 +3356,8 @@ private boolean isInIsolatedObjectMethod(SymbolEnv env, boolean ignoreInit) { return ownerType.tag == TypeTags.OBJECT && isIsolated(ownerType.flags); } - private BLangFunction getEnclNonAnonymousFunction(BLangFunction enclFunction) { + @Nullable + private BLangFunction getEnclNonAnonymousFunction(@Nullable BLangFunction enclFunction) { if (enclFunction == null || enclFunction.symbol.owner.kind == SymbolKind.PACKAGE) { return null; } @@ -3540,9 +3543,9 @@ private void markDependsOnIsolationNonInferableConstructs() { this.isolationInferenceInfoMap.get(enclInvokableSymbol).dependsOnlyOnInferableConstructs = false; } - private void analyzeFunctionInStartActionForInference(SymbolEnv env, List requiredArgs, - List restArgs, BLangExpression expr, - BInvokableSymbol symbol) { + private void analyzeFunctionInStartActionForInference( + SymbolEnv env, List requiredArgs, List restArgs, + @Nullable BLangExpression expr, BInvokableSymbol symbol) { Set argsList = new HashSet<>(requiredArgs); argsList.addAll(restArgs); if (expr != null) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/MainFunctionValidator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/MainFunctionValidator.java index 9c8f86bb0e90..79903e7799e3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/MainFunctionValidator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/MainFunctionValidator.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.elements.Flag; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType; @@ -97,8 +98,10 @@ private void detectArrayRelatedErrors(List requiredParams) } } - private BLangSimpleVariable handleSuccessfulVisit(MainParameterVisitor mainParameterVisitor, - BLangSimpleVariable foundOperand, BLangSimpleVariable param) { + @Nullable + private BLangSimpleVariable handleSuccessfulVisit( + MainParameterVisitor mainParameterVisitor, @Nullable BLangSimpleVariable foundOperand, + BLangSimpleVariable param) { BType paramType = param.getBType(); BType referredParamType = Types.getImpliedType(paramType); if (mainParameterVisitor.isOperandType(paramType) && param.expr == null && foundOperand != null) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java index dd92270be20c..7aa2c092363d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java @@ -25,6 +25,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.util.BLangCompilerConstants; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.parser.NodeCloner; @@ -572,6 +573,7 @@ private BType getQueryMapConstraintType(BType type, Location pos) { return symTable.semanticError; } + @Nullable private BType getCompletionType(List collectionTypes, Types.QueryConstructType queryConstructType, TypeChecker.AnalyzerData data) { Set completionTypes = new LinkedHashSet<>(); @@ -1246,6 +1248,7 @@ private SymbolEnv getEnvBeforeInputNode(SymbolEnv env, BLangNode node) { : new SymbolEnv(node, null); } + @Nullable private BLangNode getLastInputNodeFromEnv(SymbolEnv env) { while (env != null && (env.node.getKind() != NodeKind.FROM && env.node.getKind() != NodeKind.JOIN)) { env = env.enclEnv; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java index a169ec2ad9ff..3b3db98b8c73 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ReachabilityAnalyzer.java @@ -25,6 +25,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; import org.ballerinalang.util.diagnostic.DiagnosticWarningCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLocation; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; @@ -510,7 +511,7 @@ public void visit(BLangTransaction transactionNode, AnalyzerData data) { analyzeOnFailClause(transactionNode.onFailClause, data); } - private void analyzeOnFailClause(BLangOnFailClause onFailClause, AnalyzerData data) { + private void analyzeOnFailClause(@Nullable BLangOnFailClause onFailClause, AnalyzerData data) { if (onFailClause == null) { return; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index 5b8566b99307..9eef8e88875a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -34,6 +34,7 @@ import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; import org.ballerinalang.util.diagnostic.DiagnosticWarningCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.semantics.model.Scope; @@ -599,8 +600,9 @@ public void visit(BLangBlockFunctionBody body, AnalyzerData data) { resetNotCompletedNormally(data); } - private boolean analyzeBlockStmtFollowingIfWithoutElse(BLangStatement currentStmt, BLangStatement prevStatement, - SymbolEnv currentEnv, AnalyzerData data) { + private boolean analyzeBlockStmtFollowingIfWithoutElse( + BLangStatement currentStmt, @Nullable BLangStatement prevStatement, SymbolEnv currentEnv, + AnalyzerData data) { if (currentStmt.getKind() == NodeKind.BLOCK && prevStatement != null && prevStatement.getKind() == NodeKind.IF && ((BLangIf) prevStatement).elseStmt == null && data.notCompletedNormally) { BLangIf ifStmt = (BLangIf) prevStatement; @@ -2007,6 +2009,7 @@ private void handleDeclaredWithVar(BLangVariable variable, AnalyzerData data) { } } + @Nullable private BType getListenerType(BType bType) { LinkedHashSet compatibleTypes = new LinkedHashSet<>(); BType type = Types.getImpliedType(bType); @@ -4506,7 +4509,7 @@ private BLangExpression getBinaryExpr(BLangExpression lExpr, return binaryExpressionNode; } - private boolean validateObjectTypeInitInvocation(BLangExpression expr) { + private boolean validateObjectTypeInitInvocation(@Nullable BLangExpression expr) { // Following is invalid: // var a = new ; if (expr != null && expr.getKind() == NodeKind.TYPE_INIT_EXPR && @@ -4967,7 +4970,7 @@ private boolean isIsolated(BLangVariable varNode) { return varNode.flagSet.contains(Flag.ISOLATED); } - private void handleReadOnlyField(boolean isRecordType, LinkedHashMap fields, + private void handleReadOnlyField(boolean isRecordType, @Nullable LinkedHashMap fields, BLangSimpleVariable field, AnalyzerData data) { BType fieldType = field.getBType(); @@ -5100,7 +5103,7 @@ private Map getFieldLocations(List fields public class AnalyzerData { SymbolEnv env; BType expType; - Map narrowedTypeInfo; + @Nullable Map narrowedTypeInfo; boolean notCompletedNormally; boolean breakFound; Types.CommonAnalyzerData commonAnalyzerData = new Types.CommonAnalyzerData(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java index 7f76e1127bc4..26194514c1c7 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolEnter.java @@ -37,6 +37,7 @@ import org.ballerinalang.model.tree.types.TypeNode; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.PackageCache; import org.wso2.ballerinalang.compiler.SourceDirectory; import org.wso2.ballerinalang.compiler.desugar.ASTBuilderUtil; @@ -2429,8 +2430,8 @@ boolean checkTypeAndVarCountConsistency(BLangTupleVariable var, SymbolEnv env) { return checkTypeAndVarCountConsistency(var, null, env); } - boolean checkTypeAndVarCountConsistency(BLangTupleVariable varNode, BTupleType tupleTypeNode, - SymbolEnv env) { + boolean checkTypeAndVarCountConsistency(BLangTupleVariable varNode, @Nullable BTupleType tupleTypeNode, + SymbolEnv env) { if (tupleTypeNode == null) { /* This switch block will resolve the tuple type of the tuple variable. @@ -2608,6 +2609,7 @@ boolean checkTypeAndVarCountConsistency(BLangTupleVariable varNode, BTupleType t return true; } + @Nullable private BType getPossibleRestTypeForUnion(BLangTupleVariable varNode, List possibleTypes) { if (varNode.restVariable == null) { return null; @@ -3110,7 +3112,7 @@ BRecordType createRecordTypeForRestField(Location pos, SymbolEnv env, BRecordTyp void setRestRecordFields(Location pos, SymbolEnv env, LinkedHashMap unMappedFields, - List variableList, BType restConstraint, + List variableList, @Nullable BType restConstraint, BRecordType targetRestRecType) { LinkedHashMap fields = new LinkedHashMap<>(); LinkedHashMap markAsOptional = new LinkedHashMap<>(); @@ -3478,7 +3480,7 @@ private BTypeSymbol createTypeSymbol(long type, SymbolEnv env) { null, env.scope.owner, symTable.builtinPos, VIRTUAL); } - private void defineMemberNode(BLangVariable memberVar, SymbolEnv env, BType type) { + private void defineMemberNode(BLangVariable memberVar, SymbolEnv env, @Nullable BType type) { memberVar.setBType(type); // Module level variables declared with `var` already defined if ((env.scope.owner.tag & SymTag.PACKAGE) == SymTag.PACKAGE && memberVar.isDeclaredWithVar) { @@ -5231,6 +5233,7 @@ private void defineReferencedFunction(Location location, Set flagSet, Symb ((BObjectTypeSymbol) typeDefSymbol).referencedFunctions.add(attachedFunc); } + @Nullable private BLangFunction findFunctionBySymbol(List declaredFunctions, BSymbol symbol) { for (BLangFunction fn : declaredFunctions) { if (fn.symbol == symbol) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolResolver.java index 449ef9f0c2ad..fafef64344e6 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SymbolResolver.java @@ -29,6 +29,7 @@ import org.ballerinalang.model.tree.OperatorKind; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.parser.BLangMissingNodesHelper; @@ -1771,8 +1772,9 @@ public BType transform(BLangUserDefinedType userDefinedTypeNode, AnalyzerData da return typeResolver.validateModuleLevelDef(name, pkgAlias, typeName, userDefinedTypeNode); } + @Nullable public ParameterizedTypeInfo getTypedescParamValueType(List params, - AnalyzerData data, BSymbol varSym) { + AnalyzerData data, BSymbol varSym) { for (int i = 0; i < params.size(); i++) { BLangSimpleVariable param = params.get(i); @@ -2476,7 +2478,8 @@ public BType getPotentialIntersection(Types.IntersectionContext intersectionCont return types.getTypeIntersection(intersectionContext, lhsType, rhsType, env); } - boolean validateInferTypedescParams(Location pos, List parameters, BType retType) { + boolean validateInferTypedescParams( + Location pos, List parameters, @Nullable BType retType) { int inferTypedescParamCount = 0; BVarSymbol paramWithInferredTypedescDefault = null; Location inferDefaultLocation = null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index cef5cdbdf1a3..c6c16112ceb2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -38,6 +38,7 @@ import org.ballerinalang.util.BLangCompilerConstants; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; import org.ballerinalang.util.diagnostic.DiagnosticWarningCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.desugar.ASTBuilderUtil; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; @@ -1614,8 +1615,9 @@ private boolean checkNestedConstExpr(List expressions return true; } + @Nullable private BLangExpression getRecordKeyValueField(BLangRecordLiteral recordLiteral, - String fieldName) { + String fieldName) { for (RecordLiteralNode.RecordField recordField : recordLiteral.fields) { if (recordField.isKeyValueField()) { BLangRecordLiteral.BLangRecordKeyValueField recordKeyValueField = @@ -2289,7 +2291,7 @@ private BType checkReadOnlyListType(BLangListConstructorExpr listConstructor, An return symTable.readonlyType; } - private boolean exprIncompatible(BType eType, BLangExpression expr, AnalyzerData data) { + private boolean exprIncompatible(@Nullable BType eType, BLangExpression expr, AnalyzerData data) { if (expr.typeChecked) { return expr.getBType() == symTable.semanticError; } @@ -2848,7 +2850,7 @@ private HashSet getFieldNames(List specif return fieldNames; } - String getKeyValueFieldName(BLangRecordKeyValueField field) { + @Nullable String getKeyValueFieldName(BLangRecordKeyValueField field) { BLangRecordKey key = field.key; if (key.computedKey) { return null; @@ -3496,7 +3498,7 @@ public boolean isArrayOpenSealedType(BArrayType arrayType) { * enclosing invokable node) which is needed to lookup closure variables. The variable lookup will start from the * enclosing invokable node's environment, which are outside of the scope of a lambda function. */ - private SymbolEnv findEnclosingInvokableEnv(SymbolEnv env, BLangInvokableNode encInvokable) { + private SymbolEnv findEnclosingInvokableEnv(SymbolEnv env, @Nullable BLangInvokableNode encInvokable) { if (env.enclEnv.node == null) { return env; } @@ -5499,6 +5501,7 @@ public void visit(BLangCommitExpr commitExpr, AnalyzerData data) { data.resultType = types.checkType(commitExpr, actualType, data.expType); } + @Nullable private BType getXMLConstituents(BType bType) { BType type = Types.getImpliedType(bType); BType constituent = null; @@ -5985,6 +5988,7 @@ public void visit(BLangXMLQName bLangXMLQName, AnalyzerData data) { bLangXMLQName.namespaceURI = bLangXMLQName.nsSymbol.namespaceURI; } + @Nullable private BConstantSymbol getSymbolOfXmlQualifiedName(String localname, String prefix, BPackageSymbol pkgSymbol, Location pos, AnalyzerData data) { BSymbol constSymbol = @@ -6918,7 +6922,7 @@ private boolean isObjectCtorClass(BLangNode node) { } private boolean searchClosureVariableInExpressions(BSymbol symbol, Location pos, SymbolEnv env, - BLangInvokableNode encInvokable, BLangNode bLangNode) { + @Nullable BLangInvokableNode encInvokable, BLangNode bLangNode) { if (encInvokable != null && encInvokable.flagSet.contains(Flag.LAMBDA) && !isInParameterList(symbol, encInvokable.requiredParams)) { SymbolEnv encInvokableEnv = findEnclosingInvokableEnv(env, encInvokable); @@ -6943,8 +6947,9 @@ private boolean searchClosureVariableInExpressions(BSymbol symbol, Location pos, return false; } - private void updateObjectCtorClosureSymbols(Location pos, BLangFunction currentFunction, BSymbol resolvedSymbol, - BLangClassDefinition classDef, AnalyzerData data) { + private void updateObjectCtorClosureSymbols( + Location pos, @Nullable BLangFunction currentFunction, BSymbol resolvedSymbol, + BLangClassDefinition classDef, AnalyzerData data) { classDef.hasClosureVars = true; resolvedSymbol.closure = true; if (currentFunction != null) { @@ -7191,6 +7196,7 @@ private void checkInvocationParamAndReturnType(BLangInvocation iExpr, AnalyzerDa data.resultType = types.checkType(iExpr, actualType, data.expType); } + @Nullable private BVarSymbol incRecordParamAllowAdditionalFields(List openIncRecordParams, Set requiredParamNames) { if (openIncRecordParams.size() != 1) { @@ -7206,6 +7212,7 @@ private BVarSymbol incRecordParamAllowAdditionalFields(List openIncR return openIncRecordParams.get(0); } + @Nullable private BVarSymbol checkForIncRecordParamAllowAdditionalFields(BInvokableSymbol invokableSymbol, List incRecordParams) { Set requiredParamNames = new HashSet<>(); @@ -7329,13 +7336,13 @@ private BType checkInvocationParam(BLangInvocation iExpr, AnalyzerData data) { incRecordParamAllowAdditionalFields, data); } - private boolean isNamedArgForIncRecordParam(String namedArgName, BVarSymbol incRecordParam) { + private boolean isNamedArgForIncRecordParam(String namedArgName, @Nullable BVarSymbol incRecordParam) { return incRecordParam != null && namedArgName.equals(incRecordParam.name.value); } - private BType checkInvocationArgs(BLangInvocation iExpr, List paramTypes, BLangExpression vararg, + private BType checkInvocationArgs(BLangInvocation iExpr, List paramTypes, @Nullable BLangExpression vararg, List incRecordParams, - BVarSymbol incRecordParamAllowAdditionalFields, AnalyzerData data) { + @Nullable BVarSymbol incRecordParamAllowAdditionalFields, AnalyzerData data) { BInvokableSymbol invokableSymbol = (BInvokableSymbol) iExpr.symbol; BInvokableType bInvokableType = (BInvokableType) Types.getImpliedType(invokableSymbol.type); BInvokableTypeSymbol invokableTypeSymbol = (BInvokableTypeSymbol) bInvokableType.tsymbol; @@ -7712,6 +7719,7 @@ private void checkArrayLibSortFuncArgs(BLangInvocation iExpr) { } } + @Nullable private BVarSymbol checkParameterNameForDefaultArgument(BLangIdentifier argName, BLangExpression expr, List nonRestParams, List incRecordParams, @@ -9537,7 +9545,7 @@ public BType defineInferredRecordType(BLangRecordLiteral recordLiteral, BType ex return recordType; } - private BRecordTypeSymbol createRecordTypeSymbol(PackageID pkgID, Location location, + private BRecordTypeSymbol createRecordTypeSymbol(PackageID pkgID, @Nullable Location location, SymbolOrigin origin, AnalyzerData data) { SymbolEnv env = data.env; BRecordTypeSymbol recordSymbol = @@ -9870,7 +9878,7 @@ private static class TypeSymbolPair { private final BVarSymbol fieldSymbol; private final BType determinedType; - public TypeSymbolPair(BVarSymbol fieldSymbol, BType determinedType) { + public TypeSymbolPair(@Nullable BVarSymbol fieldSymbol, BType determinedType) { this.fieldSymbol = fieldSymbol; this.determinedType = determinedType; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeParamAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeParamAnalyzer.java index 731978cb27fc..af0e9a86a7a3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeParamAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeParamAnalyzer.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.semantics.model.Scope; @@ -359,8 +360,9 @@ private void findTypeParam(BLangExpression expr, Location loc, BType expType, BT findTypeParam(expr, loc, expType, actualType, env, resolvedTypes, result, false); } - private void findTypeParam(BLangExpression expr, Location loc, BType expType, BType actualType, SymbolEnv env, - HashSet resolvedTypes, FindTypeParamResult result, boolean checkContravariance) { + private void findTypeParam( + @Nullable BLangExpression expr, Location loc, BType expType, BType actualType, SymbolEnv env, + HashSet resolvedTypes, FindTypeParamResult result, boolean checkContravariance) { if (resolvedTypes.contains(expType)) { return; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeResolver.java index 189a1504468d..aaf9fb7be595 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeResolver.java @@ -26,6 +26,7 @@ import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.parser.BLangMissingNodesHelper; @@ -676,13 +677,14 @@ public void getFieldsOfStructureType(String name, List incl } } + @Nullable public BLangTypeDefinition getTypeDefinition(String name) { BLangNode moduleLevelDef = modTable.get(name); return moduleLevelDef != null && moduleLevelDef.getKind() == NodeKind.TYPE_DEFINITION ? (BLangTypeDefinition) moduleLevelDef : null; } - private BType resolveTypeDesc(SymbolEnv symEnv, BLangTypeDefinition defn, int depth, + private BType resolveTypeDesc(SymbolEnv symEnv, @Nullable BLangTypeDefinition defn, int depth, BLangType td, ResolverData data) { return resolveTypeDesc(symEnv, defn, depth, td, data, true); } @@ -1668,6 +1670,7 @@ private void replaceUnaryExprWithNumericLiteral(BLangFiniteTypeNode finiteTypeNo } } + @Nullable private BType blangTypeUpdate(BLangExpression expression) { BType type; switch (expression.getKind()) { @@ -1794,6 +1797,7 @@ public BType visitBuiltInTypeNode(BLangType typeNode, SymbolResolver.AnalyzerDat return typeSymbol.type; } + @Nullable public BType defineTypeDefinition(BLangTypeDefinition typeDefinition, BType resolvedType, SymbolEnv env) { if (resolvedType == null || resolvedType == symTable.noType || typeDefinition.symbol != null) { @@ -2094,6 +2098,7 @@ private void defineConstant(SymbolEnv symEnv, Map modTable, B symEnv.scope.define(constantSymbol.name, constantSymbol); } + @Nullable public BLangTypeDefinition findTypeDefinition(List typeDefinitionArrayList, String name) { for (int i = typeDefinitionArrayList.size() - 1; i >= 0; i--) { BLangTypeDefinition typeDefinition = typeDefinitionArrayList.get(i); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java index de443d69b5be..cbfab84257b3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java @@ -30,6 +30,8 @@ import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.BLangCompilerConstants; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.semantics.model.Scope; @@ -250,7 +252,7 @@ public BType checkType(BLangExpression expr, return expr.getBType(); } - public boolean typeIncompatible(Location pos, BType actualType, BType expType) { + public boolean typeIncompatible(Location pos, BType actualType, @Nullable BType expType) { return checkType(pos, actualType, expType, DiagnosticErrorCode.INCOMPATIBLE_TYPES) == symTable.semanticError; } @@ -1154,7 +1156,7 @@ private boolean isAssignableTableType(BTableType sourceTableType, BTableType tar } - BField getTableConstraintField(BType constraintType, String fieldName) { + @Nullable BField getTableConstraintField(BType constraintType, String fieldName) { constraintType = getImpliedType(constraintType); switch (constraintType.tag) { case TypeTags.RECORD: @@ -1504,7 +1506,8 @@ public boolean isInherentlyImmutableType(BType type) { * @return the implied type if provided with a type reference type or an intersection type, * else returns the original type */ - public static BType getImpliedType(BType type) { + @Contract("null -> null; !null -> !null") + public static BType getImpliedType(@Nullable BType type) { type = getReferredType(type); if (type != null && type.tag == TypeTags.INTERSECTION) { return getImpliedType(((BIntersectionType) type).effectiveType); @@ -1513,6 +1516,7 @@ public static BType getImpliedType(BType type) { return type; } + @Contract("null -> null; !null -> !null") public static BType getReferredType(BType type) { if (type != null && type.tag == TypeTags.TYPEREFDESC) { return getReferredType(((BTypeReferenceType) type).referredType); @@ -2033,6 +2037,7 @@ public void setInputClauseTypedBindingPatternType(BLangInputClause bLangInputCla bLangInputClause.nillableResultType = nextMethodReturnType; } + @Nullable private BType getTypedBindingPatternTypeForXmlCollection(BType collectionType) { BType constraint = getImpliedType(((BXMLType) collectionType).constraint); while (constraint.tag == TypeTags.XML) { @@ -2135,6 +2140,7 @@ private BType getTupleMemberType(BTupleType tupleType) { tupleTypes.iterator().next() : BUnionType.create(null, tupleTypes); } + @Nullable public BUnionType getVarTypeFromIterableObject(BObjectType collectionType) { BObjectTypeSymbol objectTypeSymbol = (BObjectTypeSymbol) collectionType.tsymbol; for (BAttachedFunction func : objectTypeSymbol.attachedFuncs) { @@ -2146,6 +2152,7 @@ public BUnionType getVarTypeFromIterableObject(BObjectType collectionType) { return null; } + @Nullable private BUnionType getVarTypeFromIteratorFunc(BAttachedFunction candidateIteratorFunc) { if (!candidateIteratorFunc.type.paramTypes.isEmpty()) { return null; @@ -2156,6 +2163,7 @@ private BUnionType getVarTypeFromIteratorFunc(BAttachedFunction candidateIterato return getVarTypeFromIteratorFuncReturnType(returnType); } + @Nullable public BUnionType getVarTypeFromIteratorFuncReturnType(BType type) { BObjectTypeSymbol objectTypeSymbol; BType returnType = getImpliedType(type); @@ -2173,6 +2181,7 @@ public BUnionType getVarTypeFromIteratorFuncReturnType(BType type) { return null; } + @Nullable private BUnionType getVarTypeFromNextFunc(BAttachedFunction nextFunc) { BType returnType; if (!nextFunc.type.paramTypes.isEmpty()) { @@ -2228,6 +2237,7 @@ private boolean checkRecordTypeInNextFuncReturnType(BRecordType recordType) { return recordType.fields.containsKey(BLangCompilerConstants.VALUE_FIELD); } + @Nullable private BRecordType getRecordType(BUnionType type) { for (BType member : type.getMemberTypes()) { BType referredRecordType = getImpliedType(member); @@ -2238,6 +2248,7 @@ private BRecordType getRecordType(BUnionType type) { return null; } + @Nullable public BErrorType getErrorType(BUnionType type) { for (BType member : type.getMemberTypes()) { member = getImpliedType(member); @@ -2259,6 +2270,7 @@ public BType getResultTypeOfNextInvocation(BObjectType iteratorType) { return Objects.requireNonNull(nextFunc).type.retType; } + @Nullable public BAttachedFunction getAttachedFuncFromObject(BObjectType objectType, String funcName) { BObjectTypeSymbol iteratorSymbol = (BObjectTypeSymbol) objectType.tsymbol; for (BAttachedFunction bAttachedFunction : iteratorSymbol.attachedFuncs) { @@ -4129,7 +4141,7 @@ boolean isSigned32LiteralValue(Long longObject) { return (longObject >= SIGNED32_MIN_VALUE && longObject <= SIGNED32_MAX_VALUE); } - BigDecimal getValidDecimalNumber(Location pos, BigDecimal bd) { + @Nullable BigDecimal getValidDecimalNumber(Location pos, BigDecimal bd) { if (bd.compareTo(DECIMAL_MAX) > 0 || bd.compareTo(DECIMAL_MIN) < 0) { dlog.error(pos, DiagnosticErrorCode.OUT_OF_RANGE, bd.toString(), symTable.decimalType); return null; @@ -5120,6 +5132,7 @@ private BType getTypeIntersection(IntersectionContext intersectionContext, BType } } + @Nullable private BType getIntersection(IntersectionContext intersectionContext, BType lhsType, SymbolEnv env, BType type, LinkedHashSet visitedTypes) { @@ -5663,7 +5676,7 @@ private BErrorType createErrorType(BType lhsType, BType rhsType, BType detailTyp return errorType; } - public BErrorType createErrorType(BType detailType, long flags, SymbolEnv env) { + public BErrorType createErrorType(@Nullable BType detailType, long flags, SymbolEnv env) { String name = anonymousModelHelper.getNextAnonymousIntersectionErrorTypeName(env.enclPkg.packageID); BErrorTypeSymbol errorTypeSymbol = Symbols.createErrorSymbol(flags | Flags.ANONYMOUS, Names.fromString(name), env.enclPkg.symbol.pkgID, null, @@ -6832,7 +6845,8 @@ public static class IntersectionContext { // Try to avoid creating new intersection types. boolean preferNonGenerativeIntersection; - private IntersectionContext(BLangDiagnosticLog diaglog, Location left, Location right) { + private IntersectionContext( + @Nullable BLangDiagnosticLog diaglog, @Nullable Location left, @Nullable Location right) { this.dlog = diaglog; this.lhsPos = left; this.rhsPos = right; @@ -6842,7 +6856,8 @@ private IntersectionContext(BLangDiagnosticLog diaglog, Location left, Location this.preferNonGenerativeIntersection = false; } - private IntersectionContext(BLangDiagnosticLog diaglog, Location left, Location right, Location pos) { + private IntersectionContext( + @Nullable BLangDiagnosticLog diaglog, @Nullable Location left, @Nullable Location right, Location pos) { this(diaglog, left, right); this.pos = pos; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/cyclefind/GlobalVariableRefAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/cyclefind/GlobalVariableRefAnalyzer.java index e91e441a25ae..ad5b08efc29a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/cyclefind/GlobalVariableRefAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/cyclefind/GlobalVariableRefAnalyzer.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; @@ -530,6 +531,7 @@ private boolean doesContainAGlobalVar(List symbolsOfCycle) { .anyMatch(symbolsOfCycle::contains); } + @Nullable private BLangIdentifier getNodeName(BSymbol symbol) { for (TopLevelNode node : pkgNode.topLevelNodes) { if (getSymbol(node) == symbol) { @@ -550,6 +552,7 @@ private BLangIdentifier getNodeName(BSymbol symbol) { return null; } + @Nullable private BSymbol getSymbol(Node node) { if (node.getKind() == NodeKind.VARIABLE) { return ((BLangVariable) node).symbol; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/Scope.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/Scope.java index baea1aab1963..a0c9e0508fe3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/Scope.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/Scope.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.semantics.model; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.util.Name; @@ -73,7 +74,7 @@ public static class ScopeEntry implements org.ballerinalang.model.ScopeEntry { public BSymbol symbol; public ScopeEntry next; - public ScopeEntry(BSymbol symbol, ScopeEntry next) { + public ScopeEntry(@Nullable BSymbol symbol, @Nullable ScopeEntry next) { this.symbol = symbol; this.next = next; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SymbolEnv.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SymbolEnv.java index 624d4d1983fa..81e662369510 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SymbolEnv.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/SymbolEnv.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.semantics.model; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BObjectTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; @@ -55,20 +56,27 @@ public class SymbolEnv { public BLangNode node; + @Nullable public BLangPackage enclPkg; public BLangType enclType; + @Nullable public BLangAnnotation enclAnnotation; + @Nullable public BLangService enclService; + @Nullable public BLangInvokableNode enclInvokable; + @Nullable public BVarSymbol enclVarSym; + @Nullable public SymbolEnv enclEnv; + @Nullable public List typeParamsEntries; public boolean logErrors; @@ -79,7 +87,7 @@ public class SymbolEnv { public boolean isModuleInit; - public SymbolEnv(BLangNode node, Scope scope) { + public SymbolEnv(BLangNode node, @Nullable Scope scope) { this.scope = scope; this.node = node; this.enclPkg = null; @@ -114,7 +122,7 @@ private void copyToWithoutEnclEnv(SymbolEnv target) { target.envCount = this.envCount; } - public static SymbolEnv createPkgEnv(BLangPackage node, Scope scope, SymbolEnv builtinEnv) { + public static SymbolEnv createPkgEnv(@Nullable BLangPackage node, Scope scope, @Nullable SymbolEnv builtinEnv) { SymbolEnv env = new SymbolEnv(node, scope); env.envCount = 0; env.enclPkg = node; @@ -131,7 +139,7 @@ public static SymbolEnv createPkgLevelSymbolEnv(BLangNode node, return symbolEnv; } - public static SymbolEnv createFunctionEnv(BLangFunction node, Scope scope, SymbolEnv env) { + public static SymbolEnv createFunctionEnv(@Nullable BLangFunction node, Scope scope, SymbolEnv env) { SymbolEnv funcEnv = createPkgLevelSymbolEnv(node, scope, env); funcEnv.envCount = env.envCount + 1; funcEnv.relativeEnvCount = 0; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BAnnotationAttachmentSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BAnnotationAttachmentSymbol.java index 4da6dc10c0d5..41c53b0a377e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BAnnotationAttachmentSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BAnnotationAttachmentSymbol.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.AnnotationAttachmentSymbol; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; import org.wso2.ballerinalang.compiler.util.Names; @@ -46,7 +47,7 @@ public BAnnotationAttachmentSymbol(BAnnotationSymbol annotationSymbol, PackageID } public BAnnotationAttachmentSymbol(PackageID annotPkgID, Name annotTag, PackageID pkgID, BSymbol owner, - Location pos, SymbolOrigin origin, BType attachedType) { + Location pos, SymbolOrigin origin, @Nullable BType attachedType) { super(ANNOTATION_ATTACHMENT, 0, Names.EMPTY, pkgID, attachedType, owner, pos, origin); this.annotPkgID = annotPkgID; this.annotTag = annotTag; @@ -75,7 +76,7 @@ public BConstAnnotationAttachmentSymbol(BAnnotationSymbol annotationSymbol, Pack public BConstAnnotationAttachmentSymbol(PackageID annotPkgID, Name annotTag, PackageID pkgID, BSymbol owner, Location pos, SymbolOrigin origin, - BConstantSymbol attachmentValueSymbol, BType attachedType) { + BConstantSymbol attachmentValueSymbol, @Nullable BType attachedType) { super(annotPkgID, annotTag, pkgID, owner, pos, origin, attachedType); this.attachmentValueSymbol = attachmentValueSymbol; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BAttachedFunction.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BAttachedFunction.java index 4bff7d56f36b..385b2c07c05d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BAttachedFunction.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BAttachedFunction.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.symbols; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType; import org.wso2.ballerinalang.compiler.util.Name; import org.wso2.ballerinalang.util.Flags; @@ -34,7 +35,7 @@ public class BAttachedFunction { public BInvokableSymbol symbol; public Location pos; - public BAttachedFunction(Name funcName, BInvokableSymbol symbol, BInvokableType type, Location pos) { + public BAttachedFunction(Name funcName, BInvokableSymbol symbol, BInvokableType type, @Nullable Location pos) { this.funcName = funcName; this.type = type; this.symbol = symbol; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BConstantSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BConstantSymbol.java index fe6936f5b755..3c5b5e7eae15 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BConstantSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BConstantSymbol.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.symbols.ConstantSymbol; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.tree.BLangConstantValue; import org.wso2.ballerinalang.compiler.util.Name; @@ -33,16 +34,17 @@ */ public class BConstantSymbol extends BVarSymbol implements ConstantSymbol { + @Nullable public BLangConstantValue value; public BType literalType; - public BConstantSymbol(long flags, Name name, PackageID pkgID, BType literalType, BType type, BSymbol owner, - Location pos, SymbolOrigin origin) { + public BConstantSymbol(long flags, Name name, PackageID pkgID, @Nullable BType literalType, BType type, + BSymbol owner, Location pos, SymbolOrigin origin) { this(flags, name, name, pkgID, literalType, type, owner, pos, origin); } - public BConstantSymbol(long flags, Name name, Name originalName, PackageID pkgID, BType literalType, BType type, - BSymbol owner, Location pos, SymbolOrigin origin) { + public BConstantSymbol(long flags, Name name, Name originalName, PackageID pkgID, @Nullable BType literalType, + BType type, BSymbol owner, Location pos, SymbolOrigin origin) { super(flags, name, originalName, pkgID, type, owner, pos, origin); this.tag = CONSTANT; this.literalType = literalType; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BErrorTypeSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BErrorTypeSymbol.java index 8392fbca61c1..1f3dd6d76b0c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BErrorTypeSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BErrorTypeSymbol.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; @@ -31,8 +32,8 @@ */ public class BErrorTypeSymbol extends BTypeSymbol { - public BErrorTypeSymbol(long symTag, long flags, Name name, PackageID pkgID, BType type, BSymbol owner, - Location pos, SymbolOrigin origin) { + public BErrorTypeSymbol(long symTag, long flags, Name name, PackageID pkgID, @Nullable BType type, + @Nullable BSymbol owner, Location pos, SymbolOrigin origin) { super(symTag, flags, name, pkgID, type, owner, pos, origin); this.kind = SymbolKind.ERROR; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableSymbol.java index b26f3014700e..9c8444547cf0 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableSymbol.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.symbols.InvokableSymbol; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; @@ -39,12 +40,15 @@ */ public class BInvokableSymbol extends BVarSymbol implements InvokableSymbol { + @Nullable public List params; + @Nullable public BVarSymbol restParam; public BType retType; public Map paramDefaultValTypes; // This field is only applicable for functions at the moment. + @Nullable public BVarSymbol receiverSymbol; public boolean bodyExist; @@ -63,7 +67,7 @@ public BInvokableSymbol(long tag, PackageID pkgID, BType type, BSymbol owner, - Location pos, + @Nullable Location pos, SymbolOrigin origin) { this(tag, flags, name, name, pkgID, type, owner, pos, origin); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableTypeSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableTypeSymbol.java index c9d071c46cd2..a38cc8df10d4 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableTypeSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableTypeSymbol.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Names; @@ -37,12 +38,15 @@ */ public class BInvokableTypeSymbol extends BTypeSymbol { + @Nullable public List params; + @Nullable public BVarSymbol restParam; + @Nullable public BType returnType; public List returnTypeAnnots; public Map defaultValues; - public BInvokableTypeSymbol(long symTag, long flags, PackageID pkgID, BType type, BSymbol owner, + public BInvokableTypeSymbol(long symTag, long flags, PackageID pkgID, @Nullable BType type, BSymbol owner, Location location, SymbolOrigin origin) { super(symTag, flags, Names.EMPTY, Names.EMPTY, pkgID, type, owner, location, origin); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BOperatorSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BOperatorSymbol.java index 71c616932b84..05edf2083cb2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BOperatorSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BOperatorSymbol.java @@ -20,6 +20,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; import org.wso2.ballerinalang.util.Flags; @@ -29,7 +30,7 @@ */ public class BOperatorSymbol extends BInvokableSymbol { - public BOperatorSymbol(Name name, PackageID pkgID, BType type, BSymbol owner, Location pos, + public BOperatorSymbol(Name name, @Nullable PackageID pkgID, BType type, @Nullable BSymbol owner, Location pos, SymbolOrigin origin) { super(SymTag.INVOKABLE, Flags.PUBLIC, name, pkgID, type, owner, pos, origin); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BPackageSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BPackageSymbol.java index aecf695a9253..7e9917bf13bd 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BPackageSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BPackageSymbol.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; import org.ballerinalang.repository.CompiledPackage; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.bir.model.BIRNode; import org.wso2.ballerinalang.compiler.semantics.model.types.BPackageType; import org.wso2.ballerinalang.compiler.util.Name; @@ -53,12 +54,13 @@ public class BPackageSymbol extends BTypeSymbol { // TODO Temporary mechanism to hold a reference to the generated bir model public BIRNode.BIRPackage bir; // TODO try to remove this + @Nullable public BIRPackageFile birPackageFile; // TODO Refactor following two flags public boolean entryPointExists = false; - public BPackageSymbol(PackageID pkgID, BSymbol owner, Location pos, SymbolOrigin origin) { + public BPackageSymbol(PackageID pkgID, @Nullable BSymbol owner, @Nullable Location pos, SymbolOrigin origin) { super(PACKAGE, 0, pkgID.name, pkgID, null, owner, pos, origin); this.type = new BPackageType(this); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BRecordTypeSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BRecordTypeSymbol.java index 05250a3d66ad..d14fcb019916 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BRecordTypeSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BRecordTypeSymbol.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; @@ -36,8 +37,8 @@ public class BRecordTypeSymbol extends BStructureTypeSymbol { public Map defaultValues; - public BRecordTypeSymbol(long symTag, long flags, Name name, PackageID pkgID, BType type, BSymbol owner, - Location pos, SymbolOrigin origin) { + public BRecordTypeSymbol(long symTag, long flags, Name name, PackageID pkgID, @Nullable BType type, + @Nullable BSymbol owner, Location pos, SymbolOrigin origin) { super(SymbolKind.RECORD, symTag, flags, name, pkgID, type, owner, pos, origin); this.defaultValues = new HashMap<>(); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BResourceFunction.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BResourceFunction.java index 7cc5fd7eea01..da548da7212c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BResourceFunction.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BResourceFunction.java @@ -19,6 +19,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.symbols.SymbolKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; @@ -40,7 +41,7 @@ public class BResourceFunction extends BAttachedFunction { public BResourceFunction(Name funcName, BInvokableSymbol symbol, BInvokableType type, Name accessor, List pathParams, - BVarSymbol restPathParam, Location pos) { + @Nullable BVarSymbol restPathParam, Location pos) { super(funcName, symbol, type, pos); this.accessor = accessor; this.pathParams = pathParams; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BServiceSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BServiceSymbol.java index b44bebb5073e..943b82ec5942 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BServiceSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BServiceSymbol.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; @@ -39,7 +40,7 @@ public class BServiceSymbol extends BSymbol { private List absResourcePath; private String attachPointStringLiteral; - public BServiceSymbol(BClassSymbol associatedClass, long flags, Name name, PackageID pkgID, BType type, + public BServiceSymbol(BClassSymbol associatedClass, long flags, Name name, PackageID pkgID, @Nullable BType type, BSymbol owner, Location pos, SymbolOrigin origin) { super(SymTag.SERVICE, flags, name, pkgID, type, owner, pos, origin); this.associatedClass = associatedClass; @@ -63,11 +64,11 @@ public List getListenerTypes() { return this.listenerTypes; } - public void setAbsResourcePath(List absResourcePath) { + public void setAbsResourcePath(@Nullable List absResourcePath) { this.absResourcePath = absResourcePath; } - public void setAttachPointStringLiteral(String attachPointStringLiteral) { + public void setAttachPointStringLiteral(@Nullable String attachPointStringLiteral) { this.attachPointStringLiteral = attachPointStringLiteral; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeDefinitionSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeDefinitionSymbol.java index 96e512269ae0..d74cf8c2b5eb 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeDefinitionSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeDefinitionSymbol.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.symbols.AnnotationAttachmentSymbol; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.semantics.model.types.BTypeReferenceType; import org.wso2.ballerinalang.compiler.util.Name; @@ -36,6 +37,7 @@ */ public class BTypeDefinitionSymbol extends BSymbol implements Annotatable { + @Nullable public BTypeReferenceType referenceType = null; private final List annAttachments; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeSymbol.java index 9ce372d8fdd0..03d11b225793 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BTypeSymbol.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolOrigin; import org.ballerinalang.model.symbols.TypeSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; import org.wso2.ballerinalang.compiler.util.Names; @@ -34,12 +35,12 @@ public class BTypeSymbol extends BSymbol implements TypeSymbol { public BTypeSymbol typeParamTSymbol; public BVarSymbol annotations; - public BTypeSymbol(long symTag, long flags, Name name, PackageID pkgID, BType type, BSymbol owner, + public BTypeSymbol(long symTag, long flags, Name name, PackageID pkgID, @Nullable BType type, BSymbol owner, Location pos, SymbolOrigin origin) { this(symTag, flags, name, name, pkgID, type, owner, pos, origin); } - public BTypeSymbol(long symTag, long flags, Name name, Name originalName, PackageID pkgID, BType type, + public BTypeSymbol(long symTag, long flags, Name name, Name originalName, PackageID pkgID, @Nullable BType type, BSymbol owner, Location pos, SymbolOrigin origin) { super(symTag, flags, name, originalName, pkgID, type, owner, pos, origin); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BVarSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BVarSymbol.java index 1c900cbbbb8f..099ed31c8e2c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BVarSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BVarSymbol.java @@ -25,6 +25,7 @@ import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; import org.ballerinalang.model.symbols.VariableSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.util.Name; @@ -44,17 +45,18 @@ public class BVarSymbol extends BSymbol implements VariableSymbol, Annotatable { public DiagnosticState state = DiagnosticState.VALID; // Only used for type-narrowing. Cache of the original symbol. + @Nullable public BVarSymbol originalSymbol; - public BVarSymbol(long flags, Name name, Name originalName, PackageID pkgID, BType type, BSymbol owner, - Location pos, SymbolOrigin origin) { + public BVarSymbol(long flags, Name name, Name originalName, @Nullable PackageID pkgID, BType type, + @Nullable BSymbol owner, @Nullable Location pos, SymbolOrigin origin) { super(VARIABLE, flags, name, originalName, pkgID, type, owner, pos, origin); this.annotationAttachments = new ArrayList<>(); this.kind = SymbolKind.VARIABLE; } - public BVarSymbol(long flags, Name name, PackageID pkgID, BType type, BSymbol owner, Location pos, - SymbolOrigin origin) { + public BVarSymbol(long flags, @Nullable Name name, @Nullable PackageID pkgID, @Nullable BType type, + @Nullable BSymbol owner, @Nullable Location pos, @Nullable SymbolOrigin origin) { this(flags, name, name, pkgID, type, owner, pos, origin); } @@ -77,6 +79,7 @@ public List getAnnotations() { return this.annotationAttachments; } + @Nullable @Override public Object getConstValue() { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BXMLAttributeSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BXMLAttributeSymbol.java index c9add56b0488..37ba252f14b9 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BXMLAttributeSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BXMLAttributeSymbol.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolOrigin; import org.ballerinalang.model.symbols.VariableSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BNoType; import org.wso2.ballerinalang.compiler.util.NodeUtils; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -36,6 +37,7 @@ public BXMLAttributeSymbol(String localname, String namespaceURI, PackageID pkgI origin); } + @Nullable @Override public Object getConstValue() { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BXMLNSSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BXMLNSSymbol.java index f12c6d67019a..0c4724e8a0a6 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BXMLNSSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BXMLNSSymbol.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; import org.ballerinalang.model.symbols.VariableSymbol; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BNoType; import org.wso2.ballerinalang.compiler.util.Name; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -38,7 +39,7 @@ public class BXMLNSSymbol extends BSymbol implements VariableSymbol { // Applicable to only module level XMLNS declarations public Name compUnit; - public BXMLNSSymbol(Name prefix, String namespaceURI, PackageID pkgID, BSymbol owner, Location pos, + public BXMLNSSymbol(Name prefix, @Nullable String namespaceURI, PackageID pkgID, BSymbol owner, Location pos, SymbolOrigin origin) { super(SymTag.XMLNS, 0, prefix, pkgID, new BNoType(TypeTags.XMLNS), owner, pos, origin); this.namespaceURI = namespaceURI; @@ -53,6 +54,7 @@ public BXMLNSSymbol(Name prefix, String namespaceURI, PackageID pkgID, BSymbol o this.compUnit = compUnit; } + @Nullable @Override public Object getConstValue() { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/Symbols.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/Symbols.java index 650806f4204b..f01dd38fbe46 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/Symbols.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/Symbols.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; import org.ballerinalang.model.symbols.SymbolOrigin; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.Scope; import org.wso2.ballerinalang.compiler.semantics.model.SymbolTable; @@ -72,7 +73,7 @@ private static BPackageSymbol createPackageSymbolScope(SymbolTable symTable, public static BObjectTypeSymbol createObjectSymbol(long flags, Name name, PackageID pkgID, - BType type, + @Nullable BType type, BSymbol owner, Location pos, SymbolOrigin origin) { @@ -83,13 +84,13 @@ public static BObjectTypeSymbol createObjectSymbol(long flags, } public static BClassSymbol createClassSymbol(long flags, - Name name, - PackageID pkgID, - BType type, - BSymbol owner, - Location pos, - SymbolOrigin origin, - boolean isServiceDecl) { + Name name, + PackageID pkgID, + @Nullable BType type, + BSymbol owner, + Location pos, + SymbolOrigin origin, + boolean isServiceDecl) { BClassSymbol typeSymbol = new BClassSymbol(SymTag.OBJECT, flags, name, pkgID, type, owner, pos, origin); typeSymbol.kind = SymbolKind.OBJECT; // This class represent the service declared via service declaration. @@ -100,9 +101,9 @@ public static BClassSymbol createClassSymbol(long flags, public static BRecordTypeSymbol createRecordSymbol(long flags, Name name, PackageID pkgID, - BType type, - BSymbol owner, - Location pos, + @Nullable BType type, + @Nullable BSymbol owner, + @Nullable Location pos, SymbolOrigin origin) { BRecordTypeSymbol typeSymbol = new BRecordTypeSymbol(SymTag.RECORD, flags, name, pkgID, type, owner, pos, origin); @@ -110,14 +111,16 @@ public static BRecordTypeSymbol createRecordSymbol(long flags, return typeSymbol; } - public static BErrorTypeSymbol createErrorSymbol(long flags, Name name, PackageID pkgID, BType type, BSymbol owner, - Location pos, SymbolOrigin origin) { + public static BErrorTypeSymbol createErrorSymbol( + long flags, Name name, PackageID pkgID, @Nullable BType type, BSymbol owner, Location pos, + SymbolOrigin origin) { return new BErrorTypeSymbol(SymTag.ERROR, flags, name, pkgID, type, owner, pos, origin); } - public static BAnnotationSymbol createAnnotationSymbol(long flags, Set points, Name name, - Name origName, PackageID pkgID, BType type, BSymbol owner, - Location pos, SymbolOrigin origin) { + public static BAnnotationSymbol createAnnotationSymbol( + long flags, Set points, Name name, + Name origName, PackageID pkgID, @Nullable BType type, BSymbol owner, + Location pos, SymbolOrigin origin) { BAnnotationSymbol annotationSymbol = new BAnnotationSymbol(name, origName, flags, points, pkgID, type, owner, pos, origin); annotationSymbol.kind = SymbolKind.ANNOTATION; @@ -142,8 +145,8 @@ public static BInvokableSymbol createFunctionSymbol(long flags, Name name, Name originalName, PackageID pkgID, - BType type, - BSymbol owner, + @Nullable BType type, + @Nullable BSymbol owner, boolean bodyExist, Location pos, SymbolOrigin origin) { @@ -158,9 +161,9 @@ public static BTypeSymbol createTypeSymbol(long symTag, long flags, Name name, PackageID pkgID, - BType type, + @Nullable BType type, BSymbol owner, - Location pos, + @Nullable Location pos, SymbolOrigin origin) { return createTypeSymbol(symTag, flags, name, name, pkgID, type, owner, pos, origin); } @@ -170,7 +173,7 @@ public static BTypeSymbol createTypeSymbol(long symTag, Name name, Name originalName, PackageID pkgID, - BType type, + @Nullable BType type, BSymbol owner, Location pos, SymbolOrigin origin) { @@ -186,7 +189,7 @@ public static BTypeSymbol createTypeSymbol(long symTag, public static BTypeDefinitionSymbol createTypeDefinitionSymbol(long flags, Name name, PackageID pkgID, - BType type, + @Nullable BType type, BSymbol owner, Location pos, SymbolOrigin origin) { @@ -197,7 +200,7 @@ public static BTypeDefinitionSymbol createTypeDefinitionSymbol(long flags, public static BInvokableTypeSymbol createInvokableTypeSymbol(long symTag, long flags, PackageID pkgID, - BType type, + @Nullable BType type, BSymbol owner, Location pos, SymbolOrigin origin) { @@ -221,18 +224,19 @@ public static BXMLNSSymbol createXMLNSSymbol(Name name, PackageID pkgID, BSymbol owner, Location pos, - SymbolOrigin origin, Name compUnit) { + SymbolOrigin origin, @Nullable Name compUnit) { return new BXMLNSSymbol(name, nsURI, pkgID, owner, pos, origin, compUnit); } - public static BResourcePathSegmentSymbol createResourcePathSegmentSymbol(Name name, - PackageID pkgID, - BType type, - BSymbol owner, - Location location, - BResourcePathSegmentSymbol parentResource, - BResourceFunction resourceMethod, - SymbolOrigin origin) { + public static BResourcePathSegmentSymbol createResourcePathSegmentSymbol( + Name name, + PackageID pkgID, + BType type, + BSymbol owner, + Location location, + @Nullable BResourcePathSegmentSymbol parentResource, + BResourceFunction resourceMethod, + SymbolOrigin origin) { return new BResourcePathSegmentSymbol(name, pkgID, type, owner, location, parentResource, resourceMethod, origin); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnyType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnyType.java index 0991d500ead1..8be118284600 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnyType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnyType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -31,11 +32,11 @@ public class BAnyType extends BBuiltInRefType implements SelectivelyImmutableReferenceType { private boolean nullable = true; - public BAnyType(int tag, BTypeSymbol tsymbol) { + public BAnyType(int tag, @Nullable BTypeSymbol tsymbol) { super(tag, tsymbol); } - public BAnyType(int tag, BTypeSymbol tsymbol, Name name, long flag) { + public BAnyType(int tag, @Nullable BTypeSymbol tsymbol, Name name, long flag) { super(tag, tsymbol); this.name = name; this.flags = flag; @@ -46,7 +47,7 @@ public BAnyType(int tag, BTypeSymbol tsymbol, boolean nullable) { this.nullable = nullable; } - public BAnyType(int tag, BTypeSymbol tsymbol, Name name, long flags, boolean nullable) { + public BAnyType(int tag, @Nullable BTypeSymbol tsymbol, Name name, long flags, boolean nullable) { super(tag, tsymbol); this.name = name; this.flags = flags; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnydataType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnydataType.java index cdfe4f488060..28fda9a5cfe1 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnydataType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BAnydataType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -46,7 +47,7 @@ public BAnydataType(BTypeSymbol tsymbol, boolean nullable) { this.isCyclic = true; } - public BAnydataType(BTypeSymbol tsymbol, Name name, long flags, boolean nullable) { + public BAnydataType(@Nullable BTypeSymbol tsymbol, Name name, long flags, boolean nullable) { super(tsymbol, new LinkedHashSet<>(INITIAL_CAPACITY), nullable, false); this.tag = TypeTags.ANYDATA; this.flags = flags; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BArrayType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BArrayType.java index be1b2986bb68..f042d259ddc9 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BArrayType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BArrayType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.ArrayType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -36,6 +37,7 @@ public class BArrayType extends BType implements ArrayType { public BArrayState state = BArrayState.OPEN; + @Nullable public BArrayType mutableType; public BArrayType(BType elementType) { @@ -48,14 +50,14 @@ public BArrayType(BType elementType, BTypeSymbol tsymbol) { this.eType = elementType; } - public BArrayType(BType elementType, BTypeSymbol tsymbol, int size, BArrayState state) { + public BArrayType(BType elementType, @Nullable BTypeSymbol tsymbol, int size, BArrayState state) { super(TypeTags.ARRAY, tsymbol); this.eType = elementType; this.size = size; this.state = state; } - public BArrayType(BType elementType, BTypeSymbol tsymbol, int size, BArrayState state, long flags) { + public BArrayType(@Nullable BType elementType, BTypeSymbol tsymbol, int size, BArrayState state, long flags) { super(TypeTags.ARRAY, tsymbol, flags); this.eType = elementType; this.size = size; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BErrorType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BErrorType.java index 89e0892f9910..a8c47094d893 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BErrorType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BErrorType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.ErrorType; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -36,7 +37,7 @@ public class BErrorType extends BType implements ErrorType { private static final String ERROR = "error<"; private static final String CLOSE_ERROR = ">"; - public BErrorType(BTypeSymbol tSymbol, BType detailType) { + public BErrorType(@Nullable BTypeSymbol tSymbol, @Nullable BType detailType) { super(TypeTags.ERROR, tSymbol, Flags.READONLY); this.detailType = detailType; this.typeIdSet = BTypeIdSet.emptySet(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BField.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BField.java index dd1169d36d1d..58c4fbaed7a4 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BField.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BField.java @@ -19,6 +19,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.types.Field; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.util.Name; @@ -37,7 +38,7 @@ public class BField implements Field, NamedNode { //Position for BIR model public Location pos; - public BField(Name name, Location pos, BVarSymbol symbol) { + public BField(Name name, @Nullable Location pos, BVarSymbol symbol) { this.name = name; this.pos = pos; this.symbol = symbol; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFiniteType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFiniteType.java index 45c5512ef81f..50b353461b65 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFiniteType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFiniteType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.types.FiniteType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression; @@ -48,7 +49,7 @@ public BFiniteType(BTypeSymbol tsymbol) { this.flags |= Flags.READONLY; } - public BFiniteType(BTypeSymbol tsymbol, Set valueSpace) { + public BFiniteType(@Nullable BTypeSymbol tsymbol, Set valueSpace) { super(TypeTags.FINITE, tsymbol); this.valueSpace = valueSpace; this.flags |= Flags.READONLY; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFutureType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFutureType.java index 4cb0b0b72cd7..c39bf3a60bda 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFutureType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BFutureType.java @@ -17,6 +17,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.ConstrainedType; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -31,12 +32,12 @@ public class BFutureType extends BBuiltInRefType implements ConstrainedType { public BType constraint; public boolean workerDerivative; - public BFutureType(int tag, BType constraint, BTypeSymbol tsymbol) { + public BFutureType(int tag, @Nullable BType constraint, @Nullable BTypeSymbol tsymbol) { super(tag, tsymbol); this.constraint = constraint; } - public BFutureType(int tag, BType constraint, BTypeSymbol tsymbol, boolean workerDerivative) { + public BFutureType(int tag, BType constraint, @Nullable BTypeSymbol tsymbol, boolean workerDerivative) { this(tag, constraint, tsymbol); this.workerDerivative = workerDerivative; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BHandleType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BHandleType.java index 8c535433699d..231b5d647353 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BHandleType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BHandleType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.util.Flags; @@ -31,7 +32,7 @@ */ public class BHandleType extends BBuiltInRefType { - public BHandleType(int tag, BTypeSymbol tsymbol) { + public BHandleType(int tag, @Nullable BTypeSymbol tsymbol) { super(tag, tsymbol, Flags.READONLY); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntersectionType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntersectionType.java index 6c3bba3fcfe5..5b16eaa65b40 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntersectionType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BIntersectionType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.IntersectionType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -41,7 +42,7 @@ public class BIntersectionType extends BType implements IntersectionType { private LinkedHashSet constituentTypes; - public BIntersectionType(BTypeSymbol tsymbol, LinkedHashSet types, + public BIntersectionType(@Nullable BTypeSymbol tsymbol, LinkedHashSet types, BType effectiveType) { super(TypeTags.INTERSECTION, tsymbol); this.constituentTypes = toFlatTypeSet(types); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BInvokableType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BInvokableType.java index 3882ba40fde0..3ce8aaf17262 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BInvokableType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BInvokableType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.InvokableType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -34,17 +35,20 @@ public class BInvokableType extends BType implements InvokableType { public List paramTypes; + @Nullable public BType restType; + @Nullable public BType retType; - public BInvokableType(List paramTypes, BType restType, BType retType, BTypeSymbol tsymbol) { + public BInvokableType(@Nullable List paramTypes, @Nullable BType restType, @Nullable BType retType, + @Nullable BTypeSymbol tsymbol) { super(TypeTags.INVOKABLE, tsymbol, Flags.READONLY); this.paramTypes = paramTypes; this.restType = restType; this.retType = retType; } - public BInvokableType(List paramTypes, BType retType, BTypeSymbol tsymbol) { + public BInvokableType(List paramTypes, BType retType, @Nullable BTypeSymbol tsymbol) { this(paramTypes, null, retType, tsymbol); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BMapType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BMapType.java index 3112abb1d6c8..891d4551a346 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BMapType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BMapType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.ConstrainedType; import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -30,14 +31,15 @@ */ public class BMapType extends BBuiltInRefType implements ConstrainedType, SelectivelyImmutableReferenceType { public BType constraint; + @Nullable public BMapType mutableType; - public BMapType(int tag, BType constraint, BTypeSymbol tsymbol) { + public BMapType(int tag, BType constraint, @Nullable BTypeSymbol tsymbol) { super(tag, tsymbol); this.constraint = constraint; } - public BMapType(int tag, BType constraint, BTypeSymbol tsymbol, long flags) { + public BMapType(int tag, @Nullable BType constraint, @Nullable BTypeSymbol tsymbol, long flags) { super(tag, tsymbol, flags); this.constraint = constraint; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BObjectType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BObjectType.java index 8abd29cc8474..56b352c8a30d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BObjectType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BObjectType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.ObjectType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BAttachedFunction; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BObjectTypeSymbol; @@ -44,6 +45,7 @@ public class BObjectType extends BStructureType implements ObjectType { private static final String READONLY = "readonly"; public boolean markedIsolatedness; + @Nullable public BObjectType mutableType = null; public BLangClassDefinition classDef = null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BParameterizedType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BParameterizedType.java index f966d588da46..0eaf3b09d152 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BParameterizedType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BParameterizedType.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.semantics.model.types; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; @@ -37,7 +38,8 @@ public class BParameterizedType extends BType { public BType paramValueType; public int paramIndex; - public BParameterizedType(BType valueType, BVarSymbol paramSymbol, BTypeSymbol tSymbol, Name name, int paramIndex) { + public BParameterizedType(@Nullable BType valueType, @Nullable BVarSymbol paramSymbol, + @Nullable BTypeSymbol tSymbol, Name name, int paramIndex) { super(TypeTags.PARAMETERIZED_TYPE, tSymbol); this.paramSymbol = paramSymbol; this.paramValueType = valueType; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BReadonlyType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BReadonlyType.java index b59d62a41f4a..ceebea43e9af 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BReadonlyType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BReadonlyType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.util.Flags; @@ -31,12 +32,12 @@ public class BReadonlyType extends BBuiltInRefType { private boolean nullable = true; - public BReadonlyType(int tag, BTypeSymbol tsymbol) { + public BReadonlyType(int tag, @Nullable BTypeSymbol tsymbol) { super(tag, tsymbol); this.flags |= Flags.READONLY; } - public BReadonlyType(int tag, BTypeSymbol tsymbol, Name name, long flag) { + public BReadonlyType(int tag, @Nullable BTypeSymbol tsymbol, Name name, long flag) { super(tag, tsymbol); this.name = name; this.flags = flag; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java index a6933f7e6856..20a40537bc08 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.RecordType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -41,16 +42,18 @@ public class BRecordType extends BStructureType implements RecordType { public static final String EMPTY = ""; public static final String READONLY = "readonly"; public boolean sealed; + @Nullable public BType restFieldType; public Boolean isAnyData = null; + @Nullable public BRecordType mutableType; - public BRecordType(BTypeSymbol tSymbol) { + public BRecordType(@Nullable BTypeSymbol tSymbol) { super(TypeTags.RECORD, tSymbol); } - public BRecordType(BTypeSymbol tSymbol, long flags) { + public BRecordType(@Nullable BTypeSymbol tSymbol, long flags) { super(TypeTags.RECORD, tSymbol, flags); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStreamType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStreamType.java index e71f6997b6f1..b4b274565322 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStreamType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BStreamType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.types.StreamType; import org.ballerinalang.model.types.Type; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -34,7 +35,8 @@ public class BStreamType extends BBuiltInRefType implements StreamType { public BType constraint; public BType completionType; - public BStreamType(int tag, BType constraint, BType completionType, BTypeSymbol tsymbol) { + public BStreamType(int tag, @Nullable BType constraint, @Nullable BType completionType, + @Nullable BTypeSymbol tsymbol) { super(tag, tsymbol); this.constraint = constraint; this.completionType = completionType != null ? completionType : new BNilType(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTableType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTableType.java index d4c3ce7fea6d..c9302c13f009 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTableType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTableType.java @@ -21,6 +21,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.types.TableType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -36,20 +37,22 @@ */ public class BTableType extends BType implements TableType { public BType constraint; + @Nullable public BType keyTypeConstraint; public List fieldNameList = new ArrayList<>(); public Location keyPos; public boolean isTypeInlineDefined; public Location constraintPos; + @Nullable public BTableType mutableType; - public BTableType(int tag, BType constraint, BTypeSymbol tSymbol) { + public BTableType(int tag, BType constraint, @Nullable BTypeSymbol tSymbol) { super(tag, tSymbol); this.constraint = constraint; } - public BTableType(int tag, BType constraint, BTypeSymbol tSymbol, long flags) { + public BTableType(int tag, @Nullable BType constraint, BTypeSymbol tSymbol, long flags) { super(tag, tSymbol, flags); this.constraint = constraint; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java index 6b647c1c2052..0125942d0af4 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java @@ -18,6 +18,7 @@ import org.ballerinalang.model.types.TupleType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -35,12 +36,15 @@ */ public class BTupleType extends BType implements TupleType { private List members; + @Nullable private List memberTypes; + @Nullable public BType restType; public Boolean isAnyData = null; public boolean resolvingToString = false; public boolean isCyclic = false; + @Nullable public BTupleType mutableType; public BTupleType(List members) { @@ -48,24 +52,24 @@ public BTupleType(List members) { this.members = members; } - public BTupleType(BTypeSymbol tsymbol, List members) { + public BTupleType(@Nullable BTypeSymbol tsymbol, List members) { super(TypeTags.TUPLE, tsymbol); this.members = members; } - public BTupleType(BTypeSymbol tsymbol, List members, boolean isCyclic) { + public BTupleType(@Nullable BTypeSymbol tsymbol, List members, boolean isCyclic) { super(TypeTags.TUPLE, tsymbol); this.members = members; this.isCyclic = isCyclic; } - public BTupleType(BTypeSymbol tsymbol, List members, BType restType, long flags) { + public BTupleType(@Nullable BTypeSymbol tsymbol, List members, BType restType, long flags) { super(TypeTags.TUPLE, tsymbol, flags); this.members = members; this.restType = restType; } - public BTupleType(BTypeSymbol tsymbol, List members, BType restType, long flags, + public BTupleType(BTypeSymbol tsymbol, List members, @Nullable BType restType, long flags, boolean isCyclic) { super(TypeTags.TUPLE, tsymbol, flags); this.members = members; @@ -176,7 +180,7 @@ public void setMembers(List members) { this.members = members; } - private void setCyclicFlag(BType type) { + private void setCyclicFlag(@Nullable BType type) { if (isCyclic) { return; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BType.java index a60272975151..a2b27de9213d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.Name; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.model.types.ValueType; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.Names; @@ -53,27 +54,28 @@ public class BType implements ValueType { public Name name; public long flags; - public BType(int tag, BTypeSymbol tsymbol) { + public BType(int tag, @Nullable BTypeSymbol tsymbol) { this.tag = tag; this.tsymbol = tsymbol; this.name = Names.EMPTY; this.flags = 0; } - public BType(int tag, BTypeSymbol tsymbol, long flags) { + public BType(int tag, @Nullable BTypeSymbol tsymbol, long flags) { this.tag = tag; this.tsymbol = tsymbol; this.name = Names.EMPTY; this.flags = flags; } - public BType(int tag, BTypeSymbol tsymbol, Name name, long flags) { + public BType(int tag, @Nullable BTypeSymbol tsymbol, Name name, long flags) { this.tag = tag; this.tsymbol = tsymbol; this.name = name; this.flags = flags; } + @Nullable public BType getReturnType() { return null; } @@ -82,7 +84,7 @@ public boolean isNullable() { return false; } - public R accept(BTypeVisitor visitor, T t) { + public R accept(BTypeVisitor visitor, @Nullable T t) { return visitor.visit(this, t); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeIdSet.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeIdSet.java index 165982bd9438..ed5b2ac5311c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeIdSet.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeIdSet.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.CompilerUtils; import java.util.ArrayList; @@ -37,8 +38,11 @@ public class BTypeIdSet { private final List> secondary; // cache + @Nullable private Set primaryAll = null; + @Nullable private Set secondaryAll = null; + @Nullable private Set all = null; public BTypeIdSet(Set primary, Set secondary) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeReferenceType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeReferenceType.java index 4914628e9a6d..11825521b9b2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeReferenceType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypeReferenceType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.ReferenceType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; @@ -39,7 +40,7 @@ public BTypeReferenceType(BType referredType, BTypeSymbol tsymbol, long flags) { this.definitionName = tsymbol.getName().getValue(); } - public BTypeReferenceType(BType referredType, BTypeSymbol tsymbol, long flags, boolean nilable) { + public BTypeReferenceType(@Nullable BType referredType, BTypeSymbol tsymbol, long flags, boolean nilable) { this(referredType, tsymbol, flags); this.nilable = nilable; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypedescType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypedescType.java index cdd883b5b4e5..4479f9ad0d58 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypedescType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTypedescType.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.ConstrainedType; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -30,7 +31,7 @@ public class BTypedescType extends BBuiltInRefType implements ConstrainedType { public BType constraint; - public BTypedescType(BType constraint, BTypeSymbol tsymbol) { + public BTypedescType(@Nullable BType constraint, @Nullable BTypeSymbol tsymbol) { super(TypeTags.TYPEDESC, tsymbol, Flags.READONLY); this.constraint = constraint; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java index b73167676809..27b80ac6b85d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.model.types.UnionType; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -60,7 +61,8 @@ public class BUnionType extends BType implements UnionType { private static final Pattern pCloneable = Pattern.compile(INT_CLONEABLE); private static final Pattern pCloneableType = Pattern.compile(CLONEABLE_TYPE); - public BUnionType(BTypeSymbol tsymbol, LinkedHashSet memberTypes, boolean nullable, boolean readonly) { + public BUnionType(@Nullable BTypeSymbol tsymbol, LinkedHashSet memberTypes, boolean nullable, + boolean readonly) { this(tsymbol, memberTypes, memberTypes, nullable, readonly); } @@ -162,7 +164,7 @@ public void setNullable(boolean nullable) { * @param isCyclic The cyclic indicator. * @return The created union type. */ - public static BUnionType create(BTypeSymbol tsymbol, LinkedHashSet types, boolean isCyclic) { + public static BUnionType create(@Nullable BTypeSymbol tsymbol, LinkedHashSet types, boolean isCyclic) { LinkedHashSet memberTypes = new LinkedHashSet<>(types.size()); boolean isImmutable = true; boolean hasNilableType = false; @@ -177,7 +179,7 @@ public static BUnionType create(BTypeSymbol tsymbol, LinkedHashSet types, * @param types The types to be used to define the union. * @return The created union type. */ - public static BUnionType create(BTypeSymbol tsymbol, LinkedHashSet types) { + public static BUnionType create(@Nullable BTypeSymbol tsymbol, LinkedHashSet types) { LinkedHashSet memberTypes = new LinkedHashSet<>(types.size()); if (types.isEmpty()) { @@ -234,7 +236,7 @@ public static BUnionType create(BTypeSymbol tsymbol, LinkedHashSet types) * @param types The types to be used to define the union. * @return The created union type. */ - public static BUnionType create(BTypeSymbol tsymbol, BType... types) { + public static BUnionType create(@Nullable BTypeSymbol tsymbol, BType... types) { LinkedHashSet memberTypes = new LinkedHashSet<>(types.length); memberTypes.addAll(Arrays.asList(types)); return create(tsymbol, memberTypes); @@ -410,6 +412,7 @@ public static LinkedHashSet toFlatTypeSet(LinkedHashSet types) { * @return the implied type if provided with a type reference type or an intersection type, * else returns the original type */ + @Nullable public static BType getImpliedType(BType type) { type = getReferredType(type); if (type != null && type.tag == TypeTags.INTERSECTION) { @@ -419,6 +422,7 @@ public static BType getImpliedType(BType type) { return type; } + @Nullable private static BType getReferredType(BType type) { if (type != null && type.tag == TypeTags.TYPEREFDESC) { return getReferredType(((BTypeReferenceType) type).referredType); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLType.java index f86112006093..50ec3c639aac 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BXMLType.java @@ -17,6 +17,7 @@ package org.wso2.ballerinalang.compiler.semantics.model.types; import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; @@ -31,14 +32,15 @@ */ public class BXMLType extends BBuiltInRefType implements SelectivelyImmutableReferenceType { public BType constraint; + @Nullable public BXMLType mutableType; - public BXMLType(BType constraint, BTypeSymbol tsymbol) { + public BXMLType(BType constraint, @Nullable BTypeSymbol tsymbol) { super(TypeTags.XML, tsymbol); this.constraint = constraint; } - public BXMLType(BType constraint, BTypeSymbol tsymbol, long flags) { + public BXMLType(@Nullable BType constraint, BTypeSymbol tsymbol, long flags) { super(TypeTags.XML, tsymbol, flags); this.constraint = constraint; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangAnnotation.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangAnnotation.java index d073ba3818d2..6a52f53fe3aa 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangAnnotation.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangAnnotation.java @@ -25,6 +25,7 @@ import org.ballerinalang.model.tree.MarkdownDocumentationNode; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.types.TypeNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.tree.types.BLangType; @@ -58,7 +59,7 @@ public BLangAnnotation() { this.attachPoints = new HashSet<>(); } - public void addAttachPoint(AttachPoint attachmentPoint) { + public void addAttachPoint(@Nullable AttachPoint attachmentPoint) { attachPoints.add(attachmentPoint); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangConstantValue.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangConstantValue.java index 71ebb1d557d1..8e76a9f25e55 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangConstantValue.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangConstantValue.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.tree; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; /** @@ -29,7 +30,7 @@ public class BLangConstantValue { public Object value; public BType type; - public BLangConstantValue(Object value, BType type) { + public BLangConstantValue(@Nullable Object value, BType type) { this.value = value; this.type = type; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangErrorVariable.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangErrorVariable.java index 7588cf43ac4a..1d873205e5c8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangErrorVariable.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangErrorVariable.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.elements.Flag; import org.ballerinalang.model.tree.ErrorVariableNode; import org.ballerinalang.model.tree.NodeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation; import org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral; @@ -41,6 +42,7 @@ public class BLangErrorVariable extends BLangVariable implements ErrorVariableNode { // BLangNodes + @Nullable public BLangSimpleVariable message; public BLangVariable cause; public BLangSimpleVariable restDetail; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangInvokableNode.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangInvokableNode.java index 779d15ef6e86..2ae669d88726 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangInvokableNode.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangInvokableNode.java @@ -26,6 +26,7 @@ import org.ballerinalang.model.tree.MarkdownDocumentationNode; import org.ballerinalang.model.tree.SimpleVariableNode; import org.ballerinalang.model.tree.types.TypeNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol; import org.wso2.ballerinalang.compiler.tree.types.BLangType; @@ -50,6 +51,7 @@ public abstract class BLangInvokableNode extends BLangNode implements InvokableN public BLangSimpleVariable restParam; public BLangType returnTypeNode; public List returnTypeAnnAttachments; + @Nullable public BLangFunctionBody body; public BLangIdentifier defaultWorkerName; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangMarkdownDocumentation.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangMarkdownDocumentation.java index 73f8cfdcaab0..3f72deda6052 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangMarkdownDocumentation.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangMarkdownDocumentation.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.tree.MarkdownDocumentationNode; import org.ballerinalang.model.tree.NodeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.expressions.BLangMarkDownDeprecatedParametersDocumentation; import org.wso2.ballerinalang.compiler.tree.expressions.BLangMarkDownDeprecationDocumentation; import org.wso2.ballerinalang.compiler.tree.expressions.BLangMarkdownDocumentationLine; @@ -43,7 +44,9 @@ public class BLangMarkdownDocumentation extends BLangNode implements MarkdownDoc public LinkedList parameters; public LinkedList references; public BLangMarkdownReturnParameterDocumentation returnParameter; + @Nullable public BLangMarkDownDeprecationDocumentation deprecationDocumentation; + @Nullable public BLangMarkDownDeprecatedParametersDocumentation deprecatedParametersDocumentation; public BLangMarkdownDocumentation() { @@ -117,6 +120,7 @@ public Map getParameterDocumentatio return parameterDocumentations; } + @Nullable @Override public String getReturnParameterDocumentation() { return returnParameter == null ? null : returnParameter.getReturnParameterDocumentation(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangNode.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangNode.java index 983692300e40..434ea26ce9b8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangNode.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangNode.java @@ -19,6 +19,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.tree.Node; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; /** @@ -47,11 +48,13 @@ public abstract class BLangNode implements Node, Cloneable { /** * The location of this node in the source file. */ + @Nullable public Location pos; /* * Following fields will be used for AST Cloning. */ + @Nullable public BLangNode cloneRef; public int cloneAttempt; @@ -65,7 +68,7 @@ public abstract class BLangNode implements Node, Cloneable { * * @param type The type of the node */ - public void setBType(BType type) { + public void setBType(@Nullable BType type) { this.type = type; this.determinedType = type; } @@ -79,7 +82,7 @@ public BType getBType() { return this.type; } - public void setDeterminedType(BType type) { + public void setDeterminedType(@Nullable BType type) { this.determinedType = type; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java index 2b53aabcaf12..10044e2a02c1 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java @@ -35,6 +35,7 @@ import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.model.tree.TypeDefinition; import org.ballerinalang.model.tree.XMLNSDeclarationNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.DiagnosticComparator; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; @@ -246,6 +247,7 @@ public List getTestablePkgs() { * * @return testable package */ + @Nullable public BLangTestablePackage getTestablePkg() { return testablePkgs.stream().findAny().orElse(null); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangService.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangService.java index 184209c9089c..61720e4c2c02 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangService.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangService.java @@ -24,6 +24,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.ServiceNode; import org.ballerinalang.model.tree.expressions.LiteralNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression; @@ -45,6 +46,7 @@ public class BLangService extends BLangNode implements ServiceNode { public List attachedExprs; public BLangClassDefinition serviceClass; public List absoluteResourcePath; + @Nullable public BLangLiteral serviceNameLiteral; public BLangIdentifier name; public List annAttachments; @@ -107,6 +109,7 @@ public LiteralNode getServiceNameLiteral() { return serviceNameLiteral; } + @Nullable @Override public Set getFlags() { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangVariable.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangVariable.java index ef4bb40c4f8c..570f225236b7 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangVariable.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangVariable.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.tree.VariableNode; import org.ballerinalang.model.tree.expressions.ExpressionNode; import org.ballerinalang.model.tree.types.TypeNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression; import org.wso2.ballerinalang.compiler.tree.types.BLangType; @@ -41,6 +42,7 @@ public abstract class BLangVariable extends BLangNode implements VariableNode { public BLangType typeNode; public List annAttachments; public BLangMarkdownDocumentation markdownDocumentationAttachment; + @Nullable public BLangExpression expr; // Parser Flags @@ -101,7 +103,7 @@ public void setTypeNode(TypeNode typeNode) { } @Override - public void setInitialExpression(ExpressionNode expr) { + public void setInitialExpression(@Nullable ExpressionNode expr) { this.expr = (BLangExpression) expr; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/OCEDynamicEnvironmentData.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/OCEDynamicEnvironmentData.java index 1782eaca95dd..62c14ff1ff59 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/OCEDynamicEnvironmentData.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/OCEDynamicEnvironmentData.java @@ -1,5 +1,6 @@ package org.wso2.ballerinalang.compiler.tree; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; @@ -22,7 +23,9 @@ public class OCEDynamicEnvironmentData { public SymbolEnv capturedClosureEnv; + @Nullable public BVarSymbol mapBlockMapSymbol; + @Nullable public BVarSymbol mapFunctionMapSymbol; public BLangTypeInit typeInit; public BObjectType objectType; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/clauses/BLangInputClause.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/clauses/BLangInputClause.java index 73de6d089454..d55f6d3c28d5 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/clauses/BLangInputClause.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/clauses/BLangInputClause.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.clauses.InputClauseNode; import org.ballerinalang.model.tree.expressions.ExpressionNode; import org.ballerinalang.model.tree.statements.VariableDefinitionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.tree.BLangNode; import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression; @@ -40,6 +41,7 @@ public abstract class BLangInputClause extends BLangNode implements InputClauseN // Semantic Data public BType varType; // T + @Nullable public BType resultType; // map public BType nillableResultType; // map? diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangBinaryExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangBinaryExpr.java index 8925114b344a..844ecd3551da 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangBinaryExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangBinaryExpr.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.OperatorKind; import org.ballerinalang.model.tree.expressions.BinaryExpressionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; @@ -37,6 +38,7 @@ public class BLangBinaryExpr extends BLangExpression implements BinaryExpression public BLangExpression rhsExpr; // Parser Flags and Data + @Nullable public OperatorKind opKind; // Semantic Data diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangCollectContextInvocation.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangCollectContextInvocation.java index 382167b98a1b..d33aa918a63a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangCollectContextInvocation.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangCollectContextInvocation.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.CollectContextInvocationNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; import org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor; @@ -48,6 +49,7 @@ public void accept(BLangNodeAnalyzer analyzer, T props) { analyzer.visit(this, props); } + @Nullable @Override public R apply(BLangNodeTransformer modifier, T props) { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangConstant.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangConstant.java index 017c294818d6..c7842ba787ed 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangConstant.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangConstant.java @@ -25,6 +25,7 @@ import org.ballerinalang.model.tree.TypeDefinition; import org.ballerinalang.model.tree.statements.ConstantNode; import org.ballerinalang.model.tree.types.TypeNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BConstantSymbol; import org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment; import org.wso2.ballerinalang.compiler.tree.BLangIdentifier; @@ -49,6 +50,7 @@ public class BLangConstant extends BLangVariable implements ConstantNode, TypeDe // BLangNodes public BLangIdentifier name; // Type definition associated with this constant. + @Nullable public BLangTypeDefinition associatedTypeDefinition; // Semantic Data diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangExpression.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangExpression.java index 9d91ad713801..98885ad616eb 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangExpression.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangExpression.java @@ -18,6 +18,7 @@ package org.wso2.ballerinalang.compiler.tree.expressions; import org.ballerinalang.model.tree.expressions.ExpressionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.semantics.model.types.BType.NarrowedTypes; @@ -39,6 +40,7 @@ public abstract class BLangExpression extends BLangNode implements ExpressionNod * populated with the generated cast expression. The tree rewrite will happen * in the 'Desugar' phase. */ + @Nullable public BLangTypeConversionExpr impConversionExpr; /** diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangFieldBasedAccess.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangFieldBasedAccess.java index 8fef6523d134..3ce91d719048 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangFieldBasedAccess.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangFieldBasedAccess.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.FieldBasedAccessNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.tree.BLangIdentifier; @@ -123,6 +124,7 @@ public static class BLangPrefixedFieldBasedAccess extends BLangFieldBasedAccess public BLangIdentifier prefix; // Semantic Data + @Nullable public BSymbol symbol; @Override diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIndexBasedAccess.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIndexBasedAccess.java index 10426e7235fa..434134a8ec16 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIndexBasedAccess.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIndexBasedAccess.java @@ -20,6 +20,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.IndexBasedAccessNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; @@ -271,7 +272,7 @@ public BLangStructFieldAccessExpr(Location pos, BLangExpression varRef, BLangExp } public BLangStructFieldAccessExpr(Location pos, BLangExpression varRef, BLangExpression keyExpr, - BVarSymbol fieldSymbol, boolean except, boolean isStoreOnCreation) { + @Nullable BVarSymbol fieldSymbol, boolean except, boolean isStoreOnCreation) { this.pos = pos; this.expr = varRef; this.indexExpr = keyExpr; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInvocation.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInvocation.java index d3b7ee0e88ac..82587768a677 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInvocation.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInvocation.java @@ -25,6 +25,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.ExpressionNode; import org.ballerinalang.model.tree.expressions.InvocationNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BResourceFunction; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; @@ -50,6 +51,7 @@ public class BLangInvocation extends BLangExpression implements InvocationNode { // BLangNodes public BLangIdentifier pkgAlias; public BLangIdentifier name; + @Nullable public BLangExpression expr; public List argExprs = new ArrayList<>(); public List annAttachments = new ArrayList<>(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLambdaFunction.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLambdaFunction.java index 1f5de0473b52..b46b43d40abe 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLambdaFunction.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLambdaFunction.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.tree.FunctionNode; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.LambdaFunctionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.tree.BLangFunction; @@ -40,6 +41,7 @@ public class BLangLambdaFunction extends BLangExpression implements LambdaFuncti public BLangFunction function; // Semantic Data + @Nullable public SymbolEnv capturedClosureEnv; public TreeMap paramMapSymbolsOfEnclInvokable = new TreeMap<>(); public TreeMap enclMapSymbols = new TreeMap<>(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLiteral.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLiteral.java index 28b96f4ddd9d..59a89fdd67ea 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLiteral.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLiteral.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.LiteralNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; @@ -30,7 +31,9 @@ public class BLangLiteral extends BLangExpression implements LiteralNode { // Parser Flags and Data + @Nullable public Object value; + @Nullable public String originalValue; public boolean isConstant; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangQueryAction.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangQueryAction.java index 568bd9ce7c16..fef57859bbbf 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangQueryAction.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangQueryAction.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.statements.QueryActionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNode; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; @@ -72,6 +73,7 @@ public void addQueryClause(BLangNode queryClause) { this.queryClauseList.add(queryClause); } + @Nullable @Override public BLangDoClause getDoClause() { for (BLangNode clause : queryClauseList) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangQueryExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangQueryExpr.java index 191dce385ec6..f5613e52fd62 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangQueryExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangQueryExpr.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.tree.IdentifierNode; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.QueryExpressionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNode; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; @@ -46,6 +47,7 @@ public class BLangQueryExpr extends BLangExpression implements QueryExpressionNo public boolean isTable = false; public boolean isMap = false; + @Nullable @Override public BLangSelectClause getSelectClause() { for (BLangNode clause : queryClauseList) { @@ -56,6 +58,7 @@ public BLangSelectClause getSelectClause() { return null; } + @Nullable @Override public BLangNode getFinalClause() { for (BLangNode clause : queryClauseList) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangRecordLiteral.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangRecordLiteral.java index 9c565f41fbc8..dccaa66834b9 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangRecordLiteral.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangRecordLiteral.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.ExpressionNode; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.tree.BLangNode; @@ -249,12 +250,14 @@ public static class BLangRecordKey extends BLangNode { // Semantic Data // This field is set only if the record type is struct. + @Nullable public BVarSymbol fieldSymbol; public BLangRecordKey(BLangExpression expr) { this.expr = expr; } + @Nullable @Override public NodeKind getKind() { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTupleVarRef.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTupleVarRef.java index e65ba1608def..f5f80ae7ed74 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTupleVarRef.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTupleVarRef.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.ExpressionNode; import org.ballerinalang.model.tree.expressions.TupleVariableReferenceNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; import org.wso2.ballerinalang.compiler.tree.BLangIdentifier; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; @@ -49,6 +50,7 @@ public BLangTupleVarRef() { this.expressions = new ArrayList<>(); } + @Nullable @Override @Deprecated public BLangIdentifier getPackageAlias() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLElementFilter.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLElementFilter.java index 21d72364d93a..4a4ada3b4e68 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLElementFilter.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLElementFilter.java @@ -20,6 +20,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.XMLElementFilter; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; @@ -36,12 +37,13 @@ public class BLangXMLElementFilter extends BLangExpression implements XMLElement public final Location nsPos; public final String namespace; public final String name; + @Nullable public BSymbol namespaceSymbol; public BLangXMLElementFilter(Location pos, String ns, - Location nsPos, + @Nullable Location nsPos, String elementName, - Location elemNamePos) { + @Nullable Location elemNamePos) { this.namespace = ns; this.name = elementName; this.pos = pos; @@ -49,11 +51,13 @@ public BLangXMLElementFilter(Location pos, String ns, this.elemNamePos = elemNamePos; } + @Nullable @Override public String getNamespace() { return null; } + @Nullable @Override public String getElementName() { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLNavigationAccess.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLNavigationAccess.java index 3973bde961b3..344d4cff729e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLNavigationAccess.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLNavigationAccess.java @@ -20,6 +20,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.XMLNavigationAccess; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; import org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor; @@ -83,6 +84,7 @@ public BLangExpression getExpression() { return this.expr; } + @Nullable @Override public String toString() { StringJoiner filters = new StringJoiner(" |"); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLQName.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLQName.java index a2ed20b01d6a..1c506d806690 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLQName.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLQName.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.tree.IdentifierNode; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.XMLQNameNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol; import org.wso2.ballerinalang.compiler.tree.BLangIdentifier; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; @@ -37,6 +38,7 @@ public class BLangXMLQName extends BLangExpression implements XMLQNameNode { public BLangIdentifier prefix; // Semantic Data + @Nullable public String namespaceURI; public BXMLNSSymbol nsSymbol; public boolean isUsedInXML = true; @@ -67,6 +69,7 @@ public void setLocalname(IdentifierNode localname) { this.localname = (BLangIdentifier) localname; } + @Nullable @Override public String getNamespaceUri() { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangCompoundAssignment.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangCompoundAssignment.java index 40e645c8d19f..825e23eefb16 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangCompoundAssignment.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangCompoundAssignment.java @@ -24,6 +24,7 @@ import org.ballerinalang.model.tree.expressions.ExpressionNode; import org.ballerinalang.model.tree.expressions.VariableReferenceNode; import org.ballerinalang.model.tree.statements.CompoundAssignmentNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; import org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor; @@ -41,6 +42,7 @@ public class BLangCompoundAssignment extends BLangStatement implements CompoundA public BLangExpression expr; // Parser Flags and Data + @Nullable public OperatorKind opKind; // Semantic Data diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangForeach.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangForeach.java index a6bc54612287..71aae2b44af2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangForeach.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangForeach.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.tree.statements.BlockStatementNode; import org.ballerinalang.model.tree.statements.ForeachNode; import org.ballerinalang.model.tree.statements.VariableDefinitionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; @@ -41,13 +42,16 @@ public class BLangForeach extends BLangStatement implements ForeachNode { public VariableDefinitionNode variableDefinitionNode; public BLangBlockStmt body; public BLangExpression collection; + @Nullable public BLangOnFailClause onFailClause; // Parser Flags and Data public boolean isDeclaredWithVar; // Semantic Data + @Nullable public BType varType; // T + @Nullable public BType resultType; // map public BType nillableResultType; // map? diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangRetry.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangRetry.java index c5d4313b717f..408ac1685b38 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangRetry.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangRetry.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.clauses.OnFailClauseNode; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.statements.RetryNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; import org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor; @@ -36,6 +37,7 @@ public class BLangRetry extends BLangStatement implements RetryNode { // BLangNodes public BLangRetrySpec retrySpec; public BLangBlockStmt retryBody; + @Nullable public BLangOnFailClause onFailClause; // Semantic Data diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangTransaction.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangTransaction.java index 882aad463d7b..020cb1f16591 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangTransaction.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangTransaction.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.statements.BlockStatementNode; import org.ballerinalang.model.tree.statements.TransactionNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; import org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor; @@ -34,6 +35,7 @@ public class BLangTransaction extends BLangStatement implements TransactionNode // BLangNodes public BLangBlockStmt transactionBody; + @Nullable public BLangOnFailClause onFailClause; // Semantic Data diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangWhile.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangWhile.java index 77f089121f3e..a5ef565ead6e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangWhile.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/statements/BLangWhile.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.tree.expressions.ExpressionNode; import org.ballerinalang.model.tree.statements.BlockStatementNode; import org.ballerinalang.model.tree.statements.WhileNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; import org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor; @@ -36,6 +37,7 @@ public class BLangWhile extends BLangStatement implements WhileNode { // BLangNodes public BLangExpression expr; public BLangBlockStmt body; + @Nullable public BLangOnFailClause onFailClause; public BLangWhile() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/types/BLangErrorType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/types/BLangErrorType.java index b0e4b551ad5d..db7e8b1926af 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/types/BLangErrorType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/types/BLangErrorType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.types.ErrorTypeNode; import org.ballerinalang.model.tree.types.TypeNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; import org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor; @@ -32,6 +33,7 @@ public class BLangErrorType extends BLangType implements ErrorTypeNode { // BLangNodes + @Nullable public BLangType detailType; // Parser Flags and Data diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/types/BLangStreamType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/types/BLangStreamType.java index 873f11102e22..2aebd467b0c2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/types/BLangStreamType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/types/BLangStreamType.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.types.StreamTypeNode; import org.ballerinalang.model.tree.types.TypeNode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; import org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor; @@ -32,6 +33,7 @@ public class BLangStreamType extends BLangType implements StreamTypeNode { // BLangNodes public BLangType type; public BLangType constraint; + @Nullable public BLangType error; public BLangStreamType() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/CompilerContext.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/CompilerContext.java index e195e113eea6..b987cf1c0d52 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/CompilerContext.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/CompilerContext.java @@ -18,6 +18,8 @@ package org.wso2.ballerinalang.compiler.util; +import org.jetbrains.annotations.Nullable; + import java.util.HashMap; import java.util.Map; @@ -41,7 +43,7 @@ public V get(Key key) { return (V) props.get(key); } - public void put(Class clazz, V value) { + public void put(Class clazz, @Nullable V value) { objects.put(clazz, value); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ImmutableTypeCloner.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ImmutableTypeCloner.java index ea65959446a4..bed0d926f092 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ImmutableTypeCloner.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ImmutableTypeCloner.java @@ -23,6 +23,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.types.SelectivelyImmutableReferenceType; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.desugar.ASTBuilderUtil; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; @@ -93,7 +94,7 @@ public final class ImmutableTypeCloner { private ImmutableTypeCloner() { } - public static BType getEffectiveImmutableType(Location pos, Types types, + public static BType getEffectiveImmutableType(@Nullable Location pos, Types types, BType type, SymbolEnv env, SymbolTable symTable, BLangAnonymousModelHelper anonymousModelHelper, Names names) { @@ -102,20 +103,17 @@ public static BType getEffectiveImmutableType(Location pos, Types types, new HashSet<>()).effectiveType; } - public static BType getEffectiveImmutableType(Location pos, Types types, - BType type, PackageID pkgId, - BSymbol owner, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, Names names) { + public static BType getEffectiveImmutableType( + @Nullable Location pos, Types types, BType type, PackageID pkgId, BSymbol owner, SymbolTable symTable, + @Nullable BLangAnonymousModelHelper anonymousModelHelper, Names names) { return getImmutableIntersectionType(pos, types, type, null, pkgId, owner, symTable, anonymousModelHelper, names, new HashSet<>(), new HashSet<>()).effectiveType; } - public static BIntersectionType getImmutableIntersectionType(Location pos, Types types, - BType type, - SymbolEnv env, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, - Names names, Set origObjFlagSet) { + public static BIntersectionType getImmutableIntersectionType( + @Nullable Location pos, Types types, BType type, SymbolEnv env, SymbolTable symTable, + BLangAnonymousModelHelper anonymousModelHelper, Names names, @Nullable Set origObjFlagSet) { return getImmutableIntersectionType(pos, types, type, env, env.enclPkg.packageID, env.scope.owner, symTable, anonymousModelHelper, names, origObjFlagSet, new HashSet<>()); } @@ -182,14 +180,10 @@ public static BType getImmutableType(Location pos, Types types, BType type, Symb unresolvedTypes); } - private static BIntersectionType getImmutableIntersectionType(Location pos, - Types types, BType bType, - SymbolEnv env, PackageID pkgId, - BSymbol owner, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, - Names names, - Set origObjFlagSet, - Set unresolvedTypes) { + private static BIntersectionType getImmutableIntersectionType( + @Nullable Location pos, Types types, BType bType, @Nullable SymbolEnv env, PackageID pkgId, + @Nullable BSymbol owner, SymbolTable symTable, @Nullable BLangAnonymousModelHelper anonymousModelHelper, + Names names, @Nullable Set origObjFlagSet, Set unresolvedTypes) { BType refType = Types.getReferredType(bType); SelectivelyImmutableReferenceType type = (SelectivelyImmutableReferenceType) refType; if (refType.tag == TypeTags.INTERSECTION && Symbols.isFlagOn(refType.flags, Flags.READONLY)) { @@ -841,6 +835,7 @@ private static BIntersectionType handleImmutableUnionType(Location pos, Types ty return immutableType; } + @Nullable private static BTypeSymbol getReadonlyTSymbol(Names names, BTypeSymbol originalTSymbol, SymbolEnv env, PackageID pkgId, BSymbol owner) { if (originalTSymbol == null) { @@ -850,6 +845,7 @@ private static BTypeSymbol getReadonlyTSymbol(Names names, BTypeSymbol originalT return getReadonlyTSymbol(originalTSymbol, env, pkgId, owner, getImmutableTypeName(names, originalTSymbol)); } + @Nullable private static BTypeSymbol getReadonlyTSymbol(BTypeSymbol originalTSymbol, SymbolEnv env, PackageID pkgId, BSymbol owner, Name immutableTypeName) { if (originalTSymbol == null) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Name.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Name.java index 0e1def40935b..f64ed85e7d72 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Name.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Name.java @@ -17,6 +17,8 @@ */ package org.wso2.ballerinalang.compiler.util; +import org.jetbrains.annotations.Nullable; + /** * @since 0.94 */ @@ -25,7 +27,7 @@ public class Name implements org.ballerinalang.model.Name { //TODO: Make this field private. public final String value; - public Name(String value) { + public Name(@Nullable String value) { this.value = value; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ProjectDirs.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ProjectDirs.java index 16259a48ed39..65b45c6565f4 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ProjectDirs.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/ProjectDirs.java @@ -19,6 +19,7 @@ import org.ballerinalang.compiler.BLangCompilerException; import org.ballerinalang.model.elements.PackageID; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.UncheckedIOException; @@ -142,6 +143,7 @@ public static boolean isProject(Path path) { * @param projectDir project path * @return project root */ + @Nullable public static Path findProjectRoot(Path projectDir) { Path path = projectDir.resolve(ProjectDirConstants.MANIFEST_FILE_NAME); if (Files.exists(path)) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/TypeDefBuilderHelper.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/TypeDefBuilderHelper.java index 727bbc9e1cdb..bdffbbca3db9 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/TypeDefBuilderHelper.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/TypeDefBuilderHelper.java @@ -22,6 +22,7 @@ import org.ballerinalang.model.elements.MarkdownDocAttachment; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.types.TypeKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.desugar.ASTBuilderUtil; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; @@ -210,8 +211,8 @@ public static BLangTypeDefinition addTypeDefinition(BType type, BTypeSymbol symb return typeDefinition; } - public static BLangTypeDefinition createTypeDefinitionForTSymbol(BType type, BSymbol symbol, BLangType typeNode, - SymbolEnv env) { + public static BLangTypeDefinition createTypeDefinitionForTSymbol( + @Nullable BType type, BSymbol symbol, BLangType typeNode, SymbolEnv env) { BLangTypeDefinition typeDefinition = (BLangTypeDefinition) TreeBuilder.createTypeDefinition(); typeDefinition.typeNode = typeNode; typeDefinition.setBType(type); @@ -282,7 +283,7 @@ public static BLangErrorType createBLangErrorType(Location pos, BErrorType type, return errorType; } - public static String getPackageAlias(SymbolEnv env, String compUnitName, PackageID typePkgId) { + public static String getPackageAlias(SymbolEnv env, @Nullable String compUnitName, PackageID typePkgId) { for (BLangImportPackage importStmt : env.enclPkg.imports) { if (importStmt == null || importStmt.compUnit == null || importStmt.compUnit.value == null || !importStmt.compUnit.value.equals(compUnitName)) { @@ -297,14 +298,15 @@ public static String getPackageAlias(SymbolEnv env, String compUnitName, Package return ""; // current module } - public static void populateStructureFieldsAndTypeInclusions(Types types, SymbolTable symTable, - BLangAnonymousModelHelper anonymousModelHelper, - Names names, BLangStructureTypeNode structureTypeNode, - BStructureType structureType, - BStructureType origStructureType, Location pos, - SymbolEnv env, PackageID pkgID, - Set unresolvedTypes, long flag, - boolean isImmutable) { + public static void populateStructureFieldsAndTypeInclusions( + Types types, SymbolTable symTable, + @Nullable BLangAnonymousModelHelper anonymousModelHelper, + Names names, BLangStructureTypeNode structureTypeNode, + BStructureType structureType, + BStructureType origStructureType, Location pos, + SymbolEnv env, PackageID pkgID, + @Nullable Set unresolvedTypes, long flag, + boolean isImmutable) { BTypeSymbol structureSymbol = structureType.tsymbol; LinkedHashMap fields = new LinkedHashMap<>(); structureType.typeInclusions = origStructureType.typeInclusions; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Unifier.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Unifier.java index 51225b103c49..8a070761425a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Unifier.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Unifier.java @@ -21,6 +21,7 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv; @@ -80,18 +81,22 @@ */ public class Unifier implements BTypeVisitor { + @Nullable private Map paramValueTypes; private Set visitedTypes = new HashSet<>(); private boolean isInvocation; private BLangInvocation invocation; + @Nullable private BLangFunction function; private SymbolTable symbolTable; + @Nullable private SymbolEnv env; private Types types; private BLangDiagnosticLog dlog; - public BType build(BType originalType, BType expType, BLangInvocation invocation, Types types, - SymbolTable symbolTable, BLangDiagnosticLog dlog) { + public BType build(BType originalType, @Nullable BType expType, + @Nullable BLangInvocation invocation, @Nullable Types types, + @Nullable SymbolTable symbolTable, @Nullable BLangDiagnosticLog dlog) { this.isInvocation = invocation != null; if (this.isInvocation) { this.invocation = invocation; @@ -944,6 +949,7 @@ private boolean isListType(int tag) { return tag == TypeTags.ARRAY || tag == TypeTags.TUPLE; } + @Nullable private BType getMatchingTypeForInferrableType(BType originalType, BType expType) { if (expType == null || !this.isInvocation) { return null; @@ -1135,6 +1141,7 @@ private List getParamsWithInferredTypedescDefault(List param // If the `expType` is `int|string|boolean` and the original type is `t|string` then the expected type for `t` // is `int|boolean`. + @Nullable private BType getExpectedTypeForInferredTypedescMember(BUnionType originalType, BType expType, BType member) { if (expType == null || !this.isInvocation || !Symbols.isFlagOn(member.flags, Flags.PARAMETERIZED)) { return null; @@ -1192,11 +1199,11 @@ private boolean isSameTypeOrError(BType newType, BType originalType) { return isSameType(newType, originalType) || isSemanticErrorInInvocation(newType); } - private boolean isSameType(BType newType, BType originalType) { + private boolean isSameType(@Nullable BType newType, @Nullable BType originalType) { return newType == originalType; } - private boolean isSemanticErrorInInvocation(BType newType) { + private boolean isSemanticErrorInInvocation(@Nullable BType newType) { return this.isInvocation && newType == symbolTable.semanticError; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/util/RepoUtils.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/util/RepoUtils.java index 856c37f6c42c..cc0fa3068690 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/util/RepoUtils.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/util/RepoUtils.java @@ -25,6 +25,7 @@ import org.ballerinalang.toml.exceptions.TomlException; import org.ballerinalang.toml.model.Manifest; import org.ballerinalang.toml.parser.ManifestProcessor; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.ProjectDirConstants; import org.wso2.ballerinalang.compiler.util.ProjectDirs; @@ -184,6 +185,7 @@ public static String getTerminalWidth() { return DEFAULT_TERMINAL_SIZE; } + @Nullable public static Path createAndGetLibsRepoPath() { String ballerinaHome = System.getProperty(ProjectDirConstants.BALLERINA_HOME); if (ballerinaHome == null || ballerinaHome.isEmpty()) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/diagnostics/SyntaxDiagnostic.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/diagnostics/SyntaxDiagnostic.java index 1ae9489efe9b..a2aa7f9b0339 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/diagnostics/SyntaxDiagnostic.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/diagnostics/SyntaxDiagnostic.java @@ -23,6 +23,7 @@ import io.ballerina.tools.diagnostics.DiagnosticCode; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticProperty; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -72,6 +73,7 @@ public String message() { return DiagnosticMessageHelper.getDiagnosticMessage(nodeDiagnostic.diagnosticCode(), nodeDiagnostic.args()); } + @Nullable @Override public List> properties() { return null; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractLexer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractLexer.java index 7d2603a57173..547fe49e64ea 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractLexer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractLexer.java @@ -24,6 +24,7 @@ import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.tools.diagnostics.DiagnosticCode; import io.ballerina.tools.text.CharReader; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; import java.util.ArrayList; @@ -41,6 +42,7 @@ public abstract class AbstractLexer { protected List leadingTriviaList; private Collection diagnostics; protected CharReader reader; + @Nullable protected ParserMode mode; protected ArrayDeque modeStack = new ArrayDeque<>(); protected ArrayDeque keywordModes = new ArrayDeque<>(); @@ -135,7 +137,7 @@ private Collection getDiagnostics() { return diagnostics; } - protected STToken cloneWithDiagnostics(STToken toClone) { + protected STToken cloneWithDiagnostics(@Nullable STToken toClone) { if (noDiagnostics()) { return toClone; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParser.java index 09846f00d827..4696a862b05c 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParser.java @@ -26,6 +26,7 @@ import io.ballerina.compiler.internal.syntax.NodeListUtils; import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.tools.diagnostics.DiagnosticCode; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; import java.util.Deque; @@ -39,6 +40,7 @@ public abstract class AbstractParser { protected final AbstractParserErrorHandler errorHandler; protected final AbstractTokenReader tokenReader; private final Deque invalidNodeInfoStack = new ArrayDeque<>(5); + @Nullable protected STToken insertedToken = null; public AbstractParser(AbstractTokenReader tokenReader, AbstractParserErrorHandler errorHandler) { @@ -202,7 +204,7 @@ protected STNode cloneWithDiagnosticIfListEmpty(STNode nodeList, STNode target, */ protected void updateLastNodeInListWithInvalidNode(List nodeList, STNode invalidParam, - DiagnosticCode diagnosticCode, + @Nullable DiagnosticCode diagnosticCode, Object... args) { int lastIndex = nodeList.size() - 1; STNode prevNode = nodeList.remove(lastIndex); @@ -289,7 +291,8 @@ protected STNode addInvalidNodeStackToTrailingMinutiae(STNode node) { * @param diagnosticCode the {@code DiagnosticCode} to be added * @param args additional arguments required to format the diagnostic message */ - protected void addInvalidNodeToNextToken(STNode invalidNode, DiagnosticCode diagnosticCode, Object... args) { + protected void addInvalidNodeToNextToken(STNode invalidNode, @Nullable DiagnosticCode diagnosticCode, + Object... args) { invalidNodeInfoStack.push(new InvalidNodeInfo(invalidNode, diagnosticCode, args)); } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParserErrorHandler.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParserErrorHandler.java index e2c5c5569acc..2d85c3bca683 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParserErrorHandler.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParserErrorHandler.java @@ -20,6 +20,7 @@ import io.ballerina.compiler.internal.parser.tree.STNode; import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; import java.util.ArrayList; @@ -117,6 +118,7 @@ public Solution recover(ParserRuleContext currentCtx, STToken nextToken, boolean return getFailSafeSolution(currentCtx, nextToken); } + @Nullable private Solution getResolution(ParserRuleContext currentCtx, STToken nextToken) { Result bestMatch = seekMatch(currentCtx); validateSolution(bestMatch, currentCtx, nextToken); @@ -312,6 +314,7 @@ public void switchContext(ParserRuleContext context) { * * @return head of the stack */ + @Nullable protected ParserRuleContext getParentContext() { return this.ctxStack.peek(); } @@ -321,6 +324,7 @@ protected ParserRuleContext getParentContext() { * * @return second element of the stack */ + @Nullable protected ParserRuleContext getGrandParentContext() { ParserRuleContext parent = this.ctxStack.pop(); ParserRuleContext grandParent = this.ctxStack.peek(); diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java index 9b6c6d6cf7e5..e1df73158faf 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java @@ -72,6 +72,7 @@ import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.tools.diagnostics.DiagnosticCode; import io.ballerina.tools.text.CharReader; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; import java.util.ArrayList; @@ -474,6 +475,7 @@ private STNode parseCompUnit() { * * @return Parsed node */ + @Nullable protected STNode parseTopLevelNode() { STToken nextToken = peek(); STNode metadata; @@ -542,7 +544,8 @@ protected STNode parseTopLevelNode() { * @param metadata Metadata that precedes the top level node * @return Parsed node */ - private STNode parseTopLevelNode(STNode metadata) { + @Nullable + private STNode parseTopLevelNode(@Nullable STNode metadata) { STToken nextToken = peek(); STNode publicQualifier = null; switch (nextToken.kind) { @@ -827,6 +830,7 @@ private STNode parseModuleName(STNode moduleNameStart) { return STNodeFactory.createNodeList(moduleNameParts); } + @Nullable private STNode parseModuleNameRhs() { return switch (peek().kind) { case DOT_TOKEN -> consume(); @@ -879,6 +883,7 @@ private STNode parseDecimalIntLiteral(ParserRuleContext context) { * * @return Parsed node */ + @Nullable private STNode parseImportPrefixDecl() { STToken nextToken = peek(); switch (nextToken.kind) { @@ -949,7 +954,7 @@ private STNode parseImportPrefix() { * @param publicQualifier Public qualifier that precedes the top level node * @return Parsed node */ - private STNode parseTopLevelNode(STNode metadata, STNode publicQualifier) { + private STNode parseTopLevelNode(STNode metadata, @Nullable STNode publicQualifier) { List topLevelQualifiers = new ArrayList<>(); return parseTopLevelNode(metadata, publicQualifier, topLevelQualifiers); } @@ -1022,7 +1027,7 @@ private STNode parseTopLevelNode(STNode metadata, STNode publicQualifier, List emptyList = new ArrayList<>(); STNode publicQualifier = STNodeFactory.createEmptyNode(); return parseVariableDecl(metadata, publicQualifier, emptyList, emptyList, true); @@ -1817,7 +1822,7 @@ private List extractVarDeclOrObjectFieldQualifiers(List qualifie } private STNode createFunctionTypeDescriptor(List qualifierList, STNode functionKeyword, - STNode funcSignature, boolean hasFuncSignature) { + @Nullable STNode funcSignature, boolean hasFuncSignature) { // Validate function type qualifiers STNode[] nodes = createFuncTypeQualNodeList(qualifierList, functionKeyword, hasFuncSignature); STNode qualifierNodeList = nodes[0]; @@ -1827,8 +1832,9 @@ private STNode createFunctionTypeDescriptor(List qualifierList, STNode f } private STNode parseVarDeclWithFunctionType(STNode metadata, STNode visibilityQualifier, List qualifierList, - STNode functionKeyword, STNode funcSignature, boolean isObjectMember, - boolean isObjectTypeDesc, boolean hasFuncSignature) { + STNode functionKeyword, @Nullable STNode funcSignature, + boolean isObjectMember, boolean isObjectTypeDesc, + boolean hasFuncSignature) { switchContext(ParserRuleContext.VAR_DECL_STMT); List extractQualifiersList = extractVarDeclOrObjectFieldQualifiers(qualifierList, isObjectMember, isObjectTypeDesc); @@ -2141,6 +2147,7 @@ private STNode parseParamList(boolean isParamNameOptional) { * @param param the new parameter * @param prevParamKind the SyntaxKind of the previously added parameter */ + @Nullable private DiagnosticCode validateParamOrder(STNode param, SyntaxKind prevParamKind) { if (prevParamKind == SyntaxKind.REST_PARAM) { return DiagnosticErrorCode.ERROR_PARAMETER_AFTER_THE_REST_PARAMETER; @@ -2174,10 +2181,12 @@ private boolean isPossibleServiceDecl(List nodeList) { }; } + @Nullable private STNode parseParameterRhs() { return parseParameterRhs(peek().kind); } + @Nullable private STNode parseParameterRhs(SyntaxKind tokenKind) { return switch (tokenKind) { case COMMA_TOKEN -> consume(); @@ -2271,8 +2280,8 @@ private STNode parseParameter(SyntaxKind prevParamKind, boolean isParamNameOptio return parseParameter(annots, prevParamKind, isParamNameOptional); } - private STNode parseAfterParamType(SyntaxKind prevParamKind, STNode annots, STNode inclusionSymbol, STNode type, - boolean isParamNameOptional) { + private STNode parseAfterParamType(SyntaxKind prevParamKind, STNode annots, + @Nullable STNode inclusionSymbol, STNode type, boolean isParamNameOptional) { STNode paramName; STToken token = peek(); switch (token.kind) { @@ -2340,7 +2349,7 @@ private STNode parseEllipsis() { * @return Parsed parameter node */ private STNode parseParameterRhs(SyntaxKind prevParamKind, STNode annots, STNode inclusionSymbol, STNode type, - STNode paramName) { + @Nullable STNode paramName) { STToken nextToken = peek(); // Required parameters if (isEndOfParameter(nextToken.kind)) { @@ -2393,6 +2402,7 @@ private STNode parseComma() { * @param isFuncTypeDesc Whether function type desc. paramNameOptional means its function type desc or ambiguous * @return Parsed node */ + @Nullable private STNode parseFuncReturnTypeDescriptor(boolean isFuncTypeDesc) { STToken nextToken = peek(); switch (nextToken.kind) { @@ -3243,6 +3253,7 @@ private STNode parseSemicolon() { * * @return Parsed node */ + @Nullable private STNode parseOptionalSemicolon() { STToken token = peek(); if (token.kind == SyntaxKind.SEMICOLON_TOKEN) { @@ -3847,7 +3858,7 @@ private STNode parseRecordKeyword() { * * @return Parsed node */ - + @Nullable private STNode parseFieldOrRestDescriptor() { STToken nextToken = peek(); switch (nextToken.kind) { @@ -3936,7 +3947,7 @@ private STNode parseRecordField(STToken nextToken, STNode metadata) { return parseIndividualRecordField(metadata, readOnlyQualifier, type); } - private STNode parseIndividualRecordField(STNode metadata, STNode readOnlyQualifier, STNode type) { + private STNode parseIndividualRecordField(STNode metadata, @Nullable STNode readOnlyQualifier, STNode type) { STNode fieldName = parseVariableName(); return parseFieldDescriptorRhs(metadata, readOnlyQualifier, type, fieldName); } @@ -4112,7 +4123,8 @@ private STNode parseFieldOrRestDescriptorRhs(STNode metadata, STNode type) { * @param fieldName Field name * @return Parsed node */ - private STNode parseFieldDescriptorRhs(STNode metadata, STNode readonlyQualifier, STNode type, STNode fieldName) { + private STNode parseFieldDescriptorRhs( + STNode metadata, @Nullable STNode readonlyQualifier, STNode type, STNode fieldName) { STToken nextToken = peek(); switch (nextToken.kind) { case SEMICOLON_TOKEN: @@ -4193,6 +4205,7 @@ private STNode parseStatements(ArrayList stmts) { * * @return Parsed node */ + @Nullable protected STNode parseStatement() { STToken nextToken = peek(); STNode annots = STNodeFactory.createEmptyNodeList(); @@ -4245,7 +4258,7 @@ boolean validateStatement(STNode statement) { }; } - private STNode getAnnotations(STNode nullbaleAnnot) { + private STNode getAnnotations(@Nullable STNode nullbaleAnnot) { if (nullbaleAnnot != null) { return nullbaleAnnot; } @@ -4442,7 +4455,7 @@ private STNode parseStatement(STNode annots, List qualifiers) { * @param finalKeyword Preceding final qualifier * @return Parsed node */ - private STNode parseVariableDecl(STNode annots, STNode finalKeyword) { + private STNode parseVariableDecl(STNode annots, @Nullable STNode finalKeyword) { List typeDescQualifiers = new ArrayList<>(); List varDecQualifiers = new ArrayList<>(); if (finalKeyword != null) { @@ -4452,7 +4465,7 @@ private STNode parseVariableDecl(STNode annots, STNode finalKeyword) { return parseVariableDecl(annots, publicQualifier, varDecQualifiers, typeDescQualifiers, false); } - private STNode parseVariableDecl(STNode annots, STNode publicQualifier, List varDeclQuals, + private STNode parseVariableDecl(STNode annots, @Nullable STNode publicQualifier, List varDeclQuals, List typeDescQualifiers, boolean isModuleVar) { startContext(ParserRuleContext.VAR_DECL_STMT); STNode typeBindingPattern = parseTypedBindingPattern(typeDescQualifiers, @@ -4467,7 +4480,8 @@ private STNode parseVarDeclTypeDescRhs(STNode typeDesc, STNode metadata, List qualifiers, + private STNode parseVarDeclTypeDescRhs(STNode typeDesc, STNode metadata, @Nullable STNode publicQual, + List qualifiers, boolean isTypedBindingPattern, boolean isModuleVar) { startContext(ParserRuleContext.VAR_DECL_STMT); // Check for complex type desc @@ -4498,7 +4512,7 @@ private STNode parseVarDeclRhs(STNode metadata, List varDeclQuals, return parseVarDeclRhs(metadata, publicQualifier, varDeclQuals, typedBindingPattern, isModuleVar); } - private STNode parseVarDeclRhs(STNode metadata, STNode publicQualifier, List varDeclQuals, + private STNode parseVarDeclRhs(STNode metadata, @Nullable STNode publicQualifier, List varDeclQuals, STNode typedBindingPattern, boolean isModuleVar) { STNode assign; STNode expr; @@ -4582,9 +4596,10 @@ private STNode parseConfigurableVarDeclRhs() { return expr; } - private STNode createModuleVarDeclaration(STNode metadata, STNode publicQualifier, List varDeclQuals, - STNode typedBindingPattern, STNode assign, STNode expr, STNode semicolon, - boolean isConfigurable, boolean hasVarInit) { + private STNode createModuleVarDeclaration( + STNode metadata, STNode publicQualifier, List varDeclQuals, STNode typedBindingPattern, + @Nullable STNode assign, @Nullable STNode expr, STNode semicolon, boolean isConfigurable, + boolean hasVarInit) { if (hasVarInit || varDeclQuals.isEmpty()) { return createModuleVarDeclaration(metadata, publicQualifier, varDeclQuals, typedBindingPattern, assign, expr, semicolon); @@ -4656,13 +4671,13 @@ private STNode createMissingSimpleVarDecl(boolean isModuleVar) { return createMissingSimpleVarDecl(metadata, isModuleVar); } - private STNode createMissingSimpleVarDecl(STNode metadata, boolean isModuleVar) { + private STNode createMissingSimpleVarDecl(@Nullable STNode metadata, boolean isModuleVar) { STNode publicQualifier = STNodeFactory.createEmptyNode(); return createMissingSimpleVarDecl(metadata, publicQualifier, new ArrayList<>(), isModuleVar); } - private STNode createMissingSimpleVarDecl(STNode metadata, STNode publicQualifier, List qualifiers, - boolean isModuleVar) { + private STNode createMissingSimpleVarDecl( + STNode metadata, @Nullable STNode publicQualifier, List qualifiers, boolean isModuleVar) { STNode emptyNode = STNodeFactory.createEmptyNode(); STNode simpleTypeDescIdentifier = SyntaxErrors.createMissingTokenWithDiagnostics(SyntaxKind.IDENTIFIER_TOKEN, DiagnosticErrorCode.ERROR_MISSING_TYPE_DESC); @@ -4704,7 +4719,8 @@ private STNode createMissingWhereClause() { return STNodeFactory.createWhereClauseNode(whereKeyword, missingExpr); } - private STNode createMissingSimpleObjectField(STNode metadata, List qualifiers, boolean isObjectTypeDesc) { + private STNode createMissingSimpleObjectField(@Nullable STNode metadata, List qualifiers, + boolean isObjectTypeDesc) { STNode emptyNode = STNodeFactory.createEmptyNode(); STNode simpleTypeDescIdentifier = SyntaxErrors.createMissingTokenWithDiagnostics(SyntaxKind.IDENTIFIER_TOKEN, DiagnosticErrorCode.ERROR_MISSING_TYPE_DESC); @@ -5334,7 +5350,7 @@ private STNode parseImplicitNewExpr(STNode newKeyword) { return createImplicitNewExpr(newKeyword, parenthesizedArgList); } - private STNode createImplicitNewExpr(STNode newKeyword, STNode parenthesizedArgList) { + private STNode createImplicitNewExpr(STNode newKeyword, @Nullable STNode parenthesizedArgList) { return STNodeFactory.createImplicitNewExpressionNode(newKeyword, parenthesizedArgList); } @@ -5729,6 +5745,7 @@ private STNode parseKeyExpr(boolean isRhsExpr) { return parseExpression(isRhsExpr); } + @Nullable private STNode parseMemberAccessKeyExprEnd() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -6030,6 +6047,7 @@ private STNode parseErrorConstructorExpr(STNode errorKeyword, boolean isAmbiguou closeParen); } + @Nullable private STNode parseErrorTypeReference() { STToken nextToken = peek(); switch (nextToken.kind) { @@ -6180,6 +6198,7 @@ private STNode parseArgList(STNode firstArg) { return STNodeFactory.createNodeList(argsList); } + @Nullable private DiagnosticErrorCode validateArgumentOrder(SyntaxKind prevArgKind, SyntaxKind curArgKind) { DiagnosticErrorCode errorCode = null; switch (prevArgKind) { @@ -6201,6 +6220,7 @@ private DiagnosticErrorCode validateArgumentOrder(SyntaxKind prevArgKind, Syntax return errorCode; } + @Nullable private STNode parseArgEnd() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -6323,6 +6343,7 @@ private STNode parseObjectConstructorExpression(STNode annots, List qual * * @return Parsed type reference or empty node */ + @Nullable private STNode parseObjectConstructorTypeReference() { STToken nextToken = peek(); switch (nextToken.kind) { @@ -6407,6 +6428,7 @@ private STNode parseObjectMembers(ParserRuleContext context) { * @param context Parsing context of the object member * @return Parsed node */ + @Nullable private STNode parseObjectMember(ParserRuleContext context) { STNode metadata; STToken nextToken = peek(); @@ -6456,7 +6478,8 @@ private STNode parseObjectMember(ParserRuleContext context) { return parseObjectMemberWithoutMeta(metadata, context); } - private STNode parseObjectMemberWithoutMeta(STNode metadata, ParserRuleContext context) { + @Nullable + private STNode parseObjectMemberWithoutMeta(@Nullable STNode metadata, ParserRuleContext context) { boolean isObjectTypeDesc = context == ParserRuleContext.OBJECT_TYPE_MEMBER; ParserRuleContext recoveryCtx; @@ -6470,6 +6493,7 @@ private STNode parseObjectMemberWithoutMeta(STNode metadata, ParserRuleContext c return parseObjectMemberWithoutMeta(metadata, typeDescQualifiers, recoveryCtx, isObjectTypeDesc); } + @Nullable private STNode parseObjectMemberWithoutMeta(STNode metadata, List qualifiers, ParserRuleContext recoveryCtx, boolean isObjectTypeDesc) { parseObjectMemberQualifiers(qualifiers); @@ -6567,7 +6591,8 @@ private boolean isObjectMethodStart(STToken token) { * @param isObjectTypeDesc Whether object type or not * @return Parse object member node */ - private STNode parseObjectMethodOrField(STNode metadata, STNode visibilityQualifier, boolean isObjectTypeDesc) { + private STNode parseObjectMethodOrField(STNode metadata, @Nullable STNode visibilityQualifier, + boolean isObjectTypeDesc) { List objectMemberQualifiers = new ArrayList<>(); return parseObjectMethodOrField(metadata, visibilityQualifier, objectMemberQualifiers, isObjectTypeDesc); } @@ -6621,7 +6646,7 @@ private STNode parseObjectMethodOrField(STNode metadata, STNode visibilityQualif * @param isObjectTypeDesc Whether object type or not * @return Parsed node */ - private STNode parseObjectField(STNode metadata, STNode visibilityQualifier, List qualifiers, + private STNode parseObjectField(STNode metadata, @Nullable STNode visibilityQualifier, List qualifiers, boolean isObjectTypeDesc) { List objectFieldQualifiers = extractObjectFieldQualifiers(qualifiers, isObjectTypeDesc); STNode objectFieldQualNodeList = STNodeFactory.createNodeList(objectFieldQualifiers); @@ -6698,8 +6723,8 @@ private STNode parseObjectFieldRhs(STNode metadata, STNode visibilityQualifier, * @param isObjectTypeDesc Whether object type or not * @return Parsed node */ - private STNode parseObjectMethodOrFuncTypeDesc(STNode metadata, STNode visibilityQualifier, List qualifiers, - boolean isObjectTypeDesc) { + private STNode parseObjectMethodOrFuncTypeDesc(STNode metadata, @Nullable STNode visibilityQualifier, + List qualifiers, boolean isObjectTypeDesc) { return parseFuncDefOrFuncTypeDesc(metadata, visibilityQualifier, qualifiers, true, isObjectTypeDesc); } @@ -6831,6 +6856,7 @@ private STNode parseResourcePathParameter() { paramName, closeBracket); } + @Nullable private STNode parseOptionalPathParamName() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -6843,6 +6869,7 @@ private STNode parseOptionalPathParamName() { }; } + @Nullable private STNode parseOptionalEllipsis() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -6860,6 +6887,7 @@ private STNode parseOptionalEllipsis() { * * @return Parsed node */ + @Nullable private STNode parseRelativeResourcePathEnd() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -6946,6 +6974,7 @@ private STNode parseBlockNode() { * * @return Else block */ + @Nullable private STNode parseElseBlock() { STToken nextToken = peek(); if (nextToken.kind != SyntaxKind.ELSE_KEYWORD) { @@ -7296,6 +7325,7 @@ private STNode parseMappingConstructorFields(List fields) { return STNodeFactory.createNodeList(fields); } + @Nullable private STNode parseMappingFieldEnd() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -7338,6 +7368,7 @@ private boolean isEndOfMappingConstructor(SyntaxKind tokenKind) { * @param fieldContext Context of the mapping field * @return Parsed node */ + @Nullable private STNode parseMappingField(ParserRuleContext fieldContext) { STToken nextToken = peek(); switch (nextToken.kind) { @@ -7379,7 +7410,7 @@ private STNode parseSpecificField(STNode readonlyKeyword) { }; } - private STNode parseQualifiedSpecificField(STNode readonlyKeyword) { + private STNode parseQualifiedSpecificField(@Nullable STNode readonlyKeyword) { STNode key = parseStringLiteral(); STNode colon = parseColon(); STNode valueExpr = parseExpression(); @@ -7391,12 +7422,12 @@ private STNode parseQualifiedSpecificField(STNode readonlyKeyword) { * * @return Parsed node */ - private STNode parseSpecificFieldWithOptionalValue(STNode readonlyKeyword) { + private STNode parseSpecificFieldWithOptionalValue(@Nullable STNode readonlyKeyword) { STNode key = parseIdentifier(ParserRuleContext.MAPPING_FIELD_NAME); return parseSpecificFieldRhs(readonlyKeyword, key); } - private STNode parseSpecificFieldRhs(STNode readonlyKeyword, STNode key) { + private STNode parseSpecificFieldRhs(@Nullable STNode readonlyKeyword, STNode key) { STNode colon; STNode valueExpr; STToken nextToken = peek(); @@ -7668,7 +7699,7 @@ private STNode extractServiceKeyword(List qualifierList) { * @return Parsed node */ private STNode parseServiceDecl(STNode metadata, STNode publicQualifier, List qualList, - STNode serviceKeyword, STNode serviceType) { + STNode serviceKeyword, @Nullable STNode serviceType) { // Invalidate public qualifier if present if (publicQualifier != null) { if (!qualList.isEmpty()) { @@ -7705,6 +7736,7 @@ private STNode parseServiceDecl(STNode metadata, STNode publicQualifier, List qualifiers) { STToken nextToken = peek(); switch (nextToken.kind) { @@ -7797,6 +7829,7 @@ private boolean isEndAbsoluteResourcePath(SyntaxKind tokenKind) { * @param isInitialSlash Whether this is the initial slash * @return Parsed node */ + @Nullable private STNode parseAbsoluteResourcePathEnd(boolean isInitialSlash) { STToken nextToken = peek(); switch (nextToken.kind) { @@ -7921,6 +7954,7 @@ private boolean isEndOfListeners(SyntaxKind tokenKind) { }; } + @Nullable private STNode parseListenersMemberEnd() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -8026,7 +8060,7 @@ private STNode parseListenerKeyword() { * @param qualifier Qualifier that precedes the listener declaration * @return Parsed node */ - private STNode parseConstantDeclaration(STNode metadata, STNode qualifier) { + private STNode parseConstantDeclaration(STNode metadata, @Nullable STNode qualifier) { startContext(ParserRuleContext.CONSTANT_DECL); STNode constKeyword = parseConstantKeyword(); // context ends inside the method @@ -8115,7 +8149,7 @@ private STNode parseConstantOrListenerDeclRhs(STNode metadata, STNode qualifier, } private STNode parseListenerOrConstRhs(STNode metadata, STNode qualifier, STNode keyword, boolean isListener, - STNode type, STNode variableName) { + @Nullable STNode type, STNode variableName) { STNode equalsToken = parseAssignOp(); STNode initializer = parseExpression(); STNode semicolonToken = parseSemicolon(); @@ -8286,7 +8320,7 @@ private STNode parseArrayTypeDescriptor(STNode memberTypeDesc) { return createArrayTypeDesc(memberTypeDesc, openBracketToken, arrayLengthNode, closeBracketToken); } - private STNode createArrayTypeDesc(STNode memberTypeDesc, STNode openBracketToken, STNode arrayLengthNode, + private STNode createArrayTypeDesc(STNode memberTypeDesc, STNode openBracketToken, @Nullable STNode arrayLengthNode, STNode closeBracketToken) { memberTypeDesc = validateForUsageOfVar(memberTypeDesc); if (arrayLengthNode != null) { @@ -8344,6 +8378,7 @@ private STNode createArrayTypeDesc(STNode memberTypeDesc, STNode openBracketToke * * @return Parsed array length */ + @Nullable private STNode parseArrayLength() { STToken token = peek(); return switch (token.kind) { @@ -8451,6 +8486,7 @@ private STNode parseAtToken() { * * @return Parse node */ + @Nullable private STNode parseMetaData() { STNode docString; STNode annotations; @@ -8475,7 +8511,8 @@ private STNode parseMetaData() { * * @return A metadata node */ - private STNode createMetadata(STNode docString, STNode annotations) { + @Nullable + private STNode createMetadata(@Nullable STNode docString, STNode annotations) { if (annotations == null && docString == null) { return STNodeFactory.createEmptyNode(); } else { @@ -8779,6 +8816,7 @@ private STNode parseOptionalResourceAccessPath(boolean isRhsExpr, boolean isInMa return resourceAccessPath; } + @Nullable private STNode parseOptionalResourceAccessMethodDot(boolean isRhsExpr, boolean isInMatchGuard) { STNode dotToken = STNodeFactory.createEmptyNode(); STToken nextToken = peek(); @@ -8800,6 +8838,7 @@ private STNode parseOptionalResourceAccessMethodDot(boolean isRhsExpr, boolean i return dotToken; } + @Nullable private STNode parseOptionalResourceAccessActionArgList(boolean isRhsExpr, boolean isInMatchGuard) { STNode argList = STNodeFactory.createEmptyNode(); STToken nextToken = peek(); @@ -8915,6 +8954,7 @@ private STNode parseComputedOrResourceAccessRestSegment(STNode openBracket) { * * @return Parsed node */ + @Nullable private STNode parseResourceAccessSegmentRhs(boolean isRhsExpr, boolean isInMatchGuard) { STToken nextToken = peek(); switch (nextToken.kind) { @@ -9151,7 +9191,7 @@ private STNode parseNilLiteral() { * @param constKeyword Const keyword * @return Parsed node */ - private STNode parseAnnotationDeclaration(STNode metadata, STNode qualifier, STNode constKeyword) { + private STNode parseAnnotationDeclaration(STNode metadata, STNode qualifier, @Nullable STNode constKeyword) { startContext(ParserRuleContext.ANNOTATION_DECL); STNode annotationKeyword = parseAnnotationKeyword(); STNode annotDecl = parseAnnotationDeclFromType(metadata, qualifier, constKeyword, annotationKeyword); @@ -9283,7 +9323,8 @@ private STNode parseAnnotationDeclRhs(STNode metadata, STNode qualifier, STNode } private STNode parseAnnotationDeclAttachPoints(STNode metadata, STNode qualifier, STNode constKeyword, - STNode annotationKeyword, STNode typeDesc, STNode annotTag) { + STNode annotationKeyword, @Nullable STNode typeDesc, + STNode annotTag) { STNode onKeyword; STNode attachPoints; STToken nextToken = peek(); @@ -9399,6 +9440,7 @@ private STNode parseAnnotationAttachPoints() { * * @return Parsed node */ + @Nullable private STNode parseAttachPointEnd() { return switch (peek().kind) { // null represents the end of attach points. @@ -9423,6 +9465,7 @@ private boolean isEndAnnotAttachPointList(SyntaxKind tokenKind) { * * @return Parsed node */ + @Nullable private STNode parseAnnotationAttachPoint() { switch (peek().kind) { case EOF_TOKEN: @@ -9524,7 +9567,7 @@ private STNode parseAttachPointIdent(STNode sourceKeyword) { * @param firstIdent first part of the dual attach-point * @return Parsed node */ - private STNode parseDualAttachPointIdent(STNode sourceKeyword, STNode firstIdent) { + private STNode parseDualAttachPointIdent(@Nullable STNode sourceKeyword, STNode firstIdent) { STNode secondIdent; switch (firstIdent.kind) { case OBJECT_KEYWORD: @@ -9798,6 +9841,7 @@ private STNode parseNamedWorkerDeclaration(STNode annots, List qualifier returnTypeDesc, workerBody, onFailClause); } + @Nullable private STNode getTransactionalKeyword(List qualifierList) { // Validate qualifiers extract transactional keyword List validatedList = new ArrayList<>(); @@ -9829,6 +9873,7 @@ private STNode getTransactionalKeyword(List qualifierList) { return transactionalKeyword; } + @Nullable private STNode parseReturnTypeDescriptor() { // If the return type is not present, simply return STToken token = peek(); @@ -10275,6 +10320,7 @@ private boolean isEndOfListConstructor(SyntaxKind tokenKind) { }; } + @Nullable private STNode parseListConstructorMemberEnd() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -10401,7 +10447,7 @@ private STNode parseTypeCastParam() { * @param keySpecifier keySpecifier that precedes this rhs * @return Parsed node */ - private STNode parseTableConstructorExprRhs(STNode tableKeyword, STNode keySpecifier) { + private STNode parseTableConstructorExprRhs(STNode tableKeyword, @Nullable STNode keySpecifier) { switchContext(ParserRuleContext.TABLE_CONSTRUCTOR); STNode openBracket = parseOpenBracket(); STNode rowList = parseRowList(); @@ -10470,6 +10516,7 @@ private boolean isEndOfTableRowList(SyntaxKind tokenKind) { }; } + @Nullable private STNode parseTableRowEnd() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -11380,6 +11427,7 @@ private STNode parseImplicitAnonFunc(STNode openParen, STNode firstParam, boolea return parseImplicitAnonFunc(inferedParams, isRhsExpr); } + @Nullable private STNode parseImplicitAnonFuncParamEnd() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -11513,6 +11561,7 @@ private STNode invalidateTypeDescAfterRestDesc(STNode restDescriptor) { return restDescriptor; } + @Nullable private STNode parseTupleMemberRhs() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -11525,6 +11574,7 @@ private STNode parseTupleMemberRhs() { }; } + @Nullable private STNode parseTypeDescInTupleRhs() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -11638,7 +11688,7 @@ private STNode parseTableConstructorOrQueryRhs(STNode tableKeyword, STNode keySp * * @return Parsed node */ - private STNode parseQueryConstructType(STNode keyword, STNode keySpecifier) { + private STNode parseQueryConstructType(STNode keyword, @Nullable STNode keySpecifier) { return STNodeFactory.createQueryConstructTypeNode(keyword, keySpecifier); } @@ -11655,7 +11705,7 @@ private STNode parseQueryConstructType(STNode keyword, STNode keySpecifier) { * @param queryConstructType queryConstructType that precedes this rhs * @return Parsed node */ - private STNode parseQueryExprRhs(STNode queryConstructType, boolean isRhsExpr, boolean allowActions) { + private STNode parseQueryExprRhs(@Nullable STNode queryConstructType, boolean isRhsExpr, boolean allowActions) { // this.tokenReader.startKeywordMode(KeywordMode.QUERY); switchContext(ParserRuleContext.QUERY_EXPRESSION); STNode fromClause = parseFromClause(isRhsExpr, allowActions); @@ -11777,6 +11827,7 @@ static boolean isKeywordMatch(SyntaxKind syntaxKind, STToken token) { * * @return Parsed node */ + @Nullable private STNode parseIntermediateClause(boolean isRhsExpr, boolean allowActions) { STToken nextToken = peek(); switch (nextToken.kind) { @@ -12198,6 +12249,7 @@ private boolean isQueryClauseStartToken(STToken nextToken) { }; } + @Nullable private STNode parseGroupingKeyListMemberEnd() { STToken nextToken = peek(); switch (nextToken.kind) { @@ -12215,6 +12267,7 @@ private STNode parseGroupingKeyListMemberEnd() { } } + @Nullable private STNode parseOrderKeyListMemberEnd() { STToken nextToken = peek(); switch (nextToken.kind) { @@ -12329,6 +12382,7 @@ private STNode parseSelectKeyword() { * * @return On conflict clause node */ + @Nullable private STNode parseOnConflictClause(boolean isRhsExpr) { STToken nextToken = peek(); if (nextToken.kind != SyntaxKind.ON_KEYWORD && nextToken.kind != SyntaxKind.CONFLICT_KEYWORD) { @@ -12556,6 +12610,7 @@ private STNode parseFlushKeyword() { * * @return peer worker name node */ + @Nullable private STNode parseOptionalPeerWorkerName() { STToken token = peek(); return switch (token.kind) { @@ -12903,6 +12958,7 @@ private boolean isEndOfReceiveFields(SyntaxKind nextTokenKind) { }; } + @Nullable private STNode parseReceiveFieldEnd() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -13119,6 +13175,7 @@ private STNode parseWaitFutureExpr() { return waitFutureExpr; } + @Nullable private STNode parseWaitFutureExprEnd() { STToken nextToken = peek(); switch (nextToken.kind) { @@ -13193,6 +13250,7 @@ private boolean isEndOfWaitFields(SyntaxKind nextTokenKind) { }; } + @Nullable private STNode parseWaitFieldEnd() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -13298,8 +13356,8 @@ private STNode parseFieldAccessIdentifier(boolean isInConditionalExpr) { * @param selectClause Select clause if any This is only for validation. * @return Query action node */ - private STNode parseQueryAction(STNode queryConstructType, STNode queryPipeline, STNode selectClause, - STNode collectClause) { + private STNode parseQueryAction(STNode queryConstructType, STNode queryPipeline, @Nullable STNode selectClause, + @Nullable STNode collectClause) { if (queryConstructType != null) { queryPipeline = SyntaxErrors.cloneWithLeadingInvalidNodeMinutiae(queryPipeline, queryConstructType, DiagnosticErrorCode.ERROR_QUERY_CONSTRUCT_TYPE_IN_QUERY_ACTION); @@ -13573,7 +13631,7 @@ private STNode parseEnumMember() { return parseEnumMemberRhs(metadata, identifierNode); } - private STNode parseEnumMemberRhs(STNode metadata, STNode identifierNode) { + private STNode parseEnumMemberRhs(@Nullable STNode metadata, STNode identifierNode) { STNode equalToken, constExprNode; switch (peek().kind) { case EQUAL_TOKEN: @@ -13593,6 +13651,7 @@ private STNode parseEnumMemberRhs(STNode metadata, STNode identifierNode) { return STNodeFactory.createEnumMemberNode(metadata, identifierNode, equalToken, constExprNode); } + @Nullable private STNode parseEnumMemberEnd() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -13705,7 +13764,7 @@ private STNode parseRetryKeywordRhs(STNode retryKeyword) { }; } - private STNode parseRetryTypeParamRhs(STNode retryKeyword, STNode typeParam) { + private STNode parseRetryTypeParamRhs(STNode retryKeyword, @Nullable STNode typeParam) { STNode args; switch (peek().kind) { case OPEN_PAREN_TOKEN: @@ -13742,6 +13801,7 @@ private STNode parseRetryBody() { * * @return Parsed node */ + @Nullable private STNode parseOptionalOnFailClause() { STToken nextToken = peek(); if (nextToken.kind == SyntaxKind.ON_KEYWORD) { @@ -13838,6 +13898,7 @@ private STNode parseOnFailClause() { blockStatement); } + @Nullable private STNode parseOnfailOptionalBP() { STToken nextToken = peek(); if (nextToken.kind == SyntaxKind.OPEN_BRACE_TOKEN) { @@ -14410,6 +14471,7 @@ private boolean isEndOfXMLStepExtend(SyntaxKind tokenKind) { }; } + @Nullable private STNode parseXMLNamePatternSeparator() { STToken token = peek(); return switch (token.kind) { @@ -14644,6 +14706,7 @@ private STNode parseMatchClause() { * * @return Match guard */ + @Nullable private STNode parseMatchGuard() { STToken nextToken = peek(); switch (nextToken.kind) { @@ -14739,6 +14802,7 @@ private STNode parseMatchPattern() { }; } + @Nullable private STNode parseMatchPatternListMemberRhs() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -14880,6 +14944,7 @@ private STNode parseRestMatchPattern() { return STNodeFactory.createRestMatchPatternNode(ellipsisToken, varKeywordToken, simpleNameReferenceNode); } + @Nullable private STNode parseListMatchPatternMemberRhs() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -14990,6 +15055,7 @@ private void invalidateExtraFieldMatchPatterns(List fieldMatchPatterns) } } + @Nullable private STNode parseFieldMatchPatternMember() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -15026,6 +15092,7 @@ public boolean isEndOfMappingMatchPattern() { }; } + @Nullable private STNode parseFieldMatchPatternRhs() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -15113,7 +15180,7 @@ private STNode parseErrorMatchPattern(STNode errorKeyword) { return parseErrorMatchPattern(errorKeyword, typeRef); } - private STNode parseErrorMatchPattern(STNode errorKeyword, STNode typeRef) { + private STNode parseErrorMatchPattern(STNode errorKeyword, @Nullable STNode typeRef) { STNode openParenthesisToken = parseOpenParenthesis(); STNode argListMatchPatternNode = parseErrorArgListMatchPatterns(); STNode closeParenthesisToken = parseCloseParenthesis(); @@ -15223,6 +15290,7 @@ private boolean isEndOfErrorFieldMatchPatterns() { return isEndOfErrorFieldBindingPatterns(); } + @Nullable private STNode parseErrorArgListMatchPatternEnd(ParserRuleContext currentCtx) { return switch (peek().kind) { case COMMA_TOKEN -> consume(); @@ -15298,6 +15366,7 @@ private STNode parseNamedArgMatchPattern(STNode identifier) { return STNodeFactory.createNamedArgMatchPatternNode(identifier, equalToken, matchPattern); } + @Nullable private DiagnosticErrorCode validateErrorFieldMatchPatternOrder(SyntaxKind prevArgKind, SyntaxKind currentArgKind) { return switch (currentArgKind) { case NAMED_ARG_MATCH_PATTERN, @@ -16099,6 +16168,7 @@ private STNode parseListBindingPattern(STNode openBracket, STNode firstMember, L return STNodeFactory.createListBindingPatternNode(openBracket, bindingPatternsNode, closeBracket); } + @Nullable private STNode parseListBindingPatternMemberRhs() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -16271,6 +16341,7 @@ private STNode parseMappingBindingPatternMember() { }; } + @Nullable private STNode parseMappingBindingPatternEnd() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -16399,7 +16470,7 @@ private STNode parseErrorBindingPattern(STNode errorKeyword) { return parseErrorBindingPattern(errorKeyword, typeRef); } - private STNode parseErrorBindingPattern(STNode errorKeyword, STNode typeRef) { + private STNode parseErrorBindingPattern(STNode errorKeyword, @Nullable STNode typeRef) { STNode openParenthesis = parseOpenParenthesis(); STNode argListBindingPatterns = parseErrorArgListBindingPatterns(); STNode closeParenthesis = parseCloseParenthesis(); @@ -16543,6 +16614,7 @@ private boolean isEndOfErrorFieldBindingPatterns() { }; } + @Nullable private STNode parseErrorArgsBindingPatternEnd(ParserRuleContext currentCtx) { return switch (peek().kind) { case COMMA_TOKEN -> consume(); @@ -16554,6 +16626,7 @@ private STNode parseErrorArgsBindingPatternEnd(ParserRuleContext currentCtx) { }; } + @Nullable private STNode parseErrorArgListBindingPattern(ParserRuleContext context, boolean isFirstArg) { switch (peek().kind) { case ELLIPSIS_TOKEN: @@ -16593,6 +16666,7 @@ private STNode parseNamedOrSimpleArgBindingPattern(STNode argNameOrSimpleBinding } } + @Nullable private DiagnosticErrorCode validateErrorFieldBindingPatternOrder(SyntaxKind prevArgKind, SyntaxKind currentArgKind) { return switch (currentArgKind) { @@ -16745,6 +16819,7 @@ private boolean isBracketedListEnd(SyntaxKind nextTokenKind) { * @param isTypedBindingPattern Is this in a definite typed-binding pattern * @return Parsed member node */ + @Nullable private STNode parseBracketedListMember(boolean isTypedBindingPattern) { STToken nextToken = peek(); switch (nextToken.kind) { @@ -16795,7 +16870,8 @@ private STNode parseBracketedListMember(boolean isTypedBindingPattern) { * @param member Member * @return Parsed node */ - private STNode parseAsArrayTypeDesc(STNode typeDesc, STNode openBracket, STNode member, ParserRuleContext context) { + private STNode parseAsArrayTypeDesc(STNode typeDesc, STNode openBracket, @Nullable STNode member, + ParserRuleContext context) { // In ambiguous scenarios typDesc: T[a] may have parsed as an indexed expression. // Therefore make an array-type-desc out of it. typeDesc = getTypeDescFromExpr(typeDesc); @@ -16808,6 +16884,7 @@ private STNode parseAsArrayTypeDesc(STNode typeDesc, STNode openBracket, STNode context); } + @Nullable private STNode parseBracketedListMemberEnd() { return switch (peek().kind) { case COMMA_TOKEN -> parseComma(); @@ -18172,7 +18249,7 @@ private STNode bracedListMemberStartsWithReadonly(STNode readonlyKeyword) { * @param readonlyKeyword Readonly keyword * @return Parsed node */ - private STNode parseIdentifierRhsInStmtStartingBrace(STNode readonlyKeyword) { + private STNode parseIdentifierRhsInStmtStartingBrace(@Nullable STNode readonlyKeyword) { STNode identifier = parseIdentifier(ParserRuleContext.VARIABLE_REF); switch (peek().kind) { case COMMA_TOKEN: // { foo, @@ -18937,6 +19014,7 @@ private List getBindingPatternsList(List ambibuousList, boolean return bindingPatterns; } + @Nullable private STNode getBindingPattern(STNode ambiguousNode, boolean isListBP) { DiagnosticCode errorCode = DiagnosticErrorCode.ERROR_INVALID_BINDING_PATTERN; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParserErrorHandler.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParserErrorHandler.java index f4624e807d99..338bba8c447b 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParserErrorHandler.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParserErrorHandler.java @@ -19,6 +19,7 @@ import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; @@ -856,7 +857,7 @@ public class BallerinaParserErrorHandler extends AbstractParserErrorHandler { private static final ParserRuleContext[] TUPLE_MEMBER = { ParserRuleContext.ANNOTATIONS, ParserRuleContext.TYPE_DESC_IN_TUPLE }; - public BallerinaParserErrorHandler(AbstractTokenReader tokenReader) { + public BallerinaParserErrorHandler(@Nullable AbstractTokenReader tokenReader) { super(tokenReader); } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/DocumentationParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/DocumentationParser.java index 4be4e8881505..8339ec3ac637 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/DocumentationParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/DocumentationParser.java @@ -22,6 +22,7 @@ import io.ballerina.compiler.internal.parser.tree.STNodeFactory; import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -307,6 +308,7 @@ private STNode parseCodeBlock(STNode startLineHash , STNode startBacktick) { * * @return Parsed node */ + @Nullable private STNode parseOptionalLangAttributeToken() { STToken token = peek(); if (token.kind == SyntaxKind.CODE_CONTENT) { @@ -415,7 +417,7 @@ private boolean isEndOfCodeLines() { * @param referenceType Token that precedes the single backtick * @return Parsed node */ - private STNode parseBallerinaNameRefOrInlineCodeRef(STNode referenceType) { + private STNode parseBallerinaNameRefOrInlineCodeRef(@Nullable STNode referenceType) { STNode startBacktick = parseBacktickToken(); boolean isCodeRef = false; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/RegExpParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/RegExpParser.java index 160f8596a6d5..0e5a72ce400a 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/RegExpParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/RegExpParser.java @@ -23,6 +23,7 @@ import io.ballerina.compiler.internal.parser.tree.STNodeFactory; import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -126,6 +127,7 @@ private STNode parseReTerm() { return STNodeFactory.createReAtomQuantifierNode(reAtom, null); } + @Nullable private STNode parseOptionalQuantifier(SyntaxKind tokenKind) { return switch (tokenKind) { case PLUS_TOKEN, ASTERISK_TOKEN, QUESTION_MARK_TOKEN, OPEN_BRACE_TOKEN -> parseReQuantifier(); @@ -322,6 +324,7 @@ private STNode parseCharacterClass() { * * @return ^ token */ + @Nullable private STNode parseNegation() { STToken nextToken = peek(); if (nextToken.kind == SyntaxKind.BITWISE_XOR_TOKEN) { @@ -335,7 +338,8 @@ private STNode parseNegation() { * * @return ReCharSet node */ - private STNode parseReCharSet(STNode prevNode) { + @Nullable + private STNode parseReCharSet(@Nullable STNode prevNode) { STToken nextToken = peek(); if (isCharacterClassEnd(nextToken.kind)) { return null; @@ -546,6 +550,7 @@ private STNode parseCloseBrace() { * * @return ? token */ + @Nullable private STNode parseNonGreedyChar() { STToken nextToken = peek(); if (nextToken.kind == SyntaxKind.QUESTION_MARK_TOKEN) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/Result.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/Result.java index c58bbbfbca40..8d8c155019fd 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/Result.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/Result.java @@ -17,6 +17,8 @@ */ package io.ballerina.compiler.internal.parser; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayDeque; /** @@ -56,6 +58,7 @@ public Result(ArrayDeque fixes, int matches this.matches = matches; } + @Nullable protected AbstractParserErrorHandler.Solution peekFix() { return this.fixes.peek(); } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/SyntaxErrors.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/SyntaxErrors.java index 22d23ca87b6a..7d3fb1fbed4a 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/SyntaxErrors.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/SyntaxErrors.java @@ -28,6 +28,7 @@ import io.ballerina.compiler.internal.syntax.SyntaxUtils; import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.tools.diagnostics.DiagnosticCode; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -455,7 +456,7 @@ public static STNode cloneWithLeadingInvalidNodeMinutiae(STNode toClone, STNode */ public static STNode cloneWithLeadingInvalidNodeMinutiae(STNode toClone, STNode invalidNode, - DiagnosticCode diagnosticCode, + @Nullable DiagnosticCode diagnosticCode, Object... args) { STToken firstToken = toClone.firstToken(); STToken firstTokenWithInvalidNodeMinutiae = cloneWithLeadingInvalidNodeMinutiae(firstToken, @@ -504,7 +505,7 @@ public static STNode cloneWithTrailingInvalidNodeMinutiae(STNode toClone, STNode */ public static STNode cloneWithTrailingInvalidNodeMinutiae(STNode toClone, STNode invalidNode, - DiagnosticCode diagnosticCode, + @Nullable DiagnosticCode diagnosticCode, Object... args) { STToken lastToken = toClone.lastToken(); STToken lastTokenWithInvalidNodeMinutiae = cloneWithTrailingInvalidNodeMinutiae(lastToken, diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/TokenReader.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/TokenReader.java index 65cd9340bdf6..0360fba723f6 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/TokenReader.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/TokenReader.java @@ -21,6 +21,7 @@ import io.ballerina.compiler.internal.parser.tree.STNodeFactory; import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; /** * Reader that can read tokens from a given lexer. Supports k-lookahead @@ -166,6 +167,7 @@ public void endKeywordMode() { * * @return Current mode */ + @Nullable @Override public ParserMode getCurrentMode() { return this.lexer.modeStack.peek(); diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java index 20161bb133d3..9ec37551a818 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java @@ -23,6 +23,7 @@ import io.ballerina.compiler.internal.parser.tree.STNodeFactory; import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -101,6 +102,7 @@ private boolean isEndOfXMLContent(SyntaxKind kind, boolean isInXMLElement) { * * @return XML content item node */ + @Nullable private STNode parseXMLContentItem() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -447,6 +449,7 @@ private boolean isEndOfXMLAttributeValue(SyntaxKind nextTokenKind) { * * @return XML text node */ + @Nullable private STNode parseXMLText() { STToken nextToken = peek(); return switch (nextToken.kind) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNode.java index 5c2c6d79ff1a..8d250c7224f3 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNode.java @@ -21,6 +21,7 @@ import io.ballerina.compiler.internal.parser.tree.STNode; import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.compiler.internal.syntax.SyntaxUtils; +import org.jetbrains.annotations.Nullable; import java.util.Deque; @@ -34,7 +35,7 @@ class HybridNode { private final State state; private final STNode node; - HybridNode(STNode node, State state) { + HybridNode(@Nullable STNode node, @Nullable State state) { this.node = node; this.state = state; } @@ -48,11 +49,11 @@ State state() { * * @return {@code STToken} value if the underlying node is a token, otherwise null */ - STToken token() { + @Nullable STToken token() { return SyntaxUtils.isToken(node) ? (STToken) node : null; } - STNode subtree() { + @Nullable STNode subtree() { return SyntaxUtils.isNonTerminalNode(node) ? node : null; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNodeStorage.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNodeStorage.java index 9cedfb5d8e5d..c40b3c937f8e 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNodeStorage.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNodeStorage.java @@ -25,6 +25,7 @@ import io.ballerina.tools.text.TextDocumentChange; import io.ballerina.tools.text.TextEdit; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; import java.util.ArrayList; @@ -45,7 +46,9 @@ public class HybridNodeStorage { private int consumedNodeIndex = 0; private int peekedNodeIndex = 0; + @Nullable private HybridNode currentToken = null; + @Nullable private HybridNode currentNode = null; // TODO Explain why we are adding the initial node diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNodes.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNodes.java index 0c5d04909b55..b38cdb6d3933 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNodes.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridNodes.java @@ -22,6 +22,7 @@ import io.ballerina.compiler.syntax.tree.Node; import io.ballerina.compiler.syntax.tree.Token; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; import java.util.Deque; @@ -43,6 +44,7 @@ private HybridNodes() { * @param kind token or a subtree * @return the next available node */ + @Nullable static HybridNode nextNode(HybridNode prevNode, HybridNode.Kind kind) { HybridNode.State state = prevNode.state().cloneState(); return switch (kind) { @@ -52,6 +54,7 @@ static HybridNode nextNode(HybridNode prevNode, HybridNode.Kind kind) { }; } + @Nullable private static HybridNode nextSubtree(HybridNode.State state) { if (state.oldTreePtr.isAtEOF() || state.oldTextOffset != state.newTextOffset) { return null; @@ -105,6 +108,7 @@ private static void syncOldWithNewTextOffset(Token token, HybridNode.State state removeInvalidTextEdits(token, state); } + @Nullable private static HybridNode getReusableTokenFromOldTree(HybridNode.State state) { Token token = getTokenFromOldTree(state); if (isNodeReusable(token, state)) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridTokenReader.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridTokenReader.java index 5a05ac547cd8..5b728aaaec92 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridTokenReader.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/HybridTokenReader.java @@ -21,6 +21,7 @@ import io.ballerina.compiler.internal.parser.KeywordMode; import io.ballerina.compiler.internal.parser.ParserMode; import io.ballerina.compiler.internal.parser.tree.STToken; +import org.jetbrains.annotations.Nullable; /** * This class supplies {@code STToken}s on-demand from @@ -83,6 +84,7 @@ public void startKeywordMode(KeywordMode keywordMode) { public void endKeywordMode() { } + @Nullable @Override public ParserMode getCurrentMode() { return null; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/IncrementalParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/IncrementalParser.java index 7f698bed3229..77bbd55264e0 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/IncrementalParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/IncrementalParser.java @@ -21,6 +21,7 @@ import io.ballerina.compiler.internal.parser.BallerinaParser; import io.ballerina.compiler.internal.parser.tree.STNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.function.Predicate; @@ -57,6 +58,7 @@ protected STNode parseStatement() { return stmtNode != null ? stmtNode : super.parseStatement(); } + @Nullable private STNode getIfReusable(STNode node, Predicate predicate) { if (node != null && predicate.test(node.kind)) { this.subtreeSupplier.consume(); diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/NodePointer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/NodePointer.java index e8418722f134..4a156d919f48 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/NodePointer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/NodePointer.java @@ -24,6 +24,7 @@ import io.ballerina.compiler.syntax.tree.NonTerminalNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.compiler.syntax.tree.Token; +import org.jetbrains.annotations.Nullable; /** * Represents a pointer to a {@code Node} in the syntax tree. @@ -43,7 +44,7 @@ private NodePointer(Node node, int childBucketIndex) { this.childBucketIndex = childBucketIndex; } - NodePointer(ModulePartNode node) { + NodePointer(@Nullable ModulePartNode node) { this(node, 0); } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/UnmodifiedSubtreeSupplier.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/UnmodifiedSubtreeSupplier.java index a6cb6bedb8f8..a38ee69a96bb 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/UnmodifiedSubtreeSupplier.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/incremental/UnmodifiedSubtreeSupplier.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.internal.parser.incremental; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; /** * Supplies unmodified/reusable {@code STNode}s from the previous {@code SyntaxTree}. @@ -45,6 +46,7 @@ public STNode consume() { * * @return reusable {@code SyntaxTree} */ + @Nullable public STNode peek() { HybridNode hybridNode = this.hybridNodeStorage.peekSubtree(); return hybridNode != null ? hybridNode.subtree() : null; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STAbstractNodeFactory.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STAbstractNodeFactory.java index 1da573301931..d1a21d81c58b 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STAbstractNodeFactory.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STAbstractNodeFactory.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.internal.parser.tree; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -63,6 +64,7 @@ public static STNode createEmptyNodeList() { return EMPTY_LIST; } + @Nullable public static STNode createEmptyNode() { return null; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNode.java index f57378721a8e..0c0121d621f2 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNode.java @@ -22,6 +22,7 @@ import io.ballerina.compiler.syntax.tree.Node; import io.ballerina.compiler.syntax.tree.NonTerminalNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -132,6 +133,7 @@ public STToken firstToken() { return (STToken) firstTokenInternal(); } + @Nullable protected STNode firstTokenInternal() { for (STNode child : childBuckets) { if (SyntaxUtils.isToken(child)) { @@ -156,6 +158,7 @@ public STToken lastToken() { return (STToken) lastTokenInternal(); } + @Nullable protected STNode lastTokenInternal() { for (int bucket = childBuckets.length - 1; bucket >= 0; bucket--) { STNode child = childInBucket(bucket); @@ -198,7 +201,7 @@ public T createUnlinkedFacade() { return (T) createFacade(0, null); } - public abstract Node createFacade(int position, NonTerminalNode parent); + public abstract Node createFacade(int position, @Nullable NonTerminalNode parent); /** * Accepts an instance of the {@code STNodeVisitor}, which can be used to diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeFactory.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeFactory.java index 974a1bd89b2c..196abecaadd6 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeFactory.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeFactory.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.internal.parser.tree; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; /** * A factory that constructs internal tree nodes. @@ -70,9 +71,9 @@ public static STNode createFunctionDefinitionNode( public static STNode createImportDeclarationNode( STNode importKeyword, - STNode orgName, + @Nullable STNode orgName, STNode moduleName, - STNode prefix, + @Nullable STNode prefix, STNode semicolon) { return new STImportDeclarationNode( @@ -178,10 +179,10 @@ public static STNode createCompoundAssignmentStatementNode( public static STNode createVariableDeclarationNode( STNode annotations, - STNode finalKeyword, + @Nullable STNode finalKeyword, STNode typedBindingPattern, - STNode equalsToken, - STNode initializer, + @Nullable STNode equalsToken, + @Nullable STNode initializer, STNode semicolonToken) { return new STVariableDeclarationNode( @@ -305,7 +306,7 @@ public static STNode createPanicStatementNode( public static STNode createReturnStatementNode( STNode returnKeyword, - STNode expression, + @Nullable STNode expression, STNode semicolonToken) { return new STReturnStatementNode( @@ -569,7 +570,7 @@ public static STNode createRestParameterNode( STNode annotations, STNode typeName, STNode ellipsisToken, - STNode paramName) { + @Nullable STNode paramName) { return new STRestParameterNode( annotations, @@ -597,10 +598,10 @@ public static STNode createImportPrefixNode( } public static STNode createSpecificFieldNode( - STNode readonlyKeyword, + @Nullable STNode readonlyKeyword, STNode fieldName, - STNode colon, - STNode valueExpr) { + @Nullable STNode colon, + @Nullable STNode valueExpr) { return new STSpecificFieldNode( readonlyKeyword, @@ -673,7 +674,7 @@ public static STNode createObjectConstructorExpressionNode( STNode annotations, STNode objectTypeQualifiers, STNode objectKeyword, - STNode typeReference, + @Nullable STNode typeReference, STNode openBraceToken, STNode members, STNode closeBraceToken) { @@ -692,7 +693,7 @@ public static STNode createRecordTypeDescriptorNode( STNode recordKeyword, STNode bodyStartDelimiter, STNode fields, - STNode recordRestDescriptor, + @Nullable STNode recordRestDescriptor, STNode bodyEndDelimiter) { return new STRecordTypeDescriptorNode( @@ -733,13 +734,13 @@ public static STNode createOptionalTypeDescriptorNode( } public static STNode createObjectFieldNode( - STNode metadata, - STNode visibilityQualifier, + @Nullable STNode metadata, + @Nullable STNode visibilityQualifier, STNode qualifierList, STNode typeName, STNode fieldName, - STNode equalsToken, - STNode expression, + @Nullable STNode equalsToken, + @Nullable STNode expression, STNode semicolonToken) { return new STObjectFieldNode( @@ -758,7 +759,7 @@ public static STNode createRecordFieldNode( STNode readonlyKeyword, STNode typeName, STNode fieldName, - STNode questionMarkToken, + @Nullable STNode questionMarkToken, STNode semicolonToken) { return new STRecordFieldNode( @@ -814,7 +815,7 @@ public static STNode createTypeReferenceNode( public static STNode createAnnotationNode( STNode atToken, STNode annotReference, - STNode annotValue) { + @Nullable STNode annotValue) { return new STAnnotationNode( atToken, @@ -823,8 +824,8 @@ public static STNode createAnnotationNode( } public static STNode createMetadataNode( - STNode documentationString, - STNode annotations) { + @Nullable STNode documentationString, + @Nullable STNode annotations) { return new STMetadataNode( documentationString, @@ -833,11 +834,11 @@ public static STNode createMetadataNode( public static STNode createModuleVariableDeclarationNode( STNode metadata, - STNode visibilityQualifier, + @Nullable STNode visibilityQualifier, STNode qualifiers, STNode typedBindingPattern, - STNode equalsToken, - STNode initializer, + @Nullable STNode equalsToken, + @Nullable STNode initializer, STNode semicolonToken) { return new STModuleVariableDeclarationNode( @@ -903,7 +904,7 @@ public static STNode createAnnotationDeclarationNode( STNode annotationKeyword, STNode typeDescriptor, STNode annotationTag, - STNode onKeyword, + @Nullable STNode onKeyword, STNode attachPoints, STNode semicolonToken) { @@ -920,7 +921,7 @@ public static STNode createAnnotationDeclarationNode( } public static STNode createAnnotationAttachPointNode( - STNode sourceKeyword, + @Nullable STNode sourceKeyword, STNode identifiers) { return new STAnnotationAttachPointNode( @@ -931,8 +932,8 @@ public static STNode createAnnotationAttachPointNode( public static STNode createXMLNamespaceDeclarationNode( STNode xmlnsKeyword, STNode namespaceuri, - STNode asKeyword, - STNode namespacePrefix, + @Nullable STNode asKeyword, + @Nullable STNode namespacePrefix, STNode semicolonToken) { return new STXMLNamespaceDeclarationNode( @@ -946,8 +947,8 @@ public static STNode createXMLNamespaceDeclarationNode( public static STNode createModuleXMLNamespaceDeclarationNode( STNode xmlnsKeyword, STNode namespaceuri, - STNode asKeyword, - STNode namespacePrefix, + @Nullable STNode asKeyword, + @Nullable STNode namespacePrefix, STNode semicolonToken) { return new STModuleXMLNamespaceDeclarationNode( @@ -960,10 +961,10 @@ public static STNode createModuleXMLNamespaceDeclarationNode( public static STNode createFunctionBodyBlockNode( STNode openBraceToken, - STNode namedWorkerDeclarator, + @Nullable STNode namedWorkerDeclarator, STNode statements, STNode closeBraceToken, - STNode semicolonToken) { + @Nullable STNode semicolonToken) { return new STFunctionBodyBlockNode( openBraceToken, @@ -1074,7 +1075,7 @@ public static STNode createTypeCastExpressionNode( public static STNode createTypeCastParamNode( STNode annotations, - STNode type) { + @Nullable STNode type) { return new STTypeCastParamNode( annotations, @@ -1122,7 +1123,7 @@ public static STNode createKeySpecifierNode( public static STNode createStreamTypeDescriptorNode( STNode streamKeywordToken, - STNode streamTypeParamsNode) { + @Nullable STNode streamTypeParamsNode) { return new STStreamTypeDescriptorNode( streamKeywordToken, @@ -1132,8 +1133,8 @@ public static STNode createStreamTypeDescriptorNode( public static STNode createStreamTypeParamsNode( STNode ltToken, STNode leftTypeDescNode, - STNode commaToken, - STNode rightTypeDescNode, + @Nullable STNode commaToken, + @Nullable STNode rightTypeDescNode, STNode gtToken) { return new STStreamTypeParamsNode( @@ -1172,7 +1173,7 @@ public static STNode createLetVariableDeclarationNode( public static STNode createTemplateExpressionNode( SyntaxKind kind, - STNode type, + @Nullable STNode type, STNode startBacktick, STNode content, STNode endBacktick) { @@ -1333,7 +1334,7 @@ public static STNode createXMLProcessingInstruction( public static STNode createTableTypeDescriptorNode( STNode tableKeywordToken, STNode rowTypeParameterNode, - STNode keyConstraintNode) { + @Nullable STNode keyConstraintNode) { return new STTableTypeDescriptorNode( tableKeywordToken, @@ -1364,7 +1365,7 @@ public static STNode createKeyTypeConstraintNode( public static STNode createFunctionTypeDescriptorNode( STNode qualifierList, STNode functionKeyword, - STNode functionSignature) { + @Nullable STNode functionSignature) { return new STFunctionTypeDescriptorNode( qualifierList, @@ -1403,7 +1404,7 @@ public static STNode createExplicitAnonymousFunctionExpressionNode( public static STNode createExpressionFunctionBodyNode( STNode rightDoubleArrow, STNode expression, - STNode semicolon) { + @Nullable STNode semicolon) { return new STExpressionFunctionBodyNode( rightDoubleArrow, @@ -1505,7 +1506,7 @@ public static STNode createLetClauseNode( } public static STNode createJoinClauseNode( - STNode outerKeyword, + @Nullable STNode outerKeyword, STNode joinKeyword, STNode typedBindingPattern, STNode inKeyword, @@ -1954,8 +1955,8 @@ public static STNode createEnumDeclarationNode( public static STNode createEnumMemberNode( STNode metadata, STNode identifier, - STNode equalToken, - STNode constExprNode) { + @Nullable STNode equalToken, + @Nullable STNode constExprNode) { return new STEnumMemberNode( metadata, @@ -1975,7 +1976,7 @@ public static STNode createArrayTypeDescriptorNode( public static STNode createArrayDimensionNode( STNode openBracket, - STNode arrayLength, + @Nullable STNode arrayLength, STNode closeBracket) { return new STArrayDimensionNode( @@ -1997,7 +1998,7 @@ public static STNode createTransactionStatementNode( public static STNode createRollbackStatementNode( STNode rollbackKeyword, - STNode expression, + @Nullable STNode expression, STNode semicolon) { return new STRollbackStatementNode( @@ -2009,7 +2010,7 @@ public static STNode createRollbackStatementNode( public static STNode createRetryStatementNode( STNode retryKeyword, STNode typeParameter, - STNode arguments, + @Nullable STNode arguments, STNode retryBody, STNode onFailClause) { @@ -2038,7 +2039,7 @@ public static STNode createTransactionalExpressionNode( public static STNode createByteArrayLiteralNode( STNode type, STNode startBacktick, - STNode content, + @Nullable STNode content, STNode endBacktick) { return new STByteArrayLiteralNode( @@ -2138,7 +2139,7 @@ public static STNode createMatchStatementNode( public static STNode createMatchClauseNode( STNode matchPatterns, - STNode matchGuard, + @Nullable STNode matchGuard, STNode rightDoubleArrow, STNode blockStatement) { @@ -2335,7 +2336,7 @@ public static STNode createOrderByClauseNode( public static STNode createOrderKeyNode( STNode expression, - STNode orderDirection) { + @Nullable STNode orderDirection) { return new STOrderKeyNode( expression, @@ -2418,7 +2419,7 @@ public static STNode createResourcePathParameterNode( STNode openBracketToken, STNode annotations, STNode typeDescriptor, - STNode ellipsisToken, + @Nullable STNode ellipsisToken, STNode paramName, STNode closeBracketToken) { @@ -2457,7 +2458,7 @@ public static STNode createErrorConstructorExpressionNode( public static STNode createParameterizedTypeDescriptorNode( SyntaxKind kind, STNode keywordToken, - STNode typeParamNode) { + @Nullable STNode typeParamNode) { return new STParameterizedTypeDescriptorNode( kind, @@ -2479,8 +2480,8 @@ public static STNode createClientResourceAccessActionNode( STNode rightArrowToken, STNode slashToken, STNode resourceAccessPath, - STNode dotToken, - STNode methodName, + @Nullable STNode dotToken, + @Nullable STNode methodName, STNode arguments) { return new STClientResourceAccessActionNode( @@ -2526,7 +2527,7 @@ public static STNode createReSequenceNode( public static STNode createReAtomQuantifierNode( STNode reAtom, - STNode reQuantifier) { + @Nullable STNode reQuantifier) { return new STReAtomQuantifierNode( reAtom, @@ -2583,7 +2584,7 @@ public static STNode createReUnicodeScriptNode( } public static STNode createReUnicodeGeneralCategoryNode( - STNode categoryStart, + @Nullable STNode categoryStart, STNode reUnicodeGeneralCategoryName) { return new STReUnicodeGeneralCategoryNode( @@ -2593,8 +2594,8 @@ public static STNode createReUnicodeGeneralCategoryNode( public static STNode createReCharacterClassNode( STNode openBracket, - STNode negation, - STNode reCharSet, + @Nullable STNode negation, + @Nullable STNode reCharSet, STNode closeBracket) { return new STReCharacterClassNode( @@ -2606,7 +2607,7 @@ public static STNode createReCharacterClassNode( public static STNode createReCharSetRangeWithReCharSetNode( STNode reCharSetRange, - STNode reCharSet) { + @Nullable STNode reCharSet) { return new STReCharSetRangeWithReCharSetNode( reCharSetRange, @@ -2635,7 +2636,7 @@ public static STNode createReCharSetAtomWithReCharSetNoDashNode( public static STNode createReCharSetRangeNoDashWithReCharSetNode( STNode reCharSetRangeNoDash, - STNode reCharSet) { + @Nullable STNode reCharSet) { return new STReCharSetRangeNoDashWithReCharSetNode( reCharSetRangeNoDash, @@ -2664,7 +2665,7 @@ public static STNode createReCharSetAtomNoDashWithReCharSetNoDashNode( public static STNode createReCapturingGroupsNode( STNode openParenthesis, - STNode reFlagExpression, + @Nullable STNode reFlagExpression, STNode reSequences, STNode closeParenthesis) { @@ -2677,7 +2678,7 @@ public static STNode createReCapturingGroupsNode( public static STNode createReFlagExpressionNode( STNode questionMark, - STNode reFlagsOnOff, + @Nullable STNode reFlagsOnOff, STNode colon) { return new STReFlagExpressionNode( @@ -2688,8 +2689,8 @@ public static STNode createReFlagExpressionNode( public static STNode createReFlagsOnOffNode( STNode lhsReFlags, - STNode minusToken, - STNode rhsReFlags) { + @Nullable STNode minusToken, + @Nullable STNode rhsReFlags) { return new STReFlagsOnOffNode( lhsReFlags, @@ -2713,7 +2714,7 @@ public static STNode createReAssertionNode( public static STNode createReQuantifierNode( STNode reBaseQuantifier, - STNode nonGreedyChar) { + @Nullable STNode nonGreedyChar) { return new STReQuantifierNode( reBaseQuantifier, @@ -2723,7 +2724,7 @@ public static STNode createReQuantifierNode( public static STNode createReBracedQuantifierNode( STNode openBraceToken, STNode leastTimesMatchedDigit, - STNode commaToken, + @Nullable STNode commaToken, STNode mostTimesMatchedDigit, STNode closeBraceToken) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeReplacer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeReplacer.java index acdd4ba9c8e3..2feaff2568bd 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeReplacer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeReplacer.java @@ -17,6 +17,8 @@ */ package io.ballerina.compiler.internal.parser.tree; +import org.jetbrains.annotations.Nullable; + /** * Replaces internal tree nodes with the given replacements. *

@@ -44,6 +46,7 @@ private boolean shouldDescend(STNode node) { return true; } + @Nullable @Override protected T modifyNode(T node) { if (node == null) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeTransformer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeTransformer.java index a8e7ede4e489..2faddd2d0d96 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeTransformer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STNodeTransformer.java @@ -18,6 +18,8 @@ package io.ballerina.compiler.internal.parser.tree; +import org.jetbrains.annotations.Nullable; + /** * The {@code NodeTransformer} transform each node in the syntax tree to * another object of type T. @@ -955,6 +957,7 @@ public T transform(STReceiveFieldNode receiveFieldNode) { // Tokens + @Nullable public T transform(STToken token) { return null; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STTreeModifier.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STTreeModifier.java index 65ae9f633b60..6a0975fb23dc 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STTreeModifier.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/tree/STTreeModifier.java @@ -18,6 +18,8 @@ package io.ballerina.compiler.internal.parser.tree; +import org.jetbrains.annotations.Nullable; + /** * Produces a new tree by doing a depth-first traversal of the internal tree. *

@@ -3021,6 +3023,7 @@ protected STNode transformSyntaxNode(STNode node) { return node; } + @Nullable protected T modifyNode(T node) { if (node == null) { return null; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/utils/ConditionalExprResolver.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/utils/ConditionalExprResolver.java index 1a80cf61210a..17b565656940 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/utils/ConditionalExprResolver.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/utils/ConditionalExprResolver.java @@ -25,6 +25,7 @@ import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.compiler.internal.syntax.SyntaxUtils; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; /** * Utility methods to resolve ambiguity between qualified name ref and conditional expression. @@ -52,6 +53,7 @@ public final class ConditionalExprResolver { private ConditionalExprResolver() { } + @Nullable public static STNode getQualifiedNameRefNode(STNode parentNode, boolean leftMost) { if (parentNode == null || parentNode.kind == SyntaxKind.LIST && ((STNodeList) parentNode).isEmpty()) { return null; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/syntax/ExternalTreeNodeList.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/syntax/ExternalTreeNodeList.java index dbf05d4e4849..36926ca74cc3 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/syntax/ExternalTreeNodeList.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/syntax/ExternalTreeNodeList.java @@ -22,6 +22,7 @@ import io.ballerina.compiler.syntax.tree.NodeTransformer; import io.ballerina.compiler.syntax.tree.NodeVisitor; import io.ballerina.compiler.syntax.tree.NonTerminalNode; +import org.jetbrains.annotations.Nullable; /** * Represents a list of {@code Node}s. This class is not exposed with the syntax tre API. @@ -41,6 +42,7 @@ public ExternalTreeNodeList(STNode node, int position, NonTerminalNode parent) { public void accept(NodeVisitor visitor) { } + @Nullable @Override public T apply(NodeTransformer transformer) { return null; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/syntax/NodeReplacer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/syntax/NodeReplacer.java index 9aa2d1bb33be..9e788aadd035 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/syntax/NodeReplacer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/syntax/NodeReplacer.java @@ -22,6 +22,7 @@ import io.ballerina.compiler.syntax.tree.Token; import io.ballerina.compiler.syntax.tree.TreeModifier; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; /** * Replaces syntax nodes with the given replacements. @@ -51,6 +52,7 @@ private boolean shouldDescend(Node node) { return oldNodeTextRange.intersectionExists(node.textRangeWithMinutiae()); } + @Nullable @Override protected T modifyNode(T node) { if (node == null) { @@ -66,6 +68,7 @@ protected T modifyNode(T node) { return (T) replaced; } + @Nullable @Override protected T modifyToken(T token) { if (token == null) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AbstractNodeFactory.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AbstractNodeFactory.java index 3fe4c81fc3d0..6d1204047376 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AbstractNodeFactory.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AbstractNodeFactory.java @@ -22,6 +22,7 @@ import io.ballerina.compiler.internal.parser.tree.STNodeFactory; import io.ballerina.compiler.internal.parser.tree.STToken; import io.ballerina.compiler.internal.syntax.NodeListUtils; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; @@ -224,6 +225,7 @@ public static SeparatedNodeList createSeparatedNodeList(Coll .toList()).createUnlinkedFacade()); } + @Nullable protected static STNode getOptionalSTNode(Node node) { return node != null ? node.internalNode() : null; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationAttachPointNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationAttachPointNode.java index 7862e0bd1b97..b4813dcb85e6 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationAttachPointNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationAttachPointNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -83,6 +84,7 @@ public AnnotationAttachPointNodeModifier modify() { */ public static class AnnotationAttachPointNodeModifier { private final AnnotationAttachPointNode oldNode; + @Nullable private Token sourceKeyword; private NodeList identifiers; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationDeclarationNode.java index 58fcb3edd6e8..481dde6273c9 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -139,12 +140,17 @@ public AnnotationDeclarationNodeModifier modify() { */ public static class AnnotationDeclarationNodeModifier { private final AnnotationDeclarationNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token visibilityQualifier; + @Nullable private Token constKeyword; private Token annotationKeyword; + @Nullable private Node typeDescriptor; private Token annotationTag; + @Nullable private Token onKeyword; private SeparatedNodeList attachPoints; private Token semicolonToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationNode.java index 986357de27e8..bea66256da77 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/AnnotationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -93,6 +94,7 @@ public static class AnnotationNodeModifier { private final AnnotationNode oldNode; private Token atToken; private Node annotReference; + @Nullable private MappingConstructorExpressionNode annotValue; public AnnotationNodeModifier(AnnotationNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ArrayDimensionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ArrayDimensionNode.java index d8b5418e0915..edee1239ebda 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ArrayDimensionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ArrayDimensionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -92,6 +93,7 @@ public ArrayDimensionNodeModifier modify() { public static class ArrayDimensionNodeModifier { private final ArrayDimensionNode oldNode; private Token openBracket; + @Nullable private Node arrayLength; private Token closeBracket; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/BallerinaNameReferenceNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/BallerinaNameReferenceNode.java index 2e2871291a08..d35efd21e403 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/BallerinaNameReferenceNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/BallerinaNameReferenceNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -99,6 +100,7 @@ public BallerinaNameReferenceNodeModifier modify() { */ public static class BallerinaNameReferenceNodeModifier { private final BallerinaNameReferenceNode oldNode; + @Nullable private Token referenceType; private Token startBacktick; private Node nameReference; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ByteArrayLiteralNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ByteArrayLiteralNode.java index b6d8869d2ba1..bd7435cb3099 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ByteArrayLiteralNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ByteArrayLiteralNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -101,6 +102,7 @@ public static class ByteArrayLiteralNodeModifier { private final ByteArrayLiteralNode oldNode; private Token type; private Token startBacktick; + @Nullable private Token content; private Token endBacktick; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ChildNodeList.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ChildNodeList.java index f64f251ca138..8d466218116a 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ChildNodeList.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ChildNodeList.java @@ -19,6 +19,7 @@ import io.ballerina.compiler.internal.parser.tree.STNode; import io.ballerina.compiler.internal.syntax.SyntaxUtils; +import org.jetbrains.annotations.Nullable; import java.util.Iterator; @@ -73,6 +74,7 @@ private int getChildCount(STNode parent) { return count; } + @Nullable private Node loadNode(int childIndex) { int index = 0; Node child = null; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ClassDefinitionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ClassDefinitionNode.java index 508f3ed7c1aa..4db8afb9dded 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ClassDefinitionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ClassDefinitionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -139,7 +140,9 @@ public ClassDefinitionNodeModifier modify() { */ public static class ClassDefinitionNodeModifier { private final ClassDefinitionNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token visibilityQualifier; private NodeList classTypeQualifiers; private Token classKeyword; @@ -147,6 +150,7 @@ public static class ClassDefinitionNodeModifier { private Token openBrace; private NodeList members; private Token closeBrace; + @Nullable private Token semicolonToken; public ClassDefinitionNodeModifier(ClassDefinitionNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ClientResourceAccessActionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ClientResourceAccessActionNode.java index e21910880004..a689ec7824a7 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ClientResourceAccessActionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ClientResourceAccessActionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -127,8 +128,11 @@ public static class ClientResourceAccessActionNodeModifier { private Token rightArrowToken; private Token slashToken; private SeparatedNodeList resourceAccessPath; + @Nullable private Token dotToken; + @Nullable private SimpleNameReferenceNode methodName; + @Nullable private ParenthesizedArgList arguments; public ClientResourceAccessActionNodeModifier(ClientResourceAccessActionNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ConstantDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ConstantDeclarationNode.java index 54dabfd90060..cc1558ecffdb 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ConstantDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ConstantDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -131,9 +132,12 @@ public ConstantDeclarationNodeModifier modify() { */ public static class ConstantDeclarationNodeModifier { private final ConstantDeclarationNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token visibilityQualifier; private Token constKeyword; + @Nullable private TypeDescriptorNode typeDescriptor; private Token variableName; private Token equalsToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/DefaultableParameterNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/DefaultableParameterNode.java index 210aaa66f855..c6e70ef0e076 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/DefaultableParameterNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/DefaultableParameterNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -109,6 +110,7 @@ public static class DefaultableParameterNodeModifier { private final DefaultableParameterNode oldNode; private NodeList annotations; private Node typeName; + @Nullable private Token paramName; private Token equalsToken; private Node expression; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/DoStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/DoStatementNode.java index f3175b4828c6..37e096ba2f1a 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/DoStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/DoStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -93,6 +94,7 @@ public static class DoStatementNodeModifier { private final DoStatementNode oldNode; private Token doKeyword; private BlockStatementNode blockStatement; + @Nullable private OnFailClauseNode onFailClause; public DoStatementNodeModifier(DoStatementNode oldNode) { @@ -117,7 +119,7 @@ public DoStatementNodeModifier withBlockStatement( } public DoStatementNodeModifier withOnFailClause( - OnFailClauseNode onFailClause) { + @Nullable OnFailClauseNode onFailClause) { this.onFailClause = onFailClause; return this; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/EnumDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/EnumDeclarationNode.java index ede131a4f7bf..ec01c5af078b 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/EnumDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/EnumDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -131,13 +132,16 @@ public EnumDeclarationNodeModifier modify() { */ public static class EnumDeclarationNodeModifier { private final EnumDeclarationNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token qualifier; private Token enumKeywordToken; private IdentifierToken identifier; private Token openBraceToken; private SeparatedNodeList enumMemberList; private Token closeBraceToken; + @Nullable private Token semicolonToken; public EnumDeclarationNodeModifier(EnumDeclarationNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/EnumMemberNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/EnumMemberNode.java index d396b7520981..b1f23163c6b8 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/EnumMemberNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/EnumMemberNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -99,9 +100,12 @@ public EnumMemberNodeModifier modify() { */ public static class EnumMemberNodeModifier { private final EnumMemberNode oldNode; + @Nullable private MetadataNode metadata; private IdentifierToken identifier; + @Nullable private Token equalToken; + @Nullable private ExpressionNode constExprNode; public EnumMemberNodeModifier(EnumMemberNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorBindingPatternNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorBindingPatternNode.java index bc8ab4b4b647..ec9cd9ba297e 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorBindingPatternNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorBindingPatternNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -108,6 +109,7 @@ public ErrorBindingPatternNodeModifier modify() { public static class ErrorBindingPatternNodeModifier { private final ErrorBindingPatternNode oldNode; private Token errorKeyword; + @Nullable private Node typeReference; private Token openParenthesis; private SeparatedNodeList argListBindingPatterns; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorConstructorExpressionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorConstructorExpressionNode.java index 74ec1ed402bf..b113ff639ffe 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorConstructorExpressionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorConstructorExpressionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -108,6 +109,7 @@ public ErrorConstructorExpressionNodeModifier modify() { public static class ErrorConstructorExpressionNodeModifier { private final ErrorConstructorExpressionNode oldNode; private Token errorKeyword; + @Nullable private TypeDescriptorNode typeReference; private Token openParenToken; private SeparatedNodeList arguments; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorMatchPatternNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorMatchPatternNode.java index a35dc3de597e..75ce5751f51f 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorMatchPatternNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ErrorMatchPatternNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -108,6 +109,7 @@ public ErrorMatchPatternNodeModifier modify() { public static class ErrorMatchPatternNodeModifier { private final ErrorMatchPatternNode oldNode; private Token errorKeyword; + @Nullable private NameReferenceNode typeReference; private Token openParenthesisToken; private SeparatedNodeList argListMatchPatternNode; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ExpressionFunctionBodyNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ExpressionFunctionBodyNode.java index df6ac035f3bc..ca6bd47fc1ba 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ExpressionFunctionBodyNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ExpressionFunctionBodyNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -93,6 +94,7 @@ public static class ExpressionFunctionBodyNodeModifier { private final ExpressionFunctionBodyNode oldNode; private Token rightDoubleArrow; private ExpressionNode expression; + @Nullable private Token semicolon; public ExpressionFunctionBodyNodeModifier(ExpressionFunctionBodyNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FlushActionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FlushActionNode.java index 09c7e2d8c398..4784200bf8ce 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FlushActionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FlushActionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public FlushActionNodeModifier modify() { public static class FlushActionNodeModifier { private final FlushActionNode oldNode; private Token flushKeyword; + @Nullable private NameReferenceNode peerWorker; public FlushActionNodeModifier(FlushActionNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ForEachStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ForEachStatementNode.java index 1d16ca701b2e..d798d722ddde 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ForEachStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ForEachStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -120,6 +121,7 @@ public static class ForEachStatementNodeModifier { private Token inKeyword; private Node actionOrExpressionNode; private BlockStatementNode blockStatement; + @Nullable private OnFailClauseNode onFailClause; public ForEachStatementNodeModifier(ForEachStatementNode oldNode) { @@ -168,7 +170,7 @@ public ForEachStatementNodeModifier withBlockStatement( } public ForEachStatementNodeModifier withOnFailClause( - OnFailClauseNode onFailClause) { + @Nullable OnFailClauseNode onFailClause) { this.onFailClause = onFailClause; return this; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionBodyBlockNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionBodyBlockNode.java index fd9f281c50ee..2c8b4adc06d5 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionBodyBlockNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionBodyBlockNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -108,9 +109,11 @@ public FunctionBodyBlockNodeModifier modify() { public static class FunctionBodyBlockNodeModifier { private final FunctionBodyBlockNode oldNode; private Token openBraceToken; + @Nullable private NamedWorkerDeclarator namedWorkerDeclarator; private NodeList statements; private Token closeBraceToken; + @Nullable private Token semicolonToken; public FunctionBodyBlockNodeModifier(FunctionBodyBlockNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionDefinitionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionDefinitionNode.java index b93639e9de67..f55cfe447602 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionDefinitionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionDefinitionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -125,6 +126,7 @@ public FunctionDefinitionNodeModifier modify() { */ public static class FunctionDefinitionNodeModifier { private final FunctionDefinitionNode oldNode; + @Nullable private MetadataNode metadata; private NodeList qualifierList; private Token functionKeyword; @@ -145,7 +147,7 @@ public FunctionDefinitionNodeModifier(FunctionDefinitionNode oldNode) { } public FunctionDefinitionNodeModifier withMetadata( - MetadataNode metadata) { + @Nullable MetadataNode metadata) { this.metadata = metadata; return this; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionSignatureNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionSignatureNode.java index 657b1ca13543..d6895633dfe7 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionSignatureNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionSignatureNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -102,6 +103,7 @@ public static class FunctionSignatureNodeModifier { private Token openParenToken; private SeparatedNodeList parameters; private Token closeParenToken; + @Nullable private ReturnTypeDescriptorNode returnTypeDesc; public FunctionSignatureNodeModifier(FunctionSignatureNode oldNode) { @@ -134,7 +136,7 @@ public FunctionSignatureNodeModifier withCloseParenToken( } public FunctionSignatureNodeModifier withReturnTypeDesc( - ReturnTypeDescriptorNode returnTypeDesc) { + @Nullable ReturnTypeDescriptorNode returnTypeDesc) { this.returnTypeDesc = returnTypeDesc; return this; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionTypeDescriptorNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionTypeDescriptorNode.java index 4df42f4d18fe..8449aaa1d265 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionTypeDescriptorNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/FunctionTypeDescriptorNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -93,6 +94,7 @@ public static class FunctionTypeDescriptorNodeModifier { private final FunctionTypeDescriptorNode oldNode; private NodeList qualifierList; private Token functionKeyword; + @Nullable private FunctionSignatureNode functionSignature; public FunctionTypeDescriptorNodeModifier(FunctionTypeDescriptorNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/IfElseStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/IfElseStatementNode.java index 5fa99db2eb09..76d787af4022 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/IfElseStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/IfElseStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -102,6 +103,7 @@ public static class IfElseStatementNodeModifier { private Token ifKeyword; private ExpressionNode condition; private BlockStatementNode ifBody; + @Nullable private Node elseBody; public IfElseStatementNodeModifier(IfElseStatementNode oldNode) { @@ -134,7 +136,7 @@ public IfElseStatementNodeModifier withIfBody( } public IfElseStatementNodeModifier withElseBody( - Node elseBody) { + @Nullable Node elseBody) { this.elseBody = elseBody; return this; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ImplicitNewExpressionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ImplicitNewExpressionNode.java index da5247eb8218..3d2fdbe863e5 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ImplicitNewExpressionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ImplicitNewExpressionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public ImplicitNewExpressionNodeModifier modify() { public static class ImplicitNewExpressionNodeModifier { private final ImplicitNewExpressionNode oldNode; private Token newKeyword; + @Nullable private ParenthesizedArgList parenthesizedArgList; public ImplicitNewExpressionNodeModifier(ImplicitNewExpressionNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ImportDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ImportDeclarationNode.java index 003085d46ab6..133cd6aa3f20 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ImportDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ImportDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -108,8 +109,10 @@ public ImportDeclarationNodeModifier modify() { public static class ImportDeclarationNodeModifier { private final ImportDeclarationNode oldNode; private Token importKeyword; + @Nullable private ImportOrgNameNode orgName; private SeparatedNodeList moduleName; + @Nullable private ImportPrefixNode prefix; private Token semicolon; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/IncludedRecordParameterNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/IncludedRecordParameterNode.java index 103fb12fef20..766fdf5c9843 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/IncludedRecordParameterNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/IncludedRecordParameterNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -102,6 +103,7 @@ public static class IncludedRecordParameterNodeModifier { private NodeList annotations; private Token asteriskToken; private Node typeName; + @Nullable private Token paramName; public IncludedRecordParameterNodeModifier(IncludedRecordParameterNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/JoinClauseNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/JoinClauseNode.java index 7ed8fde3072a..13a93df00c85 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/JoinClauseNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/JoinClauseNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -115,6 +116,7 @@ public JoinClauseNodeModifier modify() { */ public static class JoinClauseNodeModifier { private final JoinClauseNode oldNode; + @Nullable private Token outerKeyword; private Token joinKeyword; private TypedBindingPatternNode typedBindingPattern; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ListenerDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ListenerDeclarationNode.java index 65544b4e4297..cf01f83d4d8e 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ListenerDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ListenerDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -131,9 +132,12 @@ public ListenerDeclarationNodeModifier modify() { */ public static class ListenerDeclarationNodeModifier { private final ListenerDeclarationNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token visibilityQualifier; private Token listenerKeyword; + @Nullable private TypeDescriptorNode typeDescriptor; private Token variableName; private Token equalsToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/LockStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/LockStatementNode.java index 8e79869d1db7..cef973a1c158 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/LockStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/LockStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -93,6 +94,7 @@ public static class LockStatementNodeModifier { private final LockStatementNode oldNode; private Token lockKeyword; private BlockStatementNode blockStatement; + @Nullable private OnFailClauseNode onFailClause; public LockStatementNodeModifier(LockStatementNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MarkdownCodeBlockNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MarkdownCodeBlockNode.java index 3b326ab584b4..58bb07fa1ec5 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MarkdownCodeBlockNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MarkdownCodeBlockNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -117,6 +118,7 @@ public static class MarkdownCodeBlockNodeModifier { private final MarkdownCodeBlockNode oldNode; private Token startLineHashToken; private Token startBacktick; + @Nullable private Token langAttribute; private NodeList codeLines; private Token endLineHashToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MatchClauseNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MatchClauseNode.java index c6b202ba8176..4c4f0e743023 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MatchClauseNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MatchClauseNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -100,6 +101,7 @@ public MatchClauseNodeModifier modify() { public static class MatchClauseNodeModifier { private final MatchClauseNode oldNode; private SeparatedNodeList matchPatterns; + @Nullable private MatchGuardNode matchGuard; private Token rightDoubleArrow; private BlockStatementNode blockStatement; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MatchStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MatchStatementNode.java index ee4b26604b25..9e061e30dfc4 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MatchStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MatchStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -120,6 +121,7 @@ public static class MatchStatementNodeModifier { private Token openBrace; private NodeList matchClauses; private Token closeBrace; + @Nullable private OnFailClauseNode onFailClause; public MatchStatementNodeModifier(MatchStatementNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MetadataNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MetadataNode.java index a65f2e18319f..b1e30e443fe7 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MetadataNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MetadataNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -83,6 +84,7 @@ public MetadataNodeModifier modify() { */ public static class MetadataNodeModifier { private final MetadataNode oldNode; + @Nullable private Node documentationString; private NodeList annotations; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MethodDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MethodDeclarationNode.java index 1578362b49e5..a31d63ce6b49 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MethodDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MethodDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -125,6 +126,7 @@ public MethodDeclarationNodeModifier modify() { */ public static class MethodDeclarationNodeModifier { private final MethodDeclarationNode oldNode; + @Nullable private MetadataNode metadata; private NodeList qualifierList; private Token functionKeyword; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/Minutiae.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/Minutiae.java index 983c9dc8d02b..0db39fbe05cd 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/Minutiae.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/Minutiae.java @@ -23,6 +23,7 @@ import io.ballerina.tools.text.LineRange; import io.ballerina.tools.text.TextDocument; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -39,7 +40,7 @@ public final class Minutiae { private TextRange textRange; private LineRange lineRange; - Minutiae(STMinutiae internalMinutiae, Token token, int position) { + Minutiae(STMinutiae internalMinutiae, @Nullable Token token, int position) { this.internalMinutiae = internalMinutiae; this.token = token; this.position = position; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MinutiaeList.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MinutiaeList.java index a9ddad56e51c..91625e3f817a 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MinutiaeList.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/MinutiaeList.java @@ -22,6 +22,7 @@ import io.ballerina.compiler.internal.parser.tree.STNodeList; import io.ballerina.compiler.internal.syntax.NodeListUtils; import io.ballerina.compiler.internal.syntax.SyntaxUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -44,7 +45,7 @@ public final class MinutiaeList implements Iterable { private final int size; private final Minutiae[] minutiaeNodes; - MinutiaeList(Token token, STNode internalMinutiae, int position) { + MinutiaeList(@Nullable Token token, STNode internalMinutiae, int position) { if (!NodeListUtils.isSTNodeList(internalMinutiae)) { throw new IllegalArgumentException("An STNodeList instance is expected"); } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ModuleVariableDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ModuleVariableDeclarationNode.java index 948f8befc382..d91f8d01869d 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ModuleVariableDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ModuleVariableDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -123,11 +124,15 @@ public ModuleVariableDeclarationNodeModifier modify() { */ public static class ModuleVariableDeclarationNodeModifier { private final ModuleVariableDeclarationNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token visibilityQualifier; private NodeList qualifiers; private TypedBindingPatternNode typedBindingPattern; + @Nullable private Token equalsToken; + @Nullable private ExpressionNode initializer; private Token semicolonToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ModuleXMLNamespaceDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ModuleXMLNamespaceDeclarationNode.java index 522537788d41..f194e1393e9a 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ModuleXMLNamespaceDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ModuleXMLNamespaceDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -109,7 +110,9 @@ public static class ModuleXMLNamespaceDeclarationNodeModifier { private final ModuleXMLNamespaceDeclarationNode oldNode; private Token xmlnsKeyword; private ExpressionNode namespaceuri; + @Nullable private Token asKeyword; + @Nullable private IdentifierToken namespacePrefix; private Token semicolonToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NamedWorkerDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NamedWorkerDeclarationNode.java index 89e3dc9a03dc..d6d23fe9b4d3 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NamedWorkerDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NamedWorkerDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -124,11 +125,14 @@ public NamedWorkerDeclarationNodeModifier modify() { public static class NamedWorkerDeclarationNodeModifier { private final NamedWorkerDeclarationNode oldNode; private NodeList annotations; + @Nullable private Token transactionalKeyword; private Token workerKeyword; private IdentifierToken workerName; + @Nullable private Node returnTypeDesc; private BlockStatementNode workerBody; + @Nullable private OnFailClauseNode onFailClause; public NamedWorkerDeclarationNodeModifier(NamedWorkerDeclarationNode oldNode) { @@ -183,7 +187,7 @@ public NamedWorkerDeclarationNodeModifier withWorkerBody( } public NamedWorkerDeclarationNodeModifier withOnFailClause( - OnFailClauseNode onFailClause) { + @Nullable OnFailClauseNode onFailClause) { this.onFailClause = onFailClause; return this; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NodeFactory.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NodeFactory.java index 0d1652e9dfa8..c7ad68a98270 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NodeFactory.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NodeFactory.java @@ -19,6 +19,7 @@ import io.ballerina.compiler.internal.parser.tree.STNode; import io.ballerina.compiler.internal.parser.tree.STNodeFactory; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -50,8 +51,8 @@ public static ModulePartNode createModulePartNode( } public static FunctionDefinitionNode createFunctionDefinitionNode( - SyntaxKind kind, - MetadataNode metadata, + @Nullable SyntaxKind kind, + @Nullable MetadataNode metadata, NodeList qualifierList, Token functionKeyword, IdentifierToken functionName, @@ -79,9 +80,9 @@ public static FunctionDefinitionNode createFunctionDefinitionNode( public static ImportDeclarationNode createImportDeclarationNode( Token importKeyword, - ImportOrgNameNode orgName, + @Nullable ImportOrgNameNode orgName, SeparatedNodeList moduleName, - ImportPrefixNode prefix, + @Nullable ImportPrefixNode prefix, Token semicolon) { Objects.requireNonNull(importKeyword, "importKeyword must not be null"); Objects.requireNonNull(moduleName, "moduleName must not be null"); @@ -124,8 +125,8 @@ public static ListenerDeclarationNode createListenerDeclarationNode( } public static TypeDefinitionNode createTypeDefinitionNode( - MetadataNode metadata, - Token visibilityQualifier, + @Nullable MetadataNode metadata, + @Nullable Token visibilityQualifier, Token typeKeyword, Token typeName, Node typeDescriptor, @@ -222,10 +223,10 @@ public static CompoundAssignmentStatementNode createCompoundAssignmentStatementN public static VariableDeclarationNode createVariableDeclarationNode( NodeList annotations, - Token finalKeyword, + @Nullable Token finalKeyword, TypedBindingPatternNode typedBindingPattern, - Token equalsToken, - ExpressionNode initializer, + @Nullable Token equalsToken, + @Nullable ExpressionNode initializer, Token semicolonToken) { Objects.requireNonNull(annotations, "annotations must not be null"); Objects.requireNonNull(typedBindingPattern, "typedBindingPattern must not be null"); @@ -284,7 +285,7 @@ public static FailStatementNode createFailStatementNode( } public static ExpressionStatementNode createExpressionStatementNode( - SyntaxKind kind, + @Nullable SyntaxKind kind, ExpressionNode expression, Token semicolonToken) { Objects.requireNonNull(expression, "expression must not be null"); @@ -331,7 +332,7 @@ public static IfElseStatementNode createIfElseStatementNode( Token ifKeyword, ExpressionNode condition, BlockStatementNode ifBody, - Node elseBody) { + @Nullable Node elseBody) { Objects.requireNonNull(ifKeyword, "ifKeyword must not be null"); Objects.requireNonNull(condition, "condition must not be null"); Objects.requireNonNull(ifBody, "ifBody must not be null"); @@ -461,7 +462,7 @@ public static ForEachStatementNode createForEachStatementNode( Token inKeyword, Node actionOrExpressionNode, BlockStatementNode blockStatement, - OnFailClauseNode onFailClause) { + @Nullable OnFailClauseNode onFailClause) { Objects.requireNonNull(forEachKeyword, "forEachKeyword must not be null"); Objects.requireNonNull(typedBindingPattern, "typedBindingPattern must not be null"); Objects.requireNonNull(inKeyword, "inKeyword must not be null"); @@ -479,7 +480,7 @@ public static ForEachStatementNode createForEachStatementNode( } public static BinaryExpressionNode createBinaryExpressionNode( - SyntaxKind kind, + @Nullable SyntaxKind kind, Node lhsExpr, Token operator, Node rhsExpr) { @@ -496,7 +497,7 @@ public static BinaryExpressionNode createBinaryExpressionNode( } public static BracedExpressionNode createBracedExpressionNode( - SyntaxKind kind, + @Nullable SyntaxKind kind, Token openParen, ExpressionNode expression, Token closeParen) { @@ -513,7 +514,7 @@ public static BracedExpressionNode createBracedExpressionNode( } public static CheckExpressionNode createCheckExpressionNode( - SyntaxKind kind, + @Nullable SyntaxKind kind, Token checkKeyword, ExpressionNode expression) { Objects.requireNonNull(checkKeyword, "checkKeyword must not be null"); @@ -781,10 +782,10 @@ public static ImportPrefixNode createImportPrefixNode( } public static SpecificFieldNode createSpecificFieldNode( - Token readonlyKeyword, + @Nullable Token readonlyKeyword, Node fieldName, Token colon, - ExpressionNode valueExpr) { + @Nullable ExpressionNode valueExpr) { Objects.requireNonNull(fieldName, "fieldName must not be null"); STNode stSpecificFieldNode = STNodeFactory.createSpecificFieldNode( @@ -906,7 +907,7 @@ public static RecordTypeDescriptorNode createRecordTypeDescriptorNode( Token recordKeyword, Token bodyStartDelimiter, NodeList fields, - RecordRestDescriptorNode recordRestDescriptor, + @Nullable RecordRestDescriptorNode recordRestDescriptor, Token bodyEndDelimiter) { Objects.requireNonNull(recordKeyword, "recordKeyword must not be null"); Objects.requireNonNull(bodyStartDelimiter, "bodyStartDelimiter must not be null"); @@ -988,11 +989,11 @@ public static ObjectFieldNode createObjectFieldNode( } public static RecordFieldNode createRecordFieldNode( - MetadataNode metadata, - Token readonlyKeyword, + @Nullable MetadataNode metadata, + @Nullable Token readonlyKeyword, Node typeName, Token fieldName, - Token questionMarkToken, + @Nullable Token questionMarkToken, Token semicolonToken) { Objects.requireNonNull(typeName, "typeName must not be null"); Objects.requireNonNull(fieldName, "fieldName must not be null"); @@ -1010,7 +1011,7 @@ public static RecordFieldNode createRecordFieldNode( public static RecordFieldWithDefaultValueNode createRecordFieldWithDefaultValueNode( MetadataNode metadata, - Token readonlyKeyword, + @Nullable Token readonlyKeyword, Node typeName, Token fieldName, Token equalsToken, @@ -1066,7 +1067,7 @@ public static TypeReferenceNode createTypeReferenceNode( public static AnnotationNode createAnnotationNode( Token atToken, Node annotReference, - MappingConstructorExpressionNode annotValue) { + @Nullable MappingConstructorExpressionNode annotValue) { Objects.requireNonNull(atToken, "atToken must not be null"); Objects.requireNonNull(annotReference, "annotReference must not be null"); @@ -1078,7 +1079,7 @@ public static AnnotationNode createAnnotationNode( } public static MetadataNode createMetadataNode( - Node documentationString, + @Nullable Node documentationString, NodeList annotations) { Objects.requireNonNull(annotations, "annotations must not be null"); @@ -1090,11 +1091,11 @@ public static MetadataNode createMetadataNode( public static ModuleVariableDeclarationNode createModuleVariableDeclarationNode( MetadataNode metadata, - Token visibilityQualifier, + @Nullable Token visibilityQualifier, NodeList qualifiers, TypedBindingPatternNode typedBindingPattern, - Token equalsToken, - ExpressionNode initializer, + @Nullable Token equalsToken, + @Nullable ExpressionNode initializer, Token semicolonToken) { Objects.requireNonNull(qualifiers, "qualifiers must not be null"); Objects.requireNonNull(typedBindingPattern, "typedBindingPattern must not be null"); @@ -1253,10 +1254,10 @@ public static ModuleXMLNamespaceDeclarationNode createModuleXMLNamespaceDeclarat public static FunctionBodyBlockNode createFunctionBodyBlockNode( Token openBraceToken, - NamedWorkerDeclarator namedWorkerDeclarator, + @Nullable NamedWorkerDeclarator namedWorkerDeclarator, NodeList statements, Token closeBraceToken, - Token semicolonToken) { + @Nullable Token semicolonToken) { Objects.requireNonNull(openBraceToken, "openBraceToken must not be null"); Objects.requireNonNull(statements, "statements must not be null"); Objects.requireNonNull(closeBraceToken, "closeBraceToken must not be null"); @@ -1299,7 +1300,7 @@ public static NamedWorkerDeclarationNode createNamedWorkerDeclarationNode( IdentifierToken workerName, Node returnTypeDesc, BlockStatementNode workerBody, - OnFailClauseNode onFailClause) { + @Nullable OnFailClauseNode onFailClause) { Objects.requireNonNull(annotations, "annotations must not be null"); Objects.requireNonNull(workerKeyword, "workerKeyword must not be null"); Objects.requireNonNull(workerName, "workerName must not be null"); @@ -1364,7 +1365,7 @@ public static QualifiedNameReferenceNode createQualifiedNameReferenceNode( } public static BuiltinSimpleNameReferenceNode createBuiltinSimpleNameReferenceNode( - SyntaxKind kind, + @Nullable SyntaxKind kind, Token name) { Objects.requireNonNull(name, "name must not be null"); @@ -1827,7 +1828,7 @@ public static FunctionSignatureNode createFunctionSignatureNode( Token openParenToken, SeparatedNodeList parameters, Token closeParenToken, - ReturnTypeDescriptorNode returnTypeDesc) { + @Nullable ReturnTypeDescriptorNode returnTypeDesc) { Objects.requireNonNull(openParenToken, "openParenToken must not be null"); Objects.requireNonNull(parameters, "parameters must not be null"); Objects.requireNonNull(closeParenToken, "closeParenToken must not be null"); @@ -2627,7 +2628,7 @@ public static ArrayTypeDescriptorNode createArrayTypeDescriptorNode( public static ArrayDimensionNode createArrayDimensionNode( Token openBracket, - Node arrayLength, + @Nullable Node arrayLength, Token closeBracket) { Objects.requireNonNull(openBracket, "openBracket must not be null"); Objects.requireNonNull(closeBracket, "closeBracket must not be null"); @@ -2985,7 +2986,7 @@ public static MarkdownDocumentationNode createMarkdownDocumentationNode( } public static MarkdownDocumentationLineNode createMarkdownDocumentationLineNode( - SyntaxKind kind, + @Nullable SyntaxKind kind, Token hashToken, NodeList documentElements) { Objects.requireNonNull(hashToken, "hashToken must not be null"); @@ -2999,7 +3000,7 @@ public static MarkdownDocumentationLineNode createMarkdownDocumentationLineNode( } public static MarkdownParameterDocumentationLineNode createMarkdownParameterDocumentationLineNode( - SyntaxKind kind, + @Nullable SyntaxKind kind, Token hashToken, Token plusToken, Token parameterName, @@ -3281,7 +3282,7 @@ public static ErrorConstructorExpressionNode createErrorConstructorExpressionNod public static ParameterizedTypeDescriptorNode createParameterizedTypeDescriptorNode( SyntaxKind kind, Token keywordToken, - TypeParameterNode typeParamNode) { + @Nullable TypeParameterNode typeParamNode) { Objects.requireNonNull(keywordToken, "keywordToken must not be null"); STNode stParameterizedTypeDescriptorNode = STNodeFactory.createParameterizedTypeDescriptorNode( diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NodeTransformer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NodeTransformer.java index 1f9a6b0026dc..e80d19fd7c0f 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NodeTransformer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NodeTransformer.java @@ -18,6 +18,8 @@ package io.ballerina.compiler.syntax.tree; +import org.jetbrains.annotations.Nullable; + /** * The {@code NodeTransformer} transform each node in the syntax tree to * another object of type T. @@ -966,6 +968,7 @@ public T transform(ReceiveFieldNode receiveFieldNode) { // Tokens + @Nullable public T transform(Token token) { return null; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NonTerminalNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NonTerminalNode.java index c7006d8a0cbd..e43790fc982e 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NonTerminalNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/NonTerminalNode.java @@ -23,6 +23,7 @@ import io.ballerina.compiler.internal.syntax.TreeModifiers; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -44,7 +45,7 @@ public abstract class NonTerminalNode extends Node { protected final Node[] childBuckets; private ChildNodeList childNodeList; - public NonTerminalNode(STNode internalNode, int position, NonTerminalNode parent) { + public NonTerminalNode(STNode internalNode, int position, @Nullable NonTerminalNode parent) { super(internalNode, position, parent); this.childBuckets = new Node[internalNode.bucketCount()]; } @@ -143,6 +144,7 @@ public NonTerminalNode findNode(TextRange textRange) { * @param includeStartOffset whether to include start offset when checking text range * @return Innermost {@link NonTerminalNode} encapsulation given text range */ + @Nullable public NonTerminalNode findNode(TextRange textRange, boolean includeStartOffset) { TextRange textRangeWithMinutiae = textRangeWithMinutiae(); if (!(this instanceof ModulePartNode) diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ObjectConstructorExpressionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ObjectConstructorExpressionNode.java index c3298394ddb7..a1dee276dd70 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ObjectConstructorExpressionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ObjectConstructorExpressionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -126,6 +127,7 @@ public static class ObjectConstructorExpressionNodeModifier { private NodeList annotations; private NodeList objectTypeQualifiers; private Token objectKeyword; + @Nullable private TypeDescriptorNode typeReference; private Token openBraceToken; private NodeList members; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ObjectFieldNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ObjectFieldNode.java index 51c5e7163bb3..629cf239824c 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ObjectFieldNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ObjectFieldNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -131,12 +132,16 @@ public ObjectFieldNodeModifier modify() { */ public static class ObjectFieldNodeModifier { private final ObjectFieldNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token visibilityQualifier; private NodeList qualifierList; private Node typeName; private Token fieldName; + @Nullable private Token equalsToken; + @Nullable private ExpressionNode expression; private Token semicolonToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/OnFailClauseNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/OnFailClauseNode.java index ca6b053c802e..89229d90b706 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/OnFailClauseNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/OnFailClauseNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -101,6 +102,7 @@ public static class OnFailClauseNodeModifier { private final OnFailClauseNode oldNode; private Token onKeyword; private Token failKeyword; + @Nullable private TypedBindingPatternNode typedBindingPattern; private BlockStatementNode blockStatement; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/OrderKeyNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/OrderKeyNode.java index 7ac6b5c8079d..88b785e922c1 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/OrderKeyNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/OrderKeyNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public OrderKeyNodeModifier modify() { public static class OrderKeyNodeModifier { private final OrderKeyNode oldNode; private ExpressionNode expression; + @Nullable private Token orderDirection; public OrderKeyNodeModifier(OrderKeyNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ParameterizedTypeDescriptorNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ParameterizedTypeDescriptorNode.java index 697fe3beb133..170b16241092 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ParameterizedTypeDescriptorNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ParameterizedTypeDescriptorNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -86,6 +87,7 @@ public ParameterizedTypeDescriptorNodeModifier modify() { public static class ParameterizedTypeDescriptorNodeModifier { private final ParameterizedTypeDescriptorNode oldNode; private Token keywordToken; + @Nullable private TypeParameterNode typeParamNode; public ParameterizedTypeDescriptorNodeModifier(ParameterizedTypeDescriptorNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/QueryConstructTypeNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/QueryConstructTypeNode.java index 4094f1422428..7077ef300d9b 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/QueryConstructTypeNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/QueryConstructTypeNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public QueryConstructTypeNodeModifier modify() { public static class QueryConstructTypeNodeModifier { private final QueryConstructTypeNode oldNode; private Token keyword; + @Nullable private KeySpecifierNode keySpecifier; public QueryConstructTypeNodeModifier(QueryConstructTypeNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/QueryExpressionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/QueryExpressionNode.java index f5bf6d597f90..44cb63ec3def 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/QueryExpressionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/QueryExpressionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -111,9 +112,11 @@ public QueryExpressionNodeModifier modify() { */ public static class QueryExpressionNodeModifier { private final QueryExpressionNode oldNode; + @Nullable private QueryConstructTypeNode queryConstructType; private QueryPipelineNode queryPipeline; private ClauseNode resultClause; + @Nullable private OnConflictClauseNode onConflictClause; public QueryExpressionNodeModifier(QueryExpressionNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReAtomQuantifierNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReAtomQuantifierNode.java index 872c6c20cbf5..d44ee186cbdf 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReAtomQuantifierNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReAtomQuantifierNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public ReAtomQuantifierNodeModifier modify() { public static class ReAtomQuantifierNodeModifier { private final ReAtomQuantifierNode oldNode; private Node reAtom; + @Nullable private ReQuantifierNode reQuantifier; public ReAtomQuantifierNodeModifier(ReAtomQuantifierNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReBracedQuantifierNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReBracedQuantifierNode.java index 1e970aac965c..65dd1e4a6c11 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReBracedQuantifierNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReBracedQuantifierNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -109,6 +110,7 @@ public static class ReBracedQuantifierNodeModifier { private final ReBracedQuantifierNode oldNode; private Token openBraceToken; private NodeList leastTimesMatchedDigit; + @Nullable private Token commaToken; private NodeList mostTimesMatchedDigit; private Token closeBraceToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCapturingGroupsNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCapturingGroupsNode.java index 038061465d8d..05345cb38595 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCapturingGroupsNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCapturingGroupsNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -100,6 +101,7 @@ public ReCapturingGroupsNodeModifier modify() { public static class ReCapturingGroupsNodeModifier { private final ReCapturingGroupsNode oldNode; private Token openParenthesis; + @Nullable private ReFlagExpressionNode reFlagExpression; private NodeList reSequences; private Token closeParenthesis; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharSetRangeNoDashWithReCharSetNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharSetRangeNoDashWithReCharSetNode.java index f9a2754caf16..eaf697b47ee8 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharSetRangeNoDashWithReCharSetNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharSetRangeNoDashWithReCharSetNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public ReCharSetRangeNoDashWithReCharSetNodeModifier modify() { public static class ReCharSetRangeNoDashWithReCharSetNodeModifier { private final ReCharSetRangeNoDashWithReCharSetNode oldNode; private ReCharSetRangeNoDashNode reCharSetRangeNoDash; + @Nullable private Node reCharSet; public ReCharSetRangeNoDashWithReCharSetNodeModifier(ReCharSetRangeNoDashWithReCharSetNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharSetRangeWithReCharSetNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharSetRangeWithReCharSetNode.java index 8916a9ff7086..62c2d2476fc2 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharSetRangeWithReCharSetNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharSetRangeWithReCharSetNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public ReCharSetRangeWithReCharSetNodeModifier modify() { public static class ReCharSetRangeWithReCharSetNodeModifier { private final ReCharSetRangeWithReCharSetNode oldNode; private ReCharSetRangeNode reCharSetRange; + @Nullable private Node reCharSet; public ReCharSetRangeWithReCharSetNodeModifier(ReCharSetRangeWithReCharSetNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharacterClassNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharacterClassNode.java index 74c4f52d67c2..f7f73ae008a9 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharacterClassNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReCharacterClassNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -100,7 +101,9 @@ public ReCharacterClassNodeModifier modify() { public static class ReCharacterClassNodeModifier { private final ReCharacterClassNode oldNode; private Token openBracket; + @Nullable private Token negation; + @Nullable private Node reCharSet; private Token closeBracket; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReFlagsOnOffNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReFlagsOnOffNode.java index aa430c53219c..619fe5362d21 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReFlagsOnOffNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReFlagsOnOffNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -92,7 +93,9 @@ public ReFlagsOnOffNodeModifier modify() { public static class ReFlagsOnOffNodeModifier { private final ReFlagsOnOffNode oldNode; private ReFlagsNode lhsReFlags; + @Nullable private Token minusToken; + @Nullable private ReFlagsNode rhsReFlags; public ReFlagsOnOffNodeModifier(ReFlagsOnOffNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReQuantifierNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReQuantifierNode.java index f0d5c5123724..f5bffe6cd9f9 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReQuantifierNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReQuantifierNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public ReQuantifierNodeModifier modify() { public static class ReQuantifierNodeModifier { private final ReQuantifierNode oldNode; private Node reBaseQuantifier; + @Nullable private Token nonGreedyChar; public ReQuantifierNodeModifier(ReQuantifierNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReUnicodeGeneralCategoryNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReUnicodeGeneralCategoryNode.java index 7253ea4f580d..c2746726dab7 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReUnicodeGeneralCategoryNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReUnicodeGeneralCategoryNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -83,6 +84,7 @@ public ReUnicodeGeneralCategoryNodeModifier modify() { */ public static class ReUnicodeGeneralCategoryNodeModifier { private final ReUnicodeGeneralCategoryNode oldNode; + @Nullable private Node categoryStart; private Node reUnicodeGeneralCategoryName; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordFieldNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordFieldNode.java index 98d67f8a5944..cd378d933179 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordFieldNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordFieldNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -115,10 +116,13 @@ public RecordFieldNodeModifier modify() { */ public static class RecordFieldNodeModifier { private final RecordFieldNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token readonlyKeyword; private Node typeName; private Token fieldName; + @Nullable private Token questionMarkToken; private Token semicolonToken; @@ -133,7 +137,7 @@ public RecordFieldNodeModifier(RecordFieldNode oldNode) { } public RecordFieldNodeModifier withMetadata( - MetadataNode metadata) { + @Nullable MetadataNode metadata) { this.metadata = metadata; return this; } @@ -159,7 +163,7 @@ public RecordFieldNodeModifier withFieldName( } public RecordFieldNodeModifier withQuestionMarkToken( - Token questionMarkToken) { + @Nullable Token questionMarkToken) { this.questionMarkToken = questionMarkToken; return this; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordFieldWithDefaultValueNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordFieldWithDefaultValueNode.java index 8ff1caa9f1d8..d3ceba9ba5ac 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordFieldWithDefaultValueNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordFieldWithDefaultValueNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -123,7 +124,9 @@ public RecordFieldWithDefaultValueNodeModifier modify() { */ public static class RecordFieldWithDefaultValueNodeModifier { private final RecordFieldWithDefaultValueNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token readonlyKeyword; private Node typeName; private Token fieldName; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordTypeDescriptorNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordTypeDescriptorNode.java index 729e88e9360b..13c52157f826 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordTypeDescriptorNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RecordTypeDescriptorNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -110,6 +111,7 @@ public static class RecordTypeDescriptorNodeModifier { private Token recordKeyword; private Token bodyStartDelimiter; private NodeList fields; + @Nullable private RecordRestDescriptorNode recordRestDescriptor; private Token bodyEndDelimiter; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RequiredParameterNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RequiredParameterNode.java index 3648dc2a6bf1..7b7bee653fdf 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RequiredParameterNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RequiredParameterNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -93,6 +94,7 @@ public static class RequiredParameterNodeModifier { private final RequiredParameterNode oldNode; private NodeList annotations; private Node typeName; + @Nullable private Token paramName; public RequiredParameterNodeModifier(RequiredParameterNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ResourcePathParameterNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ResourcePathParameterNode.java index 49b7c72a2d84..3edbc8320928 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ResourcePathParameterNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ResourcePathParameterNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -120,7 +121,9 @@ public static class ResourcePathParameterNodeModifier { private Token openBracketToken; private NodeList annotations; private TypeDescriptorNode typeDescriptor; + @Nullable private Token ellipsisToken; + @Nullable private Token paramName; private Token closeBracketToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RestParameterNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RestParameterNode.java index 9735c960c07f..a8d1eb4d56a7 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RestParameterNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RestParameterNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -102,6 +103,7 @@ public static class RestParameterNodeModifier { private NodeList annotations; private Node typeName; private Token ellipsisToken; + @Nullable private Token paramName; public RestParameterNodeModifier(RestParameterNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RetryStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RetryStatementNode.java index 5d1fb9281677..e322307c7c96 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RetryStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RetryStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -108,9 +109,12 @@ public RetryStatementNodeModifier modify() { public static class RetryStatementNodeModifier { private final RetryStatementNode oldNode; private Token retryKeyword; + @Nullable private TypeParameterNode typeParameter; + @Nullable private ParenthesizedArgList arguments; private StatementNode retryBody; + @Nullable private OnFailClauseNode onFailClause; public RetryStatementNodeModifier(RetryStatementNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReturnStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReturnStatementNode.java index d3970c8be64b..944988a93353 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReturnStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ReturnStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -92,6 +93,7 @@ public ReturnStatementNodeModifier modify() { public static class ReturnStatementNodeModifier { private final ReturnStatementNode oldNode; private Token returnKeyword; + @Nullable private ExpressionNode expression; private Token semicolonToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RollbackStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RollbackStatementNode.java index cd1980f43d6f..9f2426c17e0f 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RollbackStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/RollbackStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -92,6 +93,7 @@ public RollbackStatementNodeModifier modify() { public static class RollbackStatementNodeModifier { private final RollbackStatementNode oldNode; private Token rollbackKeyword; + @Nullable private ExpressionNode expression; private Token semicolon; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ServiceDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ServiceDeclarationNode.java index 66530ddcee29..8850c1f96d83 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ServiceDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/ServiceDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -155,9 +156,11 @@ public ServiceDeclarationNodeModifier modify() { */ public static class ServiceDeclarationNodeModifier { private final ServiceDeclarationNode oldNode; + @Nullable private MetadataNode metadata; private NodeList qualifiers; private Token serviceKeyword; + @Nullable private TypeDescriptorNode typeDescriptor; private NodeList absoluteResourcePath; private Token onKeyword; @@ -165,6 +168,7 @@ public static class ServiceDeclarationNodeModifier { private Token openBraceToken; private NodeList members; private Token closeBraceToken; + @Nullable private Token semicolonToken; public ServiceDeclarationNodeModifier(ServiceDeclarationNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/SpecificFieldNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/SpecificFieldNode.java index cf1cbf406e9b..b94fca45375a 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/SpecificFieldNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/SpecificFieldNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -99,9 +100,12 @@ public SpecificFieldNodeModifier modify() { */ public static class SpecificFieldNodeModifier { private final SpecificFieldNode oldNode; + @Nullable private Token readonlyKeyword; private Node fieldName; + @Nullable private Token colon; + @Nullable private ExpressionNode valueExpr; public SpecificFieldNodeModifier(SpecificFieldNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/StreamTypeDescriptorNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/StreamTypeDescriptorNode.java index 505c294a036e..f5f926decdd7 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/StreamTypeDescriptorNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/StreamTypeDescriptorNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public StreamTypeDescriptorNodeModifier modify() { public static class StreamTypeDescriptorNodeModifier { private final StreamTypeDescriptorNode oldNode; private Token streamKeywordToken; + @Nullable private Node streamTypeParamsNode; public StreamTypeDescriptorNodeModifier(StreamTypeDescriptorNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/StreamTypeParamsNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/StreamTypeParamsNode.java index 8487e5ee9219..d81ea895fd1c 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/StreamTypeParamsNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/StreamTypeParamsNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -109,7 +110,9 @@ public static class StreamTypeParamsNodeModifier { private final StreamTypeParamsNode oldNode; private Token ltToken; private Node leftTypeDescNode; + @Nullable private Token commaToken; + @Nullable private Node rightTypeDescNode; private Token gtToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/SyntaxTree.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/SyntaxTree.java index df67a6847339..f260be07f2ff 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/SyntaxTree.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/SyntaxTree.java @@ -24,6 +24,7 @@ import io.ballerina.tools.text.TextDocument; import io.ballerina.tools.text.TextDocumentChange; import io.ballerina.tools.text.TextDocuments; +import org.jetbrains.annotations.Nullable; /** * The {@code SyntaxTree} represents a parsed Ballerina source file. @@ -36,7 +37,7 @@ public class SyntaxTree { private TextDocument textDocument; - SyntaxTree(Node rootNode, TextDocument textDocument, String filePath, boolean clone) { + SyntaxTree(Node rootNode, @Nullable TextDocument textDocument, @Nullable String filePath, boolean clone) { this.rootNode = modifyWithMe(rootNode, clone); this.textDocument = textDocument; this.filePath = filePath; @@ -50,7 +51,7 @@ public static SyntaxTree from(TextDocument textDocument) { return from(textDocument, null); } - public static SyntaxTree from(TextDocument textDocument, String filePath) { + public static SyntaxTree from(TextDocument textDocument, @Nullable String filePath) { BallerinaParser parser = ParserFactory.getParser(textDocument); return new SyntaxTree(parser.parse().createUnlinkedFacade(), textDocument, filePath, false); diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TableConstructorExpressionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TableConstructorExpressionNode.java index 0a1e783a3464..7dda7897fcfa 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TableConstructorExpressionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TableConstructorExpressionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -108,6 +109,7 @@ public TableConstructorExpressionNodeModifier modify() { public static class TableConstructorExpressionNodeModifier { private final TableConstructorExpressionNode oldNode; private Token tableKeyword; + @Nullable private KeySpecifierNode keySpecifier; private Token openBracket; private SeparatedNodeList rows; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TableTypeDescriptorNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TableTypeDescriptorNode.java index 6650aeb0385b..285935f6fdfd 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TableTypeDescriptorNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TableTypeDescriptorNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -93,6 +94,7 @@ public static class TableTypeDescriptorNodeModifier { private final TableTypeDescriptorNode oldNode; private Token tableKeywordToken; private Node rowTypeParameterNode; + @Nullable private Node keyConstraintNode; public TableTypeDescriptorNodeModifier(TableTypeDescriptorNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TemplateExpressionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TemplateExpressionNode.java index 3e9f9483e31e..aecef43e22d9 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TemplateExpressionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TemplateExpressionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -101,6 +102,7 @@ public TemplateExpressionNodeModifier modify() { */ public static class TemplateExpressionNodeModifier { private final TemplateExpressionNode oldNode; + @Nullable private Token type; private Token startBacktick; private NodeList content; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TransactionStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TransactionStatementNode.java index dde94d24c423..ead5852ffc43 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TransactionStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TransactionStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -93,6 +94,7 @@ public static class TransactionStatementNodeModifier { private final TransactionStatementNode oldNode; private Token transactionKeyword; private BlockStatementNode blockStatement; + @Nullable private OnFailClauseNode onFailClause; public TransactionStatementNodeModifier(TransactionStatementNode oldNode) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TreeModifier.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TreeModifier.java index ec51bacffb8f..cbfd630dbfa5 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TreeModifier.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TreeModifier.java @@ -19,6 +19,7 @@ import io.ballerina.compiler.internal.parser.tree.STNode; import io.ballerina.compiler.internal.parser.tree.STNodeFactory; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.function.Function; @@ -3822,7 +3823,8 @@ private > N modifyGenericNodeList( return nodeListCreator.apply(stNodeList.createUnlinkedFacade()); } - protected T modifyToken(T token) { + @Nullable + protected T modifyToken(@Nullable T token) { if (token == null) { return null; } @@ -3830,7 +3832,8 @@ protected T modifyToken(T token) { return (T) token.apply(this); } - protected T modifyNode(T node) { + @Nullable + protected T modifyNode(@Nullable T node) { if (node == null) { return null; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TypeCastParamNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TypeCastParamNode.java index 52214a950288..908ea9be781d 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TypeCastParamNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TypeCastParamNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -84,6 +85,7 @@ public TypeCastParamNodeModifier modify() { public static class TypeCastParamNodeModifier { private final TypeCastParamNode oldNode; private NodeList annotations; + @Nullable private Node type; public TypeCastParamNodeModifier(TypeCastParamNode oldNode) { @@ -100,7 +102,7 @@ public TypeCastParamNodeModifier withAnnotations( } public TypeCastParamNodeModifier withType( - Node type) { + @Nullable Node type) { this.type = type; return this; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TypeDefinitionNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TypeDefinitionNode.java index fa40fe0352dd..f295e2e9fd71 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TypeDefinitionNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/TypeDefinitionNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -115,7 +116,9 @@ public TypeDefinitionNodeModifier modify() { */ public static class TypeDefinitionNodeModifier { private final TypeDefinitionNode oldNode; + @Nullable private MetadataNode metadata; + @Nullable private Token visibilityQualifier; private Token typeKeyword; private Token typeName; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/VariableDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/VariableDeclarationNode.java index d8e214e3fa43..0eb2cb8a5de3 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/VariableDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/VariableDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -116,9 +117,12 @@ public VariableDeclarationNodeModifier modify() { public static class VariableDeclarationNodeModifier { private final VariableDeclarationNode oldNode; private NodeList annotations; + @Nullable private Token finalKeyword; private TypedBindingPatternNode typedBindingPattern; + @Nullable private Token equalsToken; + @Nullable private ExpressionNode initializer; private Token semicolonToken; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/WhileStatementNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/WhileStatementNode.java index 27d6001f3358..b69f8b788311 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/WhileStatementNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/WhileStatementNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -102,6 +103,7 @@ public static class WhileStatementNodeModifier { private Token whileKeyword; private ExpressionNode condition; private BlockStatementNode whileBody; + @Nullable private OnFailClauseNode onFailClause; public WhileStatementNodeModifier(WhileStatementNode oldNode) { @@ -134,7 +136,7 @@ public WhileStatementNodeModifier withWhileBody( } public WhileStatementNodeModifier withOnFailClause( - OnFailClauseNode onFailClause) { + @Nullable OnFailClauseNode onFailClause) { this.onFailClause = onFailClause; return this; } diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/XMLNamespaceDeclarationNode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/XMLNamespaceDeclarationNode.java index 1ba831623a6f..687dcac8cac5 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/XMLNamespaceDeclarationNode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/syntax/tree/XMLNamespaceDeclarationNode.java @@ -18,6 +18,7 @@ package io.ballerina.compiler.syntax.tree; import io.ballerina.compiler.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -109,7 +110,9 @@ public static class XMLNamespaceDeclarationNodeModifier { private final XMLNamespaceDeclarationNode oldNode; private Token xmlnsKeyword; private ExpressionNode namespaceuri; + @Nullable private Token asKeyword; + @Nullable private IdentifierToken namespacePrefix; private Token semicolonToken; diff --git a/compiler/ballerina-parser/src/main/java/module-info.java b/compiler/ballerina-parser/src/main/java/module-info.java index 2d0455b39c5f..69b1553eeba0 100644 --- a/compiler/ballerina-parser/src/main/java/module-info.java +++ b/compiler/ballerina-parser/src/main/java/module-info.java @@ -1,5 +1,6 @@ module io.ballerina.parser { requires io.ballerina.tools.api; + requires static org.jetbrains.annotations; exports io.ballerina.compiler.syntax.tree; exports io.ballerina.compiler.internal.parser.tree to io.ballerina.lang; } diff --git a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/diagnostics/DiagnosticInfo.java b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/diagnostics/DiagnosticInfo.java index 47bf8ba5b203..51a8df4a0cee 100644 --- a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/diagnostics/DiagnosticInfo.java +++ b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/diagnostics/DiagnosticInfo.java @@ -17,6 +17,8 @@ */ package io.ballerina.tools.diagnostics; +import org.jetbrains.annotations.Nullable; + import java.util.Arrays; /** @@ -38,7 +40,7 @@ public class DiagnosticInfo { * @param messageFormat a pattern that can be formatted with the {@link java.text.MessageFormat} utility * @param severity the severity of the diagnostic */ - public DiagnosticInfo(String code, + public DiagnosticInfo(@Nullable String code, String messageFormat, DiagnosticSeverity severity) { this.code = code; diff --git a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineMap.java b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineMap.java index 281b0c52f401..ceb269a16462 100644 --- a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineMap.java +++ b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineMap.java @@ -17,6 +17,8 @@ */ package io.ballerina.tools.text; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -87,6 +89,7 @@ private void lineRangeCheck(int lineNo) { * @param position of the source text * @return the {@code TextLine} to which the given position belongs to */ + @Nullable private TextLine findLineFrom(int position) { // Check boundary conditions if (position == 0) { diff --git a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineRange.java b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineRange.java index 515c40c6050d..eea0eea823b1 100644 --- a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineRange.java +++ b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineRange.java @@ -17,6 +17,8 @@ */ package io.ballerina.tools.text; +import org.jetbrains.annotations.Nullable; + import java.util.Objects; /** @@ -35,7 +37,7 @@ private LineRange(String fileName, LinePosition startLine, LinePosition endLine) this.endLine = endLine; } - public static LineRange from(String fileName, LinePosition startLine, LinePosition endLine) { + public static LineRange from(@Nullable String fileName, LinePosition startLine, LinePosition endLine) { return new LineRange(fileName, startLine, endLine); } diff --git a/compiler/ballerina-tools-api/src/main/java/module-info.java b/compiler/ballerina-tools-api/src/main/java/module-info.java index af7ea5a777e8..657f0a8a952c 100644 --- a/compiler/ballerina-tools-api/src/main/java/module-info.java +++ b/compiler/ballerina-tools-api/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.tools.api { + requires static org.jetbrains.annotations; exports io.ballerina.tools.diagnostics; exports io.ballerina.tools.text; } diff --git a/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/ExternalNodeVisitorTarget.java b/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/ExternalNodeVisitorTarget.java index 6317f43f0777..a79ce6cd67c0 100644 --- a/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/ExternalNodeVisitorTarget.java +++ b/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/ExternalNodeVisitorTarget.java @@ -18,6 +18,7 @@ package io.ballerinalang.compiler.internal.treegen.targets.nodevisitor; import io.ballerinalang.compiler.internal.treegen.TreeGenConfig; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -52,6 +53,7 @@ protected String getClassName() { return EXTERNAL_NODE_VISITOR_CN; } + @Nullable @Override protected String getSuperClassName() { return null; diff --git a/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/InternalNodeTransformerTarget.java b/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/InternalNodeTransformerTarget.java index 4fa54eb4e1f5..5f47359ab908 100644 --- a/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/InternalNodeTransformerTarget.java +++ b/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/InternalNodeTransformerTarget.java @@ -18,6 +18,7 @@ package io.ballerinalang.compiler.internal.treegen.targets.nodevisitor; import io.ballerinalang.compiler.internal.treegen.TreeGenConfig; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -52,6 +53,7 @@ protected String getClassName() { return INTERNAL_NODE_TRANSFORMER_CN; } + @Nullable @Override protected String getSuperClassName() { return null; diff --git a/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/InternalNodeVisitorTarget.java b/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/InternalNodeVisitorTarget.java index 37920b25964b..a56e1b16bbde 100644 --- a/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/InternalNodeVisitorTarget.java +++ b/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/InternalNodeVisitorTarget.java @@ -18,6 +18,7 @@ package io.ballerinalang.compiler.internal.treegen.targets.nodevisitor; import io.ballerinalang.compiler.internal.treegen.TreeGenConfig; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -52,6 +53,7 @@ protected String getClassName() { return INTERNAL_NODE_VISITOR_CN; } + @Nullable @Override protected String getSuperClassName() { return null; diff --git a/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/NodeTransformerTarget.java b/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/NodeTransformerTarget.java index df98e024a15b..4d664f1afb62 100644 --- a/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/NodeTransformerTarget.java +++ b/compiler/ballerina-treegen/src/main/java/io/ballerinalang/compiler/internal/treegen/targets/nodevisitor/NodeTransformerTarget.java @@ -18,6 +18,7 @@ package io.ballerinalang.compiler.internal.treegen.targets.nodevisitor; import io.ballerinalang.compiler.internal.treegen.TreeGenConfig; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -52,6 +53,7 @@ protected String getClassName() { return NODE_TRANSFORMER_CN; } + @Nullable @Override protected String getSuperClassName() { return null; diff --git a/compiler/ballerina-treegen/src/main/java/module-info.java b/compiler/ballerina-treegen/src/main/java/module-info.java index 3ddb5a9ff2d2..b59bfe7a9d58 100644 --- a/compiler/ballerina-treegen/src/main/java/module-info.java +++ b/compiler/ballerina-treegen/src/main/java/module-info.java @@ -1,5 +1,6 @@ module io.ballerina.treegen { requires com.google.gson; requires compiler; + requires static org.jetbrains.annotations; exports io.ballerinalang.compiler.internal.treegen; } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 782f04a2a207..94eeef3bc337 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -70,6 +70,7 @@ javassistVersion="3.24.1-GA" javaxMailVersion="1.6.2" javaxTransactionApiVersion="1.3" javaxWsRsApiVersion="2.1.1" +jetbrainsAnnotationsVersion="24.1.0" jetbrainsKotlinStdlibCommonVersion="1.6.0" jetbrainsKotlinStdlibVersion="1.6.0" jknackHandlebarsVersion="4.0.6" @@ -200,6 +201,7 @@ javassist = { module = "org.javassist:javassist", version.ref = "javassistVersio javax-mail = { module = "com.sun.mail:javax.mail", version.ref = "javaxMailVersion"} javax-transaction-api = { module = "javax.transaction:javax.transaction-api", version.ref = "javaxTransactionApiVersion"} javax-ws-rs-api = { module = "javax.ws.rs:javax.ws.rs-api", version.ref = "javaxWsRsApiVersion"} +jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrainsAnnotationsVersion"} jetbrains-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "jetbrainsKotlinStdlibVersion"} jetbrains-kotlin-stdlib-common = { module = "org.jetbrains.kotlin:kotlin-stdlib-common", version.ref = "jetbrainsKotlinStdlibCommonVersion"} jknack-handlebars = { module = "com.github.jknack:handlebars", version.ref = "jknackHandlebarsVersion"} diff --git a/gradle/plugins/java-convention/src/main/groovy/javaProject.gradle b/gradle/plugins/java-convention/src/main/groovy/javaProject.gradle index 69af2baf2f55..d12d6842d683 100644 --- a/gradle/plugins/java-convention/src/main/groovy/javaProject.gradle +++ b/gradle/plugins/java-convention/src/main/groovy/javaProject.gradle @@ -29,6 +29,8 @@ dependencies { checkstyle libs.puppycrawl.checkstyle implementation libs.slf4j.api + compileOnly libs.jetbrains.annotations + testCompileOnly libs.jetbrains.annotations constraints { implementation libs.commons.codec diff --git a/langlib/jballerina.java/src/main/java/module-info.java b/langlib/jballerina.java/src/main/java/module-info.java index d6a071b2dfae..83c2bc4a629e 100644 --- a/langlib/jballerina.java/src/main/java/module-info.java +++ b/langlib/jballerina.java/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.java { requires io.ballerina.runtime; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.java; } diff --git a/langlib/jballerina.java/src/main/java/org/ballerinalang/langlib/java/JavaUtils.java b/langlib/jballerina.java/src/main/java/org/ballerinalang/langlib/java/JavaUtils.java index c6facb2eb1b2..f2129c557a3d 100644 --- a/langlib/jballerina.java/src/main/java/org/ballerinalang/langlib/java/JavaUtils.java +++ b/langlib/jballerina.java/src/main/java/org/ballerinalang/langlib/java/JavaUtils.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.internal.errors.ErrorReasons; +import org.jetbrains.annotations.Nullable; /** * This class contains various utility functions required to provide the 'ballerina/jballerina.java' module API. @@ -68,6 +69,7 @@ public static Object getClass(BString namebStr) { } } + @Nullable private static Class getPrimitiveTypeClass(String name) { return switch (name) { case booleanTypeName -> Boolean.TYPE; diff --git a/langlib/jballerina.java/src/main/java/org/ballerinalang/langlib/java/ToString.java b/langlib/jballerina.java/src/main/java/org/ballerinalang/langlib/java/ToString.java index d455106f83e6..07ed6aede5b3 100644 --- a/langlib/jballerina.java/src/main/java/org/ballerinalang/langlib/java/ToString.java +++ b/langlib/jballerina.java/src/main/java/org/ballerinalang/langlib/java/ToString.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BHandle; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; /** * This class contains the implementation of the "toString" ballerina function in ballerina/jballerina.java module. @@ -31,6 +32,7 @@ public final class ToString { private ToString() { } + @Nullable public static Object toString(BHandle value) { Object referredValue = value.getValue(); if (referredValue == null) { diff --git a/langlib/lang.__internal/src/main/java/module-info.java b/langlib/lang.__internal/src/main/java/module-info.java index 46219b8cbdf8..da89da81076f 100644 --- a/langlib/lang.__internal/src/main/java/module-info.java +++ b/langlib/lang.__internal/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.lang.internal { exports org.ballerinalang.langlib.internal; requires io.ballerina.runtime; + requires static org.jetbrains.annotations; } diff --git a/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/GetAttribute.java b/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/GetAttribute.java index a3eb1965488a..2535fa97174a 100644 --- a/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/GetAttribute.java +++ b/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/GetAttribute.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.values.BXmlQName; import io.ballerina.runtime.internal.errors.ErrorCodes; import io.ballerina.runtime.internal.errors.ErrorHelper; +import org.jetbrains.annotations.Nullable; import static io.ballerina.runtime.api.creators.ErrorCreator.createError; import static io.ballerina.runtime.internal.errors.ErrorReasons.XML_OPERATION_ERROR; @@ -38,6 +39,7 @@ public final class GetAttribute { private GetAttribute() { } + @Nullable public static Object getAttribute(BXml xmlVal, BString attrName, boolean optionalFiledAccess) { if (xmlVal.getNodeType() == XmlNodeType.SEQUENCE && xmlVal.isEmpty()) { if (!optionalFiledAccess) { diff --git a/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/GetElementNameNilLifting.java b/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/GetElementNameNilLifting.java index 4bf36582406c..15338bbbedfb 100644 --- a/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/GetElementNameNilLifting.java +++ b/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/GetElementNameNilLifting.java @@ -19,6 +19,7 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BXml; +import org.jetbrains.annotations.Nullable; import static io.ballerina.runtime.api.creators.ErrorCreator.createError; import static io.ballerina.runtime.internal.errors.ErrorReasons.XML_OPERATION_ERROR; @@ -33,6 +34,7 @@ public final class GetElementNameNilLifting { private GetElementNameNilLifting() { } + @Nullable public static Object getElementNameNilLifting(BXml xmlVal) { if (IsElement.isElement(xmlVal)) { String elementName = xmlVal.getElementName(); diff --git a/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/SelectDescendants.java b/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/SelectDescendants.java index 01ef799f432c..da0d7a6dcef3 100644 --- a/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/SelectDescendants.java +++ b/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/SelectDescendants.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorHelper; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -38,6 +39,7 @@ public final class SelectDescendants { private SelectDescendants() { } + @Nullable public static BXml selectDescendants(BXml xml, BString[] qnames) { try { List qnameList = new ArrayList<>(); diff --git a/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/WorkerChannels.java b/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/WorkerChannels.java index bcde4ab88c56..0c7a8f50fefc 100644 --- a/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/WorkerChannels.java +++ b/langlib/lang.__internal/src/main/java/org/ballerinalang/langlib/internal/WorkerChannels.java @@ -22,6 +22,7 @@ import io.ballerina.runtime.internal.scheduling.Strand; import io.ballerina.runtime.internal.scheduling.WorkerDataChannel; import io.ballerina.runtime.internal.values.ChannelDetails; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -50,6 +51,7 @@ public static void autoClose(BString[] channelIds) { } } + @Nullable private static String getMatchingChannelName(String channelId, Strand currentStrand) { String channelName = null; for (ChannelDetails channelDetail : currentStrand.channelDetails) { diff --git a/langlib/lang.array/src/main/java/module-info.java b/langlib/lang.array/src/main/java/module-info.java index 627916960435..ac0e60fd896c 100644 --- a/langlib/lang.array/src/main/java/module-info.java +++ b/langlib/lang.array/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.lang.array { requires io.ballerina.runtime; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.array; } diff --git a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/IndexOf.java b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/IndexOf.java index 4e5ecd691ad4..39882ec37f58 100644 --- a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/IndexOf.java +++ b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/IndexOf.java @@ -22,6 +22,7 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.internal.TypeChecker; import org.ballerinalang.langlib.array.utils.GetFunction; +import org.jetbrains.annotations.Nullable; import static org.ballerinalang.langlib.array.utils.ArrayUtils.getElementAccessFunction; @@ -42,6 +43,7 @@ public final class IndexOf { private IndexOf() { } + @Nullable public static Object indexOf(BArray arr, Object val, long startIndex) { Type arrType = arr.getType(); int size = arr.size(); diff --git a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/LastIndexOf.java b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/LastIndexOf.java index 63650f6e08c2..a27eb48a15f2 100644 --- a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/LastIndexOf.java +++ b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/LastIndexOf.java @@ -22,6 +22,7 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.internal.TypeChecker; import org.ballerinalang.langlib.array.utils.GetFunction; +import org.jetbrains.annotations.Nullable; import static org.ballerinalang.langlib.array.utils.ArrayUtils.getElementAccessFunction; @@ -42,6 +43,7 @@ public final class LastIndexOf { private LastIndexOf() { } + @Nullable public static Object lastIndexOf(BArray arr, Object val, long startIndex) { Type arrType = arr.getType(); int size = arr.size(); diff --git a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/Next.java b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/Next.java index 55a99e2abf32..d7009d80ccf1 100644 --- a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/Next.java +++ b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/Next.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BIterator; import io.ballerina.runtime.api.values.BObject; +import org.jetbrains.annotations.Nullable; /** * Native implementation of lang.array.ArrayIterator:next(). @@ -36,6 +37,7 @@ private Next() { } //TODO: refactor hard coded values + @Nullable public static Object next(BObject m) { BIterator arrIterator = (BIterator) m.getNativeData("&iterator&"); BArray arr = (BArray) m.get(StringUtils.fromString("m")); diff --git a/langlib/lang.error/src/main/java/module-info.java b/langlib/lang.error/src/main/java/module-info.java index 6708d4cb45dc..b00bd2f66800 100644 --- a/langlib/lang.error/src/main/java/module-info.java +++ b/langlib/lang.error/src/main/java/module-info.java @@ -1,5 +1,6 @@ module io.ballerina.lang.error { requires io.ballerina.runtime; requires io.ballerina.identifier; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.error; } diff --git a/langlib/lang.error/src/main/java/org/ballerinalang/langlib/error/StackTrace.java b/langlib/lang.error/src/main/java/org/ballerinalang/langlib/error/StackTrace.java index d56787fd387e..aa22a44e71cf 100644 --- a/langlib/lang.error/src/main/java/org/ballerinalang/langlib/error/StackTrace.java +++ b/langlib/lang.error/src/main/java/org/ballerinalang/langlib/error/StackTrace.java @@ -37,6 +37,7 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.HashMap; @@ -138,6 +139,7 @@ public String stringValue(BLink parent) { return "object " + type.toString(); } + @Nullable @Override public String expressionStringValue(BLink parent) { return null; @@ -171,6 +173,7 @@ public double getFloatValue(BString fieldName) { return 0; } + @Nullable @Override public BString getStringValue(BString fieldName) { return null; @@ -181,16 +184,19 @@ public boolean getBooleanValue(BString fieldName) { return false; } + @Nullable @Override public BMap getMapValue(BString fieldName) { return null; } + @Nullable @Override public BObject getObjectValue(BString fieldName) { return null; } + @Nullable @Override public BArray getArrayValue(BString fieldName) { return null; @@ -201,11 +207,13 @@ public void addNativeData(String key, Object data) { } + @Nullable @Override public Object getNativeData(String key) { return null; } + @Nullable @Override public HashMap getNativeData() { return null; @@ -216,11 +224,13 @@ public void set(BString fieldName, Object value) { throw ErrorCreator.createError(StringUtils.fromString("No such field or method: callStack")); } + @Nullable @Override public Object copy(Map refs) { return null; } + @Nullable @Override public Object frozenCopy(Map refs) { return null; diff --git a/langlib/lang.map/src/main/java/module-info.java b/langlib/lang.map/src/main/java/module-info.java index d8748c811b87..ddcc1769ef29 100644 --- a/langlib/lang.map/src/main/java/module-info.java +++ b/langlib/lang.map/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.lang.map { requires io.ballerina.runtime; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.map; } diff --git a/langlib/lang.map/src/main/java/org/ballerinalang/langlib/map/Next.java b/langlib/lang.map/src/main/java/org/ballerinalang/langlib/map/Next.java index aa1eb733e2fb..6e6b503dd50f 100644 --- a/langlib/lang.map/src/main/java/org/ballerinalang/langlib/map/Next.java +++ b/langlib/lang.map/src/main/java/org/ballerinalang/langlib/map/Next.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.values.BIterator; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; +import org.jetbrains.annotations.Nullable; /** * Native implementation of lang.map.MapIterator:next(). @@ -44,6 +45,7 @@ private Next() { } //TODO: refactor hard coded values + @Nullable public static Object next(BObject m) { BIterator mapIterator = (BIterator) m.getNativeData("&iterator&"); BMap bMap = (BMap) m.get(StringUtils.fromString("m")); diff --git a/langlib/lang.regexp/src/main/java/module-info.java b/langlib/lang.regexp/src/main/java/module-info.java index 70f694acb764..9754c56a4b0e 100644 --- a/langlib/lang.regexp/src/main/java/module-info.java +++ b/langlib/lang.regexp/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.lang.regexp { requires io.ballerina.runtime; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.regexp; } diff --git a/langlib/lang.regexp/src/main/java/org/ballerinalang/langlib/regexp/Find.java b/langlib/lang.regexp/src/main/java/org/ballerinalang/langlib/regexp/Find.java index cafe813faaf0..4c9e3b8c348b 100644 --- a/langlib/lang.regexp/src/main/java/org/ballerinalang/langlib/regexp/Find.java +++ b/langlib/lang.regexp/src/main/java/org/ballerinalang/langlib/regexp/Find.java @@ -22,6 +22,7 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BRegexpValue; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; @@ -40,6 +41,7 @@ public final class Find { private Find() { } + @Nullable public static BArray find(BRegexpValue regExp, BString str, long startIndex) { checkIndexWithinRange(str, startIndex); int[] surrogates = getSurrogatePositions(str); @@ -51,6 +53,7 @@ public static BArray find(BRegexpValue regExp, BString str, long startIndex) { return null; } + @Nullable public static BArray findGroups(BRegexpValue regExp, BString str, long startIndex) { checkIndexWithinRange(str, startIndex); int[] surrogates = getSurrogatePositions(str); @@ -74,6 +77,7 @@ public static BArray findGroups(BRegexpValue regExp, BString str, long startInde return resultArray; } + @Nullable public static BArray findAll(BRegexpValue regExp, BString str, long startIndex) { checkIndexWithinRange(str, startIndex); Matcher matcher = RegexUtil.getMatcher(regExp, str); @@ -90,6 +94,7 @@ public static BArray findAll(BRegexpValue regExp, BString str, long startIndex) return resultArray; } + @Nullable public static BArray findAllGroups(BRegexpValue regExp, BString str, long startIndex) { checkIndexWithinRange(str, startIndex); Matcher matcher = RegexUtil.getMatcher(regExp, str); diff --git a/langlib/lang.regexp/src/main/java/org/ballerinalang/langlib/regexp/Matches.java b/langlib/lang.regexp/src/main/java/org/ballerinalang/langlib/regexp/Matches.java index 0b70603e8a1b..1d7997f8da50 100644 --- a/langlib/lang.regexp/src/main/java/org/ballerinalang/langlib/regexp/Matches.java +++ b/langlib/lang.regexp/src/main/java/org/ballerinalang/langlib/regexp/Matches.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BRegexpValue; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; @@ -38,6 +39,7 @@ public final class Matches { private Matches() { } + @Nullable public static BArray matchAt(BRegexpValue regExp, BString str, int startIndex) { checkIndexWithinRange(str, startIndex); Matcher matcher = RegexUtil.getMatcher(regExp, str); @@ -50,6 +52,7 @@ public static BArray matchAt(BRegexpValue regExp, BString str, int startIndex) { return null; } + @Nullable public static BArray matchGroupsAt(BRegexpValue regExp, BString str, int startIndex) { checkIndexWithinRange(str, startIndex); Matcher matcher = RegexUtil.getMatcher(regExp, str); diff --git a/langlib/lang.string/src/main/java/module-info.java b/langlib/lang.string/src/main/java/module-info.java index 0770c2f5ec43..94080c48f0d9 100644 --- a/langlib/lang.string/src/main/java/module-info.java +++ b/langlib/lang.string/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.lang.string { requires io.ballerina.runtime; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.string; } diff --git a/langlib/lang.string/src/main/java/org/ballerinalang/langlib/string/Next.java b/langlib/lang.string/src/main/java/org/ballerinalang/langlib/string/Next.java index c260ed05f541..dd7057315c59 100644 --- a/langlib/lang.string/src/main/java/org/ballerinalang/langlib/string/Next.java +++ b/langlib/lang.string/src/main/java/org/ballerinalang/langlib/string/Next.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.values.BIterator; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; /** * Native implementation of lang.string.StringIterator:next(). @@ -36,6 +37,7 @@ private Next() { } //TODO: refactor hard coded values + @Nullable public static Object next(BObject stringObject) { BIterator charIterator = (BIterator) stringObject.getNativeData("&iterator&"); if (charIterator == null) { diff --git a/langlib/lang.table/src/main/java/module-info.java b/langlib/lang.table/src/main/java/module-info.java index 85230c4bf4b9..f71c2b1c584c 100644 --- a/langlib/lang.table/src/main/java/module-info.java +++ b/langlib/lang.table/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.lang.table { requires io.ballerina.runtime; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.table; } diff --git a/langlib/lang.table/src/main/java/org/ballerinalang/langlib/table/Next.java b/langlib/lang.table/src/main/java/org/ballerinalang/langlib/table/Next.java index 9920b5f8618b..3849f12458d3 100644 --- a/langlib/lang.table/src/main/java/org/ballerinalang/langlib/table/Next.java +++ b/langlib/lang.table/src/main/java/org/ballerinalang/langlib/table/Next.java @@ -30,6 +30,7 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTable; import io.ballerina.runtime.internal.TypeChecker; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -51,6 +52,7 @@ private Next() { } //TODO: refactor hard coded values + @Nullable public static Object next(BObject t) { BIterator tableIterator = (BIterator) t.getNativeData("&iterator&"); BTable table = (BTable) t.get(StringUtils.fromString("t")); diff --git a/langlib/lang.typedesc/src/main/java/module-info.java b/langlib/lang.typedesc/src/main/java/module-info.java index 7418233b8c75..a46d1544a432 100644 --- a/langlib/lang.typedesc/src/main/java/module-info.java +++ b/langlib/lang.typedesc/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.lang.typedesc { requires io.ballerina.runtime; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.typedesc; } diff --git a/langlib/lang.typedesc/src/main/java/org/ballerinalang/langlib/typedesc/TypeIds.java b/langlib/lang.typedesc/src/main/java/org/ballerinalang/langlib/typedesc/TypeIds.java index 63c2e305cc52..8d28634ce588 100644 --- a/langlib/lang.typedesc/src/main/java/org/ballerinalang/langlib/typedesc/TypeIds.java +++ b/langlib/lang.typedesc/src/main/java/org/ballerinalang/langlib/typedesc/TypeIds.java @@ -35,6 +35,7 @@ import io.ballerina.runtime.internal.types.BObjectType; import io.ballerina.runtime.internal.types.BTypeIdSet; import io.ballerina.runtime.internal.types.BTypeReferenceType; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -63,6 +64,7 @@ public final class TypeIds { private TypeIds() { } + @Nullable public static Object typeIds(BTypedesc t, boolean primaryOnly) { Type describingType = t.getDescribingType(); BTypeIdSet typeIdSet = getTypeIdSetForType(describingType); @@ -84,6 +86,7 @@ public static Object typeIds(BTypedesc t, boolean primaryOnly) { return arrayValue; } + @Nullable private static BTypeIdSet getTypeIdSetForType(Type describingType) { BTypeIdSet typeIdSet; switch (describingType.getTag()) { diff --git a/langlib/lang.value/src/main/java/module-info.java b/langlib/lang.value/src/main/java/module-info.java index dcae5b19eee9..4ab03b9ffccf 100644 --- a/langlib/lang.value/src/main/java/module-info.java +++ b/langlib/lang.value/src/main/java/module-info.java @@ -1,4 +1,5 @@ module io.ballerina.lang.value { requires io.ballerina.runtime; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.value; } diff --git a/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromBalString.java b/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromBalString.java index aaa7590fe3d6..512981cd4c67 100644 --- a/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromBalString.java +++ b/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromBalString.java @@ -22,6 +22,7 @@ import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; +import org.jetbrains.annotations.Nullable; import static io.ballerina.runtime.api.creators.ErrorCreator.createError; import static io.ballerina.runtime.internal.errors.ErrorReasons.FROM_BAL_STRING_ERROR; @@ -36,6 +37,7 @@ public final class FromBalString { private FromBalString() { } + @Nullable public static Object fromBalString(BString value) { String str = value.getValue(); if (str.equals("null")) { diff --git a/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonDecimalString.java b/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonDecimalString.java index 08c1f3d0789a..1828ac91d7c5 100644 --- a/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonDecimalString.java +++ b/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonDecimalString.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.internal.JsonParser; +import org.jetbrains.annotations.Nullable; import java.io.StringReader; @@ -37,6 +38,7 @@ public final class FromJsonDecimalString { private FromJsonDecimalString() { } + @Nullable public static Object fromJsonDecimalString(BString value) { String str = value.getValue(); diff --git a/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonFloatString.java b/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonFloatString.java index 2bd36a02060f..efc1292910e7 100644 --- a/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonFloatString.java +++ b/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonFloatString.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.internal.JsonParser; +import org.jetbrains.annotations.Nullable; import java.io.StringReader; @@ -37,6 +38,7 @@ public final class FromJsonFloatString { private FromJsonFloatString() { } + @Nullable public static Object fromJsonFloatString(BString value) { String str = value.getValue(); diff --git a/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonString.java b/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonString.java index 136afb309b2f..06dd00cd6f2d 100644 --- a/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonString.java +++ b/langlib/lang.value/src/main/java/org/ballerinalang/langlib/value/FromJsonString.java @@ -23,6 +23,7 @@ import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.internal.JsonParser; +import org.jetbrains.annotations.Nullable; /** * Parse a string in JSON format and return the value that it represents. @@ -34,6 +35,7 @@ public final class FromJsonString { private FromJsonString() { } + @Nullable public static Object fromJsonString(BString value) { String str = value.getValue(); diff --git a/langlib/lang.xml/src/main/java/module-info.java b/langlib/lang.xml/src/main/java/module-info.java index 57e2ace676fd..e3264c012b1c 100644 --- a/langlib/lang.xml/src/main/java/module-info.java +++ b/langlib/lang.xml/src/main/java/module-info.java @@ -4,5 +4,6 @@ requires axiom.api; requires io.ballerina.lang.internal; requires java.xml; + requires static org.jetbrains.annotations; exports org.ballerinalang.langlib.xml; } diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Copy.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Copy.java index 30a74c8644ab..30e3cd0a9473 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Copy.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Copy.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; @@ -40,6 +41,7 @@ public final class Copy { private Copy() { } + @Nullable public static BXml copy(Strand strand, BXml xml) { try { return (BXml) xml.copy(new HashMap<>()); diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Elements.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Elements.java index 70f659ec7fe3..fd6e13eb9ee9 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Elements.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Elements.java @@ -23,6 +23,7 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorHelper; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -45,6 +46,7 @@ public final class Elements { private Elements() { } + @Nullable public static BXml elements(BXml xml, Object name) { try { if (name instanceof BString bString) { diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetElementName.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetElementName.java index 26ebab4ebef8..59e72406d869 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetElementName.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetElementName.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; /** * Get the fully qualified name of the element as a string. @@ -40,6 +41,7 @@ public final class GetElementName { private GetElementName() { } + @Nullable public static String getElementName(Strand strand, BXml xml) { try { return xml.getElementName(); diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetItemType.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetItemType.java index 3423cf8a159f..7c45a043e8c7 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetItemType.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetItemType.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; /** * Get the type of a XML as a string. If the xml is singleton, type can be one of @@ -41,6 +42,7 @@ public final class GetItemType { private GetItemType() { } + @Nullable public static Object getItemType(Strand strand, BXml xml) { try { return xml.getItemType(); diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetName.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetName.java index bd6b72a24221..a3a47cbd541f 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetName.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetName.java @@ -22,6 +22,7 @@ import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorCodes; import io.ballerina.runtime.internal.errors.ErrorHelper; +import org.jetbrains.annotations.Nullable; /** * Returns the string giving the expanded name of provided xml element. @@ -42,6 +43,7 @@ public final class GetName { private GetName() { } + @Nullable public static BString getName(BXml xmlVal) { if (!IsElement.isElement(xmlVal)) { throw ErrorHelper.getRuntimeException(ErrorCodes.XML_FUNC_TYPE_ERROR, "getName", "element"); diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetTextValue.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetTextValue.java index 21e076262fdb..51baeb233415 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetTextValue.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/GetTextValue.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; /** * Get the text value of a XML. @@ -40,6 +41,7 @@ public final class GetTextValue { private GetTextValue() { } + @Nullable public static String getTextValue(Strand strand, BXml xml) { try { return xml.getTextValue(); diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Map.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Map.java index 65bb7b66390f..a74a96288955 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Map.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Map.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.scheduling.AsyncUtils; import io.ballerina.runtime.internal.scheduling.Scheduler; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -54,6 +55,7 @@ public final class Map { private Map() { } + @Nullable public static BXml map(BXml x, BFunctionPointer func) { if (x.isSingleton()) { func.asyncCall(new Object[]{x, true}, METADATA); diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Next.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Next.java index b5a029a1b97d..7329346d7ca8 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Next.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Next.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.values.BIterator; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BXml; +import org.jetbrains.annotations.Nullable; /** * Native implementation of lang.xml.XMLIterator:next(). @@ -44,6 +45,7 @@ private Next() { } //TODO: refactor hard coded values + @Nullable public static Object next(BObject m) { BIterator xmlIterator = (BIterator) m.getNativeData("&iterator&"); BXml bXml = (BXml) m.get(StringUtils.fromString("m")); diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Select.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Select.java index 1d289fe2ab25..31af91146519 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Select.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Select.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.scheduling.Strand; +import org.jetbrains.annotations.Nullable; /** * Get all the elements-type items in the given sequence, that matches a given qualified name. @@ -41,6 +42,7 @@ public final class Select { private Select() { } + @Nullable public static BXml select(Strand strand, BXml xml, String qname) { try { return xml.elements(qname); diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/SelectDescendants.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/SelectDescendants.java index e3779ba7d8db..0cbf2c6b4a73 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/SelectDescendants.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/SelectDescendants.java @@ -23,6 +23,7 @@ import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.scheduling.Strand; import org.ballerinalang.langlib.xml.utils.XmlUtils; +import org.jetbrains.annotations.Nullable; /** * Searches in children recursively for elements matching the name and returns a sequence containing them all. @@ -44,6 +45,7 @@ public final class SelectDescendants { private SelectDescendants() { } + @Nullable public static BXml selectDescendants(Strand strand, BXml xml, BArray qnames) { try { // todo: this need to support list of qnames. diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Slice.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Slice.java index d9993fe97fc4..86c66791e89d 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Slice.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Slice.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorHelper; +import org.jetbrains.annotations.Nullable; /** * Slice and return a subsequence of the an XML sequence. @@ -40,6 +41,7 @@ public final class Slice { private Slice() { } + @Nullable public static BXml slice(BXml xml, long startIndex, long endIndex) { try { return xml.slice(startIndex, endIndex); diff --git a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Strip.java b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Strip.java index 71732d864b0d..8f6230acdeef 100644 --- a/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Strip.java +++ b/langlib/lang.xml/src/main/java/org/ballerinalang/langlib/xml/Strip.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.values.BXml; import io.ballerina.runtime.internal.errors.ErrorHelper; +import org.jetbrains.annotations.Nullable; /** * Strips the insignificant parts of the an xml value. @@ -43,6 +44,7 @@ public final class Strip { private Strip() { } + @Nullable public static BXml strip(BXml xml) { try { return xml.strip(); diff --git a/language-server/modules/langserver-commons/src/main/java/module-info.java b/language-server/modules/langserver-commons/src/main/java/module-info.java index 1efde23ddb0f..5745ffafd043 100644 --- a/language-server/modules/langserver-commons/src/main/java/module-info.java +++ b/language-server/modules/langserver-commons/src/main/java/module-info.java @@ -6,6 +6,7 @@ requires org.eclipse.lsp4j.jsonrpc; requires com.google.gson; requires io.ballerina.toml; + requires static org.jetbrains.annotations; exports org.ballerinalang.langserver.commons; exports org.ballerinalang.langserver.commons.client; exports org.ballerinalang.langserver.commons.service.spi; diff --git a/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/SignatureContext.java b/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/SignatureContext.java index 8eda6857eb4c..3efccefed54d 100644 --- a/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/SignatureContext.java +++ b/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/SignatureContext.java @@ -19,6 +19,7 @@ import io.ballerina.compiler.syntax.tree.NonTerminalNode; import org.eclipse.lsp4j.SignatureHelpCapabilities; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -42,7 +43,7 @@ public interface SignatureContext extends PositionedOperationContext { * * @param node {@link NonTerminalNode} at the cursor position */ - void setNodeAtCursor(NonTerminalNode node); + void setNodeAtCursor(@Nullable NonTerminalNode node); /** * Get the node at the signature request triggered cursor position. diff --git a/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/completion/spi/BallerinaCompletionProvider.java b/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/completion/spi/BallerinaCompletionProvider.java index c5a1a2cd4d40..48362bf3c296 100644 --- a/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/completion/spi/BallerinaCompletionProvider.java +++ b/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/completion/spi/BallerinaCompletionProvider.java @@ -21,6 +21,7 @@ import org.ballerinalang.langserver.commons.BallerinaCompletionContext; import org.ballerinalang.langserver.commons.completion.LSCompletionException; import org.ballerinalang.langserver.commons.completion.LSCompletionItem; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -50,7 +51,8 @@ enum Precedence { * @return {@link List} List of calculated Completion Items * @throws LSCompletionException when completion fails */ - List getCompletions(BallerinaCompletionContext context, T node) throws LSCompletionException; + List getCompletions(BallerinaCompletionContext context, + @Nullable T node) throws LSCompletionException; /** * Sort a given list of completion Items. diff --git a/language-server/modules/langserver-core/src/main/java/module-info.java b/language-server/modules/langserver-core/src/main/java/module-info.java index a2ad981981ed..29fb4f08b170 100644 --- a/language-server/modules/langserver-core/src/main/java/module-info.java +++ b/language-server/modules/langserver-core/src/main/java/module-info.java @@ -42,4 +42,5 @@ requires io.ballerina.syntaxapicallsgen; requires io.ballerina.central.client; requires java.management; + requires static org.jetbrains.annotations; } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSClientCapabilitiesImpl.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSClientCapabilitiesImpl.java index 4c4d495560f0..4e77f2360476 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSClientCapabilitiesImpl.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSClientCapabilitiesImpl.java @@ -21,6 +21,7 @@ import org.ballerinalang.langserver.commons.registration.BallerinaClientCapability; import org.eclipse.lsp4j.TextDocumentClientCapabilities; import org.eclipse.lsp4j.WorkspaceClientCapabilities; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -44,8 +45,8 @@ public class LSClientCapabilitiesImpl implements LSClientCapabilities { LSClientCapabilitiesImpl(TextDocumentClientCapabilities textDocCapabilities, WorkspaceClientCapabilities workspaceCapabilities, - Map experimentalClientCapabilities, - Map initializationOptionsMap) { + @Nullable Map experimentalClientCapabilities, + @Nullable Map initializationOptionsMap) { this.textDocCapabilities = (textDocCapabilities != null) ? textDocCapabilities : new TextDocumentClientCapabilities(); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSClientLogger.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSClientLogger.java index 3cb726a1a7cc..5981a023062e 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSClientLogger.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSClientLogger.java @@ -26,6 +26,7 @@ import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.TextDocumentIdentifier; import org.eclipse.lsp4j.services.LanguageClient; +import org.jetbrains.annotations.Nullable; import java.io.ByteArrayOutputStream; import java.io.PrintStream; @@ -85,8 +86,9 @@ public void notifyUser(String operation, Throwable error) { * @param identifier text document * @param pos pos */ - public void logError(LSOperation operation, String message, Throwable error, TextDocumentIdentifier identifier, - Position... pos) { + public void logError( + @Nullable LSOperation operation, String message, Throwable error, + @Nullable TextDocumentIdentifier identifier, Position... pos) { if (!this.isInitializedOnce || this.languageClient == null) { return; } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSPackageLoader.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSPackageLoader.java index 73ef8ab0c2e0..95f1149c2a7a 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSPackageLoader.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/LSPackageLoader.java @@ -46,6 +46,7 @@ import org.eclipse.lsp4j.WorkDoneProgressEnd; import org.eclipse.lsp4j.WorkDoneProgressReport; import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Names; import java.nio.file.Path; @@ -366,7 +367,7 @@ public static class ModuleInfo { private final List listenerMetaData = new ArrayList<>(); - public ModuleInfo(PackageOrg packageOrg, PackageName packageName, PackageVersion version, Path path) { + public ModuleInfo(PackageOrg packageOrg, PackageName packageName, PackageVersion version, @Nullable Path path) { this.packageOrg = packageOrg; this.packageName = packageName; this.packageVersion = version; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/DiagBasedPositionDetailsImpl.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/DiagBasedPositionDetailsImpl.java index 579c994a5d53..86011f659fac 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/DiagBasedPositionDetailsImpl.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/DiagBasedPositionDetailsImpl.java @@ -20,6 +20,7 @@ import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticProperty; import org.ballerinalang.langserver.commons.codeaction.spi.DiagBasedPositionDetails; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; @@ -45,7 +46,7 @@ private DiagBasedPositionDetailsImpl(NonTerminalNode matchedNode, } public static DiagBasedPositionDetailsImpl from(NonTerminalNode matchedNode, - Symbol matchedSymbol, + @Nullable Symbol matchedSymbol, Diagnostic diagnostic) { return new DiagBasedPositionDetailsImpl(matchedNode, matchedSymbol, diagnostic); } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/RangeBasedPositionDetailsImpl.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/RangeBasedPositionDetailsImpl.java index c780013411b2..f28887e6af39 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/RangeBasedPositionDetailsImpl.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/RangeBasedPositionDetailsImpl.java @@ -18,6 +18,7 @@ import io.ballerina.compiler.api.symbols.TypeSymbol; import io.ballerina.compiler.syntax.tree.NonTerminalNode; import org.ballerinalang.langserver.commons.codeaction.spi.RangeBasedPositionDetails; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -103,17 +104,18 @@ public static class PositionDetailsBuilder { private PositionDetailsBuilder() { } - public PositionDetailsBuilder setDocumentableNode(NonTerminalNode documentableNode) { + public PositionDetailsBuilder setDocumentableNode(@Nullable NonTerminalNode documentableNode) { this.documentableNode = documentableNode; return this; } - public PositionDetailsBuilder setEnclosingDocumentableNode(NonTerminalNode enclosingDocumentableNode) { + public PositionDetailsBuilder setEnclosingDocumentableNode( + @Nullable NonTerminalNode enclosingDocumentableNode) { this.enclosingDocumentableNode = enclosingDocumentableNode; return this; } - public PositionDetailsBuilder setStatementNode(NonTerminalNode statementNode) { + public PositionDetailsBuilder setStatementNode(@Nullable NonTerminalNode statementNode) { this.statementNode = statementNode; return this; } @@ -128,7 +130,7 @@ public PositionDetailsBuilder setCodeActionNode(NonTerminalNode codeActionNode) return this; } - public PositionDetailsBuilder setTopLevelNodeType(TypeSymbol topLevelNodeType) { + public PositionDetailsBuilder setTopLevelNodeType(@Nullable TypeSymbol topLevelNodeType) { this.topLevelNodeType = topLevelNodeType; return this; } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/ScopedSymbolFinder.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/ScopedSymbolFinder.java index 3d41f81852ed..b72975a2e9be 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/ScopedSymbolFinder.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/ScopedSymbolFinder.java @@ -38,6 +38,7 @@ import org.ballerinalang.langserver.common.utils.PositionUtil; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -54,6 +55,7 @@ */ public class ScopedSymbolFinder extends NodeVisitor { private final Range range; + @Nullable private LinePosition currentIdentifierPos; private NonTerminalNode currentNode; private static final Map, Method> SCOPED_NODE_TO_VISIT_METHOD = Arrays.stream( @@ -161,6 +163,7 @@ private void visitScopedNodeMethod(Node node) { } } + @Nullable private LinePosition nameRefPosition(NameReferenceNode nameRef) { if (nameRef.kind() == SyntaxKind.QUALIFIED_NAME_REFERENCE) { QualifiedNameReferenceNode qualifiedNameRef = (QualifiedNameReferenceNode) nameRef; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java index 3fc63e9abbb4..6054520d2c45 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java @@ -44,6 +44,7 @@ import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -225,6 +226,7 @@ public String getName() { return NAME; } + @Nullable private Node getStatementNode(Node node) { Node statementNode = node; while (statementNode != null && !(statementNode instanceof StatementNode) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/changetype/ChangeParameterTypeCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/changetype/ChangeParameterTypeCodeAction.java index 8e14858509db..e65863fcb77a 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/changetype/ChangeParameterTypeCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/changetype/ChangeParameterTypeCodeAction.java @@ -44,6 +44,7 @@ import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -152,6 +153,7 @@ public String getName() { return NAME; } + @Nullable private VariableDeclarationNode getVariableDeclarationNode(NonTerminalNode node) { while (node != null && node.kind() != SyntaxKind.LOCAL_VAR_DECL) { node = node.parent(); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/docs/DocAttachmentInfo.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/docs/DocAttachmentInfo.java index 151b5141d6a2..5dd70d06fe5b 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/docs/DocAttachmentInfo.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/docs/DocAttachmentInfo.java @@ -18,6 +18,7 @@ import io.ballerina.compiler.api.symbols.Documentation; import org.ballerinalang.langserver.common.utils.CommonUtil; import org.eclipse.lsp4j.Position; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Collections; @@ -41,8 +42,8 @@ public class DocAttachmentInfo implements Documentation { private final Position docStart; private final String padding; - public DocAttachmentInfo(String description, LinkedHashMap parameters, String returnDesc, - String deprecatedDesc, Position docStart, String padding) { + public DocAttachmentInfo(String description, LinkedHashMap parameters, @Nullable String returnDesc, + @Nullable String deprecatedDesc, Position docStart, String padding) { this.description = description; this.parameters = parameters; this.returnDesc = returnDesc; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/docs/DocumentationGenerator.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/docs/DocumentationGenerator.java index 5bc3f59752d1..0f4bc7fff3e7 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/docs/DocumentationGenerator.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/docs/DocumentationGenerator.java @@ -52,6 +52,7 @@ import org.ballerinalang.langserver.common.utils.PositionUtil; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; +import org.jetbrains.annotations.Nullable; import java.util.LinkedHashMap; import java.util.Optional; @@ -291,7 +292,7 @@ private static DocAttachmentInfo generateClassDocumentation(ClassDefinitionNode private static DocAttachmentInfo getFunctionNodeDocumentation(FunctionSignatureNode signatureNode, NodeList resourceNodes, - MetadataNode metadata, Range functionRange, + @Nullable MetadataNode metadata, Range functionRange, SyntaxTree syntaxTree) { Position docStart = functionRange.getStart(); boolean hasDeprecated = false; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/ReportFeatureUsageExecutor.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/ReportFeatureUsageExecutor.java index f430c68bb8b7..bd5088734c10 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/ReportFeatureUsageExecutor.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/executors/ReportFeatureUsageExecutor.java @@ -21,6 +21,7 @@ import org.ballerinalang.langserver.commons.command.spi.LSCommandExecutor; import org.ballerinalang.langserver.telemetry.LSFeatureUsageTelemetryEvent; import org.ballerinalang.langserver.telemetry.TelemetryUtil; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; @@ -35,6 +36,7 @@ public class ReportFeatureUsageExecutor implements LSCommandExecutor { public static final String COMMAND = "REPORT_FEATURE_USAGE"; + @Nullable @Override public Object execute(ExecuteCommandContext context) { List arguments = context.getArguments(); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java index 9581bae07469..2ab3a8f4babd 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java @@ -83,6 +83,7 @@ import org.ballerinalang.langserver.common.utils.CommonUtil; import org.ballerinalang.langserver.common.utils.PositionUtil; import org.ballerinalang.langserver.common.utils.SymbolUtil; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; @@ -98,6 +99,7 @@ public class FunctionCallExpressionTypeFinder extends NodeVisitor { private final SemanticModel semanticModel; private final FunctionCallExpressionNode functionCallExpr; + @Nullable private TypeSymbol returnTypeSymbol; private boolean resultFound = false; @@ -546,7 +548,7 @@ protected void visitSyntaxNode(Node node) { // Do nothing } - private void checkAndSetTypeResult(TypeSymbol typeSymbol) { + private void checkAndSetTypeResult(@Nullable TypeSymbol typeSymbol) { if (typeSymbol == null) { return; } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/ImportsAcceptor.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/ImportsAcceptor.java index 12b9094c2b1f..9a976e1707e6 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/ImportsAcceptor.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/ImportsAcceptor.java @@ -26,6 +26,7 @@ import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashSet; @@ -51,7 +52,8 @@ public ImportsAcceptor(DocumentServiceContext context) { this(context, null); } - public ImportsAcceptor(DocumentServiceContext context, BiConsumer onExistCallback) { + public ImportsAcceptor(DocumentServiceContext context, + @Nullable BiConsumer onExistCallback) { this.newImports = new HashSet<>(); this.currentModuleImportsMap = context.currentDocImportsMap(); this.onExistCallback = onExistCallback; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/CommonUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/CommonUtil.java index ada3125d1115..3bdff0863c0e 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/CommonUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/CommonUtil.java @@ -61,6 +61,7 @@ import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Names; import java.io.File; @@ -369,7 +370,7 @@ public static boolean isErrorOrUnionOfErrors(TypeSymbol type) { return false; } - private static void getErrorTypes(TypeSymbol type, TypeSymbol typeRef, List errorTypes) { + private static void getErrorTypes(TypeSymbol type, @Nullable TypeSymbol typeRef, List errorTypes) { TypeDescKind kind = type.typeKind(); if (kind == TypeDescKind.ERROR) { errorTypes.add(Objects.requireNonNullElse(typeRef, type)); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/FunctionGenerator.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/FunctionGenerator.java index 7059b94fa0a5..719fe42902cf 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/FunctionGenerator.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/FunctionGenerator.java @@ -24,6 +24,7 @@ import org.ballerinalang.langserver.codeaction.CodeActionModuleId; import org.ballerinalang.langserver.common.ImportsAcceptor; import org.ballerinalang.langserver.commons.DocumentServiceContext; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.tree.BLangNode; import java.util.List; @@ -277,7 +278,7 @@ public static String getReturnTypeAsString(DocumentServiceContext context, Strin * @param typeSymbol Type symbol to be converted to a string * @return Type as a string */ - public static String getParameterTypeAsString(DocumentServiceContext context, TypeSymbol typeSymbol) { + public static String getParameterTypeAsString(DocumentServiceContext context, @Nullable TypeSymbol typeSymbol) { // Unknown types are considered as 'any' when generating parameters of a function if (typeSymbol == null || typeSymbol.typeKind() == TypeDescKind.COMPILATION_ERROR) { return TypeDescKind.ANY.getName(); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/NameUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/NameUtil.java index a9f2746d24dd..8d3e3b7c1b3a 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/NameUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/NameUtil.java @@ -31,6 +31,7 @@ import org.ballerinalang.langserver.commons.BallerinaCompletionContext; import org.ballerinalang.langserver.commons.DocumentServiceContext; import org.ballerinalang.langserver.commons.PositionedOperationContext; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -129,7 +130,8 @@ public static String generateTypeName(String prefix, Set visibleSymbolNa * @param visibleNames Visible symbol names. * @return */ - public static String generateParameterName(String arg, int position, TypeSymbol type, Set visibleNames) { + public static String generateParameterName(String arg, int position, @Nullable TypeSymbol type, + Set visibleNames) { String newName; if (arg.isEmpty() || !SyntaxInfo.isIdentifier(arg)) { String typeName = type != null ? type.typeKind().getName() : ""; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/PathUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/PathUtil.java index 5a923e4d26eb..e5f28deb3f2b 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/PathUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/PathUtil.java @@ -34,6 +34,7 @@ import org.ballerinalang.langserver.commons.workspace.WorkspaceManager; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.util.RepoUtils; import java.net.URI; @@ -61,7 +62,7 @@ private PathUtil() { * @param fileUri file uri * @return {@link Optional} Path from the URI */ - public static Optional getPathFromURI(String fileUri) { + public static Optional getPathFromURI(@Nullable String fileUri) { URI uri = URI.create(fileUri); String scheme = uri.getScheme(); try { diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/SymbolUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/SymbolUtil.java index d7412cb8319d..1e47cf230230 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/SymbolUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/utils/SymbolUtil.java @@ -40,6 +40,7 @@ import org.ballerinalang.langserver.commons.BallerinaCompletionContext; import org.ballerinalang.langserver.commons.PositionedOperationContext; import org.ballerinalang.langserver.completions.CompletionSearchProvider; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -215,7 +216,7 @@ public static boolean isRecordVariable(Symbol variableSymbol) { * @param symbol to evaluate * @return {@link Optional} type descriptor */ - public static Optional getTypeDescriptor(Symbol symbol) { + public static Optional getTypeDescriptor(@Nullable Symbol symbol) { if (symbol == null) { return Optional.empty(); } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/builder/FunctionCompletionItemBuilder.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/builder/FunctionCompletionItemBuilder.java index db574a784201..77c28ae19cd6 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/builder/FunctionCompletionItemBuilder.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/builder/FunctionCompletionItemBuilder.java @@ -56,6 +56,8 @@ import org.eclipse.lsp4j.InsertTextFormat; import org.eclipse.lsp4j.MarkupContent; import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -65,9 +67,6 @@ import java.util.Optional; import java.util.StringJoiner; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - /** * This class is being used to build function type completion item. * @@ -149,7 +148,7 @@ public static CompletionItem build(ClassSymbol typeDesc, InitializerBuildMode mo * @param context LS context * @return {@link CompletionItem} */ - public static CompletionItem buildMethod(@Nonnull FunctionSymbol functionSymbol, + public static CompletionItem buildMethod(@NotNull FunctionSymbol functionSymbol, BallerinaCompletionContext context) { CompletionItem item = new CompletionItem(); setMeta(item, functionSymbol, context); @@ -162,7 +161,8 @@ public static CompletionItem buildMethod(@Nonnull FunctionSymbol functionSymbol, return item; } - static void setMeta(CompletionItem item, FunctionSymbol functionSymbol, BallerinaCompletionContext ctx) { + static void setMeta(CompletionItem item, @Nullable FunctionSymbol functionSymbol, + BallerinaCompletionContext ctx) { item.setInsertTextFormat(InsertTextFormat.Snippet); item.setKind(CompletionItemKind.Function); if (functionSymbol != null) { @@ -309,7 +309,7 @@ private static Either getDocumentation(FunctionSymbol fun * @param ctx Language Server Operation context * @return {@link Pair} of insert text(left-side) and signature label(right-side) */ - private static Pair getFunctionInvocationSignature(FunctionSymbol functionSymbol, + private static Pair getFunctionInvocationSignature(@Nullable FunctionSymbol functionSymbol, String functionName, BallerinaCompletionContext ctx) { String escapedFunctionName = CommonUtil.escapeEscapeCharsInIdentifier(functionName); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/builder/TypeCompletionItemBuilder.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/builder/TypeCompletionItemBuilder.java index 20af7d3ddcca..919ce888bda7 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/builder/TypeCompletionItemBuilder.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/builder/TypeCompletionItemBuilder.java @@ -28,6 +28,7 @@ import org.ballerinalang.langserver.common.utils.SymbolUtil; import org.eclipse.lsp4j.CompletionItem; import org.eclipse.lsp4j.CompletionItemKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -51,7 +52,7 @@ private TypeCompletionItemBuilder() { * @param label label * @return {@link CompletionItem} */ - public static CompletionItem build(Symbol bSymbol, String label) { + public static CompletionItem build(@Nullable Symbol bSymbol, String label) { CompletionItem item = new CompletionItem(); item.setLabel(label); String insertText = CommonUtil.escapeSpecialCharsInInsertText(label); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/AbstractCompletionProvider.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/AbstractCompletionProvider.java index c20fb9e5e50b..d5ef8f22e276 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/AbstractCompletionProvider.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/AbstractCompletionProvider.java @@ -85,6 +85,7 @@ import org.eclipse.lsp4j.CompletionItem; import org.eclipse.lsp4j.CompletionItemKind; import org.eclipse.lsp4j.TextEdit; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Names; import java.util.ArrayList; @@ -167,7 +168,7 @@ public void sort(BallerinaCompletionContext context, T node, List completionItems, - Object... metaData) { + @Nullable Object... metaData) { this.sort(context, node, completionItems); } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/ImportDeclarationNodeContext.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/ImportDeclarationNodeContext.java index 2032609a213a..ddae4e8ed079 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/ImportDeclarationNodeContext.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/ImportDeclarationNodeContext.java @@ -43,6 +43,7 @@ import org.eclipse.lsp4j.CompletionItem; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Names; import java.util.ArrayList; @@ -180,7 +181,7 @@ public void sort(BallerinaCompletionContext context, * @param modulePart The module name user has already written * @return {@link Integer} rank */ - private int rankModuleName(String label, String modulePart) { + private int rankModuleName(String label, @Nullable String modulePart) { // If there's a module part partially written, check if the label starts with that. if (modulePart != null && label.startsWith(modulePart)) { return 1; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/util/RegexpCompletionProvider.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/util/RegexpCompletionProvider.java index 2a3af47512c2..1be0a31ebbfb 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/util/RegexpCompletionProvider.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/completions/providers/context/util/RegexpCompletionProvider.java @@ -33,6 +33,7 @@ import org.ballerinalang.langserver.completions.util.ItemResolverConstants; import org.ballerinalang.langserver.completions.util.Snippet; import org.ballerinalang.langserver.completions.util.SnippetBlock; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -270,7 +271,7 @@ private static void addAssertionEndCompletion(NonTerminalNode nodeAtCursor, BallerinaCompletionContext ctx, RegexTemplateNodeFinder nodeFinder, List completionItems, - String resolvedWord) { + @Nullable String resolvedWord) { if (nodeFinder.getTemplateExpressionNode() != null && nodeFinder.getTemplateExpressionNode().textRange().endOffset() - 1 == ctx.getCursorPositionInTree() diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/BallerinaCompletionContextImpl.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/BallerinaCompletionContextImpl.java index c004b747d3b1..4ef63685e68c 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/BallerinaCompletionContextImpl.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/BallerinaCompletionContextImpl.java @@ -32,6 +32,7 @@ import org.eclipse.lsp4j.CompletionParams; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.jsonrpc.CancelChecker; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -49,6 +50,7 @@ public class BallerinaCompletionContextImpl extends CompletionContextImpl implem private boolean isContextTypeCaptured = false; private Optional contextType = Optional.empty(); private boolean isCapturedEnclosingNode = false; + @Nullable private ModuleMemberDeclarationNode enclosingNode = null; private final CompletionParams completionParams; private final Position cursorPosition; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/BallerinaDefinitionContextImpl.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/BallerinaDefinitionContextImpl.java index a20f8f429c1b..b944d9843a9c 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/BallerinaDefinitionContextImpl.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/BallerinaDefinitionContextImpl.java @@ -26,6 +26,7 @@ import org.ballerinalang.langserver.commons.workspace.WorkspaceManager; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.jsonrpc.CancelChecker; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -37,6 +38,7 @@ public class BallerinaDefinitionContextImpl extends PositionedOperationContextImpl implements BallerinaDefinitionContext { private boolean capturedEnclosingNode = false; + @Nullable private ModuleMemberDeclarationNode enclosingNode = null; BallerinaDefinitionContextImpl(LSOperation operation, diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/CompletionContextImpl.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/CompletionContextImpl.java index 22815b35d9aa..0febbc50eef2 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/CompletionContextImpl.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/CompletionContextImpl.java @@ -25,6 +25,7 @@ import org.eclipse.lsp4j.CompletionCapabilities; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.jsonrpc.CancelChecker; +import org.jetbrains.annotations.Nullable; /** * Language server context implementation. @@ -50,7 +51,7 @@ public class CompletionContextImpl extends PositionedOperationContextImpl implem CompletionCapabilities capabilities, Position cursorPosition, LanguageServerContext serverContext, - CancelChecker cancelChecker) { + @Nullable CancelChecker cancelChecker) { super(operation, fileUri, cursorPosition, wsManager, serverContext, cancelChecker); this.capabilities = capabilities; } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/ContextBuilder.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/ContextBuilder.java index e5fa1f4ac401..5be70f108dce 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/ContextBuilder.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/contexts/ContextBuilder.java @@ -46,6 +46,7 @@ import org.eclipse.lsp4j.RenameParams; import org.eclipse.lsp4j.SignatureHelpCapabilities; import org.eclipse.lsp4j.jsonrpc.CancelChecker; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -68,7 +69,8 @@ private ContextBuilder() { * @param serverContext language server context * @return {@link DocumentServiceContext} base context generated */ - public static DocumentServiceContext buildDocumentServiceContext(String uri, WorkspaceManager workspaceManager, + public static DocumentServiceContext buildDocumentServiceContext(@Nullable String uri, + WorkspaceManager workspaceManager, LSContextOperation operation, LanguageServerContext serverContext) { return new BaseContextImpl.BaseContextBuilder(operation, serverContext) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/documentsymbol/DocumentSymbolResolver.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/documentsymbol/DocumentSymbolResolver.java index 0991d19d8ffd..73e754a0434a 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/documentsymbol/DocumentSymbolResolver.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/documentsymbol/DocumentSymbolResolver.java @@ -50,6 +50,7 @@ import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.SymbolKind; import org.eclipse.lsp4j.SymbolTag; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -437,7 +438,7 @@ private DocumentSymbol createDocumentSymbol(String name, SymbolKind kind, Range * @return */ private DocumentSymbol createDocumentSymbol(String name, SymbolKind kind, - String detail, Range range, + @Nullable String detail, Range range, Range selectionRange, boolean isDeprecated, List children) { DocumentSymbol documentSymbol = new DocumentSymbol(); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/AbstractExtendedLanguageServer.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/AbstractExtendedLanguageServer.java index 94286ac151bd..7293e46c44ba 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/AbstractExtendedLanguageServer.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/AbstractExtendedLanguageServer.java @@ -30,6 +30,7 @@ import org.eclipse.lsp4j.jsonrpc.json.JsonRpcMethodProvider; import org.eclipse.lsp4j.jsonrpc.services.ServiceEndpoints; import org.eclipse.lsp4j.services.LanguageServer; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -111,6 +112,7 @@ public void notify(String method, Object parameter) { } } + @Nullable @Override public CompletableFuture request(String method, Object parameter) { if (!extensionServices.containsKey(method)) { diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/connector/BallerinaRecordResponse.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/connector/BallerinaRecordResponse.java index c0c4fbbb2e16..8c81e08a5af9 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/connector/BallerinaRecordResponse.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/connector/BallerinaRecordResponse.java @@ -19,6 +19,7 @@ package org.ballerinalang.langserver.extensions.ballerina.connector; import com.google.gson.JsonElement; +import org.jetbrains.annotations.Nullable; /** * Represents with record AST. @@ -36,7 +37,7 @@ public class BallerinaRecordResponse { private final Boolean beta; public BallerinaRecordResponse(String org, String module, String version, String name, - JsonElement ast, String error, Boolean beta) { + @Nullable JsonElement ast, String error, Boolean beta) { this.org = org; this.module = module; this.version = version; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/ASTModification.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/ASTModification.java index 13a861a37755..9b855328e29f 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/ASTModification.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/ASTModification.java @@ -19,6 +19,7 @@ package org.ballerinalang.langserver.extensions.ballerina.document; import com.google.gson.JsonObject; +import org.jetbrains.annotations.Nullable; /** * Pojo to modify AST. @@ -38,7 +39,7 @@ public ASTModification() { } public ASTModification(int startLine, int startColumn, int endLine, int endColumn, boolean isImport, String type, - JsonObject config) { + @Nullable JsonObject config) { this.startLine = startLine; this.startColumn = startColumn; this.endLine = endLine; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/BallerinaTreeModifyUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/BallerinaTreeModifyUtil.java index 13cc250fd0f9..bde1b5834933 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/BallerinaTreeModifyUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/BallerinaTreeModifyUtil.java @@ -36,6 +36,7 @@ import org.ballerinalang.langserver.commons.workspace.WorkspaceDocumentException; import org.ballerinalang.langserver.commons.workspace.WorkspaceManager; import org.ballerinalang.langserver.extensions.ballerina.document.visitor.UnusedSymbolsVisitor; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.ArrayList; @@ -65,6 +66,7 @@ private BallerinaTreeModifyUtil() { put("INSERT", "$STATEMENT"); }}; + @Nullable public static String resolveMapping(String type, JsonObject config) { if (type == null || type.isEmpty()) { return null; @@ -94,6 +96,7 @@ public static String resolveMapping(String type, JsonObject config) { return mapping; } + @Nullable public static String getImport(JsonObject config) { JsonElement value = config.get("TYPE"); if (value != null) { @@ -121,7 +124,7 @@ public static List getUnusedImportRanges( } public static TextEdit createTextEdit(TextDocument oldTextDocument, - JsonObject config, + @Nullable JsonObject config, String type, int startLine, int startColumn, @@ -243,6 +246,7 @@ private static boolean importExist(UnusedSymbolsVisitor unusedSymbolsVisitor, AS || unusedSymbolsVisitor.getUnusedImports().containsKey(importValue)); } + @Nullable private static TextEdit constructEdit( UnusedSymbolsVisitor unusedSymbolsVisitor, TextDocument oldTextDocument, ASTModification astModification) { diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/visitor/UnusedSymbolsVisitor.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/visitor/UnusedSymbolsVisitor.java index 7ee82dbcd997..8a6e494c612c 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/visitor/UnusedSymbolsVisitor.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/document/visitor/UnusedSymbolsVisitor.java @@ -34,6 +34,7 @@ import io.ballerina.tools.diagnostics.Location; import io.ballerina.tools.text.LineRange; import org.ballerinalang.langserver.extensions.ballerina.document.ASTModification; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.HashMap; @@ -67,7 +68,7 @@ private void addUnusedImportNode(ImportDeclarationNode importDeclarationNode) { importDeclarationNode); } - private String getImportModuleName(ImportOrgNameNode importOrgNameNode, + private String getImportModuleName(@Nullable ImportOrgNameNode importOrgNameNode, SeparatedNodeList importModuleName) { StringBuilder moduleName = new StringBuilder(); if (importOrgNameNode != null) { @@ -87,6 +88,7 @@ private String getImportModuleName(ImportOrgNameNode importOrgNameNode, return moduleName.toString(); } + @Nullable private LineRange getDeleteRange(LineRange lineRange) { if (lineRange != null) { for (LineRange aPosition : deleteRanges.keySet()) { diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageComponentsRequest.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageComponentsRequest.java index 3fa9c812f302..ddb85d8d8bc9 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageComponentsRequest.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageComponentsRequest.java @@ -16,12 +16,14 @@ package org.ballerinalang.langserver.extensions.ballerina.packages; import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.jetbrains.annotations.Nullable; /** * Package components API request. */ public class PackageComponentsRequest { + @Nullable private TextDocumentIdentifier[] documentIdentifiers; protected TextDocumentIdentifier[] getDocumentIdentifiers() { diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageMetadataRequest.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageMetadataRequest.java index cafe592a07d0..77180c4566b7 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageMetadataRequest.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/PackageMetadataRequest.java @@ -16,12 +16,14 @@ package org.ballerinalang.langserver.extensions.ballerina.packages; import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.jetbrains.annotations.Nullable; /** * Package metadata API request. */ public class PackageMetadataRequest { + @Nullable private TextDocumentIdentifier documentIdentifier; protected TextDocumentIdentifier getDocumentIdentifier() { diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/ResolvedTypeForExpression.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/ResolvedTypeForExpression.java index bf41d24b7049..57331fb4ba21 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/ResolvedTypeForExpression.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/ResolvedTypeForExpression.java @@ -17,6 +17,7 @@ import io.ballerina.tools.text.LineRange; import org.ballerinalang.diagramutil.connector.models.connector.Type; +import org.jetbrains.annotations.Nullable; /** * Represents a type info with the range identifier. @@ -33,7 +34,7 @@ public Type getType() { return type; } - public void setType(Type type) { + public void setType(@Nullable Type type) { this.type = type; } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/ResolvedTypeForSymbol.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/ResolvedTypeForSymbol.java index feb8ecd69c38..1d73a004a082 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/ResolvedTypeForSymbol.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/ResolvedTypeForSymbol.java @@ -17,6 +17,7 @@ import io.ballerina.tools.text.LinePosition; import org.ballerinalang.diagramutil.connector.models.connector.Type; +import org.jetbrains.annotations.Nullable; /** * Represents a type info with the position identifier. @@ -33,7 +34,7 @@ public Type getType() { return type; } - public void setType(Type type) { + public void setType(@Nullable Type type) { this.type = type; } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/TypeFromExpressionRequest.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/TypeFromExpressionRequest.java index d062b73f3c66..f9d6f7c27903 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/TypeFromExpressionRequest.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/TypeFromExpressionRequest.java @@ -17,6 +17,7 @@ import io.ballerina.tools.text.LineRange; import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.jetbrains.annotations.Nullable; /** * Represents a request to get type info given for given positions of expressions. @@ -24,6 +25,7 @@ public class TypeFromExpressionRequest { private TextDocumentIdentifier documentIdentifier; + @Nullable private LineRange[] expressionRanges; public TextDocumentIdentifier getDocumentIdentifier() { diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/TypeFromSymbolRequest.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/TypeFromSymbolRequest.java index 1876f07f34f6..bf3e28334b03 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/TypeFromSymbolRequest.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/symbol/TypeFromSymbolRequest.java @@ -17,12 +17,14 @@ import io.ballerina.tools.text.LinePosition; import org.eclipse.lsp4j.TextDocumentIdentifier; +import org.jetbrains.annotations.Nullable; /** * Represents a request to get type info given for given positions of symbols. */ public class TypeFromSymbolRequest { private TextDocumentIdentifier documentIdentifier; + @Nullable private LinePosition[] positions; protected LinePosition[] getPositions() { diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/semantictokens/SemanticTokensVisitor.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/semantictokens/SemanticTokensVisitor.java index 44c34f8f3016..51ab73be0057 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/semantictokens/SemanticTokensVisitor.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/semantictokens/SemanticTokensVisitor.java @@ -70,6 +70,7 @@ import org.ballerinalang.langserver.commons.SemanticTokensContext.TokenTypeModifiers; import org.ballerinalang.langserver.commons.SemanticTokensContext.TokenTypes; import org.eclipse.lsp4j.SemanticTokens; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Comparator; @@ -758,7 +759,7 @@ public void setProperties(int length, int type, int modifiers) { this.modifiers = modifiers; } - public SemanticToken processSemanticToken(List data, SemanticToken previousToken) { + public SemanticToken processSemanticToken(List data, @Nullable SemanticToken previousToken) { int line = this.getLine(); int column = this.getColumn(); int prevTokenLine = line; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/signature/SignatureHelpUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/signature/SignatureHelpUtil.java index 0cb3bd8dc3f0..b52e01d2bed2 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/signature/SignatureHelpUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/signature/SignatureHelpUtil.java @@ -66,6 +66,7 @@ import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.SignatureHelp; import org.eclipse.lsp4j.SignatureInformation; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Names; import java.util.ArrayList; @@ -96,6 +97,7 @@ private SignatureHelpUtil() { * @param context Signature Help context. * @return {@link SignatureHelp} SignatureHelp for the invocation node. */ + @Nullable public static SignatureHelp getSignatureHelp(SignatureContext context) { fillTokenInfoAtCursor(context); Optional sNode = context.getNodeAtCursor(); diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/telemetry/LSFeatureUsageTelemetryEvent.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/telemetry/LSFeatureUsageTelemetryEvent.java index c3d321e60d16..cdf9c6536040 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/telemetry/LSFeatureUsageTelemetryEvent.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/telemetry/LSFeatureUsageTelemetryEvent.java @@ -16,6 +16,7 @@ package org.ballerinalang.langserver.telemetry; import org.ballerinalang.langserver.common.utils.CommonUtil; +import org.jetbrains.annotations.Nullable; /** * Represents a telemetry event sent to gather feature usage statistics. @@ -53,7 +54,8 @@ public String getFeatureMessage() { return featureMessage; } - public static LSFeatureUsageTelemetryEvent from(String featureName, String featureClass, String featureMessage) { + public static LSFeatureUsageTelemetryEvent from( + String featureName, @Nullable String featureClass, @Nullable String featureMessage) { return new LSFeatureUsageTelemetryEvent(LS_TELEMETRY_COMPONENT_NAME, CommonUtil.SDK_VERSION, featureName, featureClass, featureMessage); } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java index 2f5649c8af51..2a2293fe45e1 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java @@ -1373,6 +1373,7 @@ private Optional createProjectContext(Path filePath, String oper return Optional.of(ProjectContext.from(project)); } + @org.jetbrains.annotations.Nullable private Project createProject(Path filePath, String operationName) { Pair projectKindAndProjectRootPair = computeProjectKindAndProjectRoot(filePath); ProjectKind projectKind = projectKindAndProjectRootPair.getLeft(); @@ -1491,6 +1492,7 @@ public static class ProjectContext { private boolean compilationCrashed; + @org.jetbrains.annotations.Nullable private Process process; private boolean projectCrashed; diff --git a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/model/JConstructor.java b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/model/JConstructor.java index 848d1f3cee53..9f93171a52d1 100644 --- a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/model/JConstructor.java +++ b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/model/JConstructor.java @@ -19,6 +19,7 @@ import org.ballerinalang.bindgen.utils.BindgenEnv; import org.ballerinalang.bindgen.utils.BindgenUtils; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.Parameter; @@ -53,7 +54,7 @@ public class JConstructor extends BFunction { private final StringBuilder paramTypes = new StringBuilder(); private final Set importedPackages = new HashSet<>(); - JConstructor(Constructor c, BindgenEnv env, JClass jClass, String constructorName) { + JConstructor(Constructor c, BindgenEnv env, JClass jClass, @Nullable String constructorName) { super(BFunctionKind.CONSTRUCTOR, env); this.constructor = c; parentClass = c.getDeclaringClass(); diff --git a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenEnv.java b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenEnv.java index 30bf37655a7b..19a1e6fced2a 100644 --- a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenEnv.java +++ b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenEnv.java @@ -21,6 +21,7 @@ import io.ballerina.projects.Project; import io.ballerina.projects.TomlDocument; import org.ballerinalang.bindgen.model.JError; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.ArrayList; @@ -158,7 +159,7 @@ public void setAlias(String alias, String className) { this.aliases.put(alias, className); } - String getAlias(String className) { + @Nullable String getAlias(String className) { for (Map.Entry entry : aliases.entrySet()) { if (className.equals(entry.getValue())) { return entry.getKey(); diff --git a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenFileGenerator.java b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenFileGenerator.java index ed423c3c4d3c..bcf5c7349160 100644 --- a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenFileGenerator.java +++ b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenFileGenerator.java @@ -83,7 +83,11 @@ private SyntaxTree generateSyntaxTree() throws BindgenException { } private SyntaxTree generateFromTemplate(Path filePath) throws BindgenException { - return generateFromTemplate(filePath, env.getAlias(currentClass.getName())); + String alias = env.getAlias(currentClass.getName()); + if (alias == null) { + throw new BindgenException("error: unable to generate the binding class '" + currentClass.getName() + "'"); + } + return generateFromTemplate(filePath, alias); } private SyntaxTree generateFromTemplate(Path filePath, String alias) throws BindgenException { diff --git a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenMvnResolver.java b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenMvnResolver.java index f89a84c2d3a5..2e6049f1bd09 100644 --- a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenMvnResolver.java +++ b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenMvnResolver.java @@ -27,6 +27,7 @@ import org.ballerinalang.maven.Dependency; import org.ballerinalang.maven.MavenResolver; import org.ballerinalang.maven.exceptions.MavenResolverException; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -79,7 +80,7 @@ public void mavenResolver(String groupId, String artifactId, String version, Pat } } - private void dependencyTraversal(Dependency dependency, String mvnRepository, Path projectRoot, + private void dependencyTraversal(Dependency dependency, String mvnRepository, @Nullable Path projectRoot, JvmTarget parentJvmTarget) throws BindgenException { if (dependency.getDepedencies() == null) { @@ -104,7 +105,8 @@ private static Dependency resolveDependency(String groupId, String artifactId, S } private void handleDependency(String groupId, String artifactId, String version, String mvnRepository, - Path projectRoot, String parent, JvmTarget parentJvmTarget) throws BindgenException { + @Nullable Path projectRoot, @Nullable String parent, JvmTarget parentJvmTarget + ) throws BindgenException { Path mvnPath = Path.of(mvnRepository, getPathFromGroupId(groupId), artifactId, version); this.env.addClasspath(mvnPath.toString()); if (projectRoot != null) { @@ -179,6 +181,7 @@ private static String getPathFromGroupId(String groupId) { return combined.getPath(); } + @Nullable private static String getModuleName(Path projectRoot, String outputPath) { if (outputPath == null) { outputPath = Path.of(System.getProperty(USER_DIR)).toString(); diff --git a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenNodeFactory.java b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenNodeFactory.java index d16dc9a228c6..5ba38ea04f3b 100644 --- a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenNodeFactory.java +++ b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenNodeFactory.java @@ -84,6 +84,7 @@ import org.ballerinalang.bindgen.model.JField; import org.ballerinalang.bindgen.model.JMethod; import org.ballerinalang.bindgen.model.JParameter; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -139,7 +140,7 @@ private BindgenNodeFactory() { * @param moduleNames - list of module names with separators * @return the import declaration node created */ - static ImportDeclarationNode createImportDeclarationNode(String orgNameValue, String prefixValue, + static ImportDeclarationNode createImportDeclarationNode(@Nullable String orgNameValue, String prefixValue, List moduleNames) { Token importKeyword = createToken(SyntaxKind.IMPORT_KEYWORD, emptyML(), singleWSML()); ImportOrgNameNode orgName = null; @@ -287,6 +288,7 @@ private static List getFunctionMarkdownParameterDocumentationLine(BFunctio return parameterDocumentationLines; } + @Nullable private static String documentationParamDescription(BFunction.BFunctionKind functionKind, JParameter jParameter) { String paramDescription = null; if (functionKind == BFunction.BFunctionKind.CONSTRUCTOR) { @@ -301,6 +303,7 @@ private static String documentationParamDescription(BFunction.BFunctionKind func return paramDescription; } + @Nullable private static String documentationReturnDescription(BFunction bFunction) { String paramDescription = null; if (bFunction.getReturnType() == null && bFunction.getErrorType() == null) { @@ -372,6 +375,7 @@ private static FunctionSignatureNode createFunctionSignatureNode(BFunction bFunc returnTypeDescriptor); } + @Nullable private static ReturnTypeDescriptorNode getFunctionSignatureReturnType(BFunction bFunction) throws BindgenException { String returnType = null; @@ -390,6 +394,7 @@ private static ReturnTypeDescriptorNode getFunctionSignatureReturnType(BFunction return createReturnTypeDescriptorNode(createSimpleNameReferenceNode(returnType)); } + @Nullable private static ReturnTypeDescriptorNode getExternalFunctionSignatureReturnType(BFunction bFunction) { if (bFunction.getKind() == BFunction.BFunctionKind.FIELD_SET) { return null; @@ -881,7 +886,7 @@ private static List getObjectArrayReturnStatements(JMethod jMetho return statementNodes; } - private static NameReferenceNode createNameReferenceNode(String namespace, String name) { + private static NameReferenceNode createNameReferenceNode(@Nullable String namespace, String name) { if (name == null || name.trim().isEmpty()) { throw new IllegalArgumentException("name must not be null, blank, or empty"); } @@ -1301,7 +1306,7 @@ private static ElseBlockNode createElseBlockNode(StatementNode elseBody) { * Creates an if else statement node using the condition, if body and the else body provided. */ private static IfElseStatementNode createIfElseStatementNode(ExpressionNode condition, BlockStatementNode ifBody, - Node elseBody) { + @Nullable Node elseBody) { Token ifKeyword = createToken(SyntaxKind.IF_KEYWORD, emptyML(), singleWSML()); return NodeFactory.createIfElseStatementNode(ifKeyword, condition, ifBody, elseBody); } diff --git a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenTreeModifier.java b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenTreeModifier.java index 7874a899fdb4..c34e10d60706 100644 --- a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenTreeModifier.java +++ b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenTreeModifier.java @@ -17,6 +17,7 @@ import org.ballerinalang.bindgen.model.JConstructor; import org.ballerinalang.bindgen.model.JField; import org.ballerinalang.bindgen.model.JMethod; +import org.jetbrains.annotations.Nullable; import java.util.AbstractMap; import java.util.Arrays; @@ -292,6 +293,7 @@ private NodeList updateExternalMethods(NodeList retrieveClassDefinition( NodeList members) { AbstractMap.SimpleEntry entry = null; @@ -307,6 +309,7 @@ private AbstractMap.SimpleEntry retrieveClassDefin return entry; } + @Nullable private FunctionDefinitionNode generateBalFunction(BFunction bFunction, boolean isExternal) { try { return createFunctionDefinitionNode(bFunction, isExternal); diff --git a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/ChildFirstClassLoader.java b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/ChildFirstClassLoader.java index 75b96e82727d..58f4ab0236bd 100644 --- a/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/ChildFirstClassLoader.java +++ b/misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/ChildFirstClassLoader.java @@ -17,6 +17,8 @@ */ package org.ballerinalang.bindgen.utils; +import org.jetbrains.annotations.Nullable; + import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; @@ -39,6 +41,7 @@ public class ChildFirstClassLoader extends URLClassLoader { system = getSystemClassLoader(); } + @Nullable @Override protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { Class loadedClass = findLoadedClass(name); diff --git a/misc/ballerinalang-data-mapper/src/main/java/module-info.java b/misc/ballerinalang-data-mapper/src/main/java/module-info.java index fcf30fc70a68..0260f9560d0f 100644 --- a/misc/ballerinalang-data-mapper/src/main/java/module-info.java +++ b/misc/ballerinalang-data-mapper/src/main/java/module-info.java @@ -9,4 +9,5 @@ requires org.slf4j; requires com.google.gson; requires com.google.common; + requires static org.jetbrains.annotations; } diff --git a/misc/ballerinalang-data-mapper/src/main/java/org/ballerinalang/datamapper/AIDataMapperCodeActionUtil.java b/misc/ballerinalang-data-mapper/src/main/java/org/ballerinalang/datamapper/AIDataMapperCodeActionUtil.java index e9311eab34fc..24a66ee22a7f 100644 --- a/misc/ballerinalang-data-mapper/src/main/java/org/ballerinalang/datamapper/AIDataMapperCodeActionUtil.java +++ b/misc/ballerinalang-data-mapper/src/main/java/org/ballerinalang/datamapper/AIDataMapperCodeActionUtil.java @@ -63,6 +63,7 @@ import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.ArrayList; @@ -373,6 +374,7 @@ private Optional findExpressionInTypeCastNode(Range range, SyntaxTree synt * @param fileContentSymbols {@link List} * @return return the symbol */ + @Nullable public Symbol findSymbol(List fileContentSymbols) { for (Symbol symbol : fileContentSymbols) { if (!"ERROR".equals(symbol.getName().get())) { @@ -772,8 +774,8 @@ private String getMappingFromServer(JsonArray dataToSend, * @return - Generated mapping Function */ private String generateMappingFunction(String mappingFromServer, String foundTypeLeft, - String foundTypeRight, String leftModule, String rightModule, - String rhsSignature, SyntaxTree syntaxTree) { + String foundTypeRight, @Nullable String leftModule, + @Nullable String rightModule, String rhsSignature, SyntaxTree syntaxTree) { String leftType = foundTypeLeft; String rightType; diff --git a/misc/ballerinalang-data-mapper/src/main/java/org/ballerinalang/datamapper/utils/HttpClientRequest.java b/misc/ballerinalang-data-mapper/src/main/java/org/ballerinalang/datamapper/utils/HttpClientRequest.java index 6269a6922480..f80eea0ac482 100644 --- a/misc/ballerinalang-data-mapper/src/main/java/org/ballerinalang/datamapper/utils/HttpClientRequest.java +++ b/misc/ballerinalang-data-mapper/src/main/java/org/ballerinalang/datamapper/utils/HttpClientRequest.java @@ -15,6 +15,7 @@ */ package org.ballerinalang.datamapper.utils; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,10 +91,12 @@ private static void setHeadersAndMethod(HttpURLConnection conn, Map responseBuilder) throws IOException { diff --git a/misc/compiler-plugins/modules/package-semantic-analyzer/src/main/java/module-info.java b/misc/compiler-plugins/modules/package-semantic-analyzer/src/main/java/module-info.java index 9fb8c7cff44f..c8219593e63a 100644 --- a/misc/compiler-plugins/modules/package-semantic-analyzer/src/main/java/module-info.java +++ b/misc/compiler-plugins/modules/package-semantic-analyzer/src/main/java/module-info.java @@ -2,5 +2,6 @@ requires io.ballerina.lang; requires io.ballerina.tools.api; requires io.ballerina.toml; + requires static org.jetbrains.annotations; exports org.ballerinalang.pkgsemanticanalyzer; } diff --git a/misc/compiler-plugins/modules/package-semantic-analyzer/src/main/java/org/ballerinalang/pkgsemanticanalyzer/PackageSemanticAnalyzerPlugin.java b/misc/compiler-plugins/modules/package-semantic-analyzer/src/main/java/org/ballerinalang/pkgsemanticanalyzer/PackageSemanticAnalyzerPlugin.java index ee7aada24f4a..7f2ac2e70b00 100644 --- a/misc/compiler-plugins/modules/package-semantic-analyzer/src/main/java/org/ballerinalang/pkgsemanticanalyzer/PackageSemanticAnalyzerPlugin.java +++ b/misc/compiler-plugins/modules/package-semantic-analyzer/src/main/java/org/ballerinalang/pkgsemanticanalyzer/PackageSemanticAnalyzerPlugin.java @@ -37,6 +37,7 @@ import io.ballerina.toml.semantic.diagnostics.TomlNodeLocation; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -113,7 +114,7 @@ private static TomlNodeLocation getExportValueNodeLocation(CompilationAnalysisCo } private static void reportTomlDiagnostic(CompilationAnalysisContext compilationAnalysisContext, - TomlNodeLocation location, String code, String message, + TomlNodeLocation location, @Nullable String code, String message, DiagnosticSeverity severity) { var diagnosticInfo = new DiagnosticInfo(code, message, severity); var tomlDiagnostic = new TomlDiagnostic(location, diagnosticInfo, message); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/module-info.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/module-info.java index 3e0366e1629e..b92017cb6eda 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/module-info.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/module-info.java @@ -9,6 +9,7 @@ requires org.eclipse.lsp4j.jsonrpc; requires io.ballerina.identifier; requires org.apache.commons.lang3; + requires static org.jetbrains.annotations; exports org.ballerinalang.debugadapter.launcher; } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/BallerinaStackFrame.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/BallerinaStackFrame.java index 93fdb18c6a86..e4bd5cb79cd1 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/BallerinaStackFrame.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/BallerinaStackFrame.java @@ -29,6 +29,7 @@ import org.ballerinalang.debugadapter.variable.BVariableType; import org.eclipse.lsp4j.debug.Source; import org.eclipse.lsp4j.debug.StackFrame; +import org.jetbrains.annotations.Nullable; import java.net.URI; import java.nio.file.Path; @@ -51,6 +52,7 @@ public class BallerinaStackFrame { private final ExecutionContext context; private final Integer frameId; private final StackFrameProxyImpl jStackFrame; + @Nullable private StackFrame dapStackFrame; private static final String STRAND_FIELD_NAME = "name"; @@ -88,6 +90,7 @@ public Optional getAsDAPStackFrame() { return Optional.ofNullable(dapStackFrame); } + @Nullable private StackFrame computeDapStackFrame() { try { if (!isBalStackFrame(jStackFrame.getStackFrame())) { @@ -197,6 +200,7 @@ private static String getFilteredStackFrame(StackFrameProxyImpl stackFrame) thro /** * Retrieves ballerina strand instance of the given stack frame. */ + @Nullable private static ObjectReference getStrand(StackFrameProxyImpl frame) { try { if (frame.visibleVariableByName(STRAND_VAR_NAME) == null) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/ExecutionContext.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/ExecutionContext.java index 9fcdba5595ae..4b934714c694 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/ExecutionContext.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/ExecutionContext.java @@ -20,6 +20,7 @@ import io.ballerina.projects.Project; import org.ballerinalang.debugadapter.jdi.VirtualMachineProxyImpl; import org.eclipse.lsp4j.debug.services.IDebugProtocolClient; +import org.jetbrains.annotations.Nullable; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -81,6 +82,7 @@ public void setDebuggeeVM(VirtualMachineProxyImpl debuggeeVM) { this.debuggeeVM = debuggeeVM; } + @Nullable public EventRequestManager getEventManager() { if (debuggeeVM == null) { return null; @@ -88,6 +90,7 @@ public EventRequestManager getEventManager() { return debuggeeVM.eventRequestManager(); } + @Nullable public BufferedReader getInputStream() { if (launchedProcess == null) { return null; @@ -95,6 +98,7 @@ public BufferedReader getInputStream() { return new BufferedReader(new InputStreamReader(launchedProcess.getInputStream(), StandardCharsets.UTF_8)); } + @Nullable public BufferedReader getErrorStream() { if (launchedProcess == null) { return null; diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java index b6d854e42bf6..b9a531220fb6 100755 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java @@ -101,6 +101,7 @@ import org.eclipse.lsp4j.jsonrpc.Endpoint; import org.eclipse.lsp4j.jsonrpc.messages.Either; import org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -141,9 +142,12 @@ public class JBallerinaDebugServer implements IDebugProtocolServer { private ClientConfigHolder clientConfigHolder; private DebugExecutionManager executionManager; private JDIEventProcessor eventProcessor; + @Nullable private DebugExpressionEvaluator evaluator; private final ExecutionContext context; + @Nullable private ThreadReferenceProxyImpl activeThread; + @Nullable private SuspendedContext suspendedContext; private DebugOutputLogger outputLogger; @@ -754,6 +758,7 @@ private synchronized void updateVariableToStackFrameMap(int parent, int child) { variableToStackFrameMap.put(child, parentRef); } + @Nullable public StackFrame toDapStackFrame(StackFrameProxyImpl stackFrameProxy) { try { if (!isBalStackFrame(stackFrameProxy.getStackFrame())) { @@ -854,6 +859,7 @@ private List fetchLocalVariablesFromMap(VariablesArguments args, Stack * @param value runtime value of the variable * @param stackFrameRef reference ID of the parent stack frame */ + @Nullable private Variable getAsDapVariable(String name, Value value, Integer stackFrameRef) { BVariable variable = VariableFactory.getVariable(suspendedContext, name, value); if (variable == null) { @@ -946,7 +952,7 @@ private Variable[] createVariableArrayFrom(VariablesArguments args, List * Thread objects that have not yet been started (see {@link java.lang.Thread#start Thread.start()}) * and thread objects that have completed their execution are not included in the returned list. */ - Map getAllThreads() { + @Nullable Map getAllThreads() { if (context.getDebuggeeVM() == null) { return null; } @@ -965,7 +971,7 @@ Map getAllThreads() { /** * Returns a map of thread instances which correspond to an active ballerina strand, against their unique ID. */ - Map getActiveStrandThreads() { + @Nullable Map getActiveStrandThreads() { Map allThreads = getAllThreads(); if (allThreads == null) { return null; diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/SuspendedContext.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/SuspendedContext.java index d78a6cd3ace9..fdafb9ab4689 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/SuspendedContext.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/SuspendedContext.java @@ -30,6 +30,7 @@ import org.ballerinalang.debugadapter.jdi.StackFrameProxyImpl; import org.ballerinalang.debugadapter.jdi.ThreadReferenceProxyImpl; import org.ballerinalang.debugadapter.jdi.VirtualMachineProxyImpl; +import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.Map; @@ -57,10 +58,12 @@ public class SuspendedContext { private DebugSourceType sourceType; private Path breakPointSourcePath; + @Nullable private String fileName; private int lineNumber; private Module module; private Document document; + @Nullable private ClassLoaderReference classLoader; private DebugExpressionCompiler debugCompiler; @@ -86,6 +89,7 @@ public VirtualMachineProxyImpl getAttachedVm() { return attachedVm; } + @Nullable public ClassLoaderReference getDebuggeeClassLoader() { if (classLoader == null) { try { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/completion/util/CompletionUtil.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/completion/util/CompletionUtil.java index 9db4184b589a..224015a5b832 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/completion/util/CompletionUtil.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/completion/util/CompletionUtil.java @@ -39,6 +39,7 @@ import org.eclipse.lsp4j.debug.CompletionItem; import org.eclipse.lsp4j.debug.CompletionItemType; import org.eclipse.lsp4j.debug.CompletionsArguments; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -208,6 +209,7 @@ private static List populateBallerinaFunctionCompletionItems(Sym return completionItems; } + @Nullable private static CompletionItemType getCompletionItemType(Symbol symbol) { return switch (symbol.kind()) { case MODULE -> CompletionItemType.MODULE; @@ -247,9 +249,9 @@ public static NonTerminalNode getNonTerminalNode(CompletionContext completionCon * @param column debug expression column number * @return non terminal node at breakpoint */ - public static NonTerminalNode getNonTerminalNode(CompletionContext completionContext, - String source, String sourcePath, NonTerminalNode nonTerminalNode, - int lineNumber, int column) { + public static NonTerminalNode getNonTerminalNode( + CompletionContext completionContext, String source, String sourcePath, + @Nullable NonTerminalNode nonTerminalNode, int lineNumber, int column) { TextDocument document = TextDocuments.from(source); SyntaxTree syntaxTree = SyntaxTree.from(document, sourcePath); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/config/ClientAttachConfigHolder.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/config/ClientAttachConfigHolder.java index 297e357c5d2e..a9bca0eb8760 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/config/ClientAttachConfigHolder.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/config/ClientAttachConfigHolder.java @@ -16,6 +16,8 @@ package org.ballerinalang.debugadapter.config; +import org.jetbrains.annotations.Nullable; + import java.util.Map; import java.util.Optional; @@ -27,6 +29,7 @@ public class ClientAttachConfigHolder extends ClientConfigHolder { // The host name or IP address of remote debuggee. + @Nullable private String hostName; public ClientAttachConfigHolder(Map args) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/config/ClientConfigHolder.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/config/ClientConfigHolder.java index ebe94c4d886b..b7521e4f5eca 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/config/ClientConfigHolder.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/config/ClientConfigHolder.java @@ -17,6 +17,7 @@ package org.ballerinalang.debugadapter.config; import org.eclipse.lsp4j.debug.RunInTerminalRequestArgumentsKind; +import org.jetbrains.annotations.Nullable; import java.util.Locale; import java.util.Map; @@ -91,6 +92,7 @@ public Optional getExtendedCapabilities() { return Optional.ofNullable(extendedClientCapabilities); } + @Nullable public RunInTerminalRequestArgumentsKind getRunInTerminalKind() { if (clientRequestArgs.get(ARG_TERMINAL_KIND) != null) { String terminalConfig = clientRequestArgs.get(ARG_TERMINAL_KIND).toString().toUpperCase(Locale.ENGLISH); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/BExpressionValue.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/BExpressionValue.java index ac1d4e0804fc..7430a72674b2 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/BExpressionValue.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/BExpressionValue.java @@ -22,6 +22,7 @@ import org.ballerinalang.debugadapter.variable.BVariable; import org.ballerinalang.debugadapter.variable.BVariableType; import org.ballerinalang.debugadapter.variable.VariableFactory; +import org.jetbrains.annotations.Nullable; /** * Ballerina specific wrapper implementation for JDI Values. @@ -30,9 +31,10 @@ public class BExpressionValue { private final SuspendedContext context; private final Value jdiValue; + @Nullable private BVariable bVariable; - public BExpressionValue(SuspendedContext context, Value jdiValue) { + public BExpressionValue(SuspendedContext context, @Nullable Value jdiValue) { this.context = context; this.jdiValue = EvaluationUtils.unboxValue(context, jdiValue); this.bVariable = null; diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluationException.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluationException.java index 59bcda21bc6a..4f5fd656794f 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluationException.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluationException.java @@ -16,6 +16,8 @@ package org.ballerinalang.debugadapter.evaluation; +import org.jetbrains.annotations.Nullable; + /** * Error type definition for debug expression evaluation related exceptions. * @@ -27,7 +29,7 @@ private EvaluationException(String message) { this(message, null); } - private EvaluationException(String message, Throwable cause) { + private EvaluationException(String message, @Nullable Throwable cause) { super(message, cause); } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluationImportResolver.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluationImportResolver.java index 538aeddb80e7..620602ca9475 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluationImportResolver.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluationImportResolver.java @@ -27,6 +27,7 @@ import io.ballerina.compiler.syntax.tree.SyntaxTree; import io.ballerina.tools.text.LinePosition; import org.ballerinalang.debugadapter.SuspendedContext; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -83,7 +84,8 @@ public Map detectUsedImports(NonTerminalNode syntaxNode) throws * @param resolvedImports a list of already resolved imports, to avoid redundant processing. * @return a map of detected imports within the given syntax node. */ - public Map detectUsedImports(NonTerminalNode syntaxNode, Map resolvedImports) + public Map detectUsedImports(NonTerminalNode syntaxNode, + @Nullable Map resolvedImports) throws EvaluationException { if (resolvedImports == null) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluatorBuilder.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluatorBuilder.java index 56074b2205f9..f15db5db6783 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluatorBuilder.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluatorBuilder.java @@ -87,6 +87,7 @@ import org.ballerinalang.debugadapter.evaluation.engine.expression.XMLFilterExpressionEvaluator; import org.ballerinalang.debugadapter.evaluation.engine.expression.XMLStepExpressionEvaluator; import org.ballerinalang.debugadapter.evaluation.engine.expression.XMLTemplateExpressionEvaluator; +import org.jetbrains.annotations.Nullable; import java.util.AbstractMap; import java.util.ArrayList; @@ -156,7 +157,9 @@ public class EvaluatorBuilder extends NodeVisitor { private final Set capturedSyntax = new HashSet<>(); private final List unsupportedNodes = new ArrayList<>(); private final EvaluationContext context; + @Nullable private Evaluator result = null; + @Nullable private EvaluationException builderException = null; public EvaluatorBuilder(EvaluationContext context) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/Evaluator.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/Evaluator.java index caa13f4fea99..2e21c791f7e8 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/Evaluator.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/Evaluator.java @@ -21,6 +21,7 @@ import org.ballerinalang.debugadapter.evaluation.BExpressionValue; import org.ballerinalang.debugadapter.evaluation.BImport; import org.ballerinalang.debugadapter.evaluation.EvaluationException; +import org.jetbrains.annotations.Nullable; import java.util.Map; @@ -52,7 +53,7 @@ public Evaluator(EvaluationContext evaluationContext) { * @return a modifier object allowing to set a value in case the expression is lvalue, * otherwise null is returned. */ - Modifier getModifier() { + @Nullable Modifier getModifier() { return null; } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/InvocationArgProcessor.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/InvocationArgProcessor.java index fe57847523b4..914b31ae6329 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/InvocationArgProcessor.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/InvocationArgProcessor.java @@ -38,6 +38,7 @@ import org.ballerinalang.debugadapter.evaluation.engine.invokable.RuntimeInstanceMethod; import org.ballerinalang.debugadapter.evaluation.engine.invokable.RuntimeStaticMethod; import org.ballerinalang.debugadapter.evaluation.utils.EvaluationUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -89,8 +90,10 @@ protected InvocationArgProcessor(SuspendedContext context, String functionName, */ public abstract List process(List> argEvaluators) throws EvaluationException; - protected List getOrderedArgList(Map namedArgValues, FunctionSymbol definitionSymbol, - FunctionDefinitionNode definitionNode) throws EvaluationException { + protected List getOrderedArgList( + Map namedArgValues, @Nullable FunctionSymbol definitionSymbol, + @Nullable FunctionDefinitionNode definitionNode + ) throws EvaluationException { try { List argValueList = new ArrayList<>(); List args = jdiMethodReference.arguments(); @@ -144,7 +147,8 @@ protected static Value getRestArgArray(SuspendedContext context, Value arrayType return getRestArgArray.invokeSafely(); } - protected static Value getElementType(SuspendedContext context, Value arrayType) throws EvaluationException { + protected static Value getElementType(SuspendedContext context, @Nullable Value arrayType + ) throws EvaluationException { ReferenceType arrayTypeRef = ((ObjectReference) arrayType).referenceType(); List methods = arrayTypeRef.methodsByName(GET_ELEMENT_TYPE_METHOD); if (methods == null || methods.size() != 1) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/ExpressionAsProgramEvaluator.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/ExpressionAsProgramEvaluator.java index aa1f0b67ea45..a66a768765c3 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/ExpressionAsProgramEvaluator.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/ExpressionAsProgramEvaluator.java @@ -57,6 +57,7 @@ import org.ballerinalang.debugadapter.evaluation.utils.VariableUtils; import org.ballerinalang.debugadapter.variable.BVariable; import org.ballerinalang.debugadapter.variable.VariableFactory; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -344,6 +345,7 @@ private void createBallerinaToml() throws Exception { * Detects all the import usages within the evaluation snippet and generates required import statements for * the detected import usages. */ + @Nullable private String generateImportDeclarations(String functionSnippet) throws EvaluationException { ModuleMemberDeclarationNode functionNode = NodeParser.parseModuleMemberDeclaration(functionSnippet); if (functionNode.kind() != SyntaxKind.FUNCTION_DEFINITION) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/MethodCallExpressionEvaluator.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/MethodCallExpressionEvaluator.java index b7a7c4768527..aca55bdcba15 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/MethodCallExpressionEvaluator.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/MethodCallExpressionEvaluator.java @@ -42,6 +42,7 @@ import org.ballerinalang.debugadapter.variable.BVariable; import org.ballerinalang.debugadapter.variable.BVariableType; import org.ballerinalang.debugadapter.variable.VariableFactory; +import org.jetbrains.annotations.Nullable; import java.util.AbstractMap; import java.util.List; @@ -78,7 +79,7 @@ public class MethodCallExpressionEvaluator extends Evaluator { protected static final String QUALIFIED_TYPE_SIGNATURE_PREFIX = "L"; protected static final String JNI_SIGNATURE_SEPARATOR = "/"; - public MethodCallExpressionEvaluator(EvaluationContext context, ExpressionNode methodCallExpressionNode, + public MethodCallExpressionEvaluator(EvaluationContext context, @Nullable ExpressionNode methodCallExpressionNode, Evaluator expression, List> argEvaluators) { super(context); this.syntaxNode = methodCallExpressionNode; @@ -184,11 +185,13 @@ private Value invokeObjectMethod(BVariable resultVar) throws EvaluationException // Returning an empty value, as returning `null` in here might lead to unexpected results, as the method // invocation can also return null if the program output is nil. return new VoidValue() { + @Nullable @Override public VirtualMachine virtualMachine() { return null; } + @Nullable @Override public Type type() { return null; diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/NewExpressionEvaluator.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/NewExpressionEvaluator.java index 259b5b5e3113..fc0b7b38aeb5 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/NewExpressionEvaluator.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/expression/NewExpressionEvaluator.java @@ -36,6 +36,7 @@ import org.ballerinalang.debugadapter.evaluation.engine.SymbolBasedArgProcessor; import org.ballerinalang.debugadapter.evaluation.engine.invokable.RuntimeStaticMethod; import org.ballerinalang.debugadapter.evaluation.utils.EvaluationUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -66,8 +67,9 @@ public class NewExpressionEvaluator extends Evaluator { private final List> argEvaluators; private static final String OBJECT_INIT_METHOD_NAME = "init"; - public NewExpressionEvaluator(EvaluationContext context, ExpressionNode newExpressionNode, List> argEvaluators) { + public NewExpressionEvaluator( + EvaluationContext context, ExpressionNode newExpressionNode, + @Nullable List> argEvaluators) { super(context); this.syntaxNode = newExpressionNode; this.argEvaluators = argEvaluators; diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/invokable/JvmMethod.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/invokable/JvmMethod.java index 3324101e7af2..d18bdd4baa71 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/invokable/JvmMethod.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/invokable/JvmMethod.java @@ -23,6 +23,7 @@ import org.ballerinalang.debugadapter.SuspendedContext; import org.ballerinalang.debugadapter.evaluation.EvaluationException; import org.ballerinalang.debugadapter.evaluation.utils.EvaluationUtils; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; @@ -39,6 +40,7 @@ public abstract class JvmMethod { protected final SuspendedContext context; protected final Method methodRef; + @Nullable protected List argValues; JvmMethod(SuspendedContext context, Method methodRef) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/validator/SerialExpressionValidator.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/validator/SerialExpressionValidator.java index b730fe3ca856..3d85d891c0b7 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/validator/SerialExpressionValidator.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/validator/SerialExpressionValidator.java @@ -26,6 +26,7 @@ import org.ballerinalang.debugadapter.evaluation.validator.impl.InvalidInputValidator; import org.ballerinalang.debugadapter.evaluation.validator.impl.StatementValidator; import org.ballerinalang.debugadapter.evaluation.validator.impl.TopLevelDeclarationValidator; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -43,7 +44,9 @@ */ public class SerialExpressionValidator extends Validator { + @Nullable private ExpressionValidator expressionValidator; + @Nullable private List otherValidators; public SerialExpressionValidator() { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/LocalVariableProxyImpl.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/LocalVariableProxyImpl.java index fe954afe54e2..0d84e1437f0e 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/LocalVariableProxyImpl.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/LocalVariableProxyImpl.java @@ -20,6 +20,7 @@ import com.sun.jdi.IncompatibleThreadStateException; import com.sun.jdi.LocalVariable; import com.sun.jdi.Type; +import org.jetbrains.annotations.Nullable; /** * Proxy implementation for JDI local variable. @@ -31,7 +32,9 @@ public class LocalVariableProxyImpl extends JdiProxy implements LocalVariablePro private final String myVariableName; private final String myTypeName; + @Nullable private LocalVariable myVariable; + @Nullable private Type myVariableType; public LocalVariableProxyImpl(StackFrameProxyImpl frame, LocalVariable variable) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/StackFrameProxyImpl.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/StackFrameProxyImpl.java index ca0a141091d0..55e94794ec44 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/StackFrameProxyImpl.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/StackFrameProxyImpl.java @@ -32,6 +32,7 @@ import com.sun.jdi.StackFrame; import com.sun.jdi.ThreadReference; import com.sun.jdi.Value; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,10 +54,14 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { //caches private int myFrameIndex = -1; + @Nullable private StackFrame myStackFrame; + @Nullable private ObjectReference myThisReference; + @Nullable private ClassLoaderReference myClassLoader; private ThreeState myIsObsolete = ThreeState.UNSURE; + @Nullable private Map myAllValues; public StackFrameProxyImpl(ThreadReferenceProxyImpl threadProxy, StackFrame frame, int fromBottomIndex) { @@ -187,6 +192,7 @@ public String toString() { } } + @Nullable public ObjectReference thisObject() throws JdiProxyException { checkValid(); try { @@ -239,17 +245,20 @@ public List visibleVariables() throws JdiProxyException throw new JdiProxyException(error.getMessage(), error); } + @Nullable @Override public LocalVariableProxyImpl visibleVariableByName(String name) throws JdiProxyException { final LocalVariable variable = visibleVariableByNameInt(name); return variable != null ? new LocalVariableProxyImpl(this, variable) : null; } + @Nullable public Value visibleValueByName(String name) throws JdiProxyException { LocalVariable variable = visibleVariableByNameInt(name); return variable != null ? getValue(new LocalVariableProxyImpl(this, variable)) : null; } + @Nullable protected LocalVariable visibleVariableByNameInt(String name) throws JdiProxyException { InvalidStackFrameException error = null; for (int attempt = 0; attempt < 2; attempt++) { @@ -393,6 +402,7 @@ public int getIndexFromBottom() { return myFrameFromBottomIndex; } + @Nullable private static Method getMethod(Location location) { try { return location.method(); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/StringReferenceProxyImpl.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/StringReferenceProxyImpl.java index 5d4d9769d6f1..d26da86a20b3 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/StringReferenceProxyImpl.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/StringReferenceProxyImpl.java @@ -17,11 +17,13 @@ package org.ballerinalang.debugadapter.jdi; import com.sun.jdi.StringReference; +import org.jetbrains.annotations.Nullable; /** * Proxy implementation for JDI strings. */ public class StringReferenceProxyImpl extends ObjectReferenceProxyImpl { + @Nullable private String myStringValue; public StringReferenceProxyImpl(VirtualMachineProxyImpl virtualMachineProxy, StringReference objectReference) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/ThreadReferenceProxyImpl.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/ThreadReferenceProxyImpl.java index 563b081daa07..266111586b4e 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/ThreadReferenceProxyImpl.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/ThreadReferenceProxyImpl.java @@ -27,6 +27,7 @@ import com.sun.jdi.ThreadGroupReference; import com.sun.jdi.ThreadReference; import com.sun.jdi.Value; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,11 +46,13 @@ public final class ThreadReferenceProxyImpl extends ObjectReferenceProxyImpl implements ThreadReferenceProxy { private static final Logger LOG = LoggerFactory.getLogger(ThreadReferenceProxyImpl.class); // cached data + @Nullable private String myName; private int myFrameCount = -1; // stack frames, 0 - bottom private final LinkedList myFramesFromBottom = new LinkedList<>(); //cache build on the base of myFramesFromBottom 0 - top, initially nothing is cached + @Nullable private List myFrames = null; private ThreadGroupReferenceProxyImpl myThreadGroupProxy; @@ -265,6 +268,7 @@ private void checkFrames(final ThreadReference threadRef) throws JdiProxyExcepti } } + @Nullable @Override public StackFrameProxyImpl frame(int i) throws JdiProxyException { final ThreadReference threadReference = getThreadReference(); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/VirtualMachineProxyImpl.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/VirtualMachineProxyImpl.java index ebd76854de1f..5870a9b049ac 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/VirtualMachineProxyImpl.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/jdi/VirtualMachineProxyImpl.java @@ -35,6 +35,7 @@ import com.sun.jdi.VoidValue; import com.sun.jdi.event.EventQueue; import com.sun.jdi.request.EventRequestManager; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,6 +67,7 @@ public class VirtualMachineProxyImpl implements JdiTimer, VirtualMachineProxy { private final Map myAllThreads = new ConcurrentHashMap<>(); private final Map myThreadGroups = new HashMap<>(); private boolean myAllThreadsDirty = true; + @Nullable private List myAllClasses; private Map> myNestedClassesCache = new HashMap<>(); @@ -549,6 +551,7 @@ public boolean canGetMethodReturnValues() { return myGetMethodReturnValues.isAvailable(); } + @Nullable public String getDefaultStratum() { return myVersionHigher14 ? myVirtualMachine.getDefaultStratum() : null; } @@ -569,6 +572,7 @@ public void setDebugTraceMode(int i) { myVirtualMachine.setDebugTraceMode(i); } + @Nullable public ThreadReferenceProxyImpl getThreadReferenceProxy(ThreadReference thread) { if (thread == null) { return null; @@ -576,7 +580,8 @@ public ThreadReferenceProxyImpl getThreadReferenceProxy(ThreadReference thread) return myAllThreads.computeIfAbsent(thread, t -> new ThreadReferenceProxyImpl(this, t)); } - public ThreadGroupReferenceProxyImpl getThreadGroupReferenceProxy(ThreadGroupReference group) { + @Nullable + public ThreadGroupReferenceProxyImpl getThreadGroupReferenceProxy(@Nullable ThreadGroupReference group) { if (group == null) { return null; } @@ -590,6 +595,7 @@ public ThreadGroupReferenceProxyImpl getThreadGroupReferenceProxy(ThreadGroupRef return proxy; } + @Nullable public ObjectReferenceProxyImpl getObjectReferenceProxy(ObjectReference objectReference) { if (objectReference != null) { if (objectReference instanceof ThreadReference threadReference) { @@ -685,6 +691,7 @@ public final boolean isAvailable() { } static final class JNITypeParserReflect { + @Nullable static Method typeNameToSignatureMethod; static { @@ -704,6 +711,7 @@ static final class JNITypeParserReflect { private JNITypeParserReflect() { } + @Nullable static String typeNameToSignature(String name) { if (typeNameToSignatureMethod != null) { try { @@ -714,6 +722,7 @@ static String typeNameToSignature(String name) { return null; } + @Nullable private static Method getDeclaredMethod(Class aClass, String name, Class... parameters) { try { Method declaredMethod = aClass.getDeclaredMethod(name, parameters); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/runner/BProgramRunner.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/runner/BProgramRunner.java index eb143d24288c..e7b73ebe337d 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/runner/BProgramRunner.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/runner/BProgramRunner.java @@ -19,6 +19,7 @@ import org.ballerinalang.debugadapter.config.ClientConfigurationException; import org.ballerinalang.debugadapter.config.ClientLaunchConfigHolder; import org.ballerinalang.debugadapter.utils.OSUtils; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.ArrayList; @@ -55,7 +56,7 @@ protected BProgramRunner(ClientLaunchConfigHolder configHolder, String projectRo */ public abstract Process start() throws Exception; - public ArrayList getBallerinaCommand(String balFile) throws ClientConfigurationException { + public ArrayList getBallerinaCommand(@Nullable String balFile) throws ClientConfigurationException { List ballerinaExec = new ArrayList<>(); if (OSUtils.isWindows()) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/utils/OSUtils.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/utils/OSUtils.java index bff002548da3..0236a9ff991e 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/utils/OSUtils.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/utils/OSUtils.java @@ -16,6 +16,8 @@ package org.ballerinalang.debugadapter.utils; +import org.jetbrains.annotations.Nullable; + import java.util.Locale; /** @@ -37,6 +39,7 @@ private OSUtils() { * * @return operating system */ + @Nullable public static String getOperatingSystem() { if (OSUtils.isWindows()) { return WINDOWS; diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/utils/PackageUtils.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/utils/PackageUtils.java index 7b127501a7f8..b7092b4753d6 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/utils/PackageUtils.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/utils/PackageUtils.java @@ -30,6 +30,7 @@ import org.ballerinalang.debugadapter.DebugSourceType; import org.ballerinalang.debugadapter.ExecutionContext; import org.ballerinalang.debugadapter.SuspendedContext; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.net.URI; @@ -148,6 +149,7 @@ public static String getDefaultModuleName(Project project) { return ""; } + @Nullable public static String getFileNameFrom(Path filePath) { try { String[] split = filePath.toString().split(FILE_SEPARATOR_REGEX); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BCompoundVariable.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BCompoundVariable.java index b87be3c474b0..e43fb97bef0a 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BCompoundVariable.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BCompoundVariable.java @@ -19,6 +19,7 @@ import com.sun.jdi.Value; import org.ballerinalang.debugadapter.SuspendedContext; import org.eclipse.lsp4j.debug.Variable; +import org.jetbrains.annotations.Nullable; import static io.ballerina.identifier.Utils.decodeIdentifier; @@ -31,6 +32,7 @@ public abstract class BCompoundVariable implements BVariable { protected final String name; protected final BVariableType type; protected Value jvmValue; + @Nullable protected Variable dapVariable; public BCompoundVariable(SuspendedContext context, String varName, BVariableType bVariableType, Value jvmValue) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BSimpleVariable.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BSimpleVariable.java index 47f6974caff0..bb4e46cb9a95 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BSimpleVariable.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BSimpleVariable.java @@ -19,6 +19,7 @@ import com.sun.jdi.Value; import org.ballerinalang.debugadapter.SuspendedContext; import org.eclipse.lsp4j.debug.Variable; +import org.jetbrains.annotations.Nullable; import static io.ballerina.identifier.Utils.decodeIdentifier; @@ -31,6 +32,7 @@ public abstract class BSimpleVariable implements BVariable { private final String name; private final BVariableType type; protected final Value jvmValue; + @Nullable private Variable dapVariable; public BSimpleVariable(SuspendedContext context, String varName, BVariableType bVariableType, Value jvmValue) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/DebugVariableException.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/DebugVariableException.java index f21d79b0c6d9..59eabe4f9a7c 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/DebugVariableException.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/DebugVariableException.java @@ -16,6 +16,8 @@ package org.ballerinalang.debugadapter.variable; +import org.jetbrains.annotations.Nullable; + /** * Error type definition for debugger variable implementation related exceptions. * @@ -27,7 +29,7 @@ public DebugVariableException(String message) { this(message, null); } - public DebugVariableException(String message, Throwable cause) { + public DebugVariableException(String message, @Nullable Throwable cause) { super(message, cause); } } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableFactory.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableFactory.java index 52af26f71dc5..af1346a2e30b 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableFactory.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableFactory.java @@ -50,6 +50,7 @@ import org.ballerinalang.debugadapter.variable.types.BXmlPi; import org.ballerinalang.debugadapter.variable.types.BXmlSequence; import org.ballerinalang.debugadapter.variable.types.BXmlText; +import org.jetbrains.annotations.Nullable; import static org.ballerinalang.debugadapter.evaluation.utils.EvaluationUtils.STRAND_VAR_NAME; import static org.ballerinalang.debugadapter.variable.VariableUtils.isClientObject; @@ -122,6 +123,7 @@ public static BVariable getVariable(SuspendedContext context, Value value) { * @param value jdi value instance of the java variable * @return Ballerina type variable instance which corresponds to the given java variable */ + @Nullable public static BVariable getVariable(SuspendedContext context, String varName, Value value) { if (varName == null || varName.isEmpty() || varName.startsWith("$") || varName.equals(STRAND_VAR_NAME)) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableUtils.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableUtils.java index 879dd77df7a3..88ae099a5675 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableUtils.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableUtils.java @@ -24,6 +24,7 @@ import org.ballerinalang.debugadapter.SuspendedContext; import org.ballerinalang.debugadapter.evaluation.EvaluationException; import org.ballerinalang.debugadapter.jdi.LocalVariableProxyImpl; +import org.jetbrains.annotations.Nullable; import java.util.AbstractMap; import java.util.ArrayList; @@ -115,6 +116,7 @@ public static String getRecordBType(Value value) { * @param bValue JDI value instance of the ballerina jvm variable. * @return variable type in string form. */ + @Nullable public static Map.Entry getPackageOrgAndName(Value bValue) { try { if (!(bValue instanceof ObjectReference valueRef)) { @@ -322,6 +324,7 @@ private static boolean isIntersectionType(Value runtimeType) { * @param typeValue JDI value instance. * @return referred type value. */ + @Nullable private static Value getReferredTypeFromTypeRefType(Value typeValue) throws DebugVariableException { while (typeValue != null && isTypeReferenceType(typeValue)) { typeValue = getFieldValue(typeValue, FIELD_REFERRED_TYPE).orElse(null); @@ -336,6 +339,7 @@ private static Value getReferredTypeFromTypeRefType(Value typeValue) throws Debu * @param typeValue JDI value instance. * @return effective type value. */ + @Nullable private static Value getEffectiveTypeFromIntersectionType(Value typeValue) throws DebugVariableException { while (typeValue != null && isIntersectionType(typeValue)) { typeValue = getFieldValue(typeValue, FIELD_EFFECTIVE_TYPE).orElse(null); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BMap.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BMap.java index 9ecc8610fdbb..dcfff25afbb5 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BMap.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BMap.java @@ -26,6 +26,7 @@ import org.ballerinalang.debugadapter.variable.IndexedCompoundVariable; import org.ballerinalang.debugadapter.variable.VariableUtils; import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.LinkedHashMap; @@ -39,6 +40,7 @@ public class BMap extends IndexedCompoundVariable { private int mapSize = -1; + @Nullable private ArrayReference loadedKeys = null; private Value[] loadedValues = null; @@ -111,6 +113,7 @@ private Map getEntries(int startIndex, int count) { return entries; } + @Nullable private Value getValueFor(Value key) { try { Optional getMethod = VariableUtils.getMethod(jvmValue, METHOD_GET); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BNil.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BNil.java index 8a63b69201d9..112740dda602 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BNil.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BNil.java @@ -20,13 +20,14 @@ import org.ballerinalang.debugadapter.SuspendedContext; import org.ballerinalang.debugadapter.variable.BSimpleVariable; import org.ballerinalang.debugadapter.variable.BVariableType; +import org.jetbrains.annotations.Nullable; /** * Ballerina nil variable type. */ public class BNil extends BSimpleVariable { - public BNil(SuspendedContext context, String name, Value value) { + public BNil(SuspendedContext context, String name, @Nullable Value value) { super(context, name, BVariableType.NIL, value); } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java index 7e72a1747997..b8fd4dfa2c61 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java @@ -25,6 +25,7 @@ import org.ballerinalang.debugadapter.variable.BVariableType; import org.ballerinalang.debugadapter.variable.NamedCompoundVariable; import org.ballerinalang.debugadapter.variable.VariableUtils; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.LinkedHashMap; @@ -44,6 +45,7 @@ public class BRecord extends NamedCompoundVariable { private static final String METHOD_GET_KEYS = "getKeys"; private static final String METHOD_GET = "get"; + @Nullable private ArrayReference loadedKeys = null; public BRecord(SuspendedContext context, String name, Value value) { @@ -80,6 +82,7 @@ public Map computeChildVariables() { } } + @Nullable private Map getRecordFields() { try { loadAllKeys(); @@ -111,6 +114,7 @@ private void loadAllKeys() { } } + @Nullable private Value getValueFor(Value key) { try { Optional getMethod = VariableUtils.getMethod(jvmValue, METHOD_GET, GET_METHOD_SIGNATURE_PATTERN); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BTable.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BTable.java index 2e02a49946b8..6850ba0d7c1b 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BTable.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BTable.java @@ -27,6 +27,7 @@ import org.ballerinalang.debugadapter.variable.IndexedCompoundVariable; import org.ballerinalang.debugadapter.variable.VariableUtils; import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -180,6 +181,7 @@ private ArrayList getChildVariables(int start, int count) { return childVariables; } + @Nullable private Value getIterator() throws Exception { Optional getIteratorMethod = VariableUtils.getMethod(jvmValue, METHOD_GET_ITERATOR, ITERATOR_VALUE_PATTERN); @@ -190,7 +192,7 @@ private Value getIterator() throws Exception { getIteratorMethod.get(), new ArrayList<>(), ObjectReference.INVOKE_SINGLE_THREADED); } - private boolean hasNext(Value iterator) throws Exception { + private boolean hasNext(@Nullable Value iterator) throws Exception { Optional hasNextMethod = VariableUtils.getMethod(iterator, METHOD_HAS_NEXT); if (hasNextMethod.isEmpty()) { return false; @@ -200,7 +202,8 @@ private boolean hasNext(Value iterator) throws Exception { return Boolean.parseBoolean(hasNext.toString()); } - private Value nextElement(Value iterator) throws Exception { + @Nullable + private Value nextElement(@Nullable Value iterator) throws Exception { Optional nextMethod = VariableUtils.getMethod(iterator, METHOD_NEXT); if (nextMethod.isEmpty()) { return null; @@ -209,7 +212,8 @@ private Value nextElement(Value iterator) throws Exception { nextMethod.get(), new ArrayList<>(), ObjectReference.INVOKE_SINGLE_THREADED); } - private Value getValues(Value next) throws Exception { + @Nullable + private Value getValues(@Nullable Value next) throws Exception { Optional getValuesMethod = VariableUtils.getMethod(next, METHOD_GET_VALUES); if (getValuesMethod.isEmpty()) { return null; diff --git a/misc/debug-adapter/modules/debug-adapter-runtime/src/main/java/module-info.java b/misc/debug-adapter/modules/debug-adapter-runtime/src/main/java/module-info.java index 550cb4cf8459..4ad5865f149c 100644 --- a/misc/debug-adapter/modules/debug-adapter-runtime/src/main/java/module-info.java +++ b/misc/debug-adapter/modules/debug-adapter-runtime/src/main/java/module-info.java @@ -1,4 +1,5 @@ module org.ballerinalang.debugadapter.runtime { requires io.ballerina.runtime; requires io.ballerina.lang.internal; + requires static org.jetbrains.annotations; } diff --git a/misc/debug-adapter/modules/debug-adapter-runtime/src/main/java/org/ballerinalang/debugadapter/runtime/DebuggerRuntime.java b/misc/debug-adapter/modules/debug-adapter-runtime/src/main/java/org/ballerinalang/debugadapter/runtime/DebuggerRuntime.java index be7fcf312e76..5dfaef48e608 100644 --- a/misc/debug-adapter/modules/debug-adapter-runtime/src/main/java/org/ballerinalang/debugadapter/runtime/DebuggerRuntime.java +++ b/misc/debug-adapter/modules/debug-adapter-runtime/src/main/java/org/ballerinalang/debugadapter/runtime/DebuggerRuntime.java @@ -51,6 +51,7 @@ import org.ballerinalang.langlib.internal.GetElements; import org.ballerinalang.langlib.internal.GetFilteredChildrenFlat; import org.ballerinalang.langlib.internal.SelectDescendants; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -255,6 +256,7 @@ public static Object createErrorValue(Object message, Object cause, Object... de * @param annotationName name of the annotation * @return annotation value with the given name */ + @Nullable public static Object getAnnotationValue(Object typedescValue, String annotationName) { if (!(typedescValue instanceof TypedescValue)) { return ErrorCreator.createError(StringUtils.fromString("Incompatible types: expected 'typedesc`, " + @@ -339,6 +341,7 @@ public static BXml getXMLFilterResult(BXml xmlVal, BString... xmlPatternChainLis * @param xmlStepPattern step expression pattern * @return the result of XML step expression */ + @Nullable public static Object getXMLStepResult(BXml xmlVal, String xmlStepPattern) { try { if (xmlStepPattern.startsWith(XML_STEP_SEPARATOR)) { diff --git a/misc/diagram-util/src/main/java/module-info.java b/misc/diagram-util/src/main/java/module-info.java index 700c5ec8baa4..f9125eda9425 100644 --- a/misc/diagram-util/src/main/java/module-info.java +++ b/misc/diagram-util/src/main/java/module-info.java @@ -7,6 +7,7 @@ requires org.apache.commons.lang3; requires io.ballerina.docerina; requires io.ballerina.central.client; + requires static org.jetbrains.annotations; exports org.ballerinalang.diagramutil; exports org.ballerinalang.diagramutil.connector.models; diff --git a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/generator/GeneratorUtils.java b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/generator/GeneratorUtils.java index cd723a85a4c1..9a64fbdd4193 100644 --- a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/generator/GeneratorUtils.java +++ b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/generator/GeneratorUtils.java @@ -45,6 +45,7 @@ import org.ballerinalang.diagramutil.connector.models.connector.Type; import org.ballerinalang.diagramutil.connector.models.connector.types.InclusionType; import org.ballerinalang.diagramutil.connector.models.connector.types.PathParamType; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -105,6 +106,7 @@ public static String getDocFromMetadata(Optional optionalMetadataN * @param semanticModel Project semantic model * @return Type */ + @Nullable public static Type getReturnParameter(ReturnTypeDescriptorNode returnTypeDescriptorNode, Optional optionalMetadataNode, SemanticModel semanticModel) { @@ -119,6 +121,7 @@ public static Type getReturnParameter(ReturnTypeDescriptorNode returnTypeDescrip return null; } + @Nullable public static String getDocLineString(NodeList documentElements) { if (documentElements.isEmpty()) { return null; @@ -131,6 +134,7 @@ public static String getDocLineString(NodeList documentElements) { return doc.toString(); } + @Nullable public static String getParameterDocFromMetadataList(String parameterName, Optional optionalMetadataNode) { if (optionalMetadataNode.isEmpty()) { diff --git a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Connector.java b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Connector.java index 7c6487629060..01cbe9745d06 100644 --- a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Connector.java +++ b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Connector.java @@ -20,6 +20,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import org.ballerinalang.central.client.model.Package; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Map; @@ -75,7 +76,7 @@ public Connector(String orgName, String moduleName, String packageName, String v } public Connector(String orgName, String moduleName, String packageName, String version, String name, - String documentation, Map displayAnnotation, List functions) { + String documentation, @Nullable Map displayAnnotation, List functions) { this.moduleName = moduleName; this.name = name; this.documentation = documentation; diff --git a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Function.java b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Function.java index f3b880fec827..e08697632adc 100644 --- a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Function.java +++ b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Function.java @@ -19,6 +19,7 @@ import com.google.gson.annotations.Expose; import org.ballerinalang.diagramutil.connector.models.connector.types.PathParamType; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Map; @@ -42,8 +43,9 @@ public class Function { @Expose public Map displayAnnotation; - public Function(String name, List queryParams, Type returnType, Map displayAnnotation, - String[] qualifiers, String documentation) { + public Function(String name, List queryParams, Type returnType, + @Nullable Map displayAnnotation, + @Nullable String[] qualifiers, String documentation) { this.name = name; this.parameters = queryParams; this.returnType = returnType; @@ -52,7 +54,7 @@ public Function(String name, List queryParams, Type returnType, Map pathParams, List queryParams, Type returnType, + public Function(String name, List pathParams, List queryParams, @Nullable Type returnType, Map displayAnnotation, String[] qualifiers, String documentation) { this.name = name; this.pathParams = pathParams; diff --git a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Type.java b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Type.java index ed74dd4437c7..9832d24185e2 100644 --- a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Type.java +++ b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/Type.java @@ -62,6 +62,7 @@ import org.ballerinalang.diagramutil.connector.models.connector.types.StreamType; import org.ballerinalang.diagramutil.connector.models.connector.types.TableType; import org.ballerinalang.diagramutil.connector.models.connector.types.UnionType; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -76,6 +77,7 @@ public class Type { private static final Map visitedTypeMap = new HashMap<>(); + @Nullable @Expose public String name; @Expose @@ -90,6 +92,7 @@ public class Type { public String defaultValue; @Expose public Map displayAnnotation; + @Nullable @Expose public String documentation; @Expose @@ -98,8 +101,8 @@ public class Type { public Type() { } - public Type(String name, String typeName, boolean optional, TypeInfo typeInfo, boolean defaultable, - String defaultValue, Map displayAnnotation, String documentation) { + public Type(String name, String typeName, boolean optional, @Nullable TypeInfo typeInfo, boolean defaultable, + String defaultValue, @Nullable Map displayAnnotation, @Nullable String documentation) { this.name = name; this.typeName = typeName; this.optional = optional; @@ -259,6 +262,7 @@ public static void flattenIntersectionNode(Node node, SemanticModel semanticMode optionalType.ifPresent(fields::add); } + @Nullable public static VisitedType getVisitedType(String typeName) { if (visitedTypeMap.containsKey(typeName)) { return visitedTypeMap.get(typeName); @@ -272,7 +276,8 @@ public static void completeVisitedTypeEntry(String typeName, Type typeNode) { visitedType.setTypeNode(typeNode); } - public static Type fromSemanticSymbol(Symbol symbol) { + @Nullable + public static Type fromSemanticSymbol(@Nullable Symbol symbol) { Type type = null; if (symbol instanceof TypeReferenceTypeSymbol typeReferenceTypeSymbol) { type = getEnumType(typeReferenceTypeSymbol, symbol); @@ -468,7 +473,7 @@ public static void clearParentSymbols() { clearVisitedTypeMap(); } - private static void setTypeInfo(String typeName, Symbol symbol, Type type) { + private static void setTypeInfo(@Nullable String typeName, Symbol symbol, Type type) { if (type != null && symbol.getName().isPresent() && symbol.getModule().isPresent()) { ModuleID moduleID = symbol.getModule().get().id(); type.typeInfo = new TypeInfo(symbol.getName().get(), moduleID.orgName(), moduleID.moduleName(), diff --git a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/TypeInfo.java b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/TypeInfo.java index 22f590477373..5217667526d3 100644 --- a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/TypeInfo.java +++ b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/TypeInfo.java @@ -18,6 +18,7 @@ package org.ballerinalang.diagramutil.connector.models.connector; import com.google.gson.annotations.Expose; +import org.jetbrains.annotations.Nullable; /** * TypeInfo model. @@ -34,7 +35,7 @@ public class TypeInfo { @Expose public String version; - public TypeInfo(String name, String orgName, String moduleName, String packageName, String version) { + public TypeInfo(String name, String orgName, String moduleName, @Nullable String packageName, String version) { this.name = name; this.orgName = orgName; this.moduleName = moduleName; diff --git a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/types/RecordType.java b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/types/RecordType.java index c02bbe9eb775..025dc05b2fcc 100644 --- a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/types/RecordType.java +++ b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/types/RecordType.java @@ -19,6 +19,7 @@ import com.google.gson.annotations.Expose; import org.ballerinalang.diagramutil.connector.models.connector.Type; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; @@ -43,7 +44,7 @@ public RecordType(List fields, Optional restType) { } } - public RecordType(List fields, Type restType) { + public RecordType(List fields, @Nullable Type restType) { this.typeName = "record"; this.fields = fields; this.restType = restType; diff --git a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/types/TableType.java b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/types/TableType.java index ff2f82778ce3..ed174816a1a4 100644 --- a/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/types/TableType.java +++ b/misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/types/TableType.java @@ -19,6 +19,7 @@ import com.google.gson.annotations.Expose; import org.ballerinalang.diagramutil.connector.models.connector.Type; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -36,7 +37,7 @@ public class TableType extends Type { @Expose public Type constraintType; - public TableType(Type rowType, List keys, Type constraintType) { + public TableType(Type rowType, @Nullable List keys, Type constraintType) { this.typeName = "table"; this.keys = keys; this.rowType = rowType; diff --git a/misc/docerina/src/main/java/module-info.java b/misc/docerina/src/main/java/module-info.java index 6621eb76b7a1..89af0cd94d16 100644 --- a/misc/docerina/src/main/java/module-info.java +++ b/misc/docerina/src/main/java/module-info.java @@ -9,4 +9,5 @@ requires io.ballerina.parser; requires io.ballerina.tools.api; requires okhttp3; + requires static org.jetbrains.annotations; } diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Annotation.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Annotation.java index cbbf49285bc9..bcc4e4495aab 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Annotation.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Annotation.java @@ -16,6 +16,7 @@ package org.ballerinalang.docgen.generator.model; import com.google.gson.annotations.Expose; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -29,7 +30,7 @@ public class Annotation extends Construct { public String attachmentPoints; public Annotation(String name, String description, List descriptionSections, boolean isDeprecated, - Type type, String attachmentPoints) { + @Nullable Type type, String attachmentPoints) { super(name, description, descriptionSections, isDeprecated); this.type = type; this.attachmentPoints = attachmentPoints; diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/AnnotationAttachment.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/AnnotationAttachment.java index a42067fb1b8b..af5666bcd3a8 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/AnnotationAttachment.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/AnnotationAttachment.java @@ -16,6 +16,7 @@ package org.ballerinalang.docgen.generator.model; import com.google.gson.annotations.Expose; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -30,7 +31,7 @@ public class AnnotationAttachment extends Construct { @Expose public String version; - public AnnotationAttachment(String name, String description, List descriptionSections, + public AnnotationAttachment(String name, String description, @Nullable List descriptionSections, boolean isDeprecated, String orgName, String moduleName, String version) { super(name, description, descriptionSections, isDeprecated); diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/BClass.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/BClass.java index 1f9c0d991952..4e9fa7898b41 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/BClass.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/BClass.java @@ -16,6 +16,7 @@ package org.ballerinalang.docgen.generator.model; import com.google.gson.annotations.Expose; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; @@ -31,6 +32,7 @@ public class BClass extends Construct { public List fields; @Expose public List methods; + @Nullable @Expose public Function initMethod; @Expose diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/BType.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/BType.java index ca9eaf24423c..70e476c90cda 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/BType.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/BType.java @@ -15,6 +15,8 @@ */ package org.ballerinalang.docgen.generator.model; +import org.jetbrains.annotations.Nullable; + import java.util.List; /** @@ -22,7 +24,7 @@ */ public class BType extends Type { public BType(String name, String description, List descriptionSections, boolean isDeprecated, - List memberTypes) { + @Nullable List memberTypes) { super(name, description, descriptionSections, isDeprecated); this.memberTypes = memberTypes; } diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Construct.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Construct.java index f9a8671fe9af..287fb65acf0a 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Construct.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Construct.java @@ -16,6 +16,7 @@ package org.ballerinalang.docgen.generator.model; import com.google.gson.annotations.Expose; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -31,6 +32,7 @@ public class Construct { public List descriptionSections; @Expose public boolean isDeprecated; + @Nullable @Expose public Type inclusionType = null; @Expose diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Error.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Error.java index 7705d1edb38e..55efeb2b6c6e 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Error.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Error.java @@ -16,6 +16,7 @@ package org.ballerinalang.docgen.generator.model; import com.google.gson.annotations.Expose; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -29,7 +30,7 @@ public class Error extends Construct { public boolean isDistinct; public Error(String name, String description, List descriptionSections, boolean isDeprecated, - Type detailType) { + @Nullable Type detailType) { super(name, description, descriptionSections, isDeprecated); this.detailType = detailType; } diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/MapType.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/MapType.java index 3d3756d1ebe0..bef275f222fc 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/MapType.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/MapType.java @@ -18,6 +18,7 @@ package org.ballerinalang.docgen.generator.model; import com.google.gson.annotations.Expose; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -29,7 +30,7 @@ public class MapType extends Construct { public Type mapParameterType; public MapType(String name, String description, List descriptionSections, boolean isDeprecated, - Type mapParameterType) { + @Nullable Type mapParameterType) { super(name, description, descriptionSections, isDeprecated); this.mapParameterType = mapParameterType; } diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/TableType.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/TableType.java index c799ebadac0f..109cf4d23877 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/TableType.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/TableType.java @@ -18,6 +18,7 @@ package org.ballerinalang.docgen.generator.model; import com.google.gson.annotations.Expose; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -31,7 +32,7 @@ public class TableType extends Construct { public Type keyConstraint; public TableType(String name, String description, List descriptionSections, boolean isDeprecated, - Type rowParameterType, Type keyConstraint) { + @Nullable Type rowParameterType, @Nullable Type keyConstraint) { super(name, description, descriptionSections, isDeprecated); this.rowParameterType = rowParameterType; this.keyConstraint = keyConstraint; diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Type.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Type.java index 423105fc1b9e..209545ab3149 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Type.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Type.java @@ -71,6 +71,7 @@ import org.ballerinalang.docgen.docs.utils.BallerinaDocUtils; import org.ballerinalang.docgen.generator.model.types.FunctionType; import org.ballerinalang.docgen.generator.model.types.ObjectType; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -89,8 +90,10 @@ public class Type { public String moduleName; @Expose public String version; + @Nullable @Expose public String name; + @Nullable @Expose public String description; @Expose @@ -127,6 +130,7 @@ public class Type { public List memberTypes = new ArrayList<>(); @Expose public int arrayDimensions; + @Nullable @Expose public Type elementType; @Expose @@ -327,9 +331,9 @@ public static Type fromNode(Node node, SemanticModel semanticModel, Module modul return type; } - public static Type fromSemanticSymbol(Symbol symbol, Optional documentation, - TypeReferenceTypeSymbol parentTypeRefSymbol, boolean isTypeInclusion, - Module module) { + public static Type fromSemanticSymbol( + Symbol symbol, Optional documentation, + @Nullable TypeReferenceTypeSymbol parentTypeRefSymbol, boolean isTypeInclusion, Module module) { Type type = new Type(); if (symbol instanceof TypeReferenceTypeSymbol typeReferenceTypeSymbol) { Symbol typeDefinition = typeReferenceTypeSymbol.definition(); diff --git a/misc/formatter/modules/formatter-cli/src/main/java/module-info.java b/misc/formatter/modules/formatter-cli/src/main/java/module-info.java index 762a4c9a938a..42d32147a628 100644 --- a/misc/formatter/modules/formatter-cli/src/main/java/module-info.java +++ b/misc/formatter/modules/formatter-cli/src/main/java/module-info.java @@ -3,4 +3,5 @@ requires io.ballerina.cli; requires info.picocli; requires io.ballerina.formatter.core; + requires static org.jetbrains.annotations; } diff --git a/misc/formatter/modules/formatter-cli/src/main/java/org/ballerinalang/formatter/cli/FormatUtil.java b/misc/formatter/modules/formatter-cli/src/main/java/org/ballerinalang/formatter/cli/FormatUtil.java index 79219f668fe1..828011d4fe16 100644 --- a/misc/formatter/modules/formatter-cli/src/main/java/org/ballerinalang/formatter/cli/FormatUtil.java +++ b/misc/formatter/modules/formatter-cli/src/main/java/org/ballerinalang/formatter/cli/FormatUtil.java @@ -29,6 +29,7 @@ import org.ballerinalang.formatter.core.FormatterException; import org.ballerinalang.formatter.core.FormatterUtils; import org.ballerinalang.formatter.core.options.FormattingOptions; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileOutputStream; @@ -61,8 +62,8 @@ private FormatUtil() { * @param dryRun run the whole formatting * @param sourceRootPath execution path */ - static void execute(List argList, boolean helpFlag, String moduleName, String fileName, boolean dryRun, - Path sourceRootPath) { + static void execute(@Nullable List argList, boolean helpFlag, @Nullable String moduleName, + @Nullable String fileName, boolean dryRun, @Nullable Path sourceRootPath) { if (helpFlag) { String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(CMD_NAME); outStream.println(commandUsageInfo); @@ -350,6 +351,7 @@ private static BuildOptions constructBuildOptions() { * @param moduleNamePart module name part * @return {@link Boolean} true or false */ + @Nullable private static ModuleId isModuleExist(BuildProject project, String moduleNamePart) { ModuleName moduleName = ModuleName.from(project.currentPackage().packageName(), moduleNamePart); for (Module module : project.currentPackage().modules()) { diff --git a/misc/formatter/modules/formatter-core/src/main/java/module-info.java b/misc/formatter/modules/formatter-core/src/main/java/module-info.java index 5df52a1830d6..a838a689caf7 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/module-info.java +++ b/misc/formatter/modules/formatter-core/src/main/java/module-info.java @@ -5,6 +5,7 @@ requires io.ballerina.tools.api; requires org.apache.commons.lang3; requires org.slf4j; + requires static org.jetbrains.annotations; exports org.ballerinalang.formatter.core; exports org.ballerinalang.formatter.core.options; diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/Formatter.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/Formatter.java index 95b693774b72..6afd3effef01 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/Formatter.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/Formatter.java @@ -54,6 +54,7 @@ import io.ballerina.tools.text.TextDocument; import io.ballerina.tools.text.TextDocuments; import org.ballerinalang.formatter.core.options.FormattingOptions; +import org.jetbrains.annotations.Nullable; /** * Class that exposes the formatting APIs. @@ -189,7 +190,7 @@ public static String formatExpression(String text) throws FormatterException { return formattedNode.toSourceCode().strip(); } - private static SyntaxTree modifyTree(SyntaxTree syntaxTree, FormattingOptions options, LineRange range) + private static SyntaxTree modifyTree(SyntaxTree syntaxTree, FormattingOptions options, @Nullable LineRange range) throws FormatterException { FormattingTreeModifier treeModifier = new FormattingTreeModifier(options, range); ModulePartNode modulePartNode = syntaxTree.rootNode(); diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingEnv.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingEnv.java index 8a77a7ef96bb..e9725f252383 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingEnv.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingEnv.java @@ -18,6 +18,7 @@ package org.ballerinalang.formatter.core; import io.ballerina.compiler.syntax.tree.Node; +import org.jetbrains.annotations.Nullable; /** * Environment that holds a set of properties related to the currently formatting node. @@ -94,5 +95,5 @@ public class FormattingEnv { /** * Reference to the next node that needs to be wrapped. */ - Node nodeToWrap = null; + @Nullable Node nodeToWrap = null; } diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java index 206307d1099a..c41ebab012d6 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java @@ -256,6 +256,7 @@ import org.ballerinalang.formatter.core.options.FunctionCallFormattingOptions; import org.ballerinalang.formatter.core.options.FunctionDefFormattingOptions; import org.ballerinalang.formatter.core.options.WrappingMethod; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -291,7 +292,7 @@ public class FormattingTreeModifier extends TreeModifier { // Range of the file to be formatted. private final LineRange lineRange; - public FormattingTreeModifier(FormattingOptions options, LineRange lineRange) { + public FormattingTreeModifier(FormattingOptions options, @Nullable LineRange lineRange) { this.options = options; this.lineRange = lineRange; this.env = new FormattingEnv(); @@ -3830,8 +3831,10 @@ public Token transform(Token token) { * @param preserveIndentation Preserve user-defined indentation * @return Formatted node */ + @Nullable @SuppressWarnings("unchecked") - private T formatNode(T node, int trailingWS, int trailingNL, Boolean preserveIndentation) { + private T formatNode(T node, int trailingWS, int trailingNL, + @Nullable Boolean preserveIndentation) { try { if (node == null) { return null; @@ -3883,7 +3886,7 @@ private T formatNode(T node, int trailingWS, int trailingNL, Bo * @return Formatted node */ @SuppressWarnings("unchecked") - private T formatNode(T node, int trailingWS, int trailingNL) { + private T formatNode(@Nullable T node, int trailingWS, int trailingNL) { return formatNode(node, trailingWS, trailingNL, null); } @@ -3897,7 +3900,9 @@ private T formatNode(T node, int trailingWS, int trailingNL) { * @param preserveIndentation Preserve user-defined indentation * @return Formatted token */ - private T formatToken(T token, int trailingWS, int trailingNL, Boolean preserveIndentation) { + @Nullable + private T formatToken(T token, int trailingWS, int trailingNL, + @Nullable Boolean preserveIndentation) { try { if (token == null) { return null; @@ -3948,7 +3953,7 @@ private T formatToken(T token, int trailingWS, int trailingNL, * @param trailingNL Number of newlines to be added after the token * @return Formatted token */ - private T formatToken(T token, int trailingWS, int trailingNL) { + private T formatToken(@Nullable T token, int trailingWS, int trailingNL) { return formatToken(token, trailingWS, trailingNL, null); } @@ -4476,7 +4481,7 @@ private void addWhitespace(int wsLength, List minutiaeList) { * @param prevMinutiae Minutiae that precedes the current token * @return true if a whitespace needs to be added. false otherwise */ - private boolean shouldAddWS(Minutiae prevMinutiae) { + private boolean shouldAddWS(@Nullable Minutiae prevMinutiae) { if (prevMinutiae == null) { return false; } @@ -4898,7 +4903,7 @@ private boolean hasTrailingNL(Token token) { return false; } - private boolean matchesMinutiaeKind(Minutiae minutiae, SyntaxKind kind) { + private boolean matchesMinutiaeKind(@Nullable Minutiae minutiae, SyntaxKind kind) { return minutiae != null && minutiae.kind() == kind; } diff --git a/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java b/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java index f050ed7adc72..c0fe2f4381e9 100644 --- a/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java +++ b/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java @@ -19,6 +19,7 @@ package io.ballerina.identifier; import org.apache.commons.text.StringEscapeUtils; +import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -109,6 +110,7 @@ private static Identifier encodeGeneratedName(String identifier) { return new Identifier(sb.toString(), isEncoded); } + @Nullable private static String getFormattedStringForQuotedIdentifiers(char c) { if (c == '$') { return "0036"; @@ -116,6 +118,7 @@ private static String getFormattedStringForQuotedIdentifiers(char c) { return getFormattedStringForJvmReservedSet(c); } + @Nullable private static String getFormattedStringForJvmReservedSet(char c) { return switch (c) { case '\\' -> "0092"; @@ -137,7 +140,8 @@ private static String getFormattedStringForJvmReservedSet(char c) { * @param encodedIdentifier encoded identifier string * @return decoded identifier */ - public static String decodeIdentifier(String encodedIdentifier) { + @Nullable + public static String decodeIdentifier(@Nullable String encodedIdentifier) { if (encodedIdentifier == null) { return null; } diff --git a/misc/identifier-util/src/main/java/module-info.java b/misc/identifier-util/src/main/java/module-info.java index 1313fcb2f8bb..b6d33e94d537 100644 --- a/misc/identifier-util/src/main/java/module-info.java +++ b/misc/identifier-util/src/main/java/module-info.java @@ -1,6 +1,7 @@ module io.ballerina.identifier { requires org.apache.commons.text; + requires static org.jetbrains.annotations; exports io.ballerina.identifier to io.ballerina.lang, io.ballerina.runtime, io.ballerina.shell, io.ballerina.testerina.runtime, io.ballerina.lang.runtime, io.ballerina.lang.error, diff --git a/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/JsonToRecordMapper.java b/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/JsonToRecordMapper.java index 584ea951f097..10460b007dec 100644 --- a/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/JsonToRecordMapper.java +++ b/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/JsonToRecordMapper.java @@ -53,6 +53,7 @@ import org.ballerinalang.formatter.core.options.ForceFormattingOptions; import org.ballerinalang.formatter.core.options.FormattingOptions; import org.ballerinalang.langserver.commons.workspace.WorkspaceManager; +import org.jetbrains.annotations.Nullable; import java.util.AbstractMap; import java.util.ArrayList; @@ -104,9 +105,10 @@ private JsonToRecordMapper() {} * @return {@link JsonToRecordResponse} Ballerina code block or the Diagnostics */ @Deprecated - public static JsonToRecordResponse convert(String jsonString, String recordName, boolean isRecordTypeDesc, - boolean isClosed, boolean forceFormatRecordFields, String filePathUri, - WorkspaceManager workspaceManager) { + public static JsonToRecordResponse convert( + String jsonString, @Nullable String recordName, boolean isRecordTypeDesc, + boolean isClosed, boolean forceFormatRecordFields, @Nullable String filePathUri, + @Nullable WorkspaceManager workspaceManager) { return convert(jsonString, recordName, isRecordTypeDesc, isClosed, forceFormatRecordFields, filePathUri, workspaceManager, false); } @@ -124,9 +126,10 @@ public static JsonToRecordResponse convert(String jsonString, String recordName, * @param isNullAsOptional To denote whether the null values in the JSON should be considered as optional fields * @return {@link JsonToRecordResponse} Ballerina code block or the Diagnostics */ - public static JsonToRecordResponse convert(String jsonString, String recordName, boolean isRecordTypeDesc, - boolean isClosed, boolean forceFormatRecordFields, String filePathUri, - WorkspaceManager workspaceManager, boolean isNullAsOptional) { + public static JsonToRecordResponse convert( + String jsonString, String recordName, boolean isRecordTypeDesc, boolean isClosed, + boolean forceFormatRecordFields, @Nullable String filePathUri, + @Nullable WorkspaceManager workspaceManager, boolean isNullAsOptional) { List existingFieldNames = getExistingTypeNames(workspaceManager, filePathUri); Map updatedFieldNames = new HashMap<>(); Map recordToTypeDescNodes = new LinkedHashMap<>(); @@ -229,8 +232,8 @@ public static JsonToRecordResponse convert(String jsonString, String recordName, * @param diagnosticMessages The list of diagnostic messages generated by the method * @param isNullAsOptional To denote whether the null values in the JSON should be considered as optional fields */ - private static void generateRecords(JsonObject jsonObject, String recordName, boolean isClosed, - Map recordToTypeDescNodes, String moveBefore, + private static void generateRecords(JsonObject jsonObject, @Nullable String recordName, boolean isClosed, + Map recordToTypeDescNodes, @Nullable String moveBefore, Map jsonNodes, List existingFieldNames, Map updatedFieldNames, @@ -295,7 +298,7 @@ private static void generateRecords(JsonObject jsonObject, String recordName, bo private static void generateRecordForObjAndArray(JsonElement jsonElement, String elementKey, boolean isClosed, Map recordToTypeDescNodes, - String moveBefore, Map jsonNodes, + @Nullable String moveBefore, Map jsonNodes, List existingFieldNames, Map updatedFieldNames, List diagnosticMessages, @@ -679,8 +682,9 @@ private static TypeDescriptorNode joinToUnionTypeDescriptorNode(List + Map visitedRecordTypeDescNodeTypeToNodes) { List extractedTypeDescNodes = extractUnionTypeDescNode(extractArrayTypeDescNode(typeDescNode)); diff --git a/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/diagnostic/DiagnosticMessage.java b/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/diagnostic/DiagnosticMessage.java index cd2f5b3bef20..52bcb076a311 100644 --- a/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/diagnostic/DiagnosticMessage.java +++ b/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/diagnostic/DiagnosticMessage.java @@ -19,6 +19,7 @@ package io.ballerina.jsonmapper.diagnostic; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Objects; @@ -35,7 +36,7 @@ public final class DiagnosticMessage { private final DiagnosticSeverity severity; private final Object[] args; - private DiagnosticMessage(String code, String description, DiagnosticSeverity severity, Object[] args) { + private DiagnosticMessage(String code, String description, DiagnosticSeverity severity, @Nullable Object[] args) { this.code = code; this.description = description; this.severity = severity; @@ -58,7 +59,7 @@ public Object[] getArgs() { return Objects.requireNonNullElse(this.args, new Object[0]).clone(); } - public static DiagnosticMessage jsonToRecordConverter100(Object[] args) { + public static DiagnosticMessage jsonToRecordConverter100(@Nullable Object[] args) { if (args != null) { return new DiagnosticMessage("JSON_TO_RECORD_CONVERTER_100", String.format("Provided JSON is invalid : %s", DiagnosticUtils. @@ -69,12 +70,12 @@ public static DiagnosticMessage jsonToRecordConverter100(Object[] args) { "Provided JSON is invalid.", DiagnosticSeverity.ERROR, null); } - public static DiagnosticMessage jsonToRecordConverter101(Object[] args) { + public static DiagnosticMessage jsonToRecordConverter101(@Nullable Object[] args) { return new DiagnosticMessage("JSON_TO_RECORD_CONVERTER_101", "Provided JSON is unsupported. It may be null or have missing types.", DiagnosticSeverity.ERROR, args); } - public static DiagnosticMessage jsonToRecordConverter102(Object[] args) { + public static DiagnosticMessage jsonToRecordConverter102(@Nullable Object[] args) { return new DiagnosticMessage("JSON_TO_RECORD_CONVERTER_102", "Error occurred while formatting the Ballerina syntax tree.", DiagnosticSeverity.ERROR, args); } diff --git a/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/diagnostic/JsonToRecordMapperDiagnostic.java b/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/diagnostic/JsonToRecordMapperDiagnostic.java index 934784418d76..d9eb524be2e3 100644 --- a/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/diagnostic/JsonToRecordMapperDiagnostic.java +++ b/misc/json-to-record-converter/src/main/java/io/ballerina/jsonmapper/diagnostic/JsonToRecordMapperDiagnostic.java @@ -23,6 +23,7 @@ import io.ballerina.tools.diagnostics.DiagnosticProperty; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import java.text.MessageFormat; import java.util.Collections; @@ -42,7 +43,7 @@ public class JsonToRecordMapperDiagnostic extends Diagnostic { private final String severity; public JsonToRecordMapperDiagnostic(String code, String message, DiagnosticSeverity severity, - Location location, Object[] args) { + @Nullable Location location, Object[] args) { this.diagnosticInfo = new DiagnosticInfo(code, message, severity); this.location = location; this.properties = Collections.emptyList(); diff --git a/misc/json-to-record-converter/src/main/java/module-info.java b/misc/json-to-record-converter/src/main/java/module-info.java index bf6dab0ba43b..74bc67d0b962 100644 --- a/misc/json-to-record-converter/src/main/java/module-info.java +++ b/misc/json-to-record-converter/src/main/java/module-info.java @@ -7,6 +7,7 @@ requires io.ballerina.parser; requires io.ballerina.tools.api; requires org.apache.commons.lang3; + requires static org.jetbrains.annotations; exports io.ballerina.jsonmapper; exports io.ballerina.jsonmapper.diagnostic; diff --git a/misc/ls-extensions/modules/bal-shell-service/src/main/java/io/ballerina/shell/service/BalShellGetResultResponse.java b/misc/ls-extensions/modules/bal-shell-service/src/main/java/io/ballerina/shell/service/BalShellGetResultResponse.java index aa42454cb929..8de0e2dfc1ba 100644 --- a/misc/ls-extensions/modules/bal-shell-service/src/main/java/io/ballerina/shell/service/BalShellGetResultResponse.java +++ b/misc/ls-extensions/modules/bal-shell-service/src/main/java/io/ballerina/shell/service/BalShellGetResultResponse.java @@ -19,6 +19,7 @@ import io.ballerina.shell.Diagnostic; import io.ballerina.shell.DiagnosticKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -30,9 +31,11 @@ * @since 2201.1.1 */ public class BalShellGetResultResponse { + @Nullable private ShellValue shellValue; private final ArrayList errors; private final ArrayList diagnostics; + @Nullable private MetaInfo metaInfo; private String consoleOut; diff --git a/misc/ls-extensions/modules/bal-shell-service/src/main/java/module-info.java b/misc/ls-extensions/modules/bal-shell-service/src/main/java/module-info.java index a578bfd33be0..e1de78bb73d6 100644 --- a/misc/ls-extensions/modules/bal-shell-service/src/main/java/module-info.java +++ b/misc/ls-extensions/modules/bal-shell-service/src/main/java/module-info.java @@ -13,6 +13,7 @@ requires io.ballerina.shell; requires io.ballerina.shell.cli; requires com.fasterxml.jackson.databind; + requires static org.jetbrains.annotations; exports io.ballerina.shell.service; } diff --git a/misc/ls-extensions/modules/json-to-record-converter/src/main/java/io/ballerina/converters/JsonToRecordConverter.java b/misc/ls-extensions/modules/json-to-record-converter/src/main/java/io/ballerina/converters/JsonToRecordConverter.java index bb06a4b24ecb..fada114a45fa 100644 --- a/misc/ls-extensions/modules/json-to-record-converter/src/main/java/io/ballerina/converters/JsonToRecordConverter.java +++ b/misc/ls-extensions/modules/json-to-record-converter/src/main/java/io/ballerina/converters/JsonToRecordConverter.java @@ -54,6 +54,7 @@ import org.ballerinalang.formatter.core.FormatterException; import org.ballerinalang.formatter.core.options.ForceFormattingOptions; import org.ballerinalang.formatter.core.options.FormattingOptions; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.ArrayList; @@ -405,8 +406,8 @@ private static TypeDescriptorNode extractOpenApiSchema( return createBuiltinSimpleNameReferenceNode(null, typeName); } - private static ArrayTypeDescriptorNode createArrayTypeDesc(TypeDescriptorNode memberTypeDesc, - Token openBracketToken, Node arrayLengthNode, + private static ArrayTypeDescriptorNode createArrayTypeDesc(TypeDescriptorNode memberTypeDesc, + Token openBracketToken, @Nullable Node arrayLengthNode, Token closeBracketToken) { NodeList arrayDimensions = NodeFactory.createEmptyNodeList(); if (memberTypeDesc.kind() == SyntaxKind.ARRAY_TYPE_DESC) { diff --git a/misc/ls-extensions/modules/json-to-record-converter/src/main/java/io/ballerina/converters/JsonToRecordRequest.java b/misc/ls-extensions/modules/json-to-record-converter/src/main/java/io/ballerina/converters/JsonToRecordRequest.java index 9908ff4d11d0..c883aa0315f2 100644 --- a/misc/ls-extensions/modules/json-to-record-converter/src/main/java/io/ballerina/converters/JsonToRecordRequest.java +++ b/misc/ls-extensions/modules/json-to-record-converter/src/main/java/io/ballerina/converters/JsonToRecordRequest.java @@ -17,6 +17,8 @@ */ package io.ballerina.converters; +import org.jetbrains.annotations.Nullable; + /** * Request format for JsonToBalRecord endpoint. * @@ -33,8 +35,9 @@ public class JsonToRecordRequest { private final boolean isNullAsOptional; - public JsonToRecordRequest(String jsonString, String recordName, boolean isRecordTypeDesc, boolean isClosed, - boolean forceFormatRecordFields, String filePathUri, boolean isNullAsOptional) { + public JsonToRecordRequest( + String jsonString, @Nullable String recordName, boolean isRecordTypeDesc, boolean isClosed, + boolean forceFormatRecordFields, @Nullable String filePathUri, boolean isNullAsOptional) { this.jsonString = jsonString; this.recordName = recordName; this.isRecordTypeDesc = isRecordTypeDesc; diff --git a/misc/ls-extensions/modules/json-to-record-converter/src/main/java/module-info.java b/misc/ls-extensions/modules/json-to-record-converter/src/main/java/module-info.java index 2db7c1c24c37..de18a5152565 100644 --- a/misc/ls-extensions/modules/json-to-record-converter/src/main/java/module-info.java +++ b/misc/ls-extensions/modules/json-to-record-converter/src/main/java/module-info.java @@ -20,6 +20,7 @@ requires swagger.parser.core; requires swagger.parser.v3; requires org.eclipse.lsp4j; + requires static org.jetbrains.annotations; exports io.ballerina.converters; exports io.ballerina.converters.util; diff --git a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ActionInvocationNode.java b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ActionInvocationNode.java index ee991a0c474c..62f33d7dc123 100644 --- a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ActionInvocationNode.java +++ b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ActionInvocationNode.java @@ -19,6 +19,7 @@ package io.ballerina.component; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nullable; /** * model obj to store action invocations. @@ -32,7 +33,7 @@ public class ActionInvocationNode extends Node { private final String path; private final String pos; - public ActionInvocationNode(String endPointRef, String name, String path, String pos) { + public ActionInvocationNode(String endPointRef, String name, @Nullable String path, String pos) { this.endPointRef = endPointRef; this.name = name; diff --git a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/EndPointNode.java b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/EndPointNode.java index 445961b7f998..3c9c07173e3d 100644 --- a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/EndPointNode.java +++ b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/EndPointNode.java @@ -19,6 +19,7 @@ package io.ballerina.component; import io.ballerina.tools.text.LineRange; +import org.jetbrains.annotations.Nullable; /** * model obj to store endpoints. @@ -32,7 +33,7 @@ public class EndPointNode { private final String baseUrl; private final LineRange pos; - public EndPointNode(String pkgID, String name, String baseUrl, LineRange pos) { + public EndPointNode(String pkgID, String name, @Nullable String baseUrl, LineRange pos) { this.pkgID = pkgID; this.name = name; diff --git a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ForStatementNode.java b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ForStatementNode.java index 3c11064f8ac0..3f583e1579a3 100644 --- a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ForStatementNode.java +++ b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ForStatementNode.java @@ -18,6 +18,8 @@ package io.ballerina.component; +import org.jetbrains.annotations.Nullable; + /** * models for statement nodes. * @@ -26,6 +28,7 @@ public class ForStatementNode extends Node { private final long length; + @Nullable private Node forBody; public ForStatementNode(long length) { diff --git a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/IfStatementNode.java b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/IfStatementNode.java index 2f96ab02f6a2..2188b152c48e 100644 --- a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/IfStatementNode.java +++ b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/IfStatementNode.java @@ -18,6 +18,8 @@ package io.ballerina.component; +import org.jetbrains.annotations.Nullable; + /** * models if statement nodes. * @@ -25,7 +27,9 @@ */ public class IfStatementNode extends Node { + @Nullable private Node ifBody; + @Nullable private Node elseBody; public IfStatementNode() { diff --git a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/Node.java b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/Node.java index 99bb67e0dbd3..1b6d83deed09 100644 --- a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/Node.java +++ b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/Node.java @@ -18,6 +18,8 @@ package io.ballerina.component; +import org.jetbrains.annotations.Nullable; + /** * base class to handle essential AST nodes. * @@ -32,7 +34,7 @@ public Node getNextNode() { return nextNode; } - public void setNextNode(Node nextNode) { + public void setNextNode(@Nullable Node nextNode) { this.nextNode = nextNode; } diff --git a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ReturningActionInvocationNode.java b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ReturningActionInvocationNode.java index a0ddc11b5075..3fd595d43362 100644 --- a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ReturningActionInvocationNode.java +++ b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/component/ReturningActionInvocationNode.java @@ -18,6 +18,8 @@ package io.ballerina.component; +import org.jetbrains.annotations.Nullable; + /** * models if statement nodes. * @@ -27,7 +29,8 @@ public class ReturningActionInvocationNode extends ActionInvocationNode { private boolean hasReturn; - public ReturningActionInvocationNode(String endPointRef, String name, String path, String pos, boolean hasReturn) { + public ReturningActionInvocationNode( + String endPointRef, String name, @Nullable String path, String pos, boolean hasReturn) { super(endPointRef, name, path, pos); this.hasReturn = hasReturn; diff --git a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/utils/ParserUtil.java b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/utils/ParserUtil.java index 67218055b519..7ee8ad9c102e 100644 --- a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/utils/ParserUtil.java +++ b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/io/ballerina/utils/ParserUtil.java @@ -17,6 +17,7 @@ import io.ballerina.component.IfStatementNode; import io.ballerina.component.Node; import org.ballerinalang.model.symbols.SymbolKind; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol; @@ -105,6 +106,7 @@ public static boolean isClientObject(BSymbol bSymbol) { return false; } + @Nullable private static BType isClientType(BType type) { if (type instanceof BUnionType bUnionType) { @@ -123,6 +125,7 @@ private static BType isClientType(BType type) { return null; } + @Nullable public static BLangExpression getURLExpressionFromArgs(BLangTypeInit connectorInitExpr) { BSymbol bSymbol = ((BLangInvocation) connectorInitExpr.initInvocation).symbol; @@ -139,6 +142,7 @@ public static BLangExpression getURLExpressionFromArgs(BLangTypeInit connectorIn return null; } + @Nullable public static BLangExpression getPathExpressionFromArgs(BLangInvocation actionInvocation) { BSymbol bSymbol = actionInvocation.symbol; diff --git a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/module-info.java b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/module-info.java index ca6c7f0802cb..f05944aa118c 100644 --- a/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/module-info.java +++ b/misc/ls-extensions/modules/performance-analyzer-services/src/main/java/module-info.java @@ -14,4 +14,5 @@ requires com.google.gson; requires org.apache.commons.lang3; requires java.net.http; + requires static org.jetbrains.annotations; } diff --git a/misc/maven-resolver/src/main/java/org/ballerinalang/maven/MavenResolver.java b/misc/maven-resolver/src/main/java/org/ballerinalang/maven/MavenResolver.java index 260c8a1fb736..cf4eb5357bf7 100644 --- a/misc/maven-resolver/src/main/java/org/ballerinalang/maven/MavenResolver.java +++ b/misc/maven-resolver/src/main/java/org/ballerinalang/maven/MavenResolver.java @@ -47,6 +47,7 @@ import org.eclipse.aether.util.filter.DependencyFilterUtils; import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor; import org.eclipse.aether.util.repository.AuthenticationBuilder; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.ArrayList; @@ -107,7 +108,7 @@ public void addRepository(String id, String url) { * @param username username which has authentication access * @param password password which has authentication access */ - public void addRepository(String id, String url, String username, String password) { + public void addRepository(String id, String url, @Nullable String username, String password) { Authentication authentication = new AuthenticationBuilder() .addUsername(username) diff --git a/misc/metrics-extensions/modules/ballerina-metrics-extension/src/main/java/module-info.java b/misc/metrics-extensions/modules/ballerina-metrics-extension/src/main/java/module-info.java index e30d7bba7261..f14f885eae2b 100644 --- a/misc/metrics-extensions/modules/ballerina-metrics-extension/src/main/java/module-info.java +++ b/misc/metrics-extensions/modules/ballerina-metrics-extension/src/main/java/module-info.java @@ -1,6 +1,7 @@ module io.ballerina.observe.metrics.extension.defaultimpl { requires io.ballerina.runtime; requires HdrHistogram; + requires static org.jetbrains.annotations; exports org.ballerinalang.observe.metrics.extension.defaultimpl; } diff --git a/misc/metrics-extensions/modules/ballerina-metrics-extension/src/main/java/org/ballerinalang/observe/metrics/extension/defaultimpl/DefaultCounter.java b/misc/metrics-extensions/modules/ballerina-metrics-extension/src/main/java/org/ballerinalang/observe/metrics/extension/defaultimpl/DefaultCounter.java index 020fc1bf89eb..a838b8a9f46a 100644 --- a/misc/metrics-extensions/modules/ballerina-metrics-extension/src/main/java/org/ballerinalang/observe/metrics/extension/defaultimpl/DefaultCounter.java +++ b/misc/metrics-extensions/modules/ballerina-metrics-extension/src/main/java/org/ballerinalang/observe/metrics/extension/defaultimpl/DefaultCounter.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.observability.metrics.AbstractMetric; import io.ballerina.runtime.observability.metrics.Counter; import io.ballerina.runtime.observability.metrics.MetricId; +import org.jetbrains.annotations.Nullable; import java.util.concurrent.atomic.LongAdder; @@ -30,7 +31,7 @@ public class DefaultCounter extends AbstractMetric implements Counter { private final LongAdder count = new LongAdder(); - public DefaultCounter(MetricId id) { + public DefaultCounter(@Nullable MetricId id) { super(id); } diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/SemverChecker.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/SemverChecker.java index 5ca19ce2ab6e..c9d2ff2148f0 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/SemverChecker.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/SemverChecker.java @@ -27,6 +27,7 @@ import io.ballerina.semver.checker.util.DiffUtils; import io.ballerina.semver.checker.util.PackageUtils; import io.ballerina.tools.diagnostics.Diagnostic; +import org.jetbrains.annotations.Nullable; import java.io.PrintStream; import java.nio.file.Path; @@ -48,7 +49,7 @@ public class SemverChecker { private final PrintStream outStream; private final PrintStream errStream; - public SemverChecker(Path projectPath, SemanticVersion releaseVersion, PrintStream out, PrintStream err) { + public SemverChecker(Path projectPath, @Nullable SemanticVersion releaseVersion, PrintStream out, PrintStream err) { this.projectPath = projectPath; this.releaseVersion = releaseVersion; this.outStream = out; diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DocumentationComparator.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DocumentationComparator.java index 4481ef253052..224e695de425 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DocumentationComparator.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DocumentationComparator.java @@ -24,6 +24,7 @@ import io.ballerina.semver.checker.diff.NodeDiffBuilder; import io.ballerina.semver.checker.diff.NodeDiffImpl; import io.ballerina.semver.checker.diff.SemverImpact; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -34,7 +35,7 @@ */ public class DocumentationComparator extends NodeComparator { - public DocumentationComparator(Node newNode, Node oldNode) { + public DocumentationComparator(@Nullable Node newNode, @Nullable Node oldNode) { super(newNode, oldNode); } diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DumbNodeComparator.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DumbNodeComparator.java index 001842f57ed1..bb4357ba7293 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DumbNodeComparator.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DumbNodeComparator.java @@ -25,6 +25,7 @@ import io.ballerina.semver.checker.diff.NodeDiffImpl; import io.ballerina.semver.checker.diff.SemverImpact; import io.ballerina.semver.checker.util.SyntaxTreeUtils; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -41,11 +42,11 @@ public class DumbNodeComparator implements Comparator { private final T oldNode; private final DiffKind nodeKind; - DumbNodeComparator(T newNode, T oldNode) { + DumbNodeComparator(@Nullable T newNode, @Nullable T oldNode) { this(newNode, oldNode, null); } - DumbNodeComparator(T newNode, T oldNode, DiffKind nodeKind) { + DumbNodeComparator(@Nullable T newNode, @Nullable T oldNode, @Nullable DiffKind nodeKind) { this.newNode = newNode; this.oldNode = oldNode; this.nodeKind = nodeKind; diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DumbNodeListComparator.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DumbNodeListComparator.java index 3e34804c91c9..543158471cc7 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DumbNodeListComparator.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/DumbNodeListComparator.java @@ -24,6 +24,7 @@ import io.ballerina.semver.checker.diff.DiffType; import io.ballerina.semver.checker.diff.NodeListDiffImpl; import io.ballerina.semver.checker.diff.SemverImpact; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; @@ -48,17 +49,18 @@ public class DumbNodeListComparator implements Comparator { this(newNodes, oldNodes, null); } - DumbNodeListComparator(NodeList newNodes, NodeList oldNodes) { + DumbNodeListComparator(@Nullable NodeList newNodes, @Nullable NodeList oldNodes) { this(newNodes, oldNodes, null); } - DumbNodeListComparator(List newNodes, List oldNodes, DiffKind nodeKind) { + DumbNodeListComparator(List newNodes, List oldNodes, @Nullable DiffKind nodeKind) { this.newNodes = newNodes; this.oldNodes = oldNodes; this.nodeKind = nodeKind; } - DumbNodeListComparator(NodeList newNodes, NodeList oldNodes, DiffKind nodeKind) { + DumbNodeListComparator(@Nullable NodeList newNodes, @Nullable NodeList oldNodes, + @Nullable DiffKind nodeKind) { this.newNodes = newNodes != null ? newNodes.stream().toList() : null; this.oldNodes = oldNodes != null ? oldNodes.stream().toList() : null; this.nodeKind = nodeKind; diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/ParamComparator.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/ParamComparator.java index b07f18109cc5..8af7f15e92a8 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/ParamComparator.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/comparator/ParamComparator.java @@ -29,6 +29,7 @@ import io.ballerina.semver.checker.diff.NodeDiffBuilder; import io.ballerina.semver.checker.diff.NodeDiffImpl; import io.ballerina.semver.checker.diff.SemverImpact; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -128,6 +129,7 @@ private Optional compareParamKind(ParameterNode newParam, Parame return paramDiffBuilder.build(); } + @Nullable private Node getParamType(ParameterNode paramNode) { if (paramNode.kind() == SyntaxKind.REQUIRED_PARAM) { return ((RequiredParameterNode) paramNode).typeName(); diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ClassDiff.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ClassDiff.java index 3ce609ca0010..6199319f3b17 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ClassDiff.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ClassDiff.java @@ -20,6 +20,7 @@ import io.ballerina.compiler.syntax.tree.ClassDefinitionNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Optional; @@ -71,7 +72,7 @@ public static class Builder extends NodeDiffImpl.Builder { private final ClassDiff classDiff; - public Builder(ClassDefinitionNode newNode, ClassDefinitionNode oldNode) { + public Builder(@Nullable ClassDefinitionNode newNode, @Nullable ClassDefinitionNode oldNode) { super(newNode, oldNode); classDiff = new ClassDiff(newNode, oldNode); } diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/EnumDiff.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/EnumDiff.java index 580e2f76aa33..3606c10bb624 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/EnumDiff.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/EnumDiff.java @@ -20,6 +20,7 @@ import io.ballerina.compiler.syntax.tree.EnumDeclarationNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Optional; @@ -71,7 +72,7 @@ public static class Builder extends NodeDiffImpl.Builder { private final EnumDiff enumDiff; - public Builder(EnumDeclarationNode newNode, EnumDeclarationNode oldNode) { + public Builder(@Nullable EnumDeclarationNode newNode, @Nullable EnumDeclarationNode oldNode) { super(newNode, oldNode); enumDiff = new EnumDiff(newNode, oldNode); } diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/FunctionDiff.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/FunctionDiff.java index 4b7c4b94ee5e..840a82d9442e 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/FunctionDiff.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/FunctionDiff.java @@ -20,6 +20,7 @@ import io.ballerina.compiler.syntax.tree.FunctionDefinitionNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Optional; @@ -103,7 +104,7 @@ public static class Builder extends NodeDiffImpl.Builder private final FunctionDiff functionDiff; - public Builder(FunctionDefinitionNode newNode, FunctionDefinitionNode oldNode) { + public Builder(@Nullable FunctionDefinitionNode newNode, @Nullable FunctionDefinitionNode oldNode) { super(newNode, oldNode); functionDiff = new FunctionDiff(newNode, oldNode); } diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ModuleConstantDiff.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ModuleConstantDiff.java index 75c40ed41e11..c8643cd4f3e7 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ModuleConstantDiff.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ModuleConstantDiff.java @@ -20,6 +20,7 @@ import io.ballerina.compiler.syntax.tree.ConstantDeclarationNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Optional; @@ -71,7 +72,7 @@ public static class Builder extends NodeDiffImpl.Builder implements NodeDiff { protected DiffKind diffKind; protected SemverImpact versionImpact; protected final List childDiffs; + @Nullable protected String message; protected NodeDiffImpl(T newNode, T oldNode) { @@ -221,7 +223,7 @@ public static class Builder implements NodeDiffBuilder { private final NodeDiffImpl nodeDiff; - public Builder(T newNode, T oldNode) { + public Builder(@Nullable T newNode, @Nullable T oldNode) { nodeDiff = new NodeDiffImpl<>(newNode, oldNode); } diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/NodeListDiffImpl.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/NodeListDiffImpl.java index cbc359e39b3e..cf472cd5f3dc 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/NodeListDiffImpl.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/NodeListDiffImpl.java @@ -23,6 +23,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import io.ballerina.compiler.syntax.tree.Node; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -52,6 +53,7 @@ public class NodeListDiffImpl implements NodeListDiff> { protected DiffKind diffKind; protected SemverImpact versionImpact; protected final List childDiffs; + @Nullable private String message; private NodeListDiffImpl(List newNodes, List oldNodes) { @@ -250,6 +252,7 @@ public NodeDiffBuilder withChildDiff(Diff childDiff) { return this; } + @Nullable @Override public NodeDiffBuilder withChildDiffs(Collection childDiffs) { nodeListDiff.childDiffs.addAll(childDiffs); diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ObjectFieldDiff.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ObjectFieldDiff.java index 09047d3ecb32..f966cc764f86 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ObjectFieldDiff.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ObjectFieldDiff.java @@ -20,6 +20,7 @@ import io.ballerina.compiler.syntax.tree.ObjectFieldNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Optional; @@ -71,7 +72,7 @@ public static class Builder extends NodeDiffImpl.Builder { private final ObjectFieldDiff fieldDiff; - public Builder(ObjectFieldNode newNode, ObjectFieldNode oldNode) { + public Builder(@Nullable ObjectFieldNode newNode, @Nullable ObjectFieldNode oldNode) { super(newNode, oldNode); fieldDiff = new ObjectFieldDiff(newNode, oldNode); } diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ServiceDiff.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ServiceDiff.java index b4dd88e75a42..07e175915147 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ServiceDiff.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/ServiceDiff.java @@ -19,6 +19,7 @@ package io.ballerina.semver.checker.diff; import io.ballerina.compiler.syntax.tree.ServiceDeclarationNode; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Optional; @@ -41,7 +42,7 @@ public static class Builder extends NodeDiffImpl.Builder private final ServiceDiff serviceDiff; - public Builder(ServiceDeclarationNode newNode, ServiceDeclarationNode oldNode) { + public Builder(@Nullable ServiceDeclarationNode newNode, @Nullable ServiceDeclarationNode oldNode) { super(newNode, oldNode); serviceDiff = new ServiceDiff(newNode, oldNode); } diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/TypeDefinitionDiff.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/TypeDefinitionDiff.java index 226d107becc8..a78990cc436e 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/TypeDefinitionDiff.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/diff/TypeDefinitionDiff.java @@ -20,6 +20,7 @@ import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.compiler.syntax.tree.TypeDefinitionNode; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Optional; @@ -71,7 +72,7 @@ public static class Builder extends NodeDiffImpl.Builder { private final TypeDefinitionDiff typeDefDiff; - public Builder(TypeDefinitionNode newNode, TypeDefinitionNode oldNode) { + public Builder(@Nullable TypeDefinitionNode newNode, @Nullable TypeDefinitionNode oldNode) { super(newNode, oldNode); typeDefDiff = new TypeDefinitionDiff(newNode, oldNode); } diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/DiffUtils.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/DiffUtils.java index 0bbc9302b0b0..ae293d7f8b8b 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/DiffUtils.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/DiffUtils.java @@ -35,6 +35,7 @@ import io.ballerina.semver.checker.diff.SemverImpact; import io.ballerina.semver.checker.diff.ServiceDiff; import io.ballerina.semver.checker.diff.TypeDefinitionDiff; +import org.jetbrains.annotations.Nullable; import static io.ballerina.semver.checker.util.SemverUtils.calculateSuggestedVersion; @@ -65,7 +66,7 @@ private DiffUtils() { * @param previousVersion last published package version * @return the suggested version in string format */ - public static String getDiffSummary(PackageDiff packageDiff, SemanticVersion localVersion, + public static String getDiffSummary(@Nullable PackageDiff packageDiff, SemanticVersion localVersion, SemanticVersion previousVersion) { StringBuilder sb = new StringBuilder(); if (packageDiff == null) { @@ -92,7 +93,7 @@ public static String getDiffSummary(PackageDiff packageDiff, SemanticVersion loc * @param previousVersion last published package version * @return the suggested version in string format */ - public static String getVersionSuggestion(PackageDiff packageDiff, SemanticVersion localVersion, + public static String getVersionSuggestion(@Nullable PackageDiff packageDiff, SemanticVersion localVersion, SemanticVersion previousVersion) { StringBuilder sb = new StringBuilder(); sb.append(System.lineSeparator()); diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/SemverUtils.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/SemverUtils.java index d0c2c3efca14..f412abc39109 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/SemverUtils.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/io/ballerina/semver/checker/util/SemverUtils.java @@ -20,6 +20,7 @@ import io.ballerina.projects.SemanticVersion; import io.ballerina.semver.checker.diff.PackageDiff; +import org.jetbrains.annotations.Nullable; /** * Semantic versioning related utilities. @@ -34,7 +35,7 @@ public final class SemverUtils { private SemverUtils() { } - public static String calculateSuggestedVersion(SemanticVersion prevVersion, PackageDiff packageDiff) { + public static String calculateSuggestedVersion(SemanticVersion prevVersion, @Nullable PackageDiff packageDiff) { if (packageDiff == null) { return prevVersion.toString(); } else { diff --git a/misc/semver-checker/modules/semver-checker-core/src/main/java/module-info.java b/misc/semver-checker/modules/semver-checker-core/src/main/java/module-info.java index b6dbcb982a42..2285d5baa50c 100644 --- a/misc/semver-checker/modules/semver-checker-core/src/main/java/module-info.java +++ b/misc/semver-checker/modules/semver-checker-core/src/main/java/module-info.java @@ -5,6 +5,7 @@ requires io.ballerina.tools.api; requires com.google.gson; requires org.slf4j; + requires static org.jetbrains.annotations; exports io.ballerina.semver.checker to io.ballerina.semver.checker.cli; exports io.ballerina.semver.checker.exception to io.ballerina.semver.checker.cli; diff --git a/misc/syntax-api-calls-gen/src/main/java/io/ballerina/syntaxapicallsgen/segment/NodeFactorySegment.java b/misc/syntax-api-calls-gen/src/main/java/io/ballerina/syntaxapicallsgen/segment/NodeFactorySegment.java index 09b0cca70cbd..1a3e4e304267 100644 --- a/misc/syntax-api-calls-gen/src/main/java/io/ballerina/syntaxapicallsgen/segment/NodeFactorySegment.java +++ b/misc/syntax-api-calls-gen/src/main/java/io/ballerina/syntaxapicallsgen/segment/NodeFactorySegment.java @@ -18,6 +18,8 @@ package io.ballerina.syntaxapicallsgen.segment; +import org.jetbrains.annotations.Nullable; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -44,7 +46,7 @@ public class NodeFactorySegment extends Segment implements Iterable { protected final String genericType; private final List parameters; - public NodeFactorySegment(String methodName, String genericType) { + public NodeFactorySegment(String methodName, @Nullable String genericType) { this.methodName = methodName; this.parameters = new ArrayList<>(); this.genericType = genericType; diff --git a/misc/syntax-api-calls-gen/src/main/java/module-info.java b/misc/syntax-api-calls-gen/src/main/java/module-info.java index 39328b564278..8c405501599d 100644 --- a/misc/syntax-api-calls-gen/src/main/java/module-info.java +++ b/misc/syntax-api-calls-gen/src/main/java/module-info.java @@ -3,6 +3,7 @@ requires com.google.gson; requires io.ballerina.parser; requires io.ballerina.tools.api; + requires static org.jetbrains.annotations; exports io.ballerina.syntaxapicallsgen; exports io.ballerina.syntaxapicallsgen.config; diff --git a/misc/testerina/modules/testerina-core/src/main/java/module-info.java b/misc/testerina/modules/testerina-core/src/main/java/module-info.java index fac9e6aade4c..2be6bc1b760f 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/module-info.java +++ b/misc/testerina/modules/testerina-core/src/main/java/module-info.java @@ -7,4 +7,5 @@ requires io.ballerina.runtime; requires io.github.javadiffutils; requires com.google.gson; + requires static org.jetbrains.annotations; } diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java index 5829f91d5bb3..6ed62012f2d8 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java @@ -23,6 +23,7 @@ import org.wso2.ballerinalang.compiler.packaging.repo.Repo; import java.nio.file.Path; +import java.util.Objects; /** * This represents the standard Ballerina built-in system package repository provider. @@ -34,7 +35,7 @@ public class TesterinaSystemPackageRepositoryProvider implements SystemPackageRe @Override public Repo loadRepository() { - return new JarRepo(SystemPackageRepositoryProvider.getClassUri(this)); + return new JarRepo(Objects.requireNonNull(SystemPackageRepositoryProvider.getClassUri(this))); } } diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java index 656d70c443ab..8ff6a7b515fb 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java @@ -32,6 +32,7 @@ import org.ballerinalang.model.tree.SimpleVariableNode; import org.ballerinalang.model.tree.expressions.RecordLiteralNode; import org.ballerinalang.util.diagnostic.DiagnosticLog; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.PackageCache; import org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; @@ -314,6 +315,7 @@ private void setAnnotationValues(List fields, Str * @param moduleName Module name passed via function annotation * @return Module packageID */ + @Nullable private PackageID getPackageID(String moduleName) { if (packageCache.getSymbol(moduleName) != null) { return packageCache.getSymbol(moduleName).pkgID; @@ -350,8 +352,8 @@ private String formatPackageName(String value, BLangPackage parent) { * @param attachmentNode MockFunction object attachment node * @return true if the provided function name valid */ - private boolean isValidFunctionName(String functionName, String moduleName, PackageID functionToMockID, - AnnotationAttachmentNode attachmentNode) { + private boolean isValidFunctionName(String functionName, String moduleName, @Nullable PackageID functionToMockID, + AnnotationAttachmentNode attachmentNode) { if (functionToMockID == null) { diagnosticLog.logDiagnostic(DiagnosticSeverity.ERROR, attachmentNode.getPosition(), "could not find specified module '" + moduleName + "'"); @@ -396,6 +398,7 @@ private String getPackageName(PackageNode packageNode) { * @param functionName Name of the function * @return Function type if found, null if not found */ + @Nullable private BType getFunctionType(Map pkgEnvMap, PackageID packageID, String functionName) { // Symbol resolver, Pass the acquired package Symbol from package cache for (Map.Entry entry : pkgEnvMap.entrySet()) { @@ -430,6 +433,7 @@ private String getQualifiedClassName(BLangTestablePackage bLangTestablePackage, return className; } + @Nullable private String getImportedFunctionClassName(BLangTestablePackage bLangTestablePackage, String pkgId, String functionName) { String className = getClassName(bLangTestablePackage.getImports(), pkgId, functionName); @@ -440,6 +444,7 @@ private String getImportedFunctionClassName(BLangTestablePackage bLangTestablePa return className; } + @Nullable private String getClassName(List imports, String pkgId, String functionName) { for (BLangImportPackage importPackage : imports) { if (importPackage.symbol.pkgID.toString().equals(pkgId)) { diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/TestProcessor.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/TestProcessor.java index c5bb28854310..4a542d0c2ccb 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/TestProcessor.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/TestProcessor.java @@ -53,6 +53,7 @@ import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.test.runtime.entity.Test; import org.ballerinalang.test.runtime.entity.TestSuite; +import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.util.Names; import java.nio.file.Path; @@ -243,6 +244,7 @@ private void processAnnotations(Module module, TestSuite suite) { * @param name String * @return AnnotationNode */ + @Nullable private AnnotationNode getAnnotationNode(AnnotationSymbol annotationSymbol, Map syntaxTreeMap, String name) { for (Map.Entry syntaxTreeEntry : syntaxTreeMap.entrySet()) { @@ -414,7 +416,7 @@ private String getStringValue(Node valueExpr) { * @param annotationNode AnnotationNode * @return AtomicBoolean */ - private AtomicBoolean isAlwaysRunValue(AnnotationNode annotationNode) { + private AtomicBoolean isAlwaysRunValue(@Nullable AnnotationNode annotationNode) { AtomicBoolean alwaysRun = new AtomicBoolean(false); if (annotationNode != null && !annotationNode.annotValue().isEmpty()) { Optional mappingNodes = annotationNode.annotValue(); @@ -449,7 +451,7 @@ private AtomicBoolean isAlwaysRunValue(AnnotationNode annotationNode) { * @param suite TestSuite * @param isBeforeGroups boolean */ - private void processGroupsAnnotation(AnnotationNode annotationNode, String functionName, TestSuite suite, + private void processGroupsAnnotation(@Nullable AnnotationNode annotationNode, String functionName, TestSuite suite, boolean isBeforeGroups) { if (annotationNode != null && !annotationNode.annotValue().isEmpty()) { Optional mappingNodes = annotationNode.annotValue(); @@ -485,7 +487,7 @@ private void processGroupsAnnotation(AnnotationNode annotationNode, String funct * @param functionName String * @param suite TestSuite */ - private void processTestAnnotation(AnnotationNode annotationNode, String functionName, TestSuite suite) { + private void processTestAnnotation(@Nullable AnnotationNode annotationNode, String functionName, TestSuite suite) { Test test = new Test(); test.setTestName(functionName); AtomicBoolean shouldSkip = new AtomicBoolean(); @@ -599,6 +601,7 @@ private String getFieldName(SpecificFieldNode specificField) { * @param module Module * @return String */ + @Nullable private String getExecutePath(Module module) { String executePath = ""; if (isSingleFileProject(module.project())) { diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/FunctionMock.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/FunctionMock.java index c63e32652b39..662786a14a26 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/FunctionMock.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/FunctionMock.java @@ -14,6 +14,7 @@ import io.ballerina.runtime.internal.values.MapValueImpl; import org.ballerinalang.test.runtime.util.TesterinaUtils; import org.ballerinalang.testerina.natives.Executor; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Method; import java.util.ArrayList; @@ -35,6 +36,7 @@ public final class FunctionMock { private FunctionMock() { } + @Nullable public static BError thenReturn(BObject caseObj) { BObject mockFunctionObj = caseObj.getObjectValue(StringUtils.fromString("mockFuncObj")); BArray args = caseObj.getArrayValue(StringUtils.fromString("args")); @@ -44,6 +46,7 @@ public static BError thenReturn(BObject caseObj) { return null; } + @Nullable public static Object mockHandler(BObject mockFuncObj, Object... args) { List caseIds = getCaseIds(mockFuncObj, args); String originalFunction = @@ -101,6 +104,7 @@ private static Object callOriginalFunction(String originalFunction, String origi originalClassName, originalFunction, argsList.toArray()); } + @Nullable private static Object callMockFunction(String originalFunction, String originalClassName, String[] mockFunctionClasses, String returnVal, Object... args) { int prefixPos = returnVal.indexOf(MockConstants.FUNCTION_CALL_PLACEHOLDER); @@ -159,6 +163,7 @@ private static String getMockClassName(String orgName, String packageName, Strin } + @Nullable private static Method getMockMethod(String orgName, String packageName, String version, String mockMethodName, String[] mockFunctionClasses, ClassLoader classLoader) throws ClassNotFoundException { @@ -176,6 +181,7 @@ private static Method getMockMethod(String orgName, String packageName, String v return mockMethod; } //Identify the class with the mockMethod(method within call) + @Nullable private static String resolveMockClass(String mockMethodName, String[] mockFunctionClasses, String orgName, String packageName, String version, ClassLoader classLoader) throws ClassNotFoundException { @@ -193,7 +199,8 @@ private static String resolveMockClass(String mockMethodName, String[] mockFunct return mockClass; } - private static void validateFunctionSignature(Method mockMethod, Method originalMethod, String mockMethodName) { + private static void validateFunctionSignature(Method mockMethod, @Nullable Method originalMethod, + String mockMethodName) { // Validation if (mockMethod != null && originalMethod != null) { // Methods type and parameters @@ -249,6 +256,7 @@ private static void validateFunctionSignature(Method mockMethod, Method original } } + @Nullable private static Method getClassDeclaredMethod(String className, String methodName, ClassLoader classLoader) throws ClassNotFoundException { Class clazz = classLoader.loadClass(className); diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/GenericMockObjectValue.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/GenericMockObjectValue.java index 72b2ab463162..9fd5e2c3bcb2 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/GenericMockObjectValue.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/GenericMockObjectValue.java @@ -34,6 +34,7 @@ import io.ballerina.runtime.internal.scheduling.Strand; import io.ballerina.runtime.internal.values.ObjectValue; import io.ballerina.runtime.internal.values.TypedescValueImpl; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -105,6 +106,7 @@ public double getFloatValue(BString fieldName) { return 0; } + @Nullable @Override public BString getStringValue(BString fieldName) { return null; @@ -116,16 +118,19 @@ public boolean getBooleanValue(BString fieldName) { } @SuppressWarnings("rawtypes") + @Nullable @Override public BMap getMapValue(BString fieldName) { return null; } + @Nullable @Override public BObject getObjectValue(BString fieldName) { return null; } + @Nullable @Override public BArray getArrayValue(BString fieldName) { return null; @@ -136,11 +141,13 @@ public void addNativeData(String key, Object data) { } + @Nullable @Override public Object getNativeData(String key) { return null; } + @Nullable @Override public HashMap getNativeData() { return null; @@ -152,17 +159,20 @@ public void set(BString fieldName, Object value) { } + @Nullable @Override public BFuture start(Strand strand, String funcName, Object... args) { return null; } + @Nullable @Override public String stringValue(BLink parent) { return null; } + @Nullable @Override public String expressionStringValue(BLink parent) { return null; @@ -297,11 +307,13 @@ private Object[] removeUnnecessaryArgs(Object[] args) { return newArgs.toArray(); } + @Nullable @Override public Object copy(Map refs) { return null; } + @Nullable @Override public Object frozenCopy(Map refs) { return null; diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/MockRegistry.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/MockRegistry.java index 791409b87a6c..61b6ed3dce30 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/MockRegistry.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/MockRegistry.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BIterator; import io.ballerina.runtime.api.values.BObject; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -47,7 +48,7 @@ public static MockRegistry getInstance() { * @param returnVal value to return when the function is called * @param hittingCount count to check the return value from the sequence of return values provided */ - public void registerCase(BObject mockObject, String functionName, BArray argsList, Object returnVal, + public void registerCase(BObject mockObject, String functionName, @Nullable BArray argsList, Object returnVal, int hittingCount) { String caseId = constructCaseId(mockObject, functionName, argsList); if (!hasHitCount(caseId)) { @@ -65,7 +66,8 @@ public void registerCase(BObject mockObject, String functionName, BArray argsLis * @param argsList arguments list passed to the function * @param returnVal value to return when the function is called */ - public void registerCase(BObject mockObject, String functionName, BArray argsList, Object returnVal) { + public void registerCase(BObject mockObject, @Nullable String functionName, @Nullable BArray argsList, + Object returnVal) { String caseId = constructCaseId(mockObject, functionName, argsList); casesMap.put(caseId, returnVal); } diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/ObjectMock.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/ObjectMock.java index d53085fc89a0..923ba832e4a4 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/ObjectMock.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/natives/mock/ObjectMock.java @@ -44,6 +44,7 @@ import io.ballerina.runtime.internal.types.BClientType; import io.ballerina.runtime.internal.values.MapValueImpl; import io.ballerina.runtime.internal.values.ObjectValue; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -119,6 +120,7 @@ public static BObject mock(BTypedesc bTypedesc, ObjectValue objectValue) { * @param caseObj ballerina object that contains information about the case to register * @return an optional error if a validation fails */ + @Nullable public static BError validatePreparedObj(BObject caseObj) { GenericMockObjectValue genericMock = (GenericMockObjectValue) caseObj; BObject mockObj = genericMock.getMockObj(); @@ -140,6 +142,7 @@ public static BError validatePreparedObj(BObject caseObj) { * @param mockObject ballerina object that contains information about the case to register * @return an optional error if a validation fails */ + @Nullable public static BError validateFunctionName(String functionName, BObject mockObject) { GenericMockObjectValue genericMock = (GenericMockObjectValue) mockObject; if (!validateFunctionName(functionName, @@ -174,6 +177,7 @@ private static void validateClientObject(GenericMockObjectValue genericMock) { * @param mockObject ballerina object that contains information about the case to register * @return an optional error if a validation fails */ + @Nullable public static BError validateResourcePath(String pathName, BObject mockObject) { GenericMockObjectValue genericMock = (GenericMockObjectValue) mockObject; if (!validateResourcePath(pathName, @@ -195,6 +199,7 @@ public static BError validateResourcePath(String pathName, BObject mockObject) { * @param caseObj ballerina MemberResourceFunctionStub object containing information about the mock * @return an optional error if a validation fails */ + @Nullable public static BError validateResourceMethod(BObject caseObj) { GenericMockObjectValue genericMock = (GenericMockObjectValue) caseObj.getObjectValue( StringUtils.fromString(MockConstants.MOCK_OBJECT)); @@ -232,6 +237,7 @@ private static boolean validateAccessor(String resourcePath, String accessor, Re * @param pathParams path parameters map provided by the user * @return an optional error if a validation fails */ + @Nullable public static BError validatePathParams(BObject caseObj, BMap pathParams) { String functionName = caseObj.getStringValue(StringUtils.fromString(MockConstants.FUNCTION_NAME)).toString(); String[] pathSegments = functionName.split(MockConstants.PATH_SEPARATOR); @@ -279,6 +285,7 @@ public static BError validatePathParams(BObject caseObj, BMap pathParams) * @param mockObject ballerina object that contains information about the case to register * @return an optional error if a validation fails */ + @Nullable public static BError validateFieldName(String fieldName, BObject mockObject) { GenericMockObjectValue genericMock = (GenericMockObjectValue) mockObject; if (!validateFieldName(fieldName, @@ -300,6 +307,7 @@ public static BError validateFieldName(String fieldName, BObject mockObject) { * @param caseObj ballerina object that contains information about the case to register * @return an optional error if a validation fails */ + @Nullable public static BError validateArguments(BObject caseObj) { String mockType = caseObj.getOriginalType().getName(); GenericMockObjectValue genericMock = (GenericMockObjectValue) caseObj.getObjectValue( @@ -370,6 +378,7 @@ public static BError validateArguments(BObject caseObj) { * @param caseObj ballerina object that contains information about the case to register * @return an optional error if a validation fails */ + @Nullable public static BError validatePathArgs(BObject caseObj) { GenericMockObjectValue genericMock = (GenericMockObjectValue) caseObj.getObjectValue( StringUtils.fromString(MockConstants.MOCK_OBJECT)); @@ -451,6 +460,7 @@ public static BError validatePathArgs(BObject caseObj) { * @param caseObj ballerina object that contains information about the case to register * @return an optional error if a validation fails */ + @Nullable public static BError validateResourceArguments(BObject caseObj) { GenericMockObjectValue genericMock = (GenericMockObjectValue) caseObj.getObjectValue( StringUtils.fromString(MockConstants.MOCK_OBJECT)); @@ -522,6 +532,7 @@ public static BError validateResourceArguments(BObject caseObj) { * @param caseObj ballerina object that contains information about the case to register * @return an optional error if a validation fails */ + @Nullable public static BError thenReturn(BObject caseObj) { GenericMockObjectValue genericMock = (GenericMockObjectValue) caseObj .get(StringUtils.fromString(MockConstants.MOCK_OBJECT)); @@ -640,6 +651,7 @@ private static boolean validateFieldAccessIsPublic(ObjectType objectType, String * @param caseObj ballerina object that contains information about the case to register * @return an optional error if a validation fails */ + @Nullable public static BError thenReturnSequence(BObject caseObj) { String mockType = caseObj.getOriginalType().getName(); GenericMockObjectValue genericMock = (GenericMockObjectValue) caseObj @@ -872,6 +884,7 @@ private static boolean validateFieldValue(Object returnVal, Type fieldType) { * @param attachedFunctions functions available in the mocked type * @return whether the function signature is valid */ + @Nullable private static BError validateFunctionSignatures(MethodType func, MethodType[] attachedFunctions) { String functionName = func.getName(); @@ -970,6 +983,7 @@ private static BError validateFunctionSignatures(MethodType func, * @param fieldMap fields available in the mocked type * @return whether the field declaration is valid */ + @Nullable private static BError validateField(Map.Entry mockField, Map fieldMap) { for (Map.Entry field : fieldMap.entrySet()) { if (field.getKey().equals(mockField.getKey())) { diff --git a/misc/testerina/modules/testerina-runtime/src/main/java/module-info.java b/misc/testerina/modules/testerina-runtime/src/main/java/module-info.java index 5f62ead13755..20970b7fb4fd 100644 --- a/misc/testerina/modules/testerina-runtime/src/main/java/module-info.java +++ b/misc/testerina/modules/testerina-runtime/src/main/java/module-info.java @@ -11,4 +11,5 @@ requires io.ballerina.identifier; requires org.objectweb.asm; requires io.github.javadiffutils; + requires static org.jetbrains.annotations; } diff --git a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/CoverageReport.java b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/CoverageReport.java index 020bde2d9756..083767951499 100644 --- a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/CoverageReport.java +++ b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/CoverageReport.java @@ -46,6 +46,7 @@ import org.jacoco.core.data.ExecutionData; import org.jacoco.core.data.SessionInfo; import org.jacoco.core.tools.ExecFileLoader; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.nio.file.Files; @@ -326,7 +327,7 @@ private void createReport(final IBundleCoverage bundleCoverage, Map moduleCoverageMap, - List exclusionList, Set exclusionClassList) { + @Nullable List exclusionList, @Nullable Set exclusionClassList) { boolean containsSourceFiles = true; for (IPackageCoverage packageCoverage : bundleCoverage.getPackages()) { @@ -576,6 +577,7 @@ private List filterPaths(Collection pathCollection, JBallerina * @param sourceFileName String * @return Document */ + @Nullable private Document getDocument(String moduleName, String sourceFileName) { Document document = null; for (Module moduleInstance : module.packageInstance().modules()) { @@ -596,6 +598,7 @@ private Document getDocument(String moduleName, String sourceFileName) { * @param sourceFileName String * @return Document */ + @Nullable private Document getDocumentFromModule(Module moduleInstance, String sourceFileName) { Document document = null; for (DocumentId documentId : moduleInstance.documentIds()) { diff --git a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/PartialCoverageModifiedCounter.java b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/PartialCoverageModifiedCounter.java index cef9b34f3ac2..d6c9507657fe 100644 --- a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/PartialCoverageModifiedCounter.java +++ b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/PartialCoverageModifiedCounter.java @@ -18,6 +18,7 @@ package org.ballerinalang.test.runtime.entity; import org.jacoco.core.analysis.ICounter; +import org.jetbrains.annotations.Nullable; /** * Represents a counter that eliminates partially covered counter status and coverts it to fully covered status. @@ -29,7 +30,7 @@ public class PartialCoverageModifiedCounter implements ICounter { private int covered; private int missed; - public PartialCoverageModifiedCounter(ICounter prevCounter) { + public PartialCoverageModifiedCounter(@Nullable ICounter prevCounter) { if (prevCounter != null) { // Handles partial line coverage modification for ballerina sources this.covered = prevCounter.getCoveredCount(); diff --git a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/PartialCoverageModifiedLine.java b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/PartialCoverageModifiedLine.java index b0f39fd1ef3c..ec903347c0d5 100644 --- a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/PartialCoverageModifiedLine.java +++ b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/PartialCoverageModifiedLine.java @@ -19,6 +19,7 @@ import org.jacoco.core.analysis.ICounter; import org.jacoco.core.analysis.ILine; +import org.jetbrains.annotations.Nullable; /** * Represents a line modified to consider partially covered coverage info as fully covered. @@ -30,7 +31,7 @@ public class PartialCoverageModifiedLine implements ILine { private final PartialCoverageModifiedCounter instructions; private final PartialCoverageModifiedCounter branches; - public PartialCoverageModifiedLine(ICounter instructions, ICounter branches) { + public PartialCoverageModifiedLine(@Nullable ICounter instructions, @Nullable ICounter branches) { this.instructions = new PartialCoverageModifiedCounter(instructions); this.branches = new PartialCoverageModifiedCounter(branches); } diff --git a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/CodeCoverageUtils.java b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/CodeCoverageUtils.java index 0a1429096644..8b01a4350476 100644 --- a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/CodeCoverageUtils.java +++ b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/CodeCoverageUtils.java @@ -36,6 +36,7 @@ import org.jacoco.core.internal.analysis.BundleCoverageImpl; import org.jacoco.report.IReportVisitor; import org.jacoco.report.xml.XMLFormatter; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.FileOutputStream; @@ -111,7 +112,7 @@ public static boolean isRequestedReportFormat(String coverageReportFormat, Strin */ public static void unzipCompiledSource(Path source, Path destination, String orgName, String moduleName, boolean enableIncludesFilter, - String includesInCoverage, Set externalExclusionList) + @Nullable String includesInCoverage, Set externalExclusionList) throws NoSuchFileException { String destJarDir = destination.toString(); try (JarFile jarFile = new JarFile(source.toFile())) { diff --git a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/TesterinaUtils.java b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/TesterinaUtils.java index ca3a75f25614..29c9b94e5fd7 100644 --- a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/TesterinaUtils.java +++ b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/TesterinaUtils.java @@ -22,6 +22,7 @@ import org.ballerinalang.test.runtime.entity.Test; import org.ballerinalang.test.runtime.entity.TestSuite; import org.ballerinalang.test.runtime.exceptions.BallerinaTestException; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -243,6 +244,7 @@ private static List getUpdatedFunctionList(List currentTests, List * @param tests the tests available in current test suite * @return */ + @Nullable private static Test getTest(String testName, List tests) { for (Test test : tests) { if (testName.equals(test.getTestName())) { @@ -259,7 +261,7 @@ private static Test getTest(String testName, List tests) { * @param currentTests the tests available in current test suite * @return list of dependent functions */ - private static List getAllDependentFunctions(Test test, List currentTests) { + private static List getAllDependentFunctions(@Nullable Test test, List currentTests) { List completeDependentTestList = new ArrayList<>(); if (test != null) { List dependentTests = test.getDependsOnTestFunctions(); @@ -389,6 +391,7 @@ private static String cleanupClassName(String className) { return className.replace(GENERATE_OBJECT_CLASS_PREFIX, "."); } + @Nullable public static String decodeIdentifier(String encodedIdentifier) { if (encodedIdentifier == null) { return null; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/api/Toml.java b/misc/toml-parser/src/main/java/io/ballerina/toml/api/Toml.java index 119311d0ddc5..c57f955b091e 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/api/Toml.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/api/Toml.java @@ -34,6 +34,7 @@ import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.text.TextDocument; import io.ballerina.tools.text.TextDocuments; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.InputStream; @@ -72,6 +73,7 @@ public Toml(TomlTableNode tomlTableNode) { * @return TOML Object * @throws IOException if file is not accessible */ + @Nullable public static Toml read(Path path) throws IOException { Path fileNamePath = path.getFileName(); if (fileNamePath == null) { @@ -89,6 +91,7 @@ public static Toml read(Path path) throws IOException { * @return TOML Object * @throws IOException if file is not accessible */ + @Nullable public static Toml read(Path path, Schema schema) throws IOException { Path fileNamePath = path.getFileName(); if (fileNamePath == null) { @@ -127,7 +130,7 @@ public static Toml read(InputStream inputStream, Schema schema) throws IOExcepti * @param fileName file name of the TOML file * @return TOML Object */ - public static Toml read(String content, String fileName) { + public static Toml read(String content, @Nullable String fileName) { TextDocument textDocument = TextDocuments.from(content); SyntaxTree syntaxTree = SyntaxTree.from(textDocument, fileName); TomlTransformer nodeTransformer = new TomlTransformer(); @@ -144,7 +147,7 @@ public static Toml read(String content, String fileName) { * @param fileName file name of the TOML file * @return TOML Object */ - public static Toml read(String content, String fileName, Schema schema) { + public static Toml read(String content, @Nullable String fileName, Schema schema) { TextDocument textDocument = TextDocuments.from(content); SyntaxTree syntaxTree = SyntaxTree.from(textDocument, fileName); TomlTransformer nodeTransformer = new TomlTransformer(); diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/diagnostics/SyntaxDiagnostic.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/diagnostics/SyntaxDiagnostic.java index 8fea7b99cde0..dee4571bd0f4 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/diagnostics/SyntaxDiagnostic.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/diagnostics/SyntaxDiagnostic.java @@ -23,6 +23,7 @@ import io.ballerina.tools.diagnostics.DiagnosticCode; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticProperty; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -72,6 +73,7 @@ public String message() { return DiagnosticMessageHelper.getDiagnosticMessage(nodeDiagnostic.diagnosticCode(), nodeDiagnostic.args()); } + @Nullable @Override public List> properties() { return null; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java index 0f2e0b5a2089..0212003dc5df 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java @@ -23,6 +23,7 @@ import io.ballerina.toml.internal.parser.tree.STToken; import io.ballerina.tools.diagnostics.DiagnosticCode; import io.ballerina.tools.text.CharReader; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; import java.util.ArrayList; @@ -40,6 +41,7 @@ public abstract class AbstractLexer { protected List leadingTriviaList; private Collection diagnostics; protected CharReader reader; + @Nullable protected ParserMode mode; protected ArrayDeque modeStack = new ArrayDeque<>(); diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractParser.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractParser.java index fa219510e4db..97f34de695a2 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractParser.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractParser.java @@ -26,6 +26,7 @@ import io.ballerina.toml.internal.syntax.NodeListUtils; import io.ballerina.toml.syntax.tree.SyntaxKind; import io.ballerina.tools.diagnostics.DiagnosticCode; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; import java.util.Deque; @@ -41,6 +42,7 @@ public abstract class AbstractParser { protected final AbstractParserErrorHandler errorHandler; protected final AbstractTokenReader tokenReader; private final Deque invalidNodeInfoStack = new ArrayDeque<>(5); + @Nullable protected STToken insertedToken = null; public AbstractParser(AbstractTokenReader tokenReader, AbstractParserErrorHandler errorHandler) { diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractParserErrorHandler.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractParserErrorHandler.java index 81aa5f37eadd..d6d60acf143a 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractParserErrorHandler.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractParserErrorHandler.java @@ -21,6 +21,7 @@ import io.ballerina.toml.internal.parser.tree.STNode; import io.ballerina.toml.internal.parser.tree.STToken; import io.ballerina.toml.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; import java.util.ArrayList; @@ -249,6 +250,7 @@ public void switchContext(ParserRuleContext context) { * * @return head of the stack */ + @Nullable protected ParserRuleContext getParentContext() { return this.ctxStack.peek(); } @@ -258,6 +260,7 @@ protected ParserRuleContext getParentContext() { * * @return second element of the stack */ + @Nullable protected ParserRuleContext getGrandParentContext() { ParserRuleContext parent = this.ctxStack.pop(); ParserRuleContext grandParent = this.ctxStack.peek(); @@ -544,6 +547,7 @@ public static class Result { * fixes.peek(). Else, if the solution is to insert/remove a token that is not the * immediate next token, then this will have a solution with {@link Action#KEEP} as the action. */ + @Nullable protected Solution solution; public Result(ArrayDeque fixes, int matches) { diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/SyntaxErrors.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/SyntaxErrors.java index 895a36543b75..ac99ffc0147f 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/SyntaxErrors.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/SyntaxErrors.java @@ -27,6 +27,7 @@ import io.ballerina.toml.internal.syntax.SyntaxUtils; import io.ballerina.toml.syntax.tree.SyntaxKind; import io.ballerina.tools.diagnostics.DiagnosticCode; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -143,7 +144,7 @@ public static STNode cloneWithLeadingInvalidNodeMinutiae(STNode toClone, STNode */ public static STNode cloneWithLeadingInvalidNodeMinutiae(STNode toClone, STNode invalidNode, - DiagnosticCode diagnosticCode, + @Nullable DiagnosticCode diagnosticCode, Object... args) { STToken firstToken = toClone.firstToken(); STToken firstTokenWithInvalidNodeMinutiae = cloneWithLeadingInvalidNodeMinutiae(firstToken, @@ -193,7 +194,7 @@ public static STNode cloneWithTrailingInvalidNodeMinutiae(STNode toClone, STNode */ public static STNode cloneWithTrailingInvalidNodeMinutiae(STNode toClone, STNode invalidNode, - DiagnosticCode diagnosticCode, + @Nullable DiagnosticCode diagnosticCode, Object... args) { STToken lastToken = toClone.lastToken(); STToken lastTokenWithInvalidNodeMinutiae = cloneWithTrailingInvalidNodeMinutiae(lastToken, diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TokenReader.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TokenReader.java index 93f030849351..7b2d1d36bbc3 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TokenReader.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TokenReader.java @@ -18,6 +18,7 @@ package io.ballerina.toml.internal.parser; import io.ballerina.toml.internal.parser.tree.STToken; +import org.jetbrains.annotations.Nullable; /** * Reader that can read tokens from a given lexer. Supports k-lookahead @@ -134,6 +135,7 @@ public void endMode() { * * @return Current mode */ + @Nullable @Override public ParserMode getCurrentMode() { return this.lexer.modeStack.peek(); diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlLexer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlLexer.java index 84479165fc41..4c60c6a76340 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlLexer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlLexer.java @@ -24,6 +24,7 @@ import io.ballerina.toml.internal.parser.tree.STToken; import io.ballerina.toml.syntax.tree.SyntaxKind; import io.ballerina.tools.text.CharReader; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -227,6 +228,7 @@ private STToken readToken() { return token; } + @Nullable private STToken readNewlineToken() { reader.mark(); if (reader.isEOF()) { diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlParser.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlParser.java index c359e4929fad..ff374ac6887a 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlParser.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlParser.java @@ -22,6 +22,7 @@ import io.ballerina.toml.internal.parser.tree.STNodeFactory; import io.ballerina.toml.internal.parser.tree.STToken; import io.ballerina.toml.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -80,6 +81,7 @@ public STNode parse() { * * @return Parsed top-level node */ + @Nullable private STNode parseTopLevelNode() { startContext(ParserRuleContext.TOP_LEVEL_NODE); STToken nextToken = peek(); @@ -217,6 +219,7 @@ private boolean isEndOfInlineTable(STToken token) { return token.kind == SyntaxKind.CLOSE_BRACE_TOKEN || token.kind == EOF_TOKEN; } + @Nullable private STNode parseInlineTableEntryEnd() { return switch (peek().kind) { case COMMA_TOKEN -> consume(); @@ -387,6 +390,7 @@ private STNode parseIdentifierLiteral() { } } + @Nullable private STNode parseSingleKey() { STToken nextToken = peek(); return switch (nextToken.kind) { @@ -429,6 +433,7 @@ private STNode parseKeyList(STNode firstKey) { return STNodeFactory.createNodeList(keyList); } + @Nullable private STNode parseKeyEnd() { STToken token = peek(); return switch (token.kind) { @@ -528,6 +533,7 @@ private boolean isNumericalLiteral(STToken token) { }; } + @Nullable private STNode parseSign() { STToken token = peek(); if (token.kind == SyntaxKind.MINUS_TOKEN || token.kind == SyntaxKind.PLUS_TOKEN) { @@ -570,6 +576,7 @@ private STNode parseMultilineStringValue() { return STNodeFactory.createStringLiteralNode(startingDoubleQuote, content, endingDoubleQuote); } + @Nullable private STNode parseMultilineStringContent() { STToken nextToken = peek(); if (nextToken.kind == SyntaxKind.IDENTIFIER_LITERAL) { @@ -594,6 +601,7 @@ private STNode parseLiteralStringValue() { return STNodeFactory.createLiteralStringLiteralNode(startingDoubleQuote, content, endingDoubleQuote); } + @Nullable private STNode parseLiteralStringContent() { STToken nextToken = peek(); if (nextToken.kind == SyntaxKind.IDENTIFIER_LITERAL) { @@ -618,6 +626,7 @@ private STNode parseMultilineLiteralStringValue() { return STNodeFactory.createLiteralStringLiteralNode(startingDoubleQuote, content, endingDoubleQuote); } + @Nullable private STNode parseMultilineLiteralStringContent() { STToken nextToken = peek(); if (nextToken.kind == SyntaxKind.IDENTIFIER_LITERAL) { @@ -690,6 +699,7 @@ private STNode parseTripleDoubleQuoteToken(ParserRuleContext ctx) { } } + @Nullable private STNode parseStringContent() { STToken nextToken = peek(); if (nextToken.kind == SyntaxKind.IDENTIFIER_LITERAL) { @@ -768,6 +778,7 @@ private STNode parseArrayValues(STNode firstValue) { return STNodeFactory.createNodeList(valuesList); } + @Nullable private STNode parseValueEnd() { return switch (peek().kind) { case COMMA_TOKEN -> consume(); @@ -784,6 +795,7 @@ private STNode parseValueEnd() { }; } + @Nullable private STNode parseArrayValue() { STToken nextToken = peek(); return switch (nextToken.kind) { diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STAbstractNodeFactory.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STAbstractNodeFactory.java index 4fdfe03a0947..0759dd7b3366 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STAbstractNodeFactory.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STAbstractNodeFactory.java @@ -18,6 +18,7 @@ package io.ballerina.toml.internal.parser.tree; import io.ballerina.toml.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -63,6 +64,7 @@ public static STNode createEmptyNodeList() { return EMPTY_LIST; } + @Nullable public static STNode createEmptyNode() { return null; } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNode.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNode.java index 2384b8114f05..be85f5d5464d 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNode.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNode.java @@ -22,6 +22,7 @@ import io.ballerina.toml.syntax.tree.Node; import io.ballerina.toml.syntax.tree.NonTerminalNode; import io.ballerina.toml.syntax.tree.SyntaxKind; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -126,6 +127,7 @@ public STToken firstToken() { return (STToken) firstTokenInternal(); } + @Nullable protected STNode firstTokenInternal() { for (STNode child : childBuckets) { if (SyntaxUtils.isToken(child)) { @@ -150,6 +152,7 @@ public STToken lastToken() { return (STToken) lastTokenInternal(); } + @Nullable protected STNode lastTokenInternal() { for (int bucket = childBuckets.length - 1; bucket >= 0; bucket--) { STNode child = childInBucket(bucket); @@ -192,7 +195,7 @@ public T createUnlinkedFacade() { return (T) createFacade(0, null); } - public abstract Node createFacade(int position, NonTerminalNode parent); + public abstract Node createFacade(int position, @Nullable NonTerminalNode parent); /** * Accepts an instance of the {@code STNodeVisitor}, which can be used to diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNodeReplacer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNodeReplacer.java index 429236da44a2..ee2620c6e5a0 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNodeReplacer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNodeReplacer.java @@ -17,6 +17,8 @@ */ package io.ballerina.toml.internal.parser.tree; +import org.jetbrains.annotations.Nullable; + /** * Replaces internal tree nodes with the given replacements. *

@@ -44,6 +46,7 @@ private boolean shouldDescend(STNode node) { return true; } + @Nullable @Override protected T modifyNode(T node) { if (node == null) { diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNodeTransformer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNodeTransformer.java index f0482b3010c4..79849e24508b 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNodeTransformer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STNodeTransformer.java @@ -18,6 +18,8 @@ package io.ballerina.toml.internal.parser.tree; +import org.jetbrains.annotations.Nullable; + /** * The {@code NodeTransformer} transform each node in the syntax tree to * another object of type T. @@ -79,6 +81,7 @@ public T transform(STKeyNode keyNode) { // Tokens + @Nullable public T transform(STToken token) { return null; } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STTreeModifier.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STTreeModifier.java index 13f4cee5208b..ccb204341009 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STTreeModifier.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/tree/STTreeModifier.java @@ -18,6 +18,8 @@ package io.ballerina.toml.internal.parser.tree; +import org.jetbrains.annotations.Nullable; + /** * Produces a new tree by doing a depth-first traversal of the internal tree. *

@@ -217,6 +219,7 @@ protected STNode transformSyntaxNode(STNode node) { return node; } + @Nullable protected T modifyNode(T node) { if (node == null) { return null; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/syntax/ExternalTreeNodeList.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/syntax/ExternalTreeNodeList.java index 4c68ad946755..8d04b73ef925 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/syntax/ExternalTreeNodeList.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/syntax/ExternalTreeNodeList.java @@ -22,6 +22,7 @@ import io.ballerina.toml.syntax.tree.NodeTransformer; import io.ballerina.toml.syntax.tree.NodeVisitor; import io.ballerina.toml.syntax.tree.NonTerminalNode; +import org.jetbrains.annotations.Nullable; /** * Represents a list of {@code Node}s. This class is not exposed with the syntax tre API. @@ -41,6 +42,7 @@ public ExternalTreeNodeList(STNode node, int position, NonTerminalNode parent) { public void accept(NodeVisitor visitor) { } + @Nullable @Override public T apply(NodeTransformer transformer) { return null; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/syntax/NodeReplacer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/syntax/NodeReplacer.java index f1f8969bb24a..d0446ea3e22a 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/syntax/NodeReplacer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/syntax/NodeReplacer.java @@ -22,6 +22,7 @@ import io.ballerina.toml.syntax.tree.Token; import io.ballerina.toml.syntax.tree.TreeModifier; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; /** * Replaces syntax nodes with the given replacements. @@ -51,6 +52,7 @@ private boolean shouldDescend(Node node) { return oldNodeTextRange.intersectionExists(node.textRangeWithMinutiae()); } + @Nullable @Override protected T modifyNode(T node) { if (node == null) { @@ -66,6 +68,7 @@ protected T modifyNode(T node) { return (T) replaced; } + @Nullable @Override protected T modifyToken(T token) { if (token == null) { diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/ast/TomlKeyNode.java b/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/ast/TomlKeyNode.java index 1196d6f19e89..14947af7eb5f 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/ast/TomlKeyNode.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/ast/TomlKeyNode.java @@ -21,6 +21,7 @@ import io.ballerina.toml.semantic.TomlType; import io.ballerina.toml.semantic.diagnostics.TomlNodeLocation; import io.ballerina.toml.syntax.tree.KeyNode; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -34,7 +35,7 @@ public class TomlKeyNode extends TomlNode { private final List keys; - public TomlKeyNode(KeyNode node, List keys, TomlNodeLocation location) { + public TomlKeyNode(KeyNode node, List keys, @Nullable TomlNodeLocation location) { super(node, TomlType.KEY_VALUE, location); this.keys = keys; } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/ast/TomlTransformer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/ast/TomlTransformer.java index 0a4fc46c7203..8e4a1286ecb6 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/ast/TomlTransformer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/ast/TomlTransformer.java @@ -47,6 +47,7 @@ import io.ballerina.toml.syntax.tree.ValueNode; import io.ballerina.tools.text.LineRange; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -273,6 +274,7 @@ private void addChildTableToParent(TomlTableNode rootTable, TomlTableNode tableC } } + @Nullable private TomlTableNode generateNewTable(TomlTableNode child, TomlKeyEntryNode lastKeyEntry, List entries) { if (child.externalTreeNode().kind() == SyntaxKind.TABLE) { @@ -453,6 +455,7 @@ public TomlNode transform(ArrayNode array) { return new TomlArrayValueNode(array, elements, getPosition(array)); } + @Nullable @Override protected TomlNode transformSyntaxNode(Node node) { return null; @@ -614,6 +617,7 @@ public TomlNode transform(InlineTableNode inlineTableNode) { * @param tomlNodes AST TomlNode key list * @return TomlNodeLocation */ + @Nullable private TomlNodeLocation getTomlNodeListLocation(List tomlNodes) { if (tomlNodes.isEmpty()) { return null; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/diagnostics/TomlDiagnostic.java b/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/diagnostics/TomlDiagnostic.java index 71d7e1a58c21..fc5852b559da 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/diagnostics/TomlDiagnostic.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/semantic/diagnostics/TomlDiagnostic.java @@ -24,6 +24,7 @@ import io.ballerina.tools.diagnostics.Location; import io.ballerina.tools.text.LinePosition; import io.ballerina.tools.text.LineRange; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Objects; @@ -60,6 +61,7 @@ public String message() { return message; } + @Nullable @Override public List> properties() { return null; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/AbstractNodeFactory.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/AbstractNodeFactory.java index 51de768d1e02..33923d6ab815 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/AbstractNodeFactory.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/AbstractNodeFactory.java @@ -23,6 +23,7 @@ import io.ballerina.toml.internal.parser.tree.STNodeFactory; import io.ballerina.toml.internal.parser.tree.STToken; import io.ballerina.toml.internal.syntax.NodeListUtils; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; @@ -208,6 +209,7 @@ public static SeparatedNodeList createSeparatedNodeList(Coll .toList()).createUnlinkedFacade()); } + @Nullable protected static STNode getOptionalSTNode(Node node) { return node != null ? node.internalNode() : null; } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/ChildNodeList.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/ChildNodeList.java index d0721d724de2..a2c9449dee26 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/ChildNodeList.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/ChildNodeList.java @@ -19,6 +19,7 @@ import io.ballerina.toml.internal.parser.tree.STNode; import io.ballerina.toml.internal.syntax.SyntaxUtils; +import org.jetbrains.annotations.Nullable; import java.util.Iterator; @@ -73,6 +74,7 @@ private int getChildCount(STNode parent) { return count; } + @Nullable private Node loadNode(int childIndex) { int index = 0; Node child = null; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/LiteralStringLiteralNode.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/LiteralStringLiteralNode.java index 64d9428a04d4..5684cf09d8dd 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/LiteralStringLiteralNode.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/LiteralStringLiteralNode.java @@ -18,6 +18,7 @@ package io.ballerina.toml.syntax.tree; import io.ballerina.toml.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -92,6 +93,7 @@ public LiteralStringLiteralNodeModifier modify() { public static class LiteralStringLiteralNodeModifier { private final LiteralStringLiteralNode oldNode; private Token startSingleQuote; + @Nullable private Token content; private Token endSingleQuote; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/Minutiae.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/Minutiae.java index eca53d3bb22b..a663f24ba041 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/Minutiae.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/Minutiae.java @@ -23,6 +23,7 @@ import io.ballerina.tools.text.LineRange; import io.ballerina.tools.text.TextDocument; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -39,7 +40,7 @@ public final class Minutiae { private TextRange textRange; private LineRange lineRange; - Minutiae(STMinutiae internalMinutiae, Token token, int position) { + Minutiae(STMinutiae internalMinutiae, @Nullable Token token, int position) { this.internalMinutiae = internalMinutiae; this.token = token; this.position = position; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/MinutiaeList.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/MinutiaeList.java index 3fe19c63b730..ba3a36e823ed 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/MinutiaeList.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/MinutiaeList.java @@ -22,6 +22,7 @@ import io.ballerina.toml.internal.parser.tree.STNodeList; import io.ballerina.toml.internal.syntax.NodeListUtils; import io.ballerina.toml.internal.syntax.SyntaxUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -44,7 +45,7 @@ public final class MinutiaeList implements Iterable { private final int size; private final Minutiae[] minutiaeNodes; - MinutiaeList(Token token, STNode internalMinutiae, int position) { + MinutiaeList(@Nullable Token token, STNode internalMinutiae, int position) { if (!NodeListUtils.isSTNodeList(internalMinutiae)) { throw new IllegalArgumentException("An STNodeList instance is expected"); } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeFactory.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeFactory.java index 3b713e47199b..8f1e37c9172a 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeFactory.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeFactory.java @@ -19,6 +19,7 @@ import io.ballerina.toml.internal.parser.tree.STNode; import io.ballerina.toml.internal.parser.tree.STNodeFactory; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -163,7 +164,7 @@ public static LiteralStringLiteralNode createLiteralStringLiteralNode( public static NumericLiteralNode createNumericLiteralNode( SyntaxKind kind, - Token sign, + @Nullable Token sign, Token value) { Objects.requireNonNull(value, "value must not be null"); diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeParser.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeParser.java index 4e96b7cadad2..d38afc66e49e 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeParser.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeParser.java @@ -17,6 +17,8 @@ */ package io.ballerina.toml.syntax.tree; +import org.jetbrains.annotations.Nullable; + /** * Parses a given input and produces a {@code Node}. * @@ -24,10 +26,12 @@ */ public class NodeParser { + @Nullable public StatementNode parseStatement(String text) { return null; } + @Nullable public ExpressionNode parseExpression(String text) { return null; } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeTransformer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeTransformer.java index ff6133cd8d0f..9fed2f77e25e 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeTransformer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NodeTransformer.java @@ -18,6 +18,8 @@ package io.ballerina.toml.syntax.tree; +import org.jetbrains.annotations.Nullable; + /** * The {@code NodeTransformer} transform each node in the syntax tree to * another object of type T. @@ -90,6 +92,7 @@ public T transform(KeyNode keyNode) { // Tokens + @Nullable public T transform(Token token) { return null; } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NonTerminalNode.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NonTerminalNode.java index 891c931a06ed..d82298dd62ce 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NonTerminalNode.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NonTerminalNode.java @@ -22,6 +22,7 @@ import io.ballerina.toml.internal.syntax.TreeModifiers; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.text.TextRange; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -43,7 +44,7 @@ public abstract class NonTerminalNode extends Node { protected final Node[] childBuckets; private ChildNodeList childNodeList; - public NonTerminalNode(STNode internalNode, int position, NonTerminalNode parent) { + public NonTerminalNode(STNode internalNode, int position, @Nullable NonTerminalNode parent) { super(internalNode, position, parent); this.childBuckets = new Node[internalNode.bucketCount()]; } @@ -131,6 +132,7 @@ public Token findToken(int position, boolean insideMinutiae) { * @param textRange to evaluate and find the node * @return {@link NonTerminalNode} which is the inner most non terminal node, encapsulating the given position */ + @Nullable public NonTerminalNode findNode(TextRange textRange) { TextRange textRangeWithMinutiae = textRangeWithMinutiae(); if (!(this instanceof DocumentNode) diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NumericLiteralNode.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NumericLiteralNode.java index ab20393c34a4..e6bbf22235f1 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NumericLiteralNode.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/NumericLiteralNode.java @@ -18,6 +18,7 @@ package io.ballerina.toml.syntax.tree; import io.ballerina.toml.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -85,6 +86,7 @@ public NumericLiteralNodeModifier modify() { */ public static class NumericLiteralNodeModifier { private final NumericLiteralNode oldNode; + @Nullable private Token sign; private Token value; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/StringLiteralNode.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/StringLiteralNode.java index b9fb77a92a75..85118a9c6679 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/StringLiteralNode.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/StringLiteralNode.java @@ -18,6 +18,7 @@ package io.ballerina.toml.syntax.tree; import io.ballerina.toml.internal.parser.tree.STNode; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Optional; @@ -92,6 +93,7 @@ public StringLiteralNodeModifier modify() { public static class StringLiteralNodeModifier { private final StringLiteralNode oldNode; private Token startDoubleQuote; + @Nullable private Token content; private Token endDoubleQuote; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/SyntaxTree.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/SyntaxTree.java index f080d08481ef..50785eb961c1 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/SyntaxTree.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/SyntaxTree.java @@ -23,6 +23,7 @@ import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.text.TextDocument; import io.ballerina.tools.text.TextDocuments; +import org.jetbrains.annotations.Nullable; /** * The {@code SyntaxTree} represents a parsed Ballerina source file. @@ -35,7 +36,7 @@ public class SyntaxTree { private TextDocument textDocument; - SyntaxTree(Node rootNode, TextDocument textDocument, String filePath, boolean clone) { + SyntaxTree(Node rootNode, @Nullable TextDocument textDocument, @Nullable String filePath, boolean clone) { this.rootNode = modifyWithMe(rootNode, clone); this.textDocument = textDocument; this.filePath = filePath; @@ -49,7 +50,7 @@ public static SyntaxTree from(TextDocument textDocument) { return from(textDocument, null); } - public static SyntaxTree from(TextDocument textDocument, String filePath) { + public static SyntaxTree from(TextDocument textDocument, @Nullable String filePath) { TomlParser parser = ParserFactory.getParser(textDocument); return new SyntaxTree(parser.parse().createUnlinkedFacade(), textDocument, filePath, false); diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/TreeModifier.java b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/TreeModifier.java index 1b0298d57639..8f7b312bfaed 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/TreeModifier.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/syntax/tree/TreeModifier.java @@ -19,6 +19,7 @@ import io.ballerina.toml.internal.parser.tree.STNode; import io.ballerina.toml.internal.parser.tree.STNodeFactory; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.function.Function; @@ -287,7 +288,8 @@ private > N modifyGenericNodeList( return nodeListCreator.apply(stNodeList.createUnlinkedFacade()); } - protected T modifyToken(T token) { + @Nullable + protected T modifyToken(@Nullable T token) { if (token == null) { return null; } @@ -295,6 +297,7 @@ protected T modifyToken(T token) { return (T) token.apply(this); } + @Nullable protected T modifyNode(T node) { if (node == null) { return null; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/SampleNodeGenerator.java b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/SampleNodeGenerator.java index cce378c1d23f..878f9494fe2a 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/SampleNodeGenerator.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/SampleNodeGenerator.java @@ -30,6 +30,7 @@ import io.ballerina.toml.syntax.tree.TableArrayNode; import io.ballerina.toml.syntax.tree.TableNode; import io.ballerina.toml.syntax.tree.Token; +import org.jetbrains.annotations.Nullable; /** * Responsible for generating sample toml syntax tree nodes for BoilerplateGenerator. @@ -43,7 +44,7 @@ public final class SampleNodeGenerator { private SampleNodeGenerator() { } - public static KeyValueNode createStringKV(String key, String value, String description) { + public static KeyValueNode createStringKV(String key, String value, @Nullable String description) { KeyNode keyNode = getKeyNode(key); Token assign = getAssignToken(); Token startingDoubleQuote = NodeFactory.createToken(SyntaxKind.DOUBLE_QUOTE_TOKEN); @@ -56,7 +57,7 @@ public static KeyValueNode createStringKV(String key, String value, String descr return NodeFactory.createKeyValueNode(keyNode, assign, stringLiteralNode); } - public static KeyValueNode createNumericKV(String key, String value, String description) { + public static KeyValueNode createNumericKV(String key, String value, @Nullable String description) { KeyNode keyNode = getKeyNode(key); Token assign = getAssignToken(); MinutiaeList endingMinList = getEndingMinList(description); @@ -65,7 +66,7 @@ public static KeyValueNode createNumericKV(String key, String value, String desc return NodeFactory.createKeyValueNode(keyNode, assign, numericLiteralNode); } - public static KeyValueNode createBooleanKV(String key, Boolean value, String description) { + public static KeyValueNode createBooleanKV(String key, Boolean value, @Nullable String description) { KeyNode keyNode = getKeyNode(key); Token assign = getAssignToken(); MinutiaeList endingMinList = getEndingMinList(description); @@ -81,7 +82,7 @@ public static KeyValueNode createBooleanKV(String key, Boolean value, String des return NodeFactory.createKeyValueNode(keyNode, assign, boolLiteralNode); } - public static TableNode createTable(String key, String description) { + public static TableNode createTable(String key, @Nullable String description) { KeyNode keyNode = getKeyNode(key); return NodeFactory.createTableNode(NodeFactory.createToken(SyntaxKind.OPEN_BRACKET_TOKEN, getLeadingTableMinList(description), NodeFactory.createEmptyMinutiaeList()), keyNode, @@ -89,7 +90,7 @@ public static TableNode createTable(String key, String description) { , getEndingMinList(null)), NodeFactory.createEmptyNodeList()); } - public static TableArrayNode createTableArray(String key, String description) { + public static TableArrayNode createTableArray(String key, @Nullable String description) { KeyNode keyNode = getKeyNode(key); return NodeFactory.createTableArrayNode(NodeFactory.createToken(SyntaxKind.OPEN_BRACKET_TOKEN, getLeadingTableMinList(description), NodeFactory.createEmptyMinutiaeList()), @@ -108,7 +109,7 @@ private static MinutiaeList getLeadingTableMinList(String comment) { return minutiaeList; } - private static MinutiaeList getEndingMinList(String comment) { + private static MinutiaeList getEndingMinList(@Nullable String comment) { Minutiae newLineMinutiae = NodeFactory.createWhitespaceMinutiae(NEW_LINE); MinutiaeList endingMinList = NodeFactory.createMinutiaeList(); if (comment != null) { diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/AbstractSchema.java b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/AbstractSchema.java index 9f8f8b62b976..1d84370150e8 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/AbstractSchema.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/AbstractSchema.java @@ -20,6 +20,7 @@ import io.ballerina.toml.semantic.ast.TomlNode; import io.ballerina.tools.diagnostics.Diagnostic; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -37,7 +38,8 @@ public abstract class AbstractSchema { private final Map message; private final CompositionSchema compositionSchemas; - public AbstractSchema(Type type, Map message, CompositionSchema compositionSchemas, String desc) { + public AbstractSchema(Type type, Map message, @Nullable CompositionSchema compositionSchemas, + @Nullable String desc) { this.type = type; this.message = message; this.compositionSchemas = compositionSchemas; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/ArraySchema.java b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/ArraySchema.java index df65ca2ec0f5..62ef88e24155 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/ArraySchema.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/ArraySchema.java @@ -23,6 +23,7 @@ import io.ballerina.toml.semantic.diagnostics.TomlDiagnostic; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -41,7 +42,7 @@ public class ArraySchema extends AbstractSchema { private final AbstractSchema items; public ArraySchema(Type type, Map message, AbstractSchema items, CompositionSchema comps, - String description) { + @Nullable String description) { super(type, message, comps, description); this.items = items; } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/BooleanSchema.java b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/BooleanSchema.java index 7d42a1ccc1c9..17dcc1458dee 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/BooleanSchema.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/BooleanSchema.java @@ -23,6 +23,7 @@ import io.ballerina.toml.semantic.diagnostics.TomlDiagnostic; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -38,8 +39,8 @@ */ public class BooleanSchema extends PrimitiveValueSchema { - public BooleanSchema(Type type, Map message, Boolean defaultValue, CompositionSchema comps, - String description) { + public BooleanSchema(Type type, Map message, Boolean defaultValue, + @Nullable CompositionSchema comps, @Nullable String description) { super(type, message, defaultValue, comps, description); } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/NumericSchema.java b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/NumericSchema.java index a0ae40acb5af..e12b1d492121 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/NumericSchema.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/NumericSchema.java @@ -25,6 +25,7 @@ import io.ballerina.toml.semantic.diagnostics.TomlDiagnostic; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -44,8 +45,9 @@ public class NumericSchema extends PrimitiveValueSchema { private final Double minimum; private final Double maximum; - public NumericSchema(Type type, Map message, Double minimum, Double maximum, Double defaultValue, - CompositionSchema compositionSchemas, String description) { + public NumericSchema(Type type, Map message, + @Nullable Double minimum, @Nullable Double maximum, @Nullable Double defaultValue, + CompositionSchema compositionSchemas, @Nullable String description) { super(type, message, defaultValue, compositionSchemas, description); this.minimum = minimum; this.maximum = maximum; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/Schema.java b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/Schema.java index 2e6255ac3149..4cafd584644e 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/Schema.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/Schema.java @@ -29,6 +29,7 @@ import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.io.BufferedReader; import java.io.IOException; @@ -57,9 +58,10 @@ public class Schema extends AbstractSchema { private static final String PROPERTY_HOLDER = "${property}"; - public Schema(String schema, String title, Type type, Map message, String description, - boolean hasAdditionalProperties, Map properties, List required, - CompositionSchema compositionSchemas) { + public Schema( + @Nullable String schema, @Nullable String title, Type type, Map message, + @Nullable String description, boolean hasAdditionalProperties, Map properties, + List required, CompositionSchema compositionSchemas) { super(type, message, compositionSchemas, description); this.schema = schema; this.title = title; diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/SchemaDeserializer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/SchemaDeserializer.java index 3642f990427f..fdf6f9a93c58 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/SchemaDeserializer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/SchemaDeserializer.java @@ -23,6 +23,7 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -140,7 +141,8 @@ private AbstractSchema getAbstractSchema(JsonDeserializationContext jsonDeserial } } - private Schema getObjectSchema(JsonDeserializationContext context, JsonObject jsonObj, CompositionSchema comps) { + private Schema getObjectSchema( + JsonDeserializationContext context, JsonObject jsonObj, @Nullable CompositionSchema comps) { JsonElement titleProp = jsonObj.get(TITLE); String title = titleProp != null ? titleProp.getAsString() : null; JsonElement schemaProp = jsonObj.get(SCHEMA); @@ -163,7 +165,7 @@ private Schema getObjectSchema(JsonDeserializationContext context, JsonObject js } private AbstractSchema getArraySchema(JsonDeserializationContext jsonDeserializationContext, JsonObject jsonObj, - CompositionSchema comps) { + @Nullable CompositionSchema comps) { JsonElement items = jsonObj.get(ITEMS).getAsJsonObject(); AbstractSchema abstractSchema = jsonDeserializationContext.deserialize(items, AbstractSchema.class); Map customMessages = parseOptionalMapFromMessageJson(jsonObj); @@ -172,7 +174,7 @@ private AbstractSchema getArraySchema(JsonDeserializationContext jsonDeserializa return new ArraySchema(Type.ARRAY, customMessages, abstractSchema, comps, desc); } - private StringSchema getStringSchema(JsonObject jsonObj, CompositionSchema comps) { + private StringSchema getStringSchema(JsonObject jsonObj, @Nullable CompositionSchema comps) { String pattern = parseOptionalStringFromJson(jsonObj, PATTERN); String defaultValue = parseOptionalStringFromJson(jsonObj, DEFAULT_VALUE); Integer minLength = parseOptionalIntFromJson(jsonObj, MIN_LENGTH); @@ -183,7 +185,7 @@ private StringSchema getStringSchema(JsonObject jsonObj, CompositionSchema comps return new StringSchema(Type.STRING, customMessages, pattern, defaultValue, minLength, maxLength, comps, desc); } - private NumericSchema getNumericSchema(JsonObject jsonObj, Type type, CompositionSchema comps) { + private NumericSchema getNumericSchema(JsonObject jsonObj, Type type, @Nullable CompositionSchema comps) { Double minimum = parseOptionalDoubleFromJson(jsonObj, MINIMUM); Double maximum = parseOptionalDoubleFromJson(jsonObj, MAXIMUM); Double defaultValue = parseOptionalDoubleFromJson(jsonObj, DEFAULT_VALUE); @@ -193,6 +195,7 @@ private NumericSchema getNumericSchema(JsonObject jsonObj, Type type, Compositio return new NumericSchema(type, customMessages, minimum, maximum, defaultValue, comps, desc); } + @Nullable private Double parseOptionalDoubleFromJson(JsonObject jsonObject, String key) { JsonElement jsonElement = jsonObject.get(key); if (jsonElement == null || jsonElement.isJsonNull()) { @@ -205,7 +208,7 @@ private Double parseOptionalDoubleFromJson(JsonObject jsonObject, String key) { throw new JsonSchemaException(key + " should always be a number"); } - private Boolean parseOptionalBooleanFromJson(JsonObject jsonObject, String key, Boolean defaultVal) { + private Boolean parseOptionalBooleanFromJson(JsonObject jsonObject, String key, @Nullable Boolean defaultVal) { JsonElement jsonElement = jsonObject.get(key); if (jsonElement == null || jsonElement.isJsonNull()) { return defaultVal; @@ -234,6 +237,7 @@ private List parseOptionalListFromJson(JsonObject jsonObject, String key return list; } + @Nullable private String parseOptionalStringFromJson(JsonObject jsonObject, String key) { JsonElement jsonElement = jsonObject.get(key); if (jsonElement == null || jsonElement.isJsonNull()) { @@ -246,6 +250,7 @@ private String parseOptionalStringFromJson(JsonObject jsonObject, String key) { throw new JsonSchemaException(key + " should always be a string"); } + @Nullable private Integer parseOptionalIntFromJson(JsonObject jsonObject, String key) { JsonElement jsonElement = jsonObject.get(key); if (jsonElement == null || jsonElement.isJsonNull()) { diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/StringSchema.java b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/StringSchema.java index b12cf0af9f2f..95ef4b28c4d3 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/StringSchema.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/validator/schema/StringSchema.java @@ -24,6 +24,7 @@ import io.ballerina.toml.semantic.diagnostics.TomlDiagnostic; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -46,9 +47,9 @@ public class StringSchema extends PrimitiveValueSchema { private final Integer minLength; private final Integer maxLength; - public StringSchema(Type type, Map message, String pattern, String defaultValue, - Integer minLength, Integer maxLength, CompositionSchema compositionSchemas, - String description) { + public StringSchema(Type type, Map message, @Nullable String pattern, @Nullable String defaultValue, + @Nullable Integer minLength, @Nullable Integer maxLength, CompositionSchema compositionSchemas, + @Nullable String description) { super(type, message, defaultValue, compositionSchemas, description); this.pattern = pattern; this.minLength = minLength; diff --git a/misc/toml-parser/src/main/java/module-info.java b/misc/toml-parser/src/main/java/module-info.java index 445cd3462f1e..e764175b9328 100644 --- a/misc/toml-parser/src/main/java/module-info.java +++ b/misc/toml-parser/src/main/java/module-info.java @@ -3,6 +3,7 @@ requires com.google.gson; requires org.apache.commons.text; requires io.ballerina.identifier; + requires static org.jetbrains.annotations; exports io.ballerina.toml.syntax.tree; exports io.ballerina.toml.semantic; diff --git a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java index 5e3dd99c406e..3fd6b1b497e1 100644 --- a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java +++ b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java @@ -51,6 +51,7 @@ import org.ballerinalang.formatter.core.FormatterException; import org.ballerinalang.formatter.core.options.ForceFormattingOptions; import org.ballerinalang.formatter.core.options.FormattingOptions; +import org.jetbrains.annotations.Nullable; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; @@ -97,8 +98,8 @@ private XMLToRecordConverter() {} public static XMLToRecordResponse convert(String xmlValue, boolean isRecordTypeDesc, boolean isClosed, boolean forceFormatRecordFields, - String textFieldName, boolean withNameSpaces, boolean withoutAttributes, - boolean withoutAttributeAnnot) { + @Nullable String textFieldName, boolean withNameSpaces, + boolean withoutAttributes, boolean withoutAttributeAnnot) { Map recordToTypeDescNodes = new LinkedHashMap<>(); Map recordToAnnotationNodes = new LinkedHashMap<>(); Map recordToElementNodes = new LinkedHashMap<>(); @@ -672,7 +673,7 @@ private static AnnotationNode getXMLNameNode(String value) { * * @return {@link AnnotationNode} xmldata:Namespace AnnotationNode */ - private static AnnotationNode getXMLNamespaceNode(String prefix, String uri) { + private static AnnotationNode getXMLNamespaceNode(@Nullable String prefix, String uri) { Token atToken = AbstractNodeFactory.createToken(SyntaxKind.AT_TOKEN); IdentifierToken modulePrefix = AbstractNodeFactory.createIdentifierToken(XMLDATA); diff --git a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordRequest.java b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordRequest.java index 46b0607c2a6c..530990b174be 100644 --- a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordRequest.java +++ b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordRequest.java @@ -18,6 +18,8 @@ package io.ballerina.xmltorecordconverter; +import org.jetbrains.annotations.Nullable; + /** * Request format for XMLToRecord endpoint. * @@ -35,7 +37,7 @@ public class XMLToRecordRequest { private final boolean withoutAttributeAnnot; public XMLToRecordRequest(String xmlValue, boolean isRecordTypeDesc, boolean isClosed, - boolean forceFormatRecordFields, String textFieldName, boolean withNameSpace, + boolean forceFormatRecordFields, @Nullable String textFieldName, boolean withNameSpace, boolean withoutAttributes, boolean withoutAttributeAnnot) { this.xmlValue = xmlValue; this.isRecordTypeDesc = isRecordTypeDesc; diff --git a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/diagnostic/DiagnosticMessage.java b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/diagnostic/DiagnosticMessage.java index adb7b4871e9a..ed1336780048 100644 --- a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/diagnostic/DiagnosticMessage.java +++ b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/diagnostic/DiagnosticMessage.java @@ -19,6 +19,7 @@ package io.ballerina.xmltorecordconverter.diagnostic; import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -57,22 +58,22 @@ public Object[] getArgs() { return Objects.requireNonNullElse(this.args, new Object[0]).clone(); } - public static DiagnosticMessage xmlToRecordConverter100(Object[] args) { + public static DiagnosticMessage xmlToRecordConverter100(@Nullable Object[] args) { return new DiagnosticMessage("XML_TO_RECORD_CONVERTER_100", "XML parser configuration error: Unable to properly configure.", DiagnosticSeverity.ERROR, args); } - public static DiagnosticMessage xmlToRecordConverter101(Object[] args) { + public static DiagnosticMessage xmlToRecordConverter101(@Nullable Object[] args) { return new DiagnosticMessage("XML_TO_RECORD_CONVERTER_101", "Error occurred while parsing the XML text.", DiagnosticSeverity.ERROR, args); } - public static DiagnosticMessage xmlToRecordConverter102(Object[] args) { + public static DiagnosticMessage xmlToRecordConverter102(@Nullable Object[] args) { return new DiagnosticMessage("XML_TO_RECORD_CONVERTER_102", "Provided input is invalid.", DiagnosticSeverity.ERROR, args); } - public static DiagnosticMessage xmlToRecordConverter103(Object[] args) { + public static DiagnosticMessage xmlToRecordConverter103(@Nullable Object[] args) { return new DiagnosticMessage("XML_TO_RECORD_CONVERTER_103", "Error occurred while formatting the Ballerina syntax tree.", DiagnosticSeverity.ERROR, args); } diff --git a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/diagnostic/XMLToRecordConverterDiagnostic.java b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/diagnostic/XMLToRecordConverterDiagnostic.java index 8f51b5282f9c..2b138eb2ef9f 100644 --- a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/diagnostic/XMLToRecordConverterDiagnostic.java +++ b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/diagnostic/XMLToRecordConverterDiagnostic.java @@ -23,6 +23,7 @@ import io.ballerina.tools.diagnostics.DiagnosticProperty; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; import java.text.MessageFormat; import java.util.Collections; @@ -42,7 +43,7 @@ public class XMLToRecordConverterDiagnostic extends Diagnostic { private final String severity; public XMLToRecordConverterDiagnostic(String code, String message, DiagnosticSeverity severity, - Location location, Object[] args) { + @Nullable Location location, Object[] args) { this.diagnosticInfo = new DiagnosticInfo(code, message, severity); this.location = location; this.properties = Collections.emptyList(); diff --git a/misc/xml-to-record-converter/src/main/java/module-info.java b/misc/xml-to-record-converter/src/main/java/module-info.java index 8d820aefc11e..1429d6606612 100644 --- a/misc/xml-to-record-converter/src/main/java/module-info.java +++ b/misc/xml-to-record-converter/src/main/java/module-info.java @@ -8,6 +8,7 @@ requires java.xml; requires org.apache.commons.lang3; requires org.eclipse.lsp4j.jsonrpc; + requires static org.jetbrains.annotations; exports io.ballerina.xmltorecordconverter; } diff --git a/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/io/samjs/plugins/badsad/BadSadCompilerPlugin20.java b/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/io/samjs/plugins/badsad/BadSadCompilerPlugin20.java index f2f816687755..0ba605ea30cb 100644 --- a/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/io/samjs/plugins/badsad/BadSadCompilerPlugin20.java +++ b/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/io/samjs/plugins/badsad/BadSadCompilerPlugin20.java @@ -19,6 +19,7 @@ import io.ballerina.projects.plugins.CompilerPlugin; import io.ballerina.projects.plugins.CompilerPluginContext; +import org.jetbrains.annotations.Nullable; import java.io.PrintStream; @@ -35,7 +36,7 @@ public void init(CompilerPluginContext pluginContext) { out.println(getStr().toCharArray()); } - String getStr() { + @Nullable String getStr() { return null; } } diff --git a/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/module-info.java b/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/module-info.java index fefe6c94cc6b..86619a12980f 100644 --- a/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/module-info.java +++ b/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/module-info.java @@ -4,6 +4,7 @@ requires io.ballerina.tools.api; requires compiler.plugin.test.diagnostic.utils.lib; requires compiler.plugin.test.string.utils.lib; + requires static org.jetbrains.annotations; exports io.samjs.plugins.badsad; } diff --git a/project-api/test-artifacts/diagnostic-utils-lib/src/main/java/io/samjs/jarlibrary/diagnosticutils/DiagnosticUtils.java b/project-api/test-artifacts/diagnostic-utils-lib/src/main/java/io/samjs/jarlibrary/diagnosticutils/DiagnosticUtils.java index 93b3b901c562..af360f2ef33b 100644 --- a/project-api/test-artifacts/diagnostic-utils-lib/src/main/java/io/samjs/jarlibrary/diagnosticutils/DiagnosticUtils.java +++ b/project-api/test-artifacts/diagnostic-utils-lib/src/main/java/io/samjs/jarlibrary/diagnosticutils/DiagnosticUtils.java @@ -22,6 +22,7 @@ import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.diagnostics.Location; +import org.jetbrains.annotations.Nullable; /** * A dummy diagnostic related util class. @@ -35,7 +36,7 @@ private DiagnosticUtils() { public static Diagnostic createDiagnostic(String code, String messageFormat, - Location location, + @Nullable Location location, DiagnosticSeverity severity, Object... args) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(code, messageFormat, severity); diff --git a/project-api/test-artifacts/diagnostic-utils-lib/src/main/java/module-info.java b/project-api/test-artifacts/diagnostic-utils-lib/src/main/java/module-info.java index 160d7b627720..242d32a396ce 100644 --- a/project-api/test-artifacts/diagnostic-utils-lib/src/main/java/module-info.java +++ b/project-api/test-artifacts/diagnostic-utils-lib/src/main/java/module-info.java @@ -1,6 +1,7 @@ module compiler.plugin.test.diagnostic.utils.lib { requires io.ballerina.lang; requires io.ballerina.tools.api; + requires static org.jetbrains.annotations; exports io.samjs.jarlibrary.diagnosticutils; } diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BCompileUtil.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BCompileUtil.java index 1beb7eb0358a..0827ccbe8716 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BCompileUtil.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BCompileUtil.java @@ -32,6 +32,7 @@ import io.ballerina.projects.repos.FileSystemCache; import io.ballerina.projects.util.ProjectConstants; import io.ballerina.projects.util.ProjectUtils; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.wso2.ballerinalang.compiler.bir.model.BIRNode; @@ -118,6 +119,7 @@ public static CompileResult compileOffline(String sourceFilePath) { return compileResult; } + @Nullable public static BIRCompileResult generateBIR(String sourceFilePath) { Project project = loadProject(sourceFilePath); NullBackend nullBackend = NullBackend.from(project.currentPackage().getCompilation()); diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/agent/server/RouteTable.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/agent/server/RouteTable.java index 10ba80dd5fed..9da55f6d87d5 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/agent/server/RouteTable.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/agent/server/RouteTable.java @@ -18,6 +18,7 @@ package org.ballerinalang.test.agent.server; import io.netty.handler.codec.http.HttpMethod; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -37,7 +38,7 @@ void addRoute(final Route route) { this.routes.add(route); } - Route findRoute(final HttpMethod method, final String path) { + @Nullable Route findRoute(final HttpMethod method, final String path) { for (final Route route : routes) { if (route.matches(method, path)) { return route; diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMainInstance.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMainInstance.java index 5f96b098a36f..7d8774a54aed 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMainInstance.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BMainInstance.java @@ -18,6 +18,7 @@ package org.ballerinalang.test.context; import org.apache.commons.lang3.ArrayUtils; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -115,20 +116,20 @@ public void runMain(String balFile, String[] flags, String[] args) throws Baller } @Override - public void runMain(String balFile, String[] flags, + public void runMain(String balFile, @Nullable String[] flags, String[] args, LogLeecher[] leechers) throws BallerinaTestException { runMain(balFile, flags, args, new HashMap<>(), new String[]{}, leechers); } @Override - public void runMain(String balFile, String[] flags, String[] args, Map envProperties, - String[] clientArgs) throws BallerinaTestException { + public void runMain(String balFile, String[] flags, String[] args, @Nullable Map envProperties, + @Nullable String[] clientArgs) throws BallerinaTestException { runMain(balFile, flags, args, envProperties, clientArgs, null); } @Override public void runMain(String balFile, String[] flags, String[] args, Map envProperties, - String[] clientArgs, LogLeecher[] leechers) throws BallerinaTestException { + String[] clientArgs, @Nullable LogLeecher[] leechers) throws BallerinaTestException { if (balFile == null || balFile.isEmpty()) { throw new IllegalArgumentException("Invalid ballerina program file name provided, name - " + balFile); } @@ -173,14 +174,15 @@ public void runMain(String sourceRoot, String packagePath, String[] flags, Strin @Override public void runMain(String sourceRoot, String packagePath, String[] flags, String[] args, - Map envProperties, String[] clientArgs) throws BallerinaTestException { + @Nullable Map envProperties, @Nullable String[] clientArgs + ) throws BallerinaTestException { runMain(sourceRoot, packagePath, flags, args, envProperties, clientArgs, null); } @Override public void runMain(String sourceRoot, String packagePath, - String[] flags, String[] args, Map envProperties, - String[] clientArgs, LogLeecher[] leechers) throws BallerinaTestException { + @Nullable String[] flags, String[] args, @Nullable Map envProperties, + @Nullable String[] clientArgs, @Nullable LogLeecher[] leechers) throws BallerinaTestException { if (sourceRoot == null || sourceRoot.isEmpty() || packagePath == null || packagePath.isEmpty()) { throw new IllegalArgumentException("Invalid ballerina program file provided, sourceRoot - " + sourceRoot + " packagePath - " + packagePath); @@ -232,8 +234,9 @@ public String getBalServerHome() { * @param commandDir where to execute the command * @throws BallerinaTestException if starting services failed */ - public void runMain(String command, String[] args, Map envProperties, String[] clientArgs, - LogLeecher[] leechers, String commandDir) throws BallerinaTestException { + public void runMain(String command, String[] args, @Nullable Map envProperties, + @Nullable String[] clientArgs, + @Nullable LogLeecher[] leechers, String commandDir) throws BallerinaTestException { String scriptName = Constant.BALLERINA_SERVER_SCRIPT_NAME; String[] cmdArray; try { @@ -348,7 +351,8 @@ public void waitForLeechers(List logLeechers, int timeout) throws Ba * @return parent instance process * @throws BallerinaTestException if starting services failed */ - public Process debugMain(String command, String[] args, Map envProperties, String[] clientArgs, + public Process debugMain(String command, String[] args, @Nullable Map envProperties, + String[] clientArgs, LogLeecher[] leechers, String commandDir, int timeout, boolean isAttachMode) throws BallerinaTestException { String scriptName = Constant.BALLERINA_SERVER_SCRIPT_NAME; @@ -463,7 +467,8 @@ public Process debugMain(String command, String[] args, Map envP * @param timeout timeout for the process waiting time, in seconds. * @throws BallerinaTestException if starting services failed */ - public void debugMain(String command, String[] args, Map envProperties, String[] clientArgs, + public void debugMain(String command, String[] args, @Nullable Map envProperties, + @Nullable String[] clientArgs, LogLeecher[] leechers, String commandDir, int timeout) throws BallerinaTestException { boolean isAttachMode = false; debugMain(command, args, envProperties, clientArgs, leechers, commandDir, timeout, isAttachMode); @@ -495,7 +500,7 @@ private boolean isLeechingDone(ServerLogReader infoReader, ServerLogReader error * * @param process parent process instance. */ - public void terminateProcessWithDescendants(Process process) { + public void terminateProcessWithDescendants(@Nullable Process process) { try { // Kills the descendants of the process. The descendants of a process are the children // of the process and the descendants of those children, recursively. diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServerInstance.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServerInstance.java index dcc709041ed0..dd3dcdfd4898 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServerInstance.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/context/BServerInstance.java @@ -20,6 +20,7 @@ import org.apache.commons.lang3.ArrayUtils; import org.ballerinalang.test.util.HttpClientRequest; import org.ballerinalang.test.util.HttpResponse; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -121,19 +122,21 @@ public void startServer(String balFile, int[] requiredPorts) throws BallerinaTes } @Override - public void startServer(String balFile, String[] buildArgs, String[] runtimeArgs, int[] requiredPorts) + public void startServer(String balFile, String[] buildArgs, @Nullable String[] runtimeArgs, int[] requiredPorts) throws BallerinaTestException { startServer(balFile, buildArgs, runtimeArgs, null, requiredPorts); } @Override - public void startServer(String balFile, String[] buildArgs, String[] runtimeArgs, Map envProperties, - int[] requiredPorts) throws BallerinaTestException { + public void startServer(String balFile, @Nullable String[] buildArgs, @Nullable String[] runtimeArgs, + @Nullable Map envProperties, int[] requiredPorts + ) throws BallerinaTestException { startServer(balFile, buildArgs, runtimeArgs, envProperties, requiredPorts, false); } @Override - public void startServer(String balFile, String[] buildArgs, String[] runtimeArgs, Map envProperties, + public void startServer(String balFile, String[] buildArgs, @Nullable String[] runtimeArgs, + @Nullable Map envProperties, int[] requiredPorts, boolean useBallerinaRunCommand) throws BallerinaTestException { if (balFile == null || balFile.isEmpty()) { throw new IllegalArgumentException("Invalid ballerina program file name provided, name - " + balFile); @@ -174,14 +177,16 @@ public void startServer(String sourceRoot, String packagePath, int[] requiredPor } @Override - public void startServer(String sourceRoot, String packagePath, String[] buildArgs, String[] runtimeArgs, - int[] requiredPorts) throws BallerinaTestException { + public void startServer(String sourceRoot, String packagePath, @Nullable String[] buildArgs, + @Nullable String[] runtimeArgs, + int @Nullable [] requiredPorts) throws BallerinaTestException { startServer(sourceRoot, packagePath, buildArgs, runtimeArgs, null, requiredPorts); } @Override public void startServer(String sourceRoot, String packagePath, String[] buildArgs, String[] runtimeArgs, - Map envProperties, int[] requiredPorts) throws BallerinaTestException { + @Nullable Map envProperties, int[] requiredPorts + ) throws BallerinaTestException { startServer(sourceRoot, packagePath, buildArgs, runtimeArgs, envProperties, requiredPorts, false); } @@ -367,7 +372,7 @@ public void removeAllLeechers() { * @param envProperties - environmental properties to be appended to the environment * @throws BallerinaTestException if starting services failed */ - private void runBuildTool(String command, String[] args, Map envProperties) + private void runBuildTool(String command, String[] args, @Nullable Map envProperties) throws BallerinaTestException { String[] cmdArray; diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/util/HttpClientRequest.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/util/HttpClientRequest.java index f0597dc37222..684358e95869 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/util/HttpClientRequest.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/util/HttpClientRequest.java @@ -19,6 +19,7 @@ import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaderValues; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -200,8 +201,9 @@ private static HttpResponse executeRequestAndPreserveNewline(String method, Stri PRESERVE_NEW_LINE_RESPONSE_BUILDER); } - private static HttpResponse executeRequestWithoutRequestBody(String method, String requestUrl, - Map headers, int readTimeout, + @Nullable + private static HttpResponse executeRequestWithoutRequestBody( + String method, String requestUrl, Map headers, int readTimeout, CheckedFunction responseBuilder) throws IOException { HttpURLConnection conn = null; try { @@ -216,10 +218,10 @@ private static HttpResponse executeRequestWithoutRequestBody(String method, Stri } } - private static HttpResponse executeRequestWithoutRequestBody(String method, String requestUrl, - Map headers, int readTimeout, - CheckedFunction responseBuilder, boolean throwError) - throws IOException { + @Nullable + private static HttpResponse executeRequestWithoutRequestBody( + String method, String requestUrl, Map headers, int readTimeout, + CheckedFunction responseBuilder, boolean throwError) throws IOException { HttpURLConnection conn = null; try { conn = getURLConnection(requestUrl, readTimeout); @@ -269,10 +271,12 @@ private static void setHeadersAndMethod(HttpURLConnection conn, Map responseBuilder, boolean throwError) throws IOException { diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/util/HttpResponse.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/util/HttpResponse.java index d3e8842c2a3f..41bd157848e8 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/util/HttpResponse.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/util/HttpResponse.java @@ -17,6 +17,8 @@ */ package org.ballerinalang.test.util; +import org.jetbrains.annotations.Nullable; + import java.util.Map; /** @@ -28,7 +30,7 @@ public class HttpResponse { private String responseMessage; private Map headers; - public HttpResponse(String data, int responseCode) { + public HttpResponse(@Nullable String data, int responseCode) { this.data = data; this.responseCode = responseCode; } diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/BallerinaTestDebugPoint.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/BallerinaTestDebugPoint.java index 0abf71788b56..5192f4381aaa 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/BallerinaTestDebugPoint.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/BallerinaTestDebugPoint.java @@ -20,6 +20,7 @@ import org.ballerinalang.test.context.BallerinaTestException; import org.eclipse.lsp4j.debug.Source; import org.eclipse.lsp4j.debug.SourceBreakpoint; +import org.jetbrains.annotations.Nullable; import java.net.URI; import java.nio.file.Path; @@ -53,15 +54,17 @@ public BallerinaTestDebugPoint(URI filePathUri, int line) { this(filePathUri, line, null, null, false); } - public BallerinaTestDebugPoint(Path filePath, int line, String condition, String logMessage) { + public BallerinaTestDebugPoint(Path filePath, int line, @Nullable String condition, @Nullable String logMessage) { this(filePath.toAbsolutePath().toUri(), line, condition, logMessage, false); } - public BallerinaTestDebugPoint(Path filePath, int line, String condition, String logMessage, boolean verified) { + public BallerinaTestDebugPoint(Path filePath, int line, @Nullable String condition, + @Nullable String logMessage, boolean verified) { this(filePath.toAbsolutePath().toUri(), line, condition, logMessage, verified); } - public BallerinaTestDebugPoint(URI filePathUri, int line, String condition, String logMessage, boolean verified) { + public BallerinaTestDebugPoint(URI filePathUri, int line, @Nullable String condition, + @Nullable String logMessage, boolean verified) { this.filePathUri = filePathUri; this.line = line; this.condition = condition; diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugHitListener.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugHitListener.java index 3b195fda8d94..de9dfa927069 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugHitListener.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugHitListener.java @@ -26,6 +26,7 @@ import org.eclipse.lsp4j.debug.StoppedEventArguments; import org.eclipse.lsp4j.debug.StoppedEventArgumentsReason; import org.eclipse.lsp4j.debug.ThreadsResponse; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,6 +95,7 @@ public void run() { } } + @Nullable private BallerinaTestDebugPoint fetchDebugHitPoint(StoppedEventArguments args) throws BallerinaTestException { if (!connector.isConnected()) { diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java index b3125219b782..cff83bd96e8f 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java @@ -51,6 +51,7 @@ import org.eclipse.lsp4j.debug.Variable; import org.eclipse.lsp4j.debug.VariablesArguments; import org.eclipse.lsp4j.debug.VariablesResponse; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -80,9 +81,11 @@ public class DebugTestRunner { private static Path testProjectBaseDir; private static Path testSingleFileBaseDir; private static BalServer balServer; + @Nullable private DAPClientConnector debugClientConnector; private boolean isConnected = false; private int port; + @Nullable private BMainInstance balClient = null; private Process debuggeeProcess; private DebugHitListener hitListener; @@ -274,6 +277,7 @@ public Optional addBreakPoint(BallerinaTestDebugPoint br return Optional.empty(); } + @Nullable private SetBreakpointsResponse setBreakpoints(List breakPoints) throws BallerinaTestException { diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/Callback.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/Callback.java index b52ee55f8761..43955d3cfeb3 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/Callback.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/Callback.java @@ -17,6 +17,8 @@ */ package org.ballerinalang.debugger.test.utils.client.connection; +import org.jetbrains.annotations.Nullable; + /** * This interface represents a callback to report back a success or a * failure state back to the originator. @@ -37,5 +39,5 @@ public interface Callback { * This should be called to notify the listener that your operation * failed with a specific error. */ - void notifyFailure(Exception e); + void notifyFailure(@Nullable Exception e); } diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/ProcessStreamConnectionProvider.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/ProcessStreamConnectionProvider.java index 435514483fb2..20c59f394bef 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/ProcessStreamConnectionProvider.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/ProcessStreamConnectionProvider.java @@ -15,6 +15,7 @@ */ package org.ballerinalang.debugger.test.utils.client.connection; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,11 +100,13 @@ private void configureJacocoAgentArgs(Map envProperties) { envProperties.put(ENV_DEBUGGER_TEST_MODE, String.valueOf(true)); } + @Nullable @Override public InputStream getInputStream() { return process != null ? process.getInputStream() : null; } + @Nullable @Override public OutputStream getOutputStream() { return process != null ? process.getOutputStream() : null; diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/SocketStreamConnectionProvider.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/SocketStreamConnectionProvider.java index 17d43bee955d..5a73f58b444a 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/SocketStreamConnectionProvider.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/client/connection/SocketStreamConnectionProvider.java @@ -16,6 +16,7 @@ package org.ballerinalang.debugger.test.utils.client.connection; import org.ballerinalang.debugger.test.utils.FileUtils; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +45,9 @@ public class SocketStreamConnectionProvider extends ProcessStreamConnectionProvi private final int port; private Socket socket; + @Nullable private InputStream inputStream; + @Nullable private OutputStream outputStream; public SocketStreamConnectionProvider(List commands, String workingDir, String address, int port, From 3eaf480942762ebd91c63c65d57c4ca4f0e46244 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Fri, 4 Oct 2024 22:51:43 +0200 Subject: [PATCH 02/12] Fix spotbugs errors --- .../jline/validator/ExpressionValidator.java | 2 +- .../validator/ModuleMemberValidator.java | 4 +- .../jline/validator/StatementValidator.java | 2 +- .../internal/scheduling/AsyncUtils.java | 3 +- .../internal/scheduling/Scheduler.java | 4 +- .../runtime/internal/types/BFunctionType.java | 3 +- .../io/ballerina/cli/cmd/CommandUtil.java | 1 - .../api/impl/BallerinaSemanticModel.java | 2 +- .../compiler/api/impl/ExpectedTypeFinder.java | 6 +- .../compiler/api/impl/NodeFinder.java | 7 +-- .../compiler/api/impl/ReferenceFinder.java | 5 +- .../compiler/api/impl/TypeParamResolver.java | 3 +- .../BallerinaTypeReferenceTypeSymbol.java | 4 +- .../BallerinaSingletonTypeBuilder.java | 3 + .../io/ballerina/projects/BalaWriter.java | 27 +++++---- .../ballerina/projects/JBallerinaBackend.java | 4 +- .../ballerina/projects/ModuleCompilation.java | 2 +- .../io/ballerina/projects/ModuleContext.java | 10 +++- .../java/io/ballerina/projects/Package.java | 14 ++--- .../io/ballerina/projects/PackageContext.java | 6 +- .../ballerina/projects/PackageResolution.java | 13 +---- .../projects/internal/BlendedManifest.java | 11 ++-- .../internal/ImportModuleResponse.java | 7 ++- .../projects/internal/ModuleResolver.java | 2 +- .../environment/DefaultPackageResolver.java | 12 ++-- .../repositories/RemotePackageRepository.java | 6 +- .../io/ballerina/projects/util/FileUtils.java | 5 +- .../spi/SystemPackageRepositoryProvider.java | 6 +- .../ballerinalang/toml/model/Dependency.java | 55 ++++++++----------- .../toml/model/DependencyMetadata.java | 7 +-- .../ballerinalang/toml/model/Manifest.java | 13 ++--- .../toml/parser/ManifestProcessor.java | 2 +- .../compiler/bir/BIRGenUtils.java | 7 ++- .../compiler/bir/codegen/JvmCodeGenUtil.java | 3 +- .../optimizer/LargeMethodOptimizer.java | 16 ++++-- .../bir/model/BIRAbstractInstruction.java | 2 - .../compiler/bir/model/BIRNode.java | 17 +----- .../compiler/bir/model/BIRNonTerminator.java | 1 - .../optimizer/BIRRecordValueOptimizer.java | 1 - .../compiler/desugar/Desugar.java | 2 +- .../compiler/desugar/MockDesugar.java | 22 ++++---- .../compiler/packaging/repo/PathBalaRepo.java | 18 +++--- .../model/symbols/BConstantSymbol.java | 1 - .../model/symbols/BInvokableSymbol.java | 1 - .../model/symbols/BInvokableTypeSymbol.java | 10 +--- .../semantics/model/types/BRecordType.java | 1 - .../semantics/model/types/BTupleType.java | 4 +- .../semantics/model/types/BUnionType.java | 5 +- .../compiler/tree/BLangNode.java | 1 - .../compiler/tree/BLangPackage.java | 7 +-- .../expressions/BLangAnnotAccessExpr.java | 2 +- .../tree/expressions/BLangBinaryExpr.java | 2 +- .../tree/expressions/BLangElvisExpr.java | 2 +- .../BLangExtendedXMLNavigationAccess.java | 2 +- .../tree/expressions/BLangIgnoreExpr.java | 2 +- .../expressions/BLangIndexBasedAccess.java | 2 +- .../BLangInferredTypedescDefaultNode.java | 2 +- .../tree/expressions/BLangInvocation.java | 4 +- .../expressions/BLangIsAssignableExpr.java | 2 +- .../tree/expressions/BLangIsLikeExpr.java | 2 +- .../tree/expressions/BLangLetExpression.java | 2 +- .../tree/expressions/BLangLiteral.java | 3 - .../BLangObjectConstructorExpression.java | 2 +- .../BLangStringTemplateLiteral.java | 6 +- .../tree/expressions/BLangTernaryExpr.java | 2 +- .../expressions/BLangTypeConversionExpr.java | 11 ++-- .../tree/expressions/BLangTypeTestExpr.java | 6 +- .../tree/expressions/BLangUnaryExpr.java | 2 +- .../tree/expressions/BLangWaitForAllExpr.java | 2 +- .../expressions/BLangXMLCommentLiteral.java | 5 +- .../expressions/BLangXMLFilterStepExtend.java | 2 +- .../BLangXMLIndexedStepExtend.java | 2 +- .../expressions/BLangXMLNavigationAccess.java | 14 ++--- .../expressions/BLangXMLProcInsLiteral.java | 6 +- .../expressions/BLangXMLQuotedString.java | 6 +- .../tree/expressions/BLangXMLTextLiteral.java | 6 +- .../ballerinalang/compiler/util/Name.java | 4 +- .../RemotePackageRepositoryTests.java | 4 +- .../toml/ManifestProcessorTest.java | 34 ++++++------ .../parser/AbstractParserErrorHandler.java | 15 +++-- .../internal/parser/BallerinaLexer.java | 3 +- .../internal/parser/BallerinaParser.java | 3 +- .../parser/BallerinaParserErrorHandler.java | 2 +- .../internal/parser/DocumentationLexer.java | 3 +- .../compiler/internal/parser/RegExpLexer.java | 3 +- .../compiler/internal/parser/Result.java | 8 +-- .../compiler/internal/parser/XMLLexer.java | 3 +- .../java/io/ballerina/tools/text/LineMap.java | 9 +-- .../common/completion/TomlCompletionUtil.java | 3 +- .../ExtractToLocalVarCodeAction.java | 2 - .../FunctionCallExpressionTypeFinder.java | 19 +++++++ .../src/main/java/module-info.java | 1 + .../debugadapter/ExecutionContext.java | 10 +--- .../debugadapter/JBallerinaDebugServer.java | 21 +++---- .../evaluation/EvaluatorBuilder.java | 2 +- .../engine/InvocationArgProcessor.java | 3 +- .../validator/SerialExpressionValidator.java | 26 ++------- .../variable/BCompoundVariable.java | 3 +- .../variable/IndexedCompoundVariable.java | 3 +- .../variable/NamedCompoundVariable.java | 3 +- .../debugadapter/variable/VariableUtils.java | 5 +- .../debugadapter/variable/types/BMap.java | 5 +- .../debugadapter/variable/types/BRecord.java | 6 ++ .../org/ballerinalang/docgen/Generator.java | 7 ++- .../docgen/generator/model/Type.java | 27 ++++----- .../java/io/ballerina/identifier/Utils.java | 5 +- ...terinaSystemPackageRepositoryProvider.java | 3 +- .../toml/internal/parser/AbstractLexer.java | 3 +- .../toml/internal/parser/TomlLexer.java | 3 +- .../test/HierarchicalPackageNameTests.java | 10 ++-- .../badsad/BadSadCompilerPlugin20.java | 3 +- .../debugger/test/utils/DebugTestRunner.java | 10 +++- 112 files changed, 343 insertions(+), 400 deletions(-) diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ExpressionValidator.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ExpressionValidator.java index 0de762496f18..9fc5345ec73c 100644 --- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ExpressionValidator.java +++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ExpressionValidator.java @@ -47,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)); } } diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ModuleMemberValidator.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ModuleMemberValidator.java index f10ba28dde35..af4c290af8e9 100644 --- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ModuleMemberValidator.java +++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/ModuleMemberValidator.java @@ -61,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)); } } diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/StatementValidator.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/StatementValidator.java index f0a223d1b03e..bb6bcddcc377 100644 --- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/StatementValidator.java +++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/validator/StatementValidator.java @@ -47,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)); } } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java index b7bca9188ae2..d515c77cb385 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java @@ -131,7 +131,8 @@ public void notifyFailure(BError error) { * @param returnValueSupplier Suppler used to set the final return value for the parent function invocation. * @param scheduler The scheduler for invoking functions */ - public static void invokeFunctionPointerAsyncIteratively(BFunctionPointer func, @Nullable String strandName, + public static void invokeFunctionPointerAsyncIteratively(BFunctionPointer func, + @Nullable String strandName, StrandMetadata metadata, int noOfIterations, Supplier argsSupplier, Consumer futureResultConsumer, diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java index 873376a8957c..1d9b53c1427d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java @@ -228,8 +228,8 @@ public FutureValue schedule( * @param metadata meta data of new strand * @return Reference to the scheduled task */ - public FutureValue schedule(Object[] params, Function function, @Nullable Strand parent, Callback callback, - String strandName, @Nullable StrandMetadata metadata) { + public FutureValue schedule(Object[] params, Function function, @Nullable Strand parent, + Callback callback, String strandName, @Nullable StrandMetadata metadata) { FutureValue future = createFuture(parent, callback, null, PredefinedTypes.TYPE_NULL, strandName, metadata); return schedule(params, function, future); } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFunctionType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFunctionType.java index e47fb78d085f..310c3ef9b650 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFunctionType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BFunctionType.java @@ -40,7 +40,6 @@ public class BFunctionType extends BAnnotatableType implements FunctionType { @Nullable public Type retType; public long flags; - @Nullable public Parameter[] parameters; public BFunctionType(Module pkg) { @@ -52,7 +51,7 @@ public BFunctionType(Module pkg) { public BFunctionType(Module pkg, long flags) { super("function", pkg, Object.class); - this.parameters = null; + this.parameters = new Parameter[0]; this.retType = null; this.flags = flags; } diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java index 0c8ab7c73fe7..8d0f448bde6e 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java @@ -998,7 +998,6 @@ private static void initToolPackage(Path path, String packageName) throws IOExce Files.writeString(balToolToml, balToolManifest); } - @Nullable private static Optional findLatest(List packageVersions) { if (packageVersions.isEmpty()) { return Optional.empty(); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/BallerinaSemanticModel.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/BallerinaSemanticModel.java index accd587b2511..0d4f4dcdfc5d 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/BallerinaSemanticModel.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/BallerinaSemanticModel.java @@ -570,7 +570,7 @@ private BSymbol getInternalSymbol(Symbol symbol) { private BPackageSymbol getModuleSymbol(BLangCompilationUnit compilationUnit) { return compilationUnit.getSourceKind() == REGULAR_SOURCE ? bLangPackage.symbol : - bLangPackage.getTestablePkg().symbol; + bLangPackage.getTestablePkg().orElseThrow().symbol; } private void addToCompiledSymbols(Set compiledSymbols, Scope.ScopeEntry scopeEntry, Location cursorPos, diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java index 7c49201c0e7b..b37a3b620a41 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java @@ -1189,7 +1189,7 @@ private Optional getExpectedTypeFromFunction(BLangNode bLangNode, To } if (langLibInvocation) { - if (bLangInvocation.expr.getBType().getKind() == TypeKind.ARRAY) { + if (bLangInvocation.expr != null && bLangInvocation.expr.getBType().getKind() == TypeKind.ARRAY) { return Optional.ofNullable(typesFactory.getTypeDescriptor (((BArrayType) bLangInvocation.expr.expectedType).eType)); } @@ -1207,7 +1207,9 @@ private Optional getExpectedTypeFromFunction(BLangNode bLangNode, To } BLangExpression bLangExpression = bLangInvocation.argExprs.get(argumentIndex); - if (bLangExpression.toString().startsWith("$missingNode$")) { + // Spotbugs thinks this can be nullable for some reason + String bLangExpressionString = bLangExpression.toString(); + if (bLangExpressionString != null && bLangExpressionString.startsWith("$missingNode$")) { return getParamType(bLangInvocation, argumentIndex, namedArgs); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/NodeFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/NodeFinder.java index d0e3717dca1d..2167bc5b6f23 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/NodeFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/NodeFinder.java @@ -46,7 +46,6 @@ import org.wso2.ballerinalang.compiler.tree.BLangSimpleVariable; import org.wso2.ballerinalang.compiler.tree.BLangTableKeySpecifier; import org.wso2.ballerinalang.compiler.tree.BLangTableKeyTypeConstraint; -import org.wso2.ballerinalang.compiler.tree.BLangTestablePackage; import org.wso2.ballerinalang.compiler.tree.BLangTupleVariable; import org.wso2.ballerinalang.compiler.tree.BLangTypeDefinition; import org.wso2.ballerinalang.compiler.tree.BLangXMLNS; @@ -230,11 +229,7 @@ class NodeFinder extends BaseVisitor { BLangNode lookup(BLangPackage module, LineRange range) { List topLevelNodes = new ArrayList<>(module.topLevelNodes); - BLangTestablePackage tests = module.getTestablePkg(); - - if (tests != null) { - topLevelNodes.addAll(tests.topLevelNodes); - } + module.getTestablePkg().ifPresent(tests -> topLevelNodes.addAll(tests.topLevelNodes)); return lookupTopLevelNodes(topLevelNodes, range); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java index f93eb5ab7803..6daa1c7f8e64 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java @@ -218,6 +218,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import static org.ballerinalang.model.symbols.SymbolOrigin.VIRTUAL; @@ -275,7 +276,7 @@ public void visit(BLangPackage pkgNode) { .toList()); if (!(pkgNode instanceof BLangTestablePackage)) { - find(pkgNode.getTestablePkg()); + find(pkgNode.getTestablePkg().orElseThrow()); } } @@ -1509,7 +1510,7 @@ private void findRefsInResourceAccessPathSegments(BLangInvocation.BLangResourceA } BLangLiteral literal = (BLangLiteral) expr; - if (literal.value.equals(pathSymbol.name.value) && addIfSameSymbol(pathSymbol, expr.pos)) { + if (Objects.equals(literal.value, pathSymbol.name.value) && addIfSameSymbol(pathSymbol, expr.pos)) { return; } } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamResolver.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamResolver.java index 2e351df60b61..60dff723bcab 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamResolver.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/TypeParamResolver.java @@ -20,6 +20,7 @@ import org.ballerinalang.model.symbols.AnnotationAttachmentSymbol; import org.ballerinalang.model.symbols.SymbolKind; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BAttachedFunction; @@ -378,7 +379,7 @@ private boolean isTypeParam(BType type) { return type == this.typeParam; } - @Nullable + @Contract("null, _ -> null") private BVarSymbol createNewVarSymbol(BVarSymbol symbol, @Nullable BType newType) { if (symbol == null) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaTypeReferenceTypeSymbol.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaTypeReferenceTypeSymbol.java index b83ff89514b5..0ca7e9d86a87 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaTypeReferenceTypeSymbol.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/symbols/BallerinaTypeReferenceTypeSymbol.java @@ -28,7 +28,7 @@ import io.ballerina.compiler.api.symbols.TypeSymbol; import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.symbols.SymbolOrigin; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Contract; import org.wso2.ballerinalang.compiler.semantics.model.Scope; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; import org.wso2.ballerinalang.compiler.semantics.model.types.BParameterizedType; @@ -199,7 +199,7 @@ private boolean isAnonOrg(ModuleID moduleID) { return ANON_ORG.equals(moduleID.orgName()); } - @Nullable + @Contract("null -> null") private BType getReferredType(BType type) { if (type == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaSingletonTypeBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaSingletonTypeBuilder.java index 2663313de43f..5b2c1c09e367 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaSingletonTypeBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/type/builders/BallerinaSingletonTypeBuilder.java @@ -70,6 +70,9 @@ public SingletonTypeSymbol build() { if (value == null) { throw new IllegalArgumentException("The value provided to the singleton type can not be null"); } + if (valueTypeSymbol == null) { + throw new IllegalArgumentException("The type symbol provided to the singleton type can not be null"); + } if (!isValidValueType(value, valueTypeSymbol)) { throw new IllegalArgumentException("Type of value provided doesn't match with the provided type symbol"); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalaWriter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalaWriter.java index 781aaab087ec..cab739ba140d 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalaWriter.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalaWriter.java @@ -37,6 +37,7 @@ import io.ballerina.tools.text.TextDocuments; import org.apache.commons.compress.utils.IOUtils; import org.ballerinalang.compiler.BLangCompilerException; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.util.RepoUtils; @@ -236,7 +237,7 @@ private static Boolean isAllPlatformDepsGraalvmCompatible(Map addPlatformLibs(ZipOutputStream balaOutpu // Following function was put in to handle a bug in windows zipFileSystem // Refer https://bugs.openjdk.java.net/browse/JDK-8195141 - @Nullable + @Contract("null -> null") private String convertPathSeperator(Path file) { if (file == null) { return null; - } else { - if (File.separatorChar == '\\') { - String replaced; - // Following is to evade spotbug issue if file is null - replaced = Optional.ofNullable(file.getFileName()).orElse(Path.of("")).toString(); - Path parent = file.getParent(); - while (parent != null) { - replaced = parent.getFileName() + UNIX_FILE_SEPARATOR + replaced; - parent = parent.getParent(); - } - return replaced; - } + } + if (File.separatorChar != '\\') { return file.toString(); } + // Following is to evade spotbug issue if file is null + String replaced = Optional.ofNullable(file.getFileName()).orElse(Path.of("")).toString(); + Path parent = file.getParent(); + while (parent != null) { + replaced = parent.getFileName() + UNIX_FILE_SEPARATOR + replaced; + parent = parent.getParent(); + } + return replaced; } } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java index 17e48ba7e47c..cf08dce1023d 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java @@ -420,7 +420,6 @@ public List conflictedJars() { } // TODO Can we move this method to Module.displayName() - @Nullable private String getJarFileName(ModuleContext moduleContext) { String jarName; if (moduleContext.project().kind() == ProjectKind.SINGLE_FILE_PROJECT) { @@ -644,7 +643,8 @@ private PlatformLibrary codeGeneratedLibrary(PackageId packageId, Package pkg = packageCache.getPackageOrThrow(packageId); ProjectEnvironment projectEnvironment = pkg.project().projectEnvironmentContext(); CompilationCache compilationCache = projectEnvironment.getService(CompilationCache.class); - String jarFileName = getJarFileName(pkg.packageContext().moduleContext(moduleName)) + fileNameSuffix; + String jarFileName = getJarFileName(pkg.packageContext().moduleContext(moduleName).orElseThrow()) + + fileNameSuffix; Optional platformSpecificLibrary = compilationCache.getPlatformSpecificLibrary( this, jarFileName); return new JarLibrary(platformSpecificLibrary.orElseThrow( diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleCompilation.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleCompilation.java index 2d7730f0bcfc..df16ef74d533 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleCompilation.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleCompilation.java @@ -82,7 +82,7 @@ private void addModuleDependencies(ModuleDescriptor moduleDescriptor, Collection directDependencies = new HashSet<>(pkg.get().moduleDependencyGraph(). getDirectDependencies(moduleDescriptor)); - ModuleContext moduleCtx = pkg.get().packageContext().moduleContext(moduleDescriptor.name()); + ModuleContext moduleCtx = pkg.get().packageContext().moduleContext(moduleDescriptor.name()).orElseThrow(); for (ModuleDependency moduleDependency : moduleCtx.dependencies()) { PackageId dependentPkgId = moduleDependency.packageDependency().packageId(); if (dependentPkgId == pkg.get().packageId()) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java index 7f0427b971b9..968d401ea241 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java @@ -494,11 +494,15 @@ private static ByteArrayOutputStream generateBIR(ModuleContext moduleContext, Co // Can we improve this logic ByteArrayOutputStream birContent = new ByteArrayOutputStream(); try { - CompiledBinaryFile.BIRPackageFile birPackageFile = moduleContext.bLangPackage.symbol.birPackageFile; + BLangPackage bLangPackage = moduleContext.bLangPackage; + if (bLangPackage == null) { + throw new IllegalStateException("BLangPackage is null"); + } + CompiledBinaryFile.BIRPackageFile birPackageFile = bLangPackage.symbol.birPackageFile; if (birPackageFile == null) { birPackageFile = new CompiledBinaryFile - .BIRPackageFile(new BIRBinaryWriter(moduleContext.bLangPackage.symbol.bir).serialize()); - moduleContext.bLangPackage.symbol.birPackageFile = birPackageFile; + .BIRPackageFile(new BIRBinaryWriter(bLangPackage.symbol.bir).serialize()); + bLangPackage.symbol.birPackageFile = birPackageFile; } byte[] pkgBirBinaryContent = PackageFileWriter.writePackage(birPackageFile); birContent.writeBytes(pkgBirBinaryContent); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java index 6f5d9f8f808d..547b32bf8e26 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java @@ -128,7 +128,6 @@ public Module module(@Nullable ModuleId moduleId) { return this.moduleMap.computeIfAbsent(moduleId, this.populateModuleFunc); } - @Nullable public Module module(ModuleName moduleName) { for (Module module : this.moduleMap.values()) { if (module.moduleName().equals(moduleName)) { @@ -136,12 +135,9 @@ public Module module(ModuleName moduleName) { } } - ModuleContext moduleContext = this.packageContext.moduleContext(moduleName); - if (moduleContext != null) { - return module(moduleContext.moduleId()); - } - - return null; + return this.packageContext.moduleContext(moduleName) + .map(moduleContext -> module(moduleContext.moduleId())) + .orElseThrow(() -> new IllegalArgumentException("Module not found: " + moduleName)); } public boolean containsModule(ModuleId moduleId) { @@ -752,7 +748,9 @@ private void deleteCaches(ResolvedPackageDependency dependency, } private void updatePackageManifest() { - ManifestBuilder manifestBuilder = ManifestBuilder.from(this.ballerinaTomlContext.tomlDocument(), + ManifestBuilder manifestBuilder = ManifestBuilder.from( + Optional.ofNullable(this.ballerinaTomlContext) + .map(TomlDocumentContext::tomlDocument).orElse(null), Optional.ofNullable(this.compilerPluginTomlContext) .map(TomlDocumentContext::tomlDocument).orElse(null), Optional.ofNullable(this.balToolTomlContext) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java index 4a3736dd675d..6f2cfd0266dc 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java @@ -206,13 +206,13 @@ ModuleContext moduleContext(ModuleId moduleId) { return moduleContextMap.get(moduleId); } - @Nullable ModuleContext moduleContext(ModuleName moduleName) { + Optional moduleContext(ModuleName moduleName) { for (ModuleContext moduleContext : moduleContextMap.values()) { if (moduleContext.moduleName().equals(moduleName)) { - return moduleContext; + return Optional.of(moduleContext); } } - return null; + return Optional.empty(); } ModuleContext defaultModuleContext() { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageResolution.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageResolution.java index f7eb0d7666b8..d6fe7a834680 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageResolution.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageResolution.java @@ -386,13 +386,7 @@ static Optional findModuleInPackage(PackageContext resolvedPackag } moduleName = ModuleName.from(packageName, moduleNamePart); } - ModuleContext resolvedModule = resolvedPackage.moduleContext(moduleName); - if (resolvedModule == null) { - return Optional.empty(); - } - - // TODO convert this to a debug log - return Optional.of(resolvedModule); + return resolvedPackage.moduleContext(moduleName); } private DependencyGraph buildPackageGraph(DependencyGraph depGraph, @@ -705,10 +699,9 @@ public Optional getModule(PackageOrg packageOrg, String moduleNam PackageName packageName; // TODO remove the null check and else block once the new resolution is fully done - packageName = importModuleResponse.packageDescriptor().name(); + packageName = importModuleResponse.packageDescriptor().orElseThrow().name(); - Optional optionalPackage = getPackage(packageOrg, - packageName); + Optional optionalPackage = getPackage(packageOrg, packageName); if (optionalPackage.isEmpty()) { return Optional.empty(); // This branch cannot be executed since the package is resolved before hand diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java index 117b71e932ba..73c525158bc0 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BlendedManifest.java @@ -39,6 +39,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import static io.ballerina.projects.PackageVersion.BUILTIN_PACKAGE_VERSION; @@ -82,12 +83,12 @@ public static BlendedManifest from(DependencyManifest dependencyManifest, AbstractPackageRepository targetRepository = localPackageRepository; Optional existingDepOptional = depContainer.get( depInPkgManifest.org(), depInPkgManifest.name()); - Repository depInPkgManifestRepo = depInPkgManifest.repository() != null && - depInPkgManifest.repository().equals(ProjectConstants.LOCAL_REPOSITORY_NAME) ? + Repository depInPkgManifestRepo = Objects.equals( + depInPkgManifest.repository(), ProjectConstants.LOCAL_REPOSITORY_NAME) ? REPOSITORY_LOCAL : new Repository(depInPkgManifest.repository()); if (depInPkgManifest.repository() != null) { - if (!depInPkgManifest.repository().equals(ProjectConstants.LOCAL_REPOSITORY_NAME) && + if (!Objects.equals(depInPkgManifest.repository(), ProjectConstants.LOCAL_REPOSITORY_NAME) && !mavenPackageRepositoryMap.containsKey(depInPkgManifest.repository())) { var diagnosticInfo = new DiagnosticInfo( ProjectDiagnosticErrorCode.CUSTOM_REPOSITORY_NOT_FOUND.diagnosticId(), @@ -101,7 +102,7 @@ public static BlendedManifest from(DependencyManifest dependencyManifest, } - if (depInPkgManifest.repository().equals(ProjectConstants.LOCAL_REPOSITORY_NAME) && + if (Objects.equals(depInPkgManifest.repository(), ProjectConstants.LOCAL_REPOSITORY_NAME) && !localPackageRepository.isPackageExists(depInPkgManifest.org(), depInPkgManifest.name(), depInPkgManifest.version())) { var diagnosticInfo = new DiagnosticInfo( @@ -116,7 +117,7 @@ public static BlendedManifest from(DependencyManifest dependencyManifest, continue; } - if (!depInPkgManifest.repository().equals(ProjectConstants.LOCAL_REPOSITORY_NAME)) { + if (!Objects.equals(depInPkgManifest.repository(), ProjectConstants.LOCAL_REPOSITORY_NAME)) { targetRepository = mavenPackageRepositoryMap.get(depInPkgManifest.repository()); if (!((MavenPackageRepository) targetRepository).isPackageExists(depInPkgManifest.org(), depInPkgManifest.name(), depInPkgManifest.version(), offline)) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ImportModuleResponse.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ImportModuleResponse.java index 3e0598755592..45882105427b 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ImportModuleResponse.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ImportModuleResponse.java @@ -21,6 +21,8 @@ import io.ballerina.projects.environment.ResolutionResponse; import org.jetbrains.annotations.Nullable; +import java.util.Optional; + /** * Represents a resolved imported module. * @@ -60,9 +62,8 @@ public ImportModuleRequest importModuleRequest() { return importModuleRequest; } - @Nullable - public PackageDescriptor packageDescriptor() { - return packageDescriptor; + public Optional packageDescriptor() { + return Optional.ofNullable(packageDescriptor); } public ResolutionResponse.ResolutionStatus resolutionStatus() { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleResolver.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleResolver.java index 1046fbd660eb..1f39320636d5 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleResolver.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ModuleResolver.java @@ -95,7 +95,7 @@ public PackageContainer resolveModuleLoadRequests( DirectPackageDependency newPkgDep; ImportModuleRequest importModuleRequest = importModResp.importModuleRequest(); - PackageDescriptor pkgDesc = importModResp.packageDescriptor(); + PackageDescriptor pkgDesc = importModResp.packageDescriptor().orElseThrow(); Optional pkgDepOptional = pkgContainer.get(pkgDesc.org(), pkgDesc.name()); ModuleLoadRequest moduleLoadRequest = importModuleRequest.moduleLoadRequest(); if (pkgDepOptional.isEmpty()) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/DefaultPackageResolver.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/DefaultPackageResolver.java index 42256bc7fc74..5558091aadc2 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/DefaultPackageResolver.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/DefaultPackageResolver.java @@ -101,11 +101,13 @@ public Collection resolvePackageNames(Collection packageVersions = distributionRepo.getPackageVersions(resolutionRequest, options); // If module exists in both repos, then we check if a newer version of diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/RemotePackageRepository.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/RemotePackageRepository.java index 0e5a05f6fb48..4708dea720b4 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/RemotePackageRepository.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/repositories/RemotePackageRepository.java @@ -208,9 +208,9 @@ private List mergeNameResolution(Collection/."); + "/."); } - + public String getModuleName() { - String[] moduleIDParts = this.getModuleID().split("/"); + String[] moduleIDParts = this.moduleID().split("/"); if (moduleIDParts.length == 2) { return moduleIDParts[1]; } throw new BLangCompilerException("invalid dependency name. dependency should be in the format " + - "/."); - } - - public DependencyMetadata getMetadata() { - return metadata; - } - - public void setMetadata(DependencyMetadata metadata) { - this.metadata = metadata; + "/."); } - + @Override public String toString() { - return null != this.metadata && - null != this.metadata.getVersion() && - !this.metadata.getVersion().trim().isEmpty() ? - getModuleID() + ":" + this.metadata.getVersion() : getModuleID(); + return moduleID + Optional.ofNullable(metadata) + .flatMap(meta -> Optional.ofNullable(meta.getVersion())) + .map(version -> version.isEmpty() ? "" : ":" + version) + .orElse(""); } - + @Override public boolean equals(Object o) { if (this == o) { @@ -83,7 +74,7 @@ public boolean equals(Object o) { } return this.toString().equals(that.toString()); } - + @Override public int hashCode() { return Objects.hash(toString()); diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java index 154c7f854f53..b992a76e2191 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/DependencyMetadata.java @@ -18,7 +18,6 @@ package org.ballerinalang.toml.model; import org.ballerinalang.toml.util.PathUtils; -import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.Optional; @@ -55,12 +54,8 @@ public void setVersion(String version) { * * @return location of the dependency */ - @Nullable public Optional getPath() { - if (PathUtils.getPath(this.path) == null) { - return Optional.empty(); - } - return Optional.of(Path.of(PathUtils.getPath(this.path))); + return Optional.ofNullable(PathUtils.getPath(this.path)).map(Path::of); } /** diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Manifest.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Manifest.java index 3e059952d317..50721ad5e01c 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Manifest.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Manifest.java @@ -52,13 +52,8 @@ public Map getDependenciesAsObjectMap() { public List getDependencies() { return this.dependencies.entrySet().stream() - .map(entry -> { - Dependency dependency = new Dependency(); - // get rid of the double quotes - dependency.setModuleID(entry.getKey()); - dependency.setMetadata(convertObjectToDependencyMetadata(entry.getValue())); - return dependency; - }) + // get rid of the double quotes + .map(entry -> new Dependency(entry.getKey(), convertObjectToDependencyMetadata(entry.getValue()))) .toList(); } @@ -67,11 +62,11 @@ private DependencyMetadata convertObjectToDependencyMetadata(Object obj) { if (obj instanceof String s) { metadata.setVersion(s); } else if (obj instanceof Map metadataMap) { - if (metadataMap.keySet().contains("version") && metadataMap.get("version") instanceof String) { + if (metadataMap.containsKey("version") && metadataMap.get("version") instanceof String) { metadata.setVersion((String) metadataMap.get("version")); } - if (metadataMap.keySet().contains("path") && metadataMap.get("path") instanceof String) { + if (metadataMap.containsKey("path") && metadataMap.get("path") instanceof String) { metadata.setPath((String) metadataMap.get("path")); } } diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/parser/ManifestProcessor.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/parser/ManifestProcessor.java index a96513a560a2..42cc4ca32b15 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/parser/ManifestProcessor.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/parser/ManifestProcessor.java @@ -239,7 +239,7 @@ public static byte[] addDependenciesToManifest(ByteArrayInputStream manifestStre } for (Dependency dep : deps) { - dependencies.put(dep.getOrgName() + "/" + dep.getModuleName(), dep.getMetadata().getVersion()); + dependencies.put(dep.getOrgName() + "/" + dep.getModuleName(), dep.metadata().getVersion()); } toml.put("dependencies", dependencies); TomlWriter writer = new TomlWriter(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenUtils.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenUtils.java index e4c4554216ba..ea2aeb03c2a0 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenUtils.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGenUtils.java @@ -22,6 +22,8 @@ import org.wso2.ballerinalang.compiler.util.Name; import java.util.Comparator; +import java.util.List; +import java.util.Optional; /** * Util functions required for handling BIR. @@ -48,11 +50,12 @@ public static void rearrangeBasicBlocks(BIRNode.BIRPackage birPackage) { public static void rearrangeBasicBlocks(BIRNode.BIRFunction birFunction) { int currentBBId = 0; // Re-arrange basic blocks - for (BIRNode.BIRBasicBlock bb : birFunction.basicBlocks) { + for (BIRNode.BIRBasicBlock bb : Optional.ofNullable(birFunction.basicBlocks).orElse(List.of())) { currentBBId = renumberBasicBlock(currentBBId, bb); } // Re-arrange error entries - birFunction.errorTable.sort(Comparator.comparingInt(o -> o.trapBB.number)); + Optional.ofNullable(birFunction.errorTable).ifPresent( + errorTable -> errorTable.sort(Comparator.comparingInt(o -> o.trapBB.number))); } public static int renumberBasicBlock(int newBBNum, BIRBasicBlock bb) { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java index c1b628ff46fb..705baa664672 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java @@ -24,6 +24,7 @@ import org.ballerinalang.compiler.BLangCompilerException; import org.ballerinalang.model.elements.PackageID; import org.ballerinalang.model.symbols.SymbolKind; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Handle; @@ -640,7 +641,7 @@ public static boolean needNoTypeGeneration(int bTypeTag) { * @return the implied type if provided with a type reference type or an intersection type, * else returns the original type */ - @Nullable + @Contract("null -> null") public static BType getImpliedType(BType type) { if (type == null) { return null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/optimizer/LargeMethodOptimizer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/optimizer/LargeMethodOptimizer.java index ad3fc9f2738e..b657291a3fcd 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/optimizer/LargeMethodOptimizer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/optimizer/LargeMethodOptimizer.java @@ -1897,9 +1897,12 @@ private BIRFunction createNewBIRFuncForSplitInBB(Name funcName, BIRNonTerminator birFunc.returnVariable = new BIRVariableDcl(currentIns.pos, retType, new Name("%0"), VarScope.FUNCTION, VarKind.RETURN, null); } - birFunc.localVars.add(0, birFunc.returnVariable); - birFunc.localVars.addAll(functionParams); - birFunc.localVars.addAll(lhsOperandList); + List localVars = birFunc.localVars; + if (localVars != null) { + localVars.add(0, birFunc.returnVariable); + localVars.addAll(functionParams); + localVars.addAll(lhsOperandList); + } // creates 2 bbs BIRBasicBlock entryBB = new BIRBasicBlock(0); @@ -1909,8 +1912,11 @@ private BIRFunction createNewBIRFuncForSplitInBB(Name funcName, BIRNonTerminator BIRBasicBlock exitBB = new BIRBasicBlock(1); exitBB.terminator = new BIRTerminator.Return(null); entryBB.terminator = new BIRTerminator.GOTO(null, exitBB, currentIns.scope); - birFunc.basicBlocks.add(entryBB); - birFunc.basicBlocks.add(exitBB); + List basicBlocks = birFunc.basicBlocks; + if (basicBlocks != null) { + basicBlocks.add(entryBB); + basicBlocks.add(exitBB); + } rectifyVarKindsAndTerminators(birFunc, selfVarDcl, exitBB); return birFunc; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRAbstractInstruction.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRAbstractInstruction.java index ea21bae50e5b..084b3c5b8172 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRAbstractInstruction.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRAbstractInstruction.java @@ -18,7 +18,6 @@ package org.wso2.ballerinalang.compiler.bir.model; import io.ballerina.tools.diagnostics.Location; -import org.jetbrains.annotations.Nullable; /** * Abstract instruction with an lhs-operand. @@ -28,7 +27,6 @@ public abstract class BIRAbstractInstruction extends BIRNode implements BIRInstruction { public InstructionKind kind; - @Nullable public BIROperand lhsOp; public BirScope scope; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java index 23373c74867a..b7d449e24bb2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNode.java @@ -323,7 +323,6 @@ public static class BIRFunction extends BIRDocumentableNode implements NamedNode /** * Receiver. This is an optional field. */ - @Nullable public BIRVariableDcl receiver; /** @@ -343,28 +342,23 @@ public static class BIRFunction extends BIRDocumentableNode implements NamedNode * entries are allocated for function arguments. The rest are for user-defined local variables and * temporary variables. */ - @Nullable public List localVars; - @Nullable public BIRVariableDcl returnVariable; /** * Variable used for parameters of this function. */ - @Nullable public List parameters; /** * List of basic blocks in this function. */ - @Nullable public List basicBlocks; /** * List of error entries in this function. */ - @Nullable public List errorTable; /** @@ -375,24 +369,18 @@ public static class BIRFunction extends BIRDocumentableNode implements NamedNode /** * List of channels this worker interacts. */ - @Nullable public ChannelDetails[] workerChannels; - @Nullable public List annotAttachments; - @Nullable public List returnTypeAnnots; - @Nullable public Set dependentGlobalVars = new TreeSet<>(); // Below fields will only be available on resource functions // TODO: consider creating a sub class for resource functions issue: #36964 - @Nullable public List pathParams; - - @Nullable + public BIRVariableDcl restPathParam; public List resourcePath; @@ -492,7 +480,7 @@ public static class BIRBasicBlock extends BIRNode { public int number; public Name id; public List instructions; - @Nullable + // TODO add @Nullable public BIRTerminator terminator; public static final String BIR_BASIC_BLOCK_PREFIX = "bb"; @@ -554,7 +542,6 @@ public static class BIRTypeDefinition extends BIRDocumentableNode implements Nam public SymbolOrigin origin; - @Nullable public List annotAttachments; /** diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java index 38d436613dc6..971980235121 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/model/BIRNonTerminator.java @@ -275,7 +275,6 @@ public void setRhsOperands(BIROperand[] operands) { public static class NewInstance extends BIRNonTerminator { public final boolean isExternalDef; public final PackageID externalPackageId; - @Nullable public BIRTypeDefinition def; public final String objectName; public final BType expectedType; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRRecordValueOptimizer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRRecordValueOptimizer.java index 503d7579127c..9a8f892c206e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRRecordValueOptimizer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/optimizer/BIRRecordValueOptimizer.java @@ -53,7 +53,6 @@ public class BIRRecordValueOptimizer extends BIRVisitor { private final List recordOperandList = new ArrayList<>(); private final Map recordOperandTypeMap = new HashMap<>(); - @Nullable private BIRNode.BIRBasicBlock lastBB = null; private BIRNode.BIRFunction currentFunction = null; private List newBBs = new ArrayList<>(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java index fdddbe690a0f..68a0ef86bc40 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java @@ -787,7 +787,7 @@ public void visit(BLangPackage pkgNode) { // Adding object functions to package level. addAttachedFunctionsToPackageLevel(pkgNode, env); - if (!pkgNode.testablePkgs.isEmpty() && pkgNode.getTestablePkg().getMockFunctionNamesMap() != null) { + if (!pkgNode.testablePkgs.isEmpty()) { mockDesugar.generateMockFunctions(pkgNode); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java index 66fac7555406..589d563f9c00 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java @@ -116,16 +116,16 @@ public void generateMockFunctions(BLangPackage pkgNode) { this.bLangPackage = pkgNode; // Get the Mock Function map from the pkgNode - Map mockFunctionMap = pkgNode.getTestablePkg().getMockFunctionNamesMap(); + Map mockFunctionMap = pkgNode.getTestablePkg().orElseThrow().getMockFunctionNamesMap(); // Get the mock function type map from the pkgNode - Map isLegacyMockingMap = pkgNode.getTestablePkg().getIsLegacyMockingMap(); + Map isLegacyMockingMap = pkgNode.getTestablePkg().orElseThrow().getIsLegacyMockingMap(); // Get the set of functions to generate Set mockFunctionSet = mockFunctionMap.keySet(); for (String function : mockFunctionSet) { if (!isLegacyMockingMap.get(function)) { - pkgNode.getTestablePkg().functions.add(generateMockFunction(function)); + pkgNode.getTestablePkg().orElseThrow().functions.add(generateMockFunction(function)); } } } @@ -138,7 +138,8 @@ public void generateMockFunctions(BLangPackage pkgNode) { */ private BLangFunction generateMockFunction(String functionName) { // Set the current mock object - this.mockFnObjectName = this.bLangPackage.getTestablePkg().getMockFunctionNamesMap().get(functionName); + this.mockFnObjectName = this.bLangPackage.getTestablePkg().orElseThrow() + .getMockFunctionNamesMap().get(functionName); // Reset both import and original functions this.importFunction = null; @@ -195,8 +196,8 @@ private BInvokableSymbol getImportFunction(String functionName, String packageNa getInvokableSymbol(functionName, packageName, this.bLangPackage.getImports()); if (bInvokableSymbol == null) { - bInvokableSymbol = - getInvokableSymbol(functionName, packageName, this.bLangPackage.getTestablePkg().getImports()); + bInvokableSymbol = getInvokableSymbol(functionName, packageName, + this.bLangPackage.getTestablePkg().orElseThrow().getImports()); } return bInvokableSymbol; @@ -389,7 +390,8 @@ private BLangLiteral generateRHSExpr(String val) { // This function synthesizes the Ballerina equivalent of : `= [(class1), (class2)]` private BLangListConstructorExpr generateClassListConstructorExpr() { - List compUnitList = this.bLangPackage.getTestablePkg().getCompilationUnits(); + List compUnitList = this.bLangPackage.getTestablePkg().orElseThrow() + .getCompilationUnits(); BArrayType bArrayType = new BArrayType(symTable.stringType, null, -1, BArrayState.OPEN); List modifiedcompUnitList = new ArrayList<>(); @@ -453,7 +455,7 @@ private BLangInvocation generateBLangInvocation() { // This function synthesizes the Ballerina equivalent of : `MockHandler()` @Nullable private BInvokableSymbol getMockHandlerInvokableSymbol() { - List packageList = bLangPackage.getTestablePkg().getImports(); + List packageList = bLangPackage.getTestablePkg().orElseThrow().getImports(); for (BLangImportPackage importPackage : packageList) { if (importPackage.alias.getValue().equals("test")) { BInvokableSymbol mockHandlerSymbol = @@ -501,8 +503,8 @@ private List generateInvocationArgsExprs() { // This function synthesizes the Ballerina equivalent of : `(` private BLangSimpleVarRef getMockFunctionReference() { - BVarSymbol mockObjectSymbol = - (BVarSymbol) bLangPackage.getTestablePkg().symbol.scope.lookup(new Name(this.mockFnObjectName)).symbol; + BVarSymbol mockObjectSymbol = (BVarSymbol) bLangPackage.getTestablePkg().orElseThrow() + .symbol.scope.lookup(new Name(this.mockFnObjectName)).symbol; BLangSimpleVarRef bLangSimpleVarRef = ASTBuilderUtil.createVariableRef(bLangPackage.pos, mockObjectSymbol); return bLangSimpleVarRef; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java index 5d5956c109ae..8b6bb5f85092 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/PathBalaRepo.java @@ -66,7 +66,7 @@ public Patten calculate(PackageID moduleID) { this.manifest.getDependencies().stream() .filter(dep -> dep.getOrgName().equals(moduleID.orgName.value) && dep.getModuleName().equals(moduleID.name.value) && - dep.getMetadata().getPath().isPresent()) + dep.metadata().getPath().isPresent()) .findFirst(); // if dependency is not found in toml @@ -75,25 +75,25 @@ public Patten calculate(PackageID moduleID) { } Dependency dep = tomlDependency.get(); - Path balaPath = dep.getMetadata().getPath().orElseThrow(); + Path balaPath = dep.metadata().getPath().orElseThrow(); // if bala file does not exists if (Files.notExists(balaPath)) { - throw new BLangCompilerException("bala file for dependency [" + dep.getModuleID() + "] does not exists: " + - dep.getMetadata().getPath().orElseThrow().toAbsolutePath().normalize()); + throw new BLangCompilerException("bala file for dependency [" + dep.moduleID() + "] does not exists: " + + dep.metadata().getPath().orElseThrow().toAbsolutePath().normalize()); } // if bala file is not a file if (!Files.isRegularFile(balaPath)) { - throw new BLangCompilerException("bala file for dependency [" + dep.getModuleID() + "] is not a file: " + - dep.getMetadata().getPath().orElseThrow().toAbsolutePath().normalize()); + throw new BLangCompilerException("bala file for dependency [" + dep.moduleID() + "] is not a file: " + + dep.metadata().getPath().orElseThrow().toAbsolutePath().normalize()); } // update version of the dependency from the current(root) project - if (moduleID.version.value.isEmpty() && null != dep.getMetadata().getVersion()) { - Matcher semverMatcher = SEM_VER_PATTERN.matcher(dep.getMetadata().getVersion()); + if (moduleID.version.value.isEmpty() && null != dep.metadata().getVersion()) { + Matcher semverMatcher = SEM_VER_PATTERN.matcher(dep.metadata().getVersion()); if (semverMatcher.matches()) { - moduleID.version = new Name(dep.getMetadata().getVersion()); + moduleID.version = new Name(dep.metadata().getVersion()); } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BConstantSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BConstantSymbol.java index 3c5b5e7eae15..f3db5d760d78 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BConstantSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BConstantSymbol.java @@ -34,7 +34,6 @@ */ public class BConstantSymbol extends BVarSymbol implements ConstantSymbol { - @Nullable public BLangConstantValue value; public BType literalType; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableSymbol.java index 9c8444547cf0..08c6f9382287 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableSymbol.java @@ -40,7 +40,6 @@ */ public class BInvokableSymbol extends BVarSymbol implements InvokableSymbol { - @Nullable public List params; @Nullable public BVarSymbol restParam; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableTypeSymbol.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableTypeSymbol.java index a38cc8df10d4..f042b528e4ee 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableTypeSymbol.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BInvokableTypeSymbol.java @@ -38,21 +38,17 @@ */ public class BInvokableTypeSymbol extends BTypeSymbol { - @Nullable - public List params; + public List params = new ArrayList<>(); @Nullable public BVarSymbol restParam; @Nullable public BType returnType; - public List returnTypeAnnots; - public Map defaultValues; + public final List returnTypeAnnots = new ArrayList<>(); + public final Map defaultValues = new HashMap<>(); public BInvokableTypeSymbol(long symTag, long flags, PackageID pkgID, @Nullable BType type, BSymbol owner, Location location, SymbolOrigin origin) { super(symTag, flags, Names.EMPTY, Names.EMPTY, pkgID, type, owner, location, origin); - this.params = new ArrayList<>(); - this.returnTypeAnnots = new ArrayList<>(); - this.defaultValues = new HashMap<>(); } @Override diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java index 20a40537bc08..b03d8ee26164 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BRecordType.java @@ -42,7 +42,6 @@ public class BRecordType extends BStructureType implements RecordType { public static final String EMPTY = ""; public static final String READONLY = "readonly"; public boolean sealed; - @Nullable public BType restFieldType; public Boolean isAnyData = null; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java index 0125942d0af4..399a697b6a72 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BTupleType.java @@ -25,7 +25,6 @@ import org.wso2.ballerinalang.compiler.util.TypeTags; import org.wso2.ballerinalang.util.Flags; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -96,8 +95,7 @@ private BTupleType(BTypeSymbol tsymbol, boolean readonly) { @Override public List getTupleTypes() { if (memberTypes == null) { - memberTypes = new ArrayList<>(members.size()); - members.forEach(member -> memberTypes.add(member.type)); + this.memberTypes = members.stream().map(member -> member.type).collect(Collectors.toList()); } return memberTypes; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java index 27b80ac6b85d..be53dac19b2b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/types/BUnionType.java @@ -19,6 +19,7 @@ import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.model.types.UnionType; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.TypeVisitor; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; @@ -412,7 +413,7 @@ public static LinkedHashSet toFlatTypeSet(LinkedHashSet types) { * @return the implied type if provided with a type reference type or an intersection type, * else returns the original type */ - @Nullable + @Contract(value = "null -> null") public static BType getImpliedType(BType type) { type = getReferredType(type); if (type != null && type.tag == TypeTags.INTERSECTION) { @@ -422,7 +423,7 @@ public static BType getImpliedType(BType type) { return type; } - @Nullable + @Contract(value = "null -> null") private static BType getReferredType(BType type) { if (type != null && type.tag == TypeTags.TYPEREFDESC) { return getReferredType(((BTypeReferenceType) type).referredType); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangNode.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangNode.java index 434ea26ce9b8..276f8d225097 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangNode.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangNode.java @@ -48,7 +48,6 @@ public abstract class BLangNode implements Node, Cloneable { /** * The location of this node in the source file. */ - @Nullable public Location pos; /* diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java index 10044e2a02c1..9f5932b6bcc9 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java @@ -35,7 +35,6 @@ import org.ballerinalang.model.tree.TopLevelNode; import org.ballerinalang.model.tree.TypeDefinition; import org.ballerinalang.model.tree.XMLNSDeclarationNode; -import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.DiagnosticComparator; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol; @@ -48,6 +47,7 @@ import java.util.EnumSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Queue; import java.util.Set; import java.util.TreeSet; @@ -247,9 +247,8 @@ public List getTestablePkgs() { * * @return testable package */ - @Nullable - public BLangTestablePackage getTestablePkg() { - return testablePkgs.stream().findAny().orElse(null); + public Optional getTestablePkg() { + return testablePkgs.stream().findAny(); } /** diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangAnnotAccessExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangAnnotAccessExpr.java index 0fd095e1ad3b..84c303df876e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangAnnotAccessExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangAnnotAccessExpr.java @@ -42,7 +42,7 @@ public class BLangAnnotAccessExpr extends BLangExpression implements AnnotAccess @Override public String toString() { - return String.valueOf(expr) + ".@" + annotationSymbol.bvmAlias(); + return expr + ".@" + annotationSymbol.bvmAlias(); } @Override diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangBinaryExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangBinaryExpr.java index 844ecd3551da..5778bb245c99 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangBinaryExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangBinaryExpr.java @@ -81,6 +81,6 @@ public R apply(BLangNodeTransformer modifier, T props) { @Override public String toString() { - return String.valueOf(lhsExpr) + " " + String.valueOf(opKind) + " " + String.valueOf(rhsExpr); + return lhsExpr + " " + opKind + " " + rhsExpr; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangElvisExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangElvisExpr.java index 73a9dd125b62..7a98b7bfafda 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangElvisExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangElvisExpr.java @@ -67,6 +67,6 @@ public R apply(BLangNodeTransformer modifier, T props) { @Override public String toString() { - return String.valueOf(lhsExpr) + "?:" + String.valueOf(rhsExpr); + return lhsExpr + "?:" + rhsExpr; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangExtendedXMLNavigationAccess.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangExtendedXMLNavigationAccess.java index 41bf15aae4f9..6c7da60c3a91 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangExtendedXMLNavigationAccess.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangExtendedXMLNavigationAccess.java @@ -85,6 +85,6 @@ public BLangExpression getExpression() { public String toString() { StringJoiner extensionString = new StringJoiner(""); this.extensions.forEach(extension -> extensionString.add(extension.toString())); - return stepExpr.toString() + extensionString.toString(); + return stepExpr.toString() + extensionString; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIgnoreExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIgnoreExpr.java index 9c78c79b7191..4ca225d09526 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIgnoreExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIgnoreExpr.java @@ -53,6 +53,6 @@ public NodeKind getKind() { @Override public String toString() { - return ("_"); + return "_"; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIndexBasedAccess.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIndexBasedAccess.java index 434134a8ec16..d508f7d3b238 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIndexBasedAccess.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIndexBasedAccess.java @@ -53,7 +53,7 @@ public BLangExpression getIndex() { @Override public String toString() { - return String.valueOf(expr) + "[" + String.valueOf(indexExpr) + "]"; + return expr + "[" + indexExpr + "]"; } @Override diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInferredTypedescDefaultNode.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInferredTypedescDefaultNode.java index e46cd9da0a0e..3c78297ce330 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInferredTypedescDefaultNode.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInferredTypedescDefaultNode.java @@ -52,6 +52,6 @@ public NodeKind getKind() { @Override public String toString() { - return ("<>"); + return "<>"; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInvocation.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInvocation.java index 82587768a677..1afa8756ebff 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInvocation.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangInvocation.java @@ -310,7 +310,7 @@ public String toString() { StringJoiner joiner = new StringJoiner("/"); resourceAccessPathSegments.exprs.forEach(item -> joiner.add(item.toString())); - br.append(joiner.toString()); + br.append(joiner); br.append("."); br.append(name == null ? String.valueOf(symbol.name) : String.valueOf(name)); @@ -318,7 +318,7 @@ public String toString() { br.append("("); StringJoiner joiner1 = new StringJoiner(","); argExprs.forEach(item -> joiner1.add(item.toString())); - br.append(joiner1.toString()); + br.append(joiner1); br.append(")"); return br.toString(); diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIsAssignableExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIsAssignableExpr.java index 7cbbdb859366..2837ad6c5788 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIsAssignableExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIsAssignableExpr.java @@ -79,6 +79,6 @@ public NodeKind getKind() { @Override public String toString() { - return String.valueOf(this.lhsExpr) + " " + this.opKind.value() + " " + this.targetType; + return this.lhsExpr + " " + this.opKind.value() + " " + this.targetType; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIsLikeExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIsLikeExpr.java index c41bd7474bec..17f548f58d07 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIsLikeExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangIsLikeExpr.java @@ -82,6 +82,6 @@ public R apply(BLangNodeTransformer modifier, T props) { @Override public String toString() { - return String.valueOf(expr) + " isLike " + typeNode.getBType(); + return expr + " isLike " + typeNode.getBType(); } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLetExpression.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLetExpression.java index 9b35e6aa58a8..3d9f503337d9 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLetExpression.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLetExpression.java @@ -81,6 +81,6 @@ public String toString() { for (BLangLetVariable letVarDeclaration : letVarDeclarations) { declarations.add(String.valueOf(letVarDeclaration)); } - return "let " + declarations.toString() + " in " + String.valueOf(this.expr); + return "let " + declarations + " in " + this.expr; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLiteral.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLiteral.java index 59a89fdd67ea..28b96f4ddd9d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLiteral.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangLiteral.java @@ -19,7 +19,6 @@ import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.expressions.LiteralNode; -import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.semantics.model.types.BType; import org.wso2.ballerinalang.compiler.tree.BLangNodeAnalyzer; import org.wso2.ballerinalang.compiler.tree.BLangNodeTransformer; @@ -31,9 +30,7 @@ public class BLangLiteral extends BLangExpression implements LiteralNode { // Parser Flags and Data - @Nullable public Object value; - @Nullable public String originalValue; public boolean isConstant; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangObjectConstructorExpression.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangObjectConstructorExpression.java index 6c34da526224..53a0cb5d8380 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangObjectConstructorExpression.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangObjectConstructorExpression.java @@ -78,7 +78,7 @@ public NodeKind getKind() { @Override public String toString() { - StringBuilder sb = new StringBuilder(""); + StringBuilder sb = new StringBuilder(); if (isClient) { sb.append("client "); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangStringTemplateLiteral.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangStringTemplateLiteral.java index 630387f509ee..5c25cba56d01 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangStringTemplateLiteral.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangStringTemplateLiteral.java @@ -33,11 +33,7 @@ public class BLangStringTemplateLiteral extends BLangExpression implements StringTemplateLiteralNode { // BLangNodes - public List exprs; - - public BLangStringTemplateLiteral() { - exprs = new ArrayList(); - } + public List exprs = new ArrayList<>(); @Override public List getExpressions() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTernaryExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTernaryExpr.java index a720784f6638..35afa4ab555b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTernaryExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTernaryExpr.java @@ -71,6 +71,6 @@ public R apply(BLangNodeTransformer modifier, T props) { @Override public String toString() { - return String.valueOf(expr) + "?" + String.valueOf(thenExpr) + ":" + String.valueOf(elseExpr); + return expr + "?" + thenExpr + ":" + elseExpr; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTypeConversionExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTypeConversionExpr.java index ce330f41bd70..f65ab81d3a17 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTypeConversionExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTypeConversionExpr.java @@ -95,13 +95,10 @@ public R apply(BLangNodeTransformer modifier, T props) { @Override public String toString() { - return new StringBuilder() - .append("<") - .append(annAttachments.isEmpty() ? "" : attachmentsToString()) - .append(targetType != null ? targetType.toString() : "") - .append("> ") - .append(String.valueOf(expr)) - .toString(); + return "<%s%s> %s".formatted( + annAttachments.isEmpty() ? "" : attachmentsToString(), + targetType != null ? targetType.toString() : "", + expr); } private String attachmentsToString() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTypeTestExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTypeTestExpr.java index 7a401a332322..b0fb1586ac29 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTypeTestExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangTypeTestExpr.java @@ -87,10 +87,6 @@ public R apply(BLangNodeTransformer modifier, T props) { @Override public String toString() { - if (isNegation) { - return expr + " !is " + typeNode; - } else { - return expr + " is " + typeNode; - } + return expr + (isNegation ? " !is " : " is ") + typeNode; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangUnaryExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangUnaryExpr.java index 0b6dfa3c4bab..a60998362dea 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangUnaryExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangUnaryExpr.java @@ -75,6 +75,6 @@ public R apply(BLangNodeTransformer modifier, T props) { @Override public String toString() { - return String.valueOf(operator) + " " + String.valueOf(expr); + return operator + " " + expr; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangWaitForAllExpr.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangWaitForAllExpr.java index b1bed05bdd88..a2cc1948cf62 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangWaitForAllExpr.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangWaitForAllExpr.java @@ -77,7 +77,7 @@ private List keyValPairs() { List keyValList = new ArrayList<>(); for (BLangWaitKeyValue keyVal : keyValuePairs) { if (keyVal.valueExpr != null) { - keyValList.add(keyVal.key.value + ":" + keyVal.valueExpr.toString()); + keyValList.add(keyVal.key.value + ":" + keyVal.valueExpr); } else { keyValList.add(keyVal.key.value); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLCommentLiteral.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLCommentLiteral.java index 613b5c2b7e7c..7d0cb34bb35b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLCommentLiteral.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLCommentLiteral.java @@ -33,12 +33,9 @@ public class BLangXMLCommentLiteral extends BLangExpression implements XMLCommentLiteralNode { // BLangNodes - public List textFragments; + public List textFragments = new ArrayList<>(); public BLangExpression concatExpr; // TODO: #AST_CLEAN - public BLangXMLCommentLiteral() { - textFragments = new ArrayList(); - } @Override public List getTextFragments() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLFilterStepExtend.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLFilterStepExtend.java index c197fec1d357..bb691ac16bde 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLFilterStepExtend.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLFilterStepExtend.java @@ -65,6 +65,6 @@ public NodeKind getKind() { public String toString() { StringJoiner filters = new StringJoiner(" |"); this.filters.forEach(f -> filters.add(f.toString())); - return "." + "/<" + filters.toString() + ">"; + return "./<%s>".formatted(filters); } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLIndexedStepExtend.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLIndexedStepExtend.java index 98412eb82fd7..b529e8a088d1 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLIndexedStepExtend.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLIndexedStepExtend.java @@ -60,7 +60,7 @@ public R apply(BLangNodeTransformer modifier, T props) { @Override public String toString() { - return "[" + String.valueOf(indexExpr) + "]"; + return "[" + indexExpr + "]"; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLNavigationAccess.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLNavigationAccess.java index 344d4cff729e..b241840c39e6 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLNavigationAccess.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLNavigationAccess.java @@ -89,14 +89,10 @@ public BLangExpression getExpression() { public String toString() { StringJoiner filters = new StringJoiner(" |"); this.filters.forEach(f -> filters.add(f.toString())); - switch (navAccessType) { - case CHILDREN: - return String.valueOf(expr) + "/*"; - case CHILD_ELEMS: - return String.valueOf(expr) + "/<" + filters.toString() + ">"; - case DESCENDANTS: - return String.valueOf(expr) + "/**/<" + filters.toString() + ">"; - } - return null; + return switch (navAccessType) { + case CHILDREN -> expr + "/*"; + case CHILD_ELEMS -> expr + "/<" + filters + ">"; + case DESCENDANTS -> expr + "/**/<" + filters + ">"; + }; } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLProcInsLiteral.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLProcInsLiteral.java index d627726ccc6f..d87a48fe8e58 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLProcInsLiteral.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLProcInsLiteral.java @@ -35,15 +35,11 @@ public class BLangXMLProcInsLiteral extends BLangExpression implements XMLProces // BLangNodes public BLangLiteral target; - public List dataFragments; + public List dataFragments = new ArrayList<>(); // Semantic Data public BLangExpression dataConcatExpr; - public BLangXMLProcInsLiteral() { - dataFragments = new ArrayList(); - } - @Override public LiteralNode getTarget() { return target; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLQuotedString.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLQuotedString.java index c927555aee30..b9e7023fc519 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLQuotedString.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLQuotedString.java @@ -34,17 +34,13 @@ public class BLangXMLQuotedString extends BLangExpression implements XMLQuotedStringNode { // BLangNodes - public List textFragments; + public List textFragments = new ArrayList<>(); // Parser Flags and Data public QuoteType quoteType; // Semantic Data public BLangExpression concatExpr; - - public BLangXMLQuotedString() { - textFragments = new ArrayList(); - } @Override public List getTextFragments() { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLTextLiteral.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLTextLiteral.java index b1eca4c1c56b..efc4cd5e3a5a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLTextLiteral.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/expressions/BLangXMLTextLiteral.java @@ -33,15 +33,11 @@ public class BLangXMLTextLiteral extends BLangExpression implements XMLTextLiteralNode { // BLangNodes - public List textFragments; + public List textFragments = new ArrayList<>(); // Semantic Data public BLangExpression concatExpr; - public BLangXMLTextLiteral() { - textFragments = new ArrayList(); - } - @Override public List getTextFragments() { return textFragments; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Name.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Name.java index f64ed85e7d72..0e1def40935b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Name.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Name.java @@ -17,8 +17,6 @@ */ package org.wso2.ballerinalang.compiler.util; -import org.jetbrains.annotations.Nullable; - /** * @since 0.94 */ @@ -27,7 +25,7 @@ public class Name implements org.ballerinalang.model.Name { //TODO: Make this field private. public final String value; - public Name(@Nullable String value) { + public Name(String value) { this.value = value; } diff --git a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/RemotePackageRepositoryTests.java b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/RemotePackageRepositoryTests.java index cc2787f34fa2..93d364d92c8d 100644 --- a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/RemotePackageRepositoryTests.java +++ b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/RemotePackageRepositoryTests.java @@ -278,10 +278,10 @@ public void testPackageNameResolution() throws CentralClientException { Assert.assertEquals(response.size(), 3); ImportModuleResponse javaArray = response.get(0); - Assert.assertEquals(javaArray.packageDescriptor().name().value(), "java.array"); + Assert.assertEquals(javaArray.packageDescriptor().orElseThrow().name().value(), "java.array"); ImportModuleResponse covid = response.get(1); - Assert.assertEquals(covid.packageDescriptor().name().value(), "covid"); + Assert.assertEquals(covid.packageDescriptor().orElseThrow().name().value(), "covid"); ImportModuleResponse unknown = response.get(2); Assert.assertEquals(unknown.resolutionStatus(), ResolutionResponse.ResolutionStatus.UNRESOLVED); diff --git a/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java b/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java index 6b3dca5a9ba6..bef462053cc3 100644 --- a/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java +++ b/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java @@ -144,9 +144,9 @@ public void testSingleDependencies() throws TomlException, IOException { Manifest manifest = ManifestProcessor.parseTomlContentFromString(this.validProjectBlock + "[dependencies] \n " + "string-utils = {path = '" + balaPath + "', version = \"1.1.5\"} \n"); - Assert.assertEquals(manifest.getDependencies().get(0).getModuleID(), "string-utils"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getVersion(), "1.1.5"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getPath().toString(), balaPath.toString()); + Assert.assertEquals(manifest.getDependencies().get(0).moduleID(), "string-utils"); + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getVersion(), "1.1.5"); + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getPath().toString(), balaPath.toString()); Files.delete(balaPath); Files.delete(tmpDir); @@ -167,15 +167,15 @@ public void testDependenciesIrregularPath() throws TomlException, IOException { Manifest manifest = ManifestProcessor.parseTomlContentFromString(this.validProjectBlock + "[dependencies] \n " + "string-utils = {path = '" + balaPath + "', version = \"1.1.5\"} \n"); - Path manifestPath = manifest.getDependencies().get(0).getMetadata().getPath(); + Path manifestPath = manifest.getDependencies().get(0).metadata().getPath().orElseThrow(); if (manifestPath.toString().contains("\\")) { manifestPath = Path.of(manifestPath.toString().replace("\\", "/")); } else { manifestPath = Path.of(manifestPath.toString().replace("/", "\\")); } - Assert.assertEquals(manifest.getDependencies().get(0).getModuleID(), "string-utils"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getVersion(), "1.1.5"); + Assert.assertEquals(manifest.getDependencies().get(0).moduleID(), "string-utils"); + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getVersion(), "1.1.5"); Assert.assertEquals(manifestPath.toString(), balaPath.toString()); } @@ -183,7 +183,7 @@ public void testDependenciesIrregularPath() throws TomlException, IOException { public void testSingleEmptyDependencies() throws TomlException { Manifest manifest = ManifestProcessor.parseTomlContentFromString(this.validProjectBlock + "[dependencies] \n " + "string-utils = {} \n"); - Assert.assertEquals(manifest.getDependencies().get(0).getModuleID(), "string-utils"); + Assert.assertEquals(manifest.getDependencies().get(0).moduleID(), "string-utils"); } @Test(description = "Multiple dependencies added with path in the regular form to the dependencies section " + @@ -196,11 +196,11 @@ public void testMultipleDependencies() throws TomlException, IOException { Manifest manifest = ManifestProcessor.parseTomlContentFromString(this.validProjectBlock + "[dependencies] \n " + "string-utils = { path = '" + balaPath + "', version = \"1.0.5\" } \n " + "jquery = { version = \"2.2.3\" } \n"); - Assert.assertEquals(manifest.getDependencies().get(0).getModuleID(), "string-utils"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getVersion(), "1.0.5"); - Assert.assertEquals(manifest.getDependencies().get(1).getModuleID(), "jquery"); - Assert.assertEquals(manifest.getDependencies().get(1).getMetadata().getVersion(), "2.2.3"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getPath().toString(), balaPath.toString()); + Assert.assertEquals(manifest.getDependencies().get(0).moduleID(), "string-utils"); + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getVersion(), "1.0.5"); + Assert.assertEquals(manifest.getDependencies().get(1).moduleID(), "jquery"); + Assert.assertEquals(manifest.getDependencies().get(1).metadata().getVersion(), "2.2.3"); + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getPath().toString(), balaPath.toString()); Files.delete(balaPath); Files.delete(tmpDir); @@ -216,11 +216,11 @@ public void testDependencyWithWindowsAbsolutePath() throws TomlException, IOExce Manifest manifest = ManifestProcessor.parseTomlContentFromString(this.validProjectBlock + "[dependencies] \n " + "string-utils = { path = '" + balaPath + "', version = \"1.0.5\" } \n " + "jquery = { version = \"2.2.3\" } \n"); - Assert.assertEquals(manifest.getDependencies().get(0).getModuleID(), "string-utils"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getVersion(), "1.0.5"); - Assert.assertEquals(manifest.getDependencies().get(1).getModuleID(), "jquery"); - Assert.assertEquals(manifest.getDependencies().get(1).getMetadata().getVersion(), "2.2.3"); - Assert.assertEquals(manifest.getDependencies().get(0).getMetadata().getPath().toString(), + Assert.assertEquals(manifest.getDependencies().get(0).moduleID(), "string-utils"); + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getVersion(), "1.0.5"); + Assert.assertEquals(manifest.getDependencies().get(1).moduleID(), "jquery"); + Assert.assertEquals(manifest.getDependencies().get(1).metadata().getVersion(), "2.2.3"); + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getPath().toString(), balaPath.toString()); Files.delete(balaPath); diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParserErrorHandler.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParserErrorHandler.java index 2d85c3bca683..6d321474e876 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParserErrorHandler.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/AbstractParserErrorHandler.java @@ -25,6 +25,7 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Class to be extended by any parser error handler class. @@ -159,7 +160,7 @@ private void validateSolution(Result bestMatch, ParserRuleContext currentCtx, ST } Solution firstFix = bestMatch.popFix(); - Solution secondFix = bestMatch.peekFix(); + Solution secondFix = bestMatch.peekFix().orElseThrow(); bestMatch.pushFix(firstFix); if (secondFix.action == Action.REMOVE && secondFix.depth == 1) { @@ -314,9 +315,8 @@ public void switchContext(ParserRuleContext context) { * * @return head of the stack */ - @Nullable protected ParserRuleContext getParentContext() { - return this.ctxStack.peek(); + return Objects.requireNonNull(this.ctxStack.peek()); } /** @@ -324,12 +324,11 @@ protected ParserRuleContext getParentContext() { * * @return second element of the stack */ - @Nullable protected ParserRuleContext getGrandParentContext() { ParserRuleContext parent = this.ctxStack.pop(); ParserRuleContext grandParent = this.ctxStack.peek(); this.ctxStack.push(parent); - return grandParent; + return Objects.requireNonNull(grandParent); } /** @@ -422,8 +421,8 @@ protected Result seekInAlternativesPaths(int lookahead, int currentDepth, int cu } if (currentMatchRemoveFixes == bestMatchRemoveFixes) { - Solution currentSol = bestMatch.peekFix(); - Solution foundSol = currentMatch.peekFix(); + Solution currentSol = bestMatch.peekFix().orElseThrow(); + Solution foundSol = currentMatch.peekFix().orElseThrow(); if (currentSol.action == Action.REMOVE && foundSol.action == Action.INSERT) { bestMatch = currentMatch; } @@ -480,7 +479,7 @@ protected Result fixAndContinue(ParserRuleContext currentCtx, int lookahead, int // i.e: do not increment the match count by 1; if (isEntryPoint) { - fixedPathResult.solution = fixedPathResult.peekFix(); + fixedPathResult.solution = fixedPathResult.peekFix().orElseThrow(); } else { fixedPathResult.solution = new Solution(Action.KEEP, currentCtx, getExpectedTokenKind(currentCtx), currentCtx.toString()); diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaLexer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaLexer.java index a00d39fee324..f0ccf57b7b01 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaLexer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaLexer.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * A LL(k) lexer for ballerina. @@ -45,7 +46,7 @@ public BallerinaLexer(CharReader charReader) { */ @Override public STToken nextToken() { - STToken token = switch (this.mode) { + STToken token = switch (Objects.requireNonNull(this.mode, "Lexer mode was null, an underflow occurred")) { case TEMPLATE -> readTemplateToken(); case REGEXP -> readRegExpTemplateToken(); case INTERPOLATION -> { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java index e1df73158faf..accb4d25527a 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java @@ -72,6 +72,7 @@ import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.tools.diagnostics.DiagnosticCode; import io.ballerina.tools.text.CharReader; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; @@ -19014,7 +19015,7 @@ private List getBindingPatternsList(List ambibuousList, boolean return bindingPatterns; } - @Nullable + @Contract("null, _ -> null; !null, _ -> !null") private STNode getBindingPattern(STNode ambiguousNode, boolean isListBP) { DiagnosticCode errorCode = DiagnosticErrorCode.ERROR_INVALID_BINDING_PATTERN; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParserErrorHandler.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParserErrorHandler.java index 338bba8c447b..9394b52682d6 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParserErrorHandler.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParserErrorHandler.java @@ -854,7 +854,7 @@ public class BallerinaParserErrorHandler extends AbstractParserErrorHandler { private static final ParserRuleContext[] OPTIONAL_TOP_LEVEL_SEMICOLON = { ParserRuleContext.TOP_LEVEL_NODE, ParserRuleContext.SEMICOLON }; - private static final ParserRuleContext[] TUPLE_MEMBER = + private static final ParserRuleContext[] TUPLE_MEMBER = { ParserRuleContext.ANNOTATIONS, ParserRuleContext.TYPE_DESC_IN_TUPLE }; public BallerinaParserErrorHandler(@Nullable AbstractTokenReader tokenReader) { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/DocumentationLexer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/DocumentationLexer.java index 739330972b23..609cade04e09 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/DocumentationLexer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/DocumentationLexer.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; /** * A LL(k) lexer for documentation in ballerina. @@ -63,7 +64,7 @@ public DocumentationLexer(CharReader charReader, */ @Override public STToken nextToken() { - STToken token = switch (this.mode) { + STToken token = switch (Objects.requireNonNull(this.mode, "Lexer mode was null, an underflow occurred")) { case DOC_LINE_START_HASH -> { processLeadingTrivia(); yield readDocLineStartHashToken(); diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/RegExpLexer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/RegExpLexer.java index b51cc5b3f5ab..e512f3c6866b 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/RegExpLexer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/RegExpLexer.java @@ -25,6 +25,7 @@ import io.ballerina.tools.text.CharReader; import java.util.ArrayList; +import java.util.Objects; /** * A LL(k) lexer for RegExp in ballerina. @@ -45,7 +46,7 @@ public RegExpLexer(CharReader charReader) { @Override public STToken nextToken() { STToken token; - switch (this.mode) { + switch (Objects.requireNonNull(this.mode, "Lexer mode was null, an underflow occurred")) { case RE_DISJUNCTION: case RE_CHAR_CLASS: token = readTokenInReDisjunction(); diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/Result.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/Result.java index 8d8c155019fd..6c4d045ec395 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/Result.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/Result.java @@ -17,9 +17,8 @@ */ package io.ballerina.compiler.internal.parser; -import org.jetbrains.annotations.Nullable; - import java.util.ArrayDeque; +import java.util.Optional; /** * Represent a result of a token-sequence-search in a sub-tree. The result will contain the fixes required to @@ -58,9 +57,8 @@ public Result(ArrayDeque fixes, int matches this.matches = matches; } - @Nullable - protected AbstractParserErrorHandler.Solution peekFix() { - return this.fixes.peek(); + protected Optional peekFix() { + return Optional.ofNullable(this.fixes.peek()); } protected AbstractParserErrorHandler.Solution popFix() { diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLLexer.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLLexer.java index cce1fffacf19..728dd5215b10 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLLexer.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLLexer.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * A LL(k) lexer for XML in ballerina. @@ -45,7 +46,7 @@ public XMLLexer(CharReader charReader) { */ @Override public STToken nextToken() { - STToken token = switch (this.mode) { + STToken token = switch (Objects.requireNonNull(this.mode, "Lexer mode was null, an underflow occurred")) { case XML_CONTENT -> readTokenInXMLContent(); case XML_ELEMENT_START_TAG -> { processLeadingXMLTrivia(); diff --git a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineMap.java b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineMap.java index ceb269a16462..63bb3d1ed8b2 100644 --- a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineMap.java +++ b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/LineMap.java @@ -45,6 +45,9 @@ TextLine textLine(int line) { LinePosition linePositionFrom(int position) { positionRangeCheck(position); TextLine textLine = findLineFrom(position); + if (textLine == null) { + throw new IllegalArgumentException("Cannot find a line with the character offset '" + position + "'"); + } return LinePosition.from(textLine.lineNo(), position - textLine.startOffset()); } @@ -98,7 +101,6 @@ private TextLine findLineFrom(int position) { return textLines[length - 1]; } - TextLine foundTextLine = null; int left = 0; int right = length - 1; while (left <= right) { @@ -109,14 +111,13 @@ private TextLine findLineFrom(int position) { int startOffset = textLines[middle].startOffset(); int endOffset = textLines[middle].endOffsetWithNewLines(); if (startOffset <= position && position < endOffset) { - foundTextLine = textLines[middle]; - break; + return textLines[middle]; } else if (endOffset <= position) { left = middle + 1; } else { right = middle - 1; } } - return foundTextLine; + return null; } } diff --git a/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/toml/common/completion/TomlCompletionUtil.java b/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/toml/common/completion/TomlCompletionUtil.java index 9ee4fd2e6a37..d19b8795105e 100644 --- a/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/toml/common/completion/TomlCompletionUtil.java +++ b/language-server/modules/langserver-commons/src/main/java/org/ballerinalang/langserver/commons/toml/common/completion/TomlCompletionUtil.java @@ -71,7 +71,8 @@ public static void fillNodeAtCursor(TomlCompletionContext context) { context.setCursorPositionInTree(txtPos); TextRange range = TextRange.from(txtPos, 0); NonTerminalNode nonTerminalNode = ((DocumentNode) st.get().rootNode()).findNode(range); - while (nonTerminalNode.parent() != null && !TomlSyntaxTreeUtil.withinTextRange(txtPos, nonTerminalNode)) { + while (nonTerminalNode != null && + nonTerminalNode.parent() != null && !TomlSyntaxTreeUtil.withinTextRange(txtPos, nonTerminalNode)) { //Takes the top-level Node of the immediate cursor position nonTerminalNode = nonTerminalNode.parent(); } diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java index 6054520d2c45..3fc63e9abbb4 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java @@ -44,7 +44,6 @@ import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -226,7 +225,6 @@ public String getName() { return NAME; } - @Nullable private Node getStatementNode(Node node) { Node statementNode = node; while (statementNode != null && !(statementNode instanceof StatementNode) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java index 2ab3a8f4babd..16a674e29ee4 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java @@ -202,6 +202,9 @@ public void visit(LetVariableDeclarationNode letVariableDeclarationNode) { @Override public void visit(StartActionNode startActionNode) { startActionNode.parent().accept(this); + if (returnTypeSymbol == null) { + throw new IllegalStateException("Return type symbol cannot be null"); + } if (resultFound && returnTypeSymbol.typeKind() == TypeDescKind.FUTURE) { FutureTypeSymbol futureTypeSymbol = (FutureTypeSymbol) returnTypeSymbol; TypeSymbol typeSymbol = futureTypeSymbol.typeParameter().orElse(null); @@ -268,6 +271,9 @@ public void visit(PositionalArgumentNode positionalArgumentNode) { if (!resultFound) { return; } + if (returnTypeSymbol == null) { + throw new IllegalStateException("Return type symbol cannot be null"); + } // This is the message parameter of an error constructor. if (returnTypeSymbol.typeKind() == TypeDescKind.ERROR) { @@ -326,6 +332,9 @@ public void visit(NamedArgumentNode namedArgumentNode) { if (!resultFound) { return; } + if (returnTypeSymbol == null) { + throw new IllegalStateException("Return type symbol cannot be null"); + } if (returnTypeSymbol.typeKind() == TypeDescKind.ERROR) { ErrorTypeSymbol errorTypeSymbol = (ErrorTypeSymbol) returnTypeSymbol; @@ -364,6 +373,10 @@ public void visit(NamedArgumentNode namedArgumentNode) { */ private Optional> getParameterSymbols() { FunctionTypeSymbol functionTypeSymbol; + if (returnTypeSymbol == null) { + throw new IllegalStateException("Return type symbol cannot be null"); + } + if (returnTypeSymbol.typeKind() == TypeDescKind.FUNCTION) { functionTypeSymbol = (FunctionTypeSymbol) returnTypeSymbol; } else if (returnTypeSymbol.kind() == SymbolKind.CLASS) { @@ -434,6 +447,9 @@ public void visit(ReturnStatementNode returnStatementNode) { resetResult(); return; } + if (returnTypeSymbol == null) { + throw new IllegalStateException("Return type symbol cannot be null"); + } if (returnTypeSymbol.typeKind() == TypeDescKind.FUNCTION) { FunctionTypeSymbol functionTypeSymbol = (FunctionTypeSymbol) returnTypeSymbol; functionTypeSymbol.returnTypeDescriptor().ifPresentOrElse(this::checkAndSetTypeResult, this::resetResult); @@ -512,6 +528,9 @@ public void visit(GroupingKeyVarDeclarationNode groupingKeyVarDeclarationNode) { @Override public void visit(SelectClauseNode selectClauseNode) { selectClauseNode.parent().parent().accept(this); + if (returnTypeSymbol == null) { + throw new IllegalStateException("Return type symbol cannot be null"); + } if (resultFound) { TypeDescKind kind = this.returnTypeSymbol.typeKind(); if (kind == TypeDescKind.ARRAY) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/module-info.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/module-info.java index b92017cb6eda..fa607cb80e57 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/module-info.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/module-info.java @@ -10,6 +10,7 @@ requires io.ballerina.identifier; requires org.apache.commons.lang3; requires static org.jetbrains.annotations; + requires com.google.errorprone.annotations; exports org.ballerinalang.debugadapter.launcher; } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/ExecutionContext.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/ExecutionContext.java index 4b934714c694..8ea32ee68af1 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/ExecutionContext.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/ExecutionContext.java @@ -20,7 +20,6 @@ import io.ballerina.projects.Project; import org.ballerinalang.debugadapter.jdi.VirtualMachineProxyImpl; import org.eclipse.lsp4j.debug.services.IDebugProtocolClient; -import org.jetbrains.annotations.Nullable; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -82,26 +81,23 @@ public void setDebuggeeVM(VirtualMachineProxyImpl debuggeeVM) { this.debuggeeVM = debuggeeVM; } - @Nullable public EventRequestManager getEventManager() { if (debuggeeVM == null) { - return null; + throw new IllegalStateException("Debuggee VM is not initialized."); } return debuggeeVM.eventRequestManager(); } - @Nullable public BufferedReader getInputStream() { if (launchedProcess == null) { - return null; + throw new IllegalStateException("Launched process is not initialized."); } return new BufferedReader(new InputStreamReader(launchedProcess.getInputStream(), StandardCharsets.UTF_8)); } - @Nullable public BufferedReader getErrorStream() { if (launchedProcess == null) { - return null; + throw new IllegalStateException("Launched process is not initialized."); } return new BufferedReader(new InputStreamReader(launchedProcess.getErrorStream(), StandardCharsets.UTF_8)); } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java index b9a531220fb6..f438a57e902c 100755 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java @@ -318,8 +318,11 @@ public CompletableFuture threads() { if (eventProcessor == null) { return CompletableFuture.completedFuture(threadsResponse); } - Map threadsMap = getActiveStrandThreads(); - if (threadsMap == null) { + Map threadsMap; + try { + threadsMap = getActiveStrandThreads(); + } catch (IllegalStateException e) { + LOGGER.error(e.getMessage()); return CompletableFuture.completedFuture(threadsResponse); } Thread[] threads = new Thread[threadsMap.size()]; @@ -348,7 +351,7 @@ public CompletableFuture pause(PauseArguments args) { public CompletableFuture stackTrace(StackTraceArguments args) { StackTraceResponse stackTraceResponse = new StackTraceResponse(); try { - activeThread = getAllThreads().get(args.getThreadId()); + ThreadReferenceProxyImpl activeThread = getAllThreads().get(args.getThreadId()); if (loadedThreadFrames.containsKey(activeThread.uniqueID())) { stackTraceResponse.setStackFrames(loadedThreadFrames.get(activeThread.uniqueID())); } else { @@ -359,6 +362,7 @@ public CompletableFuture stackTrace(StackTraceArguments args stackTraceResponse.setStackFrames(validFrames); loadedThreadFrames.put(activeThread.uniqueID(), validFrames); } + this.activeThread = activeThread; return CompletableFuture.completedFuture(stackTraceResponse); } catch (Exception e) { LOGGER.error(e.getMessage(), e); @@ -806,7 +810,7 @@ private Variable[] computeGlobalVariables(SuspendedContext context, int stackFra } private Variable[] computeStackFrameVariables(VariablesArguments args) throws Exception { - StackFrameProxyImpl stackFrame = suspendedContext.getFrame(); + StackFrameProxyImpl stackFrame = Objects.requireNonNull(suspendedContext).getFrame(); List variables = new ArrayList<>(); List localVariableProxies = stackFrame.visibleVariables(); for (LocalVariableProxyImpl var : localVariableProxies) { @@ -952,9 +956,9 @@ private Variable[] createVariableArrayFrom(VariablesArguments args, List * Thread objects that have not yet been started (see {@link java.lang.Thread#start Thread.start()}) * and thread objects that have completed their execution are not included in the returned list. */ - @Nullable Map getAllThreads() { + Map getAllThreads() { if (context.getDebuggeeVM() == null) { - return null; + throw new IllegalStateException("Debuggee VM is not available"); } Collection threadReferences = context.getDebuggeeVM().getVirtualMachine().allThreads(); Map threadsMap = new HashMap<>(); @@ -971,11 +975,8 @@ private Variable[] createVariableArrayFrom(VariablesArguments args, List /** * Returns a map of thread instances which correspond to an active ballerina strand, against their unique ID. */ - @Nullable Map getActiveStrandThreads() { + Map getActiveStrandThreads() { Map allThreads = getAllThreads(); - if (allThreads == null) { - return null; - } Map balStrandThreads = new HashMap<>(); // Filter thread references which are suspended, whose thread status is running, and which represents an active diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluatorBuilder.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluatorBuilder.java index f15db5db6783..fec4fc513127 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluatorBuilder.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/EvaluatorBuilder.java @@ -181,7 +181,7 @@ public Evaluator build(ExpressionNode parsedExpr) throws EvaluationException { unsupportedNodes.forEach(node -> errors.add(String.format("'%s' - %s", node.toString(), node.kind()))); throw createEvaluationException(UNSUPPORTED_EXPRESSION, errors); } - if (result == null) { + if (result == null && builderException != null) { throw builderException; } return result; diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/InvocationArgProcessor.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/InvocationArgProcessor.java index 914b31ae6329..471c5e6c9d71 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/InvocationArgProcessor.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/engine/InvocationArgProcessor.java @@ -147,8 +147,7 @@ protected static Value getRestArgArray(SuspendedContext context, Value arrayType return getRestArgArray.invokeSafely(); } - protected static Value getElementType(SuspendedContext context, @Nullable Value arrayType - ) throws EvaluationException { + protected static Value getElementType(SuspendedContext context, Value arrayType) throws EvaluationException { ReferenceType arrayTypeRef = ((ObjectReference) arrayType).referenceType(); List methods = arrayTypeRef.methodsByName(GET_ELEMENT_TYPE_METHOD); if (methods == null || methods.size() != 1) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/validator/SerialExpressionValidator.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/validator/SerialExpressionValidator.java index 3d85d891c0b7..08be6de83aff 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/validator/SerialExpressionValidator.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/validator/SerialExpressionValidator.java @@ -26,7 +26,6 @@ import org.ballerinalang.debugadapter.evaluation.validator.impl.InvalidInputValidator; import org.ballerinalang.debugadapter.evaluation.validator.impl.StatementValidator; import org.ballerinalang.debugadapter.evaluation.validator.impl.TopLevelDeclarationValidator; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -44,15 +43,15 @@ */ public class SerialExpressionValidator extends Validator { - @Nullable - private ExpressionValidator expressionValidator; - @Nullable - private List otherValidators; + private final ExpressionValidator expressionValidator = new ExpressionValidator(new ExpressionParser()); + private final List otherValidators = new ArrayList<>(); public SerialExpressionValidator() { super(new DebugParser()); - this.expressionValidator = null; - this.otherValidators = null; + // Validation order is important and should be preserved, to reduce the number of parser trials. + otherValidators.add(new InvalidInputValidator(debugParser)); + otherValidators.add(new TopLevelDeclarationValidator(debugParser)); + otherValidators.add(new StatementValidator()); } /** @@ -72,7 +71,6 @@ public ExpressionNode validateAndParse(String source) throws Exception { @Override public void validate(String source) throws Exception { - loadValidators(); try { expressionValidator.validate(source); } catch (DebugParserException | ValidatorException e) { @@ -106,16 +104,4 @@ private void fallBackOnOtherValidators(String source) throws EvaluationException } } } - - /** - * Loads all validator types, which are required to process the user input. - * Note: validation order is important and should be preserved, to reduce the number of parser trials. - */ - private void loadValidators() { - expressionValidator = new ExpressionValidator(new ExpressionParser()); - otherValidators = new ArrayList<>(); - otherValidators.add(new InvalidInputValidator(debugParser)); - otherValidators.add(new TopLevelDeclarationValidator(debugParser)); - otherValidators.add(new StatementValidator()); - } } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BCompoundVariable.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BCompoundVariable.java index e43fb97bef0a..75812e8af715 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BCompoundVariable.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/BCompoundVariable.java @@ -33,7 +33,7 @@ public abstract class BCompoundVariable implements BVariable { protected final BVariableType type; protected Value jvmValue; @Nullable - protected Variable dapVariable; + protected Variable dapVariable = null; public BCompoundVariable(SuspendedContext context, String varName, BVariableType bVariableType, Value jvmValue) { this.context = context; @@ -41,7 +41,6 @@ public BCompoundVariable(SuspendedContext context, String varName, BVariableType this.name = decodeIdentifier(varName); this.type = bVariableType; this.jvmValue = jvmValue; - this.dapVariable = null; } /** diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/IndexedCompoundVariable.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/IndexedCompoundVariable.java index 42a3f0ea7b71..1aece2c5ee4d 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/IndexedCompoundVariable.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/IndexedCompoundVariable.java @@ -102,11 +102,12 @@ public Value getChildByName(String key) throws DebugVariableException { @Override public Variable getDapVariable() { if (dapVariable == null) { - dapVariable = new Variable(); + Variable dapVariable = new Variable(); dapVariable.setName(this.name); dapVariable.setType(this.type.getString()); dapVariable.setValue(computeValue()); dapVariable.setIndexedVariables(getChildrenCount()); + this.dapVariable = dapVariable; } return dapVariable; } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/NamedCompoundVariable.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/NamedCompoundVariable.java index eb8d74ca1a8b..15434067ee0e 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/NamedCompoundVariable.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/NamedCompoundVariable.java @@ -73,11 +73,12 @@ public Value getChildByName(String name) throws DebugVariableException { @Override public Variable getDapVariable() { if (dapVariable == null) { - dapVariable = new Variable(); + Variable dapVariable = new Variable(); dapVariable.setName(this.name); dapVariable.setType(this.type.getString()); dapVariable.setValue(computeValue()); dapVariable.setNamedVariables(getChildrenCount()); + this.dapVariable = dapVariable; } return dapVariable; } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableUtils.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableUtils.java index 88ae099a5675..e7240fe1b3a1 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableUtils.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/VariableUtils.java @@ -24,6 +24,7 @@ import org.ballerinalang.debugadapter.SuspendedContext; import org.ballerinalang.debugadapter.evaluation.EvaluationException; import org.ballerinalang.debugadapter.jdi.LocalVariableProxyImpl; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import java.util.AbstractMap; @@ -324,7 +325,7 @@ private static boolean isIntersectionType(Value runtimeType) { * @param typeValue JDI value instance. * @return referred type value. */ - @Nullable + @Contract("null -> null") private static Value getReferredTypeFromTypeRefType(Value typeValue) throws DebugVariableException { while (typeValue != null && isTypeReferenceType(typeValue)) { typeValue = getFieldValue(typeValue, FIELD_REFERRED_TYPE).orElse(null); @@ -339,7 +340,7 @@ private static Value getReferredTypeFromTypeRefType(Value typeValue) throws Debu * @param typeValue JDI value instance. * @return effective type value. */ - @Nullable + @Contract("null -> null") private static Value getEffectiveTypeFromIntersectionType(Value typeValue) throws DebugVariableException { while (typeValue != null && isIntersectionType(typeValue)) { typeValue = getFieldValue(typeValue, FIELD_EFFECTIVE_TYPE).orElse(null); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BMap.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BMap.java index dcfff25afbb5..4125c5adeec9 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BMap.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BMap.java @@ -101,8 +101,11 @@ private Map getEntries(int startIndex, int count) { if (loadedKeys == null) { loadAllKeys(); } - Map entries = new LinkedHashMap<>(); + if (loadedKeys == null) { + return Collections.emptyMap(); + } List keysRange = loadedKeys.getValues(startIndex, count); + Map entries = new LinkedHashMap<>(); for (int i = startIndex; i < startIndex + count; i++) { Value key = keysRange.get(i - startIndex); if (loadedValues[i] == null) { diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java index b8fd4dfa2c61..6f2ff4381f2a 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/types/BRecord.java @@ -70,6 +70,9 @@ public Map computeChildVariables() { Map childVarMap = new LinkedHashMap<>(); Map recordFields = getRecordFields(); + if (recordFields == null) { + return childVarMap; + } for (Map.Entry mapEntry : recordFields.entrySet()) { childVarMap.put(Utils.encodeNonFunctionIdentifier( @@ -87,6 +90,9 @@ private Map getRecordFields() { try { loadAllKeys(); Map recordFields = new LinkedHashMap<>(); + if (loadedKeys == null) { + return null; + } List keysRange = loadedKeys.getValues(0, loadedKeys.length()); for (int i = 0; i < loadedKeys.length(); i++) { diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java index baeeb2bf1d10..cb4427a669f5 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java @@ -93,6 +93,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.StringJoiner; import java.util.stream.Stream; @@ -205,9 +206,9 @@ public static void addTypeDefinition(TypeDescriptorNode typeDescriptorNode, Stri case UNION_TYPE_DESC: Type unionType = Type.fromNode(typeDescriptorNode, semanticModel, module); if (unionType.memberTypes.stream().allMatch(type -> - (type.category != null && type.category.equals("errors")) || - (type.category != null && type.category.equals("builtin")) && - type.name.equals("error"))) { + Objects.equals(type.category, "errors") || + Objects.equals(type.category, "builtin") && + Objects.equals(type.name, "error"))) { module.errors.add(new Error(typeName, getDocFromMetadata(metaDataNode), getDescSectionsDocFromMetaDataList(metaDataNode), isDeprecated(metaDataNode), Type.fromNode(typeDescriptorNode, semanticModel, module))); diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Type.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Type.java index 209545ab3149..30d28d8f95d7 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Type.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Type.java @@ -24,6 +24,7 @@ import io.ballerina.compiler.api.symbols.Documentation; import io.ballerina.compiler.api.symbols.IntersectionTypeSymbol; import io.ballerina.compiler.api.symbols.MapTypeSymbol; +import io.ballerina.compiler.api.symbols.ModuleSymbol; import io.ballerina.compiler.api.symbols.ObjectTypeSymbol; import io.ballerina.compiler.api.symbols.ParameterSymbol; import io.ballerina.compiler.api.symbols.Qualifiable; @@ -252,8 +253,7 @@ public static Type fromNode(Node node, SemanticModel semanticModel, Module modul CATEGORY_INLINE_CLOSED_RECORD : CATEGORY_INLINE_RECORD; type.memberTypes = fields; } else if (node instanceof StreamTypeDescriptorNode streamNode) { - StreamTypeParamsNode streamParams = streamNode.streamTypeParamsNode().isPresent() ? - (StreamTypeParamsNode) streamNode.streamTypeParamsNode().get() : null; + StreamTypeParamsNode streamParams = (StreamTypeParamsNode) streamNode.streamTypeParamsNode().orElse(null); type.name = streamNode.streamKeywordToken().text(); type.category = "stream"; if (streamParams != null) { @@ -358,16 +358,15 @@ public static Type fromSemanticSymbol( resolveSymbolMetaData(type, symbol, module); type.isPublic = true; } - type.name = typeReferenceTypeSymbol.getName().isPresent() ? typeReferenceTypeSymbol.getName().get() : null; + type.name = typeReferenceTypeSymbol.getName().orElse(null); } else if (symbol instanceof RecordTypeSymbol recordTypeSymbol) { Type recordType = type; - recordType.name = recordTypeSymbol.getName().isPresent() ? recordTypeSymbol.getName().get() : ""; - recordType.description = documentation.isPresent() && documentation.get().description().isPresent() ? - documentation.get().description().get() : ""; + recordType.name = recordTypeSymbol.getName().orElse(""); + recordType.description = documentation.flatMap(Documentation::description).orElse(""); recordTypeSymbol.fieldDescriptors().forEach((name, field) -> { Type recField = new Type(); recField.name = name; - recField.description = documentation.isPresent() ? documentation.get().parameterMap().get(name) : ""; + recField.description = documentation.map(doc -> doc.parameterMap().get(name)).orElse(""); recField.elementType = fromSemanticSymbol(field.typeDescriptor(), documentation, parentTypeRefSymbol, isTypeInclusion, module); recordType.memberTypes.add(recField); @@ -385,13 +384,12 @@ public static Type fromSemanticSymbol( recordType.category = CATEGORY_INLINE_RECORD; } else if (symbol instanceof ObjectTypeSymbol objectTypeSymbol) { ObjectType objType = new ObjectType(); - objType.name = objectTypeSymbol.getName().isPresent() ? objectTypeSymbol.getName().get() : ""; + objType.name = objectTypeSymbol.getName().orElse(""); objectTypeSymbol.fieldDescriptors().forEach((name, field) -> { if (field.qualifiers().contains(Qualifier.PUBLIC)) { Type objField = new Type(); objField.name = name; - objField.description = documentation.isPresent() ? - documentation.get().parameterMap().get(name) : ""; + objField.description = documentation.map(doc -> doc.parameterMap().get(name)).orElse(""); objField.elementType = fromSemanticSymbol(field.typeDescriptor(), documentation, parentTypeRefSymbol, isTypeInclusion, module); objType.memberTypes.add(objField); @@ -408,9 +406,8 @@ public static Type fromSemanticSymbol( functionType.name = methodName; functionType.accessor = ""; } - functionType.description = methodSymbol.documentation().isPresent() && - methodSymbol.documentation().get().description().isPresent() ? - methodSymbol.documentation().get().description().get() : null; + functionType.description = methodSymbol.documentation() + .flatMap(Documentation::description).orElse(null); functionType.category = "included_function"; functionType.isIsolated = methodSymbol.qualifiers().contains(Qualifier.ISOLATED); FunctionKind functionKind; @@ -427,7 +424,7 @@ public static Type fromSemanticSymbol( methodSymbol.typeDescriptor().params().ifPresent(parameterSymbols -> { parameterSymbols.forEach(parameterSymbol -> { Type paramType = new Type(); - paramType.name = parameterSymbol.getName().isPresent() ? parameterSymbol.getName().get() : ""; + paramType.name = parameterSymbol.getName().orElse(""); paramType.elementType = fromSemanticSymbol(parameterSymbol.typeDescriptor(), methodSymbol.documentation(), parentTypeRefSymbol, isTypeInclusion, module); paramType.isDeprecated = parameterSymbol.annotations().stream() @@ -501,7 +498,7 @@ public static void addIntersectionMemberTypes(Node node, SemanticModel semanticM } public static void resolveSymbolMetaData(Type type, Symbol symbol, Module module) { - ModuleID moduleID = symbol.getModule().isPresent() ? symbol.getModule().get().id() : null; + ModuleID moduleID = symbol.getModule().map(ModuleSymbol::id).orElse(null); if (moduleID != null) { type.moduleName = moduleID.moduleName(); diff --git a/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java b/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java index c0fe2f4381e9..db701c683109 100644 --- a/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java +++ b/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java @@ -19,6 +19,7 @@ package io.ballerina.identifier; import org.apache.commons.text.StringEscapeUtils; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import java.util.regex.Matcher; @@ -140,8 +141,8 @@ private static String getFormattedStringForJvmReservedSet(char c) { * @param encodedIdentifier encoded identifier string * @return decoded identifier */ - @Nullable - public static String decodeIdentifier(@Nullable String encodedIdentifier) { + @Contract("null -> null; !null -> !null") + public static String decodeIdentifier(String encodedIdentifier) { if (encodedIdentifier == null) { return null; } diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java index 6ed62012f2d8..5829f91d5bb3 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java @@ -23,7 +23,6 @@ import org.wso2.ballerinalang.compiler.packaging.repo.Repo; import java.nio.file.Path; -import java.util.Objects; /** * This represents the standard Ballerina built-in system package repository provider. @@ -35,7 +34,7 @@ public class TesterinaSystemPackageRepositoryProvider implements SystemPackageRe @Override public Repo loadRepository() { - return new JarRepo(Objects.requireNonNull(SystemPackageRepositoryProvider.getClassUri(this))); + return new JarRepo(SystemPackageRepositoryProvider.getClassUri(this)); } } diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java index 0212003dc5df..0a5cd7ef1524 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/AbstractLexer.java @@ -28,6 +28,7 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; +import java.util.Deque; import java.util.List; /** @@ -43,7 +44,7 @@ public abstract class AbstractLexer { protected CharReader reader; @Nullable protected ParserMode mode; - protected ArrayDeque modeStack = new ArrayDeque<>(); + protected Deque modeStack = new ArrayDeque<>(); public AbstractLexer(CharReader charReader, ParserMode initialParserMode) { this(charReader, initialParserMode, new ArrayList<>(INITIAL_TRIVIA_CAPACITY), new ArrayList<>()); diff --git a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlLexer.java b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlLexer.java index 4c60c6a76340..a7b0611b00c8 100644 --- a/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlLexer.java +++ b/misc/toml-parser/src/main/java/io/ballerina/toml/internal/parser/TomlLexer.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * A LL(k) lexer for TOML. @@ -48,7 +49,7 @@ public TomlLexer(CharReader charReader) { @Override public STToken nextToken() { STToken token; - switch (this.mode) { + switch (Objects.requireNonNull(this.mode, "Lexer mode was null, an underflow occurred")) { case STRING: token = readStringToken(); break; diff --git a/project-api/project-api-test/src/test/java/io/ballerina/projects/test/HierarchicalPackageNameTests.java b/project-api/project-api-test/src/test/java/io/ballerina/projects/test/HierarchicalPackageNameTests.java index 059ffbd8a27b..a4bb23337732 100644 --- a/project-api/project-api-test/src/test/java/io/ballerina/projects/test/HierarchicalPackageNameTests.java +++ b/project-api/project-api-test/src/test/java/io/ballerina/projects/test/HierarchicalPackageNameTests.java @@ -133,11 +133,11 @@ public void testResolveHierarchicalPackageInDist() { if (importModuleResponse.resolutionStatus().equals(ResolutionResponse.ResolutionStatus.UNRESOLVED)) { Assert.assertEquals(importModuleResponse.importModuleRequest(), request4); } else if (importModuleResponse.importModuleRequest().moduleName().equals("a.c")) { - Assert.assertEquals(importModuleResponse.packageDescriptor().name().toString(), "a"); + Assert.assertEquals(importModuleResponse.packageDescriptor().orElseThrow().name().toString(), "a"); } else if (importModuleResponse.importModuleRequest().moduleName().equals("a.b.c")) { - Assert.assertEquals(importModuleResponse.packageDescriptor().name().toString(), "a.b"); + Assert.assertEquals(importModuleResponse.packageDescriptor().orElseThrow().name().toString(), "a.b"); } else { - Assert.assertEquals(importModuleResponse.packageDescriptor().name().toString(), "a.b"); + Assert.assertEquals(importModuleResponse.packageDescriptor().orElseThrow().name().toString(), "a.b"); } } } @@ -167,9 +167,9 @@ public void testResolveDifferentPackagesFromEachRepo() { Assert.assertEquals(importModuleResponseList.size(), 2); for (ImportModuleResponse importModuleResponse : importModuleResponseList) { if (importModuleResponse.importModuleRequest().moduleName().equals("a.c")) { - Assert.assertEquals(importModuleResponse.packageDescriptor().name().toString(), "a.c"); + Assert.assertEquals(importModuleResponse.packageDescriptor().orElseThrow().name().toString(), "a.c"); } else { - Assert.assertEquals(importModuleResponse.packageDescriptor().name().toString(), "a.b"); + Assert.assertEquals(importModuleResponse.packageDescriptor().orElseThrow().name().toString(), "a.b"); } } diff --git a/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/io/samjs/plugins/badsad/BadSadCompilerPlugin20.java b/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/io/samjs/plugins/badsad/BadSadCompilerPlugin20.java index 0ba605ea30cb..f2f816687755 100644 --- a/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/io/samjs/plugins/badsad/BadSadCompilerPlugin20.java +++ b/project-api/test-artifacts/bad-sad-compiler-plugin/src/main/java/io/samjs/plugins/badsad/BadSadCompilerPlugin20.java @@ -19,7 +19,6 @@ import io.ballerina.projects.plugins.CompilerPlugin; import io.ballerina.projects.plugins.CompilerPluginContext; -import org.jetbrains.annotations.Nullable; import java.io.PrintStream; @@ -36,7 +35,7 @@ public void init(CompilerPluginContext pluginContext) { out.println(getStr().toCharArray()); } - @Nullable String getStr() { + String getStr() { return null; } } diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java index cff83bd96e8f..cc60d3e55734 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java @@ -65,6 +65,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Timer; @@ -169,7 +170,8 @@ public boolean initDebugSession(DebugUtils.DebuggeeExecutionKind executionKind, launchConfigs.put("terminal", terminalKind); } initDebugSession(executionKind, launchConfigs); - return debugClientConnector.getRequestManager().getDidRunInIntegratedTerminal(); + + return Objects.requireNonNull(debugClientConnector).getRequestManager().getDidRunInIntegratedTerminal(); } /** @@ -211,8 +213,9 @@ public void initDebugSession(DebugUtils.DebuggeeExecutionKind executionKind, Map public void initDebugSession(DebugUtils.DebuggeeExecutionKind executionKind, int port, Map launchArgs) throws BallerinaTestException { - debugClientConnector = new DAPClientConnector(balServer.getServerHome(), testProjectPath, testEntryFilePath, - port, clientSupportsRunInTerminal); + DAPClientConnector debugClientConnector = + new DAPClientConnector(balServer.getServerHome(), testProjectPath, testEntryFilePath, port, + clientSupportsRunInTerminal); debugClientConnector.createConnection(); if (debugClientConnector.isConnected()) { isConnected = true; @@ -230,6 +233,7 @@ public void initDebugSession(DebugUtils.DebuggeeExecutionKind executionKind, debugClientConnector.getRequestManager().setIsProjectBasedTest(isProjectBasedTest); launchDebuggee(executionKind, launchArgs); } + this.debugClientConnector = debugClientConnector; } private void attachToDebuggee() throws BallerinaTestException { From 06d63f955ee9ab9873bdc975ec4b401e58a234a6 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Tue, 5 Nov 2024 16:46:59 +0100 Subject: [PATCH 03/12] Fix checkstyle errors --- .../src/main/java/org/ballerinalang/toml/model/Dependency.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Dependency.java b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Dependency.java index 70e8854ab81c..9d7af60c7518 100644 --- a/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Dependency.java +++ b/compiler/ballerina-lang/src/main/java/org/ballerinalang/toml/model/Dependency.java @@ -25,6 +25,8 @@ /** * Dependency definition in Ballerina.toml manifest file. + * @param moduleID module id of the dependency + * @param metadata metadata of the dependency */ public record Dependency(String moduleID, DependencyMetadata metadata) { From df558e5dc58619bd7feac0d4db9f2989d6ebf60f Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Tue, 5 Nov 2024 17:44:09 +0100 Subject: [PATCH 04/12] Fixup --- .../java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java index f1162595088b..b021abc11b04 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java @@ -66,7 +66,7 @@ private static String otherPlatformGraalvmCompatibleVerified(String target, private static Boolean isAllPlatformDepsGraalvmCompatible(Map platforms) { Boolean isAllDepsGraalvmCompatible = true; for (PackageManifest.Platform platform: platforms.values()) { - Boolean graalvmCompatible = platform.graalvmCompatible(); + Boolean graalvmCompatible = platform.isPlatfromDepsGraalvmCompatible(); if (graalvmCompatible == null) { isAllDepsGraalvmCompatible = null; } else if (!graalvmCompatible) { From c5bb91ba421d1d16a3f5cd08d65a864837d7b751 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Tue, 5 Nov 2024 17:48:19 +0100 Subject: [PATCH 05/12] Fixup --- .../java/io/ballerina/compiler/api/impl/ReferenceFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java index 6daa1c7f8e64..fbda1c56ca9b 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java @@ -276,7 +276,7 @@ public void visit(BLangPackage pkgNode) { .toList()); if (!(pkgNode instanceof BLangTestablePackage)) { - find(pkgNode.getTestablePkg().orElseThrow()); + find(pkgNode.getTestablePkg().orElse(null)); } } From 871d3297c997221871e3f27b5b9f2bb9454e3245 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Tue, 5 Nov 2024 18:03:08 +0100 Subject: [PATCH 06/12] Replace duplicate `hasTestablePackage` with `containsTestablePkg` --- .../java/io/ballerina/compiler/api/impl/ReferenceFinder.java | 4 ++-- .../main/java/io/ballerina/projects/JBallerinaBackend.java | 2 +- .../main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java | 2 +- .../compiler/bir/codegen/interop/InteropValidator.java | 2 +- .../org/wso2/ballerinalang/compiler/tree/BLangPackage.java | 4 ---- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java index fbda1c56ca9b..b7fdcac02088 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ReferenceFinder.java @@ -275,8 +275,8 @@ public void visit(BLangPackage pkgNode) { .filter(f -> !f.flagSet.contains(Flag.LAMBDA)) .toList()); - if (!(pkgNode instanceof BLangTestablePackage)) { - find(pkgNode.getTestablePkg().orElse(null)); + if (!(pkgNode instanceof BLangTestablePackage) && pkgNode.containsTestablePkg()) { + find(pkgNode.getTestablePkg().orElseThrow()); } } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java index cf08dce1023d..a8683d51de56 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java @@ -391,7 +391,7 @@ public void performCodeGen(ModuleContext moduleContext, CompilationCache compila return; } - if (!bLangPackage.hasTestablePackage()) { + if (!bLangPackage.containsTestablePkg()) { return; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java index 112146e0341d..db9332b0162f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java @@ -292,7 +292,7 @@ public BLangPackage genBIR(BLangPackage astPkg) { astPkg.accept(this); this.birOptimizer.optimizePackage(birPkg); - if (!astPkg.moduleContextDataHolder.skipTests() && astPkg.hasTestablePackage()) { + if (!astPkg.moduleContextDataHolder.skipTests() && astPkg.containsTestablePkg()) { astPkg.getTestablePkgs().forEach(testPkg -> { BIRPackage testBirPkg = new BIRPackage(testPkg.pos, testPkg.packageID.orgName, testPkg.packageID.pkgName, testPkg.packageID.name, testPkg.packageID.version, diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/InteropValidator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/InteropValidator.java index ccee37a09242..53a380c68a3b 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/InteropValidator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/InteropValidator.java @@ -105,7 +105,7 @@ private void validateModulePackages(ModuleId moduleId, CompilerBackend compilerB private void validateTestPackages(ModuleId moduleId, CompilerBackend compilerBackend, BLangPackage bLangPackage) { - if (bLangPackage.moduleContextDataHolder.skipTests() || !bLangPackage.hasTestablePackage()) { + if (bLangPackage.moduleContextDataHolder.skipTests() || !bLangPackage.containsTestablePkg()) { return; } Set testDependencies = getPlatformDependencyPaths(moduleId, compilerBackend, diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java index 9f5932b6bcc9..21092b09d135 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangPackage.java @@ -274,10 +274,6 @@ public Set getFlags() { return flagSet; } - public boolean hasTestablePackage() { - return !this.testablePkgs.isEmpty(); - } - public void addClassDefinition(BLangClassDefinition classDefNode) { this.topLevelNodes.add(classDefNode); this.classDefinitions.add(classDefNode); From d89bfd86b5a7e9919a333ecce2ac0f109ca07310 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Tue, 5 Nov 2024 18:55:55 +0100 Subject: [PATCH 07/12] Fixup testcase --- .../java/org/ballerinalang/toml/ManifestProcessorTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java b/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java index bef462053cc3..ad2ea230f3f5 100644 --- a/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java +++ b/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java @@ -200,7 +200,8 @@ public void testMultipleDependencies() throws TomlException, IOException { Assert.assertEquals(manifest.getDependencies().get(0).metadata().getVersion(), "1.0.5"); Assert.assertEquals(manifest.getDependencies().get(1).moduleID(), "jquery"); Assert.assertEquals(manifest.getDependencies().get(1).metadata().getVersion(), "2.2.3"); - Assert.assertEquals(manifest.getDependencies().get(0).metadata().getPath().toString(), balaPath.toString()); + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getPath().orElseThrow().toString(), + balaPath.toString()); Files.delete(balaPath); Files.delete(tmpDir); @@ -220,7 +221,7 @@ public void testDependencyWithWindowsAbsolutePath() throws TomlException, IOExce Assert.assertEquals(manifest.getDependencies().get(0).metadata().getVersion(), "1.0.5"); Assert.assertEquals(manifest.getDependencies().get(1).moduleID(), "jquery"); Assert.assertEquals(manifest.getDependencies().get(1).metadata().getVersion(), "2.2.3"); - Assert.assertEquals(manifest.getDependencies().get(0).metadata().getPath().toString(), + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getPath().orElseThrow().toString(), balaPath.toString()); Files.delete(balaPath); From 18c1bdc44595304f2ddac39ba8c3a1835fce6c3b Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Tue, 5 Nov 2024 19:44:48 +0100 Subject: [PATCH 08/12] Fixup testcase --- .../java/org/ballerinalang/toml/ManifestProcessorTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java b/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java index ad2ea230f3f5..64a8225bfb07 100644 --- a/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java +++ b/compiler/ballerina-lang/src/test/java/org/ballerinalang/toml/ManifestProcessorTest.java @@ -146,7 +146,8 @@ public void testSingleDependencies() throws TomlException, IOException { "string-utils = {path = '" + balaPath + "', version = \"1.1.5\"} \n"); Assert.assertEquals(manifest.getDependencies().get(0).moduleID(), "string-utils"); Assert.assertEquals(manifest.getDependencies().get(0).metadata().getVersion(), "1.1.5"); - Assert.assertEquals(manifest.getDependencies().get(0).metadata().getPath().toString(), balaPath.toString()); + Assert.assertEquals(manifest.getDependencies().get(0).metadata().getPath().orElseThrow().toString(), + balaPath.toString()); Files.delete(balaPath); Files.delete(tmpDir); From 7981b28bc329a5b23abfac5095e5ea4481cc1943 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Tue, 5 Nov 2024 22:33:16 +0100 Subject: [PATCH 09/12] Fixup testcase --- .../org/ballerinalang/debugger/test/utils/DebugTestRunner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java index cc60d3e55734..f32313fdccea 100644 --- a/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java +++ b/tests/jballerina-debugger-integration-test/src/main/java/org/ballerinalang/debugger/test/utils/DebugTestRunner.java @@ -216,6 +216,7 @@ public void initDebugSession(DebugUtils.DebuggeeExecutionKind executionKind, DAPClientConnector debugClientConnector = new DAPClientConnector(balServer.getServerHome(), testProjectPath, testEntryFilePath, port, clientSupportsRunInTerminal); + this.debugClientConnector = debugClientConnector; debugClientConnector.createConnection(); if (debugClientConnector.isConnected()) { isConnected = true; @@ -233,7 +234,6 @@ public void initDebugSession(DebugUtils.DebuggeeExecutionKind executionKind, debugClientConnector.getRequestManager().setIsProjectBasedTest(isProjectBasedTest); launchDebuggee(executionKind, launchArgs); } - this.debugClientConnector = debugClientConnector; } private void attachToDebuggee() throws BallerinaTestException { From 2d25720258575c7590e76e00bf16209eac32255e Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Fri, 22 Nov 2024 10:14:07 +0100 Subject: [PATCH 10/12] Fix compilation error --- .../io/ballerina/runtime/internal/values/TupleValueImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java index 16ce284363e9..6b523aed5db8 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java @@ -37,6 +37,7 @@ import io.ballerina.runtime.internal.errors.ErrorReasons; import io.ballerina.runtime.internal.utils.CycleUtils; import io.ballerina.runtime.internal.utils.ValueConverter; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.OutputStream; From 0cf1f3c8dcec74963fbca677c2479c98d70d2c23 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Fri, 22 Nov 2024 10:21:45 +0100 Subject: [PATCH 11/12] Fix checkstyle --- .../ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java | 1 - .../compiler/bir/codegen/methodgen/MethodGenUtils.java | 1 - 2 files changed, 2 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java index 2988a368e22d..29fec8b62e5a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGen.java @@ -107,7 +107,6 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.NO_OF_DEPENDANT_MODULES; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.OBJECT_SELF_INSTANCE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.PARENT_MODULE_START_ATTEMPTED; -import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.PARENT_MODULE_START_ATTEMPTED; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.RECEIVE_WORKER_CHANNEL_NAMES_VAR_NAME; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.SEND_WORKER_CHANNEL_NAMES_VAR_NAME; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRAND; diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGenUtils.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGenUtils.java index b790aac42d2f..3ef23e1845ab 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGenUtils.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MethodGenUtils.java @@ -20,7 +20,6 @@ import io.ballerina.identifier.Utils; import org.ballerinalang.model.elements.PackageID; -import org.jetbrains.annotations.Nullable; import org.objectweb.asm.MethodVisitor; import org.wso2.ballerinalang.compiler.bir.codegen.JvmCodeGenUtil; import org.wso2.ballerinalang.compiler.bir.model.BIRNode; From eca0cf6ba05ad411a17e9a162cbcdd1b34d645f9 Mon Sep 17 00:00:00 2001 From: Felix Schnabel Date: Mon, 25 Nov 2024 18:52:28 +0100 Subject: [PATCH 12/12] Fix Checkstyle --- .../io/ballerina/runtime/api/concurrent/StrandMetadata.java | 2 -- .../main/java/io/ballerina/runtime/internal/BalRuntime.java | 1 - .../io/ballerina/runtime/internal/scheduling/AsyncUtils.java | 2 -- .../java/io/ballerina/runtime/internal/scheduling/Strand.java | 1 - .../io/ballerina/runtime/internal/values/ValueCreator.java | 3 ++- 5 files changed, 2 insertions(+), 7 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/concurrent/StrandMetadata.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/concurrent/StrandMetadata.java index c06da73a7ee5..46490a1f3774 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/concurrent/StrandMetadata.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/concurrent/StrandMetadata.java @@ -19,8 +19,6 @@ import java.util.Map; -import org.jetbrains.annotations.Nullable; - /** * Holds metadata of a Ballerina strand. * diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java index e79b683f11b3..17f3cdb14cc8 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BalRuntime.java @@ -34,7 +34,6 @@ import io.ballerina.runtime.internal.scheduling.RuntimeRegistry; import io.ballerina.runtime.internal.scheduling.Scheduler; import io.ballerina.runtime.internal.values.FutureValue; -import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java index f4642d2beade..cc4ab7517707 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/AsyncUtils.java @@ -25,8 +25,6 @@ import io.ballerina.runtime.internal.utils.ErrorUtils; import io.ballerina.runtime.internal.values.FutureValue; import io.ballerina.runtime.internal.values.MapValue; -import io.ballerina.runtime.internal.values.ValueCreator; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java index f5dc64901347..214bd2d5a852 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java @@ -20,7 +20,6 @@ import io.ballerina.runtime.internal.utils.ErrorUtils; import io.ballerina.runtime.transactions.TransactionLocalContext; -import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java index 07385e3c54bd..c9d0bc17cd87 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ValueCreator.java @@ -119,7 +119,8 @@ public static boolean containsValueCreator(String key) { public abstract MapValue createRecordValue(String recordTypeName) throws BError; - public abstract BObject createObjectValue(String objectTypeName, @Nullable Strand parent, Object[] args) throws BError; + public abstract BObject createObjectValue(String objectTypeName, @Nullable Strand parent, Object[] args) + throws BError; public abstract BError createErrorValue(String errorTypeName, BString message, BError cause, Object details) throws BError;