1 11 12 package org.eclipse.jdt.internal.ui.text.spelling; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.Platform; 19 import org.eclipse.core.runtime.content.IContentType; 20 import org.eclipse.core.runtime.content.IContentTypeManager; 21 22 import org.eclipse.jface.text.IDocument; 23 import org.eclipse.jface.text.IRegion; 24 25 import org.eclipse.ui.texteditor.spelling.ISpellingEngine; 26 import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector; 27 import org.eclipse.ui.texteditor.spelling.SpellingContext; 28 29 import org.eclipse.jdt.core.JavaCore; 30 31 41 public class DefaultSpellingEngine implements ISpellingEngine { 42 43 44 private static final IContentType TEXT_CONTENT_TYPE= Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT); 45 46 47 private static final IContentType JAVA_CONTENT_TYPE= Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE); 48 49 50 private static final IContentType PROPERTIES_CONTENT_TYPE= Platform.getContentTypeManager().getContentType("org.eclipse.jdt.core.javaProperties"); 52 53 private Map fEngines= new HashMap (); 54 55 58 public DefaultSpellingEngine() { 59 if (JAVA_CONTENT_TYPE != null) 60 fEngines.put(JAVA_CONTENT_TYPE, new JavaSpellingEngine()); 61 if (PROPERTIES_CONTENT_TYPE != null) 62 fEngines.put(PROPERTIES_CONTENT_TYPE, new PropertiesFileSpellingEngine()); 63 if (TEXT_CONTENT_TYPE != null) 64 fEngines.put(TEXT_CONTENT_TYPE, new TextSpellingEngine()); 65 } 66 67 70 public void check(IDocument document, IRegion[] regions, SpellingContext context, ISpellingProblemCollector collector, IProgressMonitor monitor) { 71 ISpellingEngine engine= getEngine(context.getContentType()); 72 if (engine == null) 73 engine= getEngine(TEXT_CONTENT_TYPE); 74 if (engine != null) 75 engine.check(document, regions, context, collector, monitor); 76 } 77 78 86 private ISpellingEngine getEngine(IContentType contentType) { 87 if (contentType == null) 88 return null; 89 90 if (fEngines.containsKey(contentType)) 91 return (ISpellingEngine) fEngines.get(contentType); 92 93 return getEngine(contentType.getBaseType()); 94 } 95 } 96 | Popular Tags |