Generics guide for Pallada (IDEA 4.1)
For Aurora (IDEA 4.0) look at GenericsAuroraFAQ
Here is a simple How To Guide to get started with java generics. Please feel free to make any corrections or additions that you think are necessary to make the transition easier.
- use the wizard in IDEA for that. It can be found in the menu Tools/Set Up JSR014 Implementation. We will call the directory where you installed the generics JSR14_HOME.
- As of 2.4, you need to copy the classes of
gjc-rt.jar into collect.jar. Do this with the collect.jar inside IDEA_HOME/lib/generics
Set up an IDEA project
- Open the Settings (Ctrl-Alt-S)
- Select the Paths properties
- In the Paths tab add IDEA_HOME/lib/generics/collect.jar and select java 1.5

- In the Order/Export tab, put collect.jar first (before the JDK)

- Select the Compiler properties
- Select the option Use generics-enabled compiler and enter
-target jsr14 in the _Additional command line arguments

- Restart IDEA
Using JSR Adapter for compiling
- Add a property named
jsr14.home that points to JSR14_HOME<property name="jsr14.home" value="<<JSR14_HOME>>"/>
- Add
collect.jar in first in any compilation classpath
- Download the compiler adapter generously donated by Cortex eBusiness (maker of clover one of the greatest java coverage tool) here or use the cached version here and save it either in your project or your ant install
- Add
jsr14adapter-1.2.jar to your Ant classpath. In IDEA:
- Go to the Ant tool window/Properties
- Add
jsr14adapter-1.2.jar to the Additional Classpath
- Change your
javac target to add the following attributes
<javac destdir="${dir.build.classes}"
source="1.5"
compiler="com.cortexeb.Jsr14CompilerAdapter"
srcdir="${dir.plugin.util.src}:${dir.src}:${dir.additional.src}">
<classpath refid="compile.classpath"/>
</javac>
- Add this to your junit task
<junit fork="yes">
...
<jvmarg value="-Xbootclasspath/p:${jsr14.home}/gjc-rt.jar"/>
</junit>
- You are set
Using standard javac ANT task for compiling
You can compile generics code by javac ANT task:
<javac
fork="yes"
includejavaruntime="yes"
destdir="${project.classes}"
bootclasspath="${generics.home}/collect.jar"
classpathref="project.classpath"
debug="on"
source="1.5"
>
<compilerarg value="-J-Xbootclasspath/p:${generics.home}/gjc-rt.jar"/>
<src path="${project.src}"/>
<include name="**/*.java"/>
</javac>
Using sinjdoc tool for JavaDoc generation
You must have sinjdoc installed.
For generation javadocs you may use follow script:
<fileset dir="${project.src}" id="project.src.java">
<include name="**/*.java" />
</fileset>
<pathconvert pathsep=" " property="project.src.files" refid="project.src.java"/>
<java jar="${sinjdoc.home}/sinjdoc.jar" fork="true">
<jvmarg line="-Xbootclasspath/p:${generics.home}/gjc-rt.jar"/>
<classpath refid="project.classpath" />
<arg value="-protected" />
<arg value="-author" />
<arg value="-version" />
<arg value="-use" />
<arg value="-source" />
<arg value="1.5" />
<arg value="-d" />
<arg value="${project.build}/${project.name}/docs/api" />
<arg value="-sourcepath" />
<arg value="${project.src}" />
<arg line="${project.src.files}" />
</java>
See http://www.intellij.net/tracker/idea/viewSCR?publicId=14522 for more detail.