Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Kucera2010-03-15 17:33:49 +0000
committerMike Kucera2010-03-15 17:33:49 +0000
commit57450dcb94ffb2cf2ebd117c66281376f14be666 (patch)
tree668e55ed02ffa4fc138295dc140c2dfeff06a5df
parentfcf23be24246edd423f200c0e0c980459436c7c4 (diff)
downloadorg.eclipse.cdt-57450dcb94ffb2cf2ebd117c66281376f14be666.tar.gz
org.eclipse.cdt-57450dcb94ffb2cf2ebd117c66281376f14be666.tar.xz
org.eclipse.cdt-57450dcb94ffb2cf2ebd117c66281376f14be666.zip
Bug 305391 - encoding change event is not handledv201003151528
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/FileEncodingRegistry.java87
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFastIndexer.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneFullIndexer.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexer.java24
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java14
6 files changed, 137 insertions, 18 deletions
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 b4e124d9a71..2c2403a9df8 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
@@ -629,6 +629,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<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();
+ }
+
+}
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 36d5d8e8cfb..3e81bdeff54 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
@@ -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 @@ public class StandaloneFastIndexer extends StandaloneIndexer {
* @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 class StandaloneFastIndexer extends StandaloneIndexer {
* @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 class StandaloneFastIndexer extends StandaloneIndexer {
* @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);
}
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 fd213c21226..f9844f10a4a 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
@@ -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 @@ public class StandaloneFullIndexer extends StandaloneIndexer{
* @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 class StandaloneFullIndexer extends StandaloneIndexer{
* @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;
}
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 45feeee12ae..4124789fca2 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
@@ -162,32 +162,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();
}
@@ -515,4 +517,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 b2e5c7e025d..e2c7400cf34 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
@@ -120,7 +120,19 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
@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;

Back to the top