我试图从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文件。
答案 0 :(得分:2)
好问题;有关这方面的文件尚未稀缺。最好的示例代码在这里:http://tutor.rascal-mpl.org/Recipes/Recipes.html#/Recipes/Metrics/MeasuringJava/MeasuringJava.html
M3模型的源代码可以在这里解释很多:
E.g。后者包含这些定义:
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}
;以前的不同定义