Code cleanup
diff --git a/bundles/org.eclipse.jst.ws.annotations.core/src/org/eclipse/jst/ws/internal/annotations/core/processor/AnnotationsCoreProcessorFactory.java b/bundles/org.eclipse.jst.ws.annotations.core/src/org/eclipse/jst/ws/internal/annotations/core/processor/AnnotationsCoreProcessorFactory.java
index 1a0093e..58ef017 100644
--- a/bundles/org.eclipse.jst.ws.annotations.core/src/org/eclipse/jst/ws/internal/annotations/core/processor/AnnotationsCoreProcessorFactory.java
+++ b/bundles/org.eclipse.jst.ws.annotations.core/src/org/eclipse/jst/ws/internal/annotations/core/processor/AnnotationsCoreProcessorFactory.java
@@ -26,6 +26,7 @@
import com.sun.mirror.apt.AnnotationProcessor;
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.apt.AnnotationProcessorFactory;
+import com.sun.mirror.apt.AnnotationProcessors;
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
/**
@@ -58,7 +59,7 @@
}
}
- return new AnnotationsCoreProcessor(annotationProcessors);
+ return AnnotationProcessors.getCompositeAnnotationProcessor(annotationProcessors);
}
public AnnotationProcessor getAnnotationProcessor(IConfigurationElement configurationElement,
diff --git a/bundles/org.eclipse.jst.ws.cxf.creation.core/src/org/eclipse/jst/ws/internal/cxf/creation/core/commands/JAXWSAnnotateJavaCommand.java b/bundles/org.eclipse.jst.ws.cxf.creation.core/src/org/eclipse/jst/ws/internal/cxf/creation/core/commands/JAXWSAnnotateJavaCommand.java
index d5eec92..8a8d382 100644
--- a/bundles/org.eclipse.jst.ws.cxf.creation.core/src/org/eclipse/jst/ws/internal/cxf/creation/core/commands/JAXWSAnnotateJavaCommand.java
+++ b/bundles/org.eclipse.jst.ws.cxf.creation.core/src/org/eclipse/jst/ws/internal/cxf/creation/core/commands/JAXWSAnnotateJavaCommand.java
@@ -13,7 +13,6 @@
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
-import java.util.Stack;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
@@ -25,28 +24,24 @@
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
-import org.eclipse.ltk.core.refactoring.TextFileChange;
-import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
-import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
-import org.eclipse.jst.ws.internal.cxf.core.model.Java2WSDataModel;
import org.eclipse.jst.ws.annotations.core.utils.AnnotationUtils;
+import org.eclipse.jst.ws.internal.cxf.core.model.Java2WSDataModel;
import org.eclipse.jst.ws.internal.cxf.core.utils.CXFModelUtils;
import org.eclipse.jst.ws.internal.cxf.creation.core.CXFCreationCorePlugin;
import org.eclipse.jst.ws.jaxws.core.utils.JDTUtils;
import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
+import org.eclipse.ltk.core.refactoring.IUndoManager;
+import org.eclipse.ltk.core.refactoring.RefactoringCore;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.text.edits.MultiTextEdit;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
/**
* @author sclarke
*/
-@SuppressWarnings("restriction")
public class JAXWSAnnotateJavaCommand extends AbstractDataModelOperation {
-
- private Stack<Change> interfaceUndoChanges = new Stack<Change>();
- private Stack<Change> classUndoChanges = new Stack<Change>();
+ private int numberOfChanges = 0;
private Java2WSDataModel model;
private IType javaClassType;
@@ -123,7 +118,7 @@
CXFModelUtils.getImportsChange(javaInterfaceType.getCompilationUnit(), model,
textFileChange, false);
- executeChange(monitor, textFileChange, interfaceUndoChanges);
+ executeChange(monitor, textFileChange);
}
private void annotateClass(IProgressMonitor monitor) throws CoreException, InvocationTargetException,
@@ -166,7 +161,7 @@
CXFModelUtils.getImportsChange(javaClassType.getCompilationUnit(), model,
textFileChange, false);
- executeChange(monitor, textFileChange, classUndoChanges);
+ executeChange(monitor, textFileChange);
}
private void annotateSEIClass(IProgressMonitor monitor) throws CoreException, InvocationTargetException,
@@ -184,55 +179,52 @@
CXFModelUtils.getImportsChange(javaClassType.getCompilationUnit(), model,
textFileChange, true);
- executeChange(monitor, textFileChange, classUndoChanges);
+ executeChange(monitor, textFileChange);
}
- private void executeChange(IProgressMonitor monitor, Change change, Stack<Change> undoChanges)
- throws InvocationTargetException, InterruptedException {
-
+ private void executeChange(IProgressMonitor monitor, Change change) {
if (change == null) {
return;
}
-
- change.initializeValidationData(monitor);
- PerformChangeOperation changeOperation = new PerformChangeOperation(change);
-
- WorkbenchRunnableAdapter adapter = new WorkbenchRunnableAdapter(changeOperation);
- PlatformUI.getWorkbench().getProgressService().runInUI(new BusyIndicatorRunnableContext(), adapter,
- adapter.getSchedulingRule());
-
- if (undoChanges != null && changeOperation.changeExecuted()) {
- undoChanges.push(changeOperation.getUndoChange());
- }
+ IUndoManager manager= RefactoringCore.getUndoManager();
+ boolean successful = false;
+ Change undoChange = null;
+ try {
+ change.initializeValidationData(monitor);
+ RefactoringStatus valid = change.isValid(monitor);
+ if (valid.isOK()) {
+ manager.aboutToPerformChange(change);
+ undoChange = change.perform(monitor);
+ successful = true;
+ numberOfChanges++;
+ }
+ } catch (CoreException ce) {
+ ce.printStackTrace();
+ } finally {
+ manager.changePerformed(change, successful);
+ }
+ if (undoChange != null) {
+ undoChange.initializeValidationData(monitor);
+ manager.addUndo(undoChange.getName(), undoChange);
+ }
}
-
+
@Override
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
IStatus status = Status.OK_STATUS;
- try {
- if (javaInterfaceType != null) {
- while (!interfaceUndoChanges.isEmpty()) {
- Change undoChange = interfaceUndoChanges.pop();
- if (undoChange != null) {
- executeChange(monitor, undoChange, null);
- }
+
+ IUndoManager manager= RefactoringCore.getUndoManager();
+
+ if (manager.anythingToUndo()) {
+ try {
+ for (int i = 0; i < numberOfChanges; i++) {
+ manager.performUndo(null, monitor);
}
+ } catch (CoreException ce) {
+ status = ce.getStatus();
+ CXFCreationCorePlugin.log(status);
}
- if (javaClassType != null) {
- while (!classUndoChanges.isEmpty()) {
- Change undoChange = classUndoChanges.pop();
- if (undoChange != null) {
- executeChange(monitor, undoChange, null);
- }
- }
- }
- } catch (InvocationTargetException ite) {
- status = new Status(IStatus.ERROR, CXFCreationCorePlugin.PLUGIN_ID, ite.getLocalizedMessage());
- CXFCreationCorePlugin.log(status);
- } catch (InterruptedException ie) {
- status = new Status(IStatus.ERROR, CXFCreationCorePlugin.PLUGIN_ID, ie.getLocalizedMessage());
- CXFCreationCorePlugin.log(status);
}
return status;
}
diff --git a/bundles/org.eclipse.jst.ws.cxf.creation.ui/src/org/eclipse/jst/ws/internal/cxf/creation/ui/widgets/JAXWSAnnotateJavaWidget.java b/bundles/org.eclipse.jst.ws.cxf.creation.ui/src/org/eclipse/jst/ws/internal/cxf/creation/ui/widgets/JAXWSAnnotateJavaWidget.java
index b7550ba..8fe1863 100644
--- a/bundles/org.eclipse.jst.ws.cxf.creation.ui/src/org/eclipse/jst/ws/internal/cxf/creation/ui/widgets/JAXWSAnnotateJavaWidget.java
+++ b/bundles/org.eclipse.jst.ws.cxf.creation.ui/src/org/eclipse/jst/ws/internal/cxf/creation/ui/widgets/JAXWSAnnotateJavaWidget.java
@@ -27,8 +27,6 @@
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.ltk.core.refactoring.TextFileChange;
-import org.eclipse.jdt.internal.core.SourceMethod;
-import org.eclipse.jdt.internal.core.SourceType;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
import org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration;
@@ -159,7 +157,7 @@
ICompilationUnit compilationUnit = (ICompilationUnit) element;
IType[] types = compilationUnit.getTypes();
for (IType type : types) {
- if (type instanceof SourceType) {
+ if (type instanceof IType) {
return new Object[] {type};
}
}
@@ -168,9 +166,9 @@
}
}
- if (element instanceof SourceType) {
+ if (element instanceof IType) {
try {
- SourceType sourceType = (SourceType) element;
+ IType sourceType = (IType) element;
List<IMethod> publicMethods = new ArrayList<IMethod>();
IMethod[] methods = sourceType.getMethods();
if (sourceType.isInterface()) {
@@ -207,8 +205,8 @@
FindReplaceDocumentAdapter findReplaceDocumentAdapter =
new FindReplaceDocumentAdapter(document);
try {
- if (firstElement instanceof SourceType) {
- SourceType sourceType = (SourceType) firstElement;
+ if (firstElement instanceof IType) {
+ IType sourceType = (IType) firstElement;
String elementName = sourceType.getElementName();
StringBuilder regex = new StringBuilder("\\bpublic\\W+(?:\\w+\\W+){1,3}?");
@@ -219,9 +217,9 @@
annotationPreviewViewer.setSelectedRange(region.getOffset(), region.getLength());
annotationPreviewViewer.revealRange(region.getOffset(), region.getLength());
- } else if (firstElement instanceof SourceMethod) {
- SourceMethod sourceMethod = (SourceMethod) firstElement;
- SourceType sourceType = (SourceType) sourceMethod.getParent();
+ } else if (firstElement instanceof IMethod) {
+ IMethod sourceMethod = (IMethod) firstElement;
+ IType sourceType = (IType) sourceMethod.getParent();
String elementName = sourceMethod.getElementName();
@@ -509,8 +507,8 @@
@Override
protected void setValue(Object element, Object value) {
- if (element instanceof SourceMethod) {
- SourceMethod method = (SourceMethod) element;
+ if (element instanceof IMethod) {
+ IMethod method = (IMethod) element;
Boolean annotate = (Boolean) value;
Map<String, Boolean> annotationMap = model.getMethodMap().get(element);
annotationMap.put(annotationKey, annotate);
diff --git a/bundles/org.eclipse.jst.ws.jaxws.ui/src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsValuesEditingSupport.java b/bundles/org.eclipse.jst.ws.jaxws.ui/src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsValuesEditingSupport.java
index daa19ec..2110aeb 100644
--- a/bundles/org.eclipse.jst.ws.jaxws.ui/src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsValuesEditingSupport.java
+++ b/bundles/org.eclipse.jst.ws.jaxws.ui/src/org/eclipse/jst/ws/internal/jaxws/ui/views/AnnotationsValuesEditingSupport.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.jst.ws.internal.jaxws.ui.views;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
@@ -44,8 +43,6 @@
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
-import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
-import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
@@ -61,9 +58,10 @@
import org.eclipse.jst.ws.internal.jaxws.ui.JAXWSUIPlugin;
import org.eclipse.jst.ws.jaxws.core.utils.JDTUtils;
import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
+import org.eclipse.ltk.core.refactoring.IUndoManager;
+import org.eclipse.ltk.core.refactoring.RefactoringCore;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.TextFileChange;
-import org.eclipse.ltk.ui.refactoring.RefactoringUI;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.ITextEditor;
@@ -723,26 +721,31 @@
return null;
}
- @SuppressWarnings("restriction")
private void executeChange(IProgressMonitor monitor, Change change) {
if (change == null) {
return;
}
- change.initializeValidationData(monitor);
-
- PerformChangeOperation changeOperation = RefactoringUI.createUIAwareChangeOperation(change);
-
- WorkbenchRunnableAdapter adapter = new WorkbenchRunnableAdapter(changeOperation);
+ IUndoManager manager= RefactoringCore.getUndoManager();
+ boolean successful = false;
+ Change undoChange = null;
try {
- PlatformUI.getWorkbench().getProgressService().runInUI(new BusyIndicatorRunnableContext(), adapter,
- adapter.getSchedulingRule());
- } catch (InvocationTargetException ite) {
- JAXWSUIPlugin.log(ite);
- } catch (InterruptedException ie) {
- JAXWSUIPlugin.log(ie);
+ change.initializeValidationData(monitor);
+ RefactoringStatus valid = change.isValid(monitor);
+ if (valid.isOK()) {
+ manager.aboutToPerformChange(change);
+ undoChange = change.perform(monitor);
+ successful = true;
+ }
+ } catch (CoreException ce) {
+ ce.printStackTrace();
+ } finally {
+ manager.changePerformed(change, successful);
}
-
+ if (undoChange != null) {
+ undoChange.initializeValidationData(monitor);
+ manager.addUndo(undoChange.getName(), undoChange);
+ }
annotationsView.refresh();
}
}