Package ro.redeul.google.go.lang.psi.typing

Source Code of ro.redeul.google.go.lang.psi.typing.GoTypeInterface

package ro.redeul.google.go.lang.psi.typing;

import ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration;
import ro.redeul.google.go.lang.psi.types.GoPsiTypeInterface;

import java.util.HashMap;
import java.util.Map;

public class GoTypeInterface extends GoTypePsiBacked<GoPsiTypeInterface> implements GoType {

    public GoTypeInterface(GoPsiTypeInterface psiType) {
        super(psiType);
    }

    @Override
    public boolean isIdentical(GoType type) {
        if ( !(type instanceof GoTypeInterface) )
            return false;

        GoTypeInterface other = (GoTypeInterface) type;

        Map<String, GoType> myMethodTypes = getMethodSetTypes();
        Map<String, GoType> otherMethodTypes = other.getMethodSetTypes();

        for (Map.Entry<String, GoType> entry : myMethodTypes.entrySet()) {
            if (!(otherMethodTypes.containsKey(entry.getKey())))
                return false;

            if (!entry.getValue().isIdentical(otherMethodTypes.get(entry.getKey())))
                return false;

            otherMethodTypes.remove(entry.getKey());
        }

        return otherMethodTypes.size() == 0 ;
    }

    protected Map<String, GoType> getMethodSetTypes() {
        GoFunctionDeclaration functions[] = getPsiType().getMethodSet();

        Map<String, GoType> methodsMap = new HashMap<String, GoType>();
        for (GoFunctionDeclaration function : functions) {
            GoType methodType = types().fromPsiType(function);
            if (methodType instanceof GoTypeFunction)
                methodsMap.put(function.getName(), methodType);
        }

        return methodsMap;
    }

    @Override
    public <T> T accept(TypeVisitor<T> visitor) {
        return visitor.visitInterface(this);
    }

    @Override
    public String toString() {
        return "interface{ /* ... */ }";
    }
}
TOP

Related Classes of ro.redeul.google.go.lang.psi.typing.GoTypeInterface

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.