From 728f3071d9088f32ae217832246a551144da572f Mon Sep 17 00:00:00 2001 From: Wiktoria Peretiatkowicz <127852624+wkktoria@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:37:34 +0200 Subject: [PATCH 1/5] Create builder for SootClass --- .../java/sootup/core/model/SootClass.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/sootup.core/src/main/java/sootup/core/model/SootClass.java b/sootup.core/src/main/java/sootup/core/model/SootClass.java index acf1cfc2646..20f19cc864b 100644 --- a/sootup.core/src/main/java/sootup/core/model/SootClass.java +++ b/sootup.core/src/main/java/sootup/core/model/SootClass.java @@ -29,6 +29,8 @@ import java.util.Set; import java.util.function.Supplier; import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import sootup.core.frontend.ResolveException; import sootup.core.frontend.SootClassSource; import sootup.core.types.ClassType; @@ -291,4 +293,68 @@ public SootClass withClassSource(@Nonnull SootClassSource classSource) { public SootClass withSourceType(@Nonnull SourceType sourceType) { return new SootClass(classSource, sourceType); } + + /** + * Creates a builder for {@link SootClass}. + * @return a {@link SootClassBuilder} + */ + @Nonnull + public static ClassSourceStep builder() { + return new SootClassBuilder(); + } + + public interface ClassSourceStep { + @Nonnull + BuildStep withClassSource(@Nonnull SootClassSource classSource); + } + + public interface SourceTypeStep { + @Nonnull + BuildStep withSourceType(@Nonnull SourceType sourceType); + } + + public interface BuildStep { + @Nonnull + SootClass build(); + } + + /** + * Defines a {@link SootClass} builder. + */ + public static class SootClassBuilder implements ClassSourceStep, SourceTypeStep, BuildStep { + @Nullable + private SootClassSource classSource; + @Nullable + private SourceType sourceType; + + @Nullable + public SootClassSource getClassSource() { + return classSource; + } + + @Nullable + public SourceType getSourceType() { + return sourceType; + } + + @Nonnull + @Override + public BuildStep withClassSource(@Nonnull final SootClassSource classSource) { + this.classSource = classSource; + return this; + } + + @Nonnull + @Override + public BuildStep withSourceType(@Nonnull final SourceType sourceType) { + this.sourceType = sourceType; + return this; + } + + @Nonnull + @Override + public SootClass build() { + return new SootClass(classSource, sourceType); + } + } } From 1185bac21b6acbc3b3b63fc083ff28ad8746108a Mon Sep 17 00:00:00 2001 From: Wiktoria Peretiatkowicz <127852624+wkktoria@users.noreply.github.com> Date: Fri, 13 Sep 2024 16:49:24 +0200 Subject: [PATCH 2/5] Use getters in build method --- sootup.core/src/main/java/sootup/core/model/SootClass.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sootup.core/src/main/java/sootup/core/model/SootClass.java b/sootup.core/src/main/java/sootup/core/model/SootClass.java index 20f19cc864b..354f1bad3c3 100644 --- a/sootup.core/src/main/java/sootup/core/model/SootClass.java +++ b/sootup.core/src/main/java/sootup/core/model/SootClass.java @@ -354,7 +354,7 @@ public BuildStep withSourceType(@Nonnull final SourceType sourceType) { @Nonnull @Override public SootClass build() { - return new SootClass(classSource, sourceType); + return new SootClass(getClassSource(), getSourceType()); } } } From 351cde9d3d1360859aa4172bd845f669b3b97e65 Mon Sep 17 00:00:00 2001 From: Wiktoria Peretiatkowicz <127852624+wkktoria@users.noreply.github.com> Date: Tue, 17 Sep 2024 21:44:52 +0200 Subject: [PATCH 3/5] Create builder for OverridingClassSource --- .../core/frontend/OverridingClassSource.java | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java b/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java index 4d320e90522..28730be0eab 100644 --- a/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java +++ b/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java @@ -334,4 +334,171 @@ public OverridingClassSource withPosition(@Nullable Position position) { position, delegate); } + + /** + * Creates a builder for {@link OverridingClassSource}. + * + * @return a {@link OverridingClassSourceBuilder} + */ + @Nonnull + public static MethodsStep builder() { + return new OverridingClassSourceBuilder(); + } + + public interface MethodsStep { + @Nonnull + BuildStep withMethods(@Nonnull Collection overriddenSootMethods); + } + + public interface FieldsStep { + @Nonnull + BuildStep withFields(@Nonnull Collection overriddenSootFields); + } + + public interface ModifiersStep { + @Nonnull + BuildStep withModifiers(@Nonnull Set overriddenModifiers); + } + + public interface InterfacesStep { + @Nonnull + BuildStep withInterfaces(@Nonnull Set overriddenInterfaces); + } + + public interface SuperclassStep { + @Nonnull + BuildStep withSuperclass(@Nonnull Optional overriddenSuperclass); + } + + public interface OuterClassStep { + @Nonnull + BuildStep withOuterClass(@Nonnull Optional overriddenOuterClass); + } + + public interface PositionStep { + @Nonnull + BuildStep withPosition(@Nullable Position position); + } + + public interface BuildStep { + @Nonnull + OverridingClassSource build(); + } + + /** Defines a {@link OverridingClassSource} builder. */ + public static class OverridingClassSourceBuilder + implements MethodsStep, + FieldsStep, + ModifiersStep, + InterfacesStep, + SuperclassStep, + OuterClassStep, + PositionStep, + BuildStep { + @Nullable private Collection overriddenSootMethods; + @Nullable private Collection overriddenSootFields; + @Nullable private Set overriddenModifiers; + @Nullable private Set overriddenInterfaces; + @Nullable private Optional overriddenSuperclass; + @Nullable private Optional overriddenOuterClass; + @Nullable private Position position; + + @Nullable + public Collection getMethods() { + return overriddenSootMethods; + } + + @Nullable + public Collection getFields() { + return overriddenSootFields; + } + + @Nullable + public Set getModifiers() { + return overriddenModifiers; + } + + @Nullable + public Set getInterfaces() { + return overriddenInterfaces; + } + + @Nullable + public Optional getSuperclass() { + return overriddenSuperclass; + } + + @Nullable + public Optional getOuterClass() { + return overriddenOuterClass; + } + + @Nullable + public Position getPosition() { + return position; + } + + @Override + @Nonnull + public BuildStep withMethods(@Nonnull final Collection overriddenSootMethods) { + this.overriddenSootMethods = overriddenSootMethods; + return this; + } + + @Override + @Nonnull + public BuildStep withFields(@Nonnull final Collection overriddenSootFields) { + this.overriddenSootFields = overriddenSootFields; + return this; + } + + @Override + @Nonnull + public BuildStep withModifiers(@Nonnull final Set overriddenModifiers) { + this.overriddenModifiers = overriddenModifiers; + return this; + } + + @Override + @Nonnull + public BuildStep withInterfaces(@Nonnull final Set overriddenInterfaces) { + this.overriddenInterfaces = overriddenInterfaces; + return this; + } + + @Override + @Nonnull + public BuildStep withSuperclass(@Nonnull final Optional overriddenSuperclass) { + this.overriddenSuperclass = overriddenSuperclass; + return this; + } + + @Override + @Nonnull + public BuildStep withOuterClass(@Nonnull final Optional overriddenOuterClass) { + this.overriddenOuterClass = overriddenOuterClass; + return this; + } + + @Override + @Nonnull + public BuildStep withPosition(@Nullable final Position position) { + this.position = position; + return this; + } + + @Override + @Nonnull + public OverridingClassSource build() { + return new OverridingClassSource( + getMethods(), + getFields(), + getModifiers(), + getInterfaces(), + getSuperclass(), + getOuterClass(), + getPosition(), + null); + } + } } From 71699758a09b89899fa130af35170a7b916f8b37 Mon Sep 17 00:00:00 2001 From: Wiktoria Peretiatkowicz <127852624+wkktoria@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:13:28 +0200 Subject: [PATCH 4/5] Fix SootClass's builder Return different interfaces from the with* methods. --- .../main/java/sootup/core/model/SootClass.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/model/SootClass.java b/sootup.core/src/main/java/sootup/core/model/SootClass.java index 354f1bad3c3..e6df2225455 100644 --- a/sootup.core/src/main/java/sootup/core/model/SootClass.java +++ b/sootup.core/src/main/java/sootup/core/model/SootClass.java @@ -305,15 +305,15 @@ public static ClassSourceStep builder() { public interface ClassSourceStep { @Nonnull - BuildStep withClassSource(@Nonnull SootClassSource classSource); + SourceTypeStep withClassSource(@Nonnull SootClassSource classSource); } public interface SourceTypeStep { @Nonnull - BuildStep withSourceType(@Nonnull SourceType sourceType); + Build withSourceType(@Nonnull SourceType sourceType); } - public interface BuildStep { + public interface Build { @Nonnull SootClass build(); } @@ -321,7 +321,7 @@ public interface BuildStep { /** * Defines a {@link SootClass} builder. */ - public static class SootClassBuilder implements ClassSourceStep, SourceTypeStep, BuildStep { + public static class SootClassBuilder implements ClassSourceStep, SourceTypeStep, Build { @Nullable private SootClassSource classSource; @Nullable @@ -337,22 +337,22 @@ public SourceType getSourceType() { return sourceType; } - @Nonnull @Override - public BuildStep withClassSource(@Nonnull final SootClassSource classSource) { + @Nonnull + public SourceTypeStep withClassSource(@Nonnull SootClassSource classSource) { this.classSource = classSource; return this; } - @Nonnull @Override - public BuildStep withSourceType(@Nonnull final SourceType sourceType) { + @Nonnull + public Build withSourceType(@Nonnull SourceType sourceType) { this.sourceType = sourceType; return this; } - @Nonnull @Override + @Nonnull public SootClass build() { return new SootClass(getClassSource(), getSourceType()); } From 36a77d057a36230b21aebeae8d28cf08da84aafd Mon Sep 17 00:00:00 2001 From: Wiktoria Peretiatkowicz <127852624+wkktoria@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:25:36 +0200 Subject: [PATCH 5/5] Fix OverridingClassSource's builder Return different interfaces from the with* methods. --- .../core/frontend/OverridingClassSource.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java b/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java index 28730be0eab..c17164f7410 100644 --- a/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java +++ b/sootup.core/src/main/java/sootup/core/frontend/OverridingClassSource.java @@ -347,40 +347,40 @@ public static MethodsStep builder() { public interface MethodsStep { @Nonnull - BuildStep withMethods(@Nonnull Collection overriddenSootMethods); + FieldsStep withMethods(@Nonnull Collection overriddenSootMethods); } public interface FieldsStep { @Nonnull - BuildStep withFields(@Nonnull Collection overriddenSootFields); + ModifiersStep withFields(@Nonnull Collection overriddenSootFields); } public interface ModifiersStep { @Nonnull - BuildStep withModifiers(@Nonnull Set overriddenModifiers); + InterfacesStep withModifiers(@Nonnull Set overriddenModifiers); } public interface InterfacesStep { @Nonnull - BuildStep withInterfaces(@Nonnull Set overriddenInterfaces); + SuperclassStep withInterfaces(@Nonnull Set overriddenInterfaces); } public interface SuperclassStep { @Nonnull - BuildStep withSuperclass(@Nonnull Optional overriddenSuperclass); + OuterClassStep withSuperclass(@Nonnull Optional overriddenSuperclass); } public interface OuterClassStep { @Nonnull - BuildStep withOuterClass(@Nonnull Optional overriddenOuterClass); + PositionStep withOuterClass(@Nonnull Optional overriddenOuterClass); } public interface PositionStep { @Nonnull - BuildStep withPosition(@Nullable Position position); + Build withPosition(@Nullable Position position); } - public interface BuildStep { + public interface Build { @Nonnull OverridingClassSource build(); } @@ -394,7 +394,7 @@ public static class OverridingClassSourceBuilder SuperclassStep, OuterClassStep, PositionStep, - BuildStep { + Build { @Nullable private Collection overriddenSootMethods; @Nullable private Collection overriddenSootFields; @Nullable private Set overriddenModifiers; @@ -440,49 +440,49 @@ public Position getPosition() { @Override @Nonnull - public BuildStep withMethods(@Nonnull final Collection overriddenSootMethods) { + public FieldsStep withMethods(@Nonnull Collection overriddenSootMethods) { this.overriddenSootMethods = overriddenSootMethods; return this; } @Override @Nonnull - public BuildStep withFields(@Nonnull final Collection overriddenSootFields) { + public ModifiersStep withFields(@Nonnull Collection overriddenSootFields) { this.overriddenSootFields = overriddenSootFields; return this; } @Override @Nonnull - public BuildStep withModifiers(@Nonnull final Set overriddenModifiers) { + public InterfacesStep withModifiers(@Nonnull Set overriddenModifiers) { this.overriddenModifiers = overriddenModifiers; return this; } @Override @Nonnull - public BuildStep withInterfaces(@Nonnull final Set overriddenInterfaces) { + public SuperclassStep withInterfaces(@Nonnull Set overriddenInterfaces) { this.overriddenInterfaces = overriddenInterfaces; return this; } @Override @Nonnull - public BuildStep withSuperclass(@Nonnull final Optional overriddenSuperclass) { + public OuterClassStep withSuperclass(@Nonnull Optional overriddenSuperclass) { this.overriddenSuperclass = overriddenSuperclass; return this; } @Override @Nonnull - public BuildStep withOuterClass(@Nonnull final Optional overriddenOuterClass) { + public PositionStep withOuterClass(@Nonnull Optional overriddenOuterClass) { this.overriddenOuterClass = overriddenOuterClass; return this; } @Override @Nonnull - public BuildStep withPosition(@Nullable final Position position) { + public Build withPosition(@Nullable Position position) { this.position = position; return this; } @@ -491,14 +491,15 @@ public BuildStep withPosition(@Nullable final Position position) { @Nonnull public OverridingClassSource build() { return new OverridingClassSource( - getMethods(), - getFields(), - getModifiers(), - getInterfaces(), - getSuperclass(), - getOuterClass(), - getPosition(), - null); + getMethods(), + getFields(), + getModifiers(), + getInterfaces(), + getSuperclass(), + getOuterClass(), + getPosition(), + null + ); } } }