Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create SootClass builder #1069

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions sootup.core/src/main/java/sootup/core/model/SootClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(getClassSource(), getSourceType());
}
}
}