public class CommonUtil extends Object
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 org.eclipse.lsp4j.CompletionItem |
getAnnotationCompletionItem(PackageID packageID,
BLangAnnotation annotation)
Get the Annotation completion Item.
|
static String |
getBaseIndentationFromNode(org.antlr.v4.runtime.Token token)
Get the base indentation of a given node.
|
static BLangPackage |
getCurrentPackageByFileName(List<BLangPackage> packages,
String fileUri)
Get current package by given file name.
|
static String |
getDefaultValueForType(BType bType)
Get the default value for the given BType.
|
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 SymbolInfo |
getVariableByName(String name,
List<SymbolInfo> symbols)
Get the variable symbol info by the name.
|
static ArrayList<SymbolInfo> |
invocationsAndFieldsOnIdentifier(LSServiceOperationContext context,
int delimiterIndex)
Get the invocations and fields against an identifier (functions, struct fields and types including the enums).
|
static boolean |
isWithinBrackets(LSServiceOperationContext context,
List<String> terminalTokens)
Check whether the given cursor position is within the brackets.
|
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 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 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 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, BLangAnnotation annotation)
packageID
- Package Idannotation
- 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 String getBaseIndentationFromNode(org.antlr.v4.runtime.Token token)
token
- Token to be evaluatedString
Calculated base indentationpublic static SymbolInfo getVariableByName(String name, List<SymbolInfo> symbols)
name
- name of the variablesymbols
- list of symbol infoSymbolInfo
Symbol Info extractedpublic static ArrayList<SymbolInfo> invocationsAndFieldsOnIdentifier(LSServiceOperationContext context, int delimiterIndex)
context
- Text Document Service context (Completion Context)delimiterIndex
- delimiter index (index of either . or :)ArrayList
List of filtered symbol infoCopyright © 2018 WSO2. All rights reserved.