use of org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange in project che by eclipse.
the class RefactoringSession method prepareMoveChange.
private void prepareMoveChange(ChangeInfo changeInfo, Change ch) {
changeInfo.setName(ChangeInfo.ChangeName.MOVE);
if (ch instanceof MoveCompilationUnitChange) {
MoveCompilationUnitChange moveChange = (MoveCompilationUnitChange) ch;
String className = moveChange.getCu().getPath().lastSegment();
changeInfo.setOldPath(moveChange.getDestinationPackage().getPath().append(className).toString());
changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
}
}
use of org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange in project che by eclipse.
the class ReorgCorrectionsSubProcessor method getWrongPackageDeclNameProposals.
public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
ICompilationUnit cu = context.getCompilationUnit();
boolean isLinked = cu.getResource().isLinked();
// correct package declaration
// bug 38357
int relevance = cu.getPackageDeclarations().length == 0 ? IProposalRelevance.MISSING_PACKAGE_DECLARATION : IProposalRelevance.CORRECT_PACKAGE_DECLARATION;
proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance));
// move to package
IPackageDeclaration[] packDecls = cu.getPackageDeclarations();
//$NON-NLS-1$
String newPackName = packDecls.length > 0 ? packDecls[0].getElementName() : "";
IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(cu);
IPackageFragment newPack = root.getPackageFragment(newPackName);
ICompilationUnit newCU = newPack.getCompilationUnit(cu.getElementName());
if (!newCU.exists() && !isLinked) {
String label;
if (newPack.isDefaultPackage()) {
label = Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu));
} else {
String packageLabel = JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT);
label = Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel });
}
CompositeChange composite = new CompositeChange(label);
composite.add(new CreatePackageChange(newPack));
composite.add(new MoveCompilationUnitChange(cu, newPack));
proposals.add(new ChangeCorrectionProposal(label, composite, IProposalRelevance.MOVE_CU_TO_PACKAGE, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE)));
}
}
Aggregations