Author: dazarov
Date: 2011-12-14 20:47:45 -0500 (Wed, 14 Dec 2011)
New Revision: 37343
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/ConfigureProblemSeverityResolutionGenerator.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties
Log:
Add @SuppressWarnings quick fix
https://issues.jboss.org/browse/JBIDE-10187
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-15
01:46:25 UTC (rev 37342)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/AddSuppressWarningsMarkerResolution.java 2011-12-15
01:47:45 UTC (rev 37343)
@@ -50,6 +50,7 @@
IMarkerResolution2 {
public static final String SUPPRESS_WARNINGS_ANNOTATION = "SuppressWarnings";
public static final String SPACE = " "; //$NON-NLS-1$
+ public static final String DOT = "."; //$NON-NLS-1$
public static final String AT = "@"; //$NON-NLS-1$
private static final String PROBLEM_ID = JavaCore.COMPILER_PB_UNHANDLED_WARNING_TOKEN;
private SP preferences = new SP();
@@ -63,7 +64,11 @@
this.file = file;
this.element = getAnnatatableElement(element);
this.preferenceKey = preferenceKey;
- label = NLS.bind(CommonUIMessages.ADD_SUPPRESS_WARNINGS_TITLE,
element.getElementName());
+ String shortName = getShortName(preferenceKey);
+ label = NLS.bind(CommonUIMessages.ADD_SUPPRESS_WARNINGS_TITLE, shortName,
element.getElementName());
+ if(element instanceof IMethod){
+ label += "()";
+ }
}
private IAnnotatable getAnnatatableElement(IJavaElement element){
@@ -121,6 +126,16 @@
return null;
}
+ public static String getShortName(String qualifiedName){
+ int lastDot = qualifiedName.lastIndexOf(DOT);
+ String name;
+ if(lastDot < 0)
+ name = qualifiedName;
+ else
+ name = qualifiedName.substring(lastDot+1);
+ return name;
+ }
+
private void disablePreference(){
String value = preferences.getProjectPreference(file.getProject(), PROBLEM_ID);
if(!SeverityPreferences.IGNORE.equals(value)){
@@ -153,7 +168,7 @@
CommonUIMessages.ADD_SUPPRESS_WARNINGS_MESSAGE+
NLS.bind(CommonUIMessages.ADD_SUPPRESS_WARNINGS_QUESTION2,
file.getProject().getName()),
MessageDialog.QUESTION_WITH_CANCEL,
- new String[]{"Cancel", "Workspace",
file.getProject().getName()},
+ new String[]{"Cancel", "Workspace", "Project"},
0);
int result = dialog.open();
if(result == 1){
@@ -208,10 +223,25 @@
str += "({";
for(IMemberValuePair pair : annotation.getMemberValuePairs()){
- if(pair.getValue().toString().equals(parameter)){
- return false;
+ if(pair.getValueKind() == IMemberValuePair.K_STRING){
+ Object value = pair.getValue();
+ if(value instanceof String){
+ if(value.toString().equals(parameter)){
+ return false;
+ }
+ str += "\""+value+"\", ";
+ }else if(value instanceof Object[]){
+ Object[] array = (Object[])value;
+ for(Object a : array){
+ if(a instanceof String){
+ if(a.toString().equals(parameter)){
+ return false;
+ }
+ str += "\""+a+"\", ";
+ }
+ }
+ }
}
- str += "\""+pair.getValue()+"\", ";
}
str += "\""+parameter+"\"";
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/ConfigureProblemSeverityResolutionGenerator.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/ConfigureProblemSeverityResolutionGenerator.java 2011-12-15
01:46:25 UTC (rev 37342)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/ConfigureProblemSeverityResolutionGenerator.java 2011-12-15
01:47:45 UTC (rev 37343)
@@ -17,6 +17,9 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator2;
import org.jboss.tools.common.EclipseUtil;
@@ -42,10 +45,17 @@
if(preferenceKey != null && preferencePageId != null){
resolutions.add(new ConfigureProblemSeverityMarkerResolution(preferencePageId,
preferenceKey));
boolean enabled =
marker.getAttribute(ValidationErrorManager.SUPPRESS_WARNINGS_ENABLED_ATTRIBUTE, false);
- if(enabled){
+ int severity = marker.getAttribute(IMarker.SEVERITY, 0);
+ if(enabled && severity == IMarker.SEVERITY_WARNING){
IJavaElement element = findJavaElement(file, position);
if(element != null){
- resolutions.add(new AddSuppressWarningsMarkerResolution(file, element,
preferenceKey));
+ if(element instanceof IMethod){
+ ILocalVariable parameter = findParameter((IMethod)element, position);
+ if(parameter != null){
+ resolutions.add(new AddSuppressWarningsMarkerResolution(file, parameter,
preferenceKey));
+ }
+ resolutions.add(new AddSuppressWarningsMarkerResolution(file, element,
preferenceKey));
+ }
}
}
}
@@ -69,6 +79,15 @@
return null;
}
+ private ILocalVariable findParameter(IMethod method, int position) throws
JavaModelException{
+ for(ILocalVariable parameter : method.getParameters()){
+ if(parameter.getSourceRange().getOffset() <= position &&
parameter.getSourceRange().getOffset()+parameter.getSourceRange().getLength() >
position){
+ return parameter;
+ }
+ }
+ return null;
+ }
+
@Override
public boolean hasResolutions(IMarker marker) {
try {
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties 2011-12-15
01:46:25 UTC (rev 37342)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties 2011-12-15
01:47:45 UTC (rev 37343)
@@ -34,7 +34,7 @@
MANDATORYSTRING_VALIDATOR_MUST_PROVIDE_VALUE=You have to provide a {0}.
CONFIGURE_PROBLEM_SEVERITY=Configure Problem Severity
-ADD_SUPPRESS_WARNINGS_TITLE=Add @SuppressWarnings to ''{0}''
+ADD_SUPPRESS_WARNINGS_TITLE=Add @SuppressWarnings ''{0}'' to
''{1}''
ADD_SUPPRESS_WARNINGS_MESSAGE=This quick fix uses warning names that are not supported by
The Java Validator and will cause \"Unsupported @SuppressWarning\" problem
message.\n\n
ADD_SUPPRESS_WARNINGS_QUESTION1=Do you want to disable 'Unsupported
@SuppressWarnings' validation?
ADD_SUPPRESS_WARNINGS_QUESTION2=Do you want to disable 'Unsupported
@SuppressWarnings' validation on the Workspace or on the project
''{0}''?
\ No newline at end of file