Skip to content

Commit 596ea94

Browse files
committed
remove another identifierfactory in the wild
1 parent 2476d2f commit 596ea94

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,10 @@ default List<ClassType> incompleteSuperClassesOf(@Nonnull ClassType classType) {
207207
}
208208
return superClasses;
209209
}
210+
211+
Set<ClassType> directlyImplementedInterfacesOf(@Nonnull ClassType type);
212+
213+
boolean isInterface(@Nonnull ClassType type);
214+
215+
Set<ClassType> directlyExtendedInterfacesOf(@Nonnull ClassType type);
210216
}

sootup.core/src/main/java/sootup/core/types/Type.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* #L%
2323
*/
2424

25+
import javax.annotation.Nonnull;
2526
import sootup.core.jimple.visitor.Acceptor;
2627
import sootup.core.jimple.visitor.TypeVisitor;
2728

@@ -50,7 +51,7 @@ public static boolean isObject(Type type) {
5051
* This method is used to make an array type for the given type. If the given type is an array
5152
* type, then increase its dimension with given dim
5253
*/
53-
public static ArrayType makeArrayType(Type type, int dim) {
54+
public static ArrayType createArrayType(@Nonnull Type type, int dim) {
5455
if (type instanceof ArrayType) {
5556
return new ArrayType(
5657
((ArrayType) type).getBaseType(), ((ArrayType) type).getDimension() + dim);

sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/BytecodeHierarchy.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,25 @@
2626
import javax.annotation.Nullable;
2727
import sootup.core.IdentifierFactory;
2828
import sootup.core.model.SootClass;
29-
import sootup.core.typehierarchy.ViewTypeHierarchy;
29+
import sootup.core.typehierarchy.TypeHierarchy;
3030
import sootup.core.types.*;
3131
import sootup.core.views.View;
3232
import sootup.java.bytecode.interceptors.typeresolving.types.BottomType;
3333

3434
/** @author Zun Wang */
3535
public class BytecodeHierarchy {
3636

37-
private final ViewTypeHierarchy typeHierarchy;
38-
private final ClassType objectClassType;
37+
private final TypeHierarchy typeHierarchy;
38+
public final ClassType objectClassType;
39+
public final ClassType throwableClassType;
3940
private final ClassType serializableClassType;
4041
private final ClassType cloneableClassType;
4142

4243
public BytecodeHierarchy(View<? extends SootClass<?>> view) {
43-
this.typeHierarchy = new ViewTypeHierarchy(view);
44+
this.typeHierarchy = view.getTypeHierarchy();
4445
IdentifierFactory factory = view.getIdentifierFactory();
4546
objectClassType = factory.getClassType("java.lang.Object");
47+
throwableClassType = factory.getClassType("java.lang.Throwable");
4648
serializableClassType = factory.getClassType("java.io.Serializable");
4749
cloneableClassType = factory.getClassType("java.lang.Cloneable");
4850
}
@@ -144,7 +146,7 @@ public Collection<Type> getLeastCommonAncestor(Type a, Type b) {
144146
ret.add(cloneableClassType);
145147
} else {
146148
for (Type type : temp) {
147-
ret.add(Type.makeArrayType(type, 1));
149+
ret.add(Type.createArrayType(type, 1));
148150
}
149151
}
150152
} else if (a instanceof ArrayType || b instanceof ArrayType) {

sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeChecker.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import javax.annotation.Nullable;
2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
30-
import sootup.core.IdentifierFactory;
3130
import sootup.core.graph.StmtGraph;
3231
import sootup.core.jimple.basic.Local;
3332
import sootup.core.jimple.basic.Value;
@@ -48,7 +47,6 @@
4847
import sootup.core.types.NullType;
4948
import sootup.core.types.PrimitiveType;
5049
import sootup.core.types.Type;
51-
import sootup.java.core.JavaIdentifierFactory;
5250

5351
public abstract class TypeChecker extends AbstractStmtVisitor<Stmt> {
5452

@@ -58,7 +56,6 @@ public abstract class TypeChecker extends AbstractStmtVisitor<Stmt> {
5856
protected final Body.BodyBuilder builder;
5957

6058
protected final StmtGraph<?> graph;
61-
private final IdentifierFactory factory = JavaIdentifierFactory.getInstance();
6259

6360
private static final Logger logger = LoggerFactory.getLogger(TypeChecker.class);
6461

@@ -120,12 +117,12 @@ public void caseAssignStmt(@Nonnull JAssignStmt<?, ?> stmt) {
120117
}
121118
}
122119
if (!findDef) {
123-
arrayType = Type.makeArrayType(type_rhs, 1);
120+
arrayType = Type.createArrayType(type_rhs, 1);
124121
}
125122
}
126123
}
127124
if (arrayType == null) {
128-
arrayType = Type.makeArrayType(type_base, 1);
125+
arrayType = Type.createArrayType(type_base, 1);
129126
}
130127
}
131128
type_lhs = arrayType.getElementType();
@@ -181,7 +178,7 @@ public void caseAssignStmt(@Nonnull JAssignStmt<?, ?> stmt) {
181178
if (sel == null) {
182179
sel = type_base;
183180
}
184-
arrayType = Type.makeArrayType(sel, 1);
181+
arrayType = Type.createArrayType(sel, 1);
185182
}
186183
}
187184
if (arrayType != null) {
@@ -204,7 +201,7 @@ public void caseAssignStmt(@Nonnull JAssignStmt<?, ?> stmt) {
204201
} else if (rhs instanceof JCastExpr) {
205202
visit(rhs, type_lhs, stmt);
206203
} else if (rhs instanceof JInstanceOfExpr) {
207-
visit(((JInstanceOfExpr) rhs).getOp(), factory.getType("java.lang.Object"), stmt);
204+
visit(((JInstanceOfExpr) rhs).getOp(), hierarchy.objectClassType, stmt);
208205
visit(rhs, type_lhs, stmt);
209206
} else if (rhs instanceof JNewArrayExpr) {
210207
visit(((JNewArrayExpr) rhs).getSize(), PrimitiveType.getInt(), stmt);
@@ -229,12 +226,12 @@ public void caseAssignStmt(@Nonnull JAssignStmt<?, ?> stmt) {
229226

230227
@Override
231228
public void caseEnterMonitorStmt(@Nonnull JEnterMonitorStmt stmt) {
232-
visit(stmt.getOp(), factory.getType("java.lang.Object"), stmt);
229+
visit(stmt.getOp(), hierarchy.objectClassType, stmt);
233230
}
234231

235232
@Override
236233
public void caseExitMonitorStmt(@Nonnull JExitMonitorStmt stmt) {
237-
visit(stmt.getOp(), factory.getType("java.lang.Object"), stmt);
234+
visit(stmt.getOp(), hierarchy.objectClassType, stmt);
238235
}
239236

240237
@Override
@@ -254,7 +251,7 @@ public void caseReturnStmt(@Nonnull JReturnStmt stmt) {
254251

255252
@Override
256253
public void caseThrowStmt(@Nonnull JThrowStmt stmt) {
257-
visit(stmt.getOp(), factory.getType("java.lang.Throwable"), stmt);
254+
visit(stmt.getOp(), hierarchy.throwableClassType, stmt);
258255
}
259256

260257
public AugEvalFunction getFuntion() {

sootup.java.bytecode/src/main/java/sootup/java/bytecode/interceptors/typeresolving/TypeResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private Collection<Typing> applyAssignmentConstraint(
182182
Type t_old = actualTyping.getType(local);
183183
Type t_right = evalFunction.evaluate(actualTyping, defStmt.getRightOp(), defStmt, graph);
184184
if (lhs instanceof JArrayRef) {
185-
t_right = Type.makeArrayType(t_right, 1);
185+
t_right = Type.createArrayType(t_right, 1);
186186
}
187187

188188
boolean isFirstType = true;
@@ -290,7 +290,7 @@ private Type convertType(@Nonnull Type type) {
290290
} else if (type instanceof ArrayType) {
291291
Type eleType = convertType(((ArrayType) type).getElementType());
292292
if (eleType != null) {
293-
return Type.makeArrayType(eleType, 1);
293+
return Type.createArrayType(eleType, 1);
294294
} else {
295295
return null;
296296
}

sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/typeresolving/CastCounterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void testAssignStmt() {
7070
final Body.BodyBuilder builder = createMethodsBuilder("assignStmt", "void");
7171
Map<String, Type> map = new HashMap<>();
7272
map.put("l0", classType);
73-
map.put("l1", Type.makeArrayType(super1, 1));
73+
map.put("l1", Type.createArrayType(super1, 1));
7474
map.put("l2", super1);
7575
map.put("$stack3", sub1);
7676
Typing typing = createTyping(builder.getLocals(), map);

0 commit comments

Comments
 (0)