Author: dazarov
Date: 2012-01-23 13:30:47 -0500 (Mon, 23 Jan 2012)
New Revision: 38036
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAnnotationMarkerResolution.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/DeleteAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAnnotationMarkerResolution.java 2012-01-23
18:25:26 UTC (rev 38035)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAnnotationMarkerResolution.java 2012-01-23
18:30:47 UTC (rev 38036)
@@ -21,6 +21,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
+import org.eclipse.ltk.core.refactoring.TextChange;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.text.edits.MultiTextEdit;
@@ -29,12 +30,15 @@
import org.jboss.tools.cdi.internal.core.refactoring.CDIMarkerResolutionUtils;
import org.jboss.tools.cdi.ui.CDIUIMessages;
import org.jboss.tools.cdi.ui.CDIUIPlugin;
+import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
+import org.jboss.tools.common.ui.CommonUIPlugin;
public class DeleteAnnotationMarkerResolution implements
IMarkerResolution2 {
private IJavaElement element;
private String qualifiedName;
private String label;
+ private String description;
public DeleteAnnotationMarkerResolution(IJavaElement element, String qualifiedName){
this.element = element;
@@ -63,6 +67,7 @@
}
label = NLS.bind(CDIUIMessages.DELETE_ANNOTATION_MARKER_RESOLUTION_TITLE, new
String[]{shortName, element.getElementName(), type});
+ description = getPreview();
}
@Override
@@ -76,15 +81,9 @@
ICompilationUnit original =
CDIMarkerResolutionUtils.getJavaMember(element).getCompilationUnit();
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
- CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+ CompilationUnitChange change = getChange(compilationUnit);
- MultiTextEdit edit = new MultiTextEdit();
-
- change.setEdit(edit);
-
- CDIMarkerResolutionUtils.deleteAnnotation(qualifiedName, compilationUnit, element,
edit);
-
- if(edit.hasChildren()){
+ if(change.getEdit().hasChildren()){
change.perform(new NullProgressMonitor());
original.reconcile(ICompilationUnit.NO_AST, false, null, new NullProgressMonitor());
}
@@ -94,9 +93,43 @@
}
}
+ private CompilationUnitChange getChange(ICompilationUnit compilationUnit) throws
JavaModelException{
+ CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+
+ MultiTextEdit edit = new MultiTextEdit();
+
+ change.setEdit(edit);
+
+ CDIMarkerResolutionUtils.deleteAnnotation(qualifiedName, compilationUnit, element,
edit);
+
+ return change;
+ }
+
+ private CompilationUnitChange getPreviewChange(){
+ try{
+ ICompilationUnit original =
CDIMarkerResolutionUtils.getJavaMember(element).getCompilationUnit();
+
+ return getChange(original);
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ return null;
+ }
+
+ protected String getPreview(){
+ TextChange previewChange = getPreviewChange();
+
+ try {
+ return MarkerResolutionUtils.getPreview(previewChange);
+ } catch (CoreException e) {
+ CommonUIPlugin.getDefault().logError(e);
+ }
+ return label;
+ }
+
@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-23
18:25:26 UTC (rev 38035)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java 2012-01-23
18:30:47 UTC (rev 38036)
@@ -60,6 +60,8 @@
public static final String CLOSE_BRACE = "}"; //$NON-NLS-1$
public static final String OPEN_BOLD = "<b>"; //$NON-NLS-1$
public static final String CLOSE_BOLD = "</b>"; //$NON-NLS-1$
+ public static final String OPEN_DEL = "<del>"; //$NON-NLS-1$
+ public static final String CLOSE_DEL = "</del>"; //$NON-NLS-1$
public static final String NEW_LINE = "\n"; //$NON-NLS-1$
public static final String LINE_BREAK = "<br>"; //$NON-NLS-1$
@@ -584,13 +586,14 @@
return null;
String preview = previewChange.getPreviewContent(new NullProgressMonitor());
+ String current = previewChange.getCurrentContent(new NullProgressMonitor());
TextEdit edit = previewChange.getEdit();
EditSet editSet = new EditSet(edit);
// select
- preview = editSet.select(preview);
+ preview = editSet.select(preview, current);
// cut
preview = editSet.cut(preview);
@@ -605,7 +608,7 @@
private ArrayList<TextEdit> edits = new ArrayList<TextEdit>();
private ArrayList<Region> regions = new ArrayList<Region>();
- private int lastOffset = 0;
+ //private int lastOffset = 0;
public EditSet(TextEdit edit){
addEdits(edit);
@@ -620,21 +623,30 @@
}
private void sort(){
- }
-
- private int getFirstOffset(){
- if(edits.size() > 0){
- return edits.get(0).getOffset();
- }else{
- return 0;
+ if(edits.size() < 2){
+ return;
}
+ ArrayList<TextEdit> sorted = new ArrayList<TextEdit>();
+ int offset = 0;
+ int distance = 0;
+ int number = edits.size();
+ for(int i = 0; i < number; i++){
+ TextEdit edit = edits.get(0);
+ distance = edit.getOffset()-offset;
+ for(TextEdit e : edits){
+ if((e.getOffset()-offset) < distance){
+ distance = e.getOffset()-offset;
+ edit = e;
+ }
+ }
+ sorted.add(edit);
+ edits.remove(edit);
+ offset = edit.getOffset();
+ }
+ edits = sorted;
}
- private int getLastOffset(){
- return lastOffset;
- }
-
- public String select(String preview){
+ public String select(String preview, String current){
int delta = 0;
for(TextEdit edit : edits){
String text = null;
@@ -645,12 +657,28 @@
}else if(edit instanceof ReplaceEdit){
text = ((ReplaceEdit) edit).getText();
addings = text.length()-edit.getLength();
+ }else if(edit instanceof DeleteEdit){
+// text = NEW_LINE+current.substring(edit.getOffset(),
edit.getOffset()+edit.getLength());
+ //addings = -text.length();
+
+ int offset = edit.getOffset()+delta;
+ int length = edit.getLength();
+ regions.add(new Region(offset, length));
+ //lastOffset = offset+length;
+//
+// // select
+// String before = preview.substring(0, offset);
+// String after = preview.substring(offset);
+// preview = before+OPEN_DEL+text+CLOSE_DEL+after;
+//
+// delta += OPEN_DEL.length()+CLOSE_DEL.length()+addings;
+// text = null;
}
if(text != null){
int offset = edit.getOffset()+delta;
int length = text.length();
regions.add(new Region(offset, length));
- lastOffset = offset+length;
+ //lastOffset = offset+length;
// select
String before = preview.substring(0, offset);
@@ -684,7 +712,7 @@
}
position--;
}
- if(prevRegion != null && position == prevRegion.offset+prevRegion.length){
+ if(prevRegion != null && position <=
prevRegion.offset+prevRegion.length){
prevRegion.active = false;
int shift = region.offset - prevRegion.offset;
region.offset = prevRegion.offset;