 
    Can be used to go from XCut types to weaver world types." 
   [?world ?signature ?resolved-type]
-  (equals ?resolved-type (.lookupBySignature ?world ?signature)))
+  (equals ?resolved-type (.resolve ?world ?signature)))
+
+
+(defn
+  element-type
+  "Relation between a ProgramElement of kind Aspect/Enum/Class
+   and the ResolvedType instance from the weaver world it corresponds to."
+  [?element ?type]
+  (fresh [?world ?signature]
+         (elementtypedeclaration ?element)
+         (element-signature ?element ?signature)
+         (weaverworld ?world) ;todo: go straight from element to correct weaverworld (see weaverworld-model-hierarchy)
+         (weaverworld-signature-resolvedtype ?world ?signature ?type)))
+
+
 
 
 (defn

    (element ?element)
    (equals ?kind (.getKind ?element))))

(defn
  element-signature
  "Relation between a ProgramElement and its signature string."




(defn-
  ancestors-of-element
  "Returns the ancestor chain of the given ProgramElement.
   First element is the immediate parent."
  ([element] 
    (ancestors-of-element (.getParent element) []))
  ([parent sofar]
    (if-not
      (nil? parent)
      (recur (.getParent parent) (conj sofar parent))
      sofar)))

(defn-
  enclosingtypedeclaration-of-element
  "Returns the most enclosing class, aspect or enum declaration
   in which the given ProgramElement resides."
  [element] 
  (letfn [(typedeclaration? 
            [element]
            (let [kind (.getKind element)]
              (or (= kind (IProgramElement$Kind/CLASS))
                  (= kind (IProgramElement$Kind/ENUM))
                  (= kind (IProgramElement$Kind/ASPECT)))))
          (ancestortypedeclaration 
            [parent]
            (if-not
              (nil? parent)
              (if 
                (typedeclaration? parent)
                parent
                (recur (.getParent parent)))))]
         (ancestortypedeclaration (.getParent element))))
    
(defn
  element-enclosingtypedeclaration-element
  "Relation between a ProgramElement and its enclosing aspect (if any)."
  [?element ?typedeclaration]
  (all
    (element ?element)
    (equals ?typedeclaration (enclosingtypedeclaration-of-element ?element))
    (!= nil ?typedeclaration)))

(defn
  elementaspect
  [?element]
  (all
    (element ?element)
    (equals (IProgramElement$Kind/ASPECT) (.getKind ?element))))

(defn
  elementclass
  [?element]
  (all
    (element ?element)
    (equals (IProgramElement$Kind/CLASS) (.getKind ?element))))

(defn
  elementenum
  [?element]
  (all
    (element ?element)
    (equals (IProgramElement$Kind/ENUM) (.getKind ?element))))

(defn
  elementtypedeclaration
  [?element]
  (conde
    [(elementenum ?element)]
    [(elementclass ?element)]
    [(elementaspect ?element)]))

    



