KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > ASTProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.javaeditor;
13
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.Assert;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.ISafeRunnable;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.OperationCanceledException;
21 import org.eclipse.core.runtime.Platform;
22 import org.eclipse.core.runtime.SafeRunner;
23 import org.eclipse.core.runtime.Status;
24
25 import org.eclipse.ui.IPartListener2;
26 import org.eclipse.ui.IWindowListener;
27 import org.eclipse.ui.IWorkbenchPart;
28 import org.eclipse.ui.IWorkbenchPartReference;
29 import org.eclipse.ui.IWorkbenchWindow;
30 import org.eclipse.ui.PlatformUI;
31
32 import org.eclipse.jdt.core.IClassFile;
33 import org.eclipse.jdt.core.ICompilationUnit;
34 import org.eclipse.jdt.core.IJavaElement;
35 import org.eclipse.jdt.core.ITypeRoot;
36 import org.eclipse.jdt.core.JavaModelException;
37 import org.eclipse.jdt.core.dom.AST;
38 import org.eclipse.jdt.core.dom.ASTNode;
39 import org.eclipse.jdt.core.dom.ASTParser;
40 import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
41 import org.eclipse.jdt.core.dom.CompilationUnit;
42
43 import org.eclipse.jdt.internal.corext.dom.ASTNodes;
44
45 import org.eclipse.jdt.ui.JavaUI;
46
47 import org.eclipse.jdt.internal.ui.JavaPlugin;
48
49
50 /**
51  * Provides a shared AST for clients. The shared AST is
52  * the AST of the active Java editor's input element.
53  *
54  * @since 3.0
55  */

56 public final class ASTProvider {
57
58     /**
59      * Wait flag.
60      *
61      * @since 3.1
62      */

63     public static final class WAIT_FLAG {
64
65         String JavaDoc fName;
66
67         private WAIT_FLAG(String JavaDoc name) {
68             fName= name;
69         }
70
71         /*
72          * @see java.lang.Object#toString()
73          */

74         public String JavaDoc toString() {
75             return fName;
76         }
77     }
78
79     /**
80      * Wait flag indicating that a client requesting an AST
81      * wants to wait until an AST is ready.
82      * <p>
83      * An AST will be created by this AST provider if the shared
84      * AST is not for the given java element.
85      * </p>
86      *
87      * @since 3.1
88      */

89     public static final WAIT_FLAG WAIT_YES= new WAIT_FLAG("wait yes"); //$NON-NLS-1$
90

91     /**
92      * Wait flag indicating that a client requesting an AST
93      * only wants to wait for the shared AST of the active editor.
94      * <p>
95      * No AST will be created by the AST provider.
96      * </p>
97      *
98      * @since 3.1
99      */

100     public static final WAIT_FLAG WAIT_ACTIVE_ONLY= new WAIT_FLAG("wait active only"); //$NON-NLS-1$
101

102     /**
103      * Wait flag indicating that a client requesting an AST
104      * only wants the already available shared AST.
105      * <p>
106      * No AST will be created by the AST provider.
107      * </p>
108      *
109      * @since 3.1
110      */

111     public static final WAIT_FLAG WAIT_NO= new WAIT_FLAG("don't wait"); //$NON-NLS-1$
112

113
114     /**
115      * Tells whether this class is in debug mode.
116      * @since 3.0
117      */

118     private static final boolean DEBUG= "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.jdt.ui/debug/ASTProvider")); //$NON-NLS-1$//$NON-NLS-2$
119

120
121     /**
122      * Internal activation listener.
123      *
124      * @since 3.0
125      */

126     private class ActivationListener implements IPartListener2, IWindowListener {
127
128
129         /*
130          * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
131          */

132         public void partActivated(IWorkbenchPartReference ref) {
133             if (isJavaEditor(ref) && !isActiveEditor(ref))
134                 activeJavaEditorChanged(ref.getPart(true));
135         }
136
137         /*
138          * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
139          */

140         public void partBroughtToTop(IWorkbenchPartReference ref) {
141             if (isJavaEditor(ref) && !isActiveEditor(ref))
142                 activeJavaEditorChanged(ref.getPart(true));
143         }
144
145         /*
146          * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
147          */

148         public void partClosed(IWorkbenchPartReference ref) {
149             if (isActiveEditor(ref)) {
150                 if (DEBUG)
151                     System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "closed active editor: " + ref.getTitle()); //$NON-NLS-1$ //$NON-NLS-2$
152

153                 activeJavaEditorChanged(null);
154             }
155         }
156
157         /*
158          * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
159          */

