Class BslUtil


  • public class BslUtil
    extends Object
    Common methods for BSL
    • Field Detail

      • TYPE_NAME

        public static final com.google.common.base.Function<TypeItem,​String> TYPE_NAME
        Special Function for transform list of TypeItem to string
      • TYPE_NAME_RU

        public static final com.google.common.base.Function<TypeItem,​String> TYPE_NAME_RU
        Special Function for transform list of TypeItem to string
      • TRANSFORMER_FORMAL_PARAM

        public static final com.google.common.base.Function<FormalParam,​String> TRANSFORMER_FORMAL_PARAM
        Special Function for transform list of FormalParam to string
      • TRANSFORMER_FORMAL_PARAM_WITH_DEF_VALUES

        public static final com.google.common.base.Function<FormalParam,​String> TRANSFORMER_FORMAL_PARAM_WITH_DEF_VALUES
        Special Function for transform list of FormalParam with default values to string
    • Constructor Detail

      • BslUtil

        public BslUtil()
    • 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 be null
        filePath - the file name to check, cannot be null
        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 of TypeItem to string
        Parameters:
        types - list of TypeItem
        Returns:
        corresponding string with name of TypeItem
      • 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 of TypeItem have common item
        Parameters:
        expectedTypes - expected collection of TypeItem, cannot be null
        realTypes - real collection of TypeItem, cannot be null
        context - EObject for resolving proxy checking types, cannot be null
        Returns:
        true if intersection was detected
      • transformToMapOfEvent

        public static Map<CaseInsensitiveString,​List<Event>> transformToMapOfEvent​(List<Event> events)
        Transforms list of Events to map for fast searching events by name
        Parameters:
        events - all events cannot be null
        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 the Event to special name for fast searching events by name
        Parameters:
        name - name of the Event
        mapEvents - special map contains (key - event name, value - list of corresponding events) cannot be null
        event - processing Event
      • 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 to TypeItem
        Parameters:
        typesName - list of types name, cannot be null
        scope - all available scope types, cannot be null
        qualifiedNameConverter - actual IQualifiedNameConverter, cannot be null
        Returns:
        collection of the TypeItem without null elements
      • installModuleEnvironments

        @Deprecated
        public static void installModuleEnvironments​(Module module,
                                                     org.eclipse.xtext.naming.IQualifiedNameProvider qualifiedNameProvider,
                                                     Version version,
                                                     IBslOwnerComputerService ownerComputerService,
                                                     boolean installIntoMethod)
        Deprecated.
        Installs Environments for Bsl Module and its elements
        Parameters:
        module - processing Module cannot be null
        qualifiedNameProvider - IQualifiedNameProvider
        ownerComputerService - IBslOwnerComputerService
        version - actual Version, cannot be null
        installIntoMethod - if true environments will be computed into method statements
      • getResolvedTypeByName

        public static Type getResolvedTypeByName​(org.eclipse.emf.ecore.resource.Resource resource,
                                                 String typeName)
        Gets Type by name
        Parameters:
        resource - resource for resolving, cannot be null
        typeName - type name, cannot be null
        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 name qName
        Parameters:
        scope - IScope
        qName - checking name, cannot be null
        envs - actual element Environments, cannot be null
        resourceUri - uri of the Bsl module resource, cannot be null
        Returns:
        true if element with name qName 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 name qName
        Parameters:
        scope - IScope
        qName - checking name
        Returns:
        true if element with name qName 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 module
        method - current method
        env - actual Environments
        scopeProvider - actual IScopeProvider
        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 module
        env - actual Environments
        scopeProvider - actual IScopeProvider
        Returns:
        found scope
      • findCommentAnnotatedObject

        public static org.eclipse.emf.ecore.EObject findCommentAnnotatedObject​(org.eclipse.emf.ecore.EObject source)
        Find object (Statement, DeclareStatement, Method or Preprocessor) for annotating by comment
        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 current ScriptVariant for the provided context BSL model object.
        Parameters:
        object - the context BSL model object, cannot be null
        v8projectManager - the IV8ProjectManager instance, cannot be null
        Returns:
        true if scriptVariant == 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 applies function to each element of fromCollection. The returned collection is a new collection
        Parameters:
        fromCollection - source collection with elements for transformation, cannot be null
        function - function for transformation elements from source collection, cannot be null
        Returns:
        return new collection with transformed elements from source collection, never null
      • 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 be null
        block - actual Block for semantic object, cannot be null
        dynamicComputer - actual DynamicFeatureAccessComputer, cannot be null
        ownerComputerService - actual IBslOwnerComputerService, cannot be null
        mockMethodsAllowed - true if allowed for FeatureEntry.getFeature() return mock of exported user methods. Mock exported user methods is special Method 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, never null
      • isCallFromClient

        public static boolean isCallFromClient​(org.eclipse.emf.ecore.EObject feature,
                                               Invocation inv)
        Checks that object feature is calling from clients environments
        Parameters:
        feature - checking object, cannot be null
        inv - actual semantic grammar element from Bsl language model, cannot be null
        Returns:
        true object feature is calling from clients environments, false otherwise
      • isServerCall

        public static boolean isServerCall​(Module module)
        Checks that module allows using server call
        Parameters:
        module - checking bsl module, cannot be null
        Returns:
        true if module allows using server call, false otherwise
      • isGlobal

        public static boolean isGlobal​(Module module)
        Checks that is global module
        Parameters:
        module - checking bsl module, cannot be null
        Returns:
        true if module 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 be null
        typeProvider - actual IEObjectProvider for type, cannot be null
        Returns:
        list of TypeItem corresponding to typeName, if type with name typeName not found empty collection will be returned, never null
      • getSingleTypeByName

        public static TypeItem getSingleTypeByName​(String typeName,
                                                   IEObjectProvider typeProvider)
        Gets type by name for BSL element grammar
        Parameters:
        typeName - type name, cannot be null
        typeProvider - actual IEObjectProvider for type, cannot be null
        Returns:
        type corresponding to typeName, or null if there is no corresponding type for typeName
      • hasMethodClientDirective

        public static boolean hasMethodClientDirective​(Method method)
        Checks that Method has clients directive
        Parameters:
        method - checking method, cannot be null
        Returns:
        true if Method has clients directive, false otherwise
      • hasMethodServerDirective

        public static boolean hasMethodServerDirective​(Method method)
        Checks that Method has server directive
        Parameters:
        method - checking method, cannot be null
        Returns:
        true if Method has server directive, false otherwise
      • allMethods

        public static List<Method> allMethods​(ContextDef contextDef,
                                              Module module)
        More faster implementation of ContextDef.allMethods() with replacing proxy reference contextDef for bsl module to real its contextDef
        Parameters:
        contextDef - actual context def for getting all methods, cannot be null
        module - bsl module which contextDef will be used for replacing proxy ContextDef, cannot be null
        Returns:
        all methods from context def, never null
      • allProperties

        public static List<Property> allProperties​(ContextDef contextDef,
                                                   Module module)
        More faster implementation of ContextDef.allProperties() with replacing proxy reference contextDef for bsl module to real its contextDef
        Parameters:
        contextDef - actual context def for getting all properties, cannot be null
        module - bsl module which contextDef will be used for replacing proxy ContextDef, cannot be null
        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 be null
        module - bsl module which contextDef will be used for replacing proxy ContextDef, cannot be null
        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 be null
        qualifiedNameProvider - the IQualifiedNameProvider service, cannot be null
      • 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 all Block depending from method
        Parameters:
        method - Method for getting Block depends from it, cannot be null
        Returns:
        all Block depending from method, never null
      • isBuildOperationResourceSet

        public static boolean isBuildOperationResourceSet​(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
        Checks that ResourceSet was created in build operation
        Parameters:
        resourceSet - checking ResourceSet, cannot be null
        Returns:
        true if ResourceSet was created in build operation, false otherwise