How to make eclipse recognize preprocessor instructions?

I managed to get the IDE to compile the java project correctly by modifying config.ini, but the IDE itself still shows errors regarding processor statements:

//#ifdef VER_X public class Video extends FirstCanvas { //#else public class Video extends SecondCanvas { //#endif ... 

Is there a setting or plugin that would allow this?

EDIT: Maybe a little clarification: I'm looking for something that will make the IDE editor more compatible with the code. It will not allow me to follow any definitions because the THINKS editor is a mistake.

+4
source share
3 answers

A more OO approach to this would be to use separate classes, choosing between them at runtime:

 public class FirstVideo extends FirstCanvas { ... } public class SecondVideo extends SecondCanvas { ... } ... video = (something ? new FirstVideo() : new SecondVideo()); 

It does not require non-standard compilation steps to achieve and does not open the door to the horrors of eldritch C / C ++ preprocessor directives.

+2
source

Using a preprocessor is never necessary (and not recommended) in java. It is much better to configure Subversion (or your favorite source manager) to display the correct version of various java files that are unique to each application and refer to the platform neutral bridge classes (which extend the correct platform classes provided through subversion) instead of binding platform-specific classes directly from global classes that are shared across multiple platforms. However, sometimes the need for a Java preprocessor is imposed on us because of its widespread use in existing code, which is repurposed. (For example, creating a new Android version of an existing Blackberry application.) If you find that in this situation, here's how to use the preprocessor in your Java code inside Eclipse:

Install the Antenna plugin:

Make sure you have everything you worked on in Eclipse.

Go to "Help" in the top menu of Eclipse and click "Install New Software ...".

Click the "Add ..." button.

Place the “Antenna” in the “Name:” field and “ http://antenna.sf.net/update ” in the “Location:” edit box, then click the “OK” button.

The group of plugins "Uncategorized" is expanded, check the box "Antenna eclipse plugins" (Version 1.1.8), then click on the "Next" button.

Click the Finish button.

If a security warning appears, click OK.

Make sure you close all other Eclipse instances that you are running, then click Yes to restart this Eclipse instance.

Mark project as processed by Antenna:

Create a project if necessary.

Right click on the project.

Click the "Antenna Preprocessor" button located about three quarters down in the pop-up menu if it does not already have a check mark next to it.

Ensure that the device.xml file used by Antenna is in the correct folder.

HERE EXAMPLE device.xml FILE:

 <?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?> <devices> <device supportsPolishGui="true"> <capability name="android" value="true" /> <capability name="sqlite" value="true" /> <identifier>Android</identifier> <features>isVirtual</features> <groups>XT</groups> </device> </devices> 

For Android, this is a “project” / resources, and for Blackberry this is a “project” / res. (Android only wants certain Android files in the "project" / res folder.)

Antenna settings for the project:

Select a project by clicking on it.

Go to Project-> Properties-> Antenna Preprocessor.

If a warning appears that the device was not found, click OK.

Click the "Clear" button for "Optional device database directory." if it is not empty. (This must be done even if the correct directory is already displayed).

Click the Browse button and select the folder where device.xml is located. (For Android, this is the / resources project, and for Blackberry, this is the / res project.)

Click the "Clear" button for the "Device Name" combo box if it is not empty. (This must be done even if the correct device is already showing.)

Click the Search button and select a device. (For Android, it's “Android,” and for Blackberry, it's “Black Berry.”)

Click OK.

The antenna will now go through all the files in the project and comment ('// @') or uncomment the code enclosed in the preprocessor commands (should start with "// #") depending on the settings in the device.xml file.

NOTE. . This can cause java files in global packages to be marked as unsynchronized with Subversion. This can cause problems for Subversion if someone else uploads their changes and then you get the changes from the head through Subversion. If global java files are marked as unsynchronized with Subversion due to the Antenna, then it is usually best to immediately commit these changes to any of those files that you plan to change later.

Using Antennas after initial setup for a project: Anytime a file in a project changes and is saved after this Antenna comments ('// @') or uncomments the code enclosed in preprocessor commands (must start with '// # ') depending on the settings in the device.xml file as part of the save process.

NOTE. . The # # preprocess operator in the first line in java files that must be pre-processed by Blackberry must be deleted, since the Antenna should be used for all java files, and not for the Blackberry preprocessor.

Note: If the device.xml file is modified, you will need to configure the Antenna for each project that uses device.xml, as described above, for the changes to take effect.

The preprocessor commands and options used by the Antenna are described here: http://antenna.sourceforge.net/wtkpreprocess.php

+15
source

I do not agree, precompiler directives can be very useful from a security point of view. It is never recommended that you leave debugging code in the product that is coming out. This is because everyone can start checking memory and changing things, and all of a sudden, the internal workings of your code exist to be verified by an attacker. But removing debug code makes it difficult to find problems along the way. The ability of #ifdef to output debugging code so that it never fits in the release bank would be extremely useful.

Speaking of this, you cannot do it in Java.

Charles.

+1
source

All Articles