mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Bug 305391 - encoding change event is not handled
This commit is contained in:
parent
c66fc1442a
commit
ae33f98bb6
6 changed files with 143 additions and 16 deletions
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -339,7 +339,9 @@ final class DeltaProcessor {
|
||||||
} else if (element instanceof Openable) {
|
} else if (element instanceof Openable) {
|
||||||
close((Openable)element);
|
close((Openable)element);
|
||||||
}
|
}
|
||||||
|
|
||||||
fCurrentDelta.changed(element, ICElementDelta.F_CONTENT);
|
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;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -54,9 +54,9 @@ public class StandaloneFastIndexer extends StandaloneIndexer {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings,
|
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]),
|
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
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings,
|
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]),
|
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
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public StandaloneFastIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings,
|
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]),
|
super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]),
|
||||||
false, mapper, log, (IStandaloneScannerInfoProvider)null);
|
false, mapper, log, (IStandaloneScannerInfoProvider)null, fileEncodingRegistry);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,9 @@ public class StandaloneFullIndexer extends StandaloneIndexer{
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings,
|
public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> 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]),
|
super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]),
|
||||||
false, mapper, log, scanner);
|
false, mapper, log, scanner, fileEncodingRegistry);
|
||||||
fCodeReaderFactory = codeReaderFactory;
|
fCodeReaderFactory = codeReaderFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,9 +79,9 @@ public class StandaloneFullIndexer extends StandaloneIndexer{
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings,
|
public StandaloneFullIndexer(File writableIndexFile, IIndexLocationConverter converter, Map<String, IPDOMLinkageFactory> 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]),
|
super(new WritableCIndex(new WritablePDOM(writableIndexFile, converter, linkageFactoryMappings),new IIndexFragment[0]),
|
||||||
false, mapper, log, scannerProvider);
|
false, mapper, log, scannerProvider, fileEncodingRegistry);
|
||||||
fCodeReaderFactory = codeReaderFactory;
|
fCodeReaderFactory = codeReaderFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,32 +164,34 @@ public abstract class StandaloneIndexer {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected FileEncodingRegistry fFileEncodingRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Its better to provide a scanner info provider instead.
|
* @deprecated Its better to provide a scanner info provider instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public StandaloneIndexer(IWritableIndex index, boolean indexAllFiles,
|
public StandaloneIndexer(IWritableIndex index, boolean indexAllFiles,
|
||||||
ILanguageMapper mapper, IParserLogService log, IScannerInfo scanner) {
|
ILanguageMapper mapper, IParserLogService log, IScannerInfo scanner, FileEncodingRegistry fileEncodingRegistry) {
|
||||||
fIndex = index;
|
fIndex = index;
|
||||||
fIndexAllFiles = indexAllFiles;
|
fIndexAllFiles = indexAllFiles;
|
||||||
fMapper = mapper;
|
fMapper = mapper;
|
||||||
fLog = log;
|
fLog = log;
|
||||||
fScanner = scanner;
|
fScanner = scanner;
|
||||||
fScannerInfoProvider = null;
|
fScannerInfoProvider = null;
|
||||||
|
fFileEncodingRegistry = fileEncodingRegistry;
|
||||||
setupASTFilePathResolver();
|
setupASTFilePathResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public StandaloneIndexer(IWritableIndex index, boolean indexAllFiles,
|
public StandaloneIndexer(IWritableIndex index, boolean indexAllFiles,
|
||||||
ILanguageMapper mapper, IParserLogService log, IStandaloneScannerInfoProvider scannerProvider) {
|
ILanguageMapper mapper, IParserLogService log, IStandaloneScannerInfoProvider scannerProvider, FileEncodingRegistry fileEncodingRegistry) {
|
||||||
fIndex = index;
|
fIndex = index;
|
||||||
fIndexAllFiles = indexAllFiles;
|
fIndexAllFiles = indexAllFiles;
|
||||||
fMapper = mapper;
|
fMapper = mapper;
|
||||||
fLog = log;
|
fLog = log;
|
||||||
fScanner = null;
|
fScanner = null;
|
||||||
fScannerInfoProvider = scannerProvider;
|
fScannerInfoProvider = scannerProvider;
|
||||||
|
fFileEncodingRegistry = fileEncodingRegistry;
|
||||||
setupASTFilePathResolver();
|
setupASTFilePathResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,4 +519,18 @@ public abstract class StandaloneIndexer {
|
||||||
public void setExclusionFilter(FilenameFilter exclusionFilter) {
|
public void setExclusionFilter(FilenameFilter exclusionFilter) {
|
||||||
fExclusionFilter = exclusionFilter;
|
fExclusionFilter = exclusionFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public FileEncodingRegistry getFileEncodingRegistry() {
|
||||||
|
return fFileEncodingRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setFileEncodingRegistry(FileEncodingRegistry fileEncodingRegistry) {
|
||||||
|
fFileEncodingRegistry = fileEncodingRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.util.HashMap;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
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.FileContent;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
|
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
|
||||||
|
@ -129,7 +130,24 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileContent getCodeReader(Object tu) {
|
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
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue