001    package org.mesopotamia.lang.java;
002    
003    import java.util.ArrayList;
004    import java.util.List;
005    
006    import org.mesopotamia.MesopotamiaException;
007    import org.mesopotamia.NodeData;
008    import org.mesopotamia.RepositoryLanguage;
009    import org.mesopotamia.Scan;
010    import org.mesopotamia.lang.java.ref.MethodInfo;
011    import org.mesopotamia.lang.java.ref.Scope;
012    import org.mesopotamia.lang.java.ref.TypeInfo;
013    import org.mesopotamia.lang.java.ref.VariableInfo;
014    import org.w3c.dom.Element;
015    
016    import biz.hammurapi.util.Visitor;
017    
018    public class InterfaceDefinition extends ClassOrInterfaceDefinition {
019    
020            public InterfaceDefinition(NodeData xData, Class<?> context, Scan scan,
021                            RepositoryLanguage language, Object environment) throws MesopotamiaException {
022                    super(xData, context, scan, language, environment);
023    
024                    // Select attributes
025                    
026                    for(Identifier ext: select(Identifier.class, "EXTENDS_CLAUSE/*")) {
027                            Extends.add(ext.getPath());
028                    }
029    
030            }
031    
032            public void toDom(Element holder) {
033                    super.toDom(holder);
034    
035                    // Serialize attributes
036                    setElement(holder, "Extends", Extends);
037            }
038    
039            // Attributes
040            private List<String> Extends = new ArrayList<String>();
041    
042            // Accessors
043            public List<String> getExtends() {
044                    return Extends;
045            }
046    
047            protected void acceptChildren(Visitor visitor) {
048                    super.acceptChildren(visitor);
049                    // Visiting non-text attributes
050            }
051            
052            @Override
053            protected boolean isKindOfInternal(String superFcn) {
054                    if (super.isKindOfInternal(superFcn)) {
055                            return true;
056                    }
057                    
058                    Scope scope = getEnclosingScope();
059                    if (scope!=null) {
060                            for (String si: getExtends()) {
061                                    TypeInfo sti = scope.findType(si);
062                                    if (sti!=null && sti.isKindOf(superFcn)) {
063                                            return true;
064                                    }
065                            }
066                    }
067                    
068                    return false;
069            }
070    
071    
072            @Override
073            protected TypeInfo findNestedTypeInternal(String name) {
074                    TypeInfo ret = super.findNestedTypeInternal(name);
075                    if (ret!=null) {
076                            return ret;
077                    }
078                    
079                    Scope ec = getEnclosingScope();
080                    if (ec!=null) {                 
081                            for (String cInterface: getExtends()) {
082                                    TypeInfo spr = ec.findType(cInterface);
083                                    if (spr!=null) {
084                                            ret = spr.findNestedType(name);
085                                            if (ret!=null) {
086                                                    return ret;
087                                            }
088                                    }
089                            }
090                    }
091                    return null;
092            }
093            
094            @Override
095            protected MethodInfo findTypeMethodInternal(String name, String[] parameterTypes) {
096                    MethodInfo candidate = super.findTypeMethodInternal(name, parameterTypes);
097                    
098                    Scope ec = getEnclosingScope();
099                    if (ec!=null) {
100                            for (String cInterface: getExtends()) {
101                                    TypeInfo spr = ec.findType(cInterface);
102                                    if (spr!=null) {
103                                            candidate = selectMoreSpecific(candidate, spr.findTypeMethod(name, parameterTypes));
104                                    }
105                            }
106                    }
107                    return candidate;
108            }
109            
110            @Override
111            protected VariableInfo findTypeVariableInternal(String name) {
112                    VariableInfo ret = super.findTypeVariableInternal(name);
113                    if (ret!=null) {
114                            return ret;
115                    }
116                    
117                    Scope ec = getEnclosingScope();
118                    if (ec!=null) {
119                            for (String cInterface: getExtends()) {
120                                    TypeInfo spr = ec.findType(cInterface);
121                                    if (spr!=null) {
122                                            ret = spr.findTypeVariable(name);
123                                            if (ret!=null) {
124                                                    return ret;
125                                            }
126                                    }
127                            }
128                    }
129                    return null;
130            }
131    }