160         public void partDeactivated(IWorkbenchPartReference ref) {
161         }
162
163         /*
164          * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
165          */

166         public void partOpened(IWorkbenchPartReference ref) {
167             if (isJavaEditor(ref) && !isActiveEditor(ref))
168                 activeJavaEditorChanged(ref.getPart(true));
169         }
170
171         /*
172          * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
173          */

174         public void partHidden(IWorkbenchPartReference ref) {
175         }
176
177         /*
178          * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
179          */

180         public void partVisible(IWorkbenchPartReference ref) {
181             if (isJavaEditor(ref) && !isActiveEditor(ref))
182                 activeJavaEditorChanged(ref.getPart(true));
183         }
184
185         /*
186          * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
187          */

188         public void partInputChanged(IWorkbenchPartReference ref) {
189             if (isJavaEditor(ref) && isActiveEditor(ref))
190                 activeJavaEditorChanged(ref.getPart(true));
191         }
192
193         /*
194          * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
195          */

196         public void windowActivated(IWorkbenchWindow window) {
197             IWorkbenchPartReference ref= window.getPartService().getActivePartReference();
198             if (isJavaEditor(ref) && !isActiveEditor(ref))
199                 activeJavaEditorChanged(ref.getPart(true));
200         }
201
202         /*
203          * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow)
204          */

205         public void windowDeactivated(IWorkbenchWindow window) {
206         }
207
208         /*
209          * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow)
210          */

211         public void windowClosed(IWorkbenchWindow window) {
212             if (fActiveEditor != null && fActiveEditor.getSite() != null && window == fActiveEditor.getSite().getWorkbenchWindow()) {
213                 if (DEBUG)
214                     System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "closed active editor: " + fActiveEditor.getTitle()); //$NON-NLS-1$ //$NON-NLS-2$
215

216                 activeJavaEditorChanged(null);
217             }
218             window.getPartService().removePartListener(this);
219         }
220
221         /*
222          * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow)
223          */

224         public void windowOpened(IWorkbenchWindow window) {
225             window.getPartService().addPartListener(this);
226         }
227
228         private boolean isActiveEditor(IWorkbenchPartReference ref) {
229             return ref != null && isActiveEditor(ref.getPart(false));
230         }
231
232         private boolean isActiveEditor(IWorkbenchPart part) {
233             return part != null && (part == fActiveEditor);
234         }
235
236         private boolean isJavaEditor(IWorkbenchPartReference ref) {
237             if (ref == null)
238                 return false;
239
240             String JavaDoc id= ref.getId();
241
242             // The instanceof check is not need but helps clients, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=84862
243
return JavaUI.ID_CF_EDITOR.equals(id) || JavaUI.ID_CU_EDITOR.equals(id) || ref.getPart(false) instanceof JavaEditor;
244         }
245     }
246
247     public static final int SHARED_AST_LEVEL= AST.JLS3;
248     public static final boolean SHARED_AST_STATEMENT_RECOVERY= true;
249     public static final boolean SHARED_BINDING_RECOVERY= true;
250
251     private static final String JavaDoc DEBUG_PREFIX= "ASTProvider > "; //$NON-NLS-1$
252

253
254     private IJavaElement fReconcilingJavaElement;
255     private IJavaElement fActiveJavaElement;
256     private CompilationUnit fAST;
257     private ActivationListener fActivationListener;
258     private Object JavaDoc fReconcileLock= new Object JavaDoc();
259     private Object JavaDoc fWaitLock= new Object JavaDoc();
260     private boolean fIsReconciling;
261     private IWorkbenchPart fActiveEditor;
262
263     
264     /**
265      * Returns the Java plug-in's AST provider.
266      *
267      * @return the AST provider
268      * @since 3.2
269      */

270     public static ASTProvider getASTProvider() {
271         return JavaPlugin.getDefault().getASTProvider();
272     }
273     
274     /**
275      * Creates a new AST provider.
276      */

277     public ASTProvider() {
278         install();
279     }
280
281     /**
282      * Installs this AST provider.
283      */

