Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: cderoove/damp.ekeko
base: f82fb40d61
...
head fork: cderoove/damp.ekeko
compare: e9885ff554
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
BIN  EkekoPlugin/libs/core.logic-0.8.0-beta5.jar
Binary file not shown
View
61 EkekoPlugin/src/damp/ekeko/jdt/reification.clj
@@ -288,19 +288,6 @@
(ast :Type ?type) ;above trick is not necessary as Type is an actual super class
(ast ?key ?type)))
-(defn
- ast-name-of-parameter
- "Like ast/2, but ensures ?name is the SimpleName
- of a formal parameter declaration."
- [?keyw ?name]
- (fresh [?nameBinding ?parent]
- (== ?keyw :SimpleName)
- (ast ?keyw ?name)
- (equals ?nameBinding (.resolveBinding ^SimpleName ?name))
- (succeeds (.isParameter ^IVariableBinding ?nameBinding))
- (ast-parent ?name ?parent)
- (ast :SingleVariableDeclaration ?parent)))
-
(defn
ast-resolveable-declaration
@@ -336,17 +323,7 @@
]))
-(defn
- ast-expression-typebinding
- "Relation between an Expression instance ?ast,
- the keyword ?key representing its kind,
- and the ITypeBinding ?binding for its type."
- [?key ?ast ?binding]
- (all
- (ast :Expression ?ast)
- (equals ?binding (.resolveTypeBinding ^Expression ?ast))
- (!= nil ?binding)
- (ast ?key ?ast)))
+(declare ast-expression-typebinding)
(defn
ast-expression-reference
@@ -358,9 +335,36 @@
(succeeds (not (.isPrimitive ^ITypeBinding ?binding)))))
+(defn
+ ast-name-of-parameter
+ "Like ast/2, but ensures ?name is the SimpleName
+ of a formal parameter declaration."
+ [?keyw ?name]
+ (fresh [?nameBinding ?parent]
+ (== ?keyw :SimpleName)
+ (ast ?keyw ?name)
+ (equals ?nameBinding (.resolveBinding ^SimpleName ?name))
+ (succeeds (.isParameter ^IVariableBinding ?nameBinding))
+ (ast-parent ?name ?parent)
+ (ast :SingleVariableDeclaration ?parent)))
+
+
;; Bindings
;; --------
+(defn
+ ast-expression-typebinding
+ "Relation between an Expression instance ?ast,
+ the keyword ?key representing its kind,
+ and the ITypeBinding ?binding for its type."
+ [?key ?ast ?binding]
+ (all
+ (ast :Expression ?ast)
+ (equals ?binding (.resolveTypeBinding ^Expression ?ast))
+ (!= nil ?binding)
+ (ast ?key ?ast)))
+
+
(defn
ast-type-binding
"Relation between a type ASTNode ?type, the keyword ?key
@@ -385,9 +389,10 @@
See also:
API documentation of org.eclipse.jdt.core.dom.TypeDeclaration
and org.eclipse.jdt.core.dom.ITypeBinding"
- [?typeDeclaration ?binding]
+ [?key ?typeDeclaration ?binding]
(all
- (ast :TypeDeclaration ?typeDeclaration)
+ (== ?key :TypeDeclaration)
+ (ast ?key ?typeDeclaration)
(!= nil ?binding)
(equals ?binding (.resolveBinding ^TypeDeclaration ?typeDeclaration))))
@@ -427,9 +432,9 @@
Note that this relation is quite slow to compute.
See also:
- binary predicate ast-typedeclaration-binding/2
+ ternary predicate ast-typedeclaration-binding/3
which restricts ?n to TypeDeclaration instances"
- [?n ?key ?binding]
+ [?key ?n ?binding]
(all
(!= ?binding nil)
(!= ?n nil)
View
6 EkekoPlugin/src/damp/ekeko/logic.clj
@@ -3,7 +3,7 @@
:author "Coen De Roover"}
damp.ekeko.logic
(:refer-clojure :exclude [==])
- (:use [clojure.core.logic]))
+ (:use [clojure.core.logic]))
(defn-
ekeko-lvar-sym?
@@ -89,13 +89,13 @@
v+
"Non-relational. Verifies that logic variable v is ground."
[v]
- `(project [~v] (succeeds (not (lvar? ~v)))))
+ `(nonlvaro ~v))
(defmacro
v-
"Non-relational. Verifies that logic variable v is not ground."
[v]
- `(project [~v] (succeeds (lvar? ~v))))
+ `(lvaro ~v))
(defmacro
View
21 EkekoPlugin/test/test/damp/ekeko.clj
@@ -1,8 +1,8 @@
(ns test.damp.ekeko
(:refer-clojure :exclude [== type declare])
- (:use [clojure.core.logic :exclude [is]] :reload)
- (:require [damp.ekeko])
(:require
+ [clojure.core.logic :exclude [is] :as l]
+ [damp.ekeko]
[damp.ekeko.workspace
[workspace :as ws]]
[damp.ekeko.soot
@@ -111,6 +111,17 @@
(is (seq tuples2))
(is (count tuples1) (count tuples2))
(tuples-are tuples1 tuples2))
+
+(defn
+ tuples-aresubset
+ "Verifies whether all elements from its first argument sequence are
+ included in its second argument sequence (both obtained as solutions to an Ekeko query)."
+ [tuples1 tuples2]
+ (is
+ (clojure.set/subset? (into #{} tuples1)
+ (into #{} tuples2))))
+
+
@@ -122,11 +133,11 @@
(deftest
test-ekeko
(tuples-correspond
- (damp.ekeko/ekeko [?x ?y] (== ?x 1) (== ?y 2))
+ (damp.ekeko/ekeko [?x ?y] (l/== ?x 1) (l/== ?y 2))
"#{(\"1\" \"2\")}") ;string obtained through (tuples-to-stringsetstring (damp.ekeko/ekeko [?x ?y] (== ?x 1) (== ?y 2)))
(tuples-are
- (damp.ekeko/ekeko [?x ?y] (== ?x 1) (== ?y 2))
- (damp.ekeko/ekeko [?x ?y] (== ?x 1) (== ?y 2))))
+ (damp.ekeko/ekeko [?x ?y] (l/== ?x 1) (l/== ?y 2))
+ (damp.ekeko/ekeko [?x ?y] (l/== ?x 1) (l/== ?y 2))))
;; Test Suite
View
226 EkekoPlugin/test/test/damp/ekeko/jdt.clj
@@ -3,15 +3,18 @@
:author "Coen De Roover"}
test.damp.ekeko.jdt
(:refer-clojure :exclude [== type declare])
- (:use [clojure.core.logic :exclude [is]] :reload)
- (:use [damp.ekeko logic])
- (:use clojure.test)
- (:require [test.damp [ekeko :as test]]
- [damp.ekeko.jdt
- [astnode :as astnode]
- [reification :as reification]]))
+ (:require
+ [clojure.core.logic :exclude [is] :as l]
+ [test.damp [ekeko :as test]]
+ [damp.ekeko [logic :as logic]]
+ [damp.ekeko.jdt
+ [astnode :as astnode]
+ [reification :as reification]
+ [basic :as basic]])
+ (:use clojure.test))
-;; Tests
+
+;; AST Tests
(deftest
reification-ast
@@ -30,7 +33,7 @@
reification-has-relational
(doseq [[node property child shouldbenode shouldbeproperty]
(damp.ekeko/ekeko [?node ?property ?child ?shouldbenode ?shouldbeproperty]
- (fresh [?kind]
+ (l/fresh [?kind]
(reification/ast ?kind ?node)
(reification/has ?property ?node ?child)
(reification/has ?shouldbeproperty ?shouldbenode ?child)))]
@@ -44,13 +47,14 @@
reification-ast-child+
(test/tuples-are
(damp.ekeko/ekeko [?ast]
- (fresh [?kind]
- (reification/ast ?kind ?ast)))
+ (l/fresh [?kind]
+ (reification/ast ?kind ?ast)))
(damp.ekeko/ekeko [?ast]
- (fresh [?cu]
- (reification/ast :CompilationUnit ?cu)
- (conde [(== ?cu ?ast)]
- [(reification/child+ ?cu ?ast)])))))
+ (l/fresh [?cu]
+ (reification/ast :CompilationUnit ?cu)
+ (l/conde
+ [(clojure.core.logic/== ?cu ?ast)]
+ [(reification/child+ ?cu ?ast)])))))
(deftest
reification-value
@@ -65,6 +69,148 @@
(valpred ?val)
(valpred ?val)))))
+
+
+(deftest
+ reification-child-parent
+ ^{:doc "Tests relation between child/3 and parent/2."}
+ (doseq
+ [[node child parent]
+ (damp.ekeko/ekeko [?node ?child ?parent]
+ (l/fresh [?kind ?property]
+ (reification/ast ?kind ?node)
+ (reification/child ?property ?node ?child)
+ (reification/ast-parent ?child ?parent)))]
+ (is (identical? node parent))))
+
+
+(deftest
+ reification-ast-specialkinds
+ ^{:doc "Tests relational nature of ast/resolvable/2"}
+ (doseq [valpred [reification/ast-resolveable
+ reification/ast-declaration
+ reification/ast-fieldaccess
+ reification/ast-type
+ reification/ast-resolveable-declaration
+ reification/ast-invocation
+ reification/ast-expression-reference
+ reification/ast-name-of-parameter
+ ]]
+ (test/tuples-are
+ (damp.ekeko/ekeko [?val]
+ (l/fresh [?kind]
+ (valpred ?kind ?val)))
+ (damp.ekeko/ekeko [?val]
+ (l/fresh [?kind]
+ (valpred ?kind ?val)
+ (valpred ?kind ?val))))))
+
+(deftest
+ reification-ast-subnodekinds
+ ^{:doc "Tests whether ast/2 supports AST nodes of non-leaf kinds (non-exhaustive)."}
+ (doseq [[subkind kind]
+ [[:SingleVariableDeclaration :VariableDeclaration]
+ [:VariableDeclarationFragment :VariableDeclaration]
+ [:ReturnStatement :Statement]
+ [:SimpleType :Type]]]
+ (test/tuples-aresubset
+ (damp.ekeko/ekeko [?ast] (reification/ast subkind ?ast))
+ (damp.ekeko/ekeko [?ast] (reification/ast kind ?ast)))))
+
+
+
+
+;; IBinding tests
+
+
+(deftest
+ reification-ast-bindings
+ ^{:doc "Simply tests whether binding-related ternary predicates execute without exception-free."}
+ (doseq [bindingpred [reification/ast-expression-typebinding
+ reification/ast-type-binding
+ reification/ast-fieldaccess-binding
+ reification/ast-invocation-binding
+ reification/ast-typedeclaration-binding
+ reification/ast-declares-binding
+ ]]
+ (doseq [[binding] (damp.ekeko/ekeko [?binding]
+ (l/fresh [?kind ?ast]
+ (bindingpred ?kind ?ast ?binding)))]
+ (is (instance? org.eclipse.jdt.core.dom.IBinding binding)))))
+
+
+
+;; Java Model Tests
+
+(deftest
+ reification-modelunaries
+ ^{:doc "Tests that unary Java model reification predicates do not throw
+ an exception (testing whether they are relational takes a long time)."}
+ (doseq [modelpred [reification/packagefragmentroot
+ reification/packagefragmentroot-from-binary
+ reification/packagefragmentroot-from-source
+ reification/packagefragment
+ reification/classfile
+ reification/compilationunit
+ reification/type
+ reification/type-from-binary
+ reification/type-from-source
+ reification/initializer
+ reification/method
+ reification/method-from-source
+ reification/method-from-binary
+ reification/field
+ reification/field-from-source
+ reification/field-from-binary
+ ]]
+ (damp.ekeko/ekeko [?t] (modelpred ?t))))
+
+
+(deftest
+ reification-modelelement
+ ^{:doc "Tests relational nature of element/1."}
+ (test/tuples-are
+ (damp.ekeko/ekeko [?k ?e]
+ (reification/element ?k ?e))
+ (damp.ekeko/ekeko [?k ?e]
+ (reification/element ?k ?e)
+ (reification/element ?k ?e))))
+
+
+;; Basic relations
+
+(deftest
+ basic-ast-location
+ ^{:doc "Superficial test for ast-location/2."}
+ (is (< 0 (count (damp.ekeko/ekeko [?ast ?locv] (basic/ast-location ?ast ?locv))))))
+
+(deftest
+ basic-ast-encompassing-typedeclaration
+ ^{:doc "Superficial test for ast-encompassing-typedeclaration/2."}
+ (is (= 285 (count (damp.ekeko/ekeko [?ast ?typedec] (basic/ast-encompassing-typedeclaration ?ast ?typedec))))))
+
+(deftest
+ basic-ast-encompassing-methoddeclaration
+ ^{:doc "Superficial test for ast-encompassing-method/2."}
+ (is (= 240 (count (damp.ekeko/ekeko [?ast ?methoddec] (basic/ast-encompassing-method ?ast ?methoddec))))))
+
+
+(deftest
+ basic-modifiers
+ ^{:doc "Superficial test for modifier-*/1."}
+ (is
+ (= [2 32 0 0 0 0 0 0 0 0 0]
+ (for [modpred [basic/modifier-static basic/modifier-public basic/modifier-protected basic/modifier-private
+ basic/modifier-abstract basic/modifier-final basic/modifier-native basic/modifier-synchronized
+ basic/modifier-transient basic/modifier-volatile basic/modifier-strictfp]]
+ (count (damp.ekeko/ekeko [?mod] (modpred ?mod)))))))
+
+(deftest
+ basic-ast-declaration-modifier
+ ^{:doc "Superficial test for ast-declaration-modifier/3."}
+ (is (= 34 (count (damp.ekeko/ekeko [?key ?ast ?mod] (basic/ast-declaration-modifier ?key ?ast ?mod))))))
+
+
;; Test suite
@@ -73,12 +219,47 @@
(deftest
test-suite
(let [visitorproject "TestCase-JDT-CompositeVisitor"]
- (test/against-project-named visitorproject false reification-ast)
- (test/against-project-named visitorproject false reification-has-relational)
- (test/against-project-named visitorproject false reification-ast-child+)
- (test/against-project-named visitorproject false reification-value)
-
- ))
+
+ (comment
+
+ ;Reification
+ ;-----------
+
+ ;AST
+ (test/against-project-named visitorproject false reification-ast)
+ (test/against-project-named visitorproject false reification-has-relational)
+ (test/against-project-named visitorproject false reification-ast-child+)
+ (test/against-project-named visitorproject false reification-value)
+ (test/against-project-named visitorproject false reification-child-parent)
+ (test/against-project-named visitorproject false reification-ast-specialkinds)
+ (test/against-project-named visitorproject false reification-ast-subnodekinds)
+
+ ;IBinding
+ (test/against-project-named visitorproject false reification-ast-bindings)
+
+
+ ;Model
+ (test/against-project-named visitorproject false reification-modelunaries)
+
+
+ ;http://dev.clojure.org/jira/browse/LOGIC-111
+ ;(test/against-project-named visitorproject false reification-modelelement)
+
+
+ )
+
+ ;Basic
+ ;-----
+
+ (test/against-project-named visitorproject false basic-ast-location)
+ (test/against-project-named visitorproject false basic-ast-encompassing-typedeclaration)
+ (test/against-project-named visitorproject false basic-ast-encompassing-methoddeclaration)
+ (test/against-project-named visitorproject false basic-modifiers)
+ (test/against-project-named visitorproject false basic-ast-declaration-modifier)
+
+
+
+ ))
(defn
test-ns-hook
@@ -91,5 +272,6 @@
(run-tests)
)
-
+
+

No commit comments for this range

Something went wrong with that request. Please try again.