Skip to content
Snippets Groups Projects
Commit 01ee3b1c authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

refactored and added annotations to Decl

parent 9ef4fb93
Branches
No related tags found
No related merge requests found
......@@ -2,21 +2,27 @@ aspect Annotations {
syn boolean TypeInstance.hasAnnotations() = getAnnotations().getNumAnnotation()>0;
syn boolean TypeInstance.hasIntentions() = ! intentionSet().isEmpty();
// syn String Annotations.getName() = new String(lookup(""));
//
// syn byte[] Annotation.lookup(String key) = (getKey().equals(key) ? getValue() : null);
syn String Annotations.getName() = new String(lookup(""));
syn byte[] Annotations.lookup(String key) {
for(Annotation a: getAnnotations()) {
byte[] res = a.lookup(key);
if(res != null) return res;
}
return null;
}
syn byte[] Annotation.lookup(String key) = (getKey().equals(key) ? getValue() : null);
syn boolean Annotation.isIntention() = false;
eq Intention.isIntention() = true;
inh ASTNode Annotation.parentInstance();
eq TypeInstance.getAnnotations().parentInstance() = this;
eq Decl.getAnnotations().parentInstance() = this;
inh AnnotatedNode Annotation.parentInstance();
eq AnnotatedNode.getAnnotations().parentInstance() = this;
coll Set<Intention> TypeInstance.intentionSet() [new HashSet<Intention>()] with add;
coll Set<Intention> AnnotatedNode.intentionSet() [new HashSet<Intention>()] with add;
Intention contributes this
to TypeInstance.intentionSet()
to AnnotatedNode.intentionSet()
for parentInstance();
}
......
Specification ::= Decl*;
abstract Decl ::= TypeInstance Annotations /Signature/;
abstract AnnotatedNode ::= Annotations;
abstract Decl : AnnotatedNode ::= TypeInstance /Signature/;
TypeInstance ::= DataType <Name:String> Annotations;
TypeInstance :AnnotatedNode ::= DataType;
Annotations ::= Annotation*;
Annotation ::= <Key:String> <Value:byte[]>;
......
......@@ -3,12 +3,40 @@ aspect Refactoring {
syn String Decl.getName() = getTypeInstance().getName();
syn DataType Decl.getDataType() = getTypeInstance().getDataType();
syn String TypeInstance.getName() = getAnnotations().getName();
public TypeDecl.TypeDecl(TypeInstance t, Annotations a) {
this(a, t);
}
public SampleDecl.SampleDecl(TypeInstance t, Annotations a) {
this(a, t);
}
public TypeInstance.TypeInstance(DataType t, Annotations a) {
this(a, t);
}
public Field.Field(DataType t, Annotations a) {
this(a, t);
}
public Annotations Annotations.addName(String n) {
//XXX TODO: check if name already exists
addAnnotation(new Annotation("",n.getBytes()));
return this;
}
public Field.Field(TypeInstance t) {
this(t.getDataType(), t.getName(), t.getAnnotations());
this(t.getDataType(), t.getAnnotations().addName(t.getName()));
}
public TypeInstance.TypeInstance(DataType t, String n, Annotations a) {
this(t, a.addName(n));
}
public TypeInstance.TypeInstance(DataType t, String n) {
this(t, n, new Annotations());
this(t, new Annotations().addName(n));
System.out.println("WARNING! TypeInstance(DataType, String) ignoring intention list");
}
public TypeDecl.TypeDecl(TypeInstance t) {
......
......@@ -28,7 +28,7 @@ typedef struct {
boolean c;
} foo;
sample struct {
(nisse:hej) sample struct {
(name:l1)line l1;
(name:l2)line l2;
(b:"kalle anka")(c:hejdu)(a:"kalle anka")foo f;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment