|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| CompilerEventNotifier.java | - | 66.7% | 66.7% | 66.7% |
|
||||||||||||||
| 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.compiler; | |
| 38 | ||
| 39 | import java.io.File; | |
| 40 | import java.util.List; | |
| 41 | ||
| 42 | import edu.rice.cs.drjava.model.EventNotifier; | |
| 43 | ||
| 44 | import static edu.rice.cs.plt.debug.DebugUtil.debug; | |
| 45 | ||
| 46 | /** | |
| 47 | * Keeps track of all listeners to a CompilerModel, and has the ability | |
| 48 | * to notify them of some event. | |
| 49 | * <p> | |
| 50 | * | |
| 51 | * This class has a specific role of managing CompilerListeners. Other | |
| 52 | * classes with similar names use similar code to perform the same function for | |
| 53 | * other interfaces, e.g. InteractionsEventNotifier and GlobalEventNotifier. | |
| 54 | * These classes implement the appropriate interface definition so that they | |
| 55 | * can be used transparently as composite packaging for a particular listener | |
| 56 | * interface. | |
| 57 | * <p> | |
| 58 | * | |
| 59 | * Components which might otherwise manage their own list of listeners use | |
| 60 | * EventNotifiers instead to simplify their internal implementation. Notifiers | |
| 61 | * should therefore be considered a private implementation detail of the | |
| 62 | * components, and should not be used directly outside of the "host" component. | |
| 63 | * <p> | |
| 64 | * | |
| 65 | * All methods in this class must use the synchronization methods | |
| 66 | * provided by ReaderWriterLock. This ensures that multiple notifications | |
| 67 | * (reads) can occur simultaneously, but only one thread can be adding | |
| 68 | * or removing listeners (writing) at a time, and no reads can occur | |
| 69 | * during a write. | |
| 70 | * <p> | |
| 71 | * | |
| 72 | * <i>No</i> methods on this class should be synchronized using traditional | |
| 73 | * Java synchronization! | |
| 74 | * <p> | |
| 75 | * | |
| 76 | * @version $Id: CompilerEventNotifier.java 5236 2010-04-27 01:43:36Z mgricken $ | |
| 77 | */ | |
| 78 | class CompilerEventNotifier extends EventNotifier<CompilerListener> implements CompilerListener { | |
| 79 | ||
| 80 | /** Called after a compile is started by the GlobalModel. */ | |
| 81 | 57 | public void compileStarted() { |
| 82 | // new ScrollableDialog(null, "CompilerEventNotifier.compileStarted() called for listeners " + _listeners, "", "").show(); | |
| 83 | 57 | _lock.startRead(); |
| 84 | 117 | try { for (CompilerListener cl : _listeners) { cl.compileStarted(); } } |
| 85 | 57 | finally { _lock.endRead(); } |
| 86 | } | |
| 87 | ||
| 88 | /** Called when a compile has finished running. */ | |
| 89 | 57 | public void compileEnded(File workDir, List<? extends File> excludedFiles) { |
| 90 | 57 | _lock.startRead(); |
| 91 | 117 | try { for (CompilerListener cl : _listeners) { cl.compileEnded(workDir, excludedFiles); } } |
| 92 | 57 | finally { _lock.endRead(); } |
| 93 | } | |
| 94 | ||
| 95 | /** Called if the compile cannot be performed. By default, the Exception is an UnexpectedException containing an | |
| 96 | * explanatory message. | |
| 97 | */ | |
| 98 | 2 | public void compileAborted(Exception e) { |
| 99 | 2 | _lock.startRead(); |
| 100 | 4 | try { for (CompilerListener cl : _listeners) { cl.compileAborted(e); } } |
| 101 | 2 | finally { _lock.endRead(); } |
| 102 | } | |
| 103 | ||
| 104 | /** Called when files are saved before compiling. It is up to the caller of this method to check if the | |
| 105 | * documents have been saved, using IGetDocuments.hasModifiedDocuments(). | |
| 106 | */ | |
| 107 | 6 | public void saveBeforeCompile() { |
| 108 | 6 | _lock.startRead(); |
| 109 | 14 | try { for (CompilerListener cl : _listeners) { cl.saveBeforeCompile(); } } |
| 110 | 6 | finally { _lock.endRead(); } |
| 111 | } | |
| 112 | ||
| 113 | /** Called when files are saved before compiling. It is up to the caller of this method to check if the | |
| 114 | * documents have been saved, using IGetDocuments.hasModifiedDocuments(). | |
| 115 | */ | |
| 116 | 0 | public void saveUntitled() { |
| 117 | 0 | _lock.startRead(); |
| 118 | 0 | try { for (CompilerListener cl : _listeners) { cl.saveUntitled(); } } |
| 119 | 0 | finally { _lock.endRead(); } |
| 120 | } | |
| 121 | ||
| 122 | /** Called after the active compiler has been changed. */ | |
| 123 | 0 | public void activeCompilerChanged() { |
| 124 | // new ScrollableDialog(null, "CompilerEventNotifier.compileStarted() called for listeners " + _listeners, "", "").show(); | |
| 125 | 0 | _lock.startRead(); |
| 126 | 0 | try { for (CompilerListener cl : _listeners) { cl.activeCompilerChanged(); } } |
| 127 | 0 | finally { _lock.endRead(); } |
| 128 | } | |
| 129 | } |
|
||||||||||