Author: dazarov
Date: 2012-01-24 20:20:38 -0500 (Tue, 24 Jan 2012)
New Revision: 38152
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/BaseMarkerResolution.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddAnnotationMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddLocalBeanMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNameMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddRetentionAnnotationMarkerResolution.java
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/AddTargetAnnotationMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java
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/MakeBeanScopedDependentMarkerResolution.java
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/MakeMethodPublicMarkerResolution.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/AddAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddAnnotationMarkerResolution.java 2012-01-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddAnnotationMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -10,9 +10,6 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.marker;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
@@ -21,24 +18,18 @@
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;
-import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.cdi.core.CDIImages;
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;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
-public class AddAnnotationMarkerResolution implements
- IMarkerResolution2 {
+public class AddAnnotationMarkerResolution extends BaseMarkerResolution {
private IJavaElement element;
private String qualifiedName;
- private String label;
- private String description;
public AddAnnotationMarkerResolution(IJavaElement element, String qualifiedName){
this.element = element;
@@ -67,70 +58,31 @@
}
label = NLS.bind(CDIUIMessages.ADD_ANNOTATION_MARKER_RESOLUTION_TITLE, new
String[]{shortName, element.getElementName(), type});
- description = getPreview();
+ init();
}
@Override
- public String getLabel() {
- return label;
+ protected ICompilationUnit getCompilationUnit(){
+ return CDIMarkerResolutionUtils.getJavaMember(element).getCompilationUnit();
}
-
- @Override
- public void run(IMarker marker) {
- try{
- ICompilationUnit original =
CDIMarkerResolutionUtils.getJavaMember(element).getCompilationUnit();
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(compilationUnit);
-
- 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{
+ @Override
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
MultiTextEdit edit = new MultiTextEdit();
change.setEdit(edit);
- CDIMarkerResolutionUtils.addAnnotation(qualifiedName, compilationUnit, element,
"", edit);
+ try {
+ CDIMarkerResolutionUtils.addAnnotation(qualifiedName, compilationUnit, element,
"", edit);
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ }
return change;
}
- private CompilationUnitChange getPreviewChange(){
- try{
- ICompilationUnit original =
CDIMarkerResolutionUtils.getJavaMember(element).getCompilationUnit();
-
- 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 description;
- }
@Override
public Image getImage() {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddLocalBeanMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddLocalBeanMarkerResolution.java 2012-01-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddLocalBeanMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -13,9 +13,6 @@
import java.text.MessageFormat;
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.jdt.core.Flags;
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
@@ -23,31 +20,27 @@
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;
import org.eclipse.text.edits.ReplaceEdit;
-import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDIImages;
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.BaseMarkerResolution;
import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
-import org.jboss.tools.common.ui.CommonUIPlugin;
/**
* @author Daniel Azarov
*/
-public class AddLocalBeanMarkerResolution implements IMarkerResolution2 {
+public class AddLocalBeanMarkerResolution extends BaseMarkerResolution {
private static final String PUBLIC = "public"; //$NON-NLS-1$
private static final String PRIVATE = "private"; //$NON-NLS-1$
private static final String PROTECTED = "protected"; //$NON-NLS-1$
private static final String SPACE = " "; //$NON-NLS-1$
- private String label;
- private String description;
private IMethod method;
private IFile file;
@@ -55,101 +48,55 @@
this.label = MessageFormat.format(CDIUIMessages.ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE,
new Object[]{method.getDeclaringType().getElementName()});
this.method = method;
this.file = file;
- description = getPreview();
+ init();
}
@Override
- public String getLabel() {
- return label;
+ protected ICompilationUnit getCompilationUnit(){
+ return EclipseUtil.getCompilationUnit(file);
}
@Override
- public void run(IMarker marker) {
- try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
- if(original == null) {
- return;
- }
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(compilationUnit);
-
- 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{
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
MultiTextEdit edit = new MultiTextEdit();
change.setEdit(edit);
-
- IBuffer buffer = compilationUnit.getBuffer();
-
- int flag = method.getFlags();
-
- String text = buffer.getText(method.getSourceRange().getOffset(),
method.getSourceRange().getLength());
-
- // make method public
- int position = method.getSourceRange().getOffset();
-
- if((flag & Flags.AccPublic) == 0){
- if((flag & Flags.AccPrivate) != 0){
- position += text.indexOf(PRIVATE);
- edit.addChild(new ReplaceEdit(position, PRIVATE.length(), PUBLIC));
- }else if((flag & Flags.AccProtected) != 0){
- position += text.indexOf(PROTECTED);
- edit.addChild(new ReplaceEdit(position, PROTECTED.length(), PUBLIC));
- }else{
- String type = Signature.getSignatureSimpleName(method.getReturnType());
- position += text.indexOf(type);
- buffer.replace(position, 0, PUBLIC+SPACE);
- edit.addChild(new InsertEdit(position, PUBLIC+SPACE));
- }
- }
-
- // add @LocalBean annotation
- MarkerResolutionUtils.addAnnotation(CDIConstants.LOCAL_BEAN_ANNOTATION_TYPE_NAME,
compilationUnit, method.getDeclaringType(), "", edit);
-
- return change;
- }
-
- private CompilationUnitChange getPreviewChange(){
try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ IBuffer buffer = compilationUnit.getBuffer();
- return getChange(original);
- }catch(CoreException ex){
- CDIUIPlugin.getDefault().logError(ex);
- }
- return null;
- }
+ int flag = method.getFlags();
+
+ String text = buffer.getText(method.getSourceRange().getOffset(),
method.getSourceRange().getLength());
- private String getPreview(){
- TextChange previewChange = getPreviewChange();
-
- try {
- return MarkerResolutionUtils.getPreview(previewChange);
- } catch (CoreException e) {
- CommonUIPlugin.getDefault().logError(e);
+ // make method public
+ int position = method.getSourceRange().getOffset();
+
+ if((flag & Flags.AccPublic) == 0){
+ if((flag & Flags.AccPrivate) != 0){
+ position += text.indexOf(PRIVATE);
+ edit.addChild(new ReplaceEdit(position, PRIVATE.length(), PUBLIC));
+ }else if((flag & Flags.AccProtected) != 0){
+ position += text.indexOf(PROTECTED);
+ edit.addChild(new ReplaceEdit(position, PROTECTED.length(), PUBLIC));
+ }else{
+ String type = Signature.getSignatureSimpleName(method.getReturnType());
+ position += text.indexOf(type);
+ buffer.replace(position, 0, PUBLIC+SPACE);
+ edit.addChild(new InsertEdit(position, PUBLIC+SPACE));
+ }
+ }
+
+ // add @LocalBean annotation
+ MarkerResolutionUtils.addAnnotation(CDIConstants.LOCAL_BEAN_ANNOTATION_TYPE_NAME,
compilationUnit, method.getDeclaringType(), "", edit);
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
}
- return label;
+ return change;
}
@Override
- public String getDescription() {
- return description;
- }
-
- @Override
public Image getImage() {
return CDIImages.QUICKFIX_ADD;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNameMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNameMarkerResolution.java 2012-01-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNameMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -20,7 +20,6 @@
public AddNameMarkerResolution(IAnnotation annotation, String parameter) {
super(annotation, "\""+parameter+"\"");
label = NLS.bind(CDIUIMessages.ADD_NAME_MARKER_RESOLUTION_TITLE, parameter);
- description = getPreview();
}
@Override
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddRetentionAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddRetentionAnnotationMarkerResolution.java 2012-01-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddRetentionAnnotationMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -10,103 +10,52 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.marker;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
-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.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.text.edits.MultiTextEdit;
-import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDIImages;
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;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
-public class AddRetentionAnnotationMarkerResolution implements
- IMarkerResolution2 {
+public class AddRetentionAnnotationMarkerResolution extends BaseMarkerResolution {
private IType type;
- private String label;
- private String description;
public AddRetentionAnnotationMarkerResolution(IType type){
this.type = type;
label = NLS.bind(CDIUIMessages.ADD_RETENTION_MARKER_RESOLUTION_TITLE,
type.getElementName());
- description = getPreview();
+ init();
}
@Override
- public String getLabel() {
- return label;
+ protected ICompilationUnit getCompilationUnit(){
+ return type.getCompilationUnit();
}
-
- @Override
- public void run(IMarker marker) {
- try{
- ICompilationUnit original = type.getCompilationUnit();
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(compilationUnit);
-
- 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{
+ @Override
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
MultiTextEdit edit = new MultiTextEdit();
change.setEdit(edit);
-
- CDIMarkerResolutionUtils.addImport(CDIConstants.RETENTION_POLICY_RUNTIME_TYPE_NAME,
compilationUnit, true, edit);
-
- CDIMarkerResolutionUtils.addAnnotation(CDIConstants.RETENTION_ANNOTATION_TYPE_NAME,
compilationUnit, type, "(RUNTIME)", edit);
-
- return change;
- }
-
- private CompilationUnitChange getPreviewChange(){
try{
- ICompilationUnit original = type.getCompilationUnit();
+ CDIMarkerResolutionUtils.addImport(CDIConstants.RETENTION_POLICY_RUNTIME_TYPE_NAME,
compilationUnit, true, edit);
- return getChange(original);
- }catch(CoreException ex){
- CDIUIPlugin.getDefault().logError(ex);
+ CDIMarkerResolutionUtils.addAnnotation(CDIConstants.RETENTION_ANNOTATION_TYPE_NAME,
compilationUnit, type, "(RUNTIME)", edit);
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
}
- return null;
+ return change;
}
- 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 description;
- }
-
- @Override
public Image getImage() {
return CDIImages.QUICKFIX_ADD;
}
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-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddSerializableInterfaceMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -13,108 +13,55 @@
import java.text.MessageFormat;
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.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;
import org.jboss.tools.cdi.core.CDIImages;
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.EclipseUtil;
-import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
-import org.jboss.tools.common.ui.CommonUIPlugin;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
/**
* @author Daniel Azarov
*/
-public class AddSerializableInterfaceMarkerResolution implements IMarkerResolution2 {
+public class AddSerializableInterfaceMarkerResolution extends BaseMarkerResolution {
public static final String SERIALIZABLE = "java.io.Serializable";
//$NON-NLS-1$
- private String label;
- private String description;
private IType type;
private IFile file;
-
public AddSerializableInterfaceMarkerResolution(IType type, IFile file){
this.label =
MessageFormat.format(CDIUIMessages.ADD_SERIALIZABLE_INTERFACE_MARKER_RESOLUTION_TITLE, new
Object[]{type.getElementName()});
this.type = type;
this.file = file;
- description = getPreview();
+ init();
}
@Override
- public String getLabel() {
- return label;
+ protected ICompilationUnit getCompilationUnit(){
+ return EclipseUtil.getCompilationUnit(file);
}
@Override
- public void run(IMarker marker) {
- try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
- if(original == null) {
- return;
- }
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(compilationUnit);
-
- 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{
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
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);
+ CDIMarkerResolutionUtils.addInterfaceToClass(compilationUnit, type, SERIALIZABLE,
edit);
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
}
- return null;
- }
-
- private String getPreview(){
- TextChange previewChange = getPreviewChange();
- try {
- return MarkerResolutionUtils.getPreview(previewChange);
- } catch (CoreException e) {
- CommonUIPlugin.getDefault().logError(e);
- }
- return label;
+ return change;
}
-
- @Override
- public String getDescription() {
- return description;
- }
@Override
public Image getImage() {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddTargetAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddTargetAnnotationMarkerResolution.java 2012-01-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddTargetAnnotationMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -10,31 +10,22 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.marker;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
-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.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.text.edits.MultiTextEdit;
-import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDIImages;
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;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
-public class AddTargetAnnotationMarkerResolution implements
- IMarkerResolution2 {
+public class AddTargetAnnotationMarkerResolution extends BaseMarkerResolution {
private IType type;
- private String label;
- private String description;
private String[] qualifiedNames;
private String[] shortNames;
private String totalList;
@@ -45,75 +36,36 @@
shortNames = CDIMarkerResolutionUtils.getShortNames(qualifiedNames);
totalList =
CDIMarkerResolutionUtils.OPEN_BRACE+CDIMarkerResolutionUtils.getTotalList(shortNames)+CDIMarkerResolutionUtils.CLOSE_BRACE;
label = NLS.bind(CDIUIMessages.ADD_TARGET_MARKER_RESOLUTION_TITLE, totalList,
type.getElementName());
- description = getPreview();
+ init();
}
-
+
@Override
- public String getLabel() {
- return label;
+ protected ICompilationUnit getCompilationUnit(){
+ return type.getCompilationUnit();
}
-
- @Override
- public void run(IMarker marker) {
- try{
- ICompilationUnit original = type.getCompilationUnit();
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(compilationUnit);
-
- 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{
+ @Override
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
MultiTextEdit edit = new MultiTextEdit();
change.setEdit(edit);
- for(String qualifiedName : qualifiedNames){
- CDIMarkerResolutionUtils.addImport(qualifiedName, compilationUnit, true, edit);
- }
- CDIMarkerResolutionUtils.addAnnotation(CDIConstants.TARGET_ANNOTATION_TYPE_NAME,
compilationUnit, type, "("+totalList+")", edit);
-
- return change;
- }
-
- private CompilationUnitChange getPreviewChange(){
try{
- ICompilationUnit original = type.getCompilationUnit();
+ for(String qualifiedName : qualifiedNames){
+ CDIMarkerResolutionUtils.addImport(qualifiedName, compilationUnit, true, edit);
+ }
- return getChange(original);
- }catch(CoreException ex){
- CDIUIPlugin.getDefault().logError(ex);
+ CDIMarkerResolutionUtils.addAnnotation(CDIConstants.TARGET_ANNOTATION_TYPE_NAME,
compilationUnit, type, "("+totalList+")", edit);
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
}
- return null;
- }
-
- private String getPreview(){
- TextChange previewChange = getPreviewChange();
- try {
- return MarkerResolutionUtils.getPreview(previewChange);
- } catch (CoreException e) {
- CommonUIPlugin.getDefault().logError(e);
- }
- return label;
+ return change;
}
@Override
- public String getDescription() {
- return description;
- }
-
- @Override
public Image getImage() {
return CDIImages.QUICKFIX_ADD;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java 2012-01-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -10,29 +10,22 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.marker;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
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;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
-import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.cdi.core.CDIImages;
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;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
-public class ChangeAnnotationMarkerResolution implements
- IMarkerResolution2 {
+public class ChangeAnnotationMarkerResolution extends BaseMarkerResolution {
private IAnnotation annotation;
protected String sourceString = "";
@@ -41,9 +34,6 @@
private String[] qualifiedNames = new String[0];
- protected String label;
- protected String description;
-
public ChangeAnnotationMarkerResolution(IAnnotation annotation){
this.annotation = annotation;
@@ -56,7 +46,7 @@
}
label = NLS.bind(CDIUIMessages.CHANGE_ANNOTATION_MARKER_RESOLUTION_TITLE, sourceString,
changeString);
- description = getPreview();
+ init();
}
public ChangeAnnotationMarkerResolution(IAnnotation annotation, String parameter){
@@ -86,72 +76,31 @@
}
@Override
- public String getLabel() {
- return label;
- }
-
- @Override
- public void run(IMarker marker) {
- try{
- ICompilationUnit original =
CDIMarkerResolutionUtils.getJavaMember(annotation).getCompilationUnit();
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(compilationUnit);
-
- 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{
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
MultiTextEdit edit = new MultiTextEdit();
change.setEdit(edit);
-
- for(String qualifiedName : qualifiedNames){
- CDIMarkerResolutionUtils.addImport(qualifiedName, compilationUnit, true, edit);
- }
-
- IAnnotation workingCopyAnnotation =
CDIMarkerResolutionUtils.findWorkingCopy(compilationUnit, annotation);
-
- TextEdit re = new ReplaceEdit(workingCopyAnnotation.getSourceRange().getOffset(),
workingCopyAnnotation.getSourceRange().getLength(), changeString);
- edit.addChild(re);
-
- return change;
- }
-
- private CompilationUnitChange getPreviewChange(){
try{
- ICompilationUnit original =
CDIMarkerResolutionUtils.getJavaMember(annotation).getCompilationUnit();
+ for(String qualifiedName : qualifiedNames){
+ CDIMarkerResolutionUtils.addImport(qualifiedName, compilationUnit, true, edit);
+ }
- return getChange(original);
- }catch(CoreException ex){
- CDIUIPlugin.getDefault().logError(ex);
+ IAnnotation workingCopyAnnotation =
CDIMarkerResolutionUtils.findWorkingCopy(compilationUnit, annotation);
+
+ TextEdit re = new ReplaceEdit(workingCopyAnnotation.getSourceRange().getOffset(),
workingCopyAnnotation.getSourceRange().getLength(), changeString);
+ edit.addChild(re);
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
}
- return null;
- }
-
- protected String getPreview(){
- TextChange previewChange = getPreviewChange();
- try {
- return MarkerResolutionUtils.getPreview(previewChange);
- } catch (CoreException e) {
- CommonUIPlugin.getDefault().logError(e);
- }
- return label;
+ return change;
}
@Override
- public String getDescription() {
- return description;
+ protected ICompilationUnit getCompilationUnit(){
+ return CDIMarkerResolutionUtils.getJavaMember(annotation).getCompilationUnit();
}
@Override
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-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAnnotationMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -10,9 +10,6 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.marker;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
@@ -21,24 +18,18 @@
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;
-import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.cdi.core.CDIImages;
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;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
-public class DeleteAnnotationMarkerResolution implements
- IMarkerResolution2 {
+public class DeleteAnnotationMarkerResolution extends BaseMarkerResolution {
private IJavaElement element;
private String qualifiedName;
- private String label;
- private String description;
public DeleteAnnotationMarkerResolution(IJavaElement element, String qualifiedName){
this.element = element;
@@ -67,72 +58,31 @@
}
label = NLS.bind(CDIUIMessages.DELETE_ANNOTATION_MARKER_RESOLUTION_TITLE, new
String[]{shortName, element.getElementName(), type});
- description = getPreview();
+ init();
}
-
+
@Override
- public String getLabel() {
- return label;
+ protected ICompilationUnit getCompilationUnit(){
+ return CDIMarkerResolutionUtils.getJavaMember(element).getCompilationUnit();
}
@Override
- public void run(IMarker marker) {
- try{
- ICompilationUnit original =
CDIMarkerResolutionUtils.getJavaMember(element).getCompilationUnit();
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(compilationUnit);
-
- 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{
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
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);
+ CDIMarkerResolutionUtils.deleteAnnotation(qualifiedName, compilationUnit, element,
edit);
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
}
- return null;
- }
-
- protected String getPreview(){
- TextChange previewChange = getPreviewChange();
- try {
- return MarkerResolutionUtils.getPreview(previewChange);
- } catch (CoreException e) {
- CommonUIPlugin.getDefault().logError(e);
- }
- return label;
+ return change;
}
-
+
@Override
- public String getDescription() {
- return description;
- }
-
- @Override
public Image getImage() {
return CDIImages.QUICKFIX_REMOVE;
}
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-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeBeanScopedDependentMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -15,21 +15,16 @@
import java.util.Set;
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.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IBuffer;
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.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
-import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDIImages;
import org.jboss.tools.cdi.core.IBean;
@@ -38,119 +33,64 @@
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;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
/**
* @author Daniel Azarov
*/
-public class MakeBeanScopedDependentMarkerResolution implements IMarkerResolution2{
- private String label;
+public class MakeBeanScopedDependentMarkerResolution extends BaseMarkerResolution {
private IBean bean;
private IFile file;
- private String description;
+ private IAnnotation annotation;
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();
+ annotation = getScopeAnnotation();
+ init();
}
@Override
- public String getLabel() {
- return label;
+ protected ICompilationUnit getCompilationUnit(){
+ return EclipseUtil.getCompilationUnit(file);
}
-
- @Override
- public void run(IMarker marker) {
- IAnnotation originalAnnotation = getScopeAnnotation();
- if(originalAnnotation == null)
- return;
- try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
- if(original == null) {
- return;
- }
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(originalAnnotation, compilationUnit);
-
- 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(IAnnotation originalAnnotation, ICompilationUnit
compilationUnit) throws JavaModelException{
+ @Override
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
+ if(annotation != null){
+ MultiTextEdit edit = new MultiTextEdit();
- MultiTextEdit edit = new MultiTextEdit();
+ change.setEdit(edit);
- change.setEdit(edit);
+ try{
+ CDIMarkerResolutionUtils.addImport(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME,
compilationUnit, edit);
- CDIMarkerResolutionUtils.addImport(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME,
compilationUnit, edit);
+ IAnnotation workingCopyAnnotation = getWorkingCopyAnnotation(annotation,
compilationUnit);
- IAnnotation workingCopyAnnotation = getWorkingCopyAnnotation(originalAnnotation,
compilationUnit);
-
- if(workingCopyAnnotation != null){
- String shortName =
CDIMarkerResolutionUtils.getShortName(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
+ 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);
+ TextEdit re = new ReplaceEdit(workingCopyAnnotation.getSourceRange().getOffset(),
workingCopyAnnotation.getSourceRange().getLength(),
CDIMarkerResolutionUtils.AT+shortName);
+ edit.addChild(re);
- IBuffer buffer = compilationUnit.getBuffer();
+ IBuffer buffer = compilationUnit.getBuffer();
- // delete import
- String qualifiedName = getFullyQualifiedName();
- if(qualifiedName != null){
- CDIMarkerResolutionUtils.deleteImportForAnnotation(qualifiedName,
workingCopyAnnotation, compilationUnit, buffer, edit);
+ // delete import
+ String qualifiedName = getFullyQualifiedName();
+ if(qualifiedName != null){
+ CDIMarkerResolutionUtils.deleteImportForAnnotation(qualifiedName,
workingCopyAnnotation, compilationUnit, buffer, edit);
+ }
+ }
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
}
}
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){
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-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldStaticMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -13,139 +13,82 @@
import java.text.MessageFormat;
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.jdt.core.Flags;
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;
-import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.cdi.core.CDIImages;
+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.EclipseUtil;
-import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
-import org.jboss.tools.common.ui.CommonUIPlugin;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
/**
* @author Daniel Azarov
*/
-public class MakeFieldStaticMarkerResolution implements IMarkerResolution2 {
- private static final String PUBLIC = "public"; //$NON-NLS-1$
- private static final String PRIVATE = "private"; //$NON-NLS-1$
- private static final String PROTECTED = "protected"; //$NON-NLS-1$
- private static final String STATIC = "static"; //$NON-NLS-1$
- private static final String SPACE = " "; //$NON-NLS-1$
-
- private String label;
+public class MakeFieldStaticMarkerResolution extends BaseMarkerResolution {
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();
+ init();
}
-
+
@Override
- public String getLabel() {
- return label;
+ protected ICompilationUnit getCompilationUnit(){
+ return EclipseUtil.getCompilationUnit(file);
}
-
+
@Override
- public void run(IMarker marker) {
- try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
- if(original == null) {
- return;
- }
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(compilationUnit);
-
- 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{
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit) {
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);
+ IBuffer buffer = compilationUnit.getBuffer();
- return getChange(original);
+ 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(CDIMarkerResolutionUtils.PUBLIC)+CDIMarkerResolutionUtils.PUBLIC.length();
+ InsertEdit ie = new InsertEdit(position,
CDIMarkerResolutionUtils.SPACE+CDIMarkerResolutionUtils.STATIC);
+ edit.addChild(ie);
+ }else if((flag & Flags.AccPrivate) != 0){
+ position +=
text.indexOf(CDIMarkerResolutionUtils.PRIVATE)+CDIMarkerResolutionUtils.PRIVATE.length();
+ InsertEdit ie = new InsertEdit(position,
CDIMarkerResolutionUtils.SPACE+CDIMarkerResolutionUtils.STATIC);
+ edit.addChild(ie);
+ }else if((flag & Flags.AccProtected) != 0){
+ position +=
text.indexOf(CDIMarkerResolutionUtils.PROTECTED)+CDIMarkerResolutionUtils.PROTECTED.length();
+ InsertEdit ie = new InsertEdit(position,
CDIMarkerResolutionUtils.SPACE+CDIMarkerResolutionUtils.STATIC);
+ edit.addChild(ie);
+ }else{
+ String type = Signature.getSignatureSimpleName(field.getTypeSignature());
+ position += text.indexOf(type);
+ InsertEdit ie = new InsertEdit(position,
CDIMarkerResolutionUtils.SPACE+CDIMarkerResolutionUtils.STATIC);
+ edit.addChild(ie);
+ }
}catch(CoreException ex){
CDIUIPlugin.getDefault().logError(ex);
}
- return null;
+ return change;
}
- 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 description;
- }
-
- @Override
public Image getImage() {
return CDIImages.QUICKFIX_EDIT;
}
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-25
00:51:01 UTC (rev 38151)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodPublicMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -13,144 +13,87 @@
import java.text.MessageFormat;
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.jdt.core.Flags;
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;
import org.eclipse.text.edits.ReplaceEdit;
-import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.cdi.core.CDIImages;
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.EclipseUtil;
-import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
-import org.jboss.tools.common.ui.CommonUIPlugin;
+import org.jboss.tools.common.refactoring.BaseMarkerResolution;
/**
* @author Daniel Azarov
*/
-public class MakeMethodPublicMarkerResolution implements IMarkerResolution2 {
- private static final String PUBLIC = "public"; //$NON-NLS-1$
- private static final String PRIVATE = "private"; //$NON-NLS-1$
- private static final String PROTECTED = "protected"; //$NON-NLS-1$
- private static final String SPACE = " "; //$NON-NLS-1$
-
- private String label;
+public class MakeMethodPublicMarkerResolution extends BaseMarkerResolution {
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();
+ init();
}
@Override
- public String getLabel() {
- return label;
+ protected ICompilationUnit getCompilationUnit(){
+ return EclipseUtil.getCompilationUnit(file);
}
@Override
- public void run(IMarker marker) {
- try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
- if(original == null) {
- return;
- }
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- CompilationUnitChange change = getChange(compilationUnit);
-
- 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{
+ protected CompilationUnitChange getChange(ICompilationUnit compilationUnit){
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();
+ try{
+ IBuffer buffer = compilationUnit.getBuffer();
- 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);
- }else if((flag & Flags.AccProtected) != 0){
- position += text.indexOf(PROTECTED);
- ReplaceEdit re = new ReplaceEdit(position, PROTECTED.length(), PUBLIC);
- edit.addChild(re);
- }else{
- String type = Signature.getSignatureSimpleName(workingCopyMethod.getReturnType());
- position += text.indexOf(type);
- InsertEdit ie = new InsertEdit(position, PUBLIC+SPACE);
- edit.addChild(ie);
+ 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){
+ if((flag & Flags.AccPrivate) != 0){
+ position += text.indexOf(CDIMarkerResolutionUtils.PRIVATE);
+ ReplaceEdit re = new ReplaceEdit(position,
CDIMarkerResolutionUtils.PRIVATE.length(), CDIMarkerResolutionUtils.PUBLIC);
+ edit.addChild(re);
+ }else if((flag & Flags.AccProtected) != 0){
+ position += text.indexOf(CDIMarkerResolutionUtils.PROTECTED);
+ ReplaceEdit re = new ReplaceEdit(position,
CDIMarkerResolutionUtils.PROTECTED.length(), CDIMarkerResolutionUtils.PUBLIC);
+ edit.addChild(re);
+ }else{
+ String type = Signature.getSignatureSimpleName(workingCopyMethod.getReturnType());
+ position += text.indexOf(type);
+ InsertEdit ie = new InsertEdit(position,
CDIMarkerResolutionUtils.PUBLIC+CDIMarkerResolutionUtils.SPACE);
+ 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;
+ return change;
}
- 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 description;
- }
-
- @Override
public Image getImage() {
return CDIImages.QUICKFIX_EDIT;
}
-
}
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/BaseMarkerResolution.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/BaseMarkerResolution.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/BaseMarkerResolution.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.refactoring;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.ltk.core.refactoring.TextChange;
+import org.eclipse.ui.IMarkerResolution2;
+import org.jboss.tools.common.CommonPlugin;
+
+abstract public class BaseMarkerResolution implements IMarkerResolution2 {
+ protected String label;
+ protected String description;
+
+ protected final void init(){
+ description = getPreview();
+ }
+
+ @Override
+ public final String getLabel() {
+ return label;
+ }
+
+ @Override
+ public final void run(IMarker marker) {
+ try{
+ ICompilationUnit original = getCompilationUnit();
+ if(original != null){
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ TextChange change = getChange(compilationUnit);
+
+ if(change.getEdit().hasChildren()){
+ change.perform(new NullProgressMonitor());
+ original.reconcile(ICompilationUnit.NO_AST, false, null, new
NullProgressMonitor());
+ }
+ compilationUnit.discardWorkingCopy();
+ }
+ }catch(CoreException ex){
+ CommonPlugin.getDefault().logError(ex);
+ }
+ }
+
+ @Override
+ public final String getDescription() {
+ return description;
+ }
+
+ private TextChange getPreviewChange(){
+ ICompilationUnit original = getCompilationUnit();
+ if(original != null){
+ return getChange(original);
+ }
+ return null;
+ }
+
+ private String getPreview(){
+ TextChange previewChange = getPreviewChange();
+ if(previewChange != null){
+ try {
+ return MarkerResolutionUtils.getPreview(previewChange);
+ } catch (CoreException e) {
+ CommonPlugin.getDefault().logError(e);
+ }
+ }
+ return label;
+ }
+
+ abstract protected ICompilationUnit getCompilationUnit();
+
+ abstract protected TextChange getChange(ICompilationUnit compilationUnit);
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/BaseMarkerResolution.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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
00:51:01 UTC (rev 38151)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java 2012-01-25
01:20:38 UTC (rev 38152)
@@ -64,6 +64,9 @@
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$
+ public static final String PUBLIC = "public"; //$NON-NLS-1$
+ public static final String PRIVATE = "private"; //$NON-NLS-1$
+ public static final String PROTECTED = "protected"; //$NON-NLS-1$
public static final char C_SPACE = ' '; //$NON-NLS-1$
public static final char C_TAB = '\t';