Author: dazarov
Date: 2012-01-25 17:35:08 -0500 (Wed, 25 Jan 2012)
New Revision: 38191
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerDuplicantMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllOtherAnnotationsFromParametersMarkerResolution.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java
Log:
Add the code which is supposed to be inserted by the Quick Fix into its description
https://issues.jboss.org/browse/JBIDE-10636
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerDuplicantMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerDuplicantMarkerResolution.java 2012-01-25
21:44:57 UTC (rev 38190)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerDuplicantMarkerResolution.java 2012-01-25
22:35:08 UTC (rev 38191)
@@ -14,7 +14,12 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
import org.eclipse.swt.graphics.Image;
@@ -22,7 +27,9 @@
import org.jboss.tools.cdi.core.CDIImages;
import
org.jboss.tools.cdi.internal.core.refactoring.DeleteAllDisposerAnnotationsProcessor;
import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.cdi.ui.wizard.DeletePreviewWizard;
+import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
/**
* @author Daniel Azarov
@@ -31,11 +38,13 @@
private String label;
private IMethod method;
private IFile file;
+ private String description;
public DeleteAllDisposerDuplicantMarkerResolution(IMethod method, IFile file){
this.label =
MessageFormat.format(CDIUIMessages.DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE,
new Object[]{method.getElementName()});
this.method = method;
this.file = file;
+ description = getPreview();
}
@Override
@@ -58,9 +67,37 @@
return new DeleteAllDisposerAnnotationsProcessor(file, method, label);
}
+ private String getPreview(){
+ RefactoringProcessor processor = getRefactoringProcessor();
+ RefactoringStatus status;
+ try {
+ status = processor.checkInitialConditions(new NullProgressMonitor());
+
+
+ if(status.getEntryMatchingSeverity(RefactoringStatus.FATAL) != null){
+ return label;
+ }
+
+ status = processor.checkFinalConditions(new NullProgressMonitor(), null);
+
+ if(status.getEntryMatchingSeverity(RefactoringStatus.FATAL) != null){
+ return label;
+ }
+
+ CompositeChange rootChange = (CompositeChange)processor.createChange(new
NullProgressMonitor());
+
+ return MarkerResolutionUtils.getPreview(rootChange);
+ } catch (OperationCanceledException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ } catch (CoreException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ }
+ return label;
+ }
+
@Override
public String getDescription() {
- return label;
+ return description;
}
@Override
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java 2012-01-25
21:44:57 UTC (rev 38190)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java 2012-01-25
22:35:08 UTC (rev 38191)
@@ -14,8 +14,13 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.Signature;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
import org.eclipse.swt.graphics.Image;
@@ -23,7 +28,9 @@
import org.jboss.tools.cdi.core.CDIImages;
import
org.jboss.tools.cdi.internal.core.refactoring.DeleteAllInjectedConstructorsProcessor;
import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.cdi.ui.wizard.DeletePreviewWizard;
+import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
/**
* @author Daniel Azarov
@@ -32,6 +39,7 @@
private String label;
private IMethod method;
private IFile file;
+ private String description;
public DeleteAllInjectedConstructorsMarkerResolution(IMethod method, IFile file){
StringBuffer buffer = new StringBuffer();
@@ -46,6 +54,7 @@
this.label =
MessageFormat.format(CDIUIMessages.DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE,
new Object[]{buffer.toString()});
this.method = method;
this.file = file;
+ description = getPreview();
}
@Override
@@ -53,7 +62,34 @@
return label;
}
+ private String getPreview(){
+ RefactoringProcessor processor = getRefactoringProcessor();
+ RefactoringStatus status;
+ try {
+ status = processor.checkInitialConditions(new NullProgressMonitor());
+
+
+ if(status.getEntryMatchingSeverity(RefactoringStatus.FATAL) != null){
+ return label;
+ }
+ status = processor.checkFinalConditions(new NullProgressMonitor(), null);
+
+ if(status.getEntryMatchingSeverity(RefactoringStatus.FATAL) != null){
+ return label;
+ }
+
+ CompositeChange rootChange = (CompositeChange)processor.createChange(new
NullProgressMonitor());
+
+ return MarkerResolutionUtils.getPreview(rootChange);
+ } catch (OperationCanceledException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ } catch (CoreException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ }
+ return label;
+ }
+
@Override
public void run(IMarker marker) {
DeleteAllInjectedConstructorsProcessor processor = new
DeleteAllInjectedConstructorsProcessor(file, method, label);
@@ -69,7 +105,7 @@
@Override
public String getDescription() {
- return label;
+ return description;
}
@Override
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllOtherAnnotationsFromParametersMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllOtherAnnotationsFromParametersMarkerResolution.java 2012-01-25
21:44:57 UTC (rev 38190)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllOtherAnnotationsFromParametersMarkerResolution.java 2012-01-25
22:35:08 UTC (rev 38191)
@@ -14,7 +14,12 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
import org.eclipse.swt.graphics.Image;
@@ -23,7 +28,9 @@
import org.jboss.tools.cdi.internal.core.refactoring.CDIMarkerResolutionUtils;
import
org.jboss.tools.cdi.internal.core.refactoring.DeleteOtherAnnotationsFromParametersProcessor;
import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.cdi.ui.wizard.DeletePreviewWizard;
+import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
/**
* @author Daniel Azarov
@@ -33,6 +40,7 @@
private String annotationName;
private ILocalVariable parameter;
private IFile file;
+ private String description;
public DeleteAllOtherAnnotationsFromParametersMarkerResolution(String annotationName,
ILocalVariable parameter, IFile file){
String shortName = CDIMarkerResolutionUtils.AT +
CDIMarkerResolutionUtils.getShortName(annotationName);
@@ -40,6 +48,7 @@
this.annotationName = annotationName;
this.parameter = parameter;
this.file = file;
+ description = getPreview();
}
@Override
@@ -47,7 +56,34 @@
return label;
}
+ private String getPreview(){
+ RefactoringProcessor processor = getRefactoringProcessor();
+ RefactoringStatus status;
+ try {
+ status = processor.checkInitialConditions(new NullProgressMonitor());
+
+
+ if(status.getEntryMatchingSeverity(RefactoringStatus.FATAL) != null){
+ return label;
+ }
+ status = processor.checkFinalConditions(new NullProgressMonitor(), null);
+
+ if(status.getEntryMatchingSeverity(RefactoringStatus.FATAL) != null){
+ return label;
+ }
+
+ CompositeChange rootChange = (CompositeChange)processor.createChange(new
NullProgressMonitor());
+
+ return MarkerResolutionUtils.getPreview(rootChange);
+ } catch (OperationCanceledException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ } catch (CoreException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ }
+ return label;
+ }
+
@Override
public void run(IMarker marker) {
DeleteOtherAnnotationsFromParametersProcessor processor = new
DeleteOtherAnnotationsFromParametersProcessor(file, annotationName, parameter, label);
@@ -63,7 +99,7 @@
@Override
public String getDescription() {
- return label;
+ return description;
}
@Override
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java 2012-01-25
21:44:57 UTC (rev 38190)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java 2012-01-25
22:35:08 UTC (rev 38191)
@@ -37,7 +37,10 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.TextChange;
+import org.eclipse.ltk.core.refactoring.TextEditBasedChange;
import org.eclipse.text.edits.DeleteEdit;
import org.eclipse.text.edits.InsertEdit;
import org.eclipse.text.edits.MultiTextEdit;
@@ -609,29 +612,69 @@
return null;
}
- public static String getPreview(TextChange previewChange) throws CoreException{
+ public static String getPreview(Change previewChange) throws CoreException{
if(previewChange == null)
return null;
- String preview = previewChange.getPreviewContent(new NullProgressMonitor());
- String current = previewChange.getCurrentContent(new NullProgressMonitor());
+ // CompositeChange
+ // TextEditBasedChange
+ // TextChange
- TextEdit edit = previewChange.getEdit();
- EditSet editSet = new EditSet(edit);
+ String preview = getPreviewContent(previewChange);
+ //String current = previewChange.getCurrentContent(new NullProgressMonitor());
- // select
- preview = editSet.select(preview, current);
+ TextEdit edit = getEdit(previewChange);
- // cut
- preview = editSet.cut(preview);
-
- // format
- preview = preview.replaceAll(NEW_LINE, LINE_BREAK);
-
- return preview;
+ if(preview != null && edit != null){
+ EditSet editSet = new EditSet(edit);
+
+ // select
+ preview = editSet.select(preview);
+
+ // cut
+ preview = editSet.cut(preview);
+
+ // format
+ preview = preview.replaceAll(NEW_LINE, LINE_BREAK);
+
+ return preview;
+ }
+ return "";
}
+ private static String getPreviewContent(Change change) throws CoreException{
+ if(change instanceof TextEditBasedChange){
+ return ((TextEditBasedChange) change).getPreviewContent(new NullProgressMonitor());
+ }else if(change instanceof TextChange){
+ return ((TextChange) change).getPreviewContent(new NullProgressMonitor());
+ }else if(change instanceof CompositeChange){
+ for(Change child : ((CompositeChange) change).getChildren()){
+ String prev = getPreviewContent(child);
+ if(prev != null){
+ return prev;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static TextEdit getEdit(Change change) throws CoreException{
+ if(change instanceof BaseFileChange){
+ return ((BaseFileChange) change).getEdit();
+ }else if(change instanceof TextChange){
+ return ((TextChange) change).getEdit();
+ }else if(change instanceof CompositeChange){
+ for(Change child : ((CompositeChange) change).getChildren()){
+ TextEdit prev = getEdit(child);
+ if(prev != null){
+ return prev;
+ }
+ }
+ }
+ return null;
+ }
+
static class EditSet{
private ArrayList<TextEdit> edits = new ArrayList<TextEdit>();
private ArrayList<Region> regions = new ArrayList<Region>();
@@ -672,7 +715,7 @@
edits = sorted;
}
- public String select(String preview, String current){
+ public String select(String preview){
int delta = 0;
for(TextEdit edit : edits){
String text = null;