IntelliJ Community . GenericsAuroraFAQ

 
GenericsAuroraFAQ 

HOME INDEX SEARCH CHANGES GO  

This is the generics guide for Aurora. For Pallada (IDEA 4.1) look at GenericsFAQ

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.

Installation

  1. Download the Early Access JSR14 prototype from here
  2. Extract it anywhere. We will call JSR14_HOME that directory
  3. As of 2.4, you need to copy the classes of gjc-rt.jar into collect.jar
  4. Copy JSR14_HOME/collect.jar and JSR14_HOME/gjc-rt.jar to IDEA_HOME/lib/generics (you have to create the directory)

Alternatively use the wizard in IDEA for that. It can be found in the menu Tools/Set Up JSR014 Implementation. However don't forget to do step 3.

Set up an IDEA project

  1. Open the Project Properties
  2. Select the Main Module properties
  3. In the Library tab add IDEA_HOME/lib/generics/collect.jar
     
    ProjectPropertiesMainModuleLibrariesTab.jpg
     
  4. In the Order tab, put collect.jar first (before the JDK)
     
    ProjectPropertiesMainModuleOrderTab.jpg
     
  5. Select the Compiler properties
  6. Select the option Use generics-enabled compiler
     
    ProjectPropertiesCompiler.jpg
     
  7. Restart IDEA

Set up Ant

Using JSR Adapter for compiling

  1. Add a property named jsr14.home that points to JSR14_HOME
    <property name="jsr14.home" value="<<JSR14_HOME>>"/>
  2. Add collect.jar in first in any compilation classpath
  3. 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
  4. Add jsr14adapter-1.2.jar to your Ant classpath. In IDEA:
    1. Go to the Ant tool window/Properties
       
      AntToolWindowProperties.jpg
       
    2. Add jsr14adapter-1.2.jar to the Additional Classpath
       
      AntToolWindowPropertiesClasspath.jpg
       
  5. 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>
  6. Add this to your junit task
    <junit fork="yes">
    ...
    <jvmarg value="-Xbootclasspath/p:${jsr14.home}/gjc-rt.jar"/> </junit>
  7. 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>

Tips

General info on java 1.5 generics support

javadoc and javap for generics

Known issues

OutOfMemoryError using Generics

See http://www.intellij.net/tracker/idea/viewSCR?publicId=14522 for more detail.

Attachment: sort Action: Size: Date: Who: Comment:
jsr14adapter-1.2.jar action 2078 01 Sep 2003 - 04:29 JacquesMorel Cortex eBusiness Ant Compiler Adapter to generics

e d i t a t t a c h r e f - b y d i f f s m o r e
Have ideas, requests, problems regarding this site? Send feedback.
Copyright © 2000-2003 by the contributing authors. All materials at intellij.org are the property of the contributing authors.