package-info,java and @SuppressWarnings

I

Ian McCall

Hi.

I can't seem to get the snytax right for using SuppressWarnings.

The aim: A package I am working with will have a large number of unused
imports in the code. I don't control this code, so can't remove the
imports by hand. I would like to suppress all the unused import
warnings for that package alone, leaving all those warnings active in
any other package. I'm using Eclipse 3.1.1 and JDK 1.5.0_5.

My attempt at a package-info.java file, path org/eruvia/test/package-info.java:

/** Javadoc test */
@SupressWarnings("unused")
package org.eruvia.test;


Eclipse states "The annotation @SuppressWarnings is disallowed for this
location". Any clues as to where I should be putting this?


Thanks in advance for any information.
Ian
 
R

Roedy Green

Eclipse states "The annotation @SuppressWarnings is disallowed for this
location". Any clues as to where I should be putting this?

it goes inside a javadoc comment
 
H

Hendrik Maryns

Roedy Green schreef:
oops. Why did they not document the list of warnings you can suppress?
Apparently you can't just leave the list blank.

Indeed, I´ve been looking for them too. Luckily, Eclipse seems to know
all about them, that´s where Ctrl-1 comes in handy ;-)

H.

--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
 
H

Hendrik Maryns

Hendrik Maryns schreef:
Roedy Green schreef:



Indeed, I´ve been looking for them too. Luckily, Eclipse seems to know
all about them, that´s where Ctrl-1 comes in handy ;-)

After much googling, I found this:

"The set of names you can use with @SuppressWarnings for javac can be
loosely inferred by going "javac -X" and looking at the spec of -Xlint.
Any -Xlint option that does not begin with "-", and excluding "all" and
"path", can be used with SuppressWarnings. E.g.
@SuppressWarnings("deprecation")
@SuppressWarnings("unchecked")
etc."

found on http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4986256

And something can be found in the SCSL source ZIP file for 1.5. it seems:
"The full list of properties can be found at:

src\j2se\src\share\classes\com\sun\tools\javac\resources\compiler.properties

It appears the keywords are the ones surrounded by brackets. Though I am
just guessing here."

Anybody know where I can get this latest file?

Cheers, H.


--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
 
R

Roedy Green

Can it? Oops no.
As an annotation, it cannot be applied to a package or an annotation
type declaration.

Here is my current understanding, quoted from
http://mindprod.com/annotations.html#SUPPRESSWARNINGS

In JDK 1.5 an annotation was introduced called SuppressWarnings.
Unfortunately, it will be ignored until JDK 1.6. You just insert the
annotation prior to a class or method telling which sort of warning
you want suppressed. e.g.

// Turn off warnings about failing to use generics for the whole class
@SuppressWarnings( "unchecked" ) public class MyClass
{

// Suppress warnings about missing serialVersionUID
@SuppressWarnings( "serial" ) public void MyMethod1()
{ /* ... */ }

// Suppress warnings about unused variables
@SuppressWarnings( "unused" ) public void MyMethod2()
{ /* ... */ }

// Suppress warnings about both missing serialVersionUID and unused
variables
@SuppressWarnings( "serial", "unused" ) public void MyMethod3()
{ /* ... */ }
}

Here are the sorts of warning you can suppress
SuppressWarnings Options
Option Notes
all All warnings
allDeprecation deprecation even inside deprecated code
allJavadoc invalid or missing javadoc
assertIdentifier occurrence of assert used as identifier
boxing autoboxing conversion
charConcat when a char array is used in a string concatenation
without being converted explicitly to a string
conditionAssign possible accidental boolean assignment
constructorName method with constructor name
dep-ann missing @Deprecated annotation
deprecation usage of deprecated type or member outside deprecated
code
emptyBlock undocumented empty block
enumSwitch incomplete enum switch
incomplete-switch incomplete enum switch
fieldHiding field hiding another variable
finalBound type parameter with final bound
finally finally block not completing normally
hiding shorthand for fieldHiding, localHiding, typeHiding and
maskedCatchBlock
indirectStatic indirect reference to static member
intfAnnotation annotation type used as super interface
intfNonInherited interface non-inherited method compatibility
javadoc invalid javadoc
localHiding local variable hiding another variable
maskedCatchBlocks hidden catch block
nls non-nls string literals
noEffectAssign for assignment with no effect
null missing or redundant null check
over-ann missing @Override annotation
pkgDefaultMethod attempt to override package-default method
serial missing serialVersionUID
semicolon unnecessary semicolon or empty statement
specialParamHiding constructor or setter parameter hiding another
field
static-access shorthand for indirectStatic and staticReceiver
staticReceiver if a non static receiver is used to get a static field
or call a static method
suppress enable @SuppressWarnings
syntheticAccess when performing synthetic access for innerclass
synthetic-access when performing synthetic access for
innerclass
tasks enable support for tasks tags in source code
typeHiding type parameter hiding another type
unchecked unchecked type operation
unnecessaryElse unnecessary else clause
unqualified-field-access unqualified reference to field
unqualifiedField unqualified reference to field
unused shorthand for unusedArgument, unusedImport, unusedLocal,
unusedPrivate and unusedThrown
unusedArgument unused method argument
unusedImport unused import reference
unusedLocal unused local variable
unusedPrivate unused private member declaration
unusedThrown unused declared thrown exception
uselessTypeCheck unnecessary cast/instanceof operation
varargsCast varargs argument need explicit cast
warningToken unhandled warning token in @SuppressWarningsb
Some of the options above are for Eclipse only, however Javac will
quietly ignore them.
 
T

Thomas Hawtin

Roedy said:
Here is my current understanding, quoted from
http://mindprod.com/annotations.html#SUPPRESSWARNINGS
http://mindprod.com/jgloss/annotations.html#SUPPRESSWARNINGS

In JDK 1.5 an annotation was introduced called SuppressWarnings.
Unfortunately, it will be ignored until JDK 1.6. You just insert the
annotation prior to a class or method telling which sort of warning
you want suppressed. e.g.

It will be in 1.5.0_06, which should be with us soon.

As well as classes and methods, it is also applicable to enum,
interface, constructor, field, parameter and local variable declarations.

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top