Author: dazarov
Date: 2011-12-16 16:19:12 -0500 (Fri, 16 Dec 2011)
New Revision: 37407
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/AddSuppressWarningsMarkerResolution.java
Log:
Add @SuppressWarnings quick fix
https://issues.jboss.org/browse/JBIDE-10187
Modified: trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF 2011-12-16
21:07:33 UTC (rev 37406)
+++ trunk/common/plugins/org.jboss.tools.common.ui/META-INF/MANIFEST.MF 2011-12-16
21:19:12 UTC (rev 37407)
@@ -27,7 +27,8 @@
org.jboss.tools.common.validation;bundle-version="3.3.0",
org.eclipse.ui.cheatsheets;bundle-version="3.4.0",
org.eclipse.jdt.core.manipulation;bundle-version="1.4.0",
- org.eclipse.ltk.core.refactoring;bundle-version="3.5.201"
+ org.eclipse.ltk.core.refactoring;bundle-version="3.5.201",
+ org.eclipse.jpt.common.core;bundle-version="1.0.0"
Export-Package: org.jboss.tools.common.ui,
org.jboss.tools.common.ui.databinding,
org.jboss.tools.common.ui.marker,
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 2011-12-16
21:07:33 UTC (rev 37406)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/AddSuppressWarningsMarkerResolution.java 2011-12-16
21:19:12 UTC (rev 37407)
@@ -28,10 +28,14 @@
import org.eclipse.jdt.core.ISourceReference;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
+import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
@@ -97,14 +101,20 @@
ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+ 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);
+ change =
addAnnotation(SUPPRESS_WARNINGS_ANNOTATION+"(\""+preferenceKey+"\")",
compilationUnit, workingCopyElement, elementNode);
}
if(change != null){
@@ -268,18 +278,27 @@
return change;
}
- private CompilationUnitChange addAnnotation(String name, ICompilationUnit
compilationUnit, IJavaElement element) throws JavaModelException{
+ private CompilationUnitChange addAnnotation(String name, ICompilationUnit
compilationUnit, IJavaElement element, ASTNode node) throws JavaModelException{
if(!(element instanceof ISourceReference))
return null;
ISourceReference workingCopySourceReference = (ISourceReference) element;
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ int position = workingCopySourceReference.getSourceRange().getOffset();
+
+ if(node != null){
+ position = node.getStartPosition();
+ }
+
String str = AT+name;
if(!(workingCopySourceReference instanceof ILocalVariable)){
+
str += compilationUnit.findRecommendedLineSeparator();
- IBuffer buffer = compilationUnit.getBuffer();
- int index = workingCopySourceReference.getSourceRange().getOffset();
+
+ int index = position;
while(index >= 0){
char c = buffer.getChar(index);
if(c == '\r' || c == '\n')
@@ -287,8 +306,8 @@
index--;
}
index++;
- if(index != workingCopySourceReference.getSourceRange().getOffset()){
- String spaces = buffer.getText(index,
workingCopySourceReference.getSourceRange().getOffset()-index);
+ if(index != position){
+ String spaces = buffer.getText(index, position-index);
str += spaces;
}
@@ -298,7 +317,7 @@
CompilationUnitChange change = new CompilationUnitChange("",
compilationUnit);
- InsertEdit edit = new
InsertEdit(workingCopySourceReference.getSourceRange().getOffset(), str);
+ InsertEdit edit = new InsertEdit(position, str);
change.setEdit(edit);