Search in sources :

Example 1 with RefactoringChangeDescriptor

use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.

the class RenameResourceProcessor method createChange.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
public Change createChange(IProgressMonitor pm) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 1);
    try {
        RenameResourceChange change = new RenameResourceChange(fResource.getFullPath(), getNewResourceName());
        change.setDescriptor(new RefactoringChangeDescriptor(createDescriptor()));
        return change;
    } finally {
        pm.done();
    }
}
Also used : RenameResourceChange(org.eclipse.ltk.core.refactoring.resource.RenameResourceChange) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 2 with RefactoringChangeDescriptor

use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.

the class InferTypeArgumentsRefactoring method createChange.

/*
	 * @see org.eclipse.ltk.core.refactoring.Refactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    //$NON-NLS-1$
    pm.beginTask("", 1);
    try {
        DynamicValidationStateChange result = new DynamicValidationStateChange(RefactoringCoreMessages.InferTypeArgumentsRefactoring_name, fChangeManager.getAllChanges()) {

            @Override
            public final ChangeDescriptor getDescriptor() {
                final Map<String, String> arguments = new HashMap<String, String>();
                final IJavaProject project = getSingleProject();
                final String description = RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description;
                final String header = project != null ? Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description_project, BasicElementLabels.getJavaElementName(project.getElementName())) : RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description;
                final String name = project != null ? project.getElementName() : null;
                final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(name, this, header);
                final String[] settings = new String[fElements.length];
                for (int index = 0; index < settings.length; index++) settings[index] = JavaElementLabels.getTextLabel(fElements[index], JavaElementLabels.ALL_FULLY_QUALIFIED);
                comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_original_elements, settings));
                if (fAssumeCloneReturnsSameType)
                    comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_assume_clone);
                if (fLeaveUnconstrainedRaw)
                    comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_leave_unconstrained);
                final InferTypeArgumentsDescriptor descriptor = RefactoringSignatureDescriptorFactory.createInferTypeArgumentsDescriptor(name, description, comment.asString(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
                for (int index = 0; index < fElements.length; index++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (index + 1), JavaRefactoringDescriptorUtil.elementToHandle(name, fElements[index]));
                arguments.put(ATTRIBUTE_CLONE, Boolean.valueOf(fAssumeCloneReturnsSameType).toString());
                arguments.put(ATTRIBUTE_LEAVE, Boolean.valueOf(fLeaveUnconstrainedRaw).toString());
                return new RefactoringChangeDescriptor(descriptor);
            }
        };
        return result;
    } finally {
        pm.done();
    }
}
Also used : InferTypeArgumentsDescriptor(org.eclipse.jdt.core.refactoring.descriptors.InferTypeArgumentsDescriptor) IJavaProject(org.eclipse.jdt.core.IJavaProject) HashMap(java.util.HashMap) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 3 with RefactoringChangeDescriptor

use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.

the class PromoteTempToFieldRefactoring method createChange.

/*
     * @see org.eclipse.jdt.internal.corext.refactoring.base.IRefactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
     */
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 1);
    try {
        if (fFieldName.length() == 0) {
            fFieldName = getInitialFieldName();
        }
        ASTRewrite rewrite = ASTRewrite.create(fCompilationUnitNode.getAST());
        if (fInitializeIn == INITIALIZE_IN_METHOD && tempHasInitializer())
            addLocalDeclarationSplit(rewrite);
        else
            addLocalDeclarationRemoval(rewrite);
        if (fInitializeIn == INITIALIZE_IN_CONSTRUCTOR)
            addInitializersToConstructors(rewrite);
        addTempRenames(rewrite);
        addFieldDeclaration(rewrite);
        CompilationUnitChange result = new CompilationUnitChange(RefactoringCoreMessages.PromoteTempToFieldRefactoring_name, fCu);
        result.setDescriptor(new RefactoringChangeDescriptor(getRefactoringDescriptor()));
        TextEdit resultingEdits = rewrite.rewriteAST();
        TextChangeCompatibility.addTextEdit(result, RefactoringCoreMessages.PromoteTempToFieldRefactoring_editName, resultingEdits);
        return result;
    } finally {
        pm.done();
    }
}
Also used : TextEdit(org.eclipse.text.edits.TextEdit) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) CompilationUnitChange(org.eclipse.jdt.core.refactoring.CompilationUnitChange) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Example 4 with RefactoringChangeDescriptor

use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.

the class RefactoringTest method performRefactoring.

