Search in sources :

Example 1 with MoveCompilationUnitChange

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());
    }
}
Also used : CompilationUnit(org.eclipse.jdt.internal.core.CompilationUnit) MoveCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange)

Example 2 with MoveCompilationUnitChange

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)));
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CorrectPackageDeclarationProposal(org.eclipse.jdt.internal.ui.text.correction.proposals.CorrectPackageDeclarationProposal) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ChangeCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) CreatePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.CreatePackageChange) MoveCompilationUnitChange(org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IPackageDeclaration(org.eclipse.jdt.core.IPackageDeclaration)

Aggregations

MoveCompilationUnitChange (org.eclipse.jdt.internal.corext.refactoring.changes.MoveCompilationUnitChange)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageDeclaration (org.eclipse.jdt.core.IPackageDeclaration)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 CompilationUnit (org.eclipse.jdt.internal.core.CompilationUnit)1 CreatePackageChange (org.eclipse.jdt.internal.corext.refactoring.changes.CreatePackageChange)1 CorrectPackageDeclarationProposal (org.eclipse.jdt.internal.ui.text.correction.proposals.CorrectPackageDeclarationProposal)1 ChangeCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal)1 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)1