mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added a dictionary of HTML tags. Bug 243687.
This commit is contained in:
parent
e593e311fa
commit
3dae068c33
5 changed files with 104 additions and 61 deletions
|
@ -1,46 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2007 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.text.correction;
|
||||
|
||||
/**
|
||||
* Html tag constants.
|
||||
*/
|
||||
public interface IHtmlTagConstants {
|
||||
|
||||
/** Html tag close prefix */
|
||||
public static final String HTML_CLOSE_PREFIX= "</"; //$NON-NLS-1$
|
||||
|
||||
/** Html entity characters */
|
||||
public static final char[] HTML_ENTITY_CHARACTERS= new char[] { '<', '>', ' ', '&', '^', '~', '\"' };
|
||||
|
||||
/**
|
||||
* Html entity start.
|
||||
*/
|
||||
public static final char HTML_ENTITY_START= '&';
|
||||
/**
|
||||
* Html entity end.
|
||||
*/
|
||||
public static final char HTML_ENTITY_END= ';';
|
||||
|
||||
/** Html entity codes */
|
||||
public static final String[] HTML_ENTITY_CODES= new String[] { "<", ">", " ", "&", "ˆ", "˜", """ }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
|
||||
|
||||
/** Html general tags */
|
||||
public static final String[] HTML_GENERAL_TAGS= new String[] { "a", "b", "blockquote", "br", "code", "dd", "dl", "dt", "em", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "i", "li", "nl", "ol", "p", "pre", "q", "strong", "tbody", "td", "th", "tr", "tt", "ul" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ //$NON-NLS-14$ //$NON-NLS-15$ //$NON-NLS-16$ //$NON-NLS-17$ //$NON-NLS-18$ //$NON-NLS-19$ //$NON-NLS-20$ //$NON-NLS-21$ //$NON-NLS-22$ //$NON-NLS-23$ //$NON-NLS-24$ //$NON-NLS-25$ //$NON-NLS-26$ //$NON-NLS-27$ //$NON-NLS-28$ //$NON-NLS-29$ //$NON-NLS-30$
|
||||
|
||||
/** Html tag postfix */
|
||||
public static final char HTML_TAG_POSTFIX= '>';
|
||||
|
||||
/** Html tag prefix */
|
||||
public static final char HTML_TAG_PREFIX= '<';
|
||||
}
|
|
@ -26,6 +26,7 @@ import org.eclipse.ui.texteditor.spelling.SpellingProblem;
|
|||
|
||||
import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.IHtmlTagConstants;
|
||||
import org.eclipse.cdt.internal.ui.text.correction.CorrectionContext;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellCheckEngine;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellChecker;
|
||||
|
@ -114,6 +115,9 @@ public class CSpellingProblem extends SpellingProblem {
|
|||
if (checker != null) {
|
||||
CorrectionContext context= new CorrectionContext(null, getOffset(), getLength());
|
||||
|
||||
// Hack borrowed from JDT.
|
||||
fixed= arguments[0].charAt(0) == IHtmlTagConstants.HTML_TAG_PREFIX;
|
||||
|
||||
if ((sentence && match) && !fixed) {
|
||||
result= new ICCompletionProposal[] { new ChangeCaseProposal(
|
||||
arguments, getOffset(), getLength(), context,
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.text.spelling;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.IHtmlTagConstants;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.AbstractSpellDictionary;
|
||||
|
||||
/**
|
||||
* Dictionary for html tags.
|
||||
*/
|
||||
public class HtmlTagDictionary extends AbstractSpellDictionary {
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.spelling.engine.AbstractSpellDictionary#getName()
|
||||
*/
|
||||
@Override
|
||||
protected final URL getURL() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellDictionary#isCorrect(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isCorrect(final String word) {
|
||||
if (word.charAt(0) == IHtmlTagConstants.HTML_TAG_PREFIX)
|
||||
return super.isCorrect(word);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.ui.text.spelling.engine.AbstractSpellDictionary#load(java.net.URL)
|
||||
*/
|
||||
@Override
|
||||
protected synchronized boolean load(final URL url) {
|
||||
unload();
|
||||
|
||||
for (int index= 0; index < IHtmlTagConstants.HTML_GENERAL_TAGS.length; index++) {
|
||||
hashWord(IHtmlTagConstants.HTML_TAG_PREFIX + IHtmlTagConstants.HTML_GENERAL_TAGS[index] + IHtmlTagConstants.HTML_TAG_POSTFIX);
|
||||
hashWord(IHtmlTagConstants.HTML_CLOSE_PREFIX + IHtmlTagConstants.HTML_GENERAL_TAGS[index] + IHtmlTagConstants.HTML_TAG_POSTFIX);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.text.spelling.engine.AbstractSpellDictionary#stripNonLetters(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected String stripNonLetters(String word) {
|
||||
return word;
|
||||
}
|
||||
}
|
|
@ -20,7 +20,6 @@ import java.net.URL;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -55,7 +54,6 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe
|
|||
*/
|
||||
private static Set<Locale> fgLocalesWithInstalledDictionaries;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the locales for which this
|
||||
* spell check engine has dictionaries.
|
||||
|
@ -133,9 +131,7 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe
|
|||
|
||||
// Try same language
|
||||
String language= locale.getLanguage();
|
||||
Iterator<Map.Entry<Locale, ISpellDictionary>> iter= fLocaleDictionaries.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry<Locale, ISpellDictionary> entry= iter.next();
|
||||
for (Entry<Locale, ISpellDictionary> entry : fLocaleDictionaries.entrySet()) {
|
||||
Locale dictLocale= entry.getKey();
|
||||
if (dictLocale.getLanguage().equals(language))
|
||||
return entry.getValue();
|
||||
|
@ -156,9 +152,7 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe
|
|||
|
||||
// Try same language
|
||||
String language= locale.getLanguage();
|
||||
Iterator<Locale> iter= getLocalesWithInstalledDictionaries().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Locale dictLocale= iter.next();
|
||||
for (Locale dictLocale : getLocalesWithInstalledDictionaries()) {
|
||||
if (dictLocale.getLanguage().equals(language))
|
||||
return dictLocale;
|
||||
}
|
||||
|
@ -231,6 +225,7 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe
|
|||
*/
|
||||
private SpellCheckEngine() {
|
||||
fGlobalDictionaries.add(new TaskTagDictionary());
|
||||
fGlobalDictionaries.add(new HtmlTagDictionary());
|
||||
|
||||
try {
|
||||
final URL location= getDictionaryLocation();
|
||||
|
@ -388,15 +383,12 @@ public class SpellCheckEngine implements ISpellCheckEngine, IPropertyChangeListe
|
|||
public synchronized final void shutdown() {
|
||||
SpellingPreferences.removePropertyChangeListener(this);
|
||||
|
||||
ISpellDictionary dictionary= null;
|
||||
for (final Iterator<ISpellDictionary> iterator= fGlobalDictionaries.iterator(); iterator.hasNext();) {
|
||||
dictionary= iterator.next();
|
||||
for (ISpellDictionary dictionary : fGlobalDictionaries) {
|
||||
dictionary.unload();
|
||||
}
|
||||
fGlobalDictionaries= null;
|
||||
|
||||
for (Object element : fLocaleDictionaries.values()) {
|
||||
dictionary= (ISpellDictionary)element;
|
||||
for (ISpellDictionary dictionary : fLocaleDictionaries.values()) {
|
||||
dictionary.unload();
|
||||
}
|
||||
fLocaleDictionaries= null;
|
||||
|
|
|
@ -19,10 +19,10 @@ import org.eclipse.jface.text.IRegion;
|
|||
|
||||
import com.ibm.icu.text.BreakIterator;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.IHtmlTagConstants;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.DefaultSpellChecker;
|
||||
import org.eclipse.cdt.internal.ui.text.spelling.engine.ISpellCheckIterator;
|
||||
|
||||
|
||||
/**
|
||||
* Iterator to spell check multiline comment regions.
|
||||
*/
|
||||
|
@ -278,7 +278,35 @@ public class SpellCheckIterator implements ISpellCheckIterator {
|
|||
|
||||
boolean update= false;
|
||||
if (fNext - fPrevious > 0) {
|
||||
if (!isWhitespace(fPrevious, fNext) && isAlphaNumeric(fPrevious, fNext)) {
|
||||
if (fSuccessor != BreakIterator.DONE && fContent.charAt(fPrevious) == IHtmlTagConstants.HTML_TAG_PREFIX && (Character.isLetter(fContent.charAt(fNext)) || fContent.charAt(fNext) == '/')) {
|
||||
if (fContent.startsWith(IHtmlTagConstants.HTML_CLOSE_PREFIX, fPrevious))
|
||||
nextBreak();
|
||||
|
||||
nextBreak();
|
||||
|
||||
if (fSuccessor != BreakIterator.DONE && fContent.charAt(fNext) == IHtmlTagConstants.HTML_TAG_POSTFIX) {
|
||||
nextBreak();
|
||||
if (fSuccessor != BreakIterator.DONE) {
|
||||
update= true;
|
||||
token= fContent.substring(fPrevious, fNext);
|
||||
}
|
||||
}
|
||||
} else if (fSuccessor != BreakIterator.DONE && fContent.charAt(fPrevious) == IHtmlTagConstants.HTML_ENTITY_START && (Character.isLetter(fContent.charAt(fNext)))) {
|
||||
nextBreak();
|
||||
if (fSuccessor != BreakIterator.DONE && fContent.charAt(fNext) == IHtmlTagConstants.HTML_ENTITY_END) {
|
||||
nextBreak();
|
||||
if (isToken(fContent.substring(fPrevious, fNext), IHtmlTagConstants.HTML_ENTITY_CODES)) {
|
||||
skipTokens(fPrevious, IHtmlTagConstants.HTML_ENTITY_END);
|
||||
update= true;
|
||||
} else {
|
||||
token= fContent.substring(fPrevious, fNext);
|
||||
}
|
||||
} else {
|
||||
token= fContent.substring(fPrevious, fNext);
|
||||
}
|
||||
|
||||
update= true;
|
||||
} else if (!isWhitespace(fPrevious, fNext) && isAlphaNumeric(fPrevious, fNext)) {
|
||||
if (isUrlToken(fPrevious)) {
|
||||
skipTokens(fPrevious, ' ');
|
||||
} else if (fNext - fPrevious > 1 || isSingleLetter(fPrevious) && !fIsIgnoringSingleLetters) {
|
||||
|
|
Loading…
Add table
Reference in a new issue