diff --git a/sootup.jimple.frontend/src/main/java/sootup/jimple/frontend/JimpleStringAnalysisInputLocation.java b/sootup.jimple.frontend/src/main/java/sootup/jimple/frontend/JimpleStringAnalysisInputLocation.java index 64b40872b1..f40e0110c9 100644 --- a/sootup.jimple.frontend/src/main/java/sootup/jimple/frontend/JimpleStringAnalysisInputLocation.java +++ b/sootup.jimple.frontend/src/main/java/sootup/jimple/frontend/JimpleStringAnalysisInputLocation.java @@ -48,8 +48,8 @@ public class JimpleStringAnalysisInputLocation implements AnalysisInputLocation @Nonnull final Path path = Paths.get("only-in-memory.jimple"); @Nonnull final List bodyInterceptors; - @Nonnull private final OverridingClassSource classSource; @Nonnull final SourceType sourceType; + private String jimpleFileContents; public JimpleStringAnalysisInputLocation(@Nonnull String jimpleFileContents) { this(jimpleFileContents, SourceType.Application, Collections.emptyList()); @@ -59,34 +59,37 @@ public JimpleStringAnalysisInputLocation( @Nonnull String jimpleFileContents, @Nonnull SourceType sourceType, @Nonnull List bodyInterceptors) { + this.jimpleFileContents = jimpleFileContents; this.bodyInterceptors = bodyInterceptors; this.sourceType = sourceType; + } + private OverridingClassSource getOverridingClassSource( + String jimpleFileContents, List bodyInterceptors, View view) { + final @Nonnull OverridingClassSource classSource; try { JimpleConverter jimpleConverter = new JimpleConverter(); classSource = jimpleConverter.run( - CharStreams.fromString(jimpleFileContents), - this, - path, - bodyInterceptors, - new JimpleView(this)); + CharStreams.fromString(jimpleFileContents), this, path, bodyInterceptors, view); } catch (Exception e) { throw new IllegalArgumentException("No valid Jimple given.", e); } + return classSource; } @Nonnull @Override public Optional getClassSource( @Nonnull ClassType type, @Nonnull View view) { - return Optional.of(classSource); + return Optional.of(getOverridingClassSource(jimpleFileContents, bodyInterceptors, view)); } @Nonnull @Override public Collection getClassSources(@Nonnull View view) { - return Collections.singletonList(classSource); + return Collections.singletonList( + getOverridingClassSource(jimpleFileContents, bodyInterceptors, view)); } @Nonnull @@ -101,8 +104,9 @@ public List getBodyInterceptors() { return bodyInterceptors; } + /** This is expensive, don't use in production code. Use it only for test case for convenience. */ @Nonnull - public ClassType getClassType() { - return classSource.getClassType(); + public ClassType getClassType(@Nonnull View view) { + return getOverridingClassSource(jimpleFileContents, bodyInterceptors, view).getClassType(); } } diff --git a/sootup.jimple.frontend/src/test/java/sootup/jimple/frontend/JimpleStringAnalysisInputLocationTest.java b/sootup.jimple.frontend/src/test/java/sootup/jimple/frontend/JimpleStringAnalysisInputLocationTest.java index 5e37cfffbd..e93dfd7831 100644 --- a/sootup.jimple.frontend/src/test/java/sootup/jimple/frontend/JimpleStringAnalysisInputLocationTest.java +++ b/sootup.jimple.frontend/src/test/java/sootup/jimple/frontend/JimpleStringAnalysisInputLocationTest.java @@ -57,12 +57,12 @@ public void test() { new JimpleStringAnalysisInputLocation(methodStr); View view = new JimpleView(Collections.singletonList(analysisInputLocation)); - assertTrue(view.getClass(analysisInputLocation.getClassType()).isPresent()); + assertTrue(view.getClass(analysisInputLocation.getClassType(view)).isPresent()); MethodSignature methodSig = view.getIdentifierFactory() .getMethodSignature( - analysisInputLocation.getClassType(), + analysisInputLocation.getClassType(view), "banana", VoidType.getInstance(), Collections.emptyList());