• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] vJass create method problems

Status
Not open for further replies.

crl

crl

Level 7
Joined
Mar 29, 2008
Messages
117
Hi! I'm trying to learn vJass (without knowing much jass, but i think i got most of it). The problem is that i can not get the vJass compiler to compile my scripts. I'm using JassHelper version 0.9.1.2. The error message is: "Line 123: method create must return AbstractStringListIterator".

The code that contains the problem:

JASS:
   struct Abstract$NAME$ListIterator extends $NAME$Iterator
        
        private integer modcount
        
        private Abstract$TYPE$List list = 0
        private integer index = 0
        
        public static method create takes Abstract$NAME$List returns thistype 
            local thistype iter = thistype.allocate()
            set iter.list = list
            set iter.modcount = list.getModCount()
            return iter
        endmethod
        ...
    endstruct

Full code:

JASS:
library Collections
    
    globals
        constant integer ARRAY_LIST_MAX = 8190
        
        constant string ERROR_LIST_FULL = "List is full"
        constant string ERROR_HIGH_INDEX = "Index is out of bounds"
    endglobals
    
    //! textmacro Collections takes TYPE, NAME, NONE
    struct $NAME$Iterator
        
        public stub method next takes nothing returns $TYPE$
            return $NONE$
        endmethod
        public method hasNext takes nothing returns boolean
            return false
        endmethod
        public method remove takes nothing returns $TYPE$ //note: return = removed value (aka current)
            return $NONE$
        endmethod
        
    endstruct
    
    struct $NAME$Iterable
        
        public stub method iterator takes nothing returns $TYPE$Iterator
            return 0
        endmethod
        
    endstruct
    
    struct $NAME$Collection extends $NAME$Iterable
        
        // ----- MUTATERS -----
        
        public stub method add takes $TYPE$ value returns boolean
            return false
        endmethod
        
        public stub method addAll takes $TYPE$Collection values returns boolean
            return false
        endmethod
        public stub method retainAll takes $TYPE$Collection values returns boolean
            return false
        endmethod
        
        public stub method remove takes $TYPE$ value returns boolean
            return false
        endmethod
        
        public stub method replace takes $TYPE$ old, $TYPE$ new returns boolean
            return false
        endmethod
        
        // ----- ACCESERS -----
        
        public stub method contains takes $TYPE$ value returns boolean
            return false
        endmethod
        
        public stub method isEmpty takes nothing returns boolean
            return false
        endmethod
        
    endstruct
    
    struct $NAME$Set extends $NAME$Collection
    endstruct
    
    struct $NAME$List extends $NAME$Collection //0-oriented (starts from zero)
        
        // ----- MUTATERS -----
        
        public stub method insert takes $TYPE$ value, integer index returns boolean
            return false
        endmethod
        
        public stub method removeAt takes integer index returns boolean
            return false
        endmethod
        
        public stub method replaceAt takes integer index, $TYPE$ new returns boolean
            return false
        endmethod
        public method operator []= takes integer index, $TYPE$ new returns boolean 
            return replaceAt(index, new)
        endmethod
        
        // ----- ACCESERS -----
        
        public stub method get takes integer index returns $TYPE$
            return false
        endmethod
        public method operator [] takes integer index returns boolean
            return get(index)
        endmethod
        
        public stub method operator length takes nothing returns integer
            return 0
        endmethod
        
        public stub method indexOf takes $TYPE$ value returns integer
            return -1
        endmethod
        
    endstruct
    
    struct Abstract$NAME$ListIterator extends $NAME$Iterator
        
        private integer modcount
        
        private Abstract$TYPE$List list = 0
        private integer index = 0
        
        public static method create takes Abstract$NAME$List returns thistype 
            local thistype iter = thistype.allocate()
            set iter.list = list
            set iter.modcount = list.getModCount()
            return iter
        endmethod
        
        public static method next takes nothing returns $TYPE$
            if(modcount != list.getModCount) then
                return $NONE$
            endif
            local $TYPE$ val = list[index]
            set index = index + 1
            return val
        endmethod
        public static method hasNext takes nothing returns boolean
            if(modcount != list.getModCount) then
                return false
            endif
            return index < list.length
        endmethod
        public static method remove takes nothing returns $TYPE$
            local $TYPE$ val
            if(modcount != list.getModCount) then
                return false
            endif
            set val = list.get(index)
            set modcount = modcount + 1
            call list.removeAt(index)
            return val
        endmethod
        
    endstruct
    struct Abstract$NAME$List extends $NAME$List
        
        private integer modcount;
        
        method increaseModCount takes nothing returns nothing
            set modcount = modcount + 1
        endmethod
        method getModCount takes nothing returns integer
            return modcount
        endmethod
        
        public method iterator takes nothing returns $NAME$Iterator
            return Abstract$NAME$ListIterator.create(this)
        endmethod
        
        // ----- MUTATERS -----
        
        public stub method add takes $TYPE$ value returns boolean
            return false
        endmethod
        public stub method insert takes $TYPE$ value, integer index returns boolean
            return false
        endmethod
        
        public stub method addAll takes $TYPE$Collection values returns boolean
            return false
        endmethod
        public stub method retainAll takes $TYPE$Collection values returns boolean
            return false
        endmethod
        
        public stub method remove takes $TYPE$ value returns boolean
            return false
        endmethod
        public stub method removeAt takes integer index returns boolean
            return false
        endmethod
        
        public stub method replace takes $TYPE$ old, $TYPE$ new returns boolean
            return false
        endmethod
        public stub method replaceAt takes integer index, $TYPE$ new returns boolean
            return false
        endmethod
        
        // ----- ACCESERS -----
        
        public stub method get takes integer index returns $TYPE$
            return $NONE$
        endmethod
        
        public stub method indexOf takes $TYPE$ value returns integer
            return 0
        endmethod
        public stub method contains takes $TYPE$ value returns boolean
            return false
        endmethod
        
        public stub method isEmpty takes nothing returns boolean
            return false
        endmethod
        
    endstruct
    
    type $NAME$ArrayListArray extends $TYPE$ array[ARRAY_LIST_MAX]
    
    struct $NAME$ArrayList extends Abstract$NAME$List
        
        private $NAME$ArrayListArray list
        private integer count
        
        public static method create takes nothing returns $NAME$ArrayList
            local $NAME$ArrayList list = $NAME$ArrayList.allocate()
            list.list = $NAME$ArrayListArray.create()
            list.count = 0
            return list
        endmethod
        
        // ----- MUTATERS -----
        
        public method add takes $TYPE$ value returns boolean
            if(count >= ARRAY_LIST_MAX) then
                call debugMessage(ERROR_LIST_FULL)
                return false
            endif
            set count = count + 1
            set list[count] = value
            return true
        endmethod
        public method insert takes $TYPE$ value, integer index returns boolean
            set index = index + 1
            local $TYPE$ tmp
            local integer pos
            if(index > count) then
                call debugMessage(ERROR_HIGH_INDEX)
                return false
            endif
            if(count >= ARRAY_LIST_MAX) then
                call debugMessage(ERROR_LIST_FULL)
                return false
            endif
            set pos = count
            loop
                exitwhen(pos < index)
                set list[pos + 1] = list[pos]
                set pos = pos + 1
            endloop
            set list[index] = value
            set count = count + 1
            return true
        endmethod
        
        public stub method addAll takes $TYPE$Collection values returns boolean
            return false //TODO
        endmethod
        public stub method retainAll takes $TYPE$Collection values returns boolean
            return false //TODO
        endmethod
        
        public method remove takes $TYPE$ value returns boolean
            local integer pos
            local boolean changed
            if(count == 0) then //speed
                return false
            endif
            set pos = 1
            set changed = false
            loop
                exitwhen (pos > count)
                if (list[pos] == value) then
                    set changed = true
                    local pos0
                    set pos0 = count
                    loop
                        exitwhen(pos0 < pos)
                        set list[pos0] = list[pos0 + 1]
                        set pos0 = pos0 + 1
                    endloop
                    set count = count - 1
                endif
                set pos = pos + 1
            endloop
            return changed
        endmethod
        public method removeAt takes integer index returns boolean
            set index = index + 1
            if(index  + 1 > count) then
                call debugMessage(ERROR_HIGH_INDEX)
                return false
            endif
            set pos = index
            loop
                exitwhen(pos >= count)
                set list[pos] = list[pos + 1]
                set pos = pos + 1
            endloop
            set count = count - 1
            return true
        endmethod
        
        public method replace takes $TYPE$ old, $TYPE$ new returns boolean
            local integer pos
            local boolean changed
            if(count == 0) then //speed
                return false
            endif
            set pos = 1
            set changed = false
            loop
                exitwhen(pos > count)
                if(list[pos] == old) then
                    set list[pos] = new
                    set changed = true
                endif
                set pos = pos + 1
            endloop
            return changed
        endmethod
        public method replaceAt takes integer index, $TYPE$ new returns boolean
            set index = index + 1
            if(index > count) then
                call debugMessage(ERROR_HIGH_INDEX)
                return false
            endif
            set list[index] = new
            return true
        endmethod
        
        // ----- ACCESERS -----
        
        public method get takes integer index returns $TYPE$
            set index = index + 1
            if(index > count) then
                call debugMessage(ERROR_HIGH_INDEX)
                return $NONE$
            endif
            return list[index]
        endmethod
        
        public method indexOf takes $TYPE$ value returns integer
            local integer pos
            local integer res
            if(count == 0) then
                return -1
            endif
            set pos = 1
            set res = -1
            loop
                exitwhen((pos > count) or (res != -1))
                if(list[pos] == value) then
                    set res = pos
                endif
                set pos = pos + 1
            endloop
            return res
        endmethod
        public method contains takes $TYPE$ value returns boolean
            return indexOf(value) > 0
        endmethod
        
        public method isEmpty takes nothing returns boolean
            return count == 0
        endmethod
        
        public method operator length takes nothing returns integer
            return count
        endmethod
        
    endstruct
    //! endtextmacro
    
    //! runtextmacro Collections("string", "String", "0")
    
endlibrary


By the way, i have tried using Abstract$NAME$ListIterator instead of thistype.

Thanks (and +rep (if i can), ofc) for helping me.
 
Last edited:
Status
Not open for further replies.
Top