Class VariableDeclaration

    • Field Detail

      • name

        private java.lang.String name
      • isConstant

        private boolean isConstant
      • hasExplicitType

        private boolean hasExplicitType
      • modifiers

        private java.util.List<IModifier> modifiers
    • Constructor Detail

      • VariableDeclaration

        public VariableDeclaration​(java.lang.String name,
                                   TypeDescriptor<?> type)
        Creates a new variable declaration. Explicit type is assumed.
        Parameters:
        name - the name of the variable
        type - the type of the variable
        See Also:
        hasExplicitType()
      • VariableDeclaration

        public VariableDeclaration​(java.lang.String name,
                                   TypeDescriptor<?> type,
                                   boolean isConstant,
                                   Expression expression)
        Creates a new variable declaration. Explicit type is assumed.
        Parameters:
        name - the name of the variable
        type - the type of the variable
        isConstant - whether this variable is a constant
        expression - an expression denoting the initial value (may be null)
        See Also:
        hasExplicitType()
    • Method Detail

      • getName

        public java.lang.String getName()
        Get the name of this project element.
        Specified by:
        getName in interface IResolvable
        Returns:
        The name of this project element.
      • setIsConstant

        public void setIsConstant​(boolean isConstant)
        Define this variable as constant. By default, a variable is always not constant.
        Parameters:
        isConstant - true if this variable is a constant. False otherwise.
      • isConstant

        public boolean isConstant()
        Returns whether this variable is constant or not. By default, a variable is always not constant.
        Returns:
        True if this variable is a constant. False otherwise.
      • accept

        public java.lang.Object accept​(IVisitor visitor)
                                throws VilException
        Accepts the given visitor for visiting this instance.
        Parameters:
        visitor - the visitor
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • setHasExplicitType

        public void setHasExplicitType​(boolean hasExplicitType)
        Changes the formatting hint whether this declaration has an explicit type.
        Parameters:
        hasExplicitType - the new status of the formatting hint
      • hasExplicitType

        public boolean hasExplicitType()
        Returns the formatting hint whether this declaration has an explicit type.
        Returns:
        whether this declaration has an explicit type
      • addModifier

        public void addModifier​(IModifier modifier)
        Adds the specified modifier.
        Parameters:
        modifier - the modifier to be added
      • getModifierCount

        public int getModifierCount()
        Description copied from interface: IModifierHolder
        Returns the number of modifiers.
        Specified by:
        getModifierCount in interface IModifierHolder
        Returns:
        the number of modifiers
      • getModifier

        public IModifier getModifier​(int index)
        Description copied from interface: IModifierHolder
        Returns the specified modifier.
        Specified by:
        getModifier in interface IModifierHolder
        Parameters:
        index - the 0-based index of the modifier to return
        Returns:
        the specified modifier
      • hasModifier

        public boolean hasModifier​(IModifier modifier)
        Description copied from interface: IModifierHolder
        Returns whether this variable declaration has a given modifier.
        Specified by:
        hasModifier in interface IModifierHolder
        Parameters:
        modifier - the modifier to search for
        Returns:
        true if this variable declaration has the modifier attached, false else
      • resolveOperation

        public void resolveOperation​(TypeDescriptor<?> type,
                                     IMetaOperation operation)
        Resolves a (temporary) initialization expression to a ResolvableOperationExpression ("function pointer").
        Parameters:
        type - the declared type (of the function pointer)
        operation - the resolved base operation
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isImplicit

        public boolean isImplicit()
        Returns whether this variable declaration is implicit.
        Returns:
        true for implicit, false else
      • mapDefaultedParameters

        public static <V extends VariableDeclaration> java.util.Map<java.lang.String,​V> mapDefaultedParameters​(java.util.Map<java.lang.String,​V> result,
                                                                                                                     V[] decls)
        Adds all parameters with default values to result. Creates result if it does not exist but is required for storing data.
        Type Parameters:
        V - the variable declaration type
        Parameters:
        result - the map to be modified
        decls - the declarations to be (conditionally) mapped
        Returns:
        result or a new map (only if needed)
      • getRequiredParameterCount

        public static <V extends VariableDeclaration> int getRequiredParameterCount​(java.util.Map<java.lang.String,​V> named,
                                                                                    V[] decls)
        Returns the number of required parameters.
        Type Parameters:
        V - the variable declaration type
        Parameters:
        named - the named parameters (may be null)
        decls - the declared parameters (may be null)
        Returns:
        the number of required parameters
      • getParameter

        public static <V extends VariableDeclaration> V getParameter​(java.util.Map<java.lang.String,​V> named,
                                                                     java.lang.String name,
                                                                     V[] params)
        Returns a named parameter.
        Type Parameters:
        V - the variable declaration type
        Parameters:
        named - the named parameters (may be null)
        name - the parameter name (may be null)
        params - all paraams (fallback, may be null)
        Returns:
        the requested parameter or null