284     void install() {
285         // Create and register activation listener
286
fActivationListener= new ActivationListener();
287         PlatformUI.getWorkbench().addWindowListener(fActivationListener);
288
289         // Ensure existing windows get connected
290
IWorkbenchWindow[] windows= PlatformUI.getWorkbench().getWorkbenchWindows();
291         for (int i= 0, length= windows.length; i < length; i++)
292             windows[i].getPartService().addPartListener(fActivationListener);
293     }
294
295     private void activeJavaEditorChanged(IWorkbenchPart editor) {
296
297         IJavaElement javaElement= null;
298         if (editor instanceof JavaEditor)
299             javaElement= ((JavaEditor)editor).getInputJavaElement();
300
301         synchronized (this) {
302             fActiveEditor= editor;
303             fActiveJavaElement= javaElement;
304             cache(null, javaElement);
305         }
306
307         if (DEBUG)
308             System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "active editor is: " + toString(javaElement)); //$NON-NLS-1$ //$NON-NLS-2$
309

310         synchronized (fReconcileLock) {
311             if (fIsReconciling && (fReconcilingJavaElement == null || !fReconcilingJavaElement.equals(javaElement))) {
312                 fIsReconciling= false;
313                 fReconcilingJavaElement= null;
314             } else if (javaElement == null) {
315                 fIsReconciling= false;
316                 fReconcilingJavaElement= null;
317             }
318         }
319     }
320
321     /**
322      * Returns whether the given compilation unit AST is
323      * cached by this AST provided.
324      *
325      * @param ast the compilation unit AST
326      * @return <code>true</code> if the given AST is the cached one
327      */

328     public boolean isCached(CompilationUnit ast) {
329         return ast != null && fAST == ast;
330     }
331
332     /**
333      * Returns whether this AST provider is active on the given
334      * compilation unit.
335      *
336      * @param cu the compilation unit
337      * @return <code>true</code> if the given compilation unit is the active one
338      * @since 3.1
339      */

340     public boolean isActive(ICompilationUnit cu) {
341         return cu != null && cu.equals(fActiveJavaElement);
342     }
343
344     /**
345      * Informs that reconciling for the given element is about to be started.
346      *
347      * @param javaElement the Java element
348      * @see org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled()
349      */

350     void aboutToBeReconciled(IJavaElement javaElement) {
351
352         if (javaElement == null)
353             return;
354
355         if (DEBUG)
356             System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "about to reconcile: " + toString(javaElement)); //$NON-NLS-1$ //$NON-NLS-2$
357

358         synchronized (fReconcileLock) {
359             fIsReconciling= true;
360             fReconcilingJavaElement= javaElement;
361         }
362         cache(null, javaElement);
363     }
364
365     /**
366      * Disposes the cached AST.
367      */

368     private synchronized void disposeAST() {
369
370         if (fAST == null)
371             return;
372
373         if (DEBUG)
374             System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "disposing AST: " + toString(fAST) + " for: " + toString(fActiveJavaElement)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
375

376         fAST= null;
377
378         cache(null, null);
379     }
380
381     /**
382      * Returns a string for the given Java element used for debugging.
383      *
384      * @param javaElement the compilation unit AST
385      * @return a string used for debugging
386      */

387     private String JavaDoc toString(IJavaElement javaElement) {
388         if (javaElement == null)
389             return "null"; //$NON-NLS-1$
390
else
391             return javaElement.getElementName();
392
393     }
394
395     /**
396      * Returns a string for the given AST used for debugging.
397      *
398      * @param ast the compilation unit AST
399      * @return a string used for debugging
400      */

401     private String JavaDoc toString(CompilationUnit ast) {
402         if (ast == null)
403             return "null"; //$NON-NLS-1$
404

405         List JavaDoc types= ast.types();
406         if (types != null && types.size() > 0)
407             return ((AbstractTypeDeclaration)types.get(0)).getName().getIdentifier();
408         else
409             return "AST without any type"; //$NON-NLS-1$
410
}
411
412     /**
413      * Caches the given compilation unit AST for the given Java element.
414      *
415      * @param ast
416      * @param javaElement
417      */

418     private synchronized void cache(CompilationUnit ast, IJavaElement javaElement) {
419
420         if (fActiveJavaElement != null && !fActiveJavaElement.equals(javaElement)) {
421             if (DEBUG && javaElement != null) // don't report call from disposeAST()
422
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "don't cache AST for inactive: " + toString(javaElement)); //$NON-NLS-1$ //$NON-NLS-2$
423
return;
424         }
425
426         if (DEBUG && (javaElement != null || ast != null)) // don't report call from disposeAST()
427
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "caching AST: " + toString(ast) + " for: " + toString(javaElement)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
428

