Permalink
Browse files

Bug 305391 - encoding change event is not handled

  • Loading branch information...
1 parent fcf23be commit 57450dcb94ffb2cf2ebd117c66281376f14be666 Mike Kucera committed Mar 15, 2010
@@ -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
@@ -629,6 +629,10 @@ private boolean updateCurrentDeltaAndIndex(ICElement element, IResourceDelta del
}
}
}
+ }else if ((flags & IResourceDelta.ENCODING) != 0) {
+ if (element != null) {
+ elementChanged(element, delta);
+ }
}
return true;
}
@@ -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<String, String> fFilePathToEncodingMap = null;
+ private String defaultEncoding;
+
+ public FileEncodingRegistry(String defaultEncoding) {
+ this.defaultEncoding = defaultEncoding;
+ fFilePathToEncodingMap = new TreeMap<String, String>();
+ }
+
+
+ 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();
+ }
+
+}
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 QNX Software Systems and others.
+ * Copyright (c) 2006, 2010 QNX Software Systems 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
@@ -52,9 +52,9 @@
* @throws CoreException
*/
public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> 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);
}
@@ -69,9 +69,9 @@ public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter con
* @throws CoreException
*/
public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> 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);
}
@@ -85,9 +85,9 @@ public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter con
* @throws CoreException
*/
public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> 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);
}
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 QNX Software Systems and others.
+ * Copyright (c) 2006, 2010 QNX Software Systems 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
@@ -57,9 +57,9 @@
* @throws CoreException
*/
public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings,
- IScannerInfo scanner, ILanguageMapper mapper, IParserLogService log, ICodeReaderFactory codeReaderFactory) throws CoreException {
+ IScannerInfo scanner, FileEncodingRegistry fileEncodingRegistry, ILanguageMapper mapper, IParserLogService log, ICodeReaderFactory 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;
}
@@ -76,9 +76,9 @@ public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter con
* @throws CoreException
*/
public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings,
- IStandaloneScannerInfoProvider scannerProvider, ILanguageMapper mapper, IParserLogService log, ICodeReaderFactory codeReaderFactory) throws CoreException {
+ IStandaloneScannerInfoProvider scannerProvider,FileEncodingRegistry fileEncodingRegistry, ILanguageMapper mapper, IParserLogService log, ICodeReaderFactory 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;
}
@@ -162,32 +162,34 @@ public boolean accept(File dir, String name) {
}
};
+ 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();
}
@@ -515,4 +517,18 @@ public FilenameFilter getExclusionFilter() {
public void setExclusionFilter(FilenameFilter exclusionFilter) {
fExclusionFilter = exclusionFilter;
}
+
+
+ public FileEncodingRegistry getFileEncodingRegistry() {
+ return fFileEncodingRegistry;
+ }
+
+
+ public void setFileEncodingRegistry(FileEncodingRegistry fileEncodingRegistry) {
+ fFileEncodingRegistry = fileEncodingRegistry;
+ }
+
+
+
+
}
@@ -120,7 +120,19 @@ public boolean canBePartOfSDK(IIndexFileLocation ifl) {
@Override
public CodeReader getCodeReader(Object tu) {
try {
- return new CodeReader((String) tu);
+ 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) {
+ return new CodeReader(stu, fileEncoding);
+ } else {
+ return new CodeReader(stu);
+ }
} catch (IOException e) {
}
return null;

0 comments on commit 57450dc

Please sign in to comment.