Package com._1c.g5.v8.dt.bsl.util
Class BslUtil
- java.lang.Object
-
- com._1c.g5.v8.dt.bsl.util.BslUtil
-
public class BslUtil extends Object
Common methods for BSL
-
-
Field Summary
Fields Modifier and Type Field Description static com.google.common.base.Function<FormalParam,String>
TRANSFORMER_FORMAL_PARAM
SpecialFunction
for transform list ofFormalParam
to stringstatic com.google.common.base.Function<FormalParam,String>
TRANSFORMER_FORMAL_PARAM_WITH_DEF_VALUES
SpecialFunction
for transform list ofFormalParam
with default values to stringstatic com.google.common.base.Function<TypeItem,String>
TYPE_NAME
SpecialFunction
for transform list ofTypeItem
to stringstatic com.google.common.base.Function<TypeItem,String>
TYPE_NAME_RU
SpecialFunction
for transform list ofTypeItem
to string
-
Constructor Summary
Constructors Constructor Description BslUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static List<Method>
allMethods(ContextDef contextDef, Module module)
More faster implementation ofContextDef.allMethods()
with replacing proxy reference contextDef for bsl module to real its contextDefstatic List<Property>
allProperties(ContextDef contextDef, Module module)
More faster implementation ofContextDef.allProperties()
with replacing proxy reference contextDef for bsl module to real its contextDefstatic Environments
computeEnvironments(Environmental environmental, PragmaTarget pragmaTarget, Defines defines)
ComputesEnvironments
forEnvironmental
element of Bsl grammarstatic ModuleType
computeModuleType(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter)
Computes module typestatic ModuleType
computeModuleType(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider)
Computes module typestatic String
createTypesLineStr(List<TypeItem> types, boolean isRussian)
Converts list ofTypeItem
to stringstatic org.eclipse.emf.ecore.EObject
findCommentAnnotatedObject(org.eclipse.emf.ecore.EObject source)
static List<Event>
getCorrespondEvent(Method method, Map<CaseInsensitiveString,List<Event>> allEvents)
static Collection<Block>
getDependMethodsTree(Method method)
Gets allBlock
depending frommethod
static ForkJoinPool
getExecutorService()
Creates specialExecutorService
for Bsl.static org.eclipse.xtext.scoping.IScope
getExternalMethodsScope(Module module, Method method, Environments envs, org.eclipse.xtext.scoping.IScopeProvider scopeProvider)
Gets scope of all external methods for modulestatic org.eclipse.xtext.scoping.IScope
getExternalVariablesScope(Module module, Environments envs, org.eclipse.xtext.scoping.IScopeProvider scopeProvider)
Gets scope of all external variables for modulestatic List<FeatureEntry>
getRealObject(FeatureAccess featureAccess, Block block, DynamicFeatureAccessComputer dynamicComputer, IBslOwnerComputerService ownerComputerService)
Computes real objects by semantic Bsl objectstatic List<FeatureEntry>
getRealObject(FeatureAccess featureAccess, Block block, DynamicFeatureAccessComputer dynamicComputer, IBslOwnerComputerService ownerComputerService, boolean mockMethodsAllowed)
Computes real objects by semantic Bsl objectstatic List<ContextDef>
getRefContextDefs(ContextDef contextDef, Module module)
Gets all references context.static Type
getResolvedTypeByName(org.eclipse.emf.ecore.resource.Resource resource, String typeName)
GetsType
by namestatic String
getRuleSemicolonName(BslGrammarAccess grammar)
Gets name of grammar rule "SEMICOLON"
See Bsl.xtextstatic TypeItem
getSingleTypeByName(String typeName, IEObjectProvider typeProvider)
Gets type by name for BSL element grammarstatic List<TypeItem>
getTypeByName(String typeName, IEObjectProvider typeProvider)
Gets type by name for BSL element grammarstatic boolean
hasGlobalElementsWithTheSameName(org.eclipse.xtext.scoping.IScope scope, org.eclipse.xtext.naming.QualifiedName qName)
Checks that scope contains global element with nameqName
static boolean
hasMethodClientDirective(Method method)
Checks thatMethod
has clients directivestatic boolean
hasMethodServerDirective(Method method)
Checks thatMethod
has server directivestatic boolean
hasOtherResourceElements(org.eclipse.xtext.scoping.IScope scope, org.eclipse.xtext.naming.QualifiedName qName, Environments envs, org.eclipse.emf.common.util.URI resourceUri)
Checks that scope contains element with nameqName
static void
installModuleEnvironments(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter, IBslOwnerComputerService ownerComputerService, Version version, boolean installIntoMethod)
InstallsEnvironments
for BslModule
and its elementsstatic void
installModuleEnvironments(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider, Version version, IBslOwnerComputerService ownerComputerService, boolean installIntoMethod)
Deprecated.static boolean
intersectTypeItem(List<TypeItem> expectedTypes, List<TypeItem> realTypes, org.eclipse.emf.ecore.EObject context)
Checks that collections ofTypeItem
have common itemstatic boolean
isBinaryBslFile(BufferedInputStream inputStream, String fileName)
Returns whether the provided BSL file content with the provided file name is binary BSL module.static boolean
isBuildOperationResourceSet(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Checks thatResourceSet
was created in build operationstatic boolean
isCallFromClient(org.eclipse.emf.ecore.EObject feature, Invocation inv)
Checks that objectfeature
is calling from clients environmentsstatic boolean
isGlobal(Module module)
Checks that is global modulestatic boolean
isRussian(org.eclipse.emf.ecore.EObject object, IV8ProjectManager v8projectManager)
Returns currentScriptVariant
for the provided context BSL model object.static boolean
isServerCall(Module module)
Checks thatmodule
allows using server callstatic void
putEventToMapByName(String name, Map<CaseInsensitiveString,List<Event>> mapEvents, Event event)
Adds theEvent
to special name for fast searching events by namestatic void
setModuleOwner(Module module, IBslOwnerComputerService ownerService)
Computes module owner proxystatic void
setModuleType(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter)
Computes module type by module qualified namestatic void
setModuleType(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider)
Computes module type by module qualified namestatic <F,T>
Collection<T>transform(Collection<F> fromCollection, com.google.common.base.Function<? super F,T> function)
Returns a collection that appliesfunction
to each element offromCollection
.static Map<CaseInsensitiveString,List<Event>>
transformToMapOfEvent(List<Event> events)
Transforms list ofEvent
s to map for fast searching events by namestatic Collection<TypeItem>
trasformListTypeNamesToTypeItems(List<String> typesName, org.eclipse.xtext.scoping.IScope scope, org.eclipse.xtext.naming.IQualifiedNameConverter qualifiedNameConverter)
Transform list of type names toTypeItem
-
-
-
Field Detail
-
TYPE_NAME
public static final com.google.common.base.Function<TypeItem,String> TYPE_NAME
SpecialFunction
for transform list ofTypeItem
to string
-
TYPE_NAME_RU
public static final com.google.common.base.Function<TypeItem,String> TYPE_NAME_RU
SpecialFunction
for transform list ofTypeItem
to string
-
TRANSFORMER_FORMAL_PARAM
public static final com.google.common.base.Function<FormalParam,String> TRANSFORMER_FORMAL_PARAM
SpecialFunction
for transform list ofFormalParam
to string
-
TRANSFORMER_FORMAL_PARAM_WITH_DEF_VALUES
public static final com.google.common.base.Function<FormalParam,String> TRANSFORMER_FORMAL_PARAM_WITH_DEF_VALUES
SpecialFunction
for transform list ofFormalParam
with default values to string
-
-
Method Detail
-
isBinaryBslFile
public static boolean isBinaryBslFile(BufferedInputStream inputStream, String fileName) throws IOException
Returns whether the provided BSL file content with the provided file name is binary BSL module. The input stream will not be closed by this operation.BufferedInputStream
is required to keep input cursor unchanged.- Parameters:
inputStream
- the module content to check, cannot benull
filePath
- the file name to check, cannot benull
- Returns:
- whether the provided BSL file content with the provided file name is binary BSL module
- Throws:
IOException
- if an I/O error occurred
-
createTypesLineStr
public static String createTypesLineStr(List<TypeItem> types, boolean isRussian)
Converts list ofTypeItem
to string
-
getRuleSemicolonName
public static String getRuleSemicolonName(BslGrammarAccess grammar)
Gets name of grammar rule "SEMICOLON"
See Bsl.xtext- Parameters:
grammar
-BslGrammarAccess
- Returns:
- rule name
-
intersectTypeItem
public static boolean intersectTypeItem(List<TypeItem> expectedTypes, List<TypeItem> realTypes, org.eclipse.emf.ecore.EObject context)
Checks that collections ofTypeItem
have common item
-
transformToMapOfEvent
public static Map<CaseInsensitiveString,List<Event>> transformToMapOfEvent(List<Event> events)
Transforms list ofEvent
s to map for fast searching events by name- Parameters:
events
- all events cannot benull
- Returns:
- special map contains (key - event name, value - list of corresponding events)
-
putEventToMapByName
public static void putEventToMapByName(String name, Map<CaseInsensitiveString,List<Event>> mapEvents, Event event)
Adds theEvent
to special name for fast searching events by name
-
getCorrespondEvent
public static List<Event> getCorrespondEvent(Method method, Map<CaseInsensitiveString,List<Event>> allEvents)
-
trasformListTypeNamesToTypeItems
public static Collection<TypeItem> trasformListTypeNamesToTypeItems(List<String> typesName, org.eclipse.xtext.scoping.IScope scope, org.eclipse.xtext.naming.IQualifiedNameConverter qualifiedNameConverter)
Transform list of type names toTypeItem
- Parameters:
typesName
- list of types name, cannot benull
scope
- all available scope types, cannot benull
qualifiedNameConverter
- actualIQualifiedNameConverter
, cannot benull
- Returns:
- collection of the
TypeItem
withoutnull
elements
-
installModuleEnvironments
@Deprecated public static void installModuleEnvironments(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider, Version version, IBslOwnerComputerService ownerComputerService, boolean installIntoMethod)
Deprecated.InstallsEnvironments
for BslModule
and its elements- Parameters:
module
- processingModule
cannot benull
qualifiedNameProvider
-IQualifiedNameProvider
ownerComputerService
-IBslOwnerComputerService
version
- actualVersion
, cannot benull
installIntoMethod
- iftrue
environments will be computed into method statements
-
installModuleEnvironments
public static void installModuleEnvironments(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter, IBslOwnerComputerService ownerComputerService, Version version, boolean installIntoMethod)
InstallsEnvironments
for BslModule
and its elements- Parameters:
module
- processingModule
cannot benull
qualifiedNameFilePathConverter
-IQualifiedNameFilePathConverter
ownerComputerService
-IBslOwnerComputerService
version
- actualVersion
, cannot benull
installIntoMethod
- iftrue
environments will be computed into method statements
-
computeEnvironments
public static Environments computeEnvironments(Environmental environmental, PragmaTarget pragmaTarget, Defines defines)
ComputesEnvironments
forEnvironmental
element of Bsl grammar- Parameters:
environmental
- Bsl grammar element. If it has ownEnvironments
then computingEnvironments
will be intersect with itsEnvironments
, can benull
pragmaTarget
- container of actualPragma
, cannot benull
defines
- actualDefines
for currentEnvironmental
Bsl grammar element, cannot benull
- Returns:
- computed
Environments
ornull
if there is noEnvironments
-
getResolvedTypeByName
public static Type getResolvedTypeByName(org.eclipse.emf.ecore.resource.Resource resource, String typeName)
GetsType
by name- Parameters:
resource
- resource for resolving, cannot benull
typeName
- type name, cannot benull
- Returns:
- found type or
null
if type wasn't found
-
hasOtherResourceElements
public static boolean hasOtherResourceElements(org.eclipse.xtext.scoping.IScope scope, org.eclipse.xtext.naming.QualifiedName qName, Environments envs, org.eclipse.emf.common.util.URI resourceUri)
Checks that scope contains element with nameqName
- Parameters:
scope
-IScope
qName
- checking name, cannot benull
envs
- actual elementEnvironments
, cannot benull
resourceUri
- uri of the Bsl module resource, cannot benull
- Returns:
true
if element with nameqName
was found
-
hasGlobalElementsWithTheSameName
public static boolean hasGlobalElementsWithTheSameName(org.eclipse.xtext.scoping.IScope scope, org.eclipse.xtext.naming.QualifiedName qName)
Checks that scope contains global element with nameqName
- Parameters:
scope
-IScope
qName
- checking name- Returns:
true
if element with nameqName
was found
-
getExternalMethodsScope
public static org.eclipse.xtext.scoping.IScope getExternalMethodsScope(Module module, Method method, Environments envs, org.eclipse.xtext.scoping.IScopeProvider scopeProvider)
Gets scope of all external methods for module- Parameters:
module
- current Bsl modulemethod
- current methodenv
- actualEnvironments
scopeProvider
- actualIScopeProvider
- Returns:
- found scope
-
getExternalVariablesScope
public static org.eclipse.xtext.scoping.IScope getExternalVariablesScope(Module module, Environments envs, org.eclipse.xtext.scoping.IScopeProvider scopeProvider)
Gets scope of all external variables for module- Parameters:
module
- current Bsl moduleenv
- actualEnvironments
scopeProvider
- actualIScopeProvider
- Returns:
- found scope
-
findCommentAnnotatedObject
public static org.eclipse.emf.ecore.EObject findCommentAnnotatedObject(org.eclipse.emf.ecore.EObject source)
- Parameters:
source
- source object for searching- Returns:
- annotated by comment object of Bsl grammar, can be
null
if annotated object wasn't found
-
isRussian
public static boolean isRussian(org.eclipse.emf.ecore.EObject object, IV8ProjectManager v8projectManager)
Returns currentScriptVariant
for the provided context BSL model object.- Parameters:
object
- the context BSL model object, cannot benull
v8projectManager
- theIV8ProjectManager
instance, cannot benull
- Returns:
true
ifscriptVariant == RUSSIAN
,false
otherwise
-
transform
public static <F,T> Collection<T> transform(Collection<F> fromCollection, com.google.common.base.Function<? super F,T> function)
Returns a collection that appliesfunction
to each element offromCollection
. The returned collection is a new collection- Parameters:
fromCollection
- source collection with elements for transformation, cannot benull
function
- function for transformation elements from source collection, cannot benull
- Returns:
- return new collection with transformed elements from source collection, never
null
-
getExecutorService
public static ForkJoinPool getExecutorService()
Creates specialExecutorService
for Bsl.ExecutorService
uses specialThreadFactory
-BslInnerProcessorThreadFactory
- Returns:
- created
ForkJoinPool
, nevernull
-
getRealObject
public static List<FeatureEntry> getRealObject(FeatureAccess featureAccess, Block block, DynamicFeatureAccessComputer dynamicComputer, IBslOwnerComputerService ownerComputerService)
Computes real objects by semantic Bsl object- Parameters:
featureAccess
- actual semantic object, cannot benull
block
- actualBlock
for semantic object, cannot benull
dynamicComputer
- actualDynamicFeatureAccessComputer
, cannot benull
ownerComputerService
- actualIBslOwnerComputerService
, cannot benull
- Returns:
- lists of
FeatureEntry
contains computed real objects or empty list, nevernull
-
getRealObject
public static List<FeatureEntry> getRealObject(FeatureAccess featureAccess, Block block, DynamicFeatureAccessComputer dynamicComputer, IBslOwnerComputerService ownerComputerService, boolean mockMethodsAllowed)
Computes real objects by semantic Bsl object- Parameters:
featureAccess
- actual semantic object, cannot benull
block
- actualBlock
for semantic object, cannot benull
dynamicComputer
- actualDynamicFeatureAccessComputer
, cannot benull
ownerComputerService
- actualIBslOwnerComputerService
, cannot benull
mockMethodsAllowed
-true
if allowed forFeatureEntry.getFeature()
return mock of exported user methods. Mock exported user methods is specialMethod
without resource and container, which contains right name of the export method, right properties: isRetval, isDeprecated, isServerCall, source uri to the real method in module, min parameters count and information about each parameter - out or not- Returns:
- lists of
FeatureEntry
contains computed real objects or empty list, nevernull
-
isCallFromClient
public static boolean isCallFromClient(org.eclipse.emf.ecore.EObject feature, Invocation inv)
Checks that objectfeature
is calling from clients environments- Parameters:
feature
- checking object, cannot benull
inv
- actual semantic grammar element from Bsl language model, cannot benull
- Returns:
true
objectfeature
is calling from clients environments,false
otherwise
-
isServerCall
public static boolean isServerCall(Module module)
Checks thatmodule
allows using server call- Parameters:
module
- checking bsl module, cannot benull
- Returns:
true
ifmodule
allows using server call,false
otherwise
-
isGlobal
public static boolean isGlobal(Module module)
Checks that is global module- Parameters:
module
- checking bsl module, cannot benull
- Returns:
true
ifmodule
is global module,false
otherwise
-
getTypeByName
public static List<TypeItem> getTypeByName(String typeName, IEObjectProvider typeProvider)
Gets type by name for BSL element grammar- Parameters:
typeName
- - type name, cannot benull
typeProvider
- actualIEObjectProvider
for type, cannot benull
- Returns:
- list of
TypeItem
corresponding totypeName
-
getSingleTypeByName
public static TypeItem getSingleTypeByName(String typeName, IEObjectProvider typeProvider)
Gets type by name for BSL element grammar- Parameters:
typeName
- type name, cannot benull
typeProvider
- actualIEObjectProvider
for type, cannot benull
- Returns:
- type corresponding to
typeName
, ornull
if there is no corresponding type fortypeName
-
hasMethodClientDirective
public static boolean hasMethodClientDirective(Method method)
Checks thatMethod
has clients directive- Parameters:
method
- checking method, cannot benull
- Returns:
true
ifMethod
has clients directive,false
otherwise
-
hasMethodServerDirective
public static boolean hasMethodServerDirective(Method method)
Checks thatMethod
has server directive- Parameters:
method
- checking method, cannot benull
- Returns:
true
ifMethod
has server directive,false
otherwise
-
allMethods
public static List<Method> allMethods(ContextDef contextDef, Module module)
More faster implementation ofContextDef.allMethods()
with replacing proxy reference contextDef for bsl module to real its contextDef- Parameters:
contextDef
- actual context def for getting all methods, cannot benull
module
- bsl module which contextDef will be used for replacing proxy ContextDef, cannot benull
- Returns:
- all methods from context def, never
null
-
allProperties
public static List<Property> allProperties(ContextDef contextDef, Module module)
More faster implementation ofContextDef.allProperties()
with replacing proxy reference contextDef for bsl module to real its contextDef- Parameters:
contextDef
- actual context def for getting all properties, cannot benull
module
- bsl module which contextDef will be used for replacing proxy ContextDef, cannot benull
- Returns:
- all proeprties from context def, never
null
-
getRefContextDefs
public static List<ContextDef> getRefContextDefs(ContextDef contextDef, Module module)
Gets all references context. Replace proxy contextDef of Bsl module to real contextDef of module- Parameters:
contextDef
-ContextDef
for getting reference contextDefs, cannot benull
module
- bsl module which contextDef will be used for replacing proxy ContextDef, cannot benull
- Returns:
- list of references contextDef, never
null
-
setModuleType
public static void setModuleType(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider)
Computes module type by module qualified name- Parameters:
module
- the module, cannot benull
qualifiedNameProvider
- theIQualifiedNameProvider
service, cannot benull
-
setModuleType
public static void setModuleType(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter)
Computes module type by module qualified name- Parameters:
module
- the module, cannot benull
qualifiedNameFilePathConverter
- theIQualifiedNameFilePathConverter
service, cannot benull
-
setModuleOwner
public static void setModuleOwner(Module module, IBslOwnerComputerService ownerService)
Computes module owner proxy- Parameters:
module
- the module, cannot benull
ownerService
- theIBslOwnerComputerService
service, cannot benull
-
computeModuleType
public static ModuleType computeModuleType(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter)
Computes module type- Parameters:
module
-Module
, cannot benull
qualifiedNameFilePathConverter
-IQualifiedNameFilePathConverter
, cannot benull
- Returns:
- computed module type or
null
if unknown module type was detected
-
computeModuleType
public static ModuleType computeModuleType(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider)
Computes module type- Parameters:
module
-Module
provider
-IQualifiedNameProvider
- Returns:
- computed module type or
null
-
getDependMethodsTree
public static Collection<Block> getDependMethodsTree(Method method)
Gets allBlock
depending frommethod
-
isBuildOperationResourceSet
public static boolean isBuildOperationResourceSet(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Checks thatResourceSet
was created in build operation- Parameters:
resourceSet
- checkingResourceSet
, cannot benull
- Returns:
true
ifResourceSet
was created in build operation,false
otherwise
-
-