[Soot-list] Boolean Annotation Problem / Entity
Tillmann
tirunkel at informatik.uni-bremen.de
Tue Jun 14 11:38:05 EDT 2011
Hi,
i found out that's a problem by parsing annotations with boolean
elements (e.g. in JavaEE Entities - @Column(nullable=true/false)). The
jimple-generation results in an exception thrown by
ElementConstantValue. My quick-and-dirty solution is at the end of this
post.
Anyone has an answer of my Question asked a week before?
"I want to use soot and build several analysis in the JavaEE context. I
have a focus on inter-procedural analysis (CHA, Call-Graph, ...), so i
set the -w option. The problem is, that i have no main class /
main(String[] args)-method in JavaEE context, so i want to define other
entrypoints (and more than one) for my test candidate (war/ejb). I found
no option to define such behaviour.
Question 1: Is it possible to define dedicated methods as entry points
for further analysis?
Question 2: Is it possible to define more than one method as entry point?"
My input is Java-(source)code.
Index: generated/jastadd/soot/JastAddJ/ElementConstantValue.java
===================================================================
--- generated/jastadd/soot/JastAddJ/ElementConstantValue.java (revision 3571)
+++ generated/jastadd/soot/JastAddJ/ElementConstantValue.java (working copy)
@@ -1,6 +1,7 @@
package soot.JastAddJ;
-import java.util.HashSet;import java.util.LinkedHashSet;import java.io.File;import java.util.*;import beaver.*;import java.util.ArrayList;import java.util.zip.*;import java.io.*;import java.io.FileNotFoundException;import java.util.Collection;import soot.*;import soot.util.*;import soot.jimple.*;import soot.coffi.ClassFile;import soot.coffi.method_info;import soot.coffi.CONSTANT_Utf8_info;import soot.tagkit.SourceFileTag;import soot.coffi.CoffiMethodSource;
+import java.util.HashSet;import java.util.LinkedHashSet;import java.io.File;import java.util.*;import beaver.*;import java.util.ArrayList;import java.util.zip.*;import java.io.*;import java.util.Collection;import soot.*;import soot.util.*;import soot.jimple.*;import soot.coffi.ClassFile;import soot.coffi.method_info;import soot.coffi.CONSTANT_Utf8_info;import soot.tagkit.AnnotationBooleanElem;
+import soot.tagkit.SourceFileTag;import soot.coffi.CoffiMethodSource;
public class ElementConstantValue extends ElementValue implements Cloneable {
@@ -71,8 +72,11 @@
list.add(new soot.tagkit.AnnotationFloatElem(getExpr().constant().floatValue(), kind, name));
else if(type.isString())
list.add(new soot.tagkit.AnnotationStringElem(getExpr().constant().stringValue(), kind, name));
- else if(type.isIntegralType() || type().isBoolean())
+ else if(type.isIntegralType())
list.add(new soot.tagkit.AnnotationIntElem(getExpr().constant().intValue(), kind, name));
+ else if(type().isBoolean()){
+ list.add(new soot.tagkit.AnnotationBooleanElem(getExpr().constant().booleanValue(), kind, name));
+ }
else
throw new UnsupportedOperationException("Unsupported attribute constant type " + type.typeName());
}
Index: src/soot/AbstractJasminClass.java
===================================================================
--- src/soot/AbstractJasminClass.java (revision 3571)
+++ src/soot/AbstractJasminClass.java (working copy)
@@ -260,11 +260,19 @@
StringBuffer result = new StringBuffer(".elem ");
switch (elem.getKind()){
case 'Z': {
- result.append(".bool_kind ");
- result.append("\""+elem.getName()+"\" ");
- result.append(((AnnotationIntElem)elem).getValue());
- result.append("\n");
- break;
+ result.append(".bool_kind ");
+ result.append("\"" + elem.getName() + "\" ");
+ if (elem instanceof AnnotationIntElem) {
+ result.append(((AnnotationIntElem) elem).getValue());
+ } else {
+ if (((AnnotationBooleanElem) elem).getValue()) {
+ result.append(1);
+ } else {
+ result.append(0);
+ }
+ }
+ result.append("\n");
+ break;
}
case 'S': {
result.append(".short_kind ");
Index: generated/jastadd/soot/tagkit/AnnotationBooleanElem.java
===================================================================
--- generated/jastadd/soot/tagkit/AnnotationBooleanElem.java (revision 0)
+++ generated/jastadd/soot/tagkit/AnnotationBooleanElem.java (revision 0)
@@ -0,0 +1,18 @@
+package soot.tagkit;
+
+public class AnnotationBooleanElem extends AnnotationElem{
+ boolean value;
+
+ public AnnotationBooleanElem(boolean v, char kind, String name){
+ super(kind, name);
+ this.value = v;
+ }
+
+ public String toString(){
+ return super.toString()+" value: " +value;
+ }
+
+ public boolean getValue(){
+ return value;
+ }
+}
More information about the Soot-list
mailing list