Author: dazarov
Date: 2012-01-24 16:38:42 -0500 (Tue, 24 Jan 2012)
New Revision: 38121
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodPublicMarkerResolution.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/MakeMethodPublicMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodPublicMarkerResolution.java 2012-01-24
21:34:09 UTC (rev 38120)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodPublicMarkerResolution.java 2012-01-24
21:38:42 UTC (rev 38121)
@@ -20,8 +20,10 @@
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
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.InsertEdit;
import org.eclipse.text.edits.MultiTextEdit;
@@ -32,6 +34,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
@@ -45,11 +49,13 @@
private String label;
private IMethod method;
private IFile file;
+ private String description;
public MakeMethodPublicMarkerResolution(IMethod method, IFile file){
this.label =
MessageFormat.format(CDIUIMessages.MAKE_METHOD_PUBLIC_MARKER_RESOLUTION_TITLE, new
Object[]{method.getElementName()});
this.method = method;
this.file = file;
+ description = getPreview();
}
@Override
@@ -66,54 +72,80 @@
}
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
- CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+ CompilationUnitChange change = getChange(compilationUnit);
- MultiTextEdit edit = new MultiTextEdit();
+ if(change.getEdit().hasChildren()){
+ change.perform(new NullProgressMonitor());
+ original.reconcile(ICompilationUnit.NO_AST, false, null, new NullProgressMonitor());
+ }
+ compilationUnit.discardWorkingCopy();
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ private CompilationUnitChange getChange(ICompilationUnit compilationUnit) throws
JavaModelException{
+ CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+
+ MultiTextEdit edit = new MultiTextEdit();
+
+ change.setEdit(edit);
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ IMethod workingCopyMethod = CDIMarkerResolutionUtils.findWorkingCopy(compilationUnit,
method);
+ if(workingCopyMethod != null){
+ int flag = workingCopyMethod.getFlags();
- change.setEdit(edit);
- IBuffer buffer = compilationUnit.getBuffer();
-
- IMethod workingCopyMethod = CDIMarkerResolutionUtils.findWorkingCopy(compilationUnit,
method);
- if(workingCopyMethod != null){
- int flag = workingCopyMethod.getFlags();
-
- String text = buffer.getText(workingCopyMethod.getSourceRange().getOffset(),
workingCopyMethod.getSourceRange().getLength());
-
- // make method public
- int position = workingCopyMethod.getSourceRange().getOffset();
- if((flag & Flags.AccPublic) != 0){
- // do nothing
- }else if((flag & Flags.AccPrivate) != 0){
+ String text = buffer.getText(workingCopyMethod.getSourceRange().getOffset(),
workingCopyMethod.getSourceRange().getLength());
+
+ // make method public
+ int position = workingCopyMethod.getSourceRange().getOffset();
+ if((flag & Flags.AccPublic) == 0){
+ if((flag & Flags.AccPrivate) != 0){
position += text.indexOf(PRIVATE);
ReplaceEdit re = new ReplaceEdit(position, PRIVATE.length(), PUBLIC);
edit.addChild(re);
- //buffer.replace(position, PRIVATE.length(), PUBLIC);
}else if((flag & Flags.AccProtected) != 0){
position += text.indexOf(PROTECTED);
ReplaceEdit re = new ReplaceEdit(position, PROTECTED.length(), PUBLIC);
edit.addChild(re);
- //buffer.replace(position, PROTECTED.length(), PUBLIC);
}else{
String type = Signature.getSignatureSimpleName(workingCopyMethod.getReturnType());
position += text.indexOf(type);
InsertEdit ie = new InsertEdit(position, PUBLIC+SPACE);
edit.addChild(ie);
- //buffer.replace(position, 0, PUBLIC+SPACE);
}
}
- if(edit.hasChildren()){
- change.perform(new NullProgressMonitor());
- original.reconcile(ICompilationUnit.NO_AST, false, null, new NullProgressMonitor());
- }
- compilationUnit.discardWorkingCopy();
+ }
+
+ 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