protected final RefactoringStatus performRefactoring(Refactoring ref, boolean providesUndo) throws Exception {
    performDummySearch();
    IUndoManager undoManager = getUndoManager();
    if (DESCRIPTOR_TEST) {
        final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
        create.run(new NullProgressMonitor());
        RefactoringStatus checkingStatus = create.getConditionCheckingStatus();
        if (!checkingStatus.isOK())
            return checkingStatus;
        Change change = create.getChange();
        ChangeDescriptor descriptor = change.getDescriptor();
        if (descriptor instanceof RefactoringChangeDescriptor) {
            RefactoringChangeDescriptor rcd = (RefactoringChangeDescriptor) descriptor;
            RefactoringDescriptor refactoringDescriptor = rcd.getRefactoringDescriptor();
            if (refactoringDescriptor instanceof JavaRefactoringDescriptor) {
                JavaRefactoringDescriptor jrd = (JavaRefactoringDescriptor) refactoringDescriptor;
                RefactoringStatus validation = jrd.validateDescriptor();
                if (!validation.isOK())
                    return validation;
                RefactoringStatus refactoringStatus = new RefactoringStatus();
                Class expected = jrd.getClass();
                RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(jrd.getID());
                jrd = (JavaRefactoringDescriptor) contribution.createDescriptor(jrd.getID(), jrd.getProject(), jrd.getDescription(), jrd.getComment(), contribution.retrieveArgumentMap(jrd), jrd.getFlags());
                assertEquals(expected, jrd.getClass());
                ref = jrd.createRefactoring(refactoringStatus);
                if (!refactoringStatus.isOK())
                    return refactoringStatus;
                TestRenameParticipantSingle.reset();
                TestCreateParticipantSingle.reset();
                TestMoveParticipantSingle.reset();
                TestDeleteParticipantSingle.reset();
            }
        }
    }
    final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
    final PerformChangeOperation perform = new PerformChangeOperation(create);
    perform.setUndoManager(undoManager, ref.getName());
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    if (fIsPreDeltaTest) {
        IResourceChangeListener listener = new IResourceChangeListener() {

            public void resourceChanged(IResourceChangeEvent event) {
                if (create.getConditionCheckingStatus().isOK() && perform.changeExecuted()) {
                    TestModelProvider.assertTrue(event.getDelta());
                }
            }
        };
        try {
            TestModelProvider.clearDelta();
            workspace.checkpoint(false);
            workspace.addResourceChangeListener(listener);
            executePerformOperation(perform, workspace);
        } finally {
            workspace.removeResourceChangeListener(listener);
        }
    } else {
        executePerformOperation(perform, workspace);
    }
    RefactoringStatus status = create.getConditionCheckingStatus();
    if (!status.isOK())
        return status;
    assertTrue("Change wasn't executed", perform.changeExecuted());
    Change undo = perform.getUndoChange();
    if (providesUndo) {
        assertNotNull("Undo doesn't exist", undo);
        assertTrue("Undo manager is empty", undoManager.anythingToUndo());
    } else {
        assertNull("Undo manager contains undo but shouldn't", undo);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IUndoManager(org.eclipse.ltk.core.refactoring.IUndoManager) RefactoringContribution(org.eclipse.ltk.core.refactoring.RefactoringContribution) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Change(org.eclipse.ltk.core.refactoring.Change) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ChangeDescriptor(org.eclipse.ltk.core.refactoring.ChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor) RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkspace(org.eclipse.core.resources.IWorkspace) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor)

Example 5 with RefactoringChangeDescriptor

use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.

the class ConvertAnonymousToNestedRefactoring method createRefactoringDescriptor.

private RefactoringChangeDescriptor createRefactoringDescriptor() {
    final ITypeBinding binding = fAnonymousInnerClassNode.resolveBinding();
    final String[] labels = new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringMethod(), JavaElementLabels.ALL_FULLY_QUALIFIED) };
    final Map<String, String> arguments = new HashMap<String, String>();
    final String projectName = fCu.getJavaProject().getElementName();
    final int flags = RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
    final String description = RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_descriptor_description_short;
    final String header = Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_descriptor_description, labels);
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(projectName, this, header);
    comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
    comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_class_name_pattern, BasicElementLabels.getJavaElementName(fClassName)));
    String visibility = JdtFlags.getVisibilityString(fVisibility);
    if (visibility.length() == 0)
        visibility = RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_default_visibility;
    comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_visibility_pattern, visibility));
    if (fDeclareFinal && fDeclareStatic)
        comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_final_static);
    else if (fDeclareFinal)
        comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_final);
    else if (fDeclareStatic)
        comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_static);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(projectName, fCu));
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fClassName);
    arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + ' ' + new Integer(fSelectionLength).toString());
    arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fDeclareFinal).toString());
    arguments.put(ATTRIBUTE_STATIC, Boolean.valueOf(fDeclareStatic).toString());
    arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
    ConvertAnonymousDescriptor descriptor = RefactoringSignatureDescriptorFactory.createConvertAnonymousDescriptor(projectName, description, comment.asString(), arguments, flags);
    return new RefactoringChangeDescriptor(descriptor);
}
Also used : ConvertAnonymousDescriptor(org.eclipse.jdt.core.refactoring.descriptors.ConvertAnonymousDescriptor) HashMap(java.util.HashMap) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)

Aggregations

RefactoringChangeDescriptor (org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor)16 CompilationUnitChange (org.eclipse.jdt.core.refactoring.CompilationUnitChange)4 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)4 HashMap (java.util.HashMap)3 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)3 TextEdit (org.eclipse.text.edits.TextEdit)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)2 ChildListPropertyDescriptor (org.eclipse.jdt.core.dom.ChildListPropertyDescriptor)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)2 ExtractConstantDescriptor (org.eclipse.jdt.core.refactoring.descriptors.ExtractConstantDescriptor)2 ExtractLocalDescriptor (org.eclipse.jdt.core.refactoring.descriptors.ExtractLocalDescriptor)2 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)2 DynamicValidationStateChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)2 CompositeChange (org.eclipse.ltk.core.refactoring.CompositeChange)2 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)2 TextEditGroup (org.eclipse.text.edits.TextEditGroup)2 IProject (org.eclipse.core.resources.IProject)1