user1436889
user1436889

Reputation: 63

Is it possible to write code that is ignored by the GWT compiler?

I am looking for a way to write code that is ignored by the GWT compiler. For example certain methods should be ignored since they use classes that are not available in GWT.

Is it possible to flag those methods with some @Attribute magic or to remove the code during compilation? The code will not be accessed anyway when run on the GWT platform but it would be very useful to have it there when this code is run/testes in the JVM.

I know I could write some dummy classes (and actually I am doing that already). Still I am looking for an easier way. Also, for some classes I cannot create dummys since GWT already has this classes like System but only supports a small subset of functionality.

Upvotes: 0

Views: 1227

Answers (2)

David Nouls
David Nouls

Reputation: 1895

Not on a method level. You can filter out specific classes in a source package though:

<source path="client">
  <exclude name="XMLNamespaceContext.java"/>
  <exclude name="XMLUtils.java"/>
  <!-- exclude test classes, they always end with Test.java -->
  <exclude name="**/*Test.java" />
</source>

Upvotes: 2

Adelin
Adelin

Reputation: 18931

I have some classes like you, for example

private DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd");

the SimpleDateFormat class is not a GWT class and it is underlined with red and when i pointit, it says : Class 'java.text.DateFormat' is not present in JRE Emulation Library so it cannot be used in client code however my test run with no problems. here is a picture of my project structure and one of my projects test classes.enter image description here

anyway, anything you declare in the gwt.xml like will check the classes in the declared packages to have a GWT emulation, but your tests runs in JVM environment so you don't care about the classes that do not have GWT emulation. but if you use GWTTestcase things a re different since GWTTestcase fires a browser and put the tests under environment browser. to go around this problem use the MVP patter design. MVP1

MVP2 . wish you luck

Upvotes: 1

Related Questions