-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
...refactoring.common.core/src/edu/cuny/citytech/refactoring/common/core/messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
CheckingPreconditions=Checking preconditions (may take a while)... | ||
CompilingSource=Compiling source... | ||
CheckingPreconditions=Checking preconditions (may take a while)... | ||
CreatingChange=Creating change... | ||
CUContainsCompileErrors=Member ''{0}'' has a compilation unit ''{1}'' that contains compilation errors. | ||
RefactoringNotPossible=Refactoring not possible. | ||
ClearingCaches=Clearing caches... | ||
NoElementsToRefactor=No elements have passed preconditions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package edu.cuny.hunter.refactoring.common.java.core; | ||
|
||
import static edu.cuny.citytech.refactoring.common.core.Messages.CheckingPreconditions; | ||
import static edu.cuny.citytech.refactoring.common.core.Messages.NoElementsToRefactor; | ||
import static java.util.stream.Collectors.toSet; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
|
@@ -23,6 +26,8 @@ | |
import org.eclipse.jdt.internal.corext.refactoring.util.TextEditBasedChangeManager; | ||
import org.eclipse.ltk.core.refactoring.Change; | ||
import org.eclipse.ltk.core.refactoring.NullChange; | ||
import org.eclipse.ltk.core.refactoring.RefactoringStatus; | ||
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; | ||
|
||
import edu.cuny.citytech.refactoring.common.core.Messages; | ||
|
||
|
@@ -31,7 +36,6 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Raffi Khatchadourian</a> | ||
*/ | ||
@SuppressWarnings("restriction") | ||
public abstract class RefactoringProcessor extends edu.cuny.citytech.refactoring.common.core.RefactoringProcessor { | ||
|
||
protected Set<RefactorableEntity> entities = new HashSet<>(); | ||
|
@@ -92,12 +96,42 @@ protected static void manageCompilationUnit(final TextEditBasedChangeManager man | |
manager.manage(rewrite.getCu(), change); | ||
} | ||
|
||
@Override | ||
public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context) | ||
throws CoreException, OperationCanceledException { | ||
RefactoringStatus status = new RefactoringStatus(); | ||
SubMonitor progress = SubMonitor.convert(monitor, CheckingPreconditions, 1); | ||
|
||
// get the status of each stream. | ||
RefactoringStatus collectedStatus = this.getEntities().parallelStream().map(RefactorableEntity::getStatus) | ||
.collect(() -> new RefactoringStatus(), (a, b) -> a.merge(b), (a, b) -> a.merge(b)); | ||
status.merge(collectedStatus); | ||
progress.worked(1); | ||
|
||
// if there are no fatal errors. | ||
if (!status.hasFatalError()) { | ||
// these are the entities passing preconditions. | ||
Set<RefactorableEntity> passingEntities = this.getPassingEntities(); | ||
|
||
// add a fatal error if there are no passing entities. | ||
if (passingEntities.isEmpty()) | ||
status.addFatalError(Messages.NoElementsToRefactor); | ||
else { | ||
// TODO: | ||
// Checks.addModifiedFilesToChecker(ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits()), | ||
// context); | ||
} | ||
} | ||
|
||
return status; | ||
} | ||
|
||
@Override | ||
public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException { | ||
try { | ||
SubMonitor progress = SubMonitor.convert(monitor, Messages.CreatingChange, 100); | ||
|
||
Set<RefactorableEntity> entities = this.getEntities(); | ||
Set<RefactorableEntity> entities = this.getPassingEntities(); | ||
|
||
if (entities.isEmpty()) | ||
return new NullChange(NoElementsToRefactor); | ||
|
@@ -107,9 +141,7 @@ public Change createChange(IProgressMonitor monitor) throws CoreException, Opera | |
for (RefactorableEntity entity : entities) { | ||
CompilationUnitRewrite rewrite = this.getCompilationUnitRewrite(entity.getCompilationUnit(), | ||
entity.getEnclosingCompilationUnit()); | ||
|
||
entity.transform(rewrite); | ||
|
||
transformProgress.worked(1); | ||
} | ||
|
||
|
@@ -120,7 +152,6 @@ public Change createChange(IProgressMonitor monitor) throws CoreException, Opera | |
.filter(cu -> !manager.containsChangesIn(cu)).toArray(ICompilationUnit[]::new); | ||
|
||
SubMonitor saveProgress = progress.split(30).setWorkRemaining(units.length * 2); | ||
|
||
for (ICompilationUnit cu : units) { | ||
CompilationUnit compilationUnit = this.getCompilationUnit(cu, saveProgress.split(1)); | ||
manageCompilationUnit(manager, this.getCompilationUnitRewrite(cu, compilationUnit), saveProgress.split(1)); | ||
|
@@ -142,4 +173,19 @@ public Object[] getElements() { | |
protected Set<RefactorableEntity> getEntities() { | ||
return entities; | ||
} | ||
|
||
/** | ||
* @return True iff the {@link RefactorableEntity} {@link Set} changed as a result of this call. | ||
* @see java.util.Set#addAll | ||
*/ | ||
protected boolean addEntities(Set<? extends RefactorableEntity> entities) { | ||
return this.getEntities().addAll(entities); | ||
} | ||
|
||
public Set<RefactorableEntity> getPassingEntities() { | ||
Set<RefactorableEntity> entities = this.getEntities(); | ||
|
||
return entities == null ? Collections.emptySet() | ||
: entities.parallelStream().filter(s -> !s.getStatus().hasError()).collect(toSet()); | ||
} | ||
} |