Author: dazarov
Date: 2012-01-24 12:56:14 -0500 (Tue, 24 Jan 2012)
New Revision: 38111
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddSerializableInterfaceMarkerResolution.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/AddSerializableInterfaceMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddSerializableInterfaceMarkerResolution.java 2012-01-24
17:37:13 UTC (rev 38110)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddSerializableInterfaceMarkerResolution.java 2012-01-24
17:56:14 UTC (rev 38111)
@@ -18,7 +18,9 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
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.swt.graphics.Image;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.ui.IMarkerResolution2;
@@ -27,6 +29,8 @@
import org.jboss.tools.cdi.ui.CDIUIMessages;
import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.common.EclipseUtil;
+import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
+import org.jboss.tools.common.ui.CommonUIPlugin;
/**
* @author Daniel Azarov
@@ -35,6 +39,7 @@
public static final String SERIALIZABLE = "java.io.Serializable";
//$NON-NLS-1$
private String label;
+ private String description;
private IType type;
private IFile file;
@@ -43,6 +48,7 @@
this.label =
MessageFormat.format(CDIUIMessages.ADD_SERIALIZABLE_INTERFACE_MARKER_RESOLUTION_TITLE, new
Object[]{type.getElementName()});
this.type = type;
this.file = file;
+ description = getPreview();
}
@Override
@@ -77,9 +83,43 @@
}
}
+ private CompilationUnitChange getChange(ICompilationUnit compilationUnit) throws
JavaModelException{
+ CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+
+ MultiTextEdit edit = new MultiTextEdit();
+
+ change.setEdit(edit);
+
+ CDIMarkerResolutionUtils.addInterfaceToClass(compilationUnit, type, SERIALIZABLE,
edit);
+
+ return change;
+ }
+
+ private CompilationUnitChange getPreviewChange(){
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+
+ return getChange(original);
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ return null;
+ }
+
+ private 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-24
17:37:13 UTC (rev 38110)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java 2012-01-24
17:56:14 UTC (rev 38111)
@@ -681,6 +681,7 @@
// process regions
Region prevRegion = null;
for(Region region : regions){
+
int position = region.offset;
int count = NUMBER_OF_STRINGS;
int lowLimit = 0;
@@ -725,7 +726,7 @@
}
position++;
}
- region.length += position - (region.offset + region.length);
+ region.length = position - region.offset;
prevRegion = region;
}
@@ -737,6 +738,15 @@
if(!region.active){
continue;
}
+ if(region.offset > preview.length()-1){
+ region.offset = preview.length()-1;
+ }
+ if(region.offset < 0){
+ region.offset = 0;
+ }
+ if(region.offset + region.length > preview.length()-1){
+ region.length = (preview.length()-1)-region.offset;
+ }
if(index == 0 && region.offset != 0){
buffer.append(DOTS+NEW_LINE);
}