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..c17164f7410 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,172 @@ 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 + FieldsStep withMethods(@Nonnull Collection overriddenSootMethods); + } + + public interface FieldsStep { + @Nonnull + ModifiersStep withFields(@Nonnull Collection overriddenSootFields); + } + + public interface ModifiersStep { + @Nonnull + InterfacesStep withModifiers(@Nonnull Set overriddenModifiers); + } + + public interface InterfacesStep { + @Nonnull + SuperclassStep withInterfaces(@Nonnull Set overriddenInterfaces); + } + + public interface SuperclassStep { + @Nonnull + OuterClassStep withSuperclass(@Nonnull Optional overriddenSuperclass); + } + + public interface OuterClassStep { + @Nonnull + PositionStep withOuterClass(@Nonnull Optional overriddenOuterClass); + } + + public interface PositionStep { + @Nonnull + Build withPosition(@Nullable Position position); + } + + public interface Build { + @Nonnull + OverridingClassSource build(); + } + + /** Defines a {@link OverridingClassSource} builder. */ + public static class OverridingClassSourceBuilder + implements MethodsStep, + FieldsStep, + ModifiersStep, + InterfacesStep, + SuperclassStep, + OuterClassStep, + PositionStep, + Build { + @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 FieldsStep withMethods(@Nonnull Collection overriddenSootMethods) { + this.overriddenSootMethods = overriddenSootMethods; + return this; + } + + @Override + @Nonnull + public ModifiersStep withFields(@Nonnull Collection overriddenSootFields) { + this.overriddenSootFields = overriddenSootFields; + return this; + } + + @Override + @Nonnull + public InterfacesStep withModifiers(@Nonnull Set overriddenModifiers) { + this.overriddenModifiers = overriddenModifiers; + return this; + } + + @Override + @Nonnull + public SuperclassStep withInterfaces(@Nonnull Set overriddenInterfaces) { + this.overriddenInterfaces = overriddenInterfaces; + return this; + } + + @Override + @Nonnull + public OuterClassStep withSuperclass(@Nonnull Optional overriddenSuperclass) { + this.overriddenSuperclass = overriddenSuperclass; + return this; + } + + @Override + @Nonnull + public PositionStep withOuterClass(@Nonnull Optional overriddenOuterClass) { + this.overriddenOuterClass = overriddenOuterClass; + return this; + } + + @Override + @Nonnull + public Build withPosition(@Nullable Position position) { + this.position = position; + return this; + } + + @Override + @Nonnull + public OverridingClassSource build() { + return new OverridingClassSource( + getMethods(), + getFields(), + getModifiers(), + getInterfaces(), + getSuperclass(), + getOuterClass(), + getPosition(), + null + ); + } + } } 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..e6df2225455 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 + SourceTypeStep withClassSource(@Nonnull SootClassSource classSource); + } + + public interface SourceTypeStep { + @Nonnull + Build withSourceType(@Nonnull SourceType sourceType); + } + + public interface Build { + @Nonnull + SootClass build(); + } + + /** + * Defines a {@link SootClass} builder. + */ + public static class SootClassBuilder implements ClassSourceStep, SourceTypeStep, Build { + @Nullable + private SootClassSource classSource; + @Nullable + private SourceType sourceType; + + @Nullable + public SootClassSource getClassSource() { + return classSource; + } + + @Nullable + public SourceType getSourceType() { + return sourceType; + } + + @Override + @Nonnull + public SourceTypeStep withClassSource(@Nonnull SootClassSource classSource) { + this.classSource = classSource; + return this; + } + + @Override + @Nonnull + public Build withSourceType(@Nonnull SourceType sourceType) { + this.sourceType = sourceType; + return this; + } + + @Override + @Nonnull + public SootClass build() { + return new SootClass(getClassSource(), getSourceType()); + } + } }