United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-5048539 apt needs a listener mechanism
JDK-5048539 : apt needs a listener mechanism

Details
Type:
Bug
Submit Date:
2004-05-17
Status:
Resolved
Updated Date:
2004-07-16
Project Name:
JDK
Resolved Date:
2004-07-16
Component:
tools
OS:
generic
Sub-Component:
apt
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
5.0 (b59)

Related Reports
Relates:
Relates:
Relates:
Relates:

Sub Tasks

Description
Feedback from internal and external apt uses has revealed the need for a listener mechanism to let processors/factories know when annotation processing is finished so the trailing bits of files can be written, etc.

                                    

Comments
EVALUATION

Should be fixed.

###@###.### 2004-05-17
                                     
2004-05-17
SUGGESTED FIX

New files:
src/share/classes/com/sun/mirror/apt/AnnotationProcessorListener.java
src/share/classes/com/sun/mirror/apt/RoundCompleteListener.java
src/share/classes/com/sun/mirror/apt/RoundCompleteEvent.java
src/share/classes/com/sun/mirror/apt/RoundState.java
src/share/classes/com/sun/tools/apt/mirror/apt/RoundStateImpl.java
src/share/classes/com/sun/tools/apt/mirror/apt/RoundCompleteEventImpl.java

Modified files:

src/share/classes/com/sun/mirror/apt>sccs sccsdiff -r1.5 -r1.6 AnnotationProcessorEnvironment.java

------- AnnotationProcessorEnvironment.java -------
141a142,160
> 
>     /**
>      * Add a listener.  If the listener is currently registered to listen,
>      * adding it again will have no effect.
>      *
>      * @param listener The listener to add.
>      * @throws NullPointerException if the listener is null
>      */
>     void addListener(AnnotationProcessorListener listener);
>  
>  
>     /**
>      * Remove a listener.  If the listener is not currently listening,
>      * the method call does nothing.
>      *
>      * @param listener The listener to remove.
>      * @throws NullPointerException if the listener is null
>      */
>     void removeListener(AnnotationProcessorListener listener);



src/share/classes/com/sun/tools/apt/mirror/apt>sccs sccsdiff -r1.9 -r1.10 AnnotationProcessorEnvironmentImpl.javaa

------- AnnotationProcessorEnvironmentImpl.java -------
15a16
> import com.sun.tools.apt.util.Bark;
19a21,22
> import com.sun.tools.apt.mirror.apt.RoundStateImpl;
> import com.sun.tools.apt.mirror.apt.RoundCompleteEventImpl;
38,39c41,44
<     Filer filer;
< 
---
>     FilerImpl filer;
>     Bark bark;
>     Set<RoundCompleteListener> roundCompleteListeners;
> 
54a60,61
>       bark = Bark.instance(context);
>       roundCompleteListeners = new LinkedHashSet<RoundCompleteListener>();
69,72d75
< //    public Collection<PackageDeclaration> getSpecifiedPackages() {
< //    throw new UnsupportedOperationException();
< //    }
< 
134a138,164
> 
>     public void addListener(AnnotationProcessorListener listener) {
>       if (listener == null)
>           throw new NullPointerException();
>       else {
>           if (listener instanceof RoundCompleteListener)
>               roundCompleteListeners.add((RoundCompleteListener)listener);
>       }
>     }
>  
>     public void removeListener(AnnotationProcessorListener listener) {
>       if (listener == null)
>           throw new NullPointerException();
>       else
>           roundCompleteListeners.remove(listener);
>     }
> 
>     public void roundComplete() {
>       RoundState roundState  = new RoundStateImpl(bark.nerrors > 0, 
>                                                   filer.getSourceFileNames().size() > 0,
>                                                   filer.getClassFileNames().size() > 0);
>       RoundCompleteEvent roundCompleteEvent = new RoundCompleteEventImpl(this, roundState);
> 
>       filer.roundOver();
>       for(RoundCompleteListener rcl: roundCompleteListeners)
>           rcl.roundComplete(roundCompleteEvent);
>     }


src/share/classes/com/sun/tools/apt/mirror/apt>sccs sccsdiff -r1.5 -r1.6 FilerImpl.java       

------- FilerImpl.java -------
56a57,64
>     // Names of newly created source files
>     private HashSet<String> sourceFileNames = new HashSet<String>();
> 
>     // Names of newly created class files
>     private HashSet<String> classFileNames  = new HashSet<String>();
> 
>     private boolean roundOver;
> 
80c88
< 
---
>       roundOver = false;
204,208d211
< 
< 
<     private HashSet<String> sourceFileNames = new HashSet<String>();
<     private HashSet<String> classFileNames = new HashSet<String>();
< 
216a220,223
>     public void roundOver() {
>       roundOver = true;
>     }
> 
218,220c225,227
<      * Checks that the file has not already been created during this run.
<      * If not, creates intermediate directories, and deletes the file if
<      * it already exists.
---
>      * Checks that the file has not already been created during this
>      * invocation.  If not, creates intermediate directories, and
>      * deletes the file if it already exists.
222a230,233
>       if (roundOver) {
>           bark.warning(Position.NOPOS, "NoNewFilesAfterRound", file.toString());
>           throw new IOException();
>       }


src/share/classes/com/sun/tools/apt/comp>sccs sccsdiff -r1.14 -r1.15 Apt.java       

------- Apt.java -------
205c205
<       AnnotationProcessorEnvironment trivAPE =
---
>       AnnotationProcessorEnvironmentImpl trivAPE =
408a409,411
>           // Invoke listener callback mechanism
>           trivAPE.roundComplete();
> 


src/share/classes/com/sun/tools/apt/resources>sccs sccsdiff -r1.5 -r1.6 apt.properties

------- apt.properties -------
122a123,125
> apt.warn.NoNewFilesAfterRound=>     Cannot create file ''{0}'' after a round has ended.
> 


###@###.### 2004-06-25
                                     
2004-06-25
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger-rc

FIXED IN:
tiger-rc

INTEGRATED IN:
tiger-b59
tiger-rc


                                     
2004-08-03



Hardware and Software, Engineered to Work Together