mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Fix for Bug 62015 - Indexer to not rely on file extension for translation Unit
Changed all indexer file type checking to use the CoreModel file resolution services.
This commit is contained in:
parent
361017e5d4
commit
cf466da37f
6 changed files with 35 additions and 60 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2004-05-27 Bogdan Gheorghe
|
||||||
|
Fix for Bug 62015 - Indexer to not rely on file extension for translation Unit
|
||||||
|
Changed all indexer file type checking to use the CoreModel file resolution services.
|
||||||
|
|
||||||
2004-05-21 Andrew Niefer
|
2004-05-21 Andrew Niefer
|
||||||
Indexer problem reporting
|
Indexer problem reporting
|
||||||
* index/org/eclipse/cdt/internal/core/messages.properties
|
* index/org/eclipse/cdt/internal/core/messages.properties
|
||||||
|
|
|
@ -366,37 +366,6 @@ public class Util {
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @param string
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static boolean isCCFileName(String fileName) {
|
|
||||||
String[] sourceExtensions = CModelManager.sourceExtensions;
|
|
||||||
String[] headerExtensions = CModelManager.headerExtensions;
|
|
||||||
|
|
||||||
int dot =fileName.lastIndexOf("."); //$NON-NLS-1$
|
|
||||||
|
|
||||||
//No extension, give benefit of doubt
|
|
||||||
if (dot == -1)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
//Extract extension
|
|
||||||
String extension = ""; //$NON-NLS-1$
|
|
||||||
if (dot + 1 <= fileName.length())
|
|
||||||
extension = fileName.substring(dot + 1);
|
|
||||||
|
|
||||||
for (int i=0; i<sourceExtensions.length; i++){
|
|
||||||
if (sourceExtensions[i].equals(extension))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=0; i<headerExtensions.length; i++){
|
|
||||||
if (headerExtensions[i].equals(extension))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,14 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.index;
|
package org.eclipse.cdt.internal.core.index;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An <code>IIndexer</code> indexes ONE document at each time. It adds the document names and
|
* An <code>IIndexer</code> indexes ONE document at each time. It adds the document names and
|
||||||
* the words references to an IIndex. Each IIndexer can index certain types of document, and should
|
* the words references to an IIndex. Each IIndexer can index certain types of document, and should
|
||||||
* not index the other files.
|
* not index the other files.
|
||||||
*/
|
*/
|
||||||
public interface IIndexer {
|
public interface IIndexer {
|
||||||
/**
|
|
||||||
* Returns the file types the <code>IIndexer</code> handles.
|
|
||||||
*/
|
|
||||||
|
|
||||||
String[] getFileTypes();
|
|
||||||
/**
|
/**
|
||||||
* Indexes the given document, adding the document name and the word references
|
* Indexes the given document, adding the document name and the word references
|
||||||
* to this document to the given <code>IIndex</code>.The caller should use
|
* to this document to the given <code>IIndex</code>.The caller should use
|
||||||
|
@ -35,8 +32,8 @@ public interface IIndexer {
|
||||||
|
|
||||||
public void setFileTypes(String[] fileTypes);
|
public void setFileTypes(String[] fileTypes);
|
||||||
/**
|
/**
|
||||||
* Returns whether the <code>IIndexer</code> can index the given document or not.
|
* Returns whether the <code>IIndexer</code> can index the given IFile or not.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public boolean shouldIndex(IDocument document);
|
public boolean shouldIndex(IFile file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,9 @@ package org.eclipse.cdt.internal.core.search.indexing;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.filetype.ICFileType;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
|
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
|
||||||
|
@ -53,6 +56,12 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
||||||
|
|
||||||
public static boolean VERBOSE = false;
|
public static boolean VERBOSE = false;
|
||||||
|
|
||||||
|
//IDs defined in plugin.xml for file types
|
||||||
|
private final static String C_SOURCE_ID = "org.eclipse.cdt.core.fileType.c_source";
|
||||||
|
private final static String C_HEADER_ID = "org.eclipse.cdt.core.fileType.c_header";
|
||||||
|
private final static String CPP_SOURCE_ID = "org.eclipse.cdt.core.fileType.cxx_source";
|
||||||
|
private final static String CPP_HEADER_ID = "org.eclipse.cdt.core.fileType.cxx_header";
|
||||||
|
|
||||||
public AbstractIndexer() {
|
public AbstractIndexer() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -423,10 +432,6 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the file types the <code>IIndexer</code> handles.
|
|
||||||
*/
|
|
||||||
public abstract String[] getFileTypes();
|
|
||||||
/**
|
/**
|
||||||
* Returns the file types being indexed.
|
* Returns the file types being indexed.
|
||||||
*/
|
*/
|
||||||
|
@ -436,20 +441,25 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
|
||||||
*/
|
*/
|
||||||
public void index(IDocument document, IIndexerOutput output) throws IOException {
|
public void index(IDocument document, IIndexerOutput output) throws IOException {
|
||||||
this.output = output;
|
this.output = output;
|
||||||
if (shouldIndex(document)) indexFile(document);
|
if (shouldIndex(this.getResourceFile())) indexFile(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void indexFile(IDocument document) throws IOException;
|
protected abstract void indexFile(IDocument document) throws IOException;
|
||||||
/**
|
/**
|
||||||
* @see IIndexer#shouldIndex(IDocument document)
|
* @param fileToBeIndexed
|
||||||
|
* @see IIndexer#shouldIndex(IFile file)
|
||||||
*/
|
*/
|
||||||
public boolean shouldIndex(IDocument document) {
|
public boolean shouldIndex(IFile fileToBeIndexed) {
|
||||||
String type = document.getType();
|
if (fileToBeIndexed != null){
|
||||||
String[] supportedTypes = this.getFileTypes();
|
ICFileType type = CCorePlugin.getDefault().getFileType(fileToBeIndexed.getProject(),fileToBeIndexed.getName());
|
||||||
for (int i = 0; i < supportedTypes.length; ++i) {
|
if (type.isSource()){
|
||||||
if (supportedTypes[i].equals(type))
|
String id = type.getId();
|
||||||
return true;
|
if (id.equals(AbstractIndexer.C_SOURCE_ID) ||
|
||||||
|
id.equals(AbstractIndexer.CPP_SOURCE_ID))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.search.indexing;
|
package org.eclipse.cdt.internal.core.search.indexing;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.internal.core.Util;
|
import org.eclipse.cdt.internal.core.Util;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
import org.eclipse.cdt.internal.core.search.processing.JobManager;
|
||||||
|
@ -58,8 +59,8 @@ class AddFolderToIndex extends IndexRequest {
|
||||||
public boolean visit(IResourceProxy proxy) throws CoreException {
|
public boolean visit(IResourceProxy proxy) throws CoreException {
|
||||||
switch(proxy.getType()) {
|
switch(proxy.getType()) {
|
||||||
case IResource.FILE :
|
case IResource.FILE :
|
||||||
if (Util.isCCFileName(proxy.getName())) {
|
IResource resource = proxy.requestResource();
|
||||||
IResource resource = proxy.requestResource();
|
if (CoreModel.isValidTranslationUnitName(resource.getProject(),resource.getName())) {
|
||||||
if (pattern == null || !Util.isExcluded(resource, pattern))
|
if (pattern == null || !Util.isExcluded(resource, pattern))
|
||||||
indexManager.addSource((IFile)resource, container);
|
indexManager.addSource((IFile)resource, container);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
* - Unions
|
* - Unions
|
||||||
*/
|
*/
|
||||||
public class SourceIndexer extends AbstractIndexer {
|
public class SourceIndexer extends AbstractIndexer {
|
||||||
|
|
||||||
//TODO: Indexer, add additional file types
|
//TODO: Indexer, add additional file types
|
||||||
//Header files: "h" , "hh", "hpp"
|
//Header files: "h" , "hh", "hpp"
|
||||||
//Use the CModelManager defined file types
|
//Use the CModelManager defined file types
|
||||||
|
@ -72,12 +72,6 @@ public class SourceIndexer extends AbstractIndexer {
|
||||||
this.resourceFile = resource;
|
this.resourceFile = resource;
|
||||||
this.timeOut = timeOut;
|
this.timeOut = timeOut;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Returns the file types the <code>IIndexer</code> handles.
|
|
||||||
*/
|
|
||||||
public String[] getFileTypes(){
|
|
||||||
return CModelManager.sourceExtensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void indexFile(IDocument document) throws IOException {
|
protected void indexFile(IDocument document) throws IOException {
|
||||||
// Add the name of the file to the index
|
// Add the name of the file to the index
|
||||||
|
|
Loading…
Add table
Reference in a new issue