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

Add utility to get the entire program instead of the first class #18

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Changes from all 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
23 changes: 22 additions & 1 deletion src/main/java/com/diffmin/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
import gumtree.spoon.diff.operations.Operation;
import gumtree.spoon.diff.operations.OperationKind;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import spoon.Launcher;
import spoon.compiler.SpoonResource;
import spoon.compiler.SpoonResourceHelper;
import spoon.reflect.CtModel;
import spoon.reflect.declaration.CtCompilationUnit;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.declaration.CtType;

/**
Expand All @@ -35,6 +39,21 @@ public App(String prevFilePath) {
modelToBeModified = launcher.buildModel();
}

/**
* Returns the root package of the file.
*
* @param file File whose all {@link CtPackage} needs to returned
* @return Root package of the file
* @throws FileNotFoundException Exception raise via {@link SpoonResourceHelper}
*/
public CtPackage getPackage(File file) throws FileNotFoundException {
final SpoonResource resource = SpoonResourceHelper.createResource(file);
final Launcher launcher = new Launcher();
launcher.addInputResource(resource);
CtModel model = launcher.buildModel();
return model.getRootPackage();
}

/**
* Computes the list of operations which is used for patching `f2`.
*
Expand All @@ -44,7 +63,9 @@ public App(String prevFilePath) {
* @throws Exception Exception raised via {@link AstComparator}
*/
public List<Operation> getOperations(File prevFile, File newFile) throws Exception {
return new AstComparator().compare(prevFile, newFile).getRootOperations();
CtElement prevPackage = getPackage(prevFile);
CtElement newPackage = getPackage(newFile);
return new AstComparator().compare(prevPackage, newPackage).getRootOperations();
}

/**
Expand Down