Skip to content

Commit

Permalink
Merge pull request #720 from soot-oss/improve/parameter_order
Browse files Browse the repository at this point in the history
unify the parameter order; remove 'convenvience' method with unnecess…
  • Loading branch information
stschott authored Oct 25, 2023
2 parents 62a1d02 + 5f6a1cd commit 26cb811
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 61 deletions.
16 changes: 2 additions & 14 deletions sootup.core/src/main/java/sootup/core/IdentifierFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.List;
import java.util.Optional;
import javax.annotation.Nonnull;
import sootup.core.model.SootClass;
import sootup.core.signatures.FieldSignature;
import sootup.core.signatures.FieldSubSignature;
import sootup.core.signatures.MethodSignature;
Expand Down Expand Up @@ -54,15 +53,15 @@ public interface IdentifierFactory {
/**
* Gets the method signature.
*
* @param methodName the method name
* @param fullyQualifiedNameDeclClass the fully qualified name decl class
* @param methodName the method name
* @param fqReturnType the fq return type
* @param parameters the parameters
* @return the method signature
*/
MethodSignature getMethodSignature(
String methodName,
String fullyQualifiedNameDeclClass,
String methodName,
String fqReturnType,
List<String> parameters);

Expand Down Expand Up @@ -96,17 +95,6 @@ MethodSignature getMethodSignature(
Type fqReturnType,
List<Type> parameters);

/**
* Gets the method signature.
*
* @param declaringClass the declaring class
* @param subSignature the sub signature
* @return the method signature
*/
@Nonnull
MethodSignature getMethodSignature(
@Nonnull SootClass declaringClass, @Nonnull MethodSubSignature subSignature);

/**
* Gets the method signature.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public Object resolveAnnotationsDefaultValue() {
public MethodSignature getSignature() {
return JavaIdentifierFactory.getInstance()
.getMethodSignature(
utilsClass, optionalToStreamMethodSubSignature);
utilsClass.getType(), optionalToStreamMethodSubSignature);
}
})
.withSignature(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static Body.BodyBuilder createBodyBuilder(boolean withAggregation) {
builder.setStartingStmt(intToA);
builder.setMethodSignature(
JavaIdentifierFactory.getInstance()
.getMethodSignature("test", "ab.c", "void", Collections.emptyList()));
.getMethodSignature("ab.c", "test", "void", Collections.emptyList()));

builder.addFlow(intToA, intToB);
builder.addFlow(intToB, ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testModification() {

bodyBuilder.setMethodSignature(
JavaIdentifierFactory.getInstance()
.getMethodSignature("test", "ab.c", "void", Collections.emptyList()));
.getMethodSignature("ab.c", "test", "void", Collections.emptyList()));
Body testBody = bodyBuilder.build();

new CastAndReturnInliner().interceptBody(bodyBuilder, null);
Expand Down Expand Up @@ -119,7 +119,7 @@ public void testNoModification() {
bodyBuilder.addFlow(bToA, ret);
bodyBuilder.setMethodSignature(
JavaIdentifierFactory.getInstance()
.getMethodSignature("test", "ab.c", "void", Collections.emptyList()));
.getMethodSignature("ab.c", "test", "void", Collections.emptyList()));
Body testBody = bodyBuilder.build();

new CastAndReturnInliner().interceptBody(bodyBuilder, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static Body.BodyBuilder createBodyBuilder(int constantCondition) {
final MethodSignature methodSignature =
JavaIdentifierFactory.getInstance()
.getMethodSignature(
"toString", "java.lang.Object", "String", Collections.emptyList());
"java.lang.Object", "toString", "String", Collections.emptyList());
Local base =
new Local(
"someObjectThatHasSomethingToString",
Expand Down Expand Up @@ -140,7 +140,7 @@ private static Body.BodyBuilder createBodyBuilder(int constantCondition) {
bodyBuilder.addFlow(ifStmt, retb);
bodyBuilder.setMethodSignature(
JavaIdentifierFactory.getInstance()
.getMethodSignature("test", "ab.c", "void", Collections.emptyList()));
.getMethodSignature("ab.c", "test", "void", Collections.emptyList()));
return bodyBuilder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static Body.BodyBuilder createBody(boolean constantFolding) {
builder.setStartingStmt(assignA);
builder.setMethodSignature(
JavaIdentifierFactory.getInstance()
.getMethodSignature("test", "ab.c", "void", Collections.emptyList()));
.getMethodSignature("ab.c", "test", "void", Collections.emptyList()));

builder.addFlow(assignA, assignB);
builder.addFlow(assignB, assignC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static Body.BodyBuilder createBody(boolean essentialOption) {
builder.setStartingStmt(strToA);
builder.setMethodSignature(
JavaIdentifierFactory.getInstance()
.getMethodSignature("test", "ab.c", "void", Collections.emptyList()));
.getMethodSignature("ab.c", "test", "void", Collections.emptyList()));

if (essentialOption) {
Stmt newToB = JavaJimple.newAssignStmt(b, JavaJimple.newNewExpr(objectType), noPositionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static Body.BodyBuilder createBody(boolean withNop) {
builder.setStartingStmt(strToA);
builder.setMethodSignature(
JavaIdentifierFactory.getInstance()
.getMethodSignature("test", "ab.c", "void", Collections.emptyList()));
.getMethodSignature("ab.c", "test", "void", Collections.emptyList()));

builder.addFlow(strToA, jump);
builder.addFlow(jump, bToA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static Body.BodyBuilder createBody(boolean unusedLocals) {

builder.setMethodSignature(
JavaIdentifierFactory.getInstance()
.getMethodSignature("test", "a.b.c", "void", Collections.emptyList()));
.getMethodSignature("a.b.c", "test", "void", Collections.emptyList()));
return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ClassUtils;
import sootup.core.IdentifierFactory;
import sootup.core.model.SootClass;
import sootup.core.signatures.FieldSignature;
import sootup.core.signatures.FieldSubSignature;
import sootup.core.signatures.MethodSignature;
Expand Down Expand Up @@ -264,16 +263,16 @@ public PackageName getPackageName(@Nonnull final String packageName) {
/**
* Always creates a new MethodSignature AND a new ClassSignature.
*
* @param methodName the method's name
* @param fullyQualifiedNameDeclClass the fully-qualified name of the declaring class
* @param parameters the methods parameters fully-qualified name or a primitive's name
* @param methodName the method's name
* @param fqReturnType the fully-qualified name of the return type or a primitive's name
* @param parameters the methods parameters fully-qualified name or a primitive's name
* @return a MethodSignature
*/
@Override
public MethodSignature getMethodSignature(
final String methodName,
final String fullyQualifiedNameDeclClass,
final String methodName,
final String fqReturnType,
final List<String> parameters) {
JavaClassType declaringClass = getClassType(fullyQualifiedNameDeclClass);
Expand Down Expand Up @@ -321,13 +320,6 @@ public MethodSignature getMethodSignature(
return new MethodSignature(declaringClassSignature, methodName, parameters, fqReturnType);
}

@Override
@Nonnull
public MethodSignature getMethodSignature(
@Nonnull SootClass declaringClass, @Nonnull MethodSubSignature subSignature) {
return getMethodSignature(declaringClass.getType(), subSignature);
}

@Override
@Nonnull
public MethodSignature getMethodSignature(
Expand Down Expand Up @@ -425,7 +417,7 @@ public MethodSignature parseMethodSignature(@Nonnull String methodSignature) {
})
.collect(Collectors.toList());

return getMethodSignature(methodName, className, returnName, argsList);
return getMethodSignature(className, methodName, returnName, argsList);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ public ModuleJavaClassType getClassType(String fullyQualifiedClassName) {

@Override
public MethodSignature getMethodSignature(
String methodName,
String fullyQualifiedNameDeclClass,
String methodName,
String fqReturnType,
List<String> parameters) {
return super.getMethodSignature(
methodName, fullyQualifiedNameDeclClass, fqReturnType, parameters);
fullyQualifiedNameDeclClass, methodName, fqReturnType, parameters);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void test() {
// JStaticInvokeExpr
MethodSignature statMethodSig =
dif.getMethodSignature(
"print", "java.system.Out", "void", Collections.singletonList("String"));
"java.system.Out", "print", "void", Collections.singletonList("String"));
Stmt staticInvokeStmt =
new JInvokeStmt(
new JStaticInvokeExpr(
Expand All @@ -112,7 +112,7 @@ public void test() {

// JSpecialInvoke
MethodSignature smethodSig =
dif.getMethodSignature("<init>", "java.lang.Object", "void", Collections.emptyList());
dif.getMethodSignature("java.lang.Object", "<init>", "void", Collections.emptyList());
Stmt specialInvokeStmt =
new JInvokeStmt(
new JSpecialInvokeExpr(
Expand All @@ -129,7 +129,7 @@ public void test() {

// JInterfaceInvoke
MethodSignature imethodSig =
dif.getMethodSignature("remove", "java.util.Iterator", "void", Collections.emptyList());
dif.getMethodSignature("java.util.Iterator", "remove", "void", Collections.emptyList());
Stmt interfaceInvokeStmt =
new JInvokeStmt(
new JInterfaceInvokeExpr(
Expand All @@ -147,12 +147,12 @@ public void test() {
// JDynamicInvoke
MethodSignature dmethodSig =
dif.getMethodSignature(
"mylambda",
JDynamicInvokeExpr.INVOKEDYNAMIC_DUMMY_CLASS_NAME,
"mylambda",
"void",
Collections.emptyList());
MethodSignature bootstrapMethodSig =
dif.getMethodSignature("run", "Runnable", "void", Collections.emptyList());
dif.getMethodSignature("Runnable", "run", "void", Collections.emptyList());
List<Immediate> bootstrapArgs = Collections.emptyList();
List<Immediate> methodArgs = Collections.emptyList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testCreateMethod() {
LocalGenerator generator = new LocalGenerator(new HashSet<>());
MethodSignature methodSignature =
view.getIdentifierFactory()
.getMethodSignature("main", "dummyMain", "void", Collections.emptyList());
.getMethodSignature("dummyMain", "main", "void", Collections.emptyList());
Body.BodyBuilder bodyBuilder = Body.builder();

final JIdentityStmt<?> firstStmt =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private SootClass buildClass() {
String className = "some.package.SomeClass";
MethodSignature methodSignatureOne =
view.getIdentifierFactory()
.getMethodSignature("main", className, "void", Collections.emptyList());
.getMethodSignature(className, "main", "void", Collections.emptyList());

StmtPositionInfo noPosInfo = StmtPositionInfo.createNoStmtPositionInfo();
final JReturnVoidStmt returnVoidStmt = new JReturnVoidStmt(noPosInfo);
Expand All @@ -87,7 +87,7 @@ private SootClass buildClass() {

MethodSignature methodSignatureTwo =
view.getIdentifierFactory()
.getMethodSignature("otherMethod", className, "int", Collections.emptyList());
.getMethodSignature(className, "otherMethod", "int", Collections.emptyList());
bodyBuilder
.setMethodSignature(methodSignatureTwo)
.setPosition(NoPositionInformation.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SootClass buildClass(Body.BodyBuilder builder) {

MethodSignature methodSignature =
view.getIdentifierFactory()
.getMethodSignature("main", "dummyMain", "void", Collections.emptyList());
.getMethodSignature("dummyMain", "main", "void", Collections.emptyList());
Body body =
builder
.setMethodSignature(methodSignature)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void getMethodSignature() {
List<String> parameters = Collections.singletonList("java.lang.Class");

MethodSignature methodSignature =
identifierFactory.getMethodSignature("foo", "java.lang.System", "java.lang.A", parameters);
identifierFactory.getMethodSignature("java.lang.System", "foo", "java.lang.A", parameters);
assertEquals(declClass, methodSignature.getDeclClassType());
assertEquals(returnType, methodSignature.getType());
assertEquals(parameter, methodSignature.getParameterTypes().get(0));
Expand All @@ -203,7 +203,7 @@ public void getMethodSignatureString() {
List<String> parameters = Collections.singletonList("java.lang.Class");

MethodSignature methodSignature =
identifierFactory.getMethodSignature("foo", "java.lang.System", "java.lang.A", parameters);
identifierFactory.getMethodSignature("java.lang.System", "foo", "java.lang.A", parameters);
assertEquals(
"<java.lang.System: java.lang.A foo(java.lang.Class)>", methodSignature.toString());
}
Expand All @@ -215,7 +215,7 @@ public void getMethodSignatureString2() {
List<String> parameters = Collections.singletonList("java.lang.Class");

MethodSignature methodSignature =
identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters);
identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters);
assertEquals("<java.lang.System: void foo(java.lang.Class)>", methodSignature.toString());
}

Expand All @@ -226,7 +226,7 @@ public void getMethodSignatureString3() {
List<String> parameters = Collections.emptyList();

MethodSignature methodSignature =
identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters);
identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters);
assertEquals("<java.lang.System: void foo()>", methodSignature.toString());
}

Expand Down Expand Up @@ -258,10 +258,10 @@ public void compMethodSignature2() {
List<String> parameters = new ArrayList<>();

MethodSignature methodSignature =
identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters);
identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters);
parameters.add("boolean");
MethodSignature methodSignature2 =
identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters);
identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters);

assertNotEquals(methodSignature, methodSignature2);
assertNotEquals(methodSignature.hashCode(), methodSignature2.hashCode());
Expand All @@ -274,9 +274,9 @@ public void compMethodSignature1() {
List<String> parameters = Collections.emptyList();

MethodSignature methodSignature =
identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters);
identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters);
MethodSignature methodSignature2 =
identifierFactory.getMethodSignature("foo", "java.lang.System", "void", parameters);
identifierFactory.getMethodSignature("java.lang.System", "foo", "void", parameters);

assertEquals(methodSignature, methodSignature2);
assertEquals(methodSignature.hashCode(), methodSignature2.hashCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private List<Stmt> convertAssertInstruction(
stmts.add(newAssignStmt);
MethodSignature methodSig =
identifierFactory.getMethodSignature(
"<init>", "java.lang.AssertionError", "void", Collections.emptyList());
"java.lang.AssertionError", "<init>", "void", Collections.emptyList());
JSpecialInvokeExpr invoke = Jimple.newSpecialInvokeExpr(failureLocal, methodSig);
JInvokeStmt invokeStmt =
Jimple.newInvokeStmt(
Expand Down Expand Up @@ -795,7 +795,7 @@ private Stmt convertInvokeInstruction(AstJavaInvokeInstruction invokeInst) {

MethodSignature methodSig =
identifierFactory.getMethodSignature(
target.getName().toString(), declaringClassSignature, returnType, parameters);
declaringClassSignature, target.getName().toString(), returnType, parameters);

if (!callee.isStatic()) {
int receiver = invokeInst.getReceiver();
Expand Down Expand Up @@ -940,8 +940,8 @@ private List<Stmt> convertStringAddition(

MethodSignature initMethod =
identifierFactory.getMethodSignature(
"<init>",
sbType.getFullyQualifiedName(),
"<init>",
VoidType.getInstance().toString(),
Collections.singletonList(type.toString()));
CAstSourcePositionMap.Position[] pos1 = new CAstSourcePositionMap.Position[2];
Expand All @@ -957,8 +957,8 @@ private List<Stmt> convertStringAddition(

MethodSignature appendMethod =
identifierFactory.getMethodSignature(
"append",
sbType.getFullyQualifiedName(),
"append",
sbType.toString(),
Collections.singletonList(type.toString()));
Local strBuilderLocal2 = localGenerator.generateLocal(sbType);
Expand All @@ -976,7 +976,7 @@ private List<Stmt> convertStringAddition(

MethodSignature toStringMethod =
identifierFactory.getMethodSignature(
"toString", sbType.getFullyQualifiedName(), sbType.toString(), Collections.emptyList());
sbType.getFullyQualifiedName(), "toString", sbType.toString(), Collections.emptyList());

Stmt toStringStmt =
Jimple.newAssignStmt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void methodRemovalTest() {
public void methodAdditionTest() {
MethodSignature methodSignature =
p.getIdentifierFactory()
.getMethodSignature("addedMethod", "utils.Operations", "void", Collections.emptyList());
.getMethodSignature("utils.Operations", "addedMethod", "void", Collections.emptyList());
Body.BodyBuilder bodyBuilder = Body.builder();
Body body = bodyBuilder.setMethodSignature(methodSignature).build();
JavaSootMethod newMethod =
Expand Down

0 comments on commit 26cb811

Please sign in to comment.