|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| JavadocEventNotifier.java | - | 25% | 25% | 25% |
|
||||||||||||||
| 1 | /*BEGIN_COPYRIGHT_BLOCK | |
| 2 | * | |
| 3 | * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu) | |
| 4 | * All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * * Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * * Redistributions in binary form must reproduce the above copyright | |
| 11 | * notice, this list of conditions and the following disclaimer in the | |
| 12 | * documentation and/or other materials provided with the distribution. | |
| 13 | * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the | |
| 14 | * names of its contributors may be used to endorse or promote products | |
| 15 | * derived from this software without specific prior written permission. | |
| 16 | * | |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
| 21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 | * | |
| 29 | * This software is Open Source Initiative approved Open Source Software. | |
| 30 | * Open Source Initative Approved is a trademark of the Open Source Initiative. | |
| 31 | * | |
| 32 | * This file is part of DrJava. Download the current version of this project | |
| 33 | * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/ | |
| 34 | * | |
| 35 | * END_COPYRIGHT_BLOCK*/ | |
| 36 | ||
| 37 | package edu.rice.cs.drjava.model.javadoc; | |
| 38 | ||
| 39 | import java.io.File; | |
| 40 | import edu.rice.cs.drjava.model.EventNotifier; | |
| 41 | import edu.rice.cs.drjava.model.compiler.CompilerListener; | |
| 42 | ||
| 43 | /** | |
| 44 | * Keeps track of all listeners to a JavadocModel, and has the ability | |
| 45 | * to notify them of some event. | |
| 46 | * <p> | |
| 47 | * | |
| 48 | * This class has a specific role of managing JavadocListeners. Other | |
| 49 | * classes with similar names use similar code to perform the same function for | |
| 50 | * other interfaces, e.g. InteractionsEventNotifier and GlobalEventNotifier. | |
| 51 | * These classes implement the appropriate interface definition so that they | |
| 52 | * can be used transparently as composite packaging for a particular listener | |
| 53 | * interface. | |
| 54 | * <p> | |
| 55 | * | |
| 56 | * Components which might otherwise manage their own list of listeners use | |
| 57 | * EventNotifiers instead to simplify their internal implementation. Notifiers | |
| 58 | * should therefore be considered a private implementation detail of the | |
| 59 | * components, and should not be used directly outside of the "host" component. | |
| 60 | * <p> | |
| 61 | * | |
| 62 | * All methods in this class must use the synchronization methods | |
| 63 | * provided by ReaderWriterLock. This ensures that multiple notifications | |
| 64 | * (reads) can occur simultaneously, but only one thread can be adding | |
| 65 | * or removing listeners (writing) at a time, and no reads can occur | |
| 66 | * during a write. | |
| 67 | * <p> | |
| 68 | * | |
| 69 | * <i>No</i> methods on this class should be synchronized using traditional | |
| 70 | * Java synchronization! | |
| 71 | * <p> | |
| 72 | * | |
| 73 | * @version $Id: JavadocEventNotifier.java 5236 2010-04-27 01:43:36Z mgricken $ | |
| 74 | */ | |
| 75 | class JavadocEventNotifier extends EventNotifier<JavadocListener> | |
| 76 | implements JavadocListener { | |
| 77 | ||
| 78 | /** Called after Javadoc is started by the GlobalModel. */ | |
| 79 | 0 | public void javadocStarted() { |
| 80 | 0 | _lock.startRead(); |
| 81 | 0 | try { for (JavadocListener jl: _listeners) { jl.javadocStarted(); } } |
| 82 | 0 | finally { _lock.endRead(); } |
| 83 | } | |
| 84 | ||
| 85 | /** Called after Javadoc is finished. | |
| 86 | * @param success whether the Javadoc operation generated proper output | |
| 87 | * @param destDir if (success == true) the location where the output was generated, otherwise undefined (null?) | |
| 88 | * @param allDocs Whether Javadoc was run for all open documents | |
| 89 | */ | |
| 90 | 0 | public void javadocEnded(boolean success, File destDir, boolean allDocs) { |
| 91 | 0 | _lock.startRead(); |
| 92 | 0 | try { for (JavadocListener jl: _listeners) { jl.javadocEnded(success, destDir, allDocs); } } |
| 93 | 0 | finally { _lock.endRead();} |
| 94 | } | |
| 95 | ||
| 96 | /** Asks the user if all files should be saved before running javadoc (assuming the proper listener has been | |
| 97 | * installed). Does not continue with javadoc if the user fails to save! | |
| 98 | */ | |
| 99 | 1 | public void saveBeforeJavadoc() { |
| 100 | 1 | _lock.startRead(); |
| 101 | 1 | try { for (JavadocListener jl: _listeners) { jl.saveBeforeJavadoc(); } } |
| 102 | 1 | finally { _lock.endRead(); } |
| 103 | } | |
| 104 | ||
| 105 | /** Asks the user if all files should be compiled before running javadoc (assuming the proper listener has been | |
| 106 | * installed). Does not continue with javadoc if the user fails to save! | |
| 107 | */ | |
| 108 | 0 | public void compileBeforeJavadoc(final CompilerListener afterCompile) { |
| 109 | 0 | _lock.startRead(); |
| 110 | 0 | try { for (JavadocListener jl: _listeners) { jl.compileBeforeJavadoc(afterCompile); } } |
| 111 | 0 | finally { _lock.endRead(); } |
| 112 | } | |
| 113 | } | |
| 114 |
|
||||||||||