ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scotte Zinn" <sz...@patronix.com>
Subject RE: [PATCH] New <case> task
Date Wed, 11 Oct 2000 11:20:24 GMT
If you use

private static final boolean DEBUG_ENABLED = @DEBUG@;

and replace @DEBUG@ with either true or false, you can have the C equivalent
of #ifdef DEBUG in your Java code.

As long as the variable is declared as static final, most Java compilers
(including javac) will optimize out code that is written as:

if (Debugging.DEBUG_ENABLED) {
	// Do your debugging stuff here
}

The runtime penalty for a debug build is just the debugging code, as the if
statement check is removed when DEBUG_ENABLED is true. I use this technique
for littering assertions throughout my code.

-- Scotte

-----Original Message-----
From: Nico Seessle [mailto:Nico.Seessle@epost.de]
Sent: Wednesday, October 11, 2000 3:50 AM
To: ant-dev@jakarta.apache.org
Subject: Re: [PATCH] New <case> task


----- Original Message -----
From: "Diane Holt" <holtdl@yahoo.com>
To: <ant-dev@jakarta.apache.org>
Sent: Wednesday, October 11, 2000 5:19 AM
Subject: RE: [PATCH] New <case> task


> Don't know what Jose Alberto's particular need is, but I can tell you one
> of the things I'd like it for... I have a property that contains a value
> of either "true" or "false" -- note: it's not something I can have simply
> either set or not-set, because the literal value of it is used as the
> replacement string for a filter token. The token is the value of a boolean
> in a .java file, and depending on whether it is set to "true" or "false"
> determines whether the source-tree is being compiled with debug code or
> without

You CAN do it without scripting or case-tasks with just setting the property
to true or not setting it if you use something like this in your Java-Code

    private static final String DEBUG_STRING  = "@DEBUG@";
    public static final boolean DEBUG  =
DEBUG_STRING.toLowerCase().equals("true");

I don't know if and how javac/jikes/your_compiler optimizes this and/or if
it is slower than your solution (at run-time) but it works now :-) And you
can use the already-available target if/unless-solution.

Nico




Mime
View raw message