Telling IDEA 3.0 to ignore an unused parameter

Hello,

We just startted using IDEA 3.0 (build 676) and love the way it helps
getting rid of
dead code and variables.

One thing I don't see how to avoid is the following:

We use "flags" to distinguish among several constructors by their types,
e.g.

class MyClass
{
MyClass(int i, CreateFromStroe flag)
{
...
}

MyClass(int i, CreateFromRequest flag)
{
...
}

public class CreateFromStore {};
public static final CreateFromStore cCreateFromStore = null;
public class CreateFromRequest {};
public static final CreateFromRequest cCreateFromRequest = null;
}

So users of this class can create its objects with:

new MyClass(0, MyClass.cCreateFromStore);

But IDEA warns (rightly) that "flag" isn't used inside the constructor.
Trying to add
"flag = flag;" (which used to work back on the days of UNIX lint on C
programs)
makes IDEA tell me "silly assignment".

Is there any way I can tell IDEA to ignore this parameter?

Thanks,

--Amos


4 comments
Comment actions Permalink

I'd prefer an abstraction level here...
class MyClass
{
MyClass(int i)
{
...
}
}

class MyClassFromStore extends MyClass {
MyClassFromStore(int i) {
super(i);
}
}

class MyClassFromRequest extends MyClass {
MyClassFromRequest(int i) {
super(i);
}
}


--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Amos Shapira" <intellij_newsgroups@amos.mailshell.com> wrote in message
news:as5j6a$t88$1@is.intellij.net...

Hello,

>

We just startted using IDEA 3.0 (build 676) and love the way it helps
getting rid of
dead code and variables.

>

One thing I don't see how to avoid is the following:

>

We use "flags" to distinguish among several constructors by their types,
e.g.

>

class MyClass
{
MyClass(int i, CreateFromStroe flag)
{
...
}

>

MyClass(int i, CreateFromRequest flag)
{
...
}

>

public class CreateFromStore {};
public static final CreateFromStore cCreateFromStore = null;
public class CreateFromRequest {};
public static final CreateFromRequest cCreateFromRequest = null;
}

>

So users of this class can create its objects with:

>

new MyClass(0, MyClass.cCreateFromStore);

>

But IDEA warns (rightly) that "flag" isn't used inside the constructor.
Trying to add
"flag = flag;" (which used to work back on the days of UNIX lint on C
programs)
makes IDEA tell me "silly assignment".

>

Is there any way I can tell IDEA to ignore this parameter?

>

Thanks,

>

--Amos

>
>


0
Comment actions Permalink

Another way to do the same thing:

class MyClass{
MyClass(int i, MyClassType type){
if (type == MyClassType.FROM_STROE){
...
}
else if (type == MyClassType.FROM_REQUEST){
...
}
}
}

public class MyClassType {
public static final MyClassType FROM_STROE = new
MyClassType("FROM_STROE");
public static final MyClassType FROM_REQUEST = new
MyClassType("FROM_REQUEST");

private final String myName; // for debug only

private MyClassType(String name) {
myName = name;
}

public String toString() {
return myName;
}
}

BTW, it's very easy to create the latter class by New | Enumeration Class...

--
Valentin Kipiatkov
JetBrains, Inc
http://www.intellij.com
"Develop with pleasure!"


"Maxim Shafirov" <max@intellij.net> wrote in message
news:as5lvh$2qu$1@is.intellij.net...

I'd prefer an abstraction level here...
class MyClass
{
MyClass(int i)
{
...
}
}

>

class MyClassFromStore extends MyClass {
MyClassFromStore(int i) {
super(i);
}
}

>

class MyClassFromRequest extends MyClass {
MyClassFromRequest(int i) {
super(i);
}
}

>
>

--

>

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"

>
>

"Amos Shapira" <intellij_newsgroups@amos.mailshell.com> wrote in message
news:as5j6a$t88$1@is.intellij.net...

Hello,

>

We just startted using IDEA 3.0 (build 676) and love the way it helps
getting rid of
dead code and variables.

>

One thing I don't see how to avoid is the following:

>

We use "flags" to distinguish among several constructors by their types,
e.g.

>

class MyClass
{
MyClass(int i, CreateFromStroe flag)
{
...
}

>

MyClass(int i, CreateFromRequest flag)
{
...
}

>

public class CreateFromStore {};
public static final CreateFromStore cCreateFromStore = null;
public class CreateFromRequest {};
public static final CreateFromRequest cCreateFromRequest = null;
}

>

So users of this class can create its objects with:

>

new MyClass(0, MyClass.cCreateFromStore);

>

But IDEA warns (rightly) that "flag" isn't used inside the constructor.
Trying to add
"flag = flag;" (which used to work back on the days of UNIX lint on C
programs)
makes IDEA tell me "silly assignment".

>

Is there any way I can tell IDEA to ignore this parameter?

>

Thanks,

>

--Amos

>
>

>
>


0
Comment actions Permalink

One more suggestion:

class MyClass {
public static MyClass createFromStrore(int i) {
...
}

public static MyClass createFromRequest(int i) {
...
}
}

0
Comment actions Permalink

From the looks of it, there's some sort of "smell" in this code. You should
consider Polymorphism/Subclasses/or a Factory as a way of cleaning up this
type of code. A good reference for "cleaning up smells in code" is the
Refactory book by Martin Fowler.

/a


"Amos Shapira" <intellij_newsgroups@amos.mailshell.com> wrote in message
news:as5j6a$t88$1@is.intellij.net...

Hello,

>

We just startted using IDEA 3.0 (build 676) and love the way it helps
getting rid of
dead code and variables.

>

One thing I don't see how to avoid is the following:

>

We use "flags" to distinguish among several constructors by their types,
e.g.

>

class MyClass
{
MyClass(int i, CreateFromStroe flag)
{
...
}

>

MyClass(int i, CreateFromRequest flag)
{
...
}

>

public class CreateFromStore {};
public static final CreateFromStore cCreateFromStore = null;
public class CreateFromRequest {};
public static final CreateFromRequest cCreateFromRequest = null;
}

>

So users of this class can create its objects with:

>

new MyClass(0, MyClass.cCreateFromStore);

>

But IDEA warns (rightly) that "flag" isn't used inside the constructor.
Trying to add
"flag = flag;" (which used to work back on the days of UNIX lint on C
programs)
makes IDEA tell me "silly assignment".

>

Is there any way I can tell IDEA to ignore this parameter?

>

Thanks,

>

--Amos

>
>


0

Please sign in to leave a comment.