Skip to content

Commit

Permalink
63149: [ltk] allow changes to be executed after the 'main' change dur…
Browse files Browse the repository at this point in the history
…ing an undo [refactoring]
  • Loading branch information
Markus Keller committed Feb 26, 2008
1 parent 0030d8d commit 31c50f4
Show file tree
Hide file tree
Showing 18 changed files with 689 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#Mon Jan 29 10:51:35 CET 2007
#Mon Feb 25 18:17:19 CET 2008
compilers.incompatible-environment=1
compilers.p.build=0
compilers.p.deprecated=1
compilers.p.missing-bundle-classpath-entries=1
compilers.p.missing-packages=0
compilers.p.no-required-att=0
compilers.p.not-externalized-att=2
compilers.p.not-externalized-att=1
compilers.p.unknown-attribute=0
compilers.p.unknown-class=0
compilers.p.unknown-element=0
Expand Down
6 changes: 5 additions & 1 deletion org.eclipse.ltk.core.refactoring.tests/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ pluginName= Refactoring Core Test Plug-in
providerName= Eclipse.org

FailingParticipant.name = org.eclipse.ltk.core.refactoring.tests.participants.FailingParticipant
FailingParticipant2.name = org.eclipse.ltk.core.refactoring.tests.participants.FailingParticipant2
FailingParticipant2.name = org.eclipse.ltk.core.refactoring.tests.participants.FailingParticipant2

WorkingParticipant.name= Working Participant
WorkingParticipantPre.name= Working Participant Pre
WorkingParticipantPreAlways.name= Working Participant Pre Always
50 changes: 50 additions & 0 deletions org.eclipse.ltk.core.refactoring.tests/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</with>
</enablement>
</renameParticipant>

<renameParticipant
class="org.eclipse.ltk.core.refactoring.tests.participants.FailingParticipant2"
id="org.eclipse.ltk.core.refactoring.tests.participants.FailingParticipant2"
Expand All @@ -22,7 +23,56 @@
</with>
</enablement>
</renameParticipant>

<renameParticipant
class="org.eclipse.ltk.core.refactoring.tests.participants.WorkingParticipant"
id="org.eclipse.ltk.core.refactoring.tests.participants.WorkingParticipant"
name="%WorkingParticipant.name">
<enablement>
<or>
<with variable="element">
<instanceof value="org.eclipse.ltk.core.refactoring.tests.participants.Element"/>
</with>
<with variable="element">
<instanceof value="org.eclipse.ltk.core.refactoring.tests.participants.ElementWorking"/>
</with>
<with variable="element">
<instanceof value="org.eclipse.ltk.core.refactoring.tests.participants.ElementWorkingPre"/>
</with>
<with variable="element">
<instanceof value="org.eclipse.ltk.core.refactoring.tests.participants.ElementWorkingPreAlways"/>
</with>
</or>
</enablement>
</renameParticipant>

<renameParticipant
class="org.eclipse.ltk.core.refactoring.tests.participants.WorkingParticipantPre"
id="org.eclipse.ltk.core.refactoring.tests.participants.WorkingParticipantPre"
name="%WorkingParticipantPre.name">
<enablement>
<or>
<with variable="element">
<instanceof value="org.eclipse.ltk.core.refactoring.tests.participants.ElementWorkingPre"/>
</with>
</or>
</enablement>
</renameParticipant>

<renameParticipant
class="org.eclipse.ltk.core.refactoring.tests.participants.WorkingParticipantPre"
id="org.eclipse.ltk.core.refactoring.tests.participants.WorkingParticipantPreAlways"
name="%WorkingParticipantPreAlways.name">
<enablement>
<or>
<with variable="element">
<instanceof value="org.eclipse.ltk.core.refactoring.tests.participants.ElementWorkingPreAlways"/>
</with>
</or>
</enablement>
</renameParticipant>
</extension>

<extension
point="org.eclipse.ltk.core.refactoring.refactoringContributions">
<contribution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Oakland Software (Francis Upton) <[email protected]> -
* Fix for Bug 63149 [ltk] allow changes to be executed after the 'main' change during an undo [refactoring]
*******************************************************************************/
package org.eclipse.ltk.core.refactoring.tests.participants;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;

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 org.eclipse.ltk.core.refactoring.participants.ParticipantManager;
import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
Expand All @@ -25,9 +31,45 @@
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;

