]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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.spelling; | |
12 | ||
13 | import org.eclipse.core.runtime.AssertionFailedException; | |
14 | import org.eclipse.core.runtime.IProgressMonitor; | |
15 | ||
16 | import org.eclipse.jface.text.BadLocationException; | |
17 | import org.eclipse.jface.text.IDocument; | |
18 | import org.eclipse.jface.text.IRegion; | |
19 | import org.eclipse.jface.text.ITypedRegion; | |
20 | import org.eclipse.jface.text.TextUtilities; | |
21 | ||
22 | import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector; | |
23 | ||
24 | import org.eclipse.jdt.ui.PreferenceConstants; | |
25 | import org.eclipse.jdt.ui.text.IJavaPartitions; | |
26 | ||
27 | import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellChecker; | |
28 | ||
29 | ||
30 | /** | |
31 | * Java spelling engine | |
32 | * | |
33 | * @since 3.1 | |
34 | */ | |
35 | public class JavaSpellingEngine extends SpellingEngine { | |
36 | ||
37 | ||
38 | /* | |
39 | * @see org.eclipse.jdt.internal.ui.text.spelling.SpellingEngine#check(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IRegion[], org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellChecker, org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector, org.eclipse.core.runtime.IProgressMonitor) | |
40 | */ | |
41 | @Override | |
42 | protected void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor) { | |
43 | SpellEventListener listener= new SpellEventListener(collector, document); | |
44 | boolean isIgnoringJavaStrings= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.SPELLING_IGNORE_JAVA_STRINGS); | |
45 | try { | |
46 | for (int i= 0; i < regions.length; i++) { | |
47 | IRegion region= regions[i]; | |
48 | ITypedRegion[] partitions= TextUtilities.computePartitioning(document, IJavaPartitions.JAVA_PARTITIONING, region.getOffset(), region.getLength(), false); | |
49 | for (int index= 0; index < partitions.length; index++) { | |
50 | if (monitor != null && monitor.isCanceled()) | |
51 | return; | |
52 | ||
53 | if (listener.isProblemsThresholdReached()) | |
54 | return; | |
55 | ||
56 | ITypedRegion partition= partitions[index]; | |
57 | final String type= partition.getType(); | |
58 | ||
59 | if (isIgnoringJavaStrings && type.equals(IJavaPartitions.JAVA_STRING)) | |
60 | continue; | |
61 | ||
62 | if (!type.equals(IDocument.DEFAULT_CONTENT_TYPE) && !type.equals(IJavaPartitions.JAVA_CHARACTER)) | |
63 | checker.execute(listener, new SpellCheckIterator(document, partition, checker.getLocale())); | |
64 | } | |
65 | } | |
66 | } catch (BadLocationException x) { | |
67 | // ignore: the document has been changed in another thread and will be checked again | |
68 | } catch (AssertionFailedException x) { | |
69 | // ignore: the document has been changed in another thread and will be checked again | |
70 | } | |
71 | } | |
72 | } |