public class CommonUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
CommonUtil.BLangNodeComparator
Node comparator to compare the nodes by position.
|
static class |
CommonUtil.FunctionGenerator
Inner class for generating function code.
|
Modifier and Type | Field and Description |
---|---|
static String |
BALLERINA_HOME |
static String |
FILE_SEPARATOR |
static String |
LINE_SEPARATOR |
static String |
LINE_SEPARATOR_SPLIT |
static boolean |
LS_DEBUG_ENABLED |
static String |
MARKDOWN_MARKUP_KIND |
static String |
MD_LINE_SEPARATOR |
static String |
PLAIN_TEXT_MARKUP_KIND |
Modifier and Type | Method and Description |
---|---|
static void |
calculateEndColumnOfGivenName(DiagnosticPos position,
String name,
String pkgAlias)
Calculate the user defined type position.
|
static Predicate<TopLevelNode> |
checkInvalidTypesDefs()
Predicate to check for the invalid type definitions.
|
static String |
createVariableDeclaration(String variableName,
String variableType)
Generate variable code.
|
static List<org.eclipse.lsp4j.CompletionItem> |
fillCompletionWithPkgImport(HashMap<Integer,ArrayList<org.eclipse.lsp4j.CompletionItem>> completionsMap,
LSContext ctx)
Fill the completion items extracted from LS Index db with the auto import text edits.
|
static String |
generateName(int value,
Set<String> argNames)
Generates a random name.
|
static org.eclipse.lsp4j.CompletionItem |
getAnnotationCompletionItem(PackageID packageID,
BAnnotationSymbol annotationSymbol,
LSContext ctx)
Get the Annotation completion Item.
|
static List<org.eclipse.lsp4j.TextEdit> |
getAutoImportTextEdits(LSContext ctx,
String orgName,
String pkgName)
Get the text edit for an auto import statement.
|
static String |
getBTypeName(BType bType,
LSContext ctx)
Get the BType name as string.
|
static List<BLangImportPackage> |
getCurrentFileImports(BLangPackage pkg,
LSContext ctx)
Get the current file's imports.
|
static List<TopLevelNode> |
getCurrentFileTopLevelNodes(BLangPackage pkgNode,
LSContext ctx)
Get the TopLevel nodes of the current file.
|
static BLangPackage |
getCurrentPackageByFileName(List<BLangPackage> packages,
String fileUri)
Get current package by given file name.
|
static int |
getCurrentTokenFromTokenStream(LSContext context)
Get the current token index from the token stream.
|
static String |
getDefaultValueForType(BType bType)
Get the default value for the given BType.
|
static org.eclipse.lsp4j.CompletionItem |
getFillAllStructFieldsItem(List<BField> fields)
Get the completion item to fill all the struct fields.
|
static <T> T |
getLastItem(List<T> list)
Get the last item of the List.
|
static List<org.antlr.v4.runtime.Token> |
getNDefaultTokensToLeft(org.antlr.v4.runtime.TokenStream tokenStream,
int n,
int startIndex)
Get n number of default tokens from a given start index.
|
static org.antlr.v4.runtime.Token |
getNextDefaultToken(org.antlr.v4.runtime.TokenStream tokenStream,
int startIndex)
Get the next default token from the given start index.
|
static org.antlr.v4.runtime.Token |
getNthDefaultTokensToLeft(org.antlr.v4.runtime.TokenStream tokenStream,
int startIndex,
int offset)
Get the Nth Default token to the left of current token index.
|
static Map<Name,Scope.ScopeEntry> |
getObjectFunctions(BObjectTypeSymbol objectTypeSymbol)
Given an Object type, extract the non-remote functions.
|
static String |
getPackageNameComponentsCombined(BLangImportPackage importPackage)
Get the package name components combined.
|
static BLangPackage |
getPackageNode(BLangNode bLangNode) |
static String |
getPackagePrefix(BiConsumer<String,String> importsAcceptor,
PackageID currentPkgId,
PackageID typePkgId) |
static String |
getPackageURI(String pkgName,
String pkgPath,
String currentPkgName)
Get the package URI to the given package name.
|
static List<String> |
getPoppedTokenStrings(LSContext ctx)
Get the string values list of forced consumed tokens, from the LSContext.
|
static org.antlr.v4.runtime.Token |
getPreviousDefaultToken(org.antlr.v4.runtime.TokenStream tokenStream,
int startIndex)
Get the previous default token from the given start index.
|
static BLangPackage |
getSourceOwnerBLangPackage(String relativePath,
BLangPackage parentPkg)
Get the Source's owner BLang package, this can be either the parent package or the testable BLang package.
|
static List<org.eclipse.lsp4j.CompletionItem> |
getStructFieldCompletionItems(List<BField> structFields)
Get completion items list for struct fields.
|
static Predicate<SymbolInfo> |
invalidSymbolsPredicate()
Predicate to check for the invalid symbols.
|
static boolean |
isClientObject(BSymbol bSymbol)
Check whether a given symbol is client object or not.
|
static boolean |
isInvalidSymbol(BSymbol symbol) |
static boolean |
isListenerObject(BSymbol bSymbol)
Check whether the symbol is a listener object.
|
static boolean |
isTestSource(String relativeFilePath)
Check whether the source is a test source.
|
static boolean |
isValidInvokableSymbol(BSymbol symbol)
Check whether the symbol is a valid invokable symbol.
|
static boolean |
isWithinWorkerDeclaration(BLangNode bLangNode) |
static boolean |
isWorkerDereivative(BLangNode node)
Check whether the given node is a worker derivative node.
|
static boolean |
listContainsPackage(String pkg,
List<BallerinaPackage> pkgList)
Check whether the packages list contains a given package.
|
static <T> List<T> |
popNFromList(List<T> itemList,
int n)
Pop n number of Elements from the stack and return as a List.
|
static void |
populateIdCompletionMap(HashMap<Integer,ArrayList<org.eclipse.lsp4j.CompletionItem>> map,
int id,
org.eclipse.lsp4j.CompletionItem completionItem)
Populate the given map with the completion item.
|
static void |
replacePosition(DiagnosticPos oldPos,
DiagnosticPos newPos)
Replace and returns a diagnostic position with a new position.
|
static String |
topLevelNodeInLine(org.eclipse.lsp4j.TextDocumentIdentifier identifier,
int cursorLine,
WorkspaceDocumentManager docManager)
Get the top level node type at the cursor line.
|
static DiagnosticPos |
toZeroBasedPosition(DiagnosticPos diagnosticPos)
Convert the diagnostic position to a zero based positioning diagnostic position.
|
public static final String MD_LINE_SEPARATOR
public static final String LINE_SEPARATOR
public static final String FILE_SEPARATOR
public static final String LINE_SEPARATOR_SPLIT
public static final boolean LS_DEBUG_ENABLED
public static final String BALLERINA_HOME
public static final String PLAIN_TEXT_MARKUP_KIND
public static final String MARKDOWN_MARKUP_KIND
public static String getPackageURI(String pkgName, String pkgPath, String currentPkgName)
pkgName
- Name of the package that need the URI forpkgPath
- String URI of the current packagecurrentPkgName
- Name of the current packagepublic static void calculateEndColumnOfGivenName(DiagnosticPos position, String name, String pkgAlias)
position
- position of the nodename
- name of the user defined typepkgAlias
- package alias name of the user defined typepublic static DiagnosticPos toZeroBasedPosition(DiagnosticPos diagnosticPos)
diagnosticPos
- - diagnostic position to be clonedDiagnosticPos
converted diagnostic positionpublic static void replacePosition(DiagnosticPos oldPos, DiagnosticPos newPos)
oldPos
- old positionnewPos
- new positionpublic static org.antlr.v4.runtime.Token getPreviousDefaultToken(org.antlr.v4.runtime.TokenStream tokenStream, int startIndex)
tokenStream
- Token StreamstartIndex
- Start token indexToken
Previous default tokenpublic static org.antlr.v4.runtime.Token getNextDefaultToken(org.antlr.v4.runtime.TokenStream tokenStream, int startIndex)
tokenStream
- Token StreamstartIndex
- Start token indexToken
Previous default tokenpublic static List<org.antlr.v4.runtime.Token> getNDefaultTokensToLeft(org.antlr.v4.runtime.TokenStream tokenStream, int n, int startIndex)
tokenStream
- Token Streamn
- number of tokens to extractstartIndex
- Start token indexList
List of tokens extractedpublic static org.antlr.v4.runtime.Token getNthDefaultTokensToLeft(org.antlr.v4.runtime.TokenStream tokenStream, int startIndex, int offset)
tokenStream
- Token Stream to traversestartIndex
- Start position of the token streamoffset
- Number of tokens to traverse leftToken
Nth Tokenpublic static int getCurrentTokenFromTokenStream(LSContext context)
context
- LSServiceOperationContextInteger
token indexpublic static <T> List<T> popNFromList(List<T> itemList, int n)
Note: If n is greater than stack, then all the elements of list will be returned
T
- Type of the ElementsitemList
- Item Stack to pop elements fromn
- number of elements to popList
List of popped Itemspublic static String topLevelNodeInLine(org.eclipse.lsp4j.TextDocumentIdentifier identifier, int cursorLine, WorkspaceDocumentManager docManager)
identifier
- Document IdentifiercursorLine
- Cursor linedocManager
- Workspace document managerString
Top level node typepublic static BLangPackage getCurrentPackageByFileName(List<BLangPackage> packages, String fileUri)
packages
- list of packages to be searchedfileUri
- string file URIBLangPackage
current packagepublic static org.eclipse.lsp4j.CompletionItem getAnnotationCompletionItem(PackageID packageID, BAnnotationSymbol annotationSymbol, LSContext ctx)
packageID
- Package IdannotationSymbol
- BLang annotation to extract the completion Itemctx
- LS Service operation context, in this case completion contextCompletionItem
Completion item for the annotationpublic static List<org.eclipse.lsp4j.TextEdit> getAutoImportTextEdits(LSContext ctx, String orgName, String pkgName)
ctx
- Service operation contextorgName
- package org namepkgName
- package nameList
List of Text Edits to applypublic static List<org.eclipse.lsp4j.CompletionItem> fillCompletionWithPkgImport(HashMap<Integer,ArrayList<org.eclipse.lsp4j.CompletionItem>> completionsMap, LSContext ctx)
completionsMap
- Completion Map to evaluatectx
- Lang Server Operation ContextList
List of modified completion itemspublic static void populateIdCompletionMap(HashMap<Integer,ArrayList<org.eclipse.lsp4j.CompletionItem>> map, int id, org.eclipse.lsp4j.CompletionItem completionItem)
map
- ID to completion item mapid
- pkg id in indexcompletionItem
- completion item to populatepublic static String getDefaultValueForType(BType bType)
bType
- BType to get the default valueString
Default value as a Stringpublic static boolean isClientObject(BSymbol bSymbol)
bSymbol
- BSymbol to evaluateBoolean
Symbol evaluation statuspublic static boolean isListenerObject(BSymbol bSymbol)
bSymbol
- Symbol to evaluateBoolean
whether listener or notpublic static Map<Name,Scope.ScopeEntry> getObjectFunctions(BObjectTypeSymbol objectTypeSymbol)
objectTypeSymbol
- Object SymbolMap
Map of filtered scope entriespublic static boolean listContainsPackage(String pkg, List<BallerinaPackage> pkgList)
pkg
- Package to checkpkgList
- List of packages to check againstBoolean
Check status of the packagepublic static List<org.eclipse.lsp4j.CompletionItem> getStructFieldCompletionItems(List<BField> structFields)
structFields
- List of struct fieldsList
List of completion items for the struct fieldspublic static org.eclipse.lsp4j.CompletionItem getFillAllStructFieldsItem(List<BField> fields)
fields
- List of struct fieldsCompletionItem
Completion Item to fill all the optionspublic static String getBTypeName(BType bType, LSContext ctx)
bType
- BType to get the namectx
- LS Operation ContextString
BType Name as Stringpublic static <T> T getLastItem(List<T> list)
T
- List content Typelist
- List to get the Last Itempublic static boolean isTestSource(String relativeFilePath)
relativeFilePath
- source path relative to the packageBoolean
Whether a test source or notpublic static BLangPackage getSourceOwnerBLangPackage(String relativePath, BLangPackage parentPkg)
relativePath
- Relative source pathparentPkg
- parent packageBLangPackage
Resolved BLangPackagepublic static List<String> getPoppedTokenStrings(LSContext ctx)
ctx
- Language Server contextList
Token string listpublic static boolean isValidInvokableSymbol(BSymbol symbol)
symbol
- Symbol to be evaluatedBoolean
valid statuspublic static List<BLangImportPackage> getCurrentFileImports(BLangPackage pkg, LSContext ctx)
pkg
- BLangPackage to extract content fromctx
- LS Operation ContextList
List of imports in the current filepublic static boolean isInvalidSymbol(BSymbol symbol)
public static boolean isWorkerDereivative(BLangNode node)
node
- Node to be evaluatedBoolean
whether a worker derivativepublic static boolean isWithinWorkerDeclaration(BLangNode bLangNode)
public static List<TopLevelNode> getCurrentFileTopLevelNodes(BLangPackage pkgNode, LSContext ctx)
pkgNode
- Current Package nodectx
- Service Operation contextList
List of Top Level Nodespublic static String getPackageNameComponentsCombined(BLangImportPackage importPackage)
importPackage
- BLangImportPackage nodeString
Combined package namepublic static Predicate<SymbolInfo> invalidSymbolsPredicate()
Predicate
Predicate for the checkpublic static Predicate<TopLevelNode> checkInvalidTypesDefs()
Predicate
Predicate for the checkpublic static String createVariableDeclaration(String variableName, String variableType)
variableName
- variable namevariableType
- variable typeString
generated function signaturepublic static String generateName(int value, Set<String> argNames)
value
- index of the argumentargNames
- argument setpublic static BLangPackage getPackageNode(BLangNode bLangNode)
Copyright © 2019 WSO2. All rights reserved.