Hi there!
I was wondering if it would be feasible to add a feature to allow users to embed queries directly in source code, for example in specially formatted comments.
The idea behind this would be to have something like compile time assertions (similar to AspectJ’s ‘declare error’), but with the full power and elegance of .QL queries.

These embedded queries could be evaluated automatically (at compile time), and queries that ‘fail’ (e.g. produce any results) could be shown as errors.
Here’s an example of what it could look like:
public class C {
/*.QL:ASSERT(“Method C.foo should not be called from within C”)
{
from MethodCall c
where
c.getCaller().getDeclaringType()=thisType
and
c.getCallee()=thisMethod
select call.getCaller()
}
*/
public void foo() {…}
…
}
This would (roughly) be equivalent to the following AspectJ error declaration:
declare error: call(* C.foo(..)) && within(C) : “error…”;
Note that
thisType and
thisMethod would be context dependent, that is, they would depend on the location of the query.
The possible advantages of having queries directly in source code are that they are easy to create and evaluate, and more importantly, they can be placed close to the entity that they refer to, making it practical to write specialized queries that refer to particular bits of code.
Anyway, this is just an idea…(and admittedly, in this example, the AspectJ version is a bit shorter…

)
-sk