diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java index 012ad6c198b..f341a9a5fa8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2008 IBM Corporation and others. + * Copyright (c) 2002, 2010 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 @@ -339,7 +339,9 @@ final class DeltaProcessor { } else if (element instanceof Openable) { close((Openable)element); } + fCurrentDelta.changed(element, ICElementDelta.F_CONTENT); + } /** @@ -629,6 +631,10 @@ final class DeltaProcessor { } } } + } else if ((flags & IResourceDelta.ENCODING) != 0) { + if (element != null) { + elementChanged(element, delta); + } } return true; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/FileEncodingRegistry.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/FileEncodingRegistry.java new file mode 100644 index 00000000000..c54544e7f2e --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/FileEncodingRegistry.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2010 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 Rational Software - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.indexer; + +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Map; +import java.util.TreeMap; + +/** + * this class is a registry which maps file name and file's encoding, the class + * is used by standalone indexer + * + * @author johnliu + * + */ +public class FileEncodingRegistry implements Serializable { + + private Map fFilePathToEncodingMap = null; + private String defaultEncoding; + + public FileEncodingRegistry(String defaultEncoding) { + this.defaultEncoding = defaultEncoding; + fFilePathToEncodingMap = new TreeMap(); + } + + + public void setDefaultEncoding(String newDefaultEncoding) { + defaultEncoding = newDefaultEncoding; + + } + + public void registerFileEncoding(String filename, String encoding) { + if (fFilePathToEncodingMap != null) { + fFilePathToEncodingMap.put(filename, encoding); + } + + } + + public void unregisterFile(String filename) { + if (fFilePathToEncodingMap != null) { + fFilePathToEncodingMap.remove(filename); + } + + } + + public String getFileEncoding(String filename) { + String fileEncoding = null; + if (fFilePathToEncodingMap != null) { + fileEncoding = fFilePathToEncodingMap.get(filename); + } + if (fileEncoding != null) { + return fileEncoding; + + } else { + return defaultEncoding; + } + } + + public void clear() { + if (fFilePathToEncodingMap != null) { + fFilePathToEncodingMap.clear(); + } + fFilePathToEncodingMap = null; + defaultEncoding = null; + + } + + // send as little over the wire as possible + private void writeObject(ObjectOutputStream out) throws IOException { + if (fFilePathToEncodingMap != null && fFilePathToEncodingMap.isEmpty()) { + fFilePathToEncodingMap = null; + } + out.defaultWriteObject(); + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexer.java index d51b0df03ad..74ff4dfb1e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexer.java @@ -54,9 +54,9 @@ public class StandaloneFastIndexer extends StandaloneIndexer { */ @Deprecated public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, - IScannerInfo scanner, ILanguageMapper mapper, IParserLogService log) throws CoreException { + IScannerInfo scanner, FileEncodingRegistry fileEncodingRegistry, ILanguageMapper mapper, IParserLogService log) throws CoreException { super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), - false, mapper, log, scanner); + false, mapper, log, scanner, fileEncodingRegistry); } @@ -71,9 +71,9 @@ public class StandaloneFastIndexer extends StandaloneIndexer { * @throws CoreException */ public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, - IStandaloneScannerInfoProvider scannerProvider, ILanguageMapper mapper, IParserLogService log) throws CoreException { + IStandaloneScannerInfoProvider scannerProvider, FileEncodingRegistry fileEncodingRegistry, ILanguageMapper mapper, IParserLogService log) throws CoreException { super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), - false, mapper, log, scannerProvider); + false, mapper, log, scannerProvider, fileEncodingRegistry); } @@ -87,9 +87,9 @@ public class StandaloneFastIndexer extends StandaloneIndexer { * @throws CoreException */ public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, - ILanguageMapper mapper, IParserLogService log) throws CoreException { + FileEncodingRegistry fileEncodingRegistry, ILanguageMapper mapper, IParserLogService log) throws CoreException { super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), - false, mapper, log, (IStandaloneScannerInfoProvider)null); + false, mapper, log, (IStandaloneScannerInfoProvider)null, fileEncodingRegistry); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexer.java index cc7c404de09..4199f024620 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexer.java @@ -60,9 +60,9 @@ public class StandaloneFullIndexer extends StandaloneIndexer{ */ @Deprecated public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, - IScannerInfo scanner, ILanguageMapper mapper, IParserLogService log, AbstractCodeReaderFactory codeReaderFactory) throws CoreException { + IScannerInfo scanner, FileEncodingRegistry fileEncodingRegistry, ILanguageMapper mapper, IParserLogService log, AbstractCodeReaderFactory codeReaderFactory) throws CoreException { super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), - false, mapper, log, scanner); + false, mapper, log, scanner, fileEncodingRegistry); fCodeReaderFactory = codeReaderFactory; } @@ -79,9 +79,9 @@ public class StandaloneFullIndexer extends StandaloneIndexer{ * @throws CoreException */ public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map linkageFactoryMappings, - IStandaloneScannerInfoProvider scannerProvider, ILanguageMapper mapper, IParserLogService log, AbstractCodeReaderFactory codeReaderFactory) throws CoreException { + IStandaloneScannerInfoProvider scannerProvider, FileEncodingRegistry fileEncodingRegistry, ILanguageMapper mapper, IParserLogService log, AbstractCodeReaderFactory codeReaderFactory) throws CoreException { super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]), - false, mapper, log, scannerProvider); + false, mapper, log, scannerProvider, fileEncodingRegistry); fCodeReaderFactory = codeReaderFactory; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java index e0b08ed05e0..1de3acaa0ec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java @@ -164,32 +164,34 @@ public abstract class StandaloneIndexer { } }; + protected FileEncodingRegistry fFileEncodingRegistry; + /** * @deprecated Its better to provide a scanner info provider instead. */ @Deprecated public StandaloneIndexer(IWritableIndex index, boolean indexAllFiles, - ILanguageMapper mapper, IParserLogService log, IScannerInfo scanner) { + ILanguageMapper mapper, IParserLogService log, IScannerInfo scanner, FileEncodingRegistry fileEncodingRegistry) { fIndex = index; fIndexAllFiles = indexAllFiles; fMapper = mapper; fLog = log; fScanner = scanner; fScannerInfoProvider = null; - + fFileEncodingRegistry = fileEncodingRegistry; setupASTFilePathResolver(); } public StandaloneIndexer(IWritableIndex index, boolean indexAllFiles, - ILanguageMapper mapper, IParserLogService log, IStandaloneScannerInfoProvider scannerProvider) { + ILanguageMapper mapper, IParserLogService log, IStandaloneScannerInfoProvider scannerProvider, FileEncodingRegistry fileEncodingRegistry) { fIndex = index; fIndexAllFiles = indexAllFiles; fMapper = mapper; fLog = log; fScanner = null; fScannerInfoProvider = scannerProvider; - + fFileEncodingRegistry = fileEncodingRegistry; setupASTFilePathResolver(); } @@ -517,4 +519,18 @@ public abstract class StandaloneIndexer { public void setExclusionFilter(FilenameFilter exclusionFilter) { fExclusionFilter = exclusionFilter; } + + + public FileEncodingRegistry getFileEncodingRegistry() { + return fFileEncodingRegistry; + } + + + public void setFileEncodingRegistry(FileEncodingRegistry fileEncodingRegistry) { + fFileEncodingRegistry = fileEncodingRegistry; + } + + + + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java index 1b8b407e2bd..fc9726992c9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java @@ -17,6 +17,7 @@ import java.util.HashMap; import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.model.AbstractLanguage; import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.FileContent; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.internal.core.index.IndexFileLocation; @@ -129,7 +130,24 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter { @Override public FileContent getCodeReader(Object tu) { - return FileContent.createForExternalFileLocation((String) tu); + try { + String stu = (String) tu; + String fileEncoding = null; + // query file's encoding, if we find it and use it to create CodeReader + FileEncodingRegistry fileEncodingRegistry = fIndexer.getFileEncodingRegistry(); + if(fileEncodingRegistry != null){ + fileEncoding = fileEncodingRegistry.getFileEncoding(stu); + } + + if (fileEncoding != null) { + // TODO this is bad + return FileContent.adapt(new CodeReader(stu, fileEncoding)); + } else { + return FileContent.createForExternalFileLocation((String) tu); + } + } catch (IOException e) { + } + return null; } @Override