]>
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 | ||
12 | package org.eclipse.jdt.internal.ui.text.spelling; | |
13 | ||
14 | import java.util.ArrayList; | |
15 | import java.util.Arrays; | |
16 | import java.util.List; | |
17 | ||
18 | import org.eclipse.core.runtime.AssertionFailedException; | |
19 | import org.eclipse.core.runtime.IProgressMonitor; | |
20 | ||
21 | import org.eclipse.jface.text.BadLocationException; | |
22 | import org.eclipse.jface.text.IDocument; | |
23 | import org.eclipse.jface.text.IRegion; | |
24 | import org.eclipse.jface.text.ITypedRegion; | |
25 | import org.eclipse.jface.text.TextUtilities; | |
26 | ||
27 | import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector; | |
28 | ||
29 | import org.eclipse.jdt.ui.PreferenceConstants; | |
30 | ||
31 | import org.eclipse.jdt.internal.ui.JavaPlugin; | |
32 | import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions; | |
33 | import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellChecker; | |
34 | ||
35 | /** | |
36 | * Properties file spelling engine | |
37 | * | |
38 | * @since 3.1 | |
39 | */ | |
40 | public class PropertiesFileSpellingEngine extends SpellingEngine { | |
41 | ||
42 | /* | |
43 | * @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) | |
44 | */ | |
45 | @Override | |
46 | protected void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor) { | |
47 | SpellEventListener listener= new SpellEventListener(collector, document); | |
48 | boolean isIgnoringAmpersand= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.SPELLING_IGNORE_AMPERSAND_IN_PROPERTIES); | |
49 | try { | |
50 | List<ITypedRegion> partitionList= new ArrayList<ITypedRegion>(); | |
51 | for (int i= 0; i < regions.length; i++) | |
52 | partitionList.addAll(Arrays.asList(TextUtilities.computePartitioning(document, IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, regions[i].getOffset(), regions[i].getLength(), false))); | |
53 | ITypedRegion[] partitions= partitionList.toArray(new ITypedRegion[partitionList.size()]); | |
54 | ||
55 | for (int i= 0; i < partitions.length; i++) { | |
56 | if (monitor != null && monitor.isCanceled()) | |
57 | return; | |
58 | if (listener.isProblemsThresholdReached()) | |
59 | return; | |
60 | ||
61 | ITypedRegion partition= partitions[i]; | |
62 | i= listener.generated_8570212357192355589(document, checker, this, isIgnoringAmpersand, partitions, i, partition); | |
63 | } | |
64 | } catch (BadLocationException x) { | |
65 | // ignore: the document has been changed in another thread and will be checked again | |
66 | } catch (AssertionFailedException x) { | |
67 | // ignore: the document has been changed in another thread and will be checked again | |
68 | } | |
69 | } | |
70 | ||
71 | /** | |
72 | * Returns <code>true</code> iff the given region contains only | |
73 | * whitespace. | |
74 | * | |
75 | * @param document the document | |
76 | * @param offset the region's offset | |
77 | * @param length the region's length | |
78 | * @return <code>true</code> iff the given region contains only | |
79 | * whitespace | |
80 | */ | |
81 | boolean isWhitespace(IDocument document, int offset, int length) { | |
82 | try { | |
83 | for (int i= 0; i < length; i++) | |
84 | if (!Character.isWhitespace(document.getChar(offset + i))) | |
85 | return false; | |
86 | return true; | |
87 | } catch (BadLocationException x) { | |
88 | JavaPlugin.log(x); | |
89 | return false; | |
90 | } | |
91 | } | |
92 | } |