package org.yinwang.rubysonar.types;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.yinwang.rubysonar.State;
import org.yinwang.rubysonar._;


public class ModuleType extends Type {

    @NotNull
    public String name;
    @Nullable
    public String qname;


    public ModuleType(@NotNull String name, @Nullable String file, @NotNull State parent) {
        this.name = name;
        this.file = file;  // null for builtin modules
        if (file != null) {
            // This will return null iff specified file is not prefixed by
            // any path in the module search path -- i.e., the caller asked
            // the analyzer to load a file not in the search path.
            qname = _.moduleQname(file);
        }
        if (qname == null) {
            qname = name;
        }
        setTable(new State(parent, State.StateType.MODULE));
        table.setPath(qname);
        table.setType(this);
    }


    public void setName(String name) {
        this.name = name;
    }


    @Override
    public int hashCode() {
        return "ModuleType".hashCode();
    }


    @Override
    public boolean equals(Object other) {
        if (other instanceof ModuleType) {
            ModuleType co = (ModuleType) other;
            if (file != null) {
                return file.equals(co.file);
            }
        }
        return this == other;
    }


    @Override
    protected String printType(CyclicTypeRecorder ctr) {
        return name;
    }
}

@@ -156,40 +156,8 @@
 te;%0A
-import org.yinwang.rubysonar._;%0A
 %0A%0Apu
@@ -461,319 +461,73 @@
 if (
-file != null) %7B%0A            // This will return null iff specified file is not prefixed by%0A            // any path in the module search path -- i.e., the caller asked%0A            // the analyzer to load a file not in the search path.%0A            qname = _.moduleQname(file);%0A        %7D%0A        if (qname == null)
+parent.path.isEmpty()) %7B%0A            qname = name;%0A        %7D else
  %7B%0A 
@@ -536,32 +536,52 @@
          qname =
+ parent.path + %22/%22 +
  name;%0A        %7D

use ruby's global name space as qname/path