429         if (fAST != null)
430             disposeAST();
431
432         fAST= ast;
433
434         // Signal AST change
435
synchronized (fWaitLock) {
436             fWaitLock.notifyAll();
437         }
438     }
439
440     /**
441      * Returns a shared compilation unit AST for the given
442      * Java element.
443      * <p>
444      * Clients are not allowed to modify the AST and must
445      * synchronize all access to its nodes.
446      * </p>
447      *
448      * @param je the Java element
449      * @param waitFlag {@link #WAIT_YES}, {@link #WAIT_NO} or {@link #WAIT_ACTIVE_ONLY}
450      * @param progressMonitor the progress monitor or <code>null</code>
451      * @return the AST or <code>null</code> if the AST is not available
452      */

453     public CompilationUnit getAST(IJavaElement je, WAIT_FLAG waitFlag, IProgressMonitor progressMonitor) {
454         if (je == null)
455             return null;
456         
457         Assert.isTrue(je.getElementType() == IJavaElement.CLASS_FILE || je.getElementType() == IJavaElement.COMPILATION_UNIT);
458
459         if (progressMonitor != null && progressMonitor.isCanceled())
460             return null;
461
462         boolean isActiveElement;
463         synchronized (this) {
464             isActiveElement= je.equals(fActiveJavaElement);
465             if (isActiveElement) {
466                 if (fAST != null) {
467                     if (DEBUG)
468                         System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning cached AST:" + toString(fAST) + " for: " + je.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
469

470                     return fAST;
471                 }
472                 if (waitFlag == WAIT_NO) {
473                     if (DEBUG)
474                         System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning null (WAIT_NO) for: " + je.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
475

476                     return null;
477
478                 }
479             }
480         }
481         if (isActiveElement && isReconciling(je)) {
482             try {
483                 final IJavaElement activeElement= fReconcilingJavaElement;
484
485                 // Wait for AST
486
synchronized (fWaitLock) {
487                     if (DEBUG)
488                         System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "waiting for AST for: " + je.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
489

490                     fWaitLock.wait();
491                 }
492
493                 // Check whether active element is still valid
494
synchronized (this) {
495                     if (activeElement == fActiveJavaElement && fAST != null) {
496                         if (DEBUG)
497                             System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "...got AST for: " + je.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
498

499                         return fAST;
500                     }
501                 }
502                 return getAST(je, waitFlag, progressMonitor);
503             } catch (InterruptedException JavaDoc e) {
504                 return null; // thread has been interrupted don't compute AST
505
}
506         } else if (waitFlag == WAIT_NO || (waitFlag == WAIT_ACTIVE_ONLY && !(isActiveElement && fAST == null)))
507             return null;
508
509         if (isActiveElement)
510             aboutToBeReconciled(je);
511
512         CompilationUnit ast= null;
513         try {
514             ast= createAST(je, progressMonitor);
515             if (progressMonitor != null && progressMonitor.isCanceled()) {
516                 ast= null;
517                 if (DEBUG)
518                     System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "Ignore created AST for: " + je.getElementName() + " - operation has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
519
}
520         } finally {
521             if (isActiveElement) {
522                 if (fAST != null) {
523                     if (DEBUG)
524                         System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "Ignore created AST for " + je.getElementName() + " - AST from reconciler is newer"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
525
reconciled(fAST, je, null);
526                 } else
527                     reconciled(ast, je, null);
528             }
529         }
530
531         return ast;
532     }
533
534     /**
535      * Returns a shared compilation unit AST for the given
536      * Java element.
537      * <p>
538      * Clients are not allowed to modify the AST and must
539      * synchronize all access to its nodes.
540      * </p>
541      *
542      * @param je the Java element
543      * @param wait <code>true</code> if the client wants to wait for the result,
544      * <code>null</code> will be returned if the AST is not ready and
545      * the client does not want to wait
546      * @param progressMonitor the progress monitor or <code>null</code>
547      * @return the AST or <code>null</code> if the AST is not available
548      * @deprecated As of 3.1, use {@link #getAST(IJavaElement, WAIT_FLAG, IProgressMonitor)}
549      */

550     public CompilationUnit getAST(IJavaElement je, boolean wait, IProgressMonitor progressMonitor) {
551         if (wait)
552             return getAST(je, WAIT_YES, progressMonitor);
553         else
554             return getAST(je, WAIT_NO, progressMonitor);
555     }
556
557     /**
558      * Tells whether the given Java element is the one
559      * reported as currently being reconciled.
560      *
561      * @param javaElement the Java element
562      * @return <code>true</code> if reported as currently being reconciled
563      */

