From 2e7bf8dfdd7f579ad42f8a4c6ab838e31b5a3044 Mon Sep 17 00:00:00 2001 From: yeom Date: Tue, 1 Mar 2011 22:49:11 +0000 Subject: [PATCH] add annotation descriptor. type descriptor is responsible for keeping corresponding annotations. --- Robust/src/IR/AnnotationDescriptor.java | 63 +++++++++++++++++++++++++ Robust/src/IR/Tree/AnnotationNode.java | 12 ----- Robust/src/IR/Tree/BuildIR.java | 21 +++++++-- Robust/src/IR/Tree/Modifiers.java | 12 +++-- Robust/src/IR/TypeDescriptor.java | 18 +++++++ 5 files changed, 106 insertions(+), 20 deletions(-) create mode 100644 Robust/src/IR/AnnotationDescriptor.java delete mode 100644 Robust/src/IR/Tree/AnnotationNode.java diff --git a/Robust/src/IR/AnnotationDescriptor.java b/Robust/src/IR/AnnotationDescriptor.java new file mode 100644 index 00000000..f831378d --- /dev/null +++ b/Robust/src/IR/AnnotationDescriptor.java @@ -0,0 +1,63 @@ +package IR; + +import java.util.Set; + +public class AnnotationDescriptor extends Descriptor { + + public static final int MARKER_ANNOTATION = 1; + public static final int SINGLE_ANNOTATION = 2; + public static final int FULL_ANNOTATION = 3; + + private String marker; + private Set arrayedValues; // for single annotation + private int type; + + public AnnotationDescriptor(String annotationName) { + // constructor for marker annotation + super(annotationName); + this.marker = annotationName; + this.type = MARKER_ANNOTATION; + } + + public int getType() { + return type; + } + + public boolean isMarkerAnnotation() { + return type == MARKER_ANNOTATION; + } + + public boolean isSingleAnnotation() { + return type == SINGLE_ANNOTATION; + } + + public boolean isFullAnnotation() { + return type == FULL_ANNOTATION; + } + + public String getMarker() { + return marker; + } + + public boolean equals(Object o) { + if (o instanceof AnnotationDescriptor) { + AnnotationDescriptor a = (AnnotationDescriptor) o; + if (a.getType() != type) + return false; + if (!a.getMarker().equals(getMarker())) + return false; + + return true; + } + return false; + } + + public String toString() { + if (type == MARKER_ANNOTATION) { + return "@" + name; + } else { + return "@" + name + "()"; + } + } + +} diff --git a/Robust/src/IR/Tree/AnnotationNode.java b/Robust/src/IR/Tree/AnnotationNode.java deleted file mode 100644 index b0622caf..00000000 --- a/Robust/src/IR/Tree/AnnotationNode.java +++ /dev/null @@ -1,12 +0,0 @@ -package IR.Tree; - -public class AnnotationNode extends TreeNode { - //currently it only supports marker annotation that have no variables. - String name; - - public AnnotationNode(String name){ - //constructor for marker annotation - this.name=name; - } - -} diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 9a20ec9a..5634955b 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -618,6 +618,7 @@ public class BuildIR { ParseNode tn=pn.getChild("type"); TypeDescriptor t=parseTypeDescriptor(tn); + assignAnnotationsToType(m,t); ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list"); ParseNodeVector pnv=vn.getChildren(); boolean isglobal=pn.getChild("global")!=null; @@ -675,6 +676,15 @@ public class BuildIR { cn.addField(new FieldDescriptor(m, arrayt, identifier, en, isglobal)); } } + + private void assignAnnotationsToType(Modifiers modifiers, TypeDescriptor type){ + Vector annotations=modifiers.getAnnotations(); + for(int i=0; i annotations; + Vector annotations; private int value; public Modifiers() { value=0; - annotations=new Vector(); + annotations=new Vector(); } public Modifiers(int v) { value=v; } - public void addAnnotation(AnnotationNode an){ + public void addAnnotation(AnnotationDescriptor an){ annotations.add(an); } + + public Vector getAnnotations(){ + return annotations; + } public void addModifier(int mod) { value|=mod; diff --git a/Robust/src/IR/TypeDescriptor.java b/Robust/src/IR/TypeDescriptor.java index cb67bb93..a678640d 100644 --- a/Robust/src/IR/TypeDescriptor.java +++ b/Robust/src/IR/TypeDescriptor.java @@ -1,5 +1,8 @@ package IR; +import java.util.HashSet; +import java.util.Set; + /** * Descriptor * @@ -26,6 +29,8 @@ public class TypeDescriptor extends Descriptor { private int type; ClassDescriptor class_desc; boolean isClassNameRef = false; + + private HashSet annotationSet; public boolean equals(Object o) { if (o instanceof TypeDescriptor) { @@ -280,6 +285,7 @@ public class TypeDescriptor extends Descriptor { this.class_desc=null; this.arraycount=0; this.isClassNameRef =false; + this.annotationSet=new HashSet(); } public TypeDescriptor(String st) { @@ -288,6 +294,7 @@ public class TypeDescriptor extends Descriptor { this.class_desc=null; this.arraycount=0; this.isClassNameRef =false; + this.annotationSet=new HashSet(); } public ClassDescriptor getClassDesc() { @@ -300,6 +307,7 @@ public class TypeDescriptor extends Descriptor { this.class_desc=cd; this.arraycount=0; this.isClassNameRef =false; + this.annotationSet=new HashSet(); } public TypeDescriptor(int t) { @@ -307,6 +315,7 @@ public class TypeDescriptor extends Descriptor { this.type=t; this.arraycount=0; this.isClassNameRef =false; + this.annotationSet=new HashSet(); } public String toString() { @@ -353,4 +362,13 @@ public class TypeDescriptor extends Descriptor { return "offset"; else throw new Error(); } + + public void addAnnotationMarker(AnnotationDescriptor an){ + annotationSet.add(an); + } + + public Set getAnnotationMarkerSet(){ + return annotationSet; + } + } -- 2.34.1