repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/MethodIsGetterNoSetterFeature.java
package de.ecspride.sourcesinkfinder.features; import java.util.ArrayList; import java.util.List; import soot.Body; import soot.Local; import soot.SootMethod; import soot.Unit; import soot.jimple.AssignStmt; import soot.jimple.FieldRef; import soot.jimple.IdentityStmt; import soot.jimple.InstanceFieldRef; import soot.jimple.ReturnStmt; import soot.jimple.infoflow.android.data.AndroidMethod; /** * Feature that checks whether the current method begins with "get", and there * is a corresponding "set" method in the class. * * @author Steven Arzt, Siegfried Rasthofer * */ public class MethodIsGetterNoSetterFeature extends AbstractSootFeature { public MethodIsGetterNoSetterFeature(String mapsJAR, String androidJAR) { super(mapsJAR, androidJAR); } @Override public Type appliesInternal(AndroidMethod method) { SootMethod sm = getSootMethod(method); // We are only interested in getters and setters if (!sm.getName().startsWith("get") && !sm.getName().startsWith("set")) return Type.NOT_SUPPORTED; String baseName = sm.getName().substring(3); String getterName = "get" + baseName; String setterName = "set" + baseName; try { // Find the getter and the setter SootMethod getter = getSootMethod(new AndroidMethod (getterName, "", sm.getDeclaringClass().getName())); SootMethod setter = getSootMethod(new AndroidMethod (setterName, "", sm.getDeclaringClass().getName())); if (getter == null || setter == null) return Type.FALSE; if (!setter.isConcrete() || !getter.isConcrete()) return Type.NOT_SUPPORTED; Body bodyGetter = null; try{ bodyGetter = getter.retrieveActiveBody(); }catch(Exception ex){ return Type.NOT_SUPPORTED; } // Find the local that gets returned Local returnLocal = null; for (Unit u : bodyGetter.getUnits()) if (u instanceof ReturnStmt) { ReturnStmt ret = (ReturnStmt) u; if (ret.getOp() instanceof Local) { returnLocal = (Local) ret.getOp(); break; } } if (returnLocal == null) return Type.FALSE; // Find where the local is assigned a value in the code List<FieldRef> accessPath = new ArrayList<FieldRef>(); Local returnBase = returnLocal; while (returnBase != null) for (Unit u : bodyGetter.getUnits()) { if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; if (assign.getLeftOp().equals(returnBase)) if (assign.getRightOp() instanceof InstanceFieldRef) { InstanceFieldRef ref = (InstanceFieldRef) assign.getRightOp(); accessPath.add(0, ref); returnBase = (Local) ref.getBase(); break; } else returnBase = null; } else if (u instanceof IdentityStmt) { IdentityStmt id = (IdentityStmt) u; if (id.getLeftOp().equals(returnBase)) returnBase = null; } } if (accessPath.isEmpty()) return Type.FALSE; /* // Find the corresponding access path in the setter for (Unit u : bodySetter.getUnits()) if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; if (assign.getLeftOp() instanceof InstanceFieldRef && assign.getRightOp() instanceof Local) { InstanceFieldRef iref = (InstanceFieldRef) assign.getLeftOp(); if (iref.getFieldRef().toString().equals(accessPath.get(accessPath.size() - 1).getFieldRef().toString())) { // This is a starting point boolean pathFound = false; Local startLocal = (Local) iref.getBase(); int accessPathPos = accessPath.size() - 2; while (startLocal != null) { for (Unit u2 : bodySetter.getUnits()) { if (u2 instanceof AssignStmt) { AssignStmt assign2 = (AssignStmt) u2; if (assign2.getLeftOp().equals(startLocal)) if (assign2.getRightOp() instanceof InstanceFieldRef) { InstanceFieldRef ref = (InstanceFieldRef) assign2.getRightOp(); if (accessPath.get(accessPathPos--).getFieldRef().toString().equals(ref.getFieldRef().toString())) { startLocal = (Local) ref.getBase(); break; } else startLocal = null; } else startLocal = null; } else if (u2 instanceof IdentityStmt) { IdentityStmt id = (IdentityStmt) u2; if (id.getLeftOp().equals(startLocal)) { startLocal = null; pathFound = true; break; } } } } if (pathFound) { if (assign.getRightOp() instanceof Local) { // Find the parameter being set for (Unit u2 : bodySetter.getUnits()) if (u2 instanceof IdentityStmt) { IdentityStmt id = (IdentityStmt) u2; if (id.getLeftOp().equals(assign.getRightOp())) return Type.TRUE; } } break; } } } } return Type.FALSE; */ return Type.TRUE; }catch (Exception ex) { System.err.println("Something went wrong:"); ex.printStackTrace(); return Type.NOT_SUPPORTED; } } @Override public String toString() { return "<Method is lone getter or setter>"; } }
5,214
29.497076
113
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/MethodIsRealSetterFeature.java
package de.ecspride.sourcesinkfinder.features; import java.util.HashSet; import java.util.Set; import soot.SootMethod; import soot.Unit; import soot.Value; import soot.jimple.AssignStmt; import soot.jimple.IdentityStmt; import soot.jimple.InstanceFieldRef; import soot.jimple.ParameterRef; import soot.jimple.Stmt; import soot.jimple.infoflow.android.data.AndroidMethod; /** * Feature that checks whether the current method begins with "get", and there * is a corresponding "set" method in the class. * * @author Steven Arzt, Siegfried Rasthofer * */ public class MethodIsRealSetterFeature extends AbstractSootFeature { public MethodIsRealSetterFeature(String mapsJAR, String androidJAR) { super(mapsJAR, androidJAR); } @Override public Type appliesInternal(AndroidMethod method) { SootMethod sm = getSootMethod(method); if (sm == null) { System.err.println("Method not declared: " + method); return Type.NOT_SUPPORTED; } // We are only interested in setters if (!sm.getName().startsWith("set")) return Type.FALSE; if (!sm.isConcrete()) return Type.NOT_SUPPORTED; try { Set<Value> paramVals = new HashSet<Value>(); for (Unit u : sm.retrieveActiveBody().getUnits()) { if (u instanceof IdentityStmt) { IdentityStmt id = (IdentityStmt) u; if (id.getRightOp() instanceof ParameterRef) paramVals.add(id.getLeftOp()); } else if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; if (paramVals.contains(assign.getRightOp())) if (assign.getLeftOp() instanceof InstanceFieldRef) return Type.TRUE; } if (u instanceof Stmt) { Stmt stmt = (Stmt) u; if (stmt.containsInvokeExpr()) { if (stmt.getInvokeExpr().getMethod().getName().startsWith("get")) for (Value arg: stmt.getInvokeExpr().getArgs()) if (paramVals.contains(arg)) return Type.FALSE; } } } return Type.FALSE; }catch (Exception ex) { System.err.println("Something went wrong:"); ex.printStackTrace(); return Type.NOT_SUPPORTED; } } @Override public String toString() { return "<Method is lone getter or setter>"; } }
2,175
25.216867
78
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/MethodModifierFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.SootMethod; import soot.jimple.infoflow.android.data.AndroidMethod; /** * Feature checking the method modifiers * * @author Steven Arzt * */ public class MethodModifierFeature extends AbstractSootFeature { public enum Modifier{PUBLIC,PRIVATE,STATIC,PROTECTED,ABSTRACT,FINAL,SYNCHRONIZED,NATIVE}; private final Modifier modifier; public MethodModifierFeature(String mapsJAR, String androidJAR, Modifier modifier) { super(mapsJAR, androidJAR); this.modifier = modifier; } @Override public Type appliesInternal(AndroidMethod method) { SootMethod sm = getSootMethod(method); if (sm == null) return Type.NOT_SUPPORTED; try { switch(modifier){ case PUBLIC: return (sm.isPublic()? Type.TRUE : Type.FALSE); case PRIVATE: return (sm.isPrivate()? Type.TRUE : Type.FALSE); case ABSTRACT : return (sm.isAbstract()? Type.TRUE : Type.FALSE); case STATIC : return (sm.isStatic()? Type.TRUE : Type.FALSE); case PROTECTED : return (sm.isProtected()? Type.TRUE : Type.FALSE); case FINAL : return (sm.isFinal()? Type.TRUE : Type.FALSE); case SYNCHRONIZED : return (sm.isSynchronized()? Type.TRUE : Type.FALSE); case NATIVE : return (sm.isNative() ? Type.TRUE : Type.FALSE); } throw new Exception("Modifier not declared!"); } catch (Exception ex) { System.err.println("Something went wrong: " + ex.getMessage()); return Type.NOT_SUPPORTED; } } @Override public String toString() { return "<Method modifier is " + modifier.name() + ">"; } }
1,575
28.735849
90
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/MethodNameContainsFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.jimple.infoflow.android.data.AndroidMethod; import de.ecspride.sourcesinkfinder.IFeature; /** * Common class for all features that have to do with the method name * * @author Steven Arzt */ public class MethodNameContainsFeature implements IFeature { private final String endsWith; public MethodNameContainsFeature(String endsWith) { this.endsWith = endsWith.toLowerCase(); } @Override public Type applies(AndroidMethod method) { return (method.getMethodName().toLowerCase().contains(endsWith) ? Type.TRUE : Type.FALSE); } @Override public String toString() { return "<Method name contains " + this.endsWith + ">"; } }
706
22.566667
92
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/MethodNameEndsWithFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.jimple.infoflow.android.data.AndroidMethod; import de.ecspride.sourcesinkfinder.IFeature; /** * Common class for all features that have to do with the method name * * @author Siegfried Rasthofer * */ public class MethodNameEndsWithFeature implements IFeature { private final String endsWith; public MethodNameEndsWithFeature(String endsWith) { this.endsWith = endsWith; } @Override public Type applies(AndroidMethod method) { String methodNameLowerCase = method.getMethodName().toLowerCase(); String endsWithLowerCase = endsWith.toLowerCase(); return (methodNameLowerCase.endsWith(endsWithLowerCase)? Type.TRUE : Type.FALSE); } @Override public String toString() { return "<Method name ends with " + this.endsWith + ">"; } }
817
23.787879
83
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/MethodNameStartsWithFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.jimple.infoflow.android.data.AndroidMethod; import de.ecspride.sourcesinkfinder.IFeature; /** * Common class for all features that have to do with the method name * * @author Steven Arzt * */ public class MethodNameStartsWithFeature implements IFeature { private final String startsWith; public MethodNameStartsWithFeature(String startsWith, float weight) { this.startsWith = startsWith; } @Override public Type applies(AndroidMethod method) { return (method.getMethodName().startsWith(this.startsWith)? Type.TRUE : Type.FALSE); } @Override public String toString() { return "<Method name starts with " + this.startsWith + ">"; } }
721
22.290323
86
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/MethodReturnsConstantFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.Body; import soot.SootMethod; import soot.Unit; import soot.jimple.Constant; import soot.jimple.ReturnStmt; import soot.jimple.infoflow.android.data.AndroidMethod; /** * Feature that checks whether the current method returns a constant value * * @author Steven Arzt, Siegfried Rasthofer * */ public class MethodReturnsConstantFeature extends AbstractSootFeature { public MethodReturnsConstantFeature(String mapsJAR, String androidJAR) { super(mapsJAR, androidJAR); } @Override public Type appliesInternal(AndroidMethod method) { SootMethod sm = getSootMethod(method); if (sm == null || !sm.isConcrete()) return Type.NOT_SUPPORTED; try { Body body = null; try{ body = sm.retrieveActiveBody(); }catch(Exception ex){ return Type.NOT_SUPPORTED; } for (Unit u : body.getUnits()) if (u instanceof ReturnStmt) { ReturnStmt ret = (ReturnStmt) u; if (ret.getOp() instanceof Constant) return Type.TRUE; } return Type.FALSE; }catch (Exception ex) { System.err.println("Something went wrong:"); ex.printStackTrace(); return Type.NOT_SUPPORTED; } } @Override public String toString() { return "<Method returns constant>"; } }
1,275
22.2
74
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/PackageNameOfClassFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.jimple.infoflow.android.data.AndroidMethod; import de.ecspride.sourcesinkfinder.IFeature; /** * This feature checks the name of the package * @author Siegfried Rasthofer */ public class PackageNameOfClassFeature implements IFeature { private final String packageNameOfClass; public PackageNameOfClassFeature(String packageNameOfClass, float weight){ this.packageNameOfClass = packageNameOfClass; } @Override public Type applies(AndroidMethod method) { String otherPackageNameOfClass = method.getClassName().substring(0, method.getClassName().lastIndexOf(".")); return (otherPackageNameOfClass.equals(packageNameOfClass) ? Type.TRUE : Type.FALSE); } @Override public String toString() { return "<Package path of method class-name is: " + packageNameOfClass + ">"; } }
856
28.551724
110
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/ParameterContainsTypeOrNameFeature.java
package de.ecspride.sourcesinkfinder.features; import java.util.List; import soot.jimple.infoflow.android.data.AndroidMethod; import de.ecspride.sourcesinkfinder.IFeature; /** * Common class for all features that have to do with the method name * * @author Steven Arzt * */ public class ParameterContainsTypeOrNameFeature implements IFeature { private final String insideName; public ParameterContainsTypeOrNameFeature(String insideName) { this.insideName = insideName.toLowerCase(); } @Override public Type applies(AndroidMethod method) { List<String> paramList = method.getParameters(); for(String param : paramList){ if(param.toLowerCase().contains(this.insideName)) return Type.TRUE; } return Type.FALSE; } @Override public String toString() { return "<Parameter type contains " + this.insideName + ">"; } }
856
21.552632
69
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/ParameterInCallFeature.java
package de.ecspride.sourcesinkfinder.features; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import soot.Body; import soot.SootClass; import soot.SootMethod; import soot.Unit; import soot.Value; import soot.jimple.AssignStmt; import soot.jimple.CastExpr; import soot.jimple.IdentityStmt; import soot.jimple.InstanceFieldRef; import soot.jimple.InstanceInvokeExpr; import soot.jimple.InvokeExpr; import soot.jimple.ParameterRef; import soot.jimple.ReturnStmt; import soot.jimple.Stmt; import soot.jimple.infoflow.android.data.AndroidMethod; import soot.jimple.internal.JArrayRef; /** * Feature which checks whether there is a data flow of the specified kind in * the current method * * @author Steven Arzt, Siegfried Rasthofer * */ public class ParameterInCallFeature extends AbstractSootFeature { public enum CheckType { CheckSink, CheckSinkInAbstract, CheckSource, CheckFromMethodToSink, CheckFromParamToNative, CheckFromParamToInterface, CheckFromInterfaceToResult }; private final static String[] sinkMethods = {"start", "save", "send", "dump", "dial", "broadcast", "bind", "transact", "write", "update", "perform", "notify", "insert", "enqueue", "replace", "show", "dispatch", "print", "println", "create", "adjust"}; private final static String[] transformerMethods = {"get", "append", "find", "arraycopy", "valueOf", "as", "generate"}; private final static String[] writerMethods = {"writeArray", "writeBooleanArray", "writeBundle", "writeByte", "writeByteArray", "writeCharArray", "writeCharSequence", "writeDouble", "writeDoubleArray", "writeFloat", "writeFloatArray", "writeInt", "writeIntArray", "writeList", "writeLong", "writeLongArray", "writeMap", "writeParcelable", "writeParcelableArray", "writeString", "writeStringArray", "writeStringList", "writeStrongBinder", "writeStrongInterface", "writeTypedArray", "writeTypedList", "writeObject", "<init>", "add", "putExtra", "putExtras"}; private final String methodName; private final CheckType checkType; private final List<String> sinks = new ArrayList<String>(); private final int argumentPosition; private final boolean restrictPackage; public ParameterInCallFeature(String mapsJAR, String androidJAR, String methodName, CheckType checkType) { this(mapsJAR, androidJAR, methodName, -1, false, checkType); } public ParameterInCallFeature(String mapsJAR, String androidJAR, String methodName, boolean restrictPackage, CheckType checkType) { this(mapsJAR, androidJAR, methodName, -1, restrictPackage, checkType); } public ParameterInCallFeature(String mapsJAR, String androidJAR, String methodName, int parameterPostion, boolean restrictPackage, CheckType checkType) { super(mapsJAR, androidJAR); this.methodName = methodName; this.checkType = checkType; if (methodName.isEmpty()) { for (String s : sinkMethods) sinks.add(s); } else sinks.add(methodName); this.argumentPosition = parameterPostion; this.restrictPackage = restrictPackage; } @Override public Type appliesInternal(AndroidMethod method) { try { SootMethod sm = getSootMethod(method); if (sm == null) { System.err.println("Method not declared: " + method); return Type.NOT_SUPPORTED; } if (!sm.isConcrete()) return Type.NOT_SUPPORTED; // Collect the sources and then find calls where the parameter is // actually sent out Set<Value> params = new HashSet<Value>(); Set<Value> oldParams = new HashSet<Value>(); oldParams.add(null); while (!params.equals(oldParams)) { oldParams = new HashSet<Value>(params); Body body = null; try{ body = sm.retrieveActiveBody(); }catch(Exception ex){ return Type.NOT_SUPPORTED; } for (Unit u : body.getUnits()) { if (!(u instanceof Stmt)) continue; Stmt stmt = (Stmt) u; //Add private field access. Has to be in the beginning of the for loop /* // if (this.checkType == CheckType.CheckFromMethodToSink) if(u instanceof AssignStmt){ AssignStmt assi = (AssignStmt) u; if(assi.getRightOp() instanceof FieldRef){ FieldRef fr = (FieldRef)assi.getRightOp(); if(fr.getField().isPrivate() && !fr.getField().isFinal()) params.add(fr); } } */ // When we are looking for sinks, we treat the parameters // as sources if (this.checkType == CheckType.CheckSink || this.checkType == CheckType.CheckSinkInAbstract || this.checkType == CheckType.CheckFromParamToNative) if (u instanceof IdentityStmt) { IdentityStmt id = (IdentityStmt) u; if (id.getRightOp() instanceof ParameterRef) params.add(id.getLeftOp()); } // When looking for sources, we treat specific method calls // as sources if (this.checkType == CheckType.CheckSource || this.checkType == CheckType.CheckFromMethodToSink) if (u instanceof AssignStmt) { AssignStmt assi = (AssignStmt) u; if (assi.containsInvokeExpr()) { InvokeExpr inv = assi.getInvokeExpr(); if(argumentPosition == -1 && inv.getMethod().getName().startsWith(this.methodName)) params.add(assi.getLeftOp()); } } if (this.checkType == CheckType.CheckFromInterfaceToResult) if (u instanceof AssignStmt) { AssignStmt assi = (AssignStmt) u; if (assi.containsInvokeExpr()) if (assi.getInvokeExpr().getMethod().isAbstract() || assi.getInvokeExpr().getMethod().getDeclaringClass().isInterface()) params.add(assi.getLeftOp()); } // Check whether a tainted parameter flows into a return value if (this.checkType == CheckType.CheckSource || this.checkType == CheckType.CheckFromInterfaceToResult) if (u instanceof ReturnStmt) { ReturnStmt ret = (ReturnStmt) u; if (params.contains(ret.getOp())) return Type.TRUE; } if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; // Do we have an assignment a=b? if (params.contains(assign.getRightOp())) params.add(assign.getLeftOp()); if (assign.getRightOp() instanceof CastExpr) { CastExpr ce = (CastExpr) assign.getRightOp(); if (params.contains(ce.getOp())) params.add(assign.getLeftOp()); } if (assign.getRightOp() instanceof JArrayRef) { JArrayRef ref = (JArrayRef) assign.getRightOp(); if (params.contains(ref.getBase())) params.add(assign.getLeftOp()); } // Do we have a member access? if (assign.getRightOp() instanceof InstanceFieldRef) { InstanceFieldRef ref = (InstanceFieldRef) assign.getRightOp(); if (params.contains(ref.getBase())) params.add(assign.getLeftOp()); } // Do we set a field on a tainted object? if (this.checkType == CheckType.CheckFromMethodToSink) if (assign.getLeftOp() instanceof InstanceFieldRef) { InstanceFieldRef ref = (InstanceFieldRef) assign.getLeftOp(); if (params.contains(ref.getBase())) return Type.TRUE; } if (stmt.containsInvokeExpr()) { InvokeExpr inv = stmt.getInvokeExpr(); // Is this a transformer method? for (String methodSink : transformerMethods) if (inv.getMethod().getName().startsWith(methodSink)) for (Value vInv : inv.getArgs()) if (params.contains(vInv)) { params.add(assign.getLeftOp()); break; } if (inv instanceof InstanceInvokeExpr) { // If this a call on the tainted object itself? InstanceInvokeExpr instInv = (InstanceInvokeExpr) inv; if (params.contains(instInv.getBase())) params.add(assign.getLeftOp()); } // Does a tainted value flow into a static method? // Conservatively assume the return value to be tainted if (inv.getMethod().isStatic()) for (Value vInv : inv.getArgs()) if (params.contains(vInv)) { params.add(assign.getLeftOp()); break; } } } if (stmt.containsInvokeExpr()) { InvokeExpr inv = stmt.getInvokeExpr(); //Is this a source method with a specified parameter position? if(this.checkType == CheckType.CheckSource && argumentPosition >= 0 && inv.getMethod().getName().startsWith(this.methodName)) { if (argumentPosition >= inv.getArgCount()) System.out.println("shit"); params.add(inv.getArg(argumentPosition)); } // Is this a writer method that taints the base object? if (inv instanceof InstanceInvokeExpr) for (String methodSink : writerMethods) if (inv.getMethod().getName().startsWith(methodSink)) for (Value vInv : inv.getArgs()) if (params.contains(vInv)) params.add(((InstanceInvokeExpr) inv).getBase()); // Is this a sink method? if (this.checkType == CheckType.CheckSink || this.checkType == CheckType.CheckFromMethodToSink || (this.checkType == CheckType.CheckFromMethodToSink && inv.getMethod().isNative())) for (String methodSink : this.sinks) if (!isTransformer(methodSink)) if (inv.getMethod().getName().startsWith(methodSink) || inv.getMethod().getDeclaringClass().getName().startsWith(methodSink)) if (checkPackageRestriction(sm.getDeclaringClass(), inv.getMethod().getDeclaringClass())) for (Value vInv : inv.getArgs()) if (params.contains(vInv)) return Type.TRUE; if (this.checkType == CheckType.CheckSinkInAbstract) if (inv.getMethod().isAbstract() || inv.getMethod().getDeclaringClass().isInterface()) for (Value vInv : inv.getArgs()) if (params.contains(vInv)) return Type.TRUE; } } } return Type.FALSE; }catch (Exception ex) { System.err.println("Something went wrong:"); ex.printStackTrace(); return Type.NOT_SUPPORTED; } } private boolean checkPackageRestriction (SootClass methodClass, SootClass sinkClass) { if (!restrictPackage) return true; String methodPackage = methodClass.getName().substring(0, methodClass.getName().lastIndexOf(".")); String sinkPackage = sinkClass.getName().substring(0, sinkClass.getName().lastIndexOf(".")); return !methodPackage.equals(sinkPackage); } private boolean isTransformer(String methodSink) { for (String s : transformerMethods) if (methodSink.startsWith(s)) return true; return false; } @Override public String toString() { switch (this.checkType) { case CheckSink: if (this.methodName.isEmpty()) return "<Parameter to sink method call>"; else return "<Parameter to sink method " + this.methodName + ">"; case CheckSinkInAbstract: return "<Parameter to abstract sink>"; case CheckSource: return "<Value from source method " + methodName + " to return>"; case CheckFromMethodToSink: return "<Value from method " + methodName + " to sink method>"; case CheckFromParamToNative : return "<Value from method parameter to native method>"; case CheckFromInterfaceToResult: return "<Value from interface method to return>"; case CheckFromParamToInterface: return "<Value from parameter to interface method>"; default: break; } return ""; } }
11,483
33.694864
101
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/ParameterIsInterfaceFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.Scene; import soot.SootClass; import soot.jimple.infoflow.android.data.AndroidMethod; /** * Feature which checks whether the current method gets an interface as a * parameter * * @author Steven Arzt * */ public class ParameterIsInterfaceFeature extends AbstractSootFeature { public ParameterIsInterfaceFeature(String mapsJAR, String androidJAR) { super(mapsJAR, androidJAR); } @Override public Type appliesInternal(AndroidMethod method) { for (String paramType : method.getParameters()) { SootClass sc = Scene.v().forceResolve(paramType, SootClass.HIERARCHY); if (sc == null) return Type.NOT_SUPPORTED; return sc.isInterface() ? Type.TRUE : Type.FALSE; } // No interface type found return Type.FALSE; } @Override public String toString() { return "<Parameter is interface>"; } }
886
22.342105
73
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/PermissionNameFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.jimple.infoflow.android.data.AndroidMethod; import de.ecspride.sourcesinkfinder.IFeature; public class PermissionNameFeature implements IFeature { private final String permission; public PermissionNameFeature(String permission) { if(permission.contains(".")) this.permission = permission.substring(permission.lastIndexOf(".") + 1); else this.permission = permission; } @Override public Type applies(AndroidMethod method) { for (String perm : method.getPermissions()) { String stripped = perm; if (stripped.contains(".")) stripped = perm.substring(perm.lastIndexOf(".") + 1); if (stripped.equals(this.permission)) return Type.TRUE; } return Type.FALSE; } @Override public String toString() { return "<Permission name is " + this.permission + ">"; } @Override public boolean equals(Object other) { if (super.equals(other)) return true; if (!(other instanceof PermissionNameFeature)) return false; PermissionNameFeature pnf = (PermissionNameFeature) other; return pnf.permission.equals(this.permission); } @Override public int hashCode() { return this.permission.hashCode(); } }
1,215
23.32
75
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/ReturnTypeFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.SootMethod; import soot.jimple.infoflow.android.data.AndroidMethod; /** * Feature which checks the return type of a method * * @author Steven Arzt, Siegfried Rasthofer * */ public class ReturnTypeFeature extends AbstractSootFeature { private final String returnType; public ReturnTypeFeature(String mapsJAR, String androidJAR, String returnType) { super(mapsJAR, androidJAR); this.returnType = returnType; } @Override public Type appliesInternal(AndroidMethod method) { if(method.getReturnType().equals(this.returnType)) return Type.TRUE; SootMethod sm = getSootMethod(method); if (sm == null) return Type.NOT_SUPPORTED; try { if (this.isOfType(sm.getReturnType(), this.returnType)) return Type.TRUE; else return Type.FALSE; }catch (Exception ex) { System.err.println("Something went wrong:"); ex.printStackTrace(); return Type.NOT_SUPPORTED; } } @Override public String toString() { return "<Return type is " + this.returnType + ">"; } }
1,076
21.914894
81
java
SuSi
SuSi-master/SourceCode/src/de/ecspride/sourcesinkfinder/features/VoidOnMethodFeature.java
package de.ecspride.sourcesinkfinder.features; import soot.jimple.infoflow.android.data.AndroidMethod; import de.ecspride.sourcesinkfinder.IFeature; /** * Feature that matches whever a method returns void and the method name starts * with "on". * * @author Steven Arzt * */ public class VoidOnMethodFeature implements IFeature { public VoidOnMethodFeature() { } @Override public Type applies(AndroidMethod method) { return (method.getMethodName().startsWith("on") && (method.getReturnType().toString().equals("void") || method.getReturnType().toString().equals("boolean"))? Type.TRUE : Type.FALSE); } @Override public String toString() { return "<Method starts with on and has void/bool return type>"; } }
745
22.3125
87
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/examples/AnnotateClass.java
/* Soot - a J*va Optimization Framework * Copyright (C) 1997-1999 Raja Vallee-Rai * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ /* * Modified by the Sable Research Group and others 1997-1999. * See the 'credits' file distributed with Soot for the complete list of * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot) */ import soot.*; import soot.baf.*; import soot.jimple.*; import soot.options.Options; import soot.tagkit.*; import soot.util.*; import java.io.*; import java.util.*; /** Example of using Soot to create a classfile from scratch and annotate it. * The example proceeds as follows: * * - Create a SootClass <code>HelloWorld</code> extending java.lang.Object. * * - Create a 'main' method and add it to the class. * * - Create an empty JimpleBody and add it to the 'main' method. * * - Add locals and statements to JimpleBody. * * - Add annotations. * * - Write the result out to a class file. */ public class MyMain { public static void main(String[] args) throws FileNotFoundException, IOException { SootClass sClass; SootMethod method; // Resolve dependencies Scene.v().loadClassAndSupport("java.lang.Object"); Scene.v().loadClassAndSupport("java.lang.System"); // Declare 'public class HelloWorld' sClass = new SootClass("HelloWorld", Modifier.PUBLIC); // 'extends Object' sClass.setSuperclass(Scene.v().getSootClass("java.lang.Object")); Scene.v().addClass(sClass); // create and add the class attribute GenericAttribute classAttr = new GenericAttribute("MyClassAttr", "foo".getBytes()); sClass.addTag(classAttr); // Create the method, public static void main(String[]) method = new SootMethod("main", Arrays.asList(new Type[] {ArrayType.v(RefType.v("java.lang.String"), 1)}), VoidType.v(), Modifier.PUBLIC | Modifier.STATIC); sClass.addMethod(method); // Create and add the method attribute GenericAttribute mAttr = new GenericAttribute("MyMethodAttr", "".getBytes()); method.addTag(mAttr); // Create the method body { // create empty body JimpleBody body = Jimple.v().newBody(method); method.setActiveBody(body); Chain units = body.getUnits(); Local arg, tmpRef; Unit tmpUnit; // Add some locals, java.lang.String l0 arg = Jimple.v().newLocal("l0", ArrayType.v(RefType.v("java.lang.String"), 1)); body.getLocals().add(arg); // Add locals, java.io.printStream tmpRef tmpRef = Jimple.v().newLocal("tmpRef", RefType.v("java.io.PrintStream")); body.getLocals().add(tmpRef); // add "l0 = @parameter0" tmpUnit = Jimple.v().newIdentityStmt(arg, Jimple.v().newParameterRef(ArrayType.v(RefType.v("java.lang.String"), 1), 0)); tmpUnit.addTag(new MyTag(1)); units.add(tmpUnit); // add "tmpRef = java.lang.System.out" units.add(Jimple.v().newAssignStmt(tmpRef, Jimple.v().newStaticFieldRef( Scene.v().getField("<java.lang.System: java.io.PrintStream out>").makeRef()))); // insert "tmpRef.println("Hello world!")" { SootMethod toCall = Scene.v().getMethod("<java.io.PrintStream: void println(java.lang.String)>"); tmpUnit = Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), StringConstant.v("Hello world!"))); tmpUnit.addTag(new MyTag(2)); units.add(tmpUnit); } // insert "return" units.add(Jimple.v().newReturnVoidStmt()); } MyTagAggregator mta = new MyTagAggregator(); // convert the body to Baf method.setActiveBody( Baf.v().newBody((JimpleBody) method.getActiveBody())); // aggregate the tags and produce a CodeAttribute mta.transform(method.getActiveBody()); // write the class to a file String fileName = SourceLocator.v().getFileNameFor(sClass, Options.output_format_class); OutputStream streamOut = new JasminOutputStream( new FileOutputStream(fileName)); PrintWriter writerOut = new PrintWriter( new OutputStreamWriter(streamOut)); AbstractJasminClass jasminClass = new soot.baf.JasminClass(sClass); jasminClass.print(writerOut); writerOut.flush(); streamOut.close(); } } class MyTag implements Tag { int value; public MyTag(int value) { this.value = value; } public String getName() { return "MyTag"; } // output the value as a 4-byte array public byte[] getValue() { ByteArrayOutputStream baos = new ByteArrayOutputStream(4); DataOutputStream dos = new DataOutputStream(baos); try { dos.writeInt(value); dos.flush(); } catch(IOException e) { System.err.println(e); throw new RuntimeException(e); } return baos.toByteArray(); } } class MyTagAggregator extends TagAggregator { public String aggregatedName() { return "MyTag"; } public boolean wantTag(Tag t) { return (t instanceof MyTag); } public void considerTag(Tag t, Unit u) { units.add(u); tags.add(t); } }
6,530
33.739362
144
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/examples/BodyTransformer.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2008 Eric Bodden * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ import java.util.Map; import soot.Body; import soot.BodyTransformer; import soot.G; import soot.PackManager; import soot.Transform; import soot.toolkits.graph.ExceptionalUnitGraph; public class MyMain { public static void main(String[] args) { PackManager.v().getPack("jtp").add( new Transform("jtp.myTransform", new BodyTransformer() { protected void internalTransform(Body body, String phase, Map options) { new MyAnalysis(new ExceptionalUnitGraph(body)); // use G.v().out instead of System.out so that Soot can // redirect this output to the Eclipse console G.v().out.println(body.getMethod()); } })); soot.Main.main(args); } public static class MyAnalysis /*extends ForwardFlowAnalysis */ { public MyAnalysis(ExceptionalUnitGraph exceptionalUnitGraph) { //doAnalysis(); } } }
1,674
30.018519
77
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/examples/CreateSootClass.java
/* Soot - a J*va Optimization Framework * Copyright (C) 1997-1999 Raja Vallee-Rai * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ /* * Modified by the Sable Research Group and others 1997-1999. * See the 'credits' file distributed with Soot for the complete list of * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot) */ //package ashes.examples.createclass; import soot.*; import soot.jimple.*; import soot.options.Options; import soot.util.*; import java.io.*; import java.util.*; /** Example of using Soot to create a classfile from scratch. * The 'createclass' example creates a HelloWorld class file using Soot. * It proceeds as follows: * * - Create a SootClass <code>HelloWorld</code> extending java.lang.Object. * * - Create a 'main' method and add it to the class. * * - Create an empty JimpleBody and add it to the 'main' method. * * - Add locals and statements to JimpleBody. * * - Write the result out to a class file. */ public class MyMain { public static void main(String[] args) throws FileNotFoundException, IOException { SootClass sClass; SootMethod method; // Resolve dependencies Scene.v().loadClassAndSupport("java.lang.Object"); Scene.v().loadClassAndSupport("java.lang.System"); // Declare 'public class HelloWorld' sClass = new SootClass("HelloWorld", Modifier.PUBLIC); // 'extends Object' sClass.setSuperclass(Scene.v().getSootClass("java.lang.Object")); Scene.v().addClass(sClass); // Create the method, public static void main(String[]) method = new SootMethod("main", Arrays.asList(new Type[] {ArrayType.v(RefType.v("java.lang.String"), 1)}), VoidType.v(), Modifier.PUBLIC | Modifier.STATIC); sClass.addMethod(method); // Create the method body { // create empty body JimpleBody body = Jimple.v().newBody(method); method.setActiveBody(body); Chain units = body.getUnits(); Local arg, tmpRef; // Add some locals, java.lang.String l0 arg = Jimple.v().newLocal("l0", ArrayType.v(RefType.v("java.lang.String"), 1)); body.getLocals().add(arg); // Add locals, java.io.printStream tmpRef tmpRef = Jimple.v().newLocal("tmpRef", RefType.v("java.io.PrintStream")); body.getLocals().add(tmpRef); // add "l0 = @parameter0" units.add(Jimple.v().newIdentityStmt(arg, Jimple.v().newParameterRef(ArrayType.v(RefType.v("java.lang.String"), 1), 0))); // add "tmpRef = java.lang.System.out" units.add(Jimple.v().newAssignStmt(tmpRef, Jimple.v().newStaticFieldRef( Scene.v().getField("<java.lang.System: java.io.PrintStream out>").makeRef()))); // insert "tmpRef.println("Hello world!")" { SootMethod toCall = Scene.v().getMethod("<java.io.PrintStream: void println(java.lang.String)>"); units.add(Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), StringConstant.v("Hello world!")))); } // insert "return" units.add(Jimple.v().newReturnVoidStmt()); } String fileName = SourceLocator.v().getFileNameFor(sClass, Options.output_format_class); OutputStream streamOut = new JasminOutputStream( new FileOutputStream(fileName)); PrintWriter writerOut = new PrintWriter( new OutputStreamWriter(streamOut)); JasminClass jasminClass = new soot.jimple.JasminClass(sClass); jasminClass.print(writerOut); writerOut.flush(); streamOut.close(); } }
4,801
38.04065
145
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/examples/GotoInstrumenter.java
/* Soot - a J*va Optimization Framework * Copyright (C) 1997-1999 Raja Vallee-Rai * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ /* * Modified by the Sable Research Group and others 1997-1999. * See the 'credits' file distributed with Soot for the complete list of * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot) */ import soot.*; import soot.jimple.*; import soot.util.*; import java.util.*; /** Example to instrument a classfile to produce goto counts. */ public class MyMain { public static void main(String[] args) { if(args.length == 0) { System.out.println("Syntax: MyMain [soot options]"); System.exit(0); } PackManager.v().getPack("jtp").add(new Transform("jtp.instrumenter", GotoInstrumenter.v())); // Just in case, resolve the PrintStream and System soot-classes Scene.v().addBasicClass("java.io.PrintStream",SootClass.SIGNATURES); Scene.v().addBasicClass("java.lang.System",SootClass.SIGNATURES); soot.Main.main(args); } } /** InstrumentClass example. Instruments the given class to print out the number of Jimple goto statements executed. To enable this class, enable the given PackAdjuster by compiling it separately, into the soot package. */ class GotoInstrumenter extends BodyTransformer { private static GotoInstrumenter instance = new GotoInstrumenter(); private GotoInstrumenter() {} public static GotoInstrumenter v() { return instance; } private boolean addedFieldToMainClassAndLoadedPrintStream = false; private SootClass javaIoPrintStream; private Local addTmpRef(Body body) { Local tmpRef = Jimple.v().newLocal("tmpRef", RefType.v("java.io.PrintStream")); body.getLocals().add(tmpRef); return tmpRef; } private Local addTmpLong(Body body) { Local tmpLong = Jimple.v().newLocal("tmpLong", LongType.v()); body.getLocals().add(tmpLong); return tmpLong; } private void addStmtsToBefore(Chain units, Stmt s, SootField gotoCounter, Local tmpRef, Local tmpLong) { // insert "tmpRef = java.lang.System.out;" units.insertBefore(Jimple.v().newAssignStmt( tmpRef, Jimple.v().newStaticFieldRef( Scene.v().getField("<java.lang.System: java.io.PrintStream out>").makeRef())), s); // insert "tmpLong = gotoCounter;" units.insertBefore(Jimple.v().newAssignStmt(tmpLong, Jimple.v().newStaticFieldRef(gotoCounter.makeRef())), s); // insert "tmpRef.println(tmpLong);" SootMethod toCall = javaIoPrintStream.getMethod("void println(long)"); units.insertBefore(Jimple.v().newInvokeStmt( Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), tmpLong)), s); } protected void internalTransform(Body body, String phaseName, Map options) { SootClass sClass = body.getMethod().getDeclaringClass(); SootField gotoCounter = null; boolean addedLocals = false; Local tmpRef = null, tmpLong = null; Chain units = body.getUnits(); // Add code at the end of the main method to print out the // gotoCounter (this only works in simple cases, because you may have multiple returns or System.exit()'s ) synchronized(this) { if (!Scene.v().getMainClass(). declaresMethod("void main(java.lang.String[])")) throw new RuntimeException("couldn't find main() in mainClass"); if (addedFieldToMainClassAndLoadedPrintStream) gotoCounter = Scene.v().getMainClass().getFieldByName("gotoCount"); else { // Add gotoCounter field gotoCounter = new SootField("gotoCount", LongType.v(), Modifier.STATIC); Scene.v().getMainClass().addField(gotoCounter); javaIoPrintStream = Scene.v().getSootClass("java.io.PrintStream"); addedFieldToMainClassAndLoadedPrintStream = true; } } // Add code to increase goto counter each time a goto is encountered { boolean isMainMethod = body.getMethod().getSubSignature().equals("void main(java.lang.String[])"); Local tmpLocal = Jimple.v().newLocal("tmp", LongType.v()); body.getLocals().add(tmpLocal); Iterator stmtIt = units.snapshotIterator(); while(stmtIt.hasNext()) { Stmt s = (Stmt) stmtIt.next(); if(s instanceof GotoStmt) { AssignStmt toAdd1 = Jimple.v().newAssignStmt(tmpLocal, Jimple.v().newStaticFieldRef(gotoCounter.makeRef())); AssignStmt toAdd2 = Jimple.v().newAssignStmt(tmpLocal, Jimple.v().newAddExpr(tmpLocal, LongConstant.v(1L))); AssignStmt toAdd3 = Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(gotoCounter.makeRef()), tmpLocal); // insert "tmpLocal = gotoCounter;" units.insertBefore(toAdd1, s); // insert "tmpLocal = tmpLocal + 1L;" units.insertBefore(toAdd2, s); // insert "gotoCounter = tmpLocal;" units.insertBefore(toAdd3, s); } else if (s instanceof InvokeStmt) { InvokeExpr iexpr = (InvokeExpr) ((InvokeStmt)s).getInvokeExpr(); if (iexpr instanceof StaticInvokeExpr) { SootMethod target = ((StaticInvokeExpr)iexpr).getMethod(); if (target.getSignature().equals("<java.lang.System: void exit(int)>")) { if (!addedLocals) { tmpRef = addTmpRef(body); tmpLong = addTmpLong(body); addedLocals = true; } addStmtsToBefore(units, s, gotoCounter, tmpRef, tmpLong); } } } else if (isMainMethod && (s instanceof ReturnStmt || s instanceof ReturnVoidStmt)) { if (!addedLocals) { tmpRef = addTmpRef(body); tmpLong = addTmpLong(body); addedLocals = true; } addStmtsToBefore(units, s, gotoCounter, tmpRef, tmpLong); } } } } }
7,758
38.586735
118
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/GraphEditor.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.ui.*; import org.eclipse.gef.ui.parts.*; import org.eclipse.gef.*; import org.eclipse.gef.editparts.*; import ca.mcgill.sable.graph.model.*; import ca.mcgill.sable.graph.editparts.*; import org.eclipse.gef.palette.*; import org.eclipse.jface.action.*; import org.eclipse.gef.ui.actions.*; import ca.mcgill.sable.graph.actions.*; import java.util.*; public class GraphEditor extends GraphicalEditor { private Graph graph; /** * */ public GraphEditor() { DefaultEditDomain defaultEditDomain = new DefaultEditDomain(this); setEditDomain(defaultEditDomain); } /* (non-Javadoc) * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer() */ protected void initializeGraphicalViewer() { getGraphicalViewer().setContents(graph); } protected void configureGraphicalViewer() { super.configureGraphicalViewer(); ScalableRootEditPart root = new ScalableRootEditPart(); getGraphicalViewer().setRootEditPart(root); ZoomManager zManager = root.getZoomManager(); double [] zoomLevels = new double[10]; for (int i = 0; i < zoomLevels.length; i++){ zoomLevels[i] = (i + 1) * 0.25; } zManager.setZoomLevels(zoomLevels); IAction zoomIn = new ZoomInAction(zManager); IAction zoomOut = new ZoomOutAction(((ScalableRootEditPart)getGraphicalViewer().getRootEditPart()).getZoomManager()); getActionRegistry().registerAction(zoomIn); getActionRegistry().registerAction(zoomOut); IAction printAction = new PrintAction(this); getActionRegistry().registerAction(printAction); getSite().getKeyBindingService().registerAction(zoomIn); getSite().getKeyBindingService().registerAction(zoomOut); getGraphicalViewer().setEditPartFactory(new PartFactory()); getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer())); } public void setMenuProvider(ContextMenuProvider prov){ getGraphicalViewer().setContextMenu(prov); getSite().registerContextMenu(prov, getGraphicalViewer()); } public void setPartFactory(PartFactory factory){ getGraphicalViewer().setEditPartFactory(factory); } protected void setInput(IEditorInput input){ super.setInput(input); if (input instanceof Graph){ setGraph((Graph)input); } } /* (non-Javadoc) * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor) */ public void doSave(IProgressMonitor monitor) { } /* (non-Javadoc) * @see org.eclipse.ui.ISaveablePart#doSaveAs() */ public void doSaveAs() { } /* (non-Javadoc) * @see org.eclipse.ui.IEditorPart#gotoMarker(org.eclipse.core.resources.IMarker) */ public void gotoMarker(IMarker marker) { } /* (non-Javadoc) * @see org.eclipse.ui.ISaveablePart#isDirty() */ public boolean isDirty() { return false; } /* (non-Javadoc) * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed() */ public boolean isSaveAsAllowed() { return false; } /** * @return */ public Graph getGraph() { return graph; } /** * @param graph */ public void setGraph(Graph g) { graph = g; } public void setTitle(String name){ super.setTitle(name); } public void setTitleTooltip(String text){ super.setTitleToolTip(text); } public void createActions(){ super.createActions(); ActionRegistry registry = getActionRegistry(); IAction action = new SimpleSelectAction(this); registry.registerAction(action); getSelectionActions().add(action.getId()); } public ActionRegistry getGraphEditorActionRegistry(){ return getActionRegistry(); } public GraphicalViewer getGraphEditorGraphicalViewer(){ return getGraphicalViewer(); } public List getGraphEditorSelectionActions(){ return getSelectionActions(); } public String getToolTipText(){ return getTitle(); } public String getTitleToolTip(){ return super.getTitleToolTip(); } }
4,807
24.574468
119
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/GraphPlugin.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph; import org.eclipse.ui.plugin.*; import org.eclipse.core.runtime.*; import org.eclipse.core.resources.*; import java.util.*; import ca.mcgill.sable.graph.testing.*; /** * The main plugin class to be used in the desktop. */ public class GraphPlugin extends AbstractUIPlugin { //The shared instance. private static GraphPlugin plugin; //Resource bundle. private ResourceBundle resourceBundle; private GraphGenerator generator; /** * The constructor. */ public GraphPlugin(IPluginDescriptor descriptor) { super(descriptor); plugin = this; try { resourceBundle= ResourceBundle.getBundle("ca.mcgill.sable.graph.GraphPluginResources"); } catch (MissingResourceException x) { resourceBundle = null; } } /** * Returns the shared instance. */ public static GraphPlugin getDefault() { return plugin; } /** * Returns the workspace instance. */ public static IWorkspace getWorkspace() { return ResourcesPlugin.getWorkspace(); } /** * Returns the string from the plugin's resource bundle, * or 'key' if not found. */ public static String getResourceString(String key) { ResourceBundle bundle= GraphPlugin.getDefault().getResourceBundle(); try { return bundle.getString(key); } catch (MissingResourceException e) { return key; } } /** * Returns the plugin's resource bundle, */ public ResourceBundle getResourceBundle() { return resourceBundle; } /** * @return */ public GraphGenerator getGenerator() { return generator; } /** * @param generator */ public void setGenerator(GraphGenerator generator) { this.generator = generator; } }
2,486
23.87
90
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/actions/GraphActionBarContributor.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.actions; import org.eclipse.gef.ui.actions.ActionBarContributor; import org.eclipse.jface.action.*; import org.eclipse.gef.ui.actions.*; import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.*; public class GraphActionBarContributor extends ActionBarContributor { /** * */ public GraphActionBarContributor() { super(); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.ActionBarContributor#buildActions() */ protected void buildActions() { addRetargetAction(new ZoomInRetargetAction()); addRetargetAction(new ZoomOutRetargetAction()); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.ActionBarContributor#declareGlobalActionKeys() */ protected void declareGlobalActionKeys() { addGlobalActionKey(IWorkbenchActionConstants.PRINT); } // this is for zoom toolbar buttons public void contributeToToolBar(IToolBarManager toolBarManager){ super.contributeToToolBar(toolBarManager); toolBarManager.add(new Separator()); } public void contributeToMenu(IMenuManager menuManager){ super.contributeToMenu(menuManager); MenuManager viewMenu = new MenuManager("View"); viewMenu.add(getAction(GEFActionConstants.ZOOM_IN)); viewMenu.add(getAction(GEFActionConstants.ZOOM_OUT)); menuManager.insertAfter(IWorkbenchActionConstants.M_EDIT, viewMenu); } public void setActiveEditor(IEditorPart editor) { super.setActiveEditor(editor); } }
2,281
29.026316
82
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/actions/SimpleSelectAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.actions; import org.eclipse.gef.ui.actions.SelectionAction; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPart; public class SimpleSelectAction extends SelectionAction { private final static String SIMPLE_SELECT = "simple select"; private IWorkbenchPart part; /** * @param part */ public SimpleSelectAction(IWorkbenchPart part) { super(part); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ protected boolean calculateEnabled() { return true; } public void run(){ } /** * @return */ public IWorkbenchPart getPart() { return part; } /** * @param part */ public void setPart(IWorkbenchPart part) { this.part = part; } protected void init() { super.init(); setId( SIMPLE_SELECT ); } }
1,670
22.871429
74
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/editparts/ComplexNodeEditPart.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.editparts; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import org.eclipse.draw2d.*; import org.eclipse.gef.*; import org.eclipse.gef.editparts.*; import org.eclipse.draw2d.graph.*; import java.util.*; import ca.mcgill.sable.graph.model.*; import ca.mcgill.sable.graph.figures.*; import org.eclipse.draw2d.geometry.*; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import ca.mcgill.sable.graph.editpolicies.*; public class ComplexNodeEditPart extends AbstractGraphicalEditPart implements NodeEditPart, PropertyChangeListener { public ComplexNodeEditPart() { super(); } /* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies() */ protected void createEditPolicies() { } /* (non-Javadoc) * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart) */ public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) { return new ChopboxAnchor(getFigure()); } /* (non-Javadoc) * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart) */ public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) { return new ChopboxAnchor(getFigure()); } /* (non-Javadoc) * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.Request) */ public ConnectionAnchor getSourceConnectionAnchor(Request arg0) { return new ChopboxAnchor(getFigure()); } /* (non-Javadoc) * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.Request) */ public ConnectionAnchor getTargetConnectionAnchor(Request arg0) { return new ChopboxAnchor(getFigure()); } /* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() */ protected IFigure createFigure() { return new ComplexNodeFigure(); } public void contributeNodesToGraph(DirectedGraph graph, HashMap map){ Node node = new Node(this); node.width = getFigure().getBounds().width;//getNode().getWidth(); node.height = getFigure().getBounds().height; graph.nodes.add(node); map.put(this, node); } public void contributeEdgesToGraph(DirectedGraph graph, HashMap map) { List outgoing = getSourceConnections(); for (int i = 0; i < outgoing.size(); i++){ EdgeEditPart edge = (EdgeEditPart)outgoing.get(i); edge.contributeToGraph(graph, map); } } public void applyGraphResults(DirectedGraph graph, HashMap map){ SimpleNode node = (SimpleNode)map.get(this); List outgoing = getSourceConnections(); for (int i = 0; i < outgoing.size(); i++){ EdgeEditPart edge = (EdgeEditPart)outgoing.get(i); edge.applyGraphResults(graph, map); } } public ComplexNode getNode(){ return (ComplexNode)getModel(); } public List getModelChildren(){ return ((ComplexNode)getNode()).getChildren(); } public void propertyChange(PropertyChangeEvent event){ if (event.getPropertyName().equals(Element.COMPLEX_CHILD)){ refreshChildren(); } } protected void refreshVisuals(){ Iterator it = getChildren().iterator(); while (it.hasNext()){ Object next = it.next(); if (next instanceof SimpleNodeEditPart){ getFigure().add(((SimpleNodeEditPart)next).getFigure()); getFigure().setSize(getFigure().getBounds().width+((SimpleNodeEditPart)next).getFigure().getBounds().width, getFigure().getBounds().height+((SimpleNodeEditPart)next).getFigure().getBounds().height); } else if (next instanceof GraphEditPart){ getFigure().add(((GraphEditPart)next).getFigure()); getFigure().setSize(getFigure().getBounds().width+((GraphEditPart)next).getFigureWidth(), getFigure().getBounds().height+((GraphEditPart)next).getFigureHeight()); } } } }
4,632
30.517007
202
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/editparts/EdgeEditPart.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.editparts; import org.eclipse.gef.editparts.AbstractConnectionEditPart; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.draw2d.*; import org.eclipse.draw2d.graph.*; import java.util.*; import java.beans.*; import org.eclipse.draw2d.*; import ca.mcgill.sable.graph.model.Element; public class EdgeEditPart extends AbstractConnectionEditPart implements PropertyChangeListener { Font f = new Font(null, "Arial", 8, SWT.NORMAL); public EdgeEditPart() { super(); } /* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies() */ protected void createEditPolicies() { } protected IFigure createFigure(){ PolylineConnection conn = new PolylineConnection(); conn.setTargetDecoration(new PolygonDecoration()); conn.setConnectionRouter(new BendpointConnectionRouter()); if (((ca.mcgill.sable.graph.model.Edge)getModel()).getLabel() != null){ Label connLabel = new Label(((ca.mcgill.sable.graph.model.Edge)getModel()).getLabel()); connLabel.setFont(f); conn.add(connLabel); conn.getLayoutManager().setConstraint(connLabel, new MidpointLocator(conn, 0)); } return conn; } public void contributeToGraph(DirectedGraph graph, HashMap map){ Node source = (Node)map.get(getSource()); Node target = (Node)map.get(getTarget()); if (!source.equals(target)){ Edge e = new Edge(this, source, target); graph.edges.add(e); map.put(this, e); } } public void applyGraphResults(DirectedGraph graph, HashMap map){ Edge e = (Edge)map.get(this); if (e != null) { NodeList nl = e.vNodes; PolylineConnection conn = (PolylineConnection)getConnectionFigure(); if (nl != null){ ArrayList bends = new ArrayList(); for (int i = 0; i < nl.size(); i++){ Node n = nl.getNode(i); int x = n.x; int y = n.y; if (e.isFeedback){ bends.add(new AbsoluteBendpoint(x, y + n.height)); bends.add(new AbsoluteBendpoint(x, y)); } else { bends.add(new AbsoluteBendpoint(x, y)); bends.add(new AbsoluteBendpoint(x, y + n.height)); } } conn.setRoutingConstraint(bends); } else { conn.setRoutingConstraint(Collections.EMPTY_LIST); } } } public Edge getEdge(){ return (Edge)getModel(); } public void propertyChange(PropertyChangeEvent event){ if (event.getPropertyName().equals(Element.EDGE_LABEL)){ refreshVisuals(); } } public void refreshVisuals(){ if (((ca.mcgill.sable.graph.model.Edge)getModel()).getLabel() != null){ Label connLabel = new Label(((ca.mcgill.sable.graph.model.Edge)getModel()).getLabel()); connLabel.setFont(f); ((PolylineConnection)getFigure()).add(connLabel); ((PolylineConnection)getFigure()).getLayoutManager().setConstraint(connLabel, new MidpointLocator((PolylineConnection)getFigure(), 0)); } getFigure().revalidate(); } public void activate(){ super.activate(); ((ca.mcgill.sable.graph.model.Edge)getModel()).addPropertyChangeListener(this); } public void deactivate(){ super.deactivate(); ((ca.mcgill.sable.graph.model.Edge)getModel()).removePropertyChangeListener(this); } }
4,013
28.733333
138
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/editparts/GraphEditPart.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.editparts; import org.eclipse.draw2d.*; import org.eclipse.gef.editparts.*; import org.eclipse.draw2d.graph.*; import org.eclipse.gef.*; import org.eclipse.draw2d.geometry.*; import java.util.*; import ca.mcgill.sable.graph.model.*; import java.beans.*; public class GraphEditPart extends AbstractGraphicalEditPart implements PropertyChangeListener { private int figureWidth = 20000; private int figureHeight = 20000; public GraphEditPart() { super(); } /* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() */ protected IFigure createFigure() { IFigure f = new Figure() { public void setBound(Rectangle rect){ int x = bounds.x; int y = bounds.y; boolean resize = (rect.width != bounds.width) || (rect.height != bounds.height), translate = (rect.x != x) || (rect.y != y); if (isVisible() && (resize || translate)) erase(); if (translate) { int dx = rect.x - x; int dy = rect.y - y; primTranslate(dx, dy); } bounds.width = rect.width; bounds.height = rect.height; if (resize || translate) { fireMoved(); repaint(); } } }; f.setLayoutManager(new GraphLayoutManager(this)); return f; } protected void setFigure(IFigure figure){ figure.getBounds().setSize(getFigureWidth(),getFigureHeight()); super.setFigure(figure); } /* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies() */ protected void createEditPolicies() { } public void contributeNodesToGraph(DirectedGraph graph, HashMap map){ Iterator it = getChildren().iterator(); while (it.hasNext()){ Object next = it.next(); if (next instanceof SimpleNodeEditPart){ SimpleNodeEditPart child = (SimpleNodeEditPart)next; child.contributeNodesToGraph(graph, map); } } } public void contributeEdgesToGraph(DirectedGraph graph, HashMap map){ Iterator it = getChildren().iterator(); while (it.hasNext()){ Object next = it.next(); if (next instanceof SimpleNodeEditPart){ ((SimpleNodeEditPart)next).contributeEdgesToGraph(graph, map); } } } public void applyGraphResults(DirectedGraph graph, HashMap map){ Iterator it = getChildren().iterator(); while (it.hasNext()){ Object next = it.next(); if (next instanceof SimpleNodeEditPart){ ((SimpleNodeEditPart)next).applyGraphResults(graph, map); } } determineGraphBounds(graph); } private void determineGraphBounds(DirectedGraph graph){ Iterator it = graph.nodes.iterator(); int width = 0; int height = 0; while (it.hasNext()){ Node n = (Node)it.next(); if (width < n.x){ width = n.x + 300; } height = max(height, n.height); } setFigureWidth(width); setFigureHeight(height); } private int max(int i, int j){ return i < j ? j : i; } public Graph getGraph(){ return (Graph)getModel(); } public List getModelChildren(){ return getGraph().getChildren(); } public void activate(){ super.activate(); getGraph().addPropertyChangeListener(this); } public void deactivate(){ super.deactivate(); getGraph().removePropertyChangeListener(this); } public void propertyChange(PropertyChangeEvent event){ if (event.getPropertyName().equals(Element.GRAPH_CHILD)){ refreshChildren(); } getFigure().revalidate(); ((GraphicalEditPart)(getViewer().getContents())).getFigure().revalidate(); } /** * @return */ public int getFigureHeight() { return figureHeight; } /** * @return */ public int getFigureWidth() { return figureWidth; } /** * @param i */ public void setFigureHeight(int i) { figureHeight = i; } /** * @param i */ public void setFigureWidth(int i) { figureWidth = i; } }
4,625
22.13
84
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/editparts/GraphLayoutManager.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.editparts; import org.eclipse.draw2d.AbstractLayout; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.geometry.*; import org.eclipse.draw2d.graph.*; import java.util.*; public class GraphLayoutManager extends AbstractLayout { private GraphEditPart graphPart; public GraphLayoutManager(GraphEditPart graphPart) { setGraphPart(graphPart); } /* (non-Javadoc) * @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, int, int) */ protected Dimension calculatePreferredSize( IFigure arg0, int arg1, int arg2) { return null; } /* (non-Javadoc) * @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure) */ public void layout(IFigure arg0) { DirectedGraph graph = new DirectedGraph(); HashMap map = new HashMap(); // add nodes and edges to graph // retrieve them from CFGGraphEditPart getGraphPart().contributeNodesToGraph(graph, map); getGraphPart().contributeEdgesToGraph(graph, map); if (graph.nodes.size() != 0){ DirectedGraphLayout layout = new DirectedGraphLayout(); layout.visit(graph); getGraphPart().applyGraphResults(graph, map); } } /** * @return */ public GraphEditPart getGraphPart() { return graphPart; } /** * @param part */ public void setGraphPart(GraphEditPart part) { graphPart = part; } }
2,206
26.246914
103
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/editparts/PartFactory.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.editparts; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPartFactory; import ca.mcgill.sable.graph.model.*; public class PartFactory implements EditPartFactory { public PartFactory() { super(); } /* (non-Javadoc) * @see org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, java.lang.Object) */ public EditPart createEditPart(EditPart arg0, Object arg1) { EditPart part = null; if (arg1 instanceof Graph){ part = new GraphEditPart(); } else if (arg1 instanceof SimpleNode){ part = new SimpleNodeEditPart(); } else if (arg1 instanceof Edge){ part = new EdgeEditPart(); } else if (arg1 instanceof ComplexNode){ part = new ComplexNodeEditPart(); } part.setModel(arg1); return part; } }
1,627
28.071429
99
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/editparts/SimpleNodeEditPart.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.editparts; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import org.eclipse.draw2d.*; import org.eclipse.gef.*; import org.eclipse.gef.editparts.*; import org.eclipse.draw2d.graph.*; import java.util.*; import ca.mcgill.sable.graph.model.*; import ca.mcgill.sable.graph.figures.*; import org.eclipse.draw2d.geometry.*; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import ca.mcgill.sable.graph.editpolicies.*; import ca.mcgill.sable.graph.*; public class SimpleNodeEditPart extends AbstractGraphicalEditPart implements NodeEditPart, PropertyChangeListener { private Object data; public SimpleNodeEditPart() { super(); } /* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() */ protected IFigure createFigure() { RectangleFigure rect = new RectangleFigure(); ToolbarLayout layout = new ToolbarLayout(); layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER); rect.setLayoutManager(layout); Label label = new Label(); label.getInsets().top = 1; label.getInsets().bottom = 1; label.getInsets().right = 1; label.getInsets().left = 1; rect.add(label); return rect; } public void contributeNodesToGraph(DirectedGraph graph, HashMap map){ Node node = new Node(this); node.width = getFigure().getBounds().width;//getNode().getWidth(); node.height = getFigure().getBounds().height; graph.nodes.add(node); map.put(this, node); } public void contributeEdgesToGraph(DirectedGraph graph, HashMap map) { List outgoing = getSourceConnections(); for (int i = 0; i < outgoing.size(); i++){ EdgeEditPart edge = (EdgeEditPart)outgoing.get(i); edge.contributeToGraph(graph, map); } } public void applyGraphResults(DirectedGraph graph, HashMap map){ Node node = (Node)map.get(this); if (node != null){ getFigure().setBounds(new Rectangle(node.x+10, node.y, node.width, node.height));//getFigure().getBounds().height));//getFigure().getBounds().height)); List outgoing = getSourceConnections(); for (int i = 0; i < outgoing.size(); i++){ EdgeEditPart edge = (EdgeEditPart)outgoing.get(i); edge.applyGraphResults(graph, map); } } } public SimpleNode getNode(){ return (SimpleNode)getModel(); } /* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies() */ protected void createEditPolicies() { } public List getModelSourceConnections(){ return getNode().getOutputs(); } public List getModelTargetConnections(){ return getNode().getInputs(); } /* (non-Javadoc) * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart) */ public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) { return new ChopboxAnchor(getFigure()); } /* (non-Javadoc) * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart) */ public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) { return new ChopboxAnchor(getFigure()); } /* (non-Javadoc) * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.Request) */ public ConnectionAnchor getSourceConnectionAnchor(Request arg0) { return new ChopboxAnchor(getFigure()); } /* (non-Javadoc) * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.Request) */ public ConnectionAnchor getTargetConnectionAnchor(Request arg0) { return new ChopboxAnchor(getFigure()); } public void activate(){ super.activate(); getNode().addPropertyChangeListener(this); } public void deactivate(){ super.deactivate(); getNode().removePropertyChangeListener(this); } public void propertyChange(PropertyChangeEvent event){ if (event.getPropertyName().equals(Element.DATA)){ //System.out.println("new val: "+event.getNewValue()); setData(event.getNewValue()); refreshVisuals(); } else if (event.getPropertyName().equals(Element.INPUTS)){ refreshTargetConnections(); } else if (event.getPropertyName().equals(Element.OUTPUTS)){ refreshSourceConnections(); } } public List getModelChildren(){ return getNode().getChildren(); } protected void refreshVisuals(){ Iterator it = getFigure().getChildren().iterator(); while (it.hasNext()){ Object next = it.next(); if (next instanceof Label){ ((Label)next).setText(getData().toString()); if (getData() != null){ getFigure().setSize((getData().toString().length()*7)+10, ((((Label)next).getBounds().height/2)+10)); getFigure().revalidate(); ((GraphEditPart)getParent()).getFigure().revalidate(); } } } } private boolean expanded; private boolean topLevel; private boolean bottomLevel; public void switchToComplex(){ GraphPlugin.getDefault().getGenerator().expandGraph(getNode()); } /** * @return */ public Object getData() { return data; } /** * @param string */ public void setData(Object obj) { data = obj; } /** * @return */ public boolean isBottomLevel() { return bottomLevel; } /** * @return */ public boolean isExpanded() { return expanded; } /** * @return */ public boolean isTopLevel() { return topLevel; } /** * @param b */ public void setBottomLevel(boolean b) { bottomLevel = b; } /** * @param b */ public void setExpanded(boolean b) { expanded = b; } /** * @param b */ public void setTopLevel(boolean b) { topLevel = b; } }
6,380
23.637066
154
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/editpolicies/SimpleNodeMouseListener.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.editpolicies; import org.eclipse.draw2d.MouseEvent; import org.eclipse.draw2d.MouseListener; public class SimpleNodeMouseListener implements MouseListener { public SimpleNodeMouseListener() { super(); } /* (non-Javadoc) * @see org.eclipse.draw2d.MouseListener#mousePressed(org.eclipse.draw2d.MouseEvent) */ public void mousePressed(MouseEvent me) { if (me.getState() == MouseEvent.BUTTON1) { } else if (me.getState() == MouseEvent.BUTTON3) { } } /* (non-Javadoc) * @see org.eclipse.draw2d.MouseListener#mouseReleased(org.eclipse.draw2d.MouseEvent) */ public void mouseReleased(MouseEvent me) { } /* (non-Javadoc) * @see org.eclipse.draw2d.MouseListener#mouseDoubleClicked(org.eclipse.draw2d.MouseEvent) */ public void mouseDoubleClicked(MouseEvent me) { } }
1,666
27.254237
91
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/editpolicies/SimpleNodeSelectPolicy.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.editpolicies; import org.eclipse.gef.editpolicies.*; import org.eclipse.draw2d.*; import org.eclipse.gef.*; import org.eclipse.gef.requests.*; import ca.mcgill.sable.graph.editparts.*; public class SimpleNodeSelectPolicy extends SelectionEditPolicy { public SimpleNodeSelectPolicy() { super(); } /* (non-Javadoc) * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#hideSelection() */ protected void hideSelection() { } /* (non-Javadoc) * @see org.eclipse.gef.editpolicies.SelectionEditPolicy#showSelection() */ protected void showSelection() { ((SimpleNodeEditPart)getHost()).setSelected(EditPart.SELECTED);//switchToComplex(); } public void showTargetFeedback(Request request){ } }
1,580
27.232143
85
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/figures/ComplexNodeFigure.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.figures; import org.eclipse.draw2d.Figure; import org.eclipse.draw2d.*; public class ComplexNodeFigure extends Figure { public ComplexNodeFigure() { ToolbarLayout layout = new ToolbarLayout(); this.setLayoutManager(layout); } }
1,099
28.72973
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/model/ComplexNode.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.model; import java.util.*; public class ComplexNode extends Element { private ArrayList children = new ArrayList(); public ComplexNode() { super(); } public void addChild(Element child){ if (getChildren() == null){ setChildren(new ArrayList()); } getChildren().add(child); fireStructureChange(COMPLEX_CHILD, child); } /** * @return */ public ArrayList getChildren() { return children; } /** * @param list */ public void setChildren(ArrayList list) { children = list; } }
1,375
23.571429
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/model/Edge.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.model; public class Edge extends Element { private SimpleNode src; private SimpleNode tgt; private String label; /** * @return Returns the label. */ public String getLabel() { return label; } /** * @param label The label to set. */ public void setLabel(String label) { this.label = label; fireStructureChange(EDGE_LABEL, label); } /** * */ public Edge(SimpleNode src, SimpleNode tgt) { setSrc(src); setTgt(tgt); src.addOutput(this); tgt.addInput(this); } /** * @return */ public SimpleNode getSrc() { return src; } /** * @param node */ public void setSrc(SimpleNode node) { src = node; } /** * @return */ public SimpleNode getTgt() { return tgt; } /** * @param node */ public void setTgt(SimpleNode node) { tgt = node; } }
1,664
19.555556
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/model/Element.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.model; import org.eclipse.ui.views.properties.IPropertyDescriptor; import org.eclipse.ui.views.properties.IPropertySource; import java.beans.*; public class Element implements IPropertySource { public static final String GRAPH_CHILD = "graph child"; public static final String COMPLEX_CHILD = "complex child"; public static final String INPUTS = "inputs"; public static final String OUTPUTS = "outputs"; public static final String DATA = "data"; public static final String COMPLEX_CHILD_ADDED = "complex child added"; public static final String EDGE_LABEL = "edge label"; public Element() { super(); } protected PropertyChangeSupport listeners = new PropertyChangeSupport(this); public void addPropertyChangeListener(PropertyChangeListener l){ listeners.addPropertyChangeListener(l); } protected void firePropertyChange(String name, Object oldVal, Object newVal){ listeners.firePropertyChange(name, oldVal, newVal); } protected void firePropertyChange(String name, Object newVal){ firePropertyChange(name, null, newVal); } public void removePropertyChangeListener(PropertyChangeListener l){ listeners.removePropertyChangeListener(l); } public void fireStructureChange(String name, Object newVal){ firePropertyChange(name, null, newVal); } /* (non-Javadoc) * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue() */ public Object getEditableValue() { return null; } /* (non-Javadoc) * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() */ public IPropertyDescriptor[] getPropertyDescriptors() { return null; } /* (non-Javadoc) * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) */ public Object getPropertyValue(Object id) { return null; } /* (non-Javadoc) * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object) */ public boolean isPropertySet(Object id) { return false; } /* (non-Javadoc) * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object) */ public void resetPropertyValue(Object id) { } /* (non-Javadoc) * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object) */ public void setPropertyValue(Object id, Object value) { } }
3,197
29.75
109
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/model/Graph.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.model; import java.util.*; import org.eclipse.ui.*; import org.eclipse.core.resources.*; import org.eclipse.jface.resource.*; public class Graph extends Element implements IEditorInput { private ArrayList children = new ArrayList(); private IResource resource; private String name; public Graph() { super(); } public void addChild(SimpleNode child){ if (getChildren() == null){ setChildren(new ArrayList()); } getChildren().add(child); fireStructureChange(GRAPH_CHILD, child); } public void removeChild(SimpleNode child){ if (getChildren() == null)return; if (getChildren().contains(child)){ getChildren().remove(child); fireStructureChange(GRAPH_CHILD, child); } } public void removeAllChildren(){ setChildren(new ArrayList()); fireStructureChange(GRAPH_CHILD, null); } /** * @return */ public ArrayList getChildren() { return children; } /** * @param list */ public void setChildren(ArrayList list) { children = list; } public boolean exists(){ return false; } public ImageDescriptor getImageDescriptor(){ return null; } public IPersistableElement getPersistable(){ return null; } public String getToolTipText(){ return getName(); } public Object getAdapter(Class c){ if (c == IResource.class){ return getResource(); } return null; } /** * @return */ public IResource getResource() { return resource; } /** * @param resource */ public void setResource(IResource resource) { this.resource = resource; } /** * @return */ public String getName() { return name; } /** * @param string */ public void setName(String string) { name = string; } }
2,554
19.277778
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/model/SimpleNode.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.model; import java.util.*; public class SimpleNode extends Element { private ArrayList inputs; private ArrayList outputs; protected Object data; private ArrayList children = new ArrayList(); public SimpleNode() { super(); } public void addInput(Edge e){ if (getInputs() == null){ setInputs(new ArrayList()); } getInputs().add(e); fireStructureChange(INPUTS, e); } public void addOutput(Edge e){ if (getOutputs() == null){ setOutputs(new ArrayList()); } getOutputs().add(e); fireStructureChange(OUTPUTS, e); } public void removeInput(Edge e){ if (getInputs() == null) return; if (getInputs().contains(e)){ getInputs().remove(e); fireStructureChange(INPUTS, e); } } public void removeOutput(Edge e){ if (getOutputs() == null) return; if (getOutputs().contains(e)){ getOutputs().remove(e); fireStructureChange(OUTPUTS, e); } } public void removeAllInputs(){ if (getInputs() == null) return; Iterator it = getInputs().iterator(); while (it.hasNext()){ Edge e = (Edge)it.next(); e.getSrc().removeOutput(e); } setInputs(new ArrayList()); fireStructureChange(INPUTS, null); } public void removeAllOutputs(){ if (getOutputs() == null) return; Iterator it = getOutputs().iterator(); while (it.hasNext()){ Edge e = (Edge)it.next(); e.getTgt().removeInput(e); } setOutputs(new ArrayList()); fireStructureChange(OUTPUTS, null); } /** * @return */ public ArrayList getInputs() { return inputs; } /** * @return */ public ArrayList getOutputs() { return outputs; } /** * @param list */ public void setInputs(ArrayList list) { inputs = list; } /** * @param list */ public void setOutputs(ArrayList list) { outputs = list; } /** * @return */ public Object getData() { return data; } /** * @param string */ public void setData(Object string) { data = string; firePropertyChange(DATA, data.toString()); } /** * @return */ public ArrayList getChildren() { return children; } /** * @param list */ public void setChildren(ArrayList list) { children = list; } public void addChild(SimpleNode sn){ children.add(sn); fireStructureChange(COMPLEX_CHILD_ADDED, sn); } }
3,113
19.220779
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/testing/GraphGenerator.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.testing; import org.eclipse.ui.*; import org.eclipse.jface.action.*; import org.eclipse.jface.viewers.*; import ca.mcgill.sable.graph.*; import ca.mcgill.sable.graph.model.*; import org.eclipse.core.runtime.*; import java.util.*; import java.lang.reflect.*; public class GraphGenerator implements IWorkbenchWindowActionDelegate { private ArrayList children = new ArrayList(); private Graph graph; public GraphGenerator() { } public void run(IAction action){ IWorkbenchPage page = GraphPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); try{ setGraph(new Graph()); IEditorPart part = page.openEditor(graph, "ca.mcgill.sable.graph.GraphEditor"); handleChildren(); } catch (PartInitException e3){ e3.printStackTrace(); } catch (Exception e2){ e2.printStackTrace(); } } public void buildModel(){ GraphPlugin.getDefault().setGenerator(this); TestNode p1 = new TestNode(); p1.setData("P1"); TestNode p2 = new TestNode(); p2.setData("P2"); p1.addOutput(p2); TestNode c1 = new TestNode(); TestNode c2 = new TestNode(); TestNode c3 = new TestNode(); p1.addChild(c1); p1.addChild(c2); p1.addChild(c3); c1.addOutput(c2); c1.addOutput(c3); c1.addOutput(p2); c3.addOutput(p2); c1.setData("C1"); c2.setData("C2"); c3.setData("C3"); TestNode c4 = new TestNode(); TestNode c5 = new TestNode(); p2.addChild(c4); p2.addChild(c5); c4.addOutput(c5); c1.addOutput(c4); c3.addOutput(c4); p1.addOutput(c4); c4.setData("C4"); c5.setData("C5"); getChildren().add(p1); getChildren().add(p2); handleChildren(); } HashMap map; private void handleChildren(){ getGraph().removeAllChildren(); map = new HashMap(); Iterator it = getChildren().iterator(); while (it.hasNext()){ TestNode tn = (TestNode)it.next(); SimpleNode sn = new SimpleNode(); getGraph().addChild(sn); sn.setData(tn.getData()); sn.setChildren(tn.getChildren()); map.put(tn, sn); } Iterator it2 = getChildren().iterator(); while (it2.hasNext()){ TestNode tn = (TestNode)it2.next(); SimpleNode src = (SimpleNode)map.get(tn); Iterator eIt = tn.getOutputs().iterator(); while (eIt.hasNext()){ Object endTn = eIt.next(); SimpleNode tgt = (SimpleNode)map.get(endTn); if (tgt != null){ Edge e = new Edge(src, tgt); } } } } public void expandGraph(SimpleNode node){ Iterator it = getChildren().iterator(); TestNode tn = null; while (it.hasNext()){ tn = (TestNode)it.next(); if (map.get(tn).equals(node)) break; } if (tn != null){ if (tn.getChildren().size() > 0){ getChildren().remove(tn); } } Iterator childIt = node.getChildren().iterator(); while (childIt.hasNext()){ TestNode test = (TestNode)childIt.next(); getChildren().add(test); } handleChildren(); } public void dispose(){ } public void selectionChanged(IAction action, ISelection sel){ } public void init(IWorkbenchWindow window){ } /** * @return */ public ArrayList getChildren() { return children; } /** * @param list */ public void setChildren(ArrayList list) { children = list; } /** * @return */ public Graph getGraph() { return graph; } /** * @param graph */ public void setGraph(Graph graph) { this.graph = graph; } }
4,258
20.510101
107
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/graph/testing/TestNode.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.graph.testing; import java.util.*; public class TestNode { private String data; private ArrayList outputs = new ArrayList(); private ArrayList children = new ArrayList(); /** * */ public TestNode() { super(); } public void addOutput(TestNode tn){ getOutputs().add(tn); } public void addChild(TestNode tn){ getChildren().add(tn); } /** * @return */ public String getData() { return data; } /** * @return */ public ArrayList getOutputs() { return outputs; } /** * @param string */ public void setData(String string) { data = string; } /** * @param list */ public void setOutputs(ArrayList list) { outputs = list; } /** * @return */ public ArrayList getChildren() { return children; } /** * @param list */ public void setChildren(ArrayList list) { children = list; } }
1,707
18.409091
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/ISootConstants.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot; public interface ISootConstants { public static final String SOOT_OUTPUT_VIEW_ID = "ca.mcgill.sable.soot.ui.sootoutputview.view"; public static final String SOOT_PLUGIN_ID = "ca.mcgill.sable.soot"; public static final String SOOT_PLUGIN_RESOURCES_ID = "ca.mcgill.sable.soot.SootPluginResources"; public static final String JIMPLE_EXT = "jimple"; public static final String CLASS_EXT = "class"; public static final String JAVA_EXT = "java"; public static final String ICON_PATH = "icons/"; public static final String ANALYSIS_KEY_VIEW_ID = "ca.mcgill.sable.soot.ui.analysiskeyview.view"; public static final String ANALYSIS_TYPES_VIEW_ID = "ca.mcgill.sable.soot.ui.analysistypesview.view"; }
1,588
32.808511
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/Messages.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot; import java.util.MissingResourceException; import java.util.ResourceBundle; public class Messages { private static final String BUNDLE_NAME = "ca.mcgill.sable.soot.default"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); /** * */ private Messages() { } /** * @param key * @return */ public static String getString(String key) { try { return RESOURCE_BUNDLE.getString(key); } catch (MissingResourceException e) { return '!' + key + '!'; } } }
1,397
26.96
88
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/SootClasspathVariableInitializer.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2008 Eric Bodden * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot; import java.io.File; import java.io.IOException; import java.net.URL; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.jdt.core.ClasspathVariableInitializer; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.osgi.framework.Bundle; /** * This adds a classpath variable "SOOTCLASSES" to the eclipse environment. * The variable points to lib/sootclasses.jar in the plugin ca.mcgill.sable.soot.lib. * * @author Eric Bodden */ public class SootClasspathVariableInitializer extends ClasspathVariableInitializer { //the following heavily depend on plugin.xml and the projects' structure! public static final String VARIABLE_NAME_CLASSES = "SOOTCLASSES"; public static final String VARIABLE_NAME_SOURCE = "SOOTSRC"; private static final String LIBRARY_PLUGIN_NAME = "ca.mcgill.sable.soot.lib"; private static final String RELATIVE_PATH_CLASSES_JAR = "lib/sootclasses.jar"; private static final String RELATIVE_PATH_SRC_ZIP = "lib/sootsrc.zip"; @Override public void initialize(String variable) { if (variable.equals(VARIABLE_NAME_CLASSES)) { //$NON-NLS-1$ String jarPath = getSootFilePath(RELATIVE_PATH_CLASSES_JAR); if(jarPath==null) return; try { JavaCore.setClasspathVariable(VARIABLE_NAME_CLASSES, //$NON-NLS-1$ new Path(jarPath), new NullProgressMonitor()); } catch (JavaModelException e) { e.printStackTrace(); } } if (variable.equals(VARIABLE_NAME_SOURCE)) { //$NON-NLS-1$ String jarPath = getSootFilePath(RELATIVE_PATH_SRC_ZIP); if(jarPath==null) return; try { JavaCore.setClasspathVariable(VARIABLE_NAME_SOURCE, //$NON-NLS-1$ new Path(jarPath), new NullProgressMonitor()); } catch (JavaModelException e) { e.printStackTrace(); } } } /** * Code copied from AJDT implementation http://www.eclipse.org/ajdt * org.eclipse.ajdt.internal.core.AspectJRTInitializer * @param relativePath */ private static String getSootFilePath(String relativePath) { StringBuffer cpath = new StringBuffer(); // This returns the bundle with the highest version or null if none // found // - for Eclipse 3.0 compatibility Bundle ajdeBundle = Platform .getBundle(LIBRARY_PLUGIN_NAME); String pluginLoc = null; // 3.0 using bundles instead of plugin descriptors if (ajdeBundle != null) { URL installLoc = ajdeBundle.getEntry("/"); //$NON-NLS-1$ URL resolved = null; try { resolved = FileLocator.resolve(installLoc); pluginLoc = resolved.toExternalForm(); } catch (IOException e) { } } if (pluginLoc != null) { if (pluginLoc.startsWith("file:")) { //$NON-NLS-1$ cpath.append(pluginLoc.substring("file:".length())); //$NON-NLS-1$ cpath.append(relativePath); //$NON-NLS-1$ } } String sootJarPath = null; // Verify that the file actually exists at the plugins location // derived above. If not then it might be because we are inside // a runtime workbench. Check under the workspace directory. if (new File(cpath.toString()).exists()) { // File does exist under the plugins directory sootJarPath = cpath.toString(); } else { // File does *not* exist under plugins. Try under workspace... IPath rootPath = SootPlugin.getWorkspace().getRoot() .getLocation(); IPath installPath = rootPath.removeLastSegments(1); cpath = new StringBuffer().append(installPath.toOSString()); cpath.append(File.separator); // TODO: what if the workspace isn't called workspace!!! cpath.append("workspace"); //$NON-NLS-1$ cpath.append(File.separator); cpath.append(LIBRARY_PLUGIN_NAME); cpath.append(File.separator); cpath.append("aspectjrt.jar"); //$NON-NLS-1$ // Only set the aspectjrtPath if the jar file exists here. if (new File(cpath.toString()).exists()) sootJarPath = cpath.toString(); } return sootJarPath; } }
4,900
33.758865
85
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/SootConsoleFactory.java
package ca.mcgill.sable.soot; import org.eclipse.ui.console.IConsoleFactory; /** * This implements the extension point org.eclipse.ui.console.consoleFactories, * showing a widget to open the Soot console in the console view. * @author Eric Bodden */ public class SootConsoleFactory implements IConsoleFactory { public void openConsole() { SootPlugin.getDefault().showConsole(); } }
394
22.235294
79
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/SootPlugin.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Vector; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.IConsole; import org.eclipse.ui.console.IConsoleManager; import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.plugin.AbstractUIPlugin; import ca.mcgill.sable.soot.editors.ColorManager; import ca.mcgill.sable.soot.interaction.DataKeeper; import ca.mcgill.sable.soot.launching.ISootOutputEventListener; import ca.mcgill.sable.soot.launching.SootDocument; import ca.mcgill.sable.soot.launching.SootOutputEvent; import ca.mcgill.sable.soot.resources.SootPartManager; import ca.mcgill.sable.soot.resources.SootResourceManager; import ca.mcgill.sable.soot.resources.SootWorkbenchListener; /** * The main plugin class to be used in the desktop. */ public class SootPlugin extends AbstractUIPlugin { //The shared instance. private static SootPlugin plugin; //Resource bundle. private ResourceBundle resourceBundle; // used for showing soot ouptut private SootDocument soot_output_doc; // listeners for soot output events private Vector sootOutputEventListeners = new Vector(); // list of jimple editor viewers private ArrayList editorViewers = new ArrayList(); private SootPartManager partManager; private ColorManager colorManager; private DataKeeper dataKeeper; private Font sootFont = new Font(null, "Arial", 8, SWT.NORMAL); private IProject currentProject; private MessageConsole findConsole(String name) { ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); IConsole[] existing = conMan.getConsoles(); for (int i = 0; i < existing.length; i++) if (name.equals(existing[i].getName())) return (MessageConsole) existing[i]; // no console found, so create a new one MessageConsole myConsole = new MessageConsole(name, null); conMan.addConsoles(new IConsole[] { myConsole }); return myConsole; } public MessageConsole getConsole() { if(console==null) { console = findConsole("Soot"); } return console; } public void showConsole() { ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); conMan.showConsoleView(getConsole()); } /** * Method addSootOutputEventListener. * @param listener */ public void addSootOutputEventListener(ISootOutputEventListener listener) { sootOutputEventListeners.add(listener); } /** * Method removeSootOutputEventListener. * @param listener */ public void removeSootOutputEventListener(ISootOutputEventListener listener) { sootOutputEventListeners.remove(listener); } /** * Method fireSootOutputEvent. * @param event */ public void fireSootOutputEvent(SootOutputEvent event) { Iterator it = sootOutputEventListeners.iterator(); while (it.hasNext()) { ((ISootOutputEventListener)it.next()).handleSootOutputEvent(event); } } /** * The constructor. */ public SootPlugin(IPluginDescriptor descriptor) { super(descriptor); plugin = this; // should work from startUp method soot_output_doc = new SootDocument(); soot_output_doc.startUp(); try { resourceBundle= ResourceBundle.getBundle(ISootConstants.SOOT_PLUGIN_RESOURCES_ID); } catch (MissingResourceException x) { resourceBundle = null; } // maybe should go in startUp method // resource manager setManager(new SootResourceManager()); PlatformUI.getWorkbench().addWindowListener(new SootWorkbenchListener()); setPartManager(new SootPartManager()); } // used for getting any needed images for content outline // and possibly for attribute markers public static ImageDescriptor getImageDescriptor(String name){ try { URL installURL = getDefault().getDescriptor().getInstallURL(); URL iconURL = new URL(installURL, ISootConstants.ICON_PATH + name); return ImageDescriptor.createFromURL(iconURL); } catch (MalformedURLException e){ return ImageDescriptor.getMissingImageDescriptor(); } } protected void initializeDefaultPreferences(IPreferenceStore store) { // These settings will show up when Preference dialog // opens up for the first time. store.setDefault(Messages.getString("SootPlugin.classes"), "soot.Main"); //$NON-NLS-1$ //$NON-NLS-2$ store.setDefault(Messages.getString("SootPlugin.selected"), "soot.Main"); //$NON-NLS-1$ //$NON-NLS-2$ } private SootResourceManager manager; private MessageConsole console; /** * Returns the shared instance. */ public static SootPlugin getDefault() { return plugin; } /** * Returns the workspace instance. */ public static IWorkspace getWorkspace() { return ResourcesPlugin.getWorkspace(); } /** * Returns the string from the plugin's resource bundle, * or 'key' if not found. */ public static String getResourceString(String key) { ResourceBundle bundle= SootPlugin.getDefault().getResourceBundle(); try { return bundle.getString(key); } catch (MissingResourceException e) { return key; } } /** * Returns the plugin's resource bundle, */ public ResourceBundle getResourceBundle() { return resourceBundle; } /** * Method startUp. * @throws CoreException */ public void startUp() throws CoreException { super.startup(); soot_output_doc = new SootDocument(); soot_output_doc.startUp(); } /** * @see org.eclipse.core.runtime.Plugin#shutdown() */ public void shutdown() throws CoreException { super.shutdown(); sootOutputEventListeners.removeAllElements(); } /** * @return */ public SootResourceManager getManager() { return manager; } /** * @param manager */ public void setManager(SootResourceManager manager) { this.manager = manager; } public void addEditorViewer(ISourceViewer viewer) { viewer.addTextListener(getManager()); getEditorViewers().add(viewer); } /** * @return */ public ArrayList getEditorViewers() { return editorViewers; } /** * @param list */ public void setEditorViewers(ArrayList list) { editorViewers = list; } /** * @return */ public SootPartManager getPartManager() { return partManager; } /** * @param manager */ public void setPartManager(SootPartManager manager) { partManager = manager; } /** * @return */ public ColorManager getColorManager() { if (colorManager == null ){ colorManager = new ColorManager(); } return colorManager; } /** * @param manager */ public void setColorManager(ColorManager manager) { colorManager = manager; } /** * @return */ public DataKeeper getDataKeeper() { return dataKeeper; } /** * @param keeper */ public void setDataKeeper(DataKeeper keeper) { dataKeeper = keeper; } /** * @return */ public Font getSootFont() { return sootFont; } /** * @param font */ public void setSootFont(Font font) { sootFont = font; } /** * @return */ public IProject getCurrentProject() { return currentProject; } /** * @param project */ public void setCurrentProject(IProject project) { currentProject = project; } }
8,625
23.787356
103
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/AbstractAttributesColorer.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; import org.eclipse.jface.text.*; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.*; import org.eclipse.ui.*; import org.eclipse.ui.texteditor.AbstractTextEditor; import ca.mcgill.sable.soot.SootPlugin; import ca.mcgill.sable.soot.editors.*; public abstract class AbstractAttributesColorer { private ITextViewer viewer; private IEditorPart editorPart; private Color bgColor; private Display display; private ArrayList styleList; private SootAttributesHandler handler; private ColorManager colorManager; protected void init(){ setColorManager(SootPlugin.getDefault().getColorManager()); setDisplay(getEditorPart().getSite().getShell().getDisplay()); clearPres(); } protected abstract void computeColors(); private void clearPres(){ if (getEditorPart() == null) return; if (getEditorPart().getEditorInput() != null){ getDisplay().syncExec(new Runnable(){ public void run() { IRegion reg = ((AbstractTextEditor)getEditorPart()).getHighlightRange(); ((AbstractTextEditor)getEditorPart()).setInput(getEditorPart().getEditorInput()); if (reg != null){ ((AbstractTextEditor)getEditorPart()).setHighlightRange(reg.getOffset(), reg.getLength(), true); } }; }); } } protected ArrayList sortAttrsByLength(ArrayList attrs){ Iterator it = attrs.iterator(); while(it.hasNext()){ SootAttribute sa = (SootAttribute)it.next(); int sLineOffset = 0; int eLineOffset = 0; try { sLineOffset = getViewer().getDocument().getLineOffset((sa.getJavaStartLn()-1)); eLineOffset = getViewer().getDocument().getLineOffset((sa.getJavaEndLn()-1)); } catch(Exception e){ } int sOffset = sLineOffset + sa.getJavaStartPos() - 1; int eOffset = eLineOffset + sa.getJavaEndPos() - 1; int length = sOffset - eOffset; setLength(sa, length); } SootAttribute [] sorted = new SootAttribute[attrs.size()]; attrs.toArray(sorted); for (int i = 0; i< sorted.length; i++){ for (int j = i; j < sorted.length; j++){ if (sorted[j].getJavaLength() > sorted[i].getJavaLength()){ SootAttribute temp = sorted[i]; sorted[i] = sorted[j]; sorted[j] = temp; } } } ArrayList sortedArray = new ArrayList(); for (int i = sorted.length - 1; i >= 0; i--){ sortedArray.add(sorted[i]); } return sortedArray; } // set java or jimple length; protected abstract void setLength(SootAttribute sa, int length); protected void changeStyles(){ final StyleRange [] srs = new StyleRange[styleList.size()]; styleList.toArray(srs); getDisplay().asyncExec(new Runnable(){ public void run(){ for (int i = 0; i < srs.length; i++){ try{ //System.out.println("Style Range: "+srs[i]); getViewer().getTextWidget().setStyleRange(srs[i]); } catch(Exception e){ System.out.println("Seting Style Range Ex: "+e.getMessage()); } } }; }); } protected void setAttributeTextColor(int sline, int eline, int spos, int epos, RGB colorKey, boolean fg){ int sLineOffset = 0; int eLineOffset = 0; int [] offsets = new int[eline-sline+1]; int [] starts = new int[eline-sline+1]; int [] lengths = new int[eline-sline+1]; int unColLen = spos < epos ? spos-1: epos-1; try { int j = 0; for (int i = sline; i <= eline; i++){ offsets[j] = getViewer().getDocument().getLineOffset((i-1)); starts[j] = offsets[j] + unColLen; lengths[j] = getViewer().getDocument().getLineOffset(i) - 1 - starts[j]; j++; } sLineOffset = getViewer().getDocument().getLineOffset((sline-1)); eLineOffset = getViewer().getDocument().getLineOffset((eline-1)); } catch(Exception e){ return; } int sOffset = sLineOffset + spos - 1; int eOffset = eLineOffset + epos - 1; int len = eOffset - sOffset; Color color = getColorManager().getColor(colorKey); Color oldBgColor = getColorManager().getColor(IJimpleColorConstants.JIMPLE_DEFAULT); StyleRange sr; if (len > 0){ if (sline == eline){ if (fg){ sr = new StyleRange(sOffset-1, len+1, color, getBgColor()); } else { sr = new StyleRange(sOffset, len, oldBgColor, color); } getStyleList().add(sr); } else { for (int i = 0; i < starts.length; i++){ if (fg){ sr = new StyleRange(starts[i]-1, lengths[i]+1, color, getBgColor()); } else { sr = new StyleRange(starts[i], lengths[i], oldBgColor, color); } getStyleList().add(sr); } } } } /** * @return */ public Color getBgColor() { return bgColor; } /** * @return */ public ColorManager getColorManager() { return colorManager; } /** * @return */ public Display getDisplay() { return display; } /** * @return */ public IEditorPart getEditorPart() { return editorPart; } /** * @return */ public SootAttributesHandler getHandler() { return handler; } /** * @return */ public ArrayList getStyleList() { return styleList; } /** * @return */ public ITextViewer getViewer() { return viewer; } /** * @param color */ public void setBgColor(Color color) { bgColor = color; } /** * @param manager */ public void setColorManager(ColorManager manager) { colorManager = manager; } /** * @param display */ public void setDisplay(Display display) { this.display = display; } /** * @param part */ public void setEditorPart(IEditorPart part) { editorPart = part; } /** * @param handler */ public void setHandler(SootAttributesHandler handler) { this.handler = handler; } /** * @param list */ public void setStyleList(ArrayList list) { styleList = list; } /** * @param viewer */ public void setViewer(ITextViewer viewer) { this.viewer = viewer; } }
7,966
27.251773
121
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/AbstractAttributesComputer.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.io.File; import java.util.*; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; import org.eclipse.ui.texteditor.*; import ca.mcgill.sable.soot.SootPlugin; public abstract class AbstractAttributesComputer { private IResource rec; private IProject proj; /** * compute list of xml filenames */ protected ArrayList computeFiles(ArrayList names){ ArrayList fileList = new ArrayList(); String sep = System.getProperty("file.separator"); IContainer con = (IContainer)getProj().getFolder("sootOutput"+sep+"attributes"+sep); try { IResource [] files = con.members(); for (int i = 0; i < files.length; i++){ Iterator it = names.iterator(); while (it.hasNext()){ String fileNameToMatch = (String)it.next(); if (files[i].getName().matches(fileNameToMatch+"[$].*") || files[i].getName().equals(fileNameToMatch+".xml")){ fileList.add(files[i]); } } } } catch(CoreException e){ } return fileList; } /** * compute top-level names */ protected abstract ArrayList computeNames(AbstractTextEditor editor); protected abstract ArrayList computeNames(IFile file); /** * initialize rec and proj */ protected abstract void init(AbstractTextEditor editor); /** * compute attributes */ protected SootAttributesHandler computeAttributes(ArrayList files, SootAttributesHandler sah) { SootAttributeFilesReader safr = new SootAttributeFilesReader(); Iterator it = files.iterator(); while (it.hasNext()){ String fileName = ((IPath)((IFile)it.next()).getLocation()).toOSString(); AttributeDomProcessor adp = safr.readFile(fileName); if (adp != null) { sah.setAttrList(adp.getAttributes()); sah.setKeyList(adp.getKeys()); } } sah.setValuesSetTime(System.currentTimeMillis()); SootPlugin.getDefault().getManager().addToFileWithAttributes((IFile)getRec(), sah); return sah; } public SootAttributesHandler getAttributesHandler(IFile file){ ArrayList files = computeFiles(computeNames(file)); return getHandler(files); } public SootAttributesHandler getAttributesHandler(AbstractTextEditor editor){ // init init(editor); // computeFileNames ArrayList files = computeFiles(computeNames(editor)); return getHandler(files); } private SootAttributesHandler getHandler(ArrayList files){ // check if any have changed since creation of attributes in handler if (!(getRec() instanceof IFile)) return null; SootAttributesHandler handler = SootPlugin.getDefault().getManager().getAttributesHandlerForFile((IFile)getRec()); if (handler != null){ long valuesSetTime = handler.getValuesSetTime(); boolean update = handler.isUpdate(); Iterator it = files.iterator(); while (it.hasNext()){ IFile next = (IFile)it.next(); File realFile = new File(next.getLocation().toOSString()); if (realFile.lastModified() > valuesSetTime){ update = true; } } handler.setUpdate(update); // if no return handler if (!update){ return handler; } else { return computeAttributes(files, handler); } } else { return computeAttributes(files, new SootAttributesHandler()); } } /** * @return */ public IProject getProj() { return proj; } /** * @return */ public IResource getRec() { return rec; } /** * @param project */ public void setProj(IProject project) { proj = project; } /** * @param resource */ public void setRec(IResource resource) { rec = resource; } }
4,384
25.575758
116
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/AbstractSootAttributesHover.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.ArrayList; import org.eclipse.jface.text.*; import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.ui.*; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.CoreException; import ca.mcgill.sable.soot.SootPlugin; public abstract class AbstractSootAttributesHover implements ITextHover { private IEditorPart editor; private int lineNum; private String fileName; private String packFileName; private ArrayList packFileNames; private boolean editorHasChanged; private String selectedProj; private SootAttributesHandler attrsHandler; private IResource rec; private ITextViewer viewer; private IDocument document; public static final String sep = System.getProperty("file.separator"); /** * Method setEditor. * @param ed */ public void setEditor(IEditorPart ed) { editor = ed; } /** * Method getAttributes. * @return String * sub classes must implement this method * if more then one attribute return * each attribute separated by newlines */ protected abstract String getAttributes(AbstractTextEditor editor); /** * @see org.eclipse.jface.text.ITextHover#getHoverInfo(ITextViewer, IRegion) */ public String getHoverInfo(ITextViewer textViewer, org.eclipse.jface.text.IRegion hoverRegion) { // this prevents showing incorrect tags - at least temporaily // and hopefully if the editor has ever changed getHoverRegion(textViewer, hoverRegion.getOffset()); String attr = null; attr = getAttributes((AbstractTextEditor)getEditor()); return attr; } /** * @see org.eclipse.jface.text.ITextHover#getHoverRegion(ITextViewer, int) */ public org.eclipse.jface.text.IRegion getHoverRegion(ITextViewer textViewer, int offset) { try { setLineNum(textViewer.getDocument().getLineOfOffset(offset)+1); setDocument(textViewer.getDocument()); return textViewer.getDocument().getLineInformationOfOffset(offset); } catch (BadLocationException e) { return null; } } /** * Returns the lineNum. * @return int */ public int getLineNum() { return lineNum; } /** * Sets the lineNum. * @param lineNum The lineNum to set */ public void setLineNum(int lineNum) { this.lineNum = lineNum; } /** * Returns the fileName. * @return String */ public String getFileName() { return fileName; } /** * Sets the fileName. * @param fileName The fileName to set */ public void setFileName(String fileName) { this.fileName = fileName; } /** * Returns the packFileName. * @return String */ public String getPackFileName() { return packFileName; } /** * Sets the packFileName. * @param packFileName The packFileName to set */ public void setPackFileName(String packFileName) { this.packFileName = packFileName; } /** * Returns the editorHasChanged. * @return boolean */ public boolean isEditorHasChanged() { return editorHasChanged; } /** * Sets the editorHasChanged. * @param editorHasChanged The editorHasChanged to set */ public void setEditorHasChanged(boolean editorHasChanged) { this.editorHasChanged = editorHasChanged; } /** * Returns the selectedProj. * @return String */ public String getSelectedProj() { return selectedProj; } /** * Sets the selectedProj. * @param selectedProj The selectedProj to set */ public void setSelectedProj(String selectedProj) { this.selectedProj = selectedProj; } /** * Returns the attrsHandler. * @return SootAttributesHandler */ public SootAttributesHandler getAttrsHandler() { return attrsHandler; } /** * Sets the attrsHandler. * @param attrsHandler The attrsHandler to set */ public void setAttrsHandler(SootAttributesHandler attrsHandler) { this.attrsHandler = attrsHandler; } /** * Returns the editor. * @return IEditorPart */ public IEditorPart getEditor() { return editor; } /** * Returns the rec. * @return IResource */ public IResource getRec() { return rec; } /** * Sets the rec. * @param rec The rec to set */ public void setRec(IResource rec) { this.rec = rec; } /** * @return */ public IDocument getDocument() { return document; } /** * @return */ public ITextViewer getViewer() { return viewer; } /** * @param document */ public void setDocument(IDocument document) { this.document = document; } /** * @param viewer */ public void setViewer(ITextViewer viewer) { this.viewer = viewer; } /** * @return */ public ArrayList getPackFileNames() { return packFileNames; } /** * @param list */ public void setPackFileNames(ArrayList list) { packFileNames = list; } }
5,594
20.354962
97
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/AnalysisKey.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ /* * Created on Nov 18, 2003 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package ca.mcgill.sable.soot.attributes; public class AnalysisKey { private int red; private int green; private int blue; private String key; private String type; /** * @return */ public int getBlue() { return blue; } /** * @return */ public int getGreen() { return green; } /** * @return */ public String getKey() { return key; } /** * @return */ public int getRed() { return red; } /** * @param i */ public void setBlue(int i) { blue = i; } /** * @param i */ public void setGreen(int i) { green = i; } /** * @param string */ public void setKey(String string) { key = string; } /** * @param i */ public void setRed(int i) { red = i; } /** * @return */ public String getType() { return type; } /** * @param string */ public void setType(String string) { type = string; } }
1,861
16.566038
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/AttributeDomProcessor.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; //import javax.xml.parsers.*; import org.w3c.dom.*; public class AttributeDomProcessor { Document domDoc; ArrayList attributes; private ArrayList keys; private SootAttribute current; /** * Method AttributeDomProcessor. * @param domDoc */ public AttributeDomProcessor(Document domDoc) { setDomDoc(domDoc); } /** * Method processAttributesDom. */ public void processAttributesDom() { processNode(getDomDoc()); } private void processNode(Node node) { if (node.getNodeType() == Node.DOCUMENT_NODE) { NodeList children = node.getChildNodes(); if (children != null) { setAttributes(new ArrayList()); for (int i = 0; i < children.getLength(); i++) { processNode(children.item(i)); } } } else if (node.getNodeType() == Node.ELEMENT_NODE) { if ( node.getNodeName().equals("attribute")) { current = new SootAttribute(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { processAttributeNode(current, children.item(i)); } getAttributes().add(current); } else if (node.getNodeName().equals("key")){ if (keys == null){ keys = new ArrayList(); } NamedNodeMap map = node.getAttributes(); AnalysisKey key = new AnalysisKey(); key.setRed((new Integer(map.getNamedItem("red").getNodeValue())).intValue()); key.setGreen((new Integer(map.getNamedItem("green").getNodeValue())).intValue()); key.setBlue((new Integer(map.getNamedItem("blue").getNodeValue())).intValue()); key.setKey(map.getNamedItem("key").getNodeValue()); key.setType(map.getNamedItem("aType").getNodeValue()); keys.add(key); } else { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { processNode(children.item(i)); } } } } private void processAttributeNode(SootAttribute current, Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeName().equals("link")){ NamedNodeMap map = node.getAttributes(); LinkAttribute la = new LinkAttribute(); la.setLabel(map.getNamedItem("label").getNodeValue()); la.setJavaLink((new Integer(map.getNamedItem("srcLink").getNodeValue()).intValue())); la.setJimpleLink((new Integer(map.getNamedItem("jmpLink").getNodeValue()).intValue())); la.setClassName(map.getNamedItem("clssNm").getNodeValue()); la.setType(map.getNamedItem("aType").getNodeValue()); current.addLinkAttr(la); } else if (node.getNodeName().equals("color")){ NamedNodeMap map = node.getAttributes(); int r = (new Integer(map.getNamedItem("r").getNodeValue())).intValue(); int g = (new Integer(map.getNamedItem("g").getNodeValue())).intValue(); int b = (new Integer(map.getNamedItem("b").getNodeValue())).intValue(); int fgInt = (new Integer(map.getNamedItem("fg").getNodeValue())).intValue(); boolean fg = false; if (fgInt == 1){ fg = true; } ColorAttribute ca = new ColorAttribute(r, g, b, fg); ca.type(map.getNamedItem("aType").getNodeValue()); current.addColorAttr(ca);//.setColor(ca); } else if (node.getNodeName().equals("srcPos")){ NamedNodeMap map = node.getAttributes(); int sline = (new Integer(map.getNamedItem("sline").getNodeValue())).intValue(); int eline = (new Integer(map.getNamedItem("eline").getNodeValue())).intValue(); int spos = (new Integer(map.getNamedItem("spos").getNodeValue())).intValue(); int epos = (new Integer(map.getNamedItem("epos").getNodeValue())).intValue(); current.setJavaStartLn(sline); current.setJavaEndLn(eline); current.setJavaStartPos(spos); current.setJavaEndPos(epos); } else if (node.getNodeName().equals("jmpPos")){ NamedNodeMap map = node.getAttributes(); int sline = (new Integer(map.getNamedItem("sline").getNodeValue())).intValue(); int eline = (new Integer(map.getNamedItem("eline").getNodeValue())).intValue(); int spos = (new Integer(map.getNamedItem("spos").getNodeValue())).intValue(); int epos = (new Integer(map.getNamedItem("epos").getNodeValue())).intValue(); current.setJimpleStartLn(sline); current.setJimpleEndLn(eline); current.setJimpleStartPos(spos); current.setJimpleEndPos(epos); } else if (node.getNodeName().equals("text")){ NamedNodeMap map = node.getAttributes(); TextAttribute ta = new TextAttribute(); ta.setInfo(map.getNamedItem("info").getNodeValue()); ta.setType(map.getNamedItem("aType").getNodeValue()); current.addTextAttr(ta); } else { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { processAttributeNode(current, children.item(i)); } } } else if (node.getNodeType() == Node.TEXT_NODE){ String type = node.getParentNode().getNodeName(); } } /** * Returns the domDoc. * @return Document */ public Document getDomDoc() { return domDoc; } /** * Sets the domDoc. * @param domDoc The domDoc to set */ public void setDomDoc(Document domDoc) { this.domDoc = domDoc; } /** * Returns the attributes. * @return Vector */ public ArrayList getAttributes() { return attributes; } /** * Returns the current. * @return SootAttribute */ public SootAttribute getCurrent() { return current; } /** * Sets the attributes. * @param attributes The attributes to set */ public void setAttributes(ArrayList attributes) { this.attributes = attributes; } /** * Sets the current. * @param current The current to set */ public void setCurrent(SootAttribute current) { this.current = current; } /** * @return */ public ArrayList getKeys() { return keys; } /** * @param list */ public void setKeys(ArrayList list) { keys = list; } }
6,717
27.709402
91
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/AttributeFileReader.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.io.*; public class AttributeFileReader { private String filename; /** * Method AttributeFileReader. * @param filename */ public AttributeFileReader(String filename) { setFilename(filename); } /** * Method readFile. * @return String * reads given file trimming white space */ public String readFile() { StringBuffer file = new StringBuffer(); try { BufferedReader br = new BufferedReader( new FileReader(getFilename())); while (true) { String temp = br.readLine(); if (temp == null) break; temp = temp.trim(); file.append(temp); } } catch (IOException e1) { System.out.println(e1.getMessage()); } return file.toString(); } /** * Returns the filename. * @return String */ public String getFilename() { return filename; } /** * Sets the filename. * @param filename The filename to set */ public void setFilename(String filename) { this.filename = filename; } }
1,855
22.2
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/ColorAttribute.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import soot.*; import org.eclipse.swt.graphics.RGB; public class ColorAttribute{ private int red; private int green; private int blue; private int fg; private String type; public ColorAttribute(int red, int green, int blue, boolean fg){ this.red = red; this.green = green; this.blue = blue; if (fg){ this.fg = 1; } else { this.fg = 0; } } public int red(){ return red; } public int green(){ return green; } public int blue(){ return blue; } public int fg(){ return fg; } /** * @return */ public String type() { return type; } /** * @param string */ public void type(String string) { type = string; } public RGB getRGBColor(){ return new RGB(red(), green(), blue()); } }
1,754
21.21519
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/FindMethodResolver.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import org.eclipse.core.resources.IMarker; import org.eclipse.ui.IMarkerResolution; // not used public class FindMethodResolver implements IMarkerResolution { private String label; private IMarker marker; public FindMethodResolver(IMarker marker){ setMarker(marker); generateLabel(); } private void generateLabel(){ setLabel("myMarker1"); } public void setLabel(String l){ label = l; } /* (non-Javadoc) * @see org.eclipse.ui.IMarkerResolution#getLabel() */ public String getLabel() { return getLabel(); } /* (non-Javadoc) * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker) */ public void run(IMarker marker) { } /** * @return */ public IMarker getMarker() { return marker; } /** * @param marker */ public void setMarker(IMarker marker) { this.marker = marker; } }
1,725
22.972222
81
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/ISootAttributesHandler.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; public interface ISootAttributesHandler { public boolean attrExistsForJavaLine(String project, String filename, int lineNum); public boolean attrExistsForJimpleLine(String project, String filename, int lineNum); }
1,090
35.366667
88
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/JavaAttributesComputer.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; import org.eclipse.jdt.core.*; import org.eclipse.ui.*; import org.eclipse.ui.texteditor.*; public class JavaAttributesComputer extends AbstractAttributesComputer { protected ArrayList computeNames(IFile file){ IJavaElement jElem = getJavaElement(file); ICompilationUnit cu = (ICompilationUnit)jElem; return getNames(cu); } /** * compute top-level names */ protected ArrayList computeNames(AbstractTextEditor editor){ IJavaElement jElem = getJavaElement(editor); ArrayList names = new ArrayList(); if (jElem instanceof ICompilationUnit){ ICompilationUnit cu = (ICompilationUnit)jElem; return getNames(cu); } else { return names; } } private ArrayList getNames(ICompilationUnit cu){ ArrayList names = new ArrayList(); try { IType [] topLevelDecls = cu.getTypes(); for (int i = 0; i < topLevelDecls.length; i++){ names.add(topLevelDecls[i].getFullyQualifiedName()); } } catch(JavaModelException e){ } return names; } /** * initialize rec and proj */ protected void init(AbstractTextEditor editor){ IJavaElement jElem = getJavaElement(editor); setProj(jElem.getResource().getProject()); setRec(jElem.getResource()); } public IJavaElement getJavaElement(AbstractTextEditor textEditor) { IEditorInput input= textEditor.getEditorInput(); return (IJavaElement) ((IAdaptable) input).getAdapter(IJavaElement.class); } public IJavaElement getJavaElement(IFile file) { return (IJavaElement) ((IAdaptable) file).getAdapter(IJavaElement.class); } }
2,506
27.488636
76
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/JimpleAttributesComputer.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.ArrayList; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.texteditor.*; public class JimpleAttributesComputer extends AbstractAttributesComputer { protected ArrayList computeNames(IFile file){ return getNames(); } /* (non-Javadoc) * @see ca.mcgill.sable.soot.attributes.AbstractAttributesComputer#computeNames(org.eclipse.ui.texteditor.AbstractTextEditor) */ protected ArrayList computeNames(AbstractTextEditor editor) { return getNames(); } private ArrayList getNames(){ ArrayList names = new ArrayList(); names.add(fileToNoExt(getRec().getName())); return names; } /* (non-Javadoc) * @see ca.mcgill.sable.soot.attributes.AbstractAttributesComputer#init(org.eclipse.ui.texteditor.AbstractTextEditor) */ protected void init(AbstractTextEditor editor) { setRec(getResource(editor)); setProj(getRec().getProject()); } public IResource getResource(AbstractTextEditor textEditor) { IEditorInput input= textEditor.getEditorInput(); return (IResource) ((IAdaptable) input).getAdapter(IResource.class); } public String fileToNoExt(String filename) { return filename.substring(0, filename.lastIndexOf('.')); } }
2,142
29.183099
126
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/LinkAttribute.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; public class LinkAttribute { private String label; private int jimpleLink; private int javaLink; private String className; private String type; /** * @return */ public String getClassName() { return className; } /** * @return */ public String getLabel() { return label; } /** * @return */ public int getJimpleLink() { return jimpleLink; } /** * @param string */ public void setClassName(String string) { className = string; } /** * @param string */ public void setLabel(String string) { string = string.replaceAll("&lt;", "<"); label = string.replaceAll("&gt;", ">"); } /** * @param string */ public void setJimpleLink(int l) { jimpleLink = l; } /** * @return */ public int getJavaLink() { return javaLink; } /** * @param i */ public void setJavaLink(int i) { javaLink = i; } /** * @return */ public String getType() { return type; } /** * @param string */ public void setType(String string) { type = string; } }
1,900
17.104762
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/Messages.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.MissingResourceException; import java.util.ResourceBundle; public class Messages { private static final String BUNDLE_NAME = "ca.mcgill.sable.soot.attributes.attributes"; //$NON-NLS-1$ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); private Messages() { } /** * @param key * @return */ public static String getString(String key) { try { return RESOURCE_BUNDLE.getString(key); } catch (MissingResourceException e) { return '!' + key + '!'; } } }
1,408
28.354167
102
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/PosColAttribute.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import org.eclipse.swt.graphics.RGB; public class PosColAttribute { private int startOffset; private int endOffset; private int sourceStartOffset; private int sourceEndOffset; private int red; private int green; private int blue; private int fg; public RGB getRGBColor(){ return new RGB(getRed(), getGreen(), getBlue()); } /** * @return */ public int getBlue() { return blue; } /** * @return */ public int getEndOffset() { return endOffset; } /** * @return */ public int getGreen() { return green; } /** * @return */ public int getRed() { return red; } /** * @return */ public int getStartOffset() { return startOffset; } /** * @param i */ public void setBlue(int i) { blue = i; } /** * @param i */ public void setEndOffset(int i) { endOffset = i; } /** * @param i */ public void setGreen(int i) { green = i; } /** * @param i */ public void setRed(int i) { red = i; } /** * @param i */ public void setStartOffset(int i) { startOffset = i; } /** * @return */ public int getSourceEndOffset() { return sourceEndOffset; } /** * @return */ public int getSourceStartOffset() { return sourceStartOffset; } /** * @param i */ public void setSourceEndOffset(int i) { sourceEndOffset = i; } /** * @param i */ public void setSourceStartOffset(int i) { sourceStartOffset = i; } /** * @return */ public int getFg() { return fg; } /** * @param i */ public void setFg(int i) { fg = i; } }
2,513
15.219355
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttrJavaIconGenerator.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.CoreException; import org.eclipse.ui.texteditor.MarkerUtilities; public class SootAttrJavaIconGenerator implements Runnable{ private IFile rec; private SootAttributesHandler handler; public void run(){ removeOldMarkers(); addSootAttributeMarkers(); } private boolean typesContainsOneOf(ArrayList list){ boolean result = false; Iterator it = list.iterator(); while (it.hasNext()){ if (getHandler().getTypesToShow().contains(it.next())) { result = true; break; } } return result; } public void addSootAttributeMarkers(){//SootAttributesHandler handler, IFile rec) { if (getHandler().getAttrList() == null) return; Iterator it = getHandler().getAttrList().iterator(); HashMap markerAttr = new HashMap(); while (it.hasNext()) { SootAttribute sa = (SootAttribute)it.next(); if (getHandler().isShowAllTypes() || typesContainsOneOf(sa.getAnalysisTypes())) { if (((sa.getAllTextAttrs("<br>") == null) || (sa.getAllTextAttrs("<br>").length() == 0)) && ((sa.getAllLinkAttrs() == null) || (sa.getAllLinkAttrs().size() ==0))) continue; markerAttr.put(IMarker.LINE_NUMBER, new Integer(sa.getJavaStartLn())); try { MarkerUtilities.createMarker(getRec(), markerAttr, "ca.mcgill.sable.soot.sootattributemarker"); } catch(CoreException e) { System.out.println(e.getMessage()); } } } } public void removeOldMarkers(){//IFile file){ try{ getRec().deleteMarkers("ca.mcgill.sable.soot.sootattributemarker", true, IResource.DEPTH_INFINITE); } catch(CoreException e){ } } /** * @return */ public SootAttributesHandler getHandler() { return handler; } /** * @return */ public IFile getRec() { return rec; } /** * @param handler */ public void setHandler(SootAttributesHandler handler) { this.handler = handler; } /** * @param file */ public void setRec(IFile file) { rec = file; } }
2,881
25.440367
102
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttrJimpleIconGenerator.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ /* * Created on Nov 7, 2003 */ package ca.mcgill.sable.soot.attributes; import java.util.*; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.CoreException; import org.eclipse.ui.texteditor.MarkerUtilities; /** * @author jlhotak */ public class SootAttrJimpleIconGenerator implements Runnable { private IFile rec; private SootAttributesHandler handler; public void run(){ removeOldMarkers(); addSootAttributeMarkers(); } private boolean typesContainsOneOf(ArrayList list){ boolean result = false; Iterator it = list.iterator(); while (it.hasNext()){ if (getHandler().getTypesToShow().contains(it.next())) { result = true; break; } } return result; } public void addSootAttributeMarkers(){//SootAttributesHandler handler, IFile rec) { if (getHandler().getAttrList() == null) return; Iterator it = getHandler().getAttrList().iterator(); HashMap markerAttr = new HashMap(); while (it.hasNext()) { SootAttribute sa = (SootAttribute)it.next(); if (getHandler().isShowAllTypes() || typesContainsOneOf(sa.getAnalysisTypes())){ if (((sa.getAllTextAttrs("") == null) || (sa.getAllTextAttrs("").length() == 0)) && ((sa.getAllLinkAttrs() == null) || (sa.getAllLinkAttrs().size() ==0))) continue; markerAttr.put(IMarker.LINE_NUMBER, new Integer(sa.getJimpleStartLn())); try { MarkerUtilities.createMarker(getRec(), markerAttr, "ca.mcgill.sable.soot.sootattributemarker"); } catch(CoreException e) { System.out.println(e.getMessage()); } } } } public void removeOldMarkers(){//IFile file){ try{ getRec().deleteMarkers("ca.mcgill.sable.soot.sootattributemarker", true, IResource.DEPTH_INFINITE); } catch(CoreException e){ } } /** * @return */ public SootAttributesHandler getHandler() { return handler; } /** * @return */ public IFile getRec() { return rec; } /** * @param handler */ public void setHandler(SootAttributesHandler handler) { this.handler = handler; } /** * @param file */ public void setRec(IFile file) { rec = file; } }
2,935
24.982301
102
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttribute.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; public class SootAttribute { private int javaEndLn; private int javaStartLn; private int jimpleEndLn; private int jimpleStartLn; private int jimpleStartPos; private int jimpleEndPos; private int javaStartPos; private int javaEndPos; private ArrayList colorList; private ArrayList textList; private ArrayList linkList; private int jimpleLength; private int javaLength; public ArrayList getAnalysisTypes(){ ArrayList types = new ArrayList(); if (getTextList() != null){ Iterator it = getTextList().iterator(); while (it.hasNext()){ TextAttribute ta = (TextAttribute)it.next(); if (!types.contains(ta.getType())){ types.add(ta.getType()); } } } if (getLinkList() != null){ Iterator lit = getLinkList().iterator(); while (lit.hasNext()){ LinkAttribute la = (LinkAttribute)lit.next(); if (!types.contains(la.getType())){ types.add(la.getType()); } } } if (getColorList() != null){ Iterator cit = getColorList().iterator(); while (cit.hasNext()){ ColorAttribute ca = (ColorAttribute)cit.next(); if (!types.contains(ca.type())){ types.add(ca.type()); } } } return types; } public void addColorAttr(ColorAttribute color){ if (getColorList() == null){ setColorList(new ArrayList()); } getColorList().add(color); } private static final String NEWLINE = "\n"; public void addLinkAttr(LinkAttribute link){ if (getLinkList() == null){ setLinkList(new ArrayList()); } getLinkList().add(link); TextAttribute ta = new TextAttribute(); ta.setInfo(link.getLabel()); ta.setType(link.getType()); addTextAttr(ta); } public ArrayList getAllLinkAttrs(){ return getLinkList(); } public void addTextAttr(TextAttribute text){ if (getTextList() == null){ setTextList(new ArrayList()); } text.setInfo(formatText(text.getInfo())); getTextList().add(text); } public String formatText(String text){ text = text.replaceAll("&lt;", "<"); text = text.replaceAll("&gt;", ">"); text = text.replaceAll("&amp;", "&"); return text; } public StringBuffer getAllTextAttrs(String lineSep){ StringBuffer sb = new StringBuffer(); if (getTextList() != null){ Iterator it = getTextList().iterator(); while (it.hasNext()){ TextAttribute ta = (TextAttribute)it.next(); String next = ta.getInfo(); if (lineSep.equals("<br>")){ // implies java tooltip next = convertHTMLTags(next); } sb.append(next); sb.append(lineSep); } } return sb; } public StringBuffer getTextAttrsForType(String lineSep, String type){ StringBuffer sb = new StringBuffer(); if (getTextList() != null){ Iterator it = getTextList().iterator(); while (it.hasNext()){ TextAttribute ta = (TextAttribute)it.next(); if (ta.getType().equals(type)){ String next = ta.getInfo(); if (lineSep.equals("<br>")){ // implies java tooltip next = convertHTMLTags(next); } sb.append(next); sb.append(lineSep); } } } return sb; } public String convertHTMLTags(String next){ if (next == null) return null; else { next = next.replaceAll("<", "&lt;"); next = next.replaceAll(">", "&gt;"); return next; } } // these two are maybe not accurate maybe // need to check if ln in question is between // the start and end ln's public boolean attrForJimpleLn(int jimple_ln) { if (getJimpleStartLn() == jimple_ln) return true; else return false; } public boolean attrForJavaLn(int java_ln) { if (getJavaStartLn() == java_ln) return true; else return false; } public SootAttribute() { } /** * @return */ public int getJimpleEndPos() { return jimpleEndPos; } /** * @return */ public int getJimpleStartPos() { return jimpleStartPos; } /** * @param i */ public void setJimpleEndPos(int i) { jimpleEndPos = i; } /** * @param i */ public void setJimpleStartPos(int i) { jimpleStartPos = i; } /** * @return */ public ArrayList getTextList() { return textList; } /** * @param list */ public void setTextList(ArrayList list) { textList = list; } /** * @return */ public ArrayList getLinkList() { return linkList; } /** * @param list */ public void setLinkList(ArrayList list) { linkList = list; } /** * @return */ public int getJavaEndPos() { return javaEndPos; } /** * @return */ public int getJavaStartPos() { return javaStartPos; } /** * @param i */ public void setJavaEndPos(int i) { javaEndPos = i; } /** * @param i */ public void setJavaStartPos(int i) { javaStartPos = i; } /** * @return */ public int getJavaEndLn() { return javaEndLn; } /** * @return */ public int getJavaStartLn() { return javaStartLn; } /** * @return */ public int getJimpleEndLn() { return jimpleEndLn; } /** * @return */ public int getJimpleStartLn() { return jimpleStartLn; } /** * @param i */ public void setJavaEndLn(int i) { javaEndLn = i; } /** * @param i */ public void setJavaStartLn(int i) { javaStartLn = i; } /** * @param i */ public void setJimpleEndLn(int i) { jimpleEndLn = i; } /** * @param i */ public void setJimpleStartLn(int i) { jimpleStartLn = i; } /** * @return */ public int getJavaLength() { return javaLength; } /** * @return */ public int getJimpleLength() { return jimpleLength; } /** * @param i */ public void setJavaLength(int i) { javaLength = i; } /** * @param i */ public void setJimpleLength(int i) { jimpleLength = i; } /** * @return */ public ArrayList getColorList() { return colorList; } /** * @param list */ public void setColorList(ArrayList list) { colorList = list; } }
6,785
17.144385
70
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributeFilesReader.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import ca.mcgill.sable.soot.util.*; //import org.eclipse.core.resources.*; import org.w3c.dom.Document; public class SootAttributeFilesReader { /** * @see java.lang.Object#Object() */ public SootAttributeFilesReader() { } public AttributeDomProcessor readFile(String full_filename) { AttributeFileReader afr = new AttributeFileReader(full_filename); String file = afr.readFile(); if ((file == null) || (file.length() == 0)) return null; file = file.replaceAll("\"", "\\\""); StringToDom domMaker = new StringToDom(); domMaker.getDocFromString(file); Document domDoc = domMaker.getDomDoc(); AttributeDomProcessor adp = new AttributeDomProcessor(domDoc); adp.processAttributesDom(); return adp; } public String fileToNoExt(String filename) { return filename.substring(0, filename.lastIndexOf('.')); } }
1,729
28.322034
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributeJavaSelectAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; import org.eclipse.core.resources.*; import org.eclipse.jdt.core.*; import org.eclipse.jface.text.source.IVerticalRulerInfo; import org.eclipse.ui.PartInitException; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.part.*; import ca.mcgill.sable.soot.SootPlugin; public class SootAttributeJavaSelectAction extends SootAttributeSelectAction { public SootAttributeJavaSelectAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo rulerInfo) { super(bundle, prefix, editor, rulerInfo); } /* (non-Javadoc) * @see ca.mcgill.sable.soot.attributes.SootAttributeSelectAction#getMarkerLinks() */ public ArrayList getMarkerLinks(){ SootAttributesHandler handler = SootPlugin.getDefault().getManager().getAttributesHandlerForFile((IFile)getResource(getEditor())); ArrayList links = handler.getJavaLinks(getLineNumber()+1); Iterator it = links.iterator(); return links; } protected int getLinkLine(LinkAttribute la){ return la.getJavaLink(); } public void findClass(String className){ setLinkToEditor(getEditor()); String resource = removeExt(getResource(getEditor()).getName()); String ext = getResource(getEditor()).getFileExtension(); IProject proj = getResource(getEditor()).getProject(); String slashedClassName = className.replaceAll("\\.", System.getProperty("file.separator")); String classNameToFind = (ext == null) ? slashedClassName : slashedClassName+"."+ext; IJavaProject jProj = JavaCore.create(proj); try { IPackageFragmentRoot [] roots = jProj.getAllPackageFragmentRoots(); for (int i = 0; i < roots.length; i++){ if (!(roots[i].getResource() instanceof IContainer)) continue; IResource fileToFind = ((IContainer)roots[i].getResource()).findMember(classNameToFind); if (fileToFind == null) continue; if (!fileToFind.equals(resource)){ try { setLinkToEditor((AbstractTextEditor)SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput((IFile)fileToFind), fileToFind.getName())); } catch (PartInitException e){ } } } } catch (JavaModelException e){ setLinkToEditor(getEditor()); } } }
3,167
33.813187
198
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributeJimpleSelectAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; import org.eclipse.core.resources.*; import org.eclipse.jdt.core.*; import org.eclipse.jface.text.source.IVerticalRulerInfo; import org.eclipse.ui.PartInitException; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.ITextEditor; import ca.mcgill.sable.soot.SootPlugin; import org.eclipse.ui.*; import org.eclipse.ui.part.*; public class SootAttributeJimpleSelectAction extends SootAttributeSelectAction { public SootAttributeJimpleSelectAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo rulerInfo) { super(bundle, prefix, editor, rulerInfo); } public ArrayList getMarkerLinks(){ SootAttributesHandler handler = SootPlugin.getDefault().getManager().getAttributesHandlerForFile((IFile)getResource(getEditor())); ArrayList links = handler.getJimpleLinks(getLineNumber()+1); return links; } protected int getLinkLine(LinkAttribute la){ return la.getJimpleLink(); } public void findClass(String className){ setLinkToEditor(getEditor()); String resource = removeExt(getResource(getEditor()).getName()); String ext = getResource(getEditor()).getFileExtension(); String classNameToFind = (ext == null) ? className : className+"."+ext; if (!resource.equals(className)){ IContainer parent = getResource(getEditor()).getParent(); IResource file = parent.findMember(classNameToFind); try { setLinkToEditor((AbstractTextEditor)SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput((IFile)file), file.getName())); } catch (PartInitException e){ } } } }
2,534
34.208333
184
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributeResolutionGenerator.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import org.eclipse.core.resources.IMarker; import org.eclipse.ui.IMarkerResolution; import org.eclipse.ui.IMarkerResolutionGenerator2; // not used public class SootAttributeResolutionGenerator implements IMarkerResolutionGenerator2 { /* (non-Javadoc) * @see org.eclipse.ui.IMarkerResolutionGenerator2#hasResolutions(org.eclipse.core.resources.IMarker) */ public boolean hasResolutions(IMarker marker) { return true; } /* (non-Javadoc) * @see org.eclipse.ui.IMarkerResolutionGenerator#getResolutions(org.eclipse.core.resources.IMarker) */ public IMarkerResolution[] getResolutions(IMarker marker) { return new IMarkerResolution[] {new FindMethodResolver(marker)}; } }
1,560
32.934783
102
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributeRulerActionDelegate.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.ResourceBundle; import org.eclipse.jface.action.IAction; import org.eclipse.jface.text.source.IVerticalRulerInfo; import org.eclipse.ui.texteditor.*; import ca.mcgill.sable.soot.SootPlugin; import ca.mcgill.sable.soot.editors.JimpleEditor; public class SootAttributeRulerActionDelegate extends AbstractRulerActionDelegate { /** * @param bundle * @param prefix * @param editor * @param ruler */ public SootAttributeRulerActionDelegate(){ } /* (non-Javadoc) * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.source.IVerticalRulerInfo) */ protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) { try { ResourceBundle rb = SootPlugin.getDefault().getResourceBundle(); if (editor instanceof JimpleEditor){ return new SootAttributeJimpleSelectAction(rb, null, editor, rulerInfo); } else { return new SootAttributeJavaSelectAction(rb, null, editor, rulerInfo); } } catch (Exception e){ System.out.println("exception: "+e.getMessage()); } return null; } }
2,018
28.691176
164
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributeSelectAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.ArrayList; import java.util.Iterator; import java.util.ResourceBundle; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; import org.eclipse.jdt.core.*; import org.eclipse.jface.text.*; import org.eclipse.jface.text.source.*; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IMarkerResolution; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.texteditor.*; import ca.mcgill.sable.soot.editors.JimpleEditor; import ca.mcgill.sable.soot.ui.PopupListSelector; import ca.mcgill.sable.soot.*; public abstract class SootAttributeSelectAction extends ResourceAction { AbstractTextEditor editor; AbstractTextEditor linkToEditor; IVerticalRulerInfo rulerInfo; AbstractMarkerAnnotationModel model; int lineNumber; /** * @param bundle * @param prefix */ public SootAttributeSelectAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo rulerInfo) { super(bundle, prefix); setEditor((AbstractTextEditor)editor); setRulerInfo(rulerInfo); } public IResource getResource(AbstractTextEditor textEditor) { IEditorInput input= textEditor.getEditorInput(); return (IResource) ((IAdaptable) input).getAdapter(IResource.class); } protected IDocument getDocument() { IDocumentProvider provider= getEditor().getDocumentProvider(); return provider.getDocument(getEditor().getEditorInput()); } public void run() { // need to get list of texts IAnnotationModel model = getEditor().getDocumentProvider().getAnnotationModel(getEditor().getEditorInput()); if (model instanceof AbstractMarkerAnnotationModel){ setModel((AbstractMarkerAnnotationModel)model); } int markerLine = getRulerInfo().getLineOfLastMouseButtonActivity(); IResource rec = getResource(getEditor()); try { IMarker [] markers = rec.findMarkers("ca.mcgill.sable.soot.sootattributemarker", true, IResource.DEPTH_INFINITE); for (int i = 0; i < markers.length; i++){ if (getModel().getMarkerPosition(markers[i]) == null) continue; setLineNumber(getDocument().getLineOfOffset(getModel().getMarkerPosition(markers[i]).getOffset())); if (getLineNumber() == markerLine){ ArrayList links = getMarkerLinks(); Iterator lit = links.iterator(); String [] list = getMarkerLabels(links); if ((list == null) || (list.length == 0)) { // show no links } else { IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getWorkbenchWindow(); PopupListSelector popup = new PopupListSelector(window.getShell()); popup.setItems(list); int listWidth = getListWidth(list); if (getEditor() instanceof JimpleEditor){ int topIndex = ((JimpleEditor)getEditor()).getViewer().getTopIndex(); Rectangle rect = new Rectangle(320, (getLineNumber()+1-topIndex), listWidth, 45 ); popup.open(rect); } else { int topIndex = ((ITextViewer)((AbstractTextEditor)getEditor()).getAdapter(ITextOperationTarget.class)).getTopIndex(); int pos = getModel().getMarkerPosition(markers[i]).getOffset(); pos = pos / getLineNumber(); Rectangle rect = new Rectangle(320, getLineNumber()+1-topIndex, listWidth, 45 ); popup.open(rect); } handleSelection(popup.getSelected(), links); } } } } catch(CoreException e){ } catch (BadLocationException e1){ } } public int getListWidth(String[] list){ int width = 0; for (int i = 0; i < list.length; i++){ String next = list[i]; width = next.length() > width ? next.length() : width; } return width * 6; } public void handleSelection(String selected, ArrayList links){ if (selected == null) return; try { int toShow = 0; String className; Iterator it = links.iterator(); while (it.hasNext()){ LinkAttribute la = (LinkAttribute)it.next(); if (la.getLabel().equals(selected)){ toShow = getLinkLine(la) - 1;//.getJimpleLink() - 1; className = la.getClassName(); findClass(className); } } int selOffset = getLinkToEditor().getDocumentProvider().getDocument(getLinkToEditor().getEditorInput()).getLineOffset(toShow); if ((selOffset != -1) && (selOffset != 0)){ if (getLinkToEditor() instanceof JimpleEditor){ ((JimpleEditor)getLinkToEditor()).getViewer().setRangeIndication(selOffset, 1, true); SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(getLinkToEditor()); } else { SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(getLinkToEditor()); ((AbstractTextEditor)SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()).selectAndReveal(selOffset, 0); ((AbstractTextEditor)SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()).setHighlightRange(selOffset, 1, true); } } } catch(BadLocationException e){ System.out.println(e.getMessage()); } } protected abstract int getLinkLine(LinkAttribute la); public abstract void findClass(String className); public String removeExt(String fileName){ int dotIndex = fileName.lastIndexOf("."); return dotIndex < 0 ? fileName : fileName.substring(0, dotIndex); } public abstract ArrayList getMarkerLinks(); public String [] getMarkerLabels(ArrayList links){ if ((links == null) || (links.size() == 0)) return null; ArrayList list = new ArrayList(); String [] attributeTexts = new String[links.size()]; Iterator it = links.iterator(); while (it.hasNext()){ list.add(((LinkAttribute)it.next()).getLabel()); } list.toArray(attributeTexts); return attributeTexts; } public String [] fixLabels(String [] at){ for (int i = 0; i < at.length; i++){ String temp = at[i]; temp.replaceAll("&lt;", "<"); temp.replaceAll("&gt;", ">"); at[i] = temp; } return at; } public void getMarkerResolutions(IMarker marker){ SootAttributeResolutionGenerator sarg = new SootAttributeResolutionGenerator(); if (sarg.hasResolutions(marker)){ IMarkerResolution [] res = sarg.getResolutions(marker); for (int i = 0; i < res.length; i++){ //System.out.println("res: "+res[i].getLabel()); } } } /** * @return */ public AbstractTextEditor getEditor() { return editor; } /** * @param editor */ public void setEditor(AbstractTextEditor editor) { this.editor = editor; } /** * @return */ public IVerticalRulerInfo getRulerInfo() { return rulerInfo; } /** * @param info */ public void setRulerInfo(IVerticalRulerInfo info) { rulerInfo = info; } /** * @return */ public AbstractMarkerAnnotationModel getModel() { return model; } /** * @param model */ public void setModel(AbstractMarkerAnnotationModel model) { this.model = model; } /** * @return */ public int getLineNumber() { return lineNumber; } /** * @param i */ public void setLineNumber(int i) { lineNumber = i; } /** * @return */ public AbstractTextEditor getLinkToEditor() { return linkToEditor; } /** * @param editor */ public void setLinkToEditor(AbstractTextEditor editor) { linkToEditor = editor; } }
8,383
26.853821
165
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributesHandler.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; public class SootAttributesHandler { private ArrayList attrList; private String fileName; private HashMap projList; private long valuesSetTime; private boolean update = true; private ArrayList keyList; private ArrayList typesToShow; private boolean showAllTypes = true; private static final String NEWLINE = "\n\r"; public SootAttributesHandler() { } public void setAttrList(ArrayList attrList) { this.attrList = new ArrayList(); this.attrList.addAll(attrList); } public String getJimpleAttributes(int lnNum) { StringBuffer sb = new StringBuffer(); if (getAttrList() == null) return sb.toString(); Iterator it = getAttrList().iterator(); while (it.hasNext()) { SootAttribute sa = (SootAttribute)it.next(); if (sa.attrForJimpleLn(lnNum)) { if (showAllTypes){ sb.append(sa.getAllTextAttrs("\n")); } else { Iterator typesIt = typesToShow.iterator(); while (typesIt.hasNext()){ sb.append(sa.getTextAttrsForType("\n", (String)typesIt.next())); } } } } String result = sb.toString(); result = result.trim(); if (result.length() == 0 ) return null; return result; } public ArrayList getJimpleLinks(int lnNum){ Iterator it = getAttrList().iterator(); ArrayList list = new ArrayList(); while (it.hasNext()){ SootAttribute sa = (SootAttribute)it.next(); if (sa.attrForJimpleLn(lnNum)){ list = sa.getAllLinkAttrs(); } } return list; } public String getJavaAttribute(int lnNum) { StringBuffer sb = new StringBuffer(); if (getAttrList() == null) return sb.toString(); Iterator it = getAttrList().iterator(); while (it.hasNext()) { SootAttribute sa = (SootAttribute)it.next(); if (sa.attrForJavaLn(lnNum)) { if (showAllTypes){ sb.append(sa.getAllTextAttrs("<br>")); } else { Iterator typesIt = typesToShow.iterator(); while (typesIt.hasNext()){ sb.append(sa.getTextAttrsForType("<br>", (String)typesIt.next())); } } } } return sb.toString(); } public ArrayList getJavaLinks(int lnNum){ ArrayList list = new ArrayList(); if (getAttrList() == null) return list; Iterator it = getAttrList().iterator(); while (it.hasNext()){ SootAttribute sa = (SootAttribute)it.next(); if (sa.attrForJavaLn(lnNum)){ if (sa.getAllLinkAttrs() != null){ list.addAll(sa.getAllLinkAttrs()); } } } return list; } /** * Returns the projList. * @return HashMap */ public HashMap getProjList() { return projList; } /** * Sets the projList. * @param projList The projList to set */ public void setProjList(HashMap projList) { this.projList = projList; } /** * Returns the attrList. * @return Vector */ public ArrayList getAttrList() { return attrList; } /** * Returns the fileName. * @return String */ public String getFileName() { return fileName; } /** * Sets the fileName. * @param fileName The fileName to set */ public void setFileName(String fileName) { this.fileName = fileName; } /** * @return */ public long getValuesSetTime() { return valuesSetTime; } /** * @param l */ public void setValuesSetTime(long l) { valuesSetTime = l; } /** * @return */ public boolean isUpdate() { return update; } /** * @param b */ public void setUpdate(boolean b) { update = b; } /** * @return */ public ArrayList getKeyList() { if (keyList == null) return keyList; if (isShowAllTypes()){ return keyList; } else { ArrayList typeList = new ArrayList(); Iterator kIt = keyList.iterator(); while (kIt.hasNext()){ AnalysisKey key = (AnalysisKey)kIt.next(); if (getTypesToShow().contains(key.getType())){ typeList.add(key); } } return typeList; } } /** * @param list */ public void setKeyList(ArrayList list) { keyList = list; } /** * @return */ public ArrayList getTypesToShow() { return typesToShow; } /** * @param list */ public void setTypesToShow(ArrayList list) { typesToShow = list; } /** * @return */ public boolean isShowAllTypes() { return showAllTypes; } /** * @param b */ public void setShowAllTypes(boolean b) { showAllTypes = b; } }
5,134
19.705645
72
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributesJavaColorer.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; import org.eclipse.jface.text.*; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.*; import org.eclipse.ui.*; import org.eclipse.ui.texteditor.AbstractTextEditor; import ca.mcgill.sable.soot.SootPlugin; import ca.mcgill.sable.soot.editors.*; public class SootAttributesJavaColorer extends AbstractAttributesColorer implements Runnable{ public void run(){ init(); computeColors(); } public void computeColors(){//SootAttributesHandler handler, ITextViewer viewer, IEditorPart editorPart){ if ((getHandler() == null) || (getHandler().getAttrList() == null)) return; ArrayList sortedAttrs = sortAttrsByLength(getHandler().getAttrList()); Iterator it = sortedAttrs.iterator(); setStyleList(new ArrayList()); getDisplay().asyncExec( new Runnable() { public void run() { if ((getViewer() != null) && (getViewer().getTextWidget() != null)){ setBgColor(getViewer().getTextWidget().getBackground()); } }; }); while (it.hasNext()) { // sets colors for stmts SootAttribute sa = (SootAttribute)it.next(); if ((sa.getJavaStartLn() != 0) && (sa.getJavaEndLn() != 0)){ if (sa.getJavaStartPos() != 0 && sa.getJavaEndPos() != 0){ if (sa.getColorList() != null){ Iterator cit = sa.getColorList().iterator(); while (cit.hasNext()){ ColorAttribute ca = (ColorAttribute)cit.next(); if (getHandler().isShowAllTypes()){ boolean fg = ca.fg() == 1 ? true: false; setAttributeTextColor(sa.getJavaStartLn(), sa.getJavaEndLn(), sa.getJavaStartPos()+1, sa.getJavaEndPos()+1, ca.getRGBColor(), fg);//, tp); } else { if (getHandler().getTypesToShow().contains(ca.type())){ boolean fg = ca.fg() == 1 ? true: false; setAttributeTextColor(sa.getJavaStartLn(), sa.getJavaEndLn(), sa.getJavaStartPos()+1, sa.getJavaEndPos()+1, ca.getRGBColor(), fg);//, tp); } } } } } } } changeStyles(); } protected void setLength(SootAttribute sa, int len){ sa.setJavaLength(len); } }
3,094
31.925532
147
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributesJavaHover.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import org.eclipse.ui.*; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.MarkerUtilities; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.ui.text.java.hover.*; import org.eclipse.jdt.core.*; import ca.mcgill.sable.soot.*; public class SootAttributesJavaHover extends AbstractSootAttributesHover implements IJavaEditorTextHover { private ArrayList fileNames; public IJavaElement getJavaElement(AbstractTextEditor textEditor) { IEditorInput input= textEditor.getEditorInput(); return (IJavaElement) ((IAdaptable) input).getAdapter(IJavaElement.class); } protected void computeAttributes() { setAttrsHandler(new SootAttributesHandler()); createAttrFileNames(); SootAttributeFilesReader safr = new SootAttributeFilesReader(); Iterator it = fileNames.iterator(); while (it.hasNext()){ String fileName = ((IPath)it.next()).toOSString(); AttributeDomProcessor adp = safr.readFile(fileName); if (adp != null) { getAttrsHandler().setAttrList(adp.getAttributes()); } } SootPlugin.getDefault().getManager().addToFileWithAttributes((IFile)getRec(), getAttrsHandler()); } private String createAttrFileNames() { fileNames = new ArrayList(); StringBuffer sb = new StringBuffer(); sb.append(SootPlugin.getWorkspace().getRoot().getProject(getSelectedProj()).getLocation().toOSString()); sb.append(sep); sb.append("sootOutput"); sb.append(sep); sb.append("attributes"); sb.append(sep); String dir = sb.toString(); IContainer c = (IContainer)SootPlugin.getWorkspace().getRoot().getProject(getSelectedProj()).getFolder("sootOutput"+sep+"attributes"+sep); try { IResource [] files = c.members(); for (int i = 0; i < files.length; i++){ Iterator it = getPackFileNames().iterator(); while (it.hasNext()){ String fileNameToMatch = (String)it.next(); if (files[i].getName().matches(fileNameToMatch+"[$].*") || files[i].getName().matches(fileNameToMatch+"\\."+"xml")){ fileNames.add(files[i].getLocation()); } } } } catch(CoreException e){ } sb.append(getPackFileName()); sb.append(".xml"); return sb.toString(); } protected void addSootAttributeMarkers() { if (getAttrsHandler() == null)return; if (getAttrsHandler().getAttrList() == null) return; Iterator it = getAttrsHandler().getAttrList().iterator(); HashMap markerAttr = new HashMap(); while (it.hasNext()) { SootAttribute sa = (SootAttribute)it.next(); if (((sa.getAllTextAttrs("<br>") == null) || (sa.getAllTextAttrs("<br>").length() == 0)) && ((sa.getAllLinkAttrs() == null) || (sa.getAllLinkAttrs().size() ==0))) continue; markerAttr.put(IMarker.LINE_NUMBER, new Integer(sa.getJavaStartLn())); try { MarkerUtilities.createMarker(getRec(), markerAttr, "ca.mcgill.sable.soot.sootattributemarker"); } catch(CoreException e) { System.out.println(e.getMessage()); } } } protected String getAttributes(AbstractTextEditor editor) { JavaAttributesComputer jac = new JavaAttributesComputer(); SootAttributesHandler handler = jac.getAttributesHandler(editor); if (handler != null){ return handler.getJavaAttribute(getLineNum()); } else { return null; } } }
4,390
29.706294
140
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributesJimpleColorer.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.*; import org.eclipse.jface.text.*; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.*; import org.eclipse.ui.texteditor.AbstractTextEditor; import ca.mcgill.sable.soot.SootPlugin; import ca.mcgill.sable.soot.editors.*; public class SootAttributesJimpleColorer extends AbstractAttributesColorer implements Runnable{ public void run(){ init(); computeColors(); } public void computeColors(){ if ((getHandler() == null) || (getHandler().getAttrList() == null)) return; ArrayList sortedAttrs = sortAttrsByLength(getHandler().getAttrList()); Iterator it = getHandler().getAttrList().iterator(); setStyleList(new ArrayList()); getDisplay().asyncExec( new Runnable() { public void run(){ setBgColor(getViewer().getTextWidget().getBackground()); }; }); while (it.hasNext()) { // sets colors for stmts SootAttribute sa = (SootAttribute)it.next(); if ((sa.getJimpleStartLn() != 0) && (sa.getJimpleEndLn() != 0)) { if ((sa.getJimpleStartPos() != 0) && (sa.getJimpleEndPos() != 0)){ if (sa.getColorList() != null){ Iterator cit = sa.getColorList().iterator(); while (cit.hasNext()){ ColorAttribute ca = (ColorAttribute)cit.next(); if (getHandler().isShowAllTypes()){ boolean fg = ca.fg() == 1 ? true: false; setAttributeTextColor(sa.getJimpleStartLn(), sa.getJimpleEndLn(), sa.getJimpleStartPos()+1, sa.getJimpleEndPos()+1, ca.getRGBColor(), fg);//, tp); } else { if (getHandler().getTypesToShow().contains(ca.type())){ boolean fg = ca.fg() == 1 ? true: false; setAttributeTextColor(sa.getJimpleStartLn(), sa.getJimpleEndLn(), sa.getJimpleStartPos()+1, sa.getJimpleEndPos()+1, ca.getRGBColor(), fg);//, tp); } } } } } } } changeStyles(); } protected void setLength(SootAttribute sa, int len){ sa.setJimpleLength(len); } }
3,049
32.152174
155
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/SootAttributesJimpleHover.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import java.util.HashMap; import java.util.Iterator; import org.eclipse.ui.*; import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.MarkerUtilities; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; //import org.eclipse.jface.text.TextPresentation; import ca.mcgill.sable.soot.*; import ca.mcgill.sable.soot.editors.*; public class SootAttributesJimpleHover extends AbstractSootAttributesHover {//implements ITextHover { public SootAttributesJimpleHover(IEditorPart editor) { setEditor(editor); } protected String getAttributes(AbstractTextEditor editor) { JimpleAttributesComputer jac = new JimpleAttributesComputer(); SootAttributesHandler handler = jac.getAttributesHandler(editor); if (handler != null){ return handler.getJimpleAttributes( getLineNum()); } else { return null; } } }
1,851
22.74359
101
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/TextAttribute.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; public class TextAttribute { private String info; private String type; public TextAttribute() { super(); } /** * @return */ public String getInfo() { return info; } /** * @return */ public String getType() { return type; } /** * @param string */ public void setInfo(String string) { info = string; } /** * @param string */ public void setType(String string) { type = string; } }
1,300
19.650794
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/ValueBoxAttribute.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2003 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import org.eclipse.swt.graphics.RGB; public class ValueBoxAttribute { private int startOffset; private int endOffset; private int javaOffsetStart; private int javaOffsetEnd; private int red; private int green; private int blue; public RGB getRGBColor(){ return new RGB(getRed(), getGreen(), getBlue()); } /** * @return */ public int getBlue() { return blue; } /** * @return */ public int getEndOffset() { return endOffset; } /** * @return */ public int getGreen() { return green; } /** * @return */ public int getRed() { return red; } /** * @return */ public int getStartOffset() { return startOffset; } /** * @param i */ public void setBlue(int i) { blue = i; } /** * @param i */ public void setEndOffset(int i) { endOffset = i; } /** * @param i */ public void setGreen(int i) { green = i; } /** * @param i */ public void setRed(int i) { red = i; } /** * @param i */ public void setStartOffset(int i) { startOffset = i; } /** * @return */ public int getJavaOffsetEnd() { return javaOffsetEnd; } /** * @return */ public int getJavaOffsetStart() { return javaOffsetStart; } /** * @param i */ public void setJavaOffsetEnd(int i) { javaOffsetEnd = i; } /** * @param i */ public void setJavaOffsetStart(int i) { javaOffsetStart = i; } }
2,355
15.828571
69
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/attributes/VisManLauncher.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.attributes; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.*; import org.eclipse.ui.*; import ca.mcgill.sable.soot.*; import ca.mcgill.sable.soot.ui.*; import java.util.*; import org.eclipse.core.resources.*; import org.eclipse.jdt.core.*; import org.eclipse.core.runtime.*; import org.eclipse.jface.dialogs.*; public class VisManLauncher implements IWorkbenchWindowActionDelegate { private IProject proj; private IResource rec; public VisManLauncher() { super(); } /* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() */ public void dispose() { } /* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) */ public void init(IWorkbenchWindow window) { } /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); AnalysisVisManipDialog dialog = new AnalysisVisManipDialog(window.getShell()); dialog.setFileList(getFilesFromCon(getProj())); dialog.setProj(getProj()); dialog.open(); if (dialog.getReturnCode() == Dialog.OK){ if (dialog.getAllSelected() != null){ Iterator selIt = dialog.getAllSelected().iterator(); while (selIt.hasNext()){ Object next = selIt.next(); SootAttributesHandler handler = SootPlugin.getDefault().getManager().getAttributesHandlerForFile((IFile)next); Object [] elems; if ((dialog.getCurrentSettingsMap() != null) && (dialog.getCurrentSettingsMap().containsKey(next))){ elems = (Object [])dialog.getCurrentSettingsMap().get(next); } else { elems = dialog.getCheckTypes().getCheckedElements(); } ArrayList toShow = new ArrayList(); for (int i = 0; i < elems.length; i++){ toShow.add(elems[i]); } handler.setTypesToShow(toShow); handler.setShowAllTypes(false); // also update currently shown editor and legend handler.setUpdate(true); final IEditorPart activeEdPart = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); SootPlugin.getDefault().getPartManager().updatePart(activeEdPart); } } } } public HashMap configureDataMap(){ HashMap map = new HashMap(); // get all .java and .jimple files in the project // for each determine if attr xml exist and if yes which // kinds of attrs there are ArrayList files = getFilesFromCon(getProj()); Iterator it = files.iterator(); while (it.hasNext()){ IFile next = (IFile)it.next(); SootAttributesHandler handler; String fileExtension = next.getFileExtension(); if (fileExtension != null && fileExtension.equals("java")){ JavaAttributesComputer jac = new JavaAttributesComputer(); jac.setProj(getProj()); jac.setRec(getRec()); handler = jac.getAttributesHandler(next); } else { JimpleAttributesComputer jac = new JimpleAttributesComputer(); jac.setProj(getProj()); jac.setRec(getRec()); handler = jac.getAttributesHandler(next); } if ((handler != null) && (handler.getAttrList() != null)){ Iterator attrsIt = handler.getAttrList().iterator(); ArrayList types = new ArrayList(); while (attrsIt.hasNext()){ SootAttribute sa = (SootAttribute)attrsIt.next(); Iterator typesIt = sa.getAnalysisTypes().iterator(); while (typesIt.hasNext()){ String val = (String)typesIt.next(); if (!types.contains(val)){ types.add(val); } } } map.put(next, types); } else { map.put(next, null); } } return map; } public ArrayList getFilesFromCon(IContainer con){ ArrayList files = new ArrayList(); try { IResource [] recs = con.members(); for (int i = 0; i < recs.length; i++){ if (recs[i] instanceof IFile){ IFile file = (IFile)recs[i]; if (file.getFileExtension() == null) continue; if (file.getFileExtension().equals("jimple") || file.getFileExtension().equals("java")){ files.add(recs[i]); } } else if (recs[i] instanceof IContainer){ files.addAll(getFilesFromCon((IContainer)recs[i])); } else { throw new RuntimeException("unknown member type"); } } } catch(CoreException e){ } return files; } /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) */ public void selectionChanged(IAction action, ISelection selection) { if (selection instanceof IStructuredSelection){ IStructuredSelection struct = (IStructuredSelection)selection; Iterator it = struct.iterator(); while (it.hasNext()){ Object next = it.next(); if (next instanceof IResource) { setProj(((IResource)next).getProject()); setRec((IResource)next); } else if (next instanceof IJavaElement) { IJavaElement jElem = (IJavaElement)next; setProj(jElem.getJavaProject().getProject()); setRec(jElem.getResource()); } } } } /** * @return */ public IProject getProj() { return proj; } /** * @param project */ public void setProj(IProject project) { proj = project; } /** * @return */ public IResource getRec() { return rec; } /** * @param resource */ public void setRec(IResource resource) { rec = resource; } }
6,312
27.826484
138
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/CGDoneAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import org.eclipse.gef.ui.actions.EditorPartAction; import org.eclipse.ui.IEditorPart; import org.eclipse.jface.resource.*; import org.eclipse.ui.*; import org.eclipse.jface.action.*; import org.eclipse.jface.viewers.*; import org.eclipse.swt.printing.*; import soot.toolkits.graph.interaction.InteractionHandler; public class CGDoneAction implements IEditorActionDelegate { public static final String DONE = "done"; /** * @param editor */ public CGDoneAction() { } public void setActiveEditor(IAction action, IEditorPart editor){ } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ protected boolean calculateEnabled() { return true; } /* * (non-Javadoc) * @see org.eclipse.jface.action.IAction#run() * steps forward through flowsets unless method * is finished */ public void run(IAction action){ InteractionHandler.v().cgDone(true); InteractionHandler.v().setInteractionCon(); } public void selectionChanged(IAction action, ISelection sel){ } }
1,917
26.797101
74
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/CGMenuProvider.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import org.eclipse.gef.ContextMenuProvider; import org.eclipse.gef.EditPartViewer; import org.eclipse.jface.action.*; import org.eclipse.gef.ui.actions.*; import org.eclipse.ui.*; import ca.mcgill.sable.graph.*; public class CGMenuProvider extends ContextMenuProvider { ActionRegistry registry; EditPartViewer viewer; IWorkbenchPart part; /** * @param viewer */ public CGMenuProvider(EditPartViewer viewer, ActionRegistry registry, IWorkbenchPart part) { super(viewer); setRegistry(registry); this.part = part; } /* (non-Javadoc) * @see org.eclipse.gef.ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager) */ public void buildContextMenu(IMenuManager menu) { GEFActionConstants.addStandardActionGroups(menu); menu.add(getRegistry().getAction(ExpandAction.EXPAND)); menu.add(getRegistry().getAction(CollapseAction.COLLAPSE)); menu.add(getRegistry().getAction(ShowCodeAction.SHOW_IN_CODE)); } /** * @return */ public ActionRegistry getRegistry() { return registry; } /** * @param registry */ public void setRegistry(ActionRegistry registry) { this.registry = registry; } }
2,023
27.111111
100
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/CallGraphGenerator.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import org.eclipse.ui.*; import org.eclipse.jface.action.*; import org.eclipse.jface.viewers.*; import ca.mcgill.sable.graph.*; import ca.mcgill.sable.graph.model.*; import org.eclipse.core.runtime.*; import java.util.*; import java.lang.reflect.*; import soot.jimple.toolkits.annotation.callgraph.*; import soot.*; import soot.tagkit.*; import ca.mcgill.sable.soot.interaction.*; import ca.mcgill.sable.soot.*; import org.eclipse.swt.widgets.*; import org.eclipse.ui.plugin.*; import soot.toolkits.graph.interaction.*; import org.eclipse.core.resources.*; import org.eclipse.jdt.core.*; import org.eclipse.ui.texteditor.*; import org.eclipse.ui.part.*; public class CallGraphGenerator { private CallGraphInfo info; private Graph graph; private InteractionController controller; private ArrayList centerList; public CallGraphGenerator() { } public void run(){ IWorkbench workbench = SootPlugin.getDefault().getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage();; try{ if (graph == null){ setGraph(new Graph()); graph.setName("CallGraph"); } else{ graph.removeAllChildren(); } IEditorPart part = page.openEditor(graph, "ca.mcgill.sable.graph.GraphEditor", true); ((GraphEditor)part).setPartFactory(new CallGraphPartFactory()); addActions((GraphEditor)part); ((GraphEditor)part).setMenuProvider(new CGMenuProvider(((GraphEditor)part).getGraphEditorGraphicalViewer(), ((GraphEditor)part).getGraphEditorActionRegistry(), part)); buildModel(); } catch (PartInitException e3){ e3.printStackTrace(); } catch (Exception e2){ e2.printStackTrace(); } } public void addActions(GraphEditor part){ ShowCodeAction showCode = new ShowCodeAction((IWorkbenchPart)part); part.getGraphEditorActionRegistry().registerAction(showCode); part.getGraphEditorSelectionActions().add(showCode.getId()); ExpandAction expand = new ExpandAction((IWorkbenchPart)part); part.getGraphEditorActionRegistry().registerAction(expand); part.getGraphEditorSelectionActions().add(expand.getId()); CollapseAction collapse = new CollapseAction((IWorkbenchPart)part); part.getGraphEditorActionRegistry().registerAction(collapse); part.getGraphEditorSelectionActions().add(collapse.getId()); } public void buildModel(){ CallGraphNode cgn = new CallGraphNode(); getGraph().addChild(cgn); cgn.setGenerator(this); cgn.setData(getInfo().getCenter()); cgn.setExpand(false); makeCons(getInfo(), cgn); } private CallGraphNode getNodeForMethod(SootMethod meth){ CallGraphNode node = null; Iterator it = getGraph().getChildren().iterator(); while (it.hasNext()){ CallGraphNode next = (CallGraphNode)it.next(); if (next.getData().equals(meth)){ node = next; } } if (node == null){ node = new CallGraphNode(); getGraph().addChild(node); node.setData(meth); } return node; } private void makeCons(CallGraphInfo info, CallGraphNode center){ Iterator it1 = info.getInputs().iterator(); while (it1.hasNext()){ MethInfo mInfo = (MethInfo)it1.next(); SootMethod sm = mInfo.method(); CallGraphNode inNode = getNodeForMethod(sm); inNode.setGenerator(this); Edge inEdge = new Edge(inNode, center); inEdge.setLabel(mInfo.edgeKind().name()); } Iterator it2 = info.getOutputs().iterator(); while (it2.hasNext()){ MethInfo mInfo = (MethInfo)it2.next(); SootMethod sm = mInfo.method(); CallGraphNode outNode = getNodeForMethod(sm); outNode.setGenerator(this); Edge inEdge = new Edge(center, outNode); inEdge.setLabel(mInfo.edgeKind().name()); } } public void collapseGraph(CallGraphNode node){ // need to undo (remove in and out nodes // who are not in center list) ArrayList inputsToRemove = new ArrayList(); ArrayList outputsToRemove = new ArrayList(); ArrayList nodesToRemove = new ArrayList(); if (node.getInputs() != null){ Iterator inIt = node.getInputs().iterator(); while (inIt.hasNext()){ Edge next = (Edge)inIt.next(); CallGraphNode src = (CallGraphNode)next.getSrc(); if (src.isLeaf()){ inputsToRemove.add(next); nodesToRemove.add(src); } } } if (node.getOutputs() != null){ Iterator outIt = node.getOutputs().iterator(); while (outIt.hasNext()){ Edge next = (Edge)outIt.next(); CallGraphNode tgt = (CallGraphNode)next.getTgt(); if (tgt.isLeaf()){ outputsToRemove.add(next); nodesToRemove.add(tgt); } } } Iterator inRIt = inputsToRemove.iterator(); while (inRIt.hasNext()){ Edge temp = (Edge)inRIt.next(); node.removeInput(temp); } Iterator outRIt = outputsToRemove.iterator(); while (outRIt.hasNext()){ Edge temp = (Edge)outRIt.next(); node.removeInput(temp); } Iterator nodeRIt = nodesToRemove.iterator(); while (nodeRIt.hasNext()){ CallGraphNode temp = (CallGraphNode)nodeRIt.next(); temp.removeAllInputs(); temp.removeAllOutputs(); getGraph().removeChild(temp); } node.setExpand(true); } public void expandGraph(CallGraphNode node){ getController().setEvent(new InteractionEvent(IInteractionConstants.CALL_GRAPH_NEXT_METHOD, node.getData())); getController().handleEvent(); } public void showInCode(CallGraphNode node){ SootMethod meth = (SootMethod)node.getData(); String sootClassName = meth.getDeclaringClass().getName(); sootClassName = sootClassName.replaceAll("\\.", System.getProperty("file.separator")); sootClassName = sootClassName + ".java"; String sootMethName = meth.getName(); IProject [] progs = SootPlugin.getWorkspace().getRoot().getProjects(); IResource fileToOpen = null; for (int i = 0; i < progs.length; i++){ IProject project = progs[i]; IJavaProject jProj = JavaCore.create(project); try { IPackageFragmentRoot [] roots = jProj.getAllPackageFragmentRoots(); for (int j = 0; j < roots.length; j++){ if (!(roots[j].getResource() instanceof IContainer)) continue; fileToOpen = ((IContainer)roots[j].getResource()).findMember(sootClassName); if (fileToOpen == null) continue; else break; } } catch(Exception e){ } if (fileToOpen != null) break; } IWorkbench workbench = SootPlugin.getDefault().getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage();; try{ IEditorPart part = page.openEditor(new FileEditorInput((IFile)fileToOpen), org.eclipse.jdt.ui.JavaUI.ID_CU_EDITOR); SourceLnPosTag methTag = (SourceLnPosTag)meth.getTag(SourceLnPosTag.NAME); if (methTag != null){ int selOffset = ((AbstractTextEditor)part).getDocumentProvider().getDocument(part.getEditorInput()).getLineOffset(methTag.startLn()-1); ((AbstractTextEditor)SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()).selectAndReveal(selOffset, 0); } } catch (PartInitException e3){ e3.printStackTrace(); } catch (Exception e2){ e2.printStackTrace(); } } public void addToGraph(Object info){ CallGraphInfo cgInfo = (CallGraphInfo)info; SootMethod center = cgInfo.getCenter(); // find the center who is already in the graph CallGraphNode centerNode = getNodeForMethod(cgInfo.getCenter()); //addToCenterList(cgInfo.getCenter()); centerNode.setExpand(false); // make connections to all the children makeCons(cgInfo, centerNode); } /** * @return */ public Graph getGraph() { return graph; } /** * @param graph */ public void setGraph(Graph graph) { this.graph = graph; } /** * @return */ public CallGraphInfo getInfo() { return info; } /** * @param info */ public void setInfo(CallGraphInfo info) { this.info = info; } /** * @return */ public InteractionController getController() { return controller; } /** * @param controller */ public void setController(InteractionController controller) { this.controller = controller; } public void addToCenterList(Object obj){ if (getCenterList() == null){ setCenterList(new ArrayList()); } getCenterList().add(obj); } /** * @return */ public ArrayList getCenterList() { return centerList; } /** * @param list */ public void setCenterList(ArrayList list) { centerList = list; } }
9,283
26.305882
170
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/CallGraphNode.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import ca.mcgill.sable.graph.model.*; import soot.*; public class CallGraphNode extends SimpleNode { private CallGraphGenerator generator; private boolean expand = true; private boolean expandCollape = false; private boolean collapse = false; public boolean isLeaf(){ if ((getOutputs() == null) ||(getOutputs().size() == 0)) return true; return false; } public CallGraphNode() { super(); } public void setData(Object obj){ if (obj instanceof SootMethod){ data = obj; firePropertyChange(DATA, obj); } } /** * @return */ public CallGraphGenerator getGenerator() { return generator; } /** * @param generator */ public void setGenerator(CallGraphGenerator generator) { this.generator = generator; } /** * @return */ public boolean isExpand() { return expand; } /** * @param b */ public void setExpand(boolean b) { expand = b; } /** * @return */ public boolean isCollapse() { return collapse; } /** * @return */ public boolean isExpandCollape() { return expandCollape; } /** * @param b */ public void setCollapse(boolean b) { collapse = b; } /** * @param b */ public void setExpandCollape(boolean b) { expandCollape = b; } }
2,102
18.839623
71
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/CallGraphNodeEditPart.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import ca.mcgill.sable.graph.editparts.SimpleNodeEditPart; import org.eclipse.draw2d.*; import org.eclipse.draw2d.geometry.*; import java.util.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import soot.*; import org.eclipse.jface.resource.*; import ca.mcgill.sable.soot.*; public class CallGraphNodeEditPart extends SimpleNodeEditPart { public CallGraphNodeEditPart() { super(); } Font f = new Font(null, "Arial", 8, SWT.NORMAL); /* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure() */ protected IFigure createFigure() { RectangleFigure rect = new RectangleFigure(); ToolbarLayout layout = new ToolbarLayout(); layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER); rect.setLayoutManager(layout); Label cLabel = new Label(); cLabel.setFont(f); cLabel.getInsets().bottom = 1; cLabel.getInsets().top = 1; cLabel.getInsets().left = 1; cLabel.getInsets().right = 1; rect.add(cLabel); Label mLabel = new Label(); mLabel.setFont(f); mLabel.getInsets().bottom = 1; mLabel.getInsets().top = 1; mLabel.getInsets().left = 1; mLabel.getInsets().right = 1; rect.add(mLabel); return rect; } Image publicImage = null; Image privateImage = null; Image protectedImage = null; protected void loadImages(){ if (publicImage == null){ ImageDescriptor desc = SootPlugin.getImageDescriptor("public_co.gif"); publicImage = desc.createImage(); } if (protectedImage == null){ ImageDescriptor desc = SootPlugin.getImageDescriptor("protected_co.gif"); protectedImage = desc.createImage(); } if (privateImage == null){ ImageDescriptor desc = SootPlugin.getImageDescriptor("private_co.gif"); privateImage = desc.createImage(); } } protected void refreshVisuals(){ Label cLabel = (Label)getFigure().getChildren().get(0); Label mLabel = (Label)getFigure().getChildren().get(1); if (getData() != null){ SootMethod currMeth = (SootMethod)getData(); String c = currMeth.getSignature().substring(0, currMeth.getSignature().indexOf(":")+1); String m = currMeth.getSignature().substring(currMeth.getSignature().indexOf(":")+1); cLabel.setText(c); mLabel.setText(m); int len = m.length() > c.length() ? m.length() : c.length(); getFigure().setSize(len*7-6, 38); loadImages(); Image image = null; if (currMeth.isPublic()){ image = publicImage; } else if (currMeth.isProtected()){ image = protectedImage; } else { image = privateImage; } ((Label)getFigure().getChildren().get(0)).setIcon(image); getFigure().revalidate(); } } public void expandGraph(){ ((CallGraphNode)getNode()).getGenerator().expandGraph((CallGraphNode)getNode()); } public void collapseGraph(){ ((CallGraphNode)getNode()).getGenerator().collapseGraph((CallGraphNode)getNode()); } public void showInCode(){ ((CallGraphNode)getNode()).getGenerator().showInCode((CallGraphNode)getNode()); } }
3,861
27.189781
91
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/CallGraphPartFactory.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import ca.mcgill.sable.graph.editparts.PartFactory; import org.eclipse.gef.*; public class CallGraphPartFactory extends PartFactory { public CallGraphPartFactory() { super(); } /* (non-Javadoc) * @see org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, java.lang.Object) */ public EditPart createEditPart(EditPart arg0, Object arg1) { EditPart part = super.createEditPart(arg0, arg1); if (arg1 instanceof CallGraphNode){ part = new CallGraphNodeEditPart(); } part.setModel(arg1); return part; } }
1,417
29.826087
99
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/CollapseAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import org.eclipse.jface.action.*; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.*; import org.eclipse.gef.ui.actions.*; import ca.mcgill.sable.graph.actions.*; public class CollapseAction extends SimpleSelectAction { public static final String COLLAPSE = "collapse action"; public CollapseAction(IWorkbenchPart part) { super(part); } protected void init(){ super.init(); setId(COLLAPSE); setText("Collapse"); } public void run(){ CallGraphNodeEditPart cgPart = (CallGraphNodeEditPart)getSelectedObjects().get(0); cgPart.collapseGraph(); } public boolean calculateEnabled(){ return true; } }
1,523
26.709091
84
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/CollapseAllAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import org.eclipse.gef.ui.actions.EditorPartAction; import org.eclipse.ui.IEditorPart; import org.eclipse.jface.resource.*; import org.eclipse.ui.*; import org.eclipse.jface.action.*; import org.eclipse.jface.viewers.*; import org.eclipse.swt.printing.*; import soot.toolkits.graph.interaction.InteractionHandler; import org.eclipse.ui.IEditorPart; import soot.toolkits.graph.interaction.InteractionHandler; import ca.mcgill.sable.soot.SootPlugin; import org.eclipse.ui.*; public class CollapseAllAction implements IEditorActionDelegate { public static final String COLLAPSE_ALL = "collapse all"; /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ protected boolean calculateEnabled() { return true; } public CollapseAllAction() { } public void run(IAction action){ InteractionHandler.v().setCgReset(true); InteractionHandler.v().setInteractionCon(); } public void setActiveEditor(IAction action, IEditorPart part){ } protected void init() { } public void selectionChanged(IAction action, ISelection sel){ } }
1,967
26.71831
74
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/ExpandAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import org.eclipse.jface.action.*; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.*; import org.eclipse.gef.ui.actions.*; import ca.mcgill.sable.graph.actions.*; public class ExpandAction extends SimpleSelectAction { public static final String EXPAND = "expand action"; public ExpandAction(IWorkbenchPart part) { super(part); } protected void init(){ super.init(); setId(EXPAND); setText("Expand"); } public void run(){ CallGraphNodeEditPart cgPart = (CallGraphNodeEditPart)getSelectedObjects().get(0); cgPart.expandGraph(); } public boolean calculateEnabled(){ return true; } }
1,511
26
84
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/callgraph/ShowCodeAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.callgraph; import org.eclipse.jface.action.*; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.*; import org.eclipse.gef.ui.actions.*; import ca.mcgill.sable.graph.actions.*; public class ShowCodeAction extends SimpleSelectAction { public static final String SHOW_IN_CODE = "show in code"; public ShowCodeAction(IWorkbenchPart part) { super(part); } protected void init(){ super.init(); setId(SHOW_IN_CODE); setText("Show in Code"); } public void run(){ CallGraphNodeEditPart cgPart = (CallGraphNodeEditPart)getSelectedObjects().get(0); cgPart.showInCode(); } public boolean calculateEnabled(){ return true; } }
1,530
26.339286
84
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/AnnotatedCFGSaver.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2005 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg; import soot.util.dot.*; import ca.mcgill.sable.soot.cfg.model.*; import java.util.*; public class AnnotatedCFGSaver { private CFGGraph graph; private String fileNameBase; private String title; public AnnotatedCFGSaver(CFGGraph graph, String fileNameBase, String title) { this.graph = graph; this.fileNameBase = fileNameBase; this.title = title; } public void saveGraph(){ DotGraph canvas = initGraph(); HashMap nodes = makeNodes(canvas); makeEdges(canvas, nodes); formatNames(canvas, nodes); String fileName = formFileName(); System.out.println("cfg fileName: "+fileName); canvas.plot(fileName); } private DotGraph initGraph(){ DotGraph canvas = new DotGraph(title); canvas.setGraphLabel(title); canvas.setGraphSize(8.0, 10.0); canvas.setOrientation(DotGraphConstants.GRAPH_ORIENT_PORTRAIT); canvas.setNodeShape(DotGraphConstants.NODE_SHAPE_PLAINTEXT); return canvas; } private HashMap makeNodes(DotGraph canvas){ HashMap nodeMap = new HashMap(); Iterator it = graph.getChildren().iterator(); int count = 0; while (it.hasNext()){ CFGNode next = (CFGNode)it.next(); String nodeName = "n"+count; nodeMap.put(next, nodeName); canvas.drawNode(nodeName); count++; } return nodeMap; } private void makeEdges(DotGraph canvas, HashMap nodeMap){ Iterator it = nodeMap.keySet().iterator(); while (it.hasNext()){ CFGNode node = (CFGNode)it.next(); String nodeName = (String)nodeMap.get(node); Iterator inputs = node.getInputs().iterator(); while (inputs.hasNext()){ CFGEdge edge = (CFGEdge)inputs.next(); CFGNode src = edge.getFrom(); String srcName = (String)nodeMap.get(src); canvas.drawEdge(srcName, nodeName); } } } private void formatNames(DotGraph canvas, HashMap nodeMap){ Iterator it = nodeMap.keySet().iterator(); while (it.hasNext()){ CFGNode node = (CFGNode)it.next(); String nodeName = (String)nodeMap.get(node); DotGraphNode dgNode = canvas.getNode(nodeName); dgNode.setHTMLLabel(getNodeLabel(node)); } } private String getNodeLabel(CFGNode node){ StringBuffer sb = new StringBuffer(); sb.append("<<TABLE BORDER=\"0\">"); sb.append("<TR><TD>"); if (node.getBefore() != null) { Iterator before = node.getBefore().getChildren().iterator(); while (before.hasNext()){ Iterator pFlowData = ((CFGPartialFlowData)before.next()).getChildren().iterator(); while (pFlowData.hasNext()){ CFGFlowInfo info = (CFGFlowInfo)pFlowData.next(); String temp = info.getText(); temp = temp.replaceAll("<", "&lt;"); temp = temp.replaceAll(">", "&gt;"); sb.append(temp); } } } sb.append("</TD></TR>"); sb.append("<TR><TD>"); sb.append("<TABLE>"); sb.append("<TR><TD>"); Iterator data = node.getData().getText().iterator(); while (data.hasNext()){ String temp = data.next().toString(); temp = temp.replaceAll("<", "&lt;"); temp = temp.replaceAll(">", "&gt;"); sb.append(temp); } sb.append("</TD></TR>"); sb.append("</TABLE>"); sb.append("</TD></TR>"); sb.append("<TR><TD>"); if (node.getAfter() != null){ Iterator after = node.getAfter().getChildren().iterator(); while (after.hasNext()){ Iterator pFlowData = ((CFGPartialFlowData)after.next()).getChildren().iterator(); while (pFlowData.hasNext()){ CFGFlowInfo info = (CFGFlowInfo)pFlowData.next(); String temp = info.getText(); temp = temp.replaceAll("<", "&lt;"); temp = temp.replaceAll(">", "&gt;"); sb.append(temp); } } } sb.append("</TD></TR>"); sb.append("</TABLE>>"); System.out.println("node data string: "+sb.toString()); return sb.toString(); } private String formFileName(){ StringBuffer sb = new StringBuffer(); sb.append(fileNameBase); String sep = System.getProperty("file.separator"); sb.append(sep); sb.append(title); sb.append(".cfg"); return sb.toString(); } }
4,793
28.9625
86
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/CFGEditor.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.ui.*; import org.eclipse.gef.ui.parts.*; import org.eclipse.gef.*; import org.eclipse.gef.editparts.*; import ca.mcgill.sable.soot.cfg.model.*; import ca.mcgill.sable.soot.cfg.editParts.*; //import org.eclipse.gef.palette.*; import org.eclipse.jface.action.*; import org.eclipse.gef.ui.actions.*; public class CFGEditor extends GraphicalEditor { private CFGGraph cfgGraph; public CFGEditor() { DefaultEditDomain defaultEditDomain = new DefaultEditDomain(this); setEditDomain(defaultEditDomain); } /* (non-Javadoc) * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer() */ protected void initializeGraphicalViewer() { getGraphicalViewer().setContents(cfgGraph); } protected void configureGraphicalViewer() { super.configureGraphicalViewer(); ScalableRootEditPart root = new ScalableRootEditPart(); getGraphicalViewer().setRootEditPart(root); ZoomManager zManager = root.getZoomManager(); double [] zoomLevels = new double[10]; for (int i = 0; i < zoomLevels.length; i++){ zoomLevels[i] = (i + 1) * 0.25; } zManager.setZoomLevels(zoomLevels); IAction zoomIn = new ZoomInAction(zManager); IAction zoomOut = new ZoomOutAction(((ScalableRootEditPart)getGraphicalViewer().getRootEditPart()).getZoomManager()); getActionRegistry().registerAction(zoomIn); getActionRegistry().registerAction(zoomOut); getSite().getKeyBindingService().registerAction(zoomIn); getSite().getKeyBindingService().registerAction(zoomOut); getGraphicalViewer().setEditPartFactory(new CFGPartFactory()); getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer())); StopAction stop = new StopAction(this); getActionRegistry().registerAction(stop); this.getSelectionActions().add(stop.getId()); UnStopAction unStop = new UnStopAction(this); getActionRegistry().registerAction(unStop); this.getSelectionActions().add(unStop.getId()); CFGMenuProvider menuProvider = new CFGMenuProvider(getGraphicalViewer(), getActionRegistry(), this); getGraphicalViewer().setContextMenu(menuProvider); getSite().registerContextMenu(menuProvider, getGraphicalViewer()); } // this is for zoom protected void createActions(){ super.createActions(); /* System.out.println("creating actions"); ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer)getGraphicalViewer(); ScalableRootEditPart root = ((ScalableRootEditPart)viewer.getRootEditPart()); ZoomManager zManager = root.getZoomManager(); IAction zoomIn = new ZoomInAction(zManager); IAction zoomOut = new ZoomOutAction(((ScalableRootEditPart)getGraphicalViewer().getRootEditPart()).getZoomManager()); getActionRegistry().registerAction(zoomIn); getActionRegistry().registerAction(zoomOut); getSite().getKeyBindingService().registerAction(zoomIn); getSite().getKeyBindingService().registerAction(zoomOut); */ } protected void setInput(IEditorInput input){ super.setInput(input); if (input instanceof CFGGraph){ setCfgGraph((CFGGraph)input); } // could also read from a dot file } /* (non-Javadoc) * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor) */ public void doSave(IProgressMonitor monitor) { // TODO Auto-generated method stub /*System.out.println("saving cfgs"); // idea is to save to dot file String fileNameBase = SootPlugin.getDefault().getCurrentProject().getFolder("sootOutput").getLocation().toOSString(); AnnotatedCFGSaver saver = new AnnotatedCFGSaver(getCfgGraph(), fileNameBase, this.getTitle()); saver.saveGraph(); isSaved = true; firePropertyChange(IEditorPart.PROP_DIRTY); */ } /*public void setContentsChanged(){ isSaved = false; firePropertyChange(IEditorPart.PROP_DIRTY); }*/ /* (non-Javadoc) * @see org.eclipse.ui.ISaveablePart#doSaveAs() */ public void doSaveAs() { // TODO Auto-generated method stub } /* (non-Javadoc) * @see org.eclipse.ui.IEditorPart#gotoMarker(org.eclipse.core.resources.IMarker) */ public void gotoMarker(IMarker marker) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see org.eclipse.ui.ISaveablePart#isDirty() */ public boolean isDirty() { // TODO Auto-generated method stub //return !isSaved; return false; } /* (non-Javadoc) * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed() */ public boolean isSaveAsAllowed() { // TODO Auto-generated method stub return false; } /** * @return */ public CFGGraph getCfgGraph() { return cfgGraph; } /** * @param graph */ public void setCfgGraph(CFGGraph graph) { cfgGraph = graph; } public void setTitle(String name){ super.setTitle(name); } public void setTitleTooltip(String text){ super.setTitleToolTip(text); } public String getToolTipText(){ return "cfg editor"; } }
5,824
27.140097
119
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/CFGMenuProvider.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ /* * Created on May 20, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package ca.mcgill.sable.soot.cfg; import org.eclipse.gef.ContextMenuProvider; import org.eclipse.gef.EditPartViewer; import org.eclipse.jface.action.*; import org.eclipse.gef.ui.actions.*; import org.eclipse.ui.*; import ca.mcgill.sable.graph.*; /** * @author jlhotak * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class CFGMenuProvider extends ContextMenuProvider { ActionRegistry registry; EditPartViewer viewer; IWorkbenchPart part; /** * @param viewer */ public CFGMenuProvider(EditPartViewer viewer, ActionRegistry registry, IWorkbenchPart part) { super(viewer); setRegistry(registry); this.part = part; // TODO Auto-generated constructor stub } /* (non-Javadoc) * @see org.eclipse.gef.ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager) */ public void buildContextMenu(IMenuManager menu) { GEFActionConstants.addStandardActionGroups(menu); // TODO Auto-generated method stub //IAction showCode = new ShowCodeAction(part); //System.out.println("registry: "+getRegistry()); //System.out.println("acion: "+getRegistry().getAction(StopAction.STOP)); menu.add(getRegistry().getAction(StopAction.STOP)); menu.add(getRegistry().getAction(UnStopAction.UN_STOP)); //getRegistry().registerAction(showCode); //((GraphEditor)part).getGraphEditorSelectionActions().add(showCode); } /** * @return */ public ActionRegistry getRegistry() { return registry; } /** * @param registry */ public void setRegistry(ActionRegistry registry) { this.registry = registry; } }
2,626
28.516854
100
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/CFGTests.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg; import org.eclipse.ui.*; import org.eclipse.jface.action.*; import org.eclipse.jface.viewers.*; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Display; import org.eclipse.draw2d.*; import org.eclipse.draw2d.graph.*; import org.eclipse.draw2d.geometry.*; import java.util.*; public class CFGTests implements IWorkbenchWindowActionDelegate { public void run(IAction action){ Shell shell = new Shell(); shell.open(); shell.setText("CFG Test"); LightweightSystem lws = new LightweightSystem(shell); Panel p = new Panel(); p.setBounds(new Rectangle(0,0,-1,-1)); lws.setContents(p); HashMap nodeMap = new HashMap(); DirectedGraph dg = makeSimpleGraph(); Iterator nIt = dg.nodes.iterator(); while (nIt.hasNext()){ Node nextNode = (Node)nIt.next(); IFigure node = new RectangleFigure(); IFigure label = new Label((String)nextNode.data); label.setSize(nextNode.width, 36); node.add(label); int len = ((String)nextNode.data).length() * 5; node.setLocation(new Point(nextNode.x, nextNode.y)); node.setSize(nextNode.width, 36); System.out.println("bounds: "+node.getBounds()); p.add(node); nodeMap.put(nextNode, node); } Iterator eIt = dg.edges.iterator(); while (eIt.hasNext()){ Edge nextEdge = (Edge)eIt.next(); PolylineConnection edge = new PolylineConnection(); ChopboxAnchor ca1 = new ChopboxAnchor((IFigure)nodeMap.get(nextEdge.source)); ChopboxAnchor ca2 = new ChopboxAnchor((IFigure)nodeMap.get(nextEdge.target)); edge.setSourceAnchor(ca1); edge.setTargetAnchor(ca2); edge.setTargetDecoration(new PolygonDecoration()); p.add(edge); } lws.setContents(p); Display display = Display.getDefault(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } } public DirectedGraph makeSimpleGraph(){ NodeList nl = new NodeList(); Node n1 = new Node(); String data = "y = 3"; n1.data = data; n1.width = data.length() * 7; nl.add(n1); Node n2 = new Node(); data = "if i >= 10 goto L0"; n2.data = data; n2.width = data.length() * 7; nl.add(n2); Node n3 = new Node(); data = "if i != 0 goto L1"; n3.data = data; n3.width = data.length() * 7; nl.add(n3); Node n4 = new Node(); data = "x = 5"; n4.data = data; n4.width = data.length() * 7; nl.add(n4); EdgeList el = new EdgeList(); Edge e1 = new Edge(n1, n2); el.add(e1); Edge e2 = new Edge(n2, n3); el.add(e2); Edge e3 = new Edge(n2, n4); el.add(e3); DirectedGraph dg = new DirectedGraph(); dg.edges = el; dg.nodes = nl; DirectedGraphLayout dgl = new DirectedGraphLayout(); dgl.visit(dg); return dg; } public void selectionChanged(IAction action, ISelection selection){ } public void dispose(){ } public void init(IWorkbenchWindow window){ } /** * */ public CFGTests() { super(); // TODO Auto-generated constructor stub } }
3,790
26.471014
80
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/CFGViewer.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg; import org.eclipse.ui.*; import org.eclipse.jface.action.*; import org.eclipse.jface.viewers.*; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Display; import org.eclipse.draw2d.*; import org.eclipse.draw2d.graph.*; import org.eclipse.draw2d.geometry.*; import java.util.*; import ca.mcgill.sable.soot.launching.*; import soot.toolkits.graph.*; import org.eclipse.swt.SWT; public class CFGViewer { public void run(Object sootGraph){ Shell shell = new Shell(); shell.open(); shell.setText("CFG Test"); LightweightSystem lws = new LightweightSystem(shell); Panel p = new Panel(); HashMap nodeMap = new HashMap(); org.eclipse.draw2d.graph.DirectedGraph dg = makeSootGraph((soot.toolkits.graph.DirectedGraph)sootGraph); Iterator nIt = dg.nodes.iterator(); while (nIt.hasNext()){ Node nextNode = (Node)nIt.next(); IFigure node = new RectangleFigure(); IFigure label = new Label((String)nextNode.data); label.setSize(nextNode.width, 36); node.add(label); int len = ((String)nextNode.data).length() * 5; node.setLocation(new Point(nextNode.x, nextNode.y)); node.setSize(nextNode.width, 36); p.add(node); nodeMap.put(nextNode, node); } Iterator eIt = dg.edges.iterator(); while (eIt.hasNext()){ Edge nextEdge = (Edge)eIt.next(); PolylineConnection edge = new PolylineConnection(); ChopboxAnchor ca1 = new ChopboxAnchor((IFigure)nodeMap.get(nextEdge.source)); ChopboxAnchor ca2 = new ChopboxAnchor((IFigure)nodeMap.get(nextEdge.target)); edge.setSourceAnchor(ca1); edge.setTargetAnchor(ca2); edge.setTargetDecoration(new PolygonDecoration()); p.add(edge); } lws.setContents(p); Display display = Display.getDefault(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } } public org.eclipse.draw2d.graph.DirectedGraph makeSootGraph(soot.toolkits.graph.DirectedGraph sootGraph){ org.eclipse.draw2d.graph.DirectedGraph dg = new org.eclipse.draw2d.graph.DirectedGraph(); NodeList nodes = new NodeList(); EdgeList edges = new EdgeList(); HashMap nodeMap = new HashMap(); Iterator it = sootGraph.iterator(); while (it.hasNext()){ Object node = it.next(); Node n; if (!nodeMap.containsKey(node)){ n = new Node(node.toString()); n.width = node.toString().length() * 7; nodes.add(n); nodeMap.put(node, n); } else { n = (Node)nodeMap.get(node); } Iterator succIt = sootGraph.getSuccsOf(node).iterator(); while (succIt.hasNext()){ Object succ = succIt.next(); Node s; if (!nodeMap.containsKey(succ)){ s = new Node(succ.toString()); s.width = s.toString().length() * 7; nodes.add(s); nodeMap.put(succ, s); } else { s = (Node)nodeMap.get(succ); } Edge e = new Edge(n, s); edges.add(e); } } dg.nodes = nodes; dg.edges = edges; DirectedGraphLayout dgl = new DirectedGraphLayout(); dgl.visit(dg); return dg; } public org.eclipse.draw2d.graph.DirectedGraph makeSimpleGraph(){ NodeList nl = new NodeList(); Node n1 = new Node(); String data = "y = 3"; n1.data = data; n1.width = data.length() * 7; nl.add(n1); Node n2 = new Node(); data = "if i >= 10 goto L0"; n2.data = data; n2.width = data.length() * 7; nl.add(n2); Node n3 = new Node(); data = "if i != 0 goto L1"; n3.data = data; n3.width = data.length() * 7; nl.add(n3); Node n4 = new Node(); data = "x = 5"; n4.data = data; n4.width = data.length() * 7; nl.add(n4); EdgeList el = new EdgeList(); Edge e1 = new Edge(n1, n2); el.add(e1); Edge e2 = new Edge(n2, n3); el.add(e2); Edge e3 = new Edge(n2, n4); el.add(e3); org.eclipse.draw2d.graph.DirectedGraph dg = new org.eclipse.draw2d.graph.DirectedGraph(); dg.edges = el; dg.nodes = nl; DirectedGraphLayout dgl = new DirectedGraphLayout(); dgl.visit(dg); return dg; } public void selectionChanged(IAction action, ISelection selection){ } public void dispose(){ } public void init(IWorkbenchWindow window){ } public CFGViewer() { super(); } }
4,990
26.727778
106
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/ModelCreator.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg; import soot.toolkits.graph.*; import ca.mcgill.sable.soot.cfg.model.*; import java.util.*; import ca.mcgill.sable.soot.*; import org.eclipse.ui.*; import org.eclipse.core.runtime.*; import org.eclipse.core.resources.*; import soot.toolkits.graph.interaction.*; import soot.toolkits.scalar.*; import soot.*; public class ModelCreator { private DirectedGraph sootGraph; private CFGGraph model; private IResource resource; private String edName = "CFG Editor"; private HashMap nodeMap = new HashMap(); public ModelCreator() { } public void buildModel(CFGGraph cfgGraph){ cfgGraph.setResource(getResource()); Iterator nodesIt = getSootGraph().iterator(); ArrayList nodeList = new ArrayList(); ArrayList edgeList = new ArrayList(); boolean isExceptions = false; ArrayList exceptHeads = null; if (getSootGraph().getHeads().size() > 1) { isExceptions = true; } // handle graphs that have exceptions if (getSootGraph() instanceof UnitGraph){ UnitGraph unitGraph = (UnitGraph)getSootGraph(); if (isExceptions){ exceptHeads = findExceptionBlockHeads(unitGraph.getBody()); } } while (nodesIt.hasNext()){ Object node = nodesIt.next(); CFGNode cfgNode; if (!getNodeMap().containsKey(node)){ cfgNode = new CFGNode(); initializeNode(node, cfgNode, cfgGraph); getNodeMap().put(node, cfgNode); } else { cfgNode = (CFGNode)getNodeMap().get(node); } Iterator succIt = getSootGraph().getSuccsOf(node).iterator(); while (succIt.hasNext()){ Object succ = succIt.next(); CFGNode cfgSucc; if (!getNodeMap().containsKey(succ)){ cfgSucc = new CFGNode(); initializeNode(succ, cfgSucc, cfgGraph); getNodeMap().put(succ, cfgSucc); } else { cfgSucc = (CFGNode)getNodeMap().get(succ); } CFGEdge cfgEdge = new CFGEdge(cfgNode, cfgSucc); } } Iterator headsIt = getSootGraph().getHeads().iterator(); while (headsIt.hasNext()){ Object next = headsIt.next(); CFGNode node = (CFGNode)getNodeMap().get(next); if ((exceptHeads != null) && exceptHeads.contains(next)) continue; node.getData().setHead(true); } Iterator tailsIt = getSootGraph().getTails().iterator(); while (tailsIt.hasNext()){ Object next = tailsIt.next(); CFGNode node = (CFGNode)getNodeMap().get(next); node.getData().setTail(true); } setModel(cfgGraph); } private boolean canFit(CFGPartialFlowData pFlow, int length){ Iterator it = pFlow.getChildren().iterator(); int total = 0; while (it.hasNext()){ String next = ((CFGFlowInfo)it.next()).getText(); total += next.length(); } if (total + length < 60) return true; return false; } public void highlightNode(soot.Unit u){ Iterator it = getNodeMap().keySet().iterator(); while (it.hasNext()){ Object next = it.next(); if (next.equals(u)){ CFGNode node = (CFGNode)getNodeMap().get(next); node.handleHighlightEvent(next); } } } public ArrayList findExceptionBlockHeads(Body b){ ArrayList exceptHeads = new ArrayList(); Iterator trapsIt = b.getTraps().iterator(); while (trapsIt.hasNext()){ Trap trap = (Trap)trapsIt.next(); exceptHeads.add(trap.getBeginUnit()); } return exceptHeads; } public void updateNode(FlowInfo fi){ Iterator it = getNodeMap().keySet().iterator(); while (it.hasNext()){ Object next = it.next(); if (next.equals(fi.unit())){ CFGNode node = (CFGNode)getNodeMap().get(next); getModel().newFlowData(); CFGFlowData data = new CFGFlowData(); if (fi.isBefore()){ node.setBefore(data); } else{ node.setAfter(data); } if (fi.info() instanceof FlowSet){ FlowSet fs = (FlowSet)fi.info(); Iterator fsIt = fs.iterator(); CFGFlowInfo startBrace = new CFGFlowInfo(); CFGPartialFlowData nextFlow = new CFGPartialFlowData(); data.addChild(nextFlow); nextFlow.addChild(startBrace); startBrace.setText("{"); while (fsIt.hasNext()){ Object elem = fsIt.next(); CFGFlowInfo info = new CFGFlowInfo(); if (canFit(nextFlow, elem.toString().length())){ nextFlow.addChild(info); } else { nextFlow = new CFGPartialFlowData(); data.addChild(nextFlow); nextFlow.addChild(info); } info.setText(elem.toString()); if(fsIt.hasNext()){ CFGFlowInfo comma = new CFGFlowInfo(); nextFlow.addChild(comma); comma.setText(", "); } } CFGFlowInfo endBrace = new CFGFlowInfo(); nextFlow.addChild(endBrace); endBrace.setText("}"); } else { String text = fi.info().toString(); ArrayList textGroups = new ArrayList(); int last = 0; for (int i = 0; i < text.length()/50; i++){ if (last+50 < text.length()){ int nextComma = text.indexOf(",", last+50); if (nextComma != -1){ textGroups.add(text.substring(last, nextComma+1)); last = nextComma+2; } } } if (last < text.length()){ textGroups.add(text.substring(last)); } Iterator itg = textGroups.iterator(); while (itg.hasNext()){ String nextGroup = (String)itg.next(); CFGFlowInfo info = new CFGFlowInfo(); CFGPartialFlowData pFlow = new CFGPartialFlowData(); data.addChild(pFlow); pFlow.addChild(info); info.setText(nextGroup); } } } } } private void initializeNode(Object sootNode, CFGNode cfgNode, CFGGraph cfgGraph){ ArrayList textList = new ArrayList(); int width = 0; if (sootNode instanceof soot.toolkits.graph.Block){ soot.toolkits.graph.Block block = (soot.toolkits.graph.Block)sootNode; Iterator it = block.iterator(); while (it.hasNext()){ soot.Unit u = (soot.Unit)it.next(); if (width < u.toString().length()){ width = u.toString().length(); } textList.add(u); } } else { textList.add(sootNode); width = sootNode.toString().length(); } cfgGraph.addChild(cfgNode); CFGNodeData nodeData = new CFGNodeData(); cfgNode.setData(nodeData); nodeData.setText(textList); } IEditorPart part; public void displayModel(){ IWorkbenchPage page = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); try{ CFGGraph cfgGraph = new CFGGraph(); cfgGraph.setName("cfgGraph"); part = page.openEditor(cfgGraph, "ca.mcgill.sable.soot.cfg.CFGEditor"); if (part instanceof CFGEditor){ ((CFGEditor)part).setTitle(getEdName()); ((CFGEditor)part).setTitleTooltip(getEdName()); } buildModel(cfgGraph); } catch (PartInitException ex){ System.out.println("error message: "+ex.getMessage()); System.out.println("part kind: "+part.getClass()); ex.printStackTrace(); } catch(Exception e){ System.out.println("exception error msg: "+e.getMessage()); System.out.println("error type: "+e.getClass()); e.printStackTrace(); } } public void setEditorName(String name){ edName = name; } public String getEditorName(){ return edName; } /** * @return */ public DirectedGraph getSootGraph() { return sootGraph; } /** * @param graph */ public void setSootGraph(DirectedGraph graph) { sootGraph = graph; } /** * @return */ public CFGGraph getModel() { return model; } /** * @param graph */ public void setModel(CFGGraph graph) { model = graph; } /** * @return */ public IResource getResource() { return resource; } /** * @param resource */ public void setResource(IResource resource) { this.resource = resource; } /** * @return */ public String getEdName() { return edName; } /** * @return */ public HashMap getNodeMap() { return nodeMap; } /** * @param string */ public void setEdName(String string) { edName = string; } /** * @param map */ public void setNodeMap(HashMap map) { nodeMap = map; } }
8,844
24.056657
106
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/StopAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg; import org.eclipse.jface.action.*; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.*; import org.eclipse.gef.ui.actions.*; import ca.mcgill.sable.graph.actions.*; import ca.mcgill.sable.soot.cfg.editParts.*; public class StopAction extends SimpleSelectAction { public static final String STOP = "mark stop action"; public StopAction(IWorkbenchPart part) { super(part); } protected void init(){ super.init(); setId(STOP); setText("Add Breakpoint"); } public void run(){ if (!getSelectedObjects().isEmpty() && (getSelectedObjects().get(0) instanceof NodeDataEditPart)){ NodeDataEditPart cfgPart = (NodeDataEditPart)getSelectedObjects().get(0); cfgPart.markStop(); } } public boolean calculateEnabled(){ return true; } }
1,649
26.5
100
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/UnStopAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg; import org.eclipse.jface.action.*; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.*; import org.eclipse.gef.ui.actions.*; import ca.mcgill.sable.graph.actions.*; import ca.mcgill.sable.soot.cfg.editParts.*; public class UnStopAction extends SimpleSelectAction { public static final String UN_STOP = "un mark stop action"; public UnStopAction(IWorkbenchPart part) { super(part); } protected void init(){ super.init(); setId(UN_STOP); setText("Remove Breakpoint"); } public void run(){ NodeDataEditPart cfgPart = (NodeDataEditPart)getSelectedObjects().get(0); cfgPart.unMarkStop(); } public boolean calculateEnabled(){ return true; } }
1,558
26.839286
75
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/actions/CFGActionBarContributor.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg.actions; import org.eclipse.gef.ui.actions.ActionBarContributor; import org.eclipse.jface.action.*; import org.eclipse.gef.ui.actions.*; import org.eclipse.ui.IWorkbenchActionConstants; import ca.mcgill.sable.soot.interaction.*; import org.eclipse.ui.*; public class CFGActionBarContributor extends ActionBarContributor { public CFGActionBarContributor() { super(); } private StepForwardAction stepForward; private StepBackwardAction stepBackward; private FinishMethodAction finishMethod; private NextMethodAction nextMethod; private FlowSelectAction flowSelect; private StopInteractionAction stopInteraction; /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.ActionBarContributor#buildActions() */ protected void buildActions() { addRetargetAction(new ZoomInRetargetAction()); addRetargetAction(new ZoomOutRetargetAction()); flowSelect = new FlowSelectAction(null); addAction(flowSelect); stepBackward = new StepBackwardAction(null); addAction(stepBackward); stepForward = new StepForwardAction(null); addAction(stepForward); finishMethod = new FinishMethodAction(null); addAction(finishMethod); nextMethod = new NextMethodAction(null); addAction(nextMethod); stopInteraction = new StopInteractionAction(null); addAction(stopInteraction); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.ActionBarContributor#declareGlobalActionKeys() */ protected void declareGlobalActionKeys() { } // this is for zoom toolbar buttons public void contributeToToolBar(IToolBarManager toolBarManager){ super.contributeToToolBar(toolBarManager); toolBarManager.add(new Separator()); toolBarManager.add(getAction(StepBackwardAction.STEP_BACKWARD)); toolBarManager.add(getAction(StepForwardAction.STEP_FORWARD)); toolBarManager.add(getAction(FinishMethodAction.FINISH_METHOD)); toolBarManager.add(getAction(NextMethodAction.NEXT_METHOD)); toolBarManager.add(getAction(StopInteractionAction.STOP_INTERACTION)); } public void contributeToMenu(IMenuManager menuManager){ super.contributeToMenu(menuManager); MenuManager viewMenu = new MenuManager("View"); viewMenu.add(getAction(GEFActionConstants.ZOOM_IN)); viewMenu.add(getAction(GEFActionConstants.ZOOM_OUT)); menuManager.insertAfter(IWorkbenchActionConstants.M_EDIT, viewMenu); } public void setActiveEditor(IEditorPart editor) { super.setActiveEditor(editor); stepForward.setEditorPart( editor ); stepBackward.setEditorPart(editor); finishMethod.setEditorPart(editor); nextMethod.setEditorPart(editor); flowSelect.setEditorPart(editor); stopInteraction.setEditorPart(editor); } }
3,528
30.230088
82
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/actions/FinishMethodAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg.actions; import org.eclipse.gef.ui.actions.EditorPartAction; import org.eclipse.ui.IEditorPart; import ca.mcgill.sable.soot.*; import soot.toolkits.graph.interaction.*; import org.eclipse.jface.resource.*; public class FinishMethodAction extends EditorPartAction { public static final String FINISH_METHOD = "finish method"; /** * @param editor */ public FinishMethodAction(IEditorPart editor) { super(editor); setImageDescriptor(SootPlugin.getImageDescriptor("finish_method.gif")); setToolTipText("Finish Method"); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ protected boolean calculateEnabled() { return true; } /* * (non-Javadoc) * @see org.eclipse.jface.action.IAction#run() * finishes displaying the flow sets for the current * method */ public void run(){ if (SootPlugin.getDefault().getDataKeeper().inMiddle()){ SootPlugin.getDefault().getDataKeeper().stepForwardAuto(); } InteractionHandler.v().autoCon(true); if (!InteractionHandler.v().doneCurrent()){ InteractionHandler.v().setInteractionCon(); } } public void setEditorPart(IEditorPart part){ super.setEditorPart(part); } protected void init() { super.init(); setId( FINISH_METHOD ); } }
2,143
27.210526
74
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/actions/FlowSelectAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg.actions; import org.eclipse.gef.ui.actions.SelectionAction; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.gef.*; public class FlowSelectAction extends SelectionAction { public static final String FLOW_SELECT = "flow select"; /** * @param part */ public FlowSelectAction(IWorkbenchPart part) { super(part); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ protected boolean calculateEnabled() { return true; } public void setEditorPart(IEditorPart part){ } protected void init() { super.init(); setId( FLOW_SELECT ); } public void run(){ try { EditPart part = (EditPart)getSelectedObjects().get(0); System.out.println("part selected: "+part.getClass()); } catch(ClassCastException e1){ } catch(IndexOutOfBoundsException e2){ } } }
1,747
25.089552
74
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/actions/NextMethodAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg.actions; import org.eclipse.gef.ui.actions.EditorPartAction; import org.eclipse.ui.IEditorPart; import ca.mcgill.sable.soot.*; import soot.toolkits.graph.interaction.*; import org.eclipse.jface.resource.*; public class NextMethodAction extends EditorPartAction { public static final String NEXT_METHOD = "next method"; /** * @param editor */ public NextMethodAction(IEditorPart editor) { super(editor); setImageDescriptor(SootPlugin.getImageDescriptor("next_method.gif")); setToolTipText("Next Method"); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ protected boolean calculateEnabled() { return true; } /* * (non-Javadoc) * @see org.eclipse.jface.action.IAction#run() * continues to the next method if the current * one is finished */ public void run(){ if (InteractionHandler.v().doneCurrent()){ InteractionHandler.v().setInteractionCon(); } } public void setEditorPart(IEditorPart part){ super.setEditorPart(part); } protected void init() { super.init(); setId( NEXT_METHOD ); } }
1,963
26.661972
74
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/actions/StepBackwardAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg.actions; import org.eclipse.gef.ui.actions.EditorPartAction; import org.eclipse.ui.IEditorPart; import ca.mcgill.sable.soot.*; import soot.toolkits.graph.interaction.*; import org.eclipse.jface.resource.*; public class StepBackwardAction extends EditorPartAction { public static final String STEP_BACKWARD = "step backward"; /** * @param editor */ public StepBackwardAction(IEditorPart editor) { super(editor); setImageDescriptor(SootPlugin.getImageDescriptor("resume_co_back.gif")); setToolTipText("Step Backward"); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ protected boolean calculateEnabled() { return true; } /* * (non-Javadoc) * @see org.eclipse.jface.action.IAction#run() * shows flowsets in step backward */ public void run(){ SootPlugin.getDefault().getDataKeeper().stepBack(); } public void setEditorPart(IEditorPart part){ super.setEditorPart(part); } protected void init() { super.init(); setId( STEP_BACKWARD ); } }
1,903
27
74
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/actions/StepForwardAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg.actions; import org.eclipse.gef.ui.actions.EditorPartAction; import org.eclipse.ui.IEditorPart; import ca.mcgill.sable.soot.*; import soot.toolkits.graph.interaction.*; import org.eclipse.jface.resource.*; public class StepForwardAction extends EditorPartAction { public static final String STEP_FORWARD = "step forward"; /** * @param editor */ public StepForwardAction(IEditorPart editor) { super(editor); setImageDescriptor(SootPlugin.getImageDescriptor("resume_co.gif")); setToolTipText("Step Forward"); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ protected boolean calculateEnabled() { return true; } /* * (non-Javadoc) * @see org.eclipse.jface.action.IAction#run() * steps forward through flowsets unless method * is finished */ public void run(){ if (SootPlugin.getDefault().getDataKeeper().inMiddle()){ SootPlugin.getDefault().getDataKeeper().stepForward(); } else { if (!InteractionHandler.v().doneCurrent()){ InteractionHandler.v().setInteractionCon();//true); } } } public void setEditorPart(IEditorPart part){ super.setEditorPart(part); } protected void init() { super.init(); setId( STEP_FORWARD ); } }
2,110
26.776316
74
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/actions/StopInteractionAction.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg.actions; import org.eclipse.gef.ui.actions.EditorPartAction; import org.eclipse.ui.IEditorPart; import ca.mcgill.sable.soot.*; import soot.toolkits.graph.interaction.*; import org.eclipse.jface.resource.*; public class StopInteractionAction extends EditorPartAction { public static final String STOP_INTERACTION = "stop interaction"; /** * @param editor */ public StopInteractionAction(IEditorPart editor) { super(editor); setImageDescriptor(SootPlugin.getImageDescriptor("stop_icon.gif")); setToolTipText("Stop Interaction"); } /* (non-Javadoc) * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled() */ protected boolean calculateEnabled() { return true; } /* * (non-Javadoc) * @see org.eclipse.jface.action.IAction#run() * steps forward through flowsets unless method * is finished */ public void run(){ InteractionHandler.v().stopInteraction(true); InteractionHandler.v().setInteractionCon(); } public void setEditorPart(IEditorPart part){ super.setEditorPart(part); } protected void init() { super.init(); setId( STOP_INTERACTION); } }
1,985
27.371429
74
java
soot
soot-master/eclipse/ca.mcgill.sable.soot/src/ca/mcgill/sable/soot/cfg/editParts/CFGEdgeEditPart.java
/* Soot - a J*va Optimization Framework * Copyright (C) 2004 Jennifer Lhotak * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ package ca.mcgill.sable.soot.cfg.editParts; import org.eclipse.gef.editparts.AbstractConnectionEditPart; import org.eclipse.draw2d.*; import org.eclipse.draw2d.graph.*; import java.util.*; import ca.mcgill.sable.soot.cfg.model.*; import java.beans.*; public class CFGEdgeEditPart extends AbstractConnectionEditPart { public CFGEdgeEditPart() { super(); } /* (non-Javadoc) * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies() */ protected void createEditPolicies() { } protected IFigure createFigure(){ PolylineConnection conn = new PolylineConnection(); conn.setTargetDecoration(new PolygonDecoration()); conn.setConnectionRouter(new BendpointConnectionRouter()); return conn; } public void contributeToGraph(DirectedGraph graph, HashMap map){ Node source = (Node)map.get(getSource()); Node target = (Node)map.get(getTarget()); if (!source.equals(target)){ Edge e = new Edge(this, source, target); graph.edges.add(e); map.put(this, e); } } public void applyGraphResults(DirectedGraph graph, HashMap map){ Edge e = (Edge)map.get(this); if (e != null) { NodeList nl = e.vNodes; PolylineConnection conn = (PolylineConnection)getConnectionFigure(); if (nl != null){ ArrayList bends = new ArrayList(); for (int i = 0; i < nl.size(); i++){ Node n = nl.getNode(i); int x = n.x; int y = n.y; if (e.isFeedback){ bends.add(new AbsoluteBendpoint(x, y + n.height)); bends.add(new AbsoluteBendpoint(x, y)); } else { bends.add(new AbsoluteBendpoint(x, y)); bends.add(new AbsoluteBendpoint(x, y + n.height)); } } conn.setRoutingConstraint(bends); } else { conn.setRoutingConstraint(Collections.EMPTY_LIST); } } else { PolylineConnection conn = (PolylineConnection)getConnectionFigure(); Node n = (Node)map.get(getSource()); ArrayList bends = new ArrayList(); bends.add(new AbsoluteBendpoint(n.width/2 + n.x + 8, n.y + n.height + 8)); bends.add(new AbsoluteBendpoint(n.width + n.x + 8, n.y + n.height + 8)); bends.add(new AbsoluteBendpoint(n.x + n.width + 8, n.y - 16)); bends.add(new AbsoluteBendpoint(n.x + n.width/2 + 16, n.y - 16)); conn.setRoutingConstraint(bends); } } public CFGEdge getEdge(){ return (CFGEdge)getModel(); } }
3,167
28.333333
77
java