Author: dazarov
Date: 2012-01-24 16:34:09 -0500 (Tue, 24 Jan 2012)
New Revision: 38120
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeBeanScopedDependentMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldProtectedMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldStaticMarkerResolution.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/MakeBeanScopedDependentMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeBeanScopedDependentMarkerResolution.java 2012-01-24
21:29:57 UTC (rev 38119)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeBeanScopedDependentMarkerResolution.java 2012-01-24
21:34:09 UTC (rev 38120)
@@ -13,8 +13,6 @@
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
@@ -23,12 +21,11 @@
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IImportContainer;
-import org.eclipse.jdt.core.IImportDeclaration;
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.DeleteEdit;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
@@ -41,6 +38,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
@@ -49,11 +48,13 @@
private String label;
private IBean bean;
private IFile file;
+ private String description;
public MakeBeanScopedDependentMarkerResolution(IBean bean, IFile file){
this.label =
MessageFormat.format(CDIUIMessages.MAKE_BEAN_SCOPED_DEPENDENT_MARKER_RESOLUTION_TITLE, new
Object[]{bean.getElementName()});
this.bean = bean;
this.file = file;
+ description = getPreview();
}
@Override
@@ -73,32 +74,9 @@
}
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
- CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+ CompilationUnitChange change = getChange(originalAnnotation, compilationUnit);
- MultiTextEdit edit = new MultiTextEdit();
-
- change.setEdit(edit);
-
- CDIMarkerResolutionUtils.addImport(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME,
compilationUnit, edit);
-
- IAnnotation workingCopyAnnotation = getWorkingCopyAnnotation(originalAnnotation,
compilationUnit);
-
- if(workingCopyAnnotation != null){
- String shortName =
CDIMarkerResolutionUtils.getShortName(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
-
- TextEdit re = new ReplaceEdit(workingCopyAnnotation.getSourceRange().getOffset(),
workingCopyAnnotation.getSourceRange().getLength(),
CDIMarkerResolutionUtils.AT+shortName);
- edit.addChild(re);
-
- IBuffer buffer = compilationUnit.getBuffer();
-
- // delete import
- String qualifiedName = getFullyQualifiedName();
- if(qualifiedName != null){
- CDIMarkerResolutionUtils.deleteImportForAnnotation(qualifiedName,
workingCopyAnnotation, compilationUnit, buffer, edit);
- }
- }
-
- if(edit.hasChildren()){
+ if(change.getEdit().hasChildren()){
change.perform(new NullProgressMonitor());
original.reconcile(ICompilationUnit.NO_AST, false, null, new NullProgressMonitor());
}
@@ -109,7 +87,70 @@
}
+ private CompilationUnitChange getChange(IAnnotation originalAnnotation, ICompilationUnit
compilationUnit) throws JavaModelException{
+ CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+
+ MultiTextEdit edit = new MultiTextEdit();
+
+ change.setEdit(edit);
+
+ CDIMarkerResolutionUtils.addImport(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME,
compilationUnit, edit);
+
+ IAnnotation workingCopyAnnotation = getWorkingCopyAnnotation(originalAnnotation,
compilationUnit);
+
+ if(workingCopyAnnotation != null){
+ String shortName =
CDIMarkerResolutionUtils.getShortName(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
+
+ TextEdit re = new ReplaceEdit(workingCopyAnnotation.getSourceRange().getOffset(),
workingCopyAnnotation.getSourceRange().getLength(),
CDIMarkerResolutionUtils.AT+shortName);
+ edit.addChild(re);
+
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ // delete import
+ String qualifiedName = getFullyQualifiedName();
+ if(qualifiedName != null){
+ CDIMarkerResolutionUtils.deleteImportForAnnotation(qualifiedName,
workingCopyAnnotation, compilationUnit, buffer, edit);
+ }
+ }
+
+ return change;
+ }
+ private CompilationUnitChange getPreviewChange(){
+ IAnnotation originalAnnotation = getScopeAnnotation();
+ if(originalAnnotation == null)
+ return null;
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ if(original == null) {
+ return null;
+ }
+
+ return getChange(originalAnnotation, original);
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ return null;
+ }
+
+ private String getPreview(){
+ TextChange previewChange = getPreviewChange();
+ if(previewChange != null){
+ try {
+ return MarkerResolutionUtils.getPreview(previewChange);
+ } catch (CoreException e) {
+ CommonUIPlugin.getDefault().logError(e);
+ }
+ }
+ return label;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+
private IAnnotation getWorkingCopyAnnotation(IAnnotation annotation, ICompilationUnit
compilationUnit){
IType type = compilationUnit.getType(bean.getBeanClass().getElementName());
if(type != null){
@@ -142,11 +183,6 @@
}
@Override
- public String getDescription() {
- return label;
- }
-
- @Override
public Image getImage() {
return CDIImages.QUICKFIX_EDIT;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldProtectedMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldProtectedMarkerResolution.java 2012-01-24
21:29:57 UTC (rev 38119)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldProtectedMarkerResolution.java 2012-01-24
21:34:09 UTC (rev 38120)
@@ -20,8 +20,10 @@
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ltk.core.refactoring.TextChange;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.text.edits.MultiTextEdit;
@@ -33,6 +35,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
@@ -44,11 +48,13 @@
private String label;
private IField field;
private IFile file;
+ private String description;
public MakeFieldProtectedMarkerResolution(IField field, IFile file){
this.label =
MessageFormat.format(CDIUIMessages.MAKE_FIELD_PROTECTED_MARKER_RESOLUTION_TITLE, new
Object[]{field.getElementName()});
this.field = field;
this.file = file;
+ description = getPreview();
}
@Override
@@ -80,26 +86,9 @@
}
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
- CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+ CompilationUnitChange change = getChange(compilationUnit);
- MultiTextEdit edit = new MultiTextEdit();
-
- change.setEdit(edit);
- IBuffer buffer = compilationUnit.getBuffer();
-
- int flag = field.getFlags();
-
- String text = buffer.getText(field.getSourceRange().getOffset(),
field.getSourceRange().getLength());
-
- int position = field.getSourceRange().getOffset();
- if((flag & Flags.AccPublic) != 0){
- position += text.indexOf(PUBLIC);
- TextEdit re = new ReplaceEdit(position, PUBLIC.length(), PROTECTED);
- edit.addChild(re);
- //buffer.replace(position, PUBLIC.length(), PROTECTED);
- }
-
- if(edit.hasChildren()){
+ if(change.getEdit().hasChildren()){
change.perform(new NullProgressMonitor());
original.reconcile(ICompilationUnit.NO_AST, false, null, new NullProgressMonitor());
}
@@ -109,9 +98,53 @@
}
}
+ private CompilationUnitChange getChange(ICompilationUnit compilationUnit) throws
JavaModelException{
+ CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+
+ MultiTextEdit edit = new MultiTextEdit();
+
+ change.setEdit(edit);
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ int flag = field.getFlags();
+
+ String text = buffer.getText(field.getSourceRange().getOffset(),
field.getSourceRange().getLength());
+
+ int position = field.getSourceRange().getOffset();
+ if((flag & Flags.AccPublic) != 0){
+ position += text.indexOf(PUBLIC);
+ TextEdit re = new ReplaceEdit(position, PUBLIC.length(), PROTECTED);
+ edit.addChild(re);
+ }
+
+ 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/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldStaticMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldStaticMarkerResolution.java 2012-01-24
21:29:57 UTC (rev 38119)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldStaticMarkerResolution.java 2012-01-24
21:34:09 UTC (rev 38120)
@@ -20,8 +20,10 @@
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
+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;
@@ -30,6 +32,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
@@ -44,11 +48,13 @@
private String label;
private IField field;
private IFile file;
+ private String description;
public MakeFieldStaticMarkerResolution(IField field, IFile file){
this.label =
MessageFormat.format(CDIUIMessages.MAKE_FIELD_STATIC_MARKER_RESOLUTION_TITLE, new
Object[]{field.getElementName()});
this.field = field;
this.file = file;
+ description = getPreview();
}
@Override
@@ -65,42 +71,9 @@
}
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
- CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+ CompilationUnitChange change = getChange(compilationUnit);
- MultiTextEdit edit = new MultiTextEdit();
-
- change.setEdit(edit);
- IBuffer buffer = compilationUnit.getBuffer();
-
- int flag = field.getFlags();
-
- String text = buffer.getText(field.getSourceRange().getOffset(),
field.getSourceRange().getLength());
-
- int position = field.getSourceRange().getOffset();
- if((flag & Flags.AccPublic) != 0){
- position += text.indexOf(PUBLIC)+PUBLIC.length();
- InsertEdit ie = new InsertEdit(position, SPACE+STATIC);
- edit.addChild(ie);
- //buffer.replace(position, 0, SPACE+STATIC);
- }else if((flag & Flags.AccPrivate) != 0){
- position += text.indexOf(PRIVATE)+PRIVATE.length();
- InsertEdit ie = new InsertEdit(position, SPACE+STATIC);
- edit.addChild(ie);
- //buffer.replace(position, 0, SPACE+STATIC);
- }else if((flag & Flags.AccProtected) != 0){
- position += text.indexOf(PROTECTED)+PROTECTED.length();
- InsertEdit ie = new InsertEdit(position, SPACE+STATIC);
- edit.addChild(ie);
- //buffer.replace(position, 0, SPACE+STATIC);
- }else{
- String type = Signature.getSignatureSimpleName(field.getTypeSignature());
- position += text.indexOf(type);
- InsertEdit ie = new InsertEdit(position, SPACE+STATIC);
- edit.addChild(ie);
- //buffer.replace(position, 0, STATIC+SPACE);
- }
-
- if(edit.hasChildren()){
+ if(change.getEdit().hasChildren()){
change.perform(new NullProgressMonitor());
original.reconcile(ICompilationUnit.NO_AST, false, null, new NullProgressMonitor());
}
@@ -110,9 +83,66 @@
}
}
+ private CompilationUnitChange getChange(ICompilationUnit compilationUnit) throws
JavaModelException{
+ CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+
+ MultiTextEdit edit = new MultiTextEdit();
+
+ change.setEdit(edit);
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ int flag = field.getFlags();
+
+ String text = buffer.getText(field.getSourceRange().getOffset(),
field.getSourceRange().getLength());
+
+ int position = field.getSourceRange().getOffset();
+ if((flag & Flags.AccPublic) != 0){
+ position += text.indexOf(PUBLIC)+PUBLIC.length();
+ InsertEdit ie = new InsertEdit(position, SPACE+STATIC);
+ edit.addChild(ie);
+ }else if((flag & Flags.AccPrivate) != 0){
+ position += text.indexOf(PRIVATE)+PRIVATE.length();
+ InsertEdit ie = new InsertEdit(position, SPACE+STATIC);
+ edit.addChild(ie);
+ }else if((flag & Flags.AccProtected) != 0){
+ position += text.indexOf(PROTECTED)+PROTECTED.length();
+ InsertEdit ie = new InsertEdit(position, SPACE+STATIC);
+ edit.addChild(ie);
+ }else{
+ String type = Signature.getSignatureSimpleName(field.getTypeSignature());
+ position += text.indexOf(type);
+ InsertEdit ie = new InsertEdit(position, SPACE+STATIC);
+ edit.addChild(ie);
+ }
+
+ 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