Package com._1c.g5.v8.dt.bsl.util
Class BslUtil
java.lang.Object
com._1c.g5.v8.dt.bsl.util.BslUtil
Common methods for BSL
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.google.common.base.Function<FormalParam,String> SpecialFunctionfor transform list ofFormalParamto stringstatic final com.google.common.base.Function<FormalParam,String> SpecialFunctionfor transform list ofFormalParamwith default values to string -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallMethods(ContextDef contextDef, Module module, INamingService namingService) More faster implementation ofContextDef.allMethods()with replacing proxy reference contextDef for bsl module to real its contextDefallProperties(ContextDef contextDef, Module module, INamingService namingService) More faster implementation ofContextDef.allProperties()with replacing proxy reference contextDef for bsl module to real its contextDefstatic EnvironmentscomputeEnvironments(Environmental environmental, PragmaTarget pragmaTarget, Defines defines) ComputesEnvironmentsforEnvironmentalelement of Bsl grammarstatic ModuleTypecomputeModuleType(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter) Computes module typestatic ModuleTypecomputeModuleType(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider) Computes module typestatic Collection<String>computeTypeNames(Collection<TypeItem> types, org.eclipse.emf.ecore.EObject context) Computes name of the each type from the specified collection.static StringcreateTypesLineStr(List<TypeItem> types, boolean isRussian) Converts list ofTypeItemto stringstatic org.eclipse.emf.ecore.EObjectfindCommentAnnotatedObject(org.eclipse.emf.ecore.EObject source) getCorrespondEvent(Method method, Map<CaseInsensitiveString, List<Event>> allEvents) static Collection<Block>getDependMethodsTree(Method method) Gets allBlockdepending frommethodstatic ForkJoinPoolCreates specialExecutorServicefor Bsl.static org.eclipse.xtext.scoping.IScopegetExternalMethodsScope(Module module, Method method, Environments envs, org.eclipse.xtext.scoping.IScopeProvider scopeProvider) Gets scope of all external methods for modulestatic org.eclipse.xtext.scoping.IScopegetExternalVariablesScope(Module module, Environments envs, org.eclipse.xtext.scoping.IScopeProvider scopeProvider) Gets scope of all external variables for modulestatic org.eclipse.xtext.nodemodel.INodegetMethodSignatureLastNode(Method method) Gets lastINodecorresponding to the method signaturestatic 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, INamingService namingService) Gets all references context.static TypegetResolvedTypeByName(org.eclipse.emf.ecore.resource.Resource resource, String typeName) GetsTypeby namestatic StringgetRuleSemicolonName(BslGrammarAccess grammar) Gets name of grammar rule "SEMICOLON"
See Bsl.xtextstatic TypeItemgetSingleTypeByName(String typeName, IEObjectProvider typeProvider) Gets type by name for BSL element grammargetTypeByName(String typeName, IEObjectProvider typeProvider) Gets type by name for BSL element grammarstatic booleanhasGlobalElementsWithTheSameName(org.eclipse.xtext.scoping.IScope scope, org.eclipse.xtext.naming.QualifiedName qName) Checks that scope contains global element with nameqNamestatic booleanhasMethodClientDirective(Method method) Checks thatMethodhas clients directivestatic booleanhasMethodServerDirective(Method method) Checks thatMethodhas server directivestatic booleanhasOtherResourceElements(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 nameqNamestatic voidinstallModuleEnvironments(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter, IBslOwnerComputerService ownerComputerService, Version version, boolean installIntoMethod) InstallsEnvironmentsfor BslModuleand its elementsstatic voidinstallModuleEnvironments(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider, Version version, IBslOwnerComputerService ownerComputerService, boolean installIntoMethod) Deprecated.static booleanintersectTypeItem(List<TypeItem> expectedTypes, List<TypeItem> realTypes, org.eclipse.emf.ecore.EObject context) Checks that collections ofTypeItemhave common itemstatic booleanisBinaryBslFile(BufferedInputStream inputStream, String fileName) Returns whether the provided BSL file content with the provided file name is binary BSL module.static booleanisBuildOperationResourceSet(org.eclipse.emf.ecore.resource.ResourceSet resourceSet) Checks thatResourceSetwas created in build operationstatic booleanisCallFromClient(org.eclipse.emf.ecore.EObject feature, Invocation inv) Checks that objectfeatureis calling from clients environmentsstatic booleanisExternalModuleContextDef(ContextDef refContextDef, Module module, INamingService namingService) Checks if the contextDef belongs to another modulestatic booleanChecks that is global modulestatic booleanisRussian(IV8Project v8project) Returns currentScriptVariantfor the providedIV8Projectstatic booleanisRussian(org.eclipse.emf.ecore.EObject object, IV8ProjectManager v8projectManager) Returns currentScriptVariantfor the provided context BSL model object.static booleanisServerCall(Module module) Checks thatmoduleallows using server callstatic voidputEventToMapByName(String name, Map<CaseInsensitiveString, List<Event>> mapEvents, Event event) Adds theEventto special name for fast searching events by namestatic voidsetModuleOwner(Module module, IBslOwnerComputerService ownerService) Computes module owner proxystatic voidsetModuleType(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter) Computes module type by module qualified namestatic voidsetModuleType(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 appliesfunctionto each element offromCollection.static Map<CaseInsensitiveString,List<Event>> transformToMapOfEvent(List<Event> events) Transforms list ofEvents 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 Details
-
TRANSFORMER_FORMAL_PARAM
SpecialFunctionfor transform list ofFormalParamto string -
TRANSFORMER_FORMAL_PARAM_WITH_DEF_VALUES
public static final com.google.common.base.Function<FormalParam,String> TRANSFORMER_FORMAL_PARAM_WITH_DEF_VALUESSpecialFunctionfor transform list ofFormalParamwith default values to string
-
-
Constructor Details
-
BslUtil
public BslUtil()
-
-
Method Details
-
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.BufferedInputStreamis required to keep input cursor unchanged.- Parameters:
inputStream- the module content to check, cannot benullfilePath- 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
Converts list ofTypeItemto string -
getRuleSemicolonName
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 ofTypeItemhave common item -
transformToMapOfEvent
Transforms list ofEvents 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 theEventto special name for fast searching events by name -
getCorrespondEvent
-
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 benullscope- all available scope types, cannot benullqualifiedNameConverter- actualIQualifiedNameConverter, cannot benull- Returns:
- collection of the
TypeItemwithoutnullelements
-
installModuleEnvironments
@Deprecated public static void installModuleEnvironments(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider, Version version, IBslOwnerComputerService ownerComputerService, boolean installIntoMethod) Deprecated.InstallsEnvironmentsfor BslModuleand its elements- Parameters:
module- processingModulecannot benullqualifiedNameProvider-IQualifiedNameProviderownerComputerService-IBslOwnerComputerServiceversion- actualVersion, cannot benullinstallIntoMethod- iftrueenvironments will be computed into method statements
-
installModuleEnvironments
public static void installModuleEnvironments(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter, IBslOwnerComputerService ownerComputerService, Version version, boolean installIntoMethod) InstallsEnvironmentsfor BslModuleand its elements- Parameters:
module- processingModulecannot benullqualifiedNameFilePathConverter-IQualifiedNameFilePathConverterownerComputerService-IBslOwnerComputerServiceversion- actualVersion, cannot benullinstallIntoMethod- iftrueenvironments will be computed into method statements
-
computeEnvironments
public static Environments computeEnvironments(Environmental environmental, PragmaTarget pragmaTarget, Defines defines) ComputesEnvironmentsforEnvironmentalelement of Bsl grammar- Parameters:
environmental- Bsl grammar element. If it has ownEnvironmentsthen computingEnvironmentswill be intersect with itsEnvironments, can benullpragmaTarget- container of actualPragma, cannot benulldefines- actualDefinesfor currentEnvironmentalBsl grammar element, cannot benull- Returns:
- computed
Environmentsornullif there is noEnvironments
-
getResolvedTypeByName
public static Type getResolvedTypeByName(org.eclipse.emf.ecore.resource.Resource resource, String typeName) GetsTypeby name- Parameters:
resource- resource for resolving, cannot benulltypeName- type name, cannot benull- Returns:
- found type or
nullif 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-IScopeqName- checking name, cannot benullenvs- actual elementEnvironments, cannot benullresourceUri- uri of the Bsl module resource, cannot benull- Returns:
trueif element with nameqNamewas 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-IScopeqName- checking name- Returns:
trueif element with nameqNamewas 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- actualEnvironmentsscopeProvider- 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- actualEnvironmentsscopeProvider- 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
nullif annotated object wasn't found
-
isRussian
public static boolean isRussian(org.eclipse.emf.ecore.EObject object, IV8ProjectManager v8projectManager) Returns currentScriptVariantfor the provided context BSL model object.- Parameters:
object- the context BSL model object, cannot benullv8projectManager- theIV8ProjectManagerinstance, cannot benull- Returns:
trueifscriptVariant == RUSSIAN,falseotherwise
-
isRussian
Returns currentScriptVariantfor the providedIV8Project- Parameters:
v8project- currentIV8Project, cannot benull- Returns:
trueifscriptVariant == RUSSIAN,falseotherwise
-
transform
public static <F,T> Collection<T> transform(Collection<F> fromCollection, com.google.common.base.Function<? super F, T> function) Returns a collection that appliesfunctionto each element offromCollection. The returned collection is a new collection- Parameters:
fromCollection- source collection with elements for transformation, cannot benullfunction- function for transformation elements from source collection, cannot benull- Returns:
- return new collection with transformed elements from source collection, never
null
-
getExecutorService
Creates specialExecutorServicefor Bsl.ExecutorServiceuses 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 benullblock- actualBlockfor semantic object, cannot benulldynamicComputer- actualDynamicFeatureAccessComputer, cannot benullownerComputerService- actualIBslOwnerComputerService, cannot benull- Returns:
- lists of
FeatureEntrycontains 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 benullblock- actualBlockfor semantic object, cannot benulldynamicComputer- actualDynamicFeatureAccessComputer, cannot benullownerComputerService- actualIBslOwnerComputerService, cannot benullmockMethodsAllowed-trueif allowed forFeatureEntry.getFeature()return mock of exported user methods. Mock exported user methods is specialMethodwithout 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
FeatureEntrycontains computed real objects or empty list, nevernull
-
isCallFromClient
Checks that objectfeatureis calling from clients environments- Parameters:
feature- checking object, cannot benullinv- actual semantic grammar element from Bsl language model, cannot benull- Returns:
trueobjectfeatureis calling from clients environments,falseotherwise
-
isServerCall
Checks thatmoduleallows using server call- Parameters:
module- checking bsl module, cannot benull- Returns:
trueifmoduleallows using server call,falseotherwise
-
isGlobal
Checks that is global module- Parameters:
module- checking bsl module, cannot benull- Returns:
trueifmoduleis global module,falseotherwise
-
getTypeByName
Gets type by name for BSL element grammar- Parameters:
typeName- - type name, cannot benulltypeProvider- actualIEObjectProviderfor type, cannot benull- Returns:
- list of
TypeItemcorresponding totypeName, if type with nametypeNamenot found empty collection will be returned, nevernull
-
getSingleTypeByName
Gets type by name for BSL element grammar- Parameters:
typeName- type name, cannot benulltypeProvider- actualIEObjectProviderfor type, cannot benull- Returns:
- type corresponding to
typeName, ornullif there is no corresponding type fortypeName
-
hasMethodClientDirective
Checks thatMethodhas clients directive- Parameters:
method- checking method, cannot benull- Returns:
trueifMethodhas clients directive,falseotherwise
-
hasMethodServerDirective
Checks thatMethodhas server directive- Parameters:
method- checking method, cannot benull- Returns:
trueifMethodhas server directive,falseotherwise
-
allMethods
public static List<Method> allMethods(ContextDef contextDef, Module module, INamingService namingService) 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 benullmodule- bsl module which contextDef will be used for replacing proxy ContextDef, cannot benullnamingService-INamingServiceservice reference. May not benull- Returns:
- all methods from context def, never
null
-
allProperties
public static List<Property> allProperties(ContextDef contextDef, Module module, INamingService namingService) 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 benullmodule- bsl module which contextDef will be used for replacing proxy ContextDef, cannot benullnamingService-INamingServiceservice reference. May not benull- Returns:
- all proeprties from context def, never
null
-
getRefContextDefs
public static List<ContextDef> getRefContextDefs(ContextDef contextDef, Module module, INamingService namingService) Gets all references context. Replace proxy contextDef of Bsl module to real contextDef of module- Parameters:
contextDef-ContextDeffor getting reference contextDefs, cannot benullmodule- bsl module which contextDef will be used for replacing proxy ContextDef, cannot benullnamingService-INamingServiceservice reference. May not 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 benullqualifiedNameProvider- theIQualifiedNameProviderservice, cannot benull
-
setModuleType
public static void setModuleType(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter) Computes module type by module qualified name- Parameters:
module- the module, cannot benullqualifiedNameFilePathConverter- theIQualifiedNameFilePathConverterservice, cannot benull
-
setModuleOwner
Computes module owner proxy- Parameters:
module- the module, cannot benullownerService- theIBslOwnerComputerServiceservice, cannot benull
-
computeModuleType
public static ModuleType computeModuleType(Module module, IQualifiedNameFilePathConverter qualifiedNameFilePathConverter) Computes module type- Parameters:
module-Module, cannot benullqualifiedNameFilePathConverter-IQualifiedNameFilePathConverter, cannot benull- Returns:
- computed module type or
nullif unknown module type was detected
-
computeModuleType
public static ModuleType computeModuleType(Module module, org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider) Computes module type- Parameters:
module-Moduleprovider-IQualifiedNameProvider- Returns:
- computed module type or
null
-
getDependMethodsTree
Gets allBlockdepending frommethod -
isBuildOperationResourceSet
public static boolean isBuildOperationResourceSet(org.eclipse.emf.ecore.resource.ResourceSet resourceSet) Checks thatResourceSetwas created in build operation- Parameters:
resourceSet- checkingResourceSet, cannot benull- Returns:
trueifResourceSetwas created in build operation,falseotherwise
-
getMethodSignatureLastNode
Gets lastINodecorresponding to the method signature- Parameters:
method- analyzingMethod, cannot benull- Returns:
- last
INodecorresponding to the method signature ornullif node was not found
-
isExternalModuleContextDef
public static boolean isExternalModuleContextDef(ContextDef refContextDef, Module module, INamingService namingService) Checks if the contextDef belongs to another module- Parameters:
refContextDef- Reference context def of a module. May not benullmodule- processingModulecannot benullnamingService-INamingServiceservice reference. May not benull- Returns:
- True if the contex belongs to another module comparing to a provided one
-
computeTypeNames
public static Collection<String> computeTypeNames(Collection<TypeItem> types, org.eclipse.emf.ecore.EObject context) Computes name of the each type from the specified collection.
Resulting collection contains for eachTypeItem- its name, see
McoreUtil.getTypeName(TypeItem) - its category name, see
McoreUtil.getTypeCategoryRu(TypeItem) - if
TypeItemisTypeSetthen resulting collection contains all names ofTypeinTypeSet - if
TypeItemisTypeSetthen resulting collection contains all names of parent types forTypeSet
- Parameters:
types- collection ofTypeItems for computing their names, cannot benullcontext- contextEObjectfor resolving proxy, cannot benull- Returns:
- collection without null or empty elements containing for each
TypeItemfrom the specified collection- its name, see
McoreUtil.getTypeName(TypeItem) - its category name, see
McoreUtil.getTypeCategoryRu(TypeItem) - if
TypeItemisTypeSetthen resulting collection contains all names ofTypeinTypeSet - if
TypeItemisTypeSetthen resulting collection contains all names of parent types forTypeSet
null - its name, see
- its name, see
-