public class ElementRenameProcessor extends RenameProcessor {

Object[] fElements= new Object[] { new Element() };


public static List fHistory;

public static final String WORKING_CREATE= "workingCreate";
public static final String WORKING_EXEC= "workingExec";
public static final String WORKING_EXEC_UNDO= "workingExecUndo";
public static final String WORKINGPRE_CREATE= "workingPreCreate";
public static final String WORKINGPRE_CREATEPRE= "workingPreCreatePre";
public static final String WORKINGPRE_EXEC= "workingPreExec";
public static final String WORKINGPRE_EXECPRE= "workingPreExecPre";
public static final String WORKINGPRE_EXEC_UNDO= "workingPreExecUndo";
public static final String WORKINGPRE_EXECPRE_UNDO= "workingPreExecPreUndo";
public static final String MAIN_CREATE= "mainCreate";
public static final String MAIN_EXEC= "mainExec";
public static final String MAIN_EXEC_UNDO= "mainExecUndo";

Object[] fElements;

int fOptions;

public static void resetHistory() {
fHistory= new ArrayList();
}

public ElementRenameProcessor(int options) {
resetHistory();
fOptions= options;
if ((options & ElementRenameRefactoring.WORKING) != 0) {
if ((options & ElementRenameRefactoring.PRE_CHANGE) != 0) {
if ((options & ElementRenameRefactoring.ALWAYS_ENABLED) != 0)
fElements= new Object[] { new ElementWorkingPreAlways() };
else
fElements= new Object[] { new ElementWorkingPre() };
} else
fElements= new Object[] { new ElementWorking() };
} else
fElements= new Object[] { new Element() };
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -74,14 +116,33 @@ public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditio
* {@inheritDoc}
*/
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
return new NullChange();
fHistory.add(MAIN_CREATE);
return new NullChange() {
public Change perform(IProgressMonitor monitor) throws CoreException {
if ((fOptions & ElementRenameRefactoring.FAIL_TO_EXECUTE) != 0)
throw new RuntimeException();
fHistory.add(MAIN_EXEC);
// Undo change
return new NullChange() {
public Change perform(IProgressMonitor m2) throws CoreException {
fHistory.add(MAIN_EXEC_UNDO);
// Redo change
return new NullChange() {
public Change perform(IProgressMonitor m3) throws CoreException {
fHistory.add(MAIN_EXEC);
return null;
}
};
}
};
}
};
}

/**
* {@inheritDoc}
*/
public RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants sharedParticipants) throws CoreException {
return ParticipantManager.loadRenameParticipants(new RefactoringStatus(), this, fElements[0],
new RenameArguments("test", true), new String[0], new SharableParticipants());
return ParticipantManager.loadRenameParticipants(new RefactoringStatus(), this, fElements[0], new RenameArguments("test", true), new String[0], new SharableParticipants());
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Oakland Software (Francis Upton) <[email protected]> -
* Fix for Bug 63149 [ltk] allow changes to be executed after the 'main' change during an undo [refactoring]
*******************************************************************************/
package org.eclipse.ltk.core.refactoring.tests.participants;

import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;

public class ElementRenameRefactoring extends RenameRefactoring {

public ElementRenameRefactoring() {
super(new ElementRenameProcessor());
// Use a working participant
public static final int WORKING= 0x01;

// Cause the main refactoring to fail
public static final int FAIL_TO_EXECUTE= 0x02;

// Use the working pre-change participant
public static final int PRE_CHANGE= 0x04;

// Use the participants that are never disabled
public static final int ALWAYS_ENABLED= 0x08;

public ElementRenameRefactoring(int options) {
super(new ElementRenameProcessor(options));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2008 Oakland Software Incorporated and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Oakland Software ([email protected]) - initial contribution - bug 63149
*******************************************************************************/
package org.eclipse.ltk.core.refactoring.tests.participants;

/**
* The element to be renamed
*/
public class ElementWorking {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2008 Oakland Software Incorporated and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Oakland Software ([email protected]) - initial contribution - bug 63149
*******************************************************************************/
package org.eclipse.ltk.core.refactoring.tests.participants;

/**
* The element to be renamed
*/
public class ElementWorkingPre {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2008 Oakland Software Incorporated and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Oakland Software ([email protected]) - initial contribution - bug 63149
*******************************************************************************/
package org.eclipse.ltk.core.refactoring.tests.participants;

/**
* The element to be renamed
*/
public class ElementWorkingPreAlways {
}
Loading

0 comments on commit 31c50f4

Please sign in to comment.