从 M3 模型中提取事实
Extracting facts from M3 models
我正在尝试从 Java M3 模型中提取有关类型声明的一些事实。从一组M3文件中,我尝试使用一个理解,例如
> [type(m) | m <- models];
虽然我得到:未声明的变量:类型
然后我只是尝试从方法中获取事实,使用:
> [methods(m) | m <- models];
如文档所述。尽管如此,我还是得到了类似的东西:
|std:///lang/java/m3/Core.rsc|(8877,1,<186,52>,<186,53>): NoSuchAnnotation("declarations")
那么,在一组 M3 模型上导航的正确方法是什么?如何获取有关 类 和 M3 模型接口的信息?
我已经使用函数 createM3FromProjectJars 构建了 M3 文件。
好问题;关于此的文档目前还很少。最好的示例代码在这里:http://tutor.rascal-mpl.org/Recipes/Recipes.html#/Recipes/Metrics/MeasuringJava/MeasuringJava.html
M3模型的源码这里可以解释很多:
- https://github.com/usethesource/rascal/blob/master/src/org/rascalmpl/library/analysis/m3/Core.rsc
- https://github.com/usethesource/rascal/blob/master/src/org/rascalmpl/library/lang/java/m3/Core.rsc
例如后者包含这些定义:
anno rel[loc from, loc to] M3@extends; // classes extending classes and interfaces extending interfaces
anno rel[loc from, loc to] M3@implements; // classes implementing interfaces
anno rel[loc from, loc to] M3@methodInvocation; // methods calling each other (including constructors)
anno rel[loc from, loc to] M3@fieldAccess; // code using data (like fields)
anno rel[loc from, loc to] M3@typeDependency; // using a type literal in some code (types of variables, annotations)
anno rel[loc from, loc to] M3@methodOverrides; // which method override which other methods
anno rel[loc declaration, loc annotation] M3@annotations;
前者包含这些:
anno rel[loc name, loc src] M3@declarations; // maps declarations to where they are declared. contains any kind of data or type or code declaration (classes, fields, methods, variables, etc. etc.)
anno rel[loc name, TypeSymbol typ] M3@types; // assigns types to declared source code artifacts
anno rel[loc src, loc name] M3@uses; // maps source locations of usages to the respective declarations
anno rel[loc from, loc to] M3@containment; // what is logically contained in what else (not necessarily physically, but usually also)
anno list[Message] M3@messages; // error messages and warnings produced while constructing a single m3 model
anno rel[str simpleName, loc qualifiedName] M3@names; // convenience mapping from logical names to end-user readable (GUI) names, and vice versa
anno rel[loc definition, loc comments] M3@documentation; // comments and javadoc attached to declared things
anno rel[loc definition, Modifier modifier] M3@modifiers; // modifiers associated with declared things
这些定义准确地记录了 Java M3 的模型。如果直接从 jar 文件生成 M3 模型,我不知道这些信息有多少。来自 Eclipse 源项目,所有这些表都已填充。
要实现您的查询,您可以:
[ m@types | m <- models]
;生成一个列表[rel[loc name, TypeSymbol typ]]
{ *m@types | m <- models}
;所有模型中所有类型表的 rel[loc name, TypeSymbol typ] 并集
{ t | m <- models, t <- m@types}
;之前定义不同
我正在尝试从 Java M3 模型中提取有关类型声明的一些事实。从一组M3文件中,我尝试使用一个理解,例如
> [type(m) | m <- models];
虽然我得到:未声明的变量:类型
然后我只是尝试从方法中获取事实,使用:
> [methods(m) | m <- models];
如文档所述。尽管如此,我还是得到了类似的东西:
|std:///lang/java/m3/Core.rsc|(8877,1,<186,52>,<186,53>): NoSuchAnnotation("declarations")
那么,在一组 M3 模型上导航的正确方法是什么?如何获取有关 类 和 M3 模型接口的信息?
我已经使用函数 createM3FromProjectJars 构建了 M3 文件。
好问题;关于此的文档目前还很少。最好的示例代码在这里:http://tutor.rascal-mpl.org/Recipes/Recipes.html#/Recipes/Metrics/MeasuringJava/MeasuringJava.html
M3模型的源码这里可以解释很多:
- https://github.com/usethesource/rascal/blob/master/src/org/rascalmpl/library/analysis/m3/Core.rsc
- https://github.com/usethesource/rascal/blob/master/src/org/rascalmpl/library/lang/java/m3/Core.rsc
例如后者包含这些定义:
anno rel[loc from, loc to] M3@extends; // classes extending classes and interfaces extending interfaces
anno rel[loc from, loc to] M3@implements; // classes implementing interfaces
anno rel[loc from, loc to] M3@methodInvocation; // methods calling each other (including constructors)
anno rel[loc from, loc to] M3@fieldAccess; // code using data (like fields)
anno rel[loc from, loc to] M3@typeDependency; // using a type literal in some code (types of variables, annotations)
anno rel[loc from, loc to] M3@methodOverrides; // which method override which other methods
anno rel[loc declaration, loc annotation] M3@annotations;
前者包含这些:
anno rel[loc name, loc src] M3@declarations; // maps declarations to where they are declared. contains any kind of data or type or code declaration (classes, fields, methods, variables, etc. etc.)
anno rel[loc name, TypeSymbol typ] M3@types; // assigns types to declared source code artifacts
anno rel[loc src, loc name] M3@uses; // maps source locations of usages to the respective declarations
anno rel[loc from, loc to] M3@containment; // what is logically contained in what else (not necessarily physically, but usually also)
anno list[Message] M3@messages; // error messages and warnings produced while constructing a single m3 model
anno rel[str simpleName, loc qualifiedName] M3@names; // convenience mapping from logical names to end-user readable (GUI) names, and vice versa
anno rel[loc definition, loc comments] M3@documentation; // comments and javadoc attached to declared things
anno rel[loc definition, Modifier modifier] M3@modifiers; // modifiers associated with declared things
这些定义准确地记录了 Java M3 的模型。如果直接从 jar 文件生成 M3 模型,我不知道这些信息有多少。来自 Eclipse 源项目,所有这些表都已填充。
要实现您的查询,您可以:
[ m@types | m <- models]
;生成一个列表[rel[loc name, TypeSymbol typ]]{ *m@types | m <- models}
;所有模型中所有类型表的 rel[loc name, TypeSymbol typ] 并集{ t | m <- models, t <- m@types}
;之前定义不同