Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get eclipse to recognize preprocessor statements?

I've managed to get the IDE to compile the java project correctly by modifying the config.ini, but the IDE itself is still showing errors concerning the processor statements:

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

Is there a setting or a plug-in that would solve this?

EDIT: Maybe a little clarification: I'm looking for something that will make the IDE editor more compliant with the code. It won't let me follow any definitions because of what the editor THINKS are errors.

like image 283
Jay Avatar asked Dec 02 '22 06:12

Jay


1 Answers

Using a preprocessor is never necessary (nor advisable) in java. It is far better to configure Subversion (or your favorite source manager) to pull in the correct version of various java files that are unique to each application and to reference platform neutral bridge classes (which extend the correct platform classes brought in via subversion) instead of referencing platform specific classes directly from global classes that are shared by multiple platforms. However, sometimes the need for a java preprocessor is forced upon us due to its extensive use in pre-existing code that is being repurposed. (For example, making a new Android version of an existing Blackberry application.) If you find yourself in that situation, then here is how to use a preprocessor in your java code inside of Eclipse:

Install the Antenna plug-in:

Make sure that you have everything that you've been working on in Eclipse saved.

Go to "Help" in top menu in Eclipse and click on "Install New Software..." option.

Click on the "Add..." button.

Put "Antenna" in the "Name:" edit box and "http://antenna.sf.net/update" in the "Location:" edit box, then click on the "OK" button.

Expanded the "Uncategorized" plugin group, check the checkbox for "Antenna eclipse plugins" (Version 1.1.8), then "click" on the Next button.

Click on the "Finish" button.

If a security warning pops up, then click on the "OK" button.

Make sure that you close any other instances of Eclipse that you have running, then click on the "Yes" button to restart this instance of Eclipse.

Mark the project as processible by Antenna:

Create the project, if needed.

Right click on the project.

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

Make sure the device.xml file used by Antenna is located in the correct folder.

HERE IS AN 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 '"project"/resources' and for Blackberry this is '"project"/res'. (Android only wants Android specific files in the "project"/res folder.)

Set up Antenna for the project:

Select the project by clicking on it.

Go to Project->Properties->Antenna Preprocessor.

If a warning pops up telling you that the device cannot be found, then click on the 'OK' button.

Click the 'Clear' button for 'Optional directory of device database.' combo box if it is not empty. (This must be done even if the correct directory is already showing).

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

Click the 'Clear' button for '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 the device. (For Android this is 'Android' and for Blackberry this is 'Black Berry'.)

Click the 'OK' button.

Antenna will now go thru all of the files in the project and comment ('// @') or uncomment code enclosed by preprocessor commands (must start with '//#') depending upon the settings in the device.xml file.

NOTE: This may cause the java files in the global packages to be marked as out of sync with Subversion. This can cause issues for Subversion if someone else uploads their changes and then you get the changes from head via Subversion. If global java files are marked as out of sync with Subversion due to Antenna, then it is usually best to commit those changes immediately for any of those files that you plan on changing later.

Using Antenna after initial setup for the project: Anytime a file in the project is changed and saved after this Antenna will comment ('// @') or uncomment code enclosed by preprocessor commands (must start with '//#') depending upon the settings in the device.xml file as part of the saving process.

NOTE: The //#preprocess statement at the first line in java files that Blackberry preprocessed will have to be removed since Antenna will have to be used for all java files instead of the Blackberry preprocessor.

NOTE: If the device.xml file is changed, then you will have to set up Antenna for each project that uses the device.xml as described above again for the changes to take effect.

Preprocessor commands and options used by Antenna are explained here: http://antenna.sourceforge.net/wtkpreprocess.php

like image 99
Danny Remington - OMS Avatar answered Dec 28 '22 18:12

Danny Remington - OMS