Author: dazarov
Date: 2012-01-18 17:06:49 -0500 (Wed, 18 Jan 2012)
New Revision: 37960
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/AddSuppressWarningsMarkerResolution.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/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-18
21:07:22 UTC (rev 37959)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java 2012-01-18
22:06:49 UTC (rev 37960)
@@ -14,6 +14,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IAnnotatable;
@@ -35,6 +36,7 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
+import org.eclipse.ltk.core.refactoring.TextChange;
import org.eclipse.text.edits.DeleteEdit;
import org.eclipse.text.edits.InsertEdit;
import org.eclipse.text.edits.MultiTextEdit;
@@ -44,6 +46,7 @@
public class MarkerResolutionUtils {
public static final String DOT = "."; //$NON-NLS-1$
+ public static final String DOTS = "..."; //$NON-NLS-1$
public static final String COMMA = ","; //$NON-NLS-1$
public static final String SEMICOLON = ";"; //$NON-NLS-1$
public static final String SPACE = " "; //$NON-NLS-1$
@@ -54,11 +57,17 @@
public static final String EXTENDS = "extends"; //$NON-NLS-1$
public static final String OPEN_BRACE = "{"; //$NON-NLS-1$
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 NEW_LINE = "\n"; //$NON-NLS-1$
+ public static final String LINE_BREAK = "<br>"; //$NON-NLS-1$
public static final char C_SPACE = ' '; //$NON-NLS-1$
public static final char C_TAB = '\t';
public static final char C_CARRIAGE_RETURN = '\r';
public static final char C_NEW_LINE = '\n';
+
+ private static final int NUMBER_OF_STRINGS = 3;
static final HashSet<String> primitives = new HashSet<String>();
static{
@@ -568,5 +577,61 @@
}
return null;
}
-
+
+ public static String getPreview(TextChange previewChange) throws CoreException{
+ String preview = previewChange.getPreviewContent(new NullProgressMonitor());
+ TextEdit edit = previewChange.getEdit();
+ String text = null;
+ if(edit instanceof InsertEdit){
+ text = ((InsertEdit) edit).getText();
+ }else if(edit instanceof ReplaceEdit){
+ text = ((ReplaceEdit) edit).getText();
+ }
+ if(edit != null && text != null){
+ int offset = edit.getOffset();
+ int length = text.length();
+
+ // select
+ String before = preview.substring(0, offset);
+ String after = preview.substring(offset+length);
+ preview = before+OPEN_BOLD+text+CLOSE_BOLD+after;
+
+ // cut
+ int position = offset;
+ int count = NUMBER_OF_STRINGS;
+ String startText = NEW_LINE;
+ while(position >= 0){
+ char c = preview.charAt(position);
+ if(c == C_NEW_LINE){
+ count--;
+ if(count == 0){
+ position++;
+ startText = DOTS+startText;
+ break;
+ }
+ }
+ position--;
+ }
+ int start = position;
+ String endText = NEW_LINE;
+ position = offset+length;
+ count = NUMBER_OF_STRINGS;
+ while(position < preview.length()-1){
+ char c = preview.charAt(position);
+ if(c == C_NEW_LINE){
+ count--;
+ if(count == 0){
+ endText += DOTS;
+ break;
+ }
+ }
+ position++;
+ }
+ preview = startText+preview.substring(start, position)+endText;
+
+ // format
+ preview = preview.replaceAll(NEW_LINE, LINE_BREAK);
+ }
+ return preview;
+ }
}
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/AddSuppressWarningsMarkerResolution.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/AddSuppressWarningsMarkerResolution.java 2012-01-18
21:07:22 UTC (rev 37959)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/AddSuppressWarningsMarkerResolution.java 2012-01-18
22:06:49 UTC (rev 37960)
@@ -39,6 +39,7 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
+import org.eclipse.ltk.core.refactoring.TextChange;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
@@ -49,6 +50,7 @@
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.preferences.SeverityPreferences;
+import org.jboss.tools.common.refactoring.MarkerResolutionUtils;
import org.jboss.tools.common.ui.CommonUIMessages;
import org.jboss.tools.common.ui.CommonUIPlugin;
import org.jboss.tools.common.validation.WarningNameManager;
@@ -70,6 +72,7 @@
private IAnnotatable element;
private String preferenceKey;
private String label;
+ private String description;
public AddSuppressWarningsMarkerResolution(IFile file, IJavaElement element, String
preferenceKey){
this.file = file;
@@ -85,8 +88,21 @@
if(element instanceof IMethod){
label += "()";
}
+
+ description = getPreview();
}
+ private String getPreview(){
+ TextChange previewChange = getPreviewChange();
+
+ try {
+ return MarkerResolutionUtils.getPreview(previewChange);
+ } catch (CoreException e) {
+ CommonUIPlugin.getDefault().logError(e);
+ }
+ return label;
+ }
+
private IAnnotatable getAnnatatableElement(IJavaElement element){
IJavaElement elem = element;
while(elem != null){
@@ -102,6 +118,42 @@
public String getLabel() {
return label;
}
+
+ private TextChange getPreviewChange(){
+ if(element != null && preferenceKey != null){
+ disablePreference();
+ try {
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ if(original == null) {
+ return null;
+ }
+
+ return getChange(original);
+ } catch (JavaModelException e) {
+ CommonUIPlugin.getDefault().logError(e);
+ }
+ }
+ return null;
+ }
+
+ private CompilationUnitChange getChange(ICompilationUnit compilationUnit) throws
JavaModelException{
+ CompilationUnit cuNode = ASTTools.buildASTRoot(compilationUnit);
+
+ IJavaElement workingCopyElement = findWorkingCopy(compilationUnit,
(IJavaElement)element);
+ ASTNode elementNode = null;
+ if(workingCopyElement instanceof JavaElement){
+ elementNode = ((JavaElement) workingCopyElement).findNode(cuNode);
+ }
+
+ IAnnotation annotation = findAnnotation(workingCopyElement);
+ CompilationUnitChange change = null;
+ if(annotation != null){
+ change = updateAnnotation(SUPPRESS_WARNINGS_ANNOTATION, preferenceKey,
compilationUnit, annotation);
+ }else{
+ change =
addAnnotation(SUPPRESS_WARNINGS_ANNOTATION+"(\""+preferenceKey+"\")",
compilationUnit, workingCopyElement, elementNode);
+ }
+ return change;
+ }
@Override
public void run(IMarker marker) {
@@ -114,22 +166,8 @@
}
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
- CompilationUnit cuNode = ASTTools.buildASTRoot(compilationUnit);
+ CompilationUnitChange change = getChange(compilationUnit);
- IJavaElement workingCopyElement = findWorkingCopy(compilationUnit,
(IJavaElement)element);
- ASTNode elementNode = null;
- if(workingCopyElement instanceof JavaElement){
- elementNode = ((JavaElement) workingCopyElement).findNode(cuNode);
- }
-
- IAnnotation annotation = findAnnotation(workingCopyElement);
- CompilationUnitChange change = null;
- if(annotation != null){
- change = updateAnnotation(SUPPRESS_WARNINGS_ANNOTATION, preferenceKey,
compilationUnit, annotation);
- }else{
- change =
addAnnotation(SUPPRESS_WARNINGS_ANNOTATION+"(\""+preferenceKey+"\")",
compilationUnit, workingCopyElement, elementNode);
- }
-
if(change != null){
change.perform(new NullProgressMonitor());
original.reconcile(ICompilationUnit.NO_AST, false, null, new
NullProgressMonitor());
@@ -233,7 +271,7 @@
}
@Override
public String getDescription() {
- return label;
+ return description;
}
@Override