public class CommonUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
CommonUtil.FunctionGenerator
Inner class for generating function code.
|
Modifier and Type | Field and Description |
---|---|
static String |
BALLERINA_HOME |
static String |
LINE_SEPARATOR |
static String |
LINE_SEPARATOR_SPLIT |
static boolean |
LS_DEBUG_ENABLED |
Constructor and Description |
---|
CommonUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
calculateEndColumnOfGivenName(DiagnosticPos position,
String name,
String pkgAlias)
Calculate the user defined type position.
|
static List<SymbolInfo> |
getActionsOfEndpoint(BEndpointVarSymbol bEndpointVarSymbol)
Get the actions defined over and endpoint.
|
static org.eclipse.lsp4j.CompletionItem |
getAnnotationCompletionItem(PackageID packageID,
BAnnotationSymbol annotationSymbol)
Get the Annotation completion Item.
|
static String |
getBTypeName(BType bType,
LSContext ctx)
Get the BType name as string.
|
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 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 List<org.antlr.v4.runtime.Token> |
getNDefaultTokensToRight(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 org.antlr.v4.runtime.Token |
getNthDefaultTokensToRight(org.antlr.v4.runtime.TokenStream tokenStream,
int startIndex,
int offset)
Get the Nth Default token to the right of current token index.
|
static String |
getPackageURI(String pkgName,
String currentPkgPath,
String currentPkgName)
Get the package URI to the given package name.
|
static Path |
getPath(LSDocument document)
Common utility to get a Path from the given uri string.
|
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 List<org.eclipse.lsp4j.CompletionItem> |
getStructFieldPopulateCompletionItems(List<BField> structFields)
Get completion items list for struct fields.
|
static ArrayList<SymbolInfo> |
invocationsAndFieldsOnIdentifier(LSServiceOperationContext context,
String variableName,
String delimiter)
Get the invocations and fields against an identifier (functions, struct fields and types including the enums).
|
static boolean |
isEndpointObject(BSymbol bSymbol)
Check whether a given symbol is an endpoint object or not.
|
static boolean |
isWithinBrackets(LSServiceOperationContext context,
List<String> terminalTokens)
Check whether the given cursor position is within the brackets.
|
static boolean |
listContainsPackage(String pkg,
List<BallerinaPackage> pkgList)
Check whether the packages list contains a given package.
|
static <T> List<T> |
popNFromStack(Stack<T> itemStack,
int n)
Pop n number of Elements from the stack and return as a List.
|
static String |
topLevelNodeTypeInLine(org.eclipse.lsp4j.TextDocumentIdentifier identifier,
org.eclipse.lsp4j.Position startPosition,
WorkspaceDocumentManager docManager)
Get the top level node type in the line.
|
static DiagnosticPos |
toZeroBasedPosition(DiagnosticPos diagnosticPos)
Convert the diagnostic position to a zero based positioning diagnostic position.
|
public static final String LINE_SEPARATOR
public static final String LINE_SEPARATOR_SPLIT
public static final boolean LS_DEBUG_ENABLED
public static final String BALLERINA_HOME
public static String getPackageURI(String pkgName, String currentPkgPath, String currentPkgName)
pkgName
- Name of the package that need the URI forcurrentPkgPath
- String URI of the current packagecurrentPkgName
- Name of the current packagepublic static Path getPath(LSDocument document)
document
- LSDocument object of the filePath
Path of the uripublic 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 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 List<org.antlr.v4.runtime.Token> getNDefaultTokensToRight(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 org.antlr.v4.runtime.Token getNthDefaultTokensToRight(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 rightToken
Nth Tokenpublic static int getCurrentTokenFromTokenStream(LSContext context)
context
- LSServiceOperationContextInteger
token indexpublic static <T> List<T> popNFromStack(Stack<T> itemStack, int n)
T
- Type of the ElementsitemStack
- Item Stack to pop elements fromn
- number of elements to popList
List of popped Itemspublic static boolean isWithinBrackets(LSServiceOperationContext context, List<String> terminalTokens)
context
- Text document contextterminalTokens
- List of terminal tokensBoolean
Whether the cursor is within the brackets or notpublic static String topLevelNodeTypeInLine(org.eclipse.lsp4j.TextDocumentIdentifier identifier, org.eclipse.lsp4j.Position startPosition, WorkspaceDocumentManager docManager)
identifier
- Document IdentifierstartPosition
- Start positiondocManager
- 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)
packageID
- Package IdannotationSymbol
- BLang annotation to extract the completion ItemCompletionItem
Completion item for the annotationpublic static String getDefaultValueForType(BType bType)
bType
- BType to get the default valueString
Default value as a Stringpublic static ArrayList<SymbolInfo> invocationsAndFieldsOnIdentifier(LSServiceOperationContext context, String variableName, String delimiter)
context
- Text Document Service context (Completion Context)variableName
- Variable name to evaluate against (Can be package alias or defined variable)delimiter
- delimiter String (. or :)ArrayList
List of filtered symbol infopublic static boolean isEndpointObject(BSymbol bSymbol)
bSymbol
- BSymbol to evaluateBoolean
Symbol evaluation statuspublic 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> getStructFieldPopulateCompletionItems(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 List<SymbolInfo> getActionsOfEndpoint(BEndpointVarSymbol bEndpointVarSymbol)
bEndpointVarSymbol
- Endpoint variable symbol to evaluateList
List of extracted actions as Symbol InfoCopyright © 2018 WSO2. All rights reserved.