- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为 Java 的一个子集制作合金元模型。
下面是一些签名:
abstract sig Id {}
sig Package{}
sig ClassId, MethodId,FieldId extends Id {}
abstract sig Accessibility {}
one sig public, private_, protected extends Accessibility {}
abstract sig Type {}
abstract sig PrimitiveType extends Type {}
one sig Int_, Long_ extends PrimitiveType {}
sig Class extends Type {
package: one Package,
id: one ClassId,
extend: lone Class,
methods: set Method,
fields: set Field
}
sig Field {
id : one FieldId,
type: one Type,
acc : lone Accessibility
}
sig Method {
id : one MethodId,
param: lone Type,
acc: lone Accessibility,
return: one Type,
b: one Body
}
abstract sig Body {}
sig LiteralValue extends Body {} // returns a random value
abstract sig Qualifier {}
one sig this_, super_ extends Qualifier {}
sig MethodInvocation extends Body {
id_methodInvoked : one Method,
q: lone Qualifier
}
// return new A().k();
sig ConstructorMethodInvocation extends Body {
id_Class : one Class,
cmethodInvoked: one Method
}{
(this.@cmethodInvoked in (this.@id_Class).methods) || (this.@cmethodInvoked in ((this.@id_Class).^extend).methods && (this.@cmethodInvoked).acc != private_)
}
// return x;
// return this.x;
// return super.x;
sig FieldInvocation extends Body {
id_fieldInvoked : one Field,
qField: lone Qualifier
}
// return new A().x;
sig ConstructorFieldInvocation extends Body {
id_cf : one Class,
cfieldInvoked: one Field
}{
(this.@cfieldInvoked in (this.@id_cf).fields) || ( this.@cfieldInvoked in ((this.@id_cf).^extend).fields && (this.@cfieldInvoked).acc != private_)
}
在Java语言中,如果某个方法不是私有(private)方法,我们只能调用类内部的方法(通过该类的实例化)。我尝试通过以下签名在我的合金模型中表示此限制:
sig ConstructorMethodInvocation extends Body {
id_Class : one Class,
cmethodInvoked: one Method
}{
(this.@cmethodInvoked in (this.@id_Class).methods || this.@cmethodInvoked in ((this.@id_Class).^extend).methods && (this.@cmethodInvoked).acc != private_)
因此,合金中的 ConstructorMethodInitation 签名尝试表示 Java 中的构造,如 new A().x()。另外,方法 x() 只有在不是类 A 的私有(private)方法时才能被调用。因此,我添加了以下限制(在 ConstructorMethodInitation 签名中)以避免调用类 id_Class 的私有(private)方法:
(this.@cmethodInvoked in (this.@id_Class).methods || this.@cmethodInvoked in ((this.@id_Class).^extend).methods && (this.@cmethodInvoked).acc != private_)
但是,尽管有此限制,求解器仍坚持生成实例(对于 ConstructorMethodInitation),其中 cmethodInvoked 是 id_Class 的私有(private)方法。同样的情况也发生在 ConstructorFieldInitation 上。
有人看出我做错了什么吗?
最佳答案
这是因为您在 ConstructorMethodInitation
信号的附加事实中放错了括号:按照现在的方式,您有一个顶级析取,它允许实例 (cmethodInvoked
) > 在 id_Class.methods
中)或者(在 id_Class.^extend.methods
中并且不是私有(private)的)。如果您将附加事实 block 更改为
{
this.@cmethodInvoked in this.@id_Class.*extend.methods
this.@cmethodInvoked.acc != private_
}
您将得到预期的行为(星号运算符(*
)是反射传递闭包,它基本上意味着与您打算编写的原始析取相同;您仍然可以使用旧的约束并修复括号)。
为了检查是否不存在任何方法为私有(private)的 ConstructorMethodInitation
实例,我执行了
check {
no c: ConstructorMethodInvocation {
c.cmethodInvoked.acc = private_
}
}
没有发现反例。
关于java - 生成明显不一致的合金实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19007092/
我很难理解 Alloy 4 中谓词和函数之间的区别。我已经阅读了软件抽象中的第 4.5.2 节,但我仍然不清楚。谁能帮我理解一下? 最佳答案 一个函数只是代表一个参数化的表达式,它在每个调用站点被
我最近在与 Alloy 合作。 我可以这样说吗: fact{ all i: Int | i >= 0 } 我想说:Alloy 使用的所有 Integer 都应该是正数。 合金不会失败,但也不会给我实例
我正在尝试使用合金开始使用 Titanium 平台,但它并不像看起来那么容易。我目前正在使用以下代码运行一个合金项目。非常基本,没什么奇怪的,但是在自动生成的第一个屏幕上,我无法阅读设备上的文本。它的
我需要将状态栏样式更改为黑色,我不知道如何......我试图把 索引.xml:
我将 liferay 与 piwik 一起使用,并希望将客户端验证错误事件捕获到 piwik 中的自定义变量中。例如默认的用户注册页面有许多字段和合金 ui 验证器配置。我想捕获注册用户在 piwik
我正在尝试打开另一个包含新窗口的 Controller ,但是该窗口没有显示。 这是我在 index.js 中创建 Controller 的调用: function addSong() { v
您好,如何使用 24 小时格式显示时间字段的允许 ui 日期选择器?如果我正在使用 [code] " bean="" value="" label="Schedule
根据release notes对于 Alloy 4.2,存在与整数相关的语义变化。这些更改似乎对合金书的练习 A.1.6 有影响。 在本练习中,给出了以下代码作为基础(我在最后添加了“Int”以显示我
我有两个合金事实:。因为我注意到关系演算风格似乎比谓词演算风格更有效(生成的变量和子句更少),所以我想用关系演算风格重写它们。。对于A5,我有这样的想法:。它工作得很好,如果我正确理解了风格的话,那就
我有两个合金事实:。当我注意到关系演算风格似乎比谓词演算风格更有效(生成的变量和子句更少)时,我想用关系演算风格重写它们。。对于A5,我有这样的想法:。它工作得很好,如果我正确理解了风格的话,那就是关
我正在使用 iPhone 4s 模拟器运行以下代码: Ti.Geolocation.getCurrentPosition(function(e){ Ti.API.log(JSON.string
我是一名优秀的程序员,十分优秀!