KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > JavaCompositeReconcilingStrategy


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 package org.eclipse.jdt.internal.ui.text;
12
13 import org.eclipse.jface.text.IRegion;
14 import org.eclipse.jface.text.reconciler.DirtyRegion;
15 import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
16 import org.eclipse.jface.text.source.IAnnotationModel;
17 import org.eclipse.jface.text.source.ISourceViewer;
18
19 import org.eclipse.ui.texteditor.IDocumentProvider;
20 import org.eclipse.ui.texteditor.ITextEditor;
21
22 import org.eclipse.jdt.internal.ui.JavaPlugin;
23 import org.eclipse.jdt.internal.ui.text.java.IProblemRequestorExtension;
24 import org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy;
25 import org.eclipse.jdt.internal.ui.text.spelling.JavaSpellingReconcileStrategy;
26
27 /**
28  * Reconciling strategy for Java code. This is a composite strategy containing the
29  * regular java model reconciler and the comment spelling strategy.
30  *
31  * @since 3.0
32  */

33 public class JavaCompositeReconcilingStrategy extends CompositeReconcilingStrategy {
34
35     private ITextEditor fEditor;
36     private JavaReconcilingStrategy fJavaStrategy;
37
38     /**
39      * Creates a new Java reconciling strategy.
40      *
41      * @param viewer the source viewer
42      * @param editor the editor of the strategy's reconciler
43      * @param documentPartitioning the document partitioning this strategy uses for configuration
44      */

45     public JavaCompositeReconcilingStrategy(ISourceViewer viewer, ITextEditor editor, String JavaDoc documentPartitioning) {
46         fEditor= editor;
47         fJavaStrategy= new JavaReconcilingStrategy(editor);
48         setReconcilingStrategies(new IReconcilingStrategy[] {
49             fJavaStrategy,
50             new JavaSpellingReconcileStrategy(viewer, editor)
51         });
52     }
53
54     /**
55      * Returns the problem requestor for the editor's input element.
56      *
57      * @return the problem requestor for the editor's input element
58      */

59     private IProblemRequestorExtension getProblemRequestorExtension() {
60         IDocumentProvider p= fEditor.getDocumentProvider();
61         if (p == null) {
62             // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=51522
63
p= JavaPlugin.getDefault().getCompilationUnitDocumentProvider();
64         }
65         IAnnotationModel m= p.getAnnotationModel(fEditor.getEditorInput());
66         if (m instanceof IProblemRequestorExtension)
67             return (IProblemRequestorExtension) m;
68         return null;
69     }
70
71     /*
72      * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
73      */

74     public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
75         IProblemRequestorExtension e= getProblemRequestorExtension();
76         if (e != null) {
77             try {
78                 e.beginReportingSequence();
79                 super.reconcile(dirtyRegion, subRegion);
80             } finally {
81                 e.endReportingSequence();
82             }
83         } else {
84             super.reconcile(dirtyRegion, subRegion);
85         }
86     }
87
88     /*
89      * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
90      */

91     public void reconcile(IRegion partition) {
92         IProblemRequestorExtension e= getProblemRequestorExtension();
93         if (e != null) {
94             try {
95                 e.beginReportingSequence();
96                 super.reconcile(partition);
97             } finally {
98                 e.endReportingSequence();
99             }
100         } else {
101             super.reconcile(partition);
102         }
103     }
104
105     /**
106      * Tells this strategy whether to inform its listeners.
107      *
108      * @param notify <code>true</code> if listeners should be notified
109      */

110     public void notifyListeners(boolean notify) {
111         fJavaStrategy.notifyListeners(notify);
112     }
113
114     /*
115      * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#initialReconcile()
116      */

117     public void initialReconcile() {
118         IProblemRequestorExtension e= getProblemRequestorExtension();
119         if (e != null) {
120             try {
121                 e.beginReportingSequence();
122                 super.initialReconcile();
123             } finally {
124                 e.endReportingSequence();
125             }
126         } else {
127             super.initialReconcile();
128         }
129     }
130
131     /**
132      * Called before reconciling is started.
133      *
134      * @since 3.0
135      */

136     public void aboutToBeReconciled() {
137         fJavaStrategy.aboutToBeReconciled();
138
139     }
140 }
141
Popular Tags