564     private boolean isReconciling(IJavaElement javaElement) {
565         synchronized (fReconcileLock) {
566             return javaElement != null && javaElement.equals(fReconcilingJavaElement) && fIsReconciling;
567         }
568     }
569
570     /**
571      * Creates a new compilation unit AST.
572      *
573      * @param je the Java element for which to create the AST
574      * @param progressMonitor the progress monitor
575      * @return AST
576      */

577     private CompilationUnit createAST(final IJavaElement je, final IProgressMonitor progressMonitor) {
578         if (!hasSource(je))
579             return null;
580         
581         if (progressMonitor != null && progressMonitor.isCanceled())
582             return null;
583         
584         final ASTParser parser = ASTParser.newParser(SHARED_AST_LEVEL);
585         parser.setResolveBindings(true);
586         parser.setStatementsRecovery(SHARED_AST_STATEMENT_RECOVERY);
587         parser.setBindingsRecovery(SHARED_BINDING_RECOVERY);
588
589         if (progressMonitor != null && progressMonitor.isCanceled())
590             return null;
591         
592         if (je.getElementType() == IJavaElement.COMPILATION_UNIT)
593             parser.setSource((ICompilationUnit)je);
594         else if (je.getElementType() == IJavaElement.CLASS_FILE)
595             parser.setSource((IClassFile)je);
596
597         if (progressMonitor != null && progressMonitor.isCanceled())
598             return null;
599
600         final CompilationUnit root[]= new CompilationUnit[1];
601         
602         SafeRunner.run(new ISafeRunnable() {
603             public void run() {
604                 try {
605                     if (progressMonitor != null && progressMonitor.isCanceled())
606                         return;
607                     if (DEBUG)
608                         System.err.println(getThreadName() + " - " + DEBUG_PREFIX + "creating AST for: " + je.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
609
root[0]= (CompilationUnit)parser.createAST(progressMonitor);
610                 } catch (OperationCanceledException ex) {
611                     return;
612                 }
613             }
614             public void handleException(Throwable JavaDoc ex) {
615                 IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.OK, "Error in JDT Core during AST creation", ex); //$NON-NLS-1$
616
JavaPlugin.getDefault().getLog().log(status);
617             }
618         });
619         
620         // mark as unmodifiable
621
if (root[0] != null)
622             ASTNodes.setFlagsToAST(root[0], ASTNode.PROTECT);
623         
624         return root[0];
625     }
626     
627     /**
628      * Checks whether the given Java element has accessible source.
629      *
630      * @param je the Java element to test
631      * @return <code>true</code> if the element has source
632      * @since 3.2
633      */

634     private boolean hasSource(IJavaElement je) {
635         if (je == null || !je.exists())
636             return false;
637         
638         try {
639             return je instanceof ITypeRoot && ((ITypeRoot)je).getBuffer() != null;
640         } catch (JavaModelException ex) {
641             IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.OK, "Error in JDT Core during AST creation", ex); //$NON-NLS-1$
642
JavaPlugin.getDefault().getLog().log(status);
643         }
644         return false;
645     }
646     
647     /**
648      * Disposes this AST provider.
649      */

650     public void dispose() {
651
652         // Dispose activation listener
653
PlatformUI.getWorkbench().removeWindowListener(fActivationListener);
654         fActivationListener= null;
655
656         disposeAST();
657
658         synchronized (fWaitLock) {
659             fWaitLock.notifyAll();
660         }
661     }
662
663     /*
664      * @see org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#reconciled(org.eclipse.jdt.core.dom.CompilationUnit)
665      */

666     void reconciled(CompilationUnit ast, IJavaElement javaElement, IProgressMonitor progressMonitor) {
667
668         if (DEBUG)
669             System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "reconciled: " + toString(javaElement) + ", AST: " + toString(ast)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
670

671         synchronized (fReconcileLock) {
672
673             fIsReconciling= progressMonitor != null && progressMonitor.isCanceled();
674             if (javaElement == null || !javaElement.equals(fReconcilingJavaElement)) {
675
676                 if (DEBUG)
677                     System.out.println(getThreadName() + " - " + DEBUG_PREFIX + " ignoring AST of out-dated editor"); //$NON-NLS-1$ //$NON-NLS-2$
678

679                 // Signal - threads might wait for wrong element
680
synchronized (fWaitLock) {
681                     fWaitLock.notifyAll();
682                 }
683
684                 return;
685             }
686
687             cache(ast, javaElement);
688         }
689     }
690
691     private String JavaDoc getThreadName() {
692         String JavaDoc name= Thread.currentThread().getName();
693         if (name != null)
694             return name;
695         else
696             return Thread.currentThread().toString();
697     }
698     
699 }
700
701
Popular Tags