1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Initial CTags Indexer contribution

Added timing option to all three indexers
Modified event notification for all indexers to make use of ICDTIndexer constants
Modified SearchEngine to work with all 3 indexers
Added UI block for CTagsIndexer
Ironed out some UI wrinkles in Indexer Block
Added indexer change event for UI Block
This commit is contained in:
Bogdan Gheorghe 2005-03-28 16:36:13 +00:00
parent 6f398f8b5b
commit b456fdc959
34 changed files with 1901 additions and 83 deletions

View file

@ -18,6 +18,9 @@ org.eclipse.cdt.core/debug/search=false
# Reports encoded index entries
org.eclipse.cdt.core/debug/indexer=false
# Reports time taken for an index
org.eclipse.cdt.core/debug/indextimes=false
# Reports search matches
org.eclipse.cdt.core/debug/matchlocator=false

View file

@ -1,3 +1,12 @@
2005-03-28 Bogdan Gheorghe
Modified DeltaProcessor to make use of ICDTIndexer elements when requesting an index for an element.
Added indextiming option to trace options in CCorePlugin.
Added new CTagsIndexer
* model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
* src/org/eclipse/cdt/core/CCorePlugin.java
* plugin.xml
2005-03-24 Eric ter Haar
Added some e_machine types and made section reading seek to each section
before reading encase section records are extended.

View file

@ -1,3 +1,31 @@
2005-03-28 Bogdan Gheorghe
Initial CTags Indexer contribution
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsEntry.java
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsAddCompilationUnitToIndex.java
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsAddFileToIndex.java
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsConsoleParser.java
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsFileReader.java
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsHeader.java
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexAll.jav
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexer.java
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsIndexeRequest.java
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsRemoveFromIndex.java
* index/org/eclipse/cdt/internal/core/index/ctagsindexer/CTagsSaveIndex.java
Added timing option to all three indexers
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java
* index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRunner.java
Modified event notification for all indexers to make use of ICDTIndexer constants as opposed to ICElements, in
order to allow indexers to request additional jobs without having to create or retrieve an ICElement
* index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexer.java
* index/org/eclipse/cdt/core/index/ICDTIndexer.java
* index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java
2005-03-18 Alain Magloire
Move more code in the try/finally as a precaution. Bad things
where happening (i.e. NPE) but the monitor was not decremented

View file

@ -10,9 +10,9 @@
**********************************************************************/
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.index.IIndexer;
import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceDelta;
/**
@ -48,6 +48,13 @@ public interface ICDTIndexer extends IIndexer {
static public final int _STATIC = 8;
static public final int _DELAYUNTILBUILDINFO = 16;
/***
* Indexable units
*/
static public final int PROJECT = 1;
static public final int FOLDER = 2;
static public final int COMPILATION_UNIT = 4;
/**
* Returns what features this <code>ICDTIndexer</code> provides.
@ -59,14 +66,14 @@ public interface ICDTIndexer extends IIndexer {
* The <code>IResourcDelta</code> and (TODO: <code>IResourceChangeEvent</code> are provided for indexers
* to decide how to schedule this event).
*/
public void addRequest(ICElement cElement, IResourceDelta delta/*, IResourceChangeEvent event*/);
public void addRequest(IProject project, IResourceDelta delta, int kind);
/**
* The <code>IndexManager</code> calls addRequest when it receives an event from the <code>DeltaProcessor</code>.
* The <code>IResourcDelta</code> and (TODO:<code>IResourceChangeEvent</code> are provided for the indexder
* to decide how to schedule this event).
*/
public void removeRequest(ICElement cElement, IResourceDelta delta/*, IResourceChangeEvent event*/);
public void removeRequest(IProject project, IResourceDelta delta, int kind);
/**
* The <code>IndexManager</code> will send out a jobFinishedEvent to the indexer that
@ -88,4 +95,17 @@ public interface ICDTIndexer extends IIndexer {
*/
public void notifyIdle(long idlingTime);
/**
* Returns if this indexer is enabled
* @param p
* @return
*/
public boolean isIndexEnabled(IProject p);
/**
* Returns the storage used by this indexer.
* @return
*/
public IIndexStorage getIndexStorage();
}

View file

@ -0,0 +1,75 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.util.HashMap;
import java.util.StringTokenizer;
class CTagEntry{
private final CTagsConsoleParser parser;
String elementName;
String fileName;
int lineNumber;
/* Miscellaneous extension fields */
HashMap tagExtensionField;
String line;
public CTagEntry(CTagsConsoleParser parser, String line) {
this.line = line;
this.parser = parser;
elementName = ""; //$NON-NLS-1$
fileName =""; //$NON-NLS-1$
lineNumber = 0;
tagExtensionField = new HashMap();
parse();
}
void parse () {
String delim = CTagsConsoleParser.TAB_SEPARATOR;
StringTokenizer st = new StringTokenizer(line, delim);
for (int state = 0; st.hasMoreTokens(); state++) {
String token = st.nextToken();
switch (state) {
case 0: // ELEMENT_NAME:
elementName = token;
break;
case 1: // FILE_NAME:
fileName = token;
break;
case 2: // LINE NUMBER;
try {
String sub = token.trim();
if (Character.isDigit(sub.charAt(0))) {
lineNumber = Integer.parseInt(sub);
}
} catch (NumberFormatException e) {
} catch (IndexOutOfBoundsException e) {
}
break;
default: // EXTENSION_FIELDS:
int i = token.indexOf(':');
if (i != -1) {
String key = token.substring(0, i);
String value = token.substring(i + 1);
tagExtensionField.put(key, value);
}
break;
}
}
}
}

View file

@ -0,0 +1,46 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.IOException;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
/**
* @author Bogdan Gheorghe
*/
public class CTagsAddCompilationUnitToIndex extends CTagsAddFileToIndex {
char[] contents;
public CTagsAddCompilationUnitToIndex(IFile resource, IPath indexedContainer, CTagsIndexer indexer) {
super(resource, indexedContainer, indexer);
}
protected boolean indexDocument(IIndex index) throws IOException {
if (!initializeContents()) return false;
index.add(new IFileDocument(resource, this.contents), new CTagsIndexerRunner(resource, indexer));
return true;
}
public boolean initializeContents() {
if (this.contents == null) {
try {
IPath location = resource.getLocation();
if (location != null)
this.contents = org.eclipse.cdt.internal.core.Util.getFileCharContent(location.toFile(), null);
} catch (IOException e) {
}
}
return this.contents != null;
}
}

View file

@ -0,0 +1,74 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.IOException;
import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* @author Bogdan Gheorghe
*/
public abstract class CTagsAddFileToIndex extends CTagsIndexRequest {
IFile resource;
public CTagsAddFileToIndex(IFile resource, IPath indexPath, CTagsIndexer indexer) {
super(indexPath, indexer);
this.resource = resource;
}
public boolean execute(IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
/* ensure no concurrent write access to index */
IIndex index = indexer.getIndex(this.indexPath, true, /*reuse index file*/ true /*create if none*/);
if (index == null) return true;
ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
monitor.enterWrite(); // ask permission to write
if (!indexDocument(index)) return false;
} catch (IOException e) {
org.eclipse.cdt.internal.core.model.Util.log(null, "Index I/O Exception: " + e.getMessage() + " on File: " + resource.getName(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
if (IndexManager.VERBOSE) {
JobManager.verbose("-> failed to index " + this.resource + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
e.printStackTrace();
}
return false;
} finally {
monitor.exitWrite(); // free write lock
}
return true;
}
protected abstract boolean indexDocument(IIndex index) throws IOException;
public String toString() {
return "indexing " + this.resource.getFullPath(); //$NON-NLS-1$
}
/**
* The resource being indexed
* @return
*/
public IResource getResource(){
return resource;
}
}

View file

@ -0,0 +1,175 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.IConsoleParser;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.internal.core.index.domsourceindexer.IndexEncoderUtil;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants.EntryType;
/**
* @author Bogdan Gheorghe
*/
public class CTagsConsoleParser implements IConsoleParser {
final static String TAB_SEPARATOR = "\t"; //$NON-NLS-1$
final static String PATTERN_SEPARATOR = ";\""; //$NON-NLS-1$
final static String COLONCOLON = "::"; //$NON-NLS-1$
final static String LANGUAGE = "language"; //$NON-NLS-1$
final static String KIND = "kind"; //$NON-NLS-1$
final static String LINE = "line"; //$NON-NLS-1$
final static String FILE = "file"; //$NON-NLS-1$
final static String INHERITS = "inherits"; //$NON-NLS-1$
final static String ACCESS = "access"; //$NON-NLS-1$
final static String IMPLEMENTATION = "implementation"; //$NON-NLS-1$
final static String CLASS = "class"; //$NON-NLS-1$
final static String MACRO = "macro"; //$NON-NLS-1$
final static String ENUMERATOR = "enumerator"; //$NON-NLS-1$
final static String FUNCTION = "function"; //$NON-NLS-1$
final static String ENUM = "enum"; //$NON-NLS-1$
final static String MEMBER = "member"; //$NON-NLS-1$
final static String NAMESPACE = "namespace"; //$NON-NLS-1$
final static String PROTOTYPE = "prototype"; //$NON-NLS-1$
final static String STRUCT = "struct"; //$NON-NLS-1$
final static String TYPEDEF = "typedef"; //$NON-NLS-1$
final static String UNION = "union"; //$NON-NLS-1$
final static String VARIABLE = "variable"; //$NON-NLS-1$
final static String EXTERNALVAR = ""; //$NON-NLS-1$
private CTagsIndexerRunner indexer;
public CTagsConsoleParser(CTagsIndexerRunner indexer){
this.indexer = indexer;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.ctagsindexer.IConsoleParser#processLine(java.lang.String)
*/
public boolean processLine(String line) {
CTagEntry tempTag = new CTagEntry(this, line);
if (indexer != null)
encodeTag(tempTag);
return false;
}
public CTagEntry processLineReturnTag(String line){
CTagEntry tempTag = new CTagEntry(this, line);
return tempTag;
}
/**
* @param tempTag
*/
private void encodeTag(CTagEntry tempTag) {
EntryType entryType = null;
String kind = (String)tempTag.tagExtensionField.get(KIND);
if (kind == null)
return;
char[][] fullName = getQualifiedName(tempTag);
ICSearchConstants.LimitTo type = ICSearchConstants.DECLARATIONS;
if (kind.equals(CLASS)){
entryType = IIndexEncodingConstants.CLASS;
} else if (kind.equals(MACRO)){
entryType = IIndexEncodingConstants.MACRO;
} else if (kind.equals(ENUMERATOR)){
entryType = IIndexEncodingConstants.ENUMERATOR;
} else if (kind.equals(FUNCTION)){
entryType = IIndexEncodingConstants.FUNCTION;
} else if (kind.equals(ENUM)){
entryType = IIndexEncodingConstants.ENUM;
} else if (kind.equals(MEMBER)){
entryType = IIndexEncodingConstants.FIELD;
} else if (kind.equals(NAMESPACE)){
entryType = IIndexEncodingConstants.NAMESPACE;
} else if (kind.equals(PROTOTYPE)){
entryType = IIndexEncodingConstants.FUNCTION;
type = ICSearchConstants.DEFINITIONS;
} else if (kind.equals(STRUCT)){
entryType = IIndexEncodingConstants.STRUCT;
} else if (kind.equals(TYPEDEF)){
entryType = IIndexEncodingConstants.TYPEDEF;
} else if (kind.equals(UNION)){
entryType = IIndexEncodingConstants.UNION;
} else if (kind.equals(VARIABLE)){
entryType = IIndexEncodingConstants.VAR;
} else if (kind.equals(EXTERNALVAR)){
}
if (entryType != null)
indexer.getOutput().addRef(IndexEncoderUtil.encodeEntry(fullName,entryType,type), getIndexFlag());
}
/**
* @return
*/
private int getIndexFlag() {
int fileNum = 0;
IndexedFile mainIndexFile = indexer.getOutput().getIndexedFile(
indexer.getResourceFile().getFullPath().toString());
if (mainIndexFile != null)
fileNum = mainIndexFile.getFileNumber();
return fileNum;
}
/**
* @param tempTag
* @return
*/
public char[][] getQualifiedName(CTagEntry tempTag) {
char[][] fullName = null;
String name = null;
String[] types = {NAMESPACE, CLASS, STRUCT, UNION, FUNCTION, ENUM};
for (int i=0; i<types.length; i++){
//look for name
name = (String) tempTag.tagExtensionField.get(types[i]);
if (name != null)
break;
}
if (name != null){
StringTokenizer st = new StringTokenizer(name, COLONCOLON);
fullName = new char[st.countTokens() + 1][];
int i=0;
while (st.hasMoreTokens()){
fullName[i] = st.nextToken().toCharArray();
i++;
}
fullName[i] = tempTag.elementName.toCharArray();
} else {
fullName = new char[1][];
fullName[0] = tempTag.elementName.toCharArray();
}
return fullName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.ctagsindexer.IConsoleParser#shutdown()
*/
public void shutdown() {
// TODO Auto-generated method stub
}
}

View file

@ -0,0 +1,157 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.internal.core.index.IDocument;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.IIndexer;
import org.eclipse.cdt.internal.core.index.IIndexerOutput;
import org.eclipse.cdt.internal.core.index.domsourceindexer.IndexEncoderUtil;
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
import org.eclipse.cdt.internal.core.index.impl.IndexedFile;
import org.eclipse.cdt.internal.core.search.indexing.IIndexConstants;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants.EntryType;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
public class CTagsFileReader {
String filename = null;
List list = null;
IProject project;
IIndex index;
public CTagsFileReader(IProject project,String filename) {
this.filename = filename;
this.project = project;
}
public void parse() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(filename));
CTagsHeader header = new CTagsHeader();
// Skip the header.
header.parse(reader);
String s;
String currentFileName = null;
IFile currentFile = null;
CTagsConsoleParser parser = new CTagsConsoleParser(null);
MiniIndexer indexer = null;
//Make sure we have an index before proceeding
if (index == null)
return;
while ((s = reader.readLine()) != null) {
CTagEntry tagEntry = parser.processLineReturnTag(s);
String fileName = tagEntry.fileName;
if (currentFileName == null ||
(!currentFileName.equals(fileName))){
currentFileName = fileName;
currentFile = (IFile) project.findMember(fileName);
indexer = new MiniIndexer(currentFile);
index.add(new IFileDocument(currentFile),indexer);
}
//encode new tag in current file
char[][] fullName = parser.getQualifiedName(tagEntry);
//encode name
indexer.addToOutput(fullName,(String)tagEntry.tagExtensionField.get(CTagsConsoleParser.KIND));
}
}
class MiniIndexer implements IIndexer, IIndexConstants {
IIndexerOutput output;
IFile currentFile;
/**
* @param currentFile
*/
public MiniIndexer(IFile currentFile) {
this.currentFile = currentFile;
}
public void addToOutput(char[][]fullName, String kind){
if (kind == null)
return;
IndexedFile mainIndexFile = this.output.getIndexedFile(currentFile.getFullPath().toString());
int fileNum = 0;
if (mainIndexFile != null)
fileNum = mainIndexFile.getFileNumber();
EntryType entryType = null;
ICSearchConstants.LimitTo type = ICSearchConstants.DECLARATIONS;
if (kind.equals(CTagsConsoleParser.CLASS)){
entryType = IIndexEncodingConstants.CLASS;
} else if (kind.equals(CTagsConsoleParser.MACRO)){
entryType = IIndexEncodingConstants.MACRO;
} else if (kind.equals(CTagsConsoleParser.ENUMERATOR)){
entryType = IIndexEncodingConstants.ENUMERATOR;
} else if (kind.equals(CTagsConsoleParser.FUNCTION)){
entryType = IIndexEncodingConstants.FUNCTION;
} else if (kind.equals(CTagsConsoleParser.ENUM)){
entryType = IIndexEncodingConstants.ENUM;
} else if (kind.equals(CTagsConsoleParser.MEMBER)){
entryType = IIndexEncodingConstants.FIELD;
} else if (kind.equals(CTagsConsoleParser.NAMESPACE)){
entryType = IIndexEncodingConstants.NAMESPACE;
} else if (kind.equals(CTagsConsoleParser.PROTOTYPE)){
entryType = IIndexEncodingConstants.FUNCTION;
} else if (kind.equals(CTagsConsoleParser.STRUCT)){
entryType = IIndexEncodingConstants.STRUCT;
} else if (kind.equals(CTagsConsoleParser.TYPEDEF)){
entryType = IIndexEncodingConstants.TYPEDEF;
} else if (kind.equals(CTagsConsoleParser.UNION)){
entryType = IIndexEncodingConstants.UNION;
} else if (kind.equals(CTagsConsoleParser.VARIABLE)){
entryType = IIndexEncodingConstants.VAR;
} else if (kind.equals(CTagsConsoleParser.EXTERNALVAR)){
}
if (entryType != null)
output.addRef(IndexEncoderUtil.encodeEntry(fullName,entryType,type), fileNum);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.IIndexer#index(org.eclipse.cdt.internal.core.index.IDocument, org.eclipse.cdt.internal.core.index.IIndexerOutput)
*/
public void index(IDocument document, IIndexerOutput output) throws IOException {
this.output = output;
this.output.addDocument(document);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.IIndexer#shouldIndex(org.eclipse.core.resources.IFile)
*/
public boolean shouldIndex(IFile file) {
return true;
}
}
/**
* @param index
*/
public void setIndex(IIndex index) {
this.index = index;
}
}

View file

@ -0,0 +1,102 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.IOException;
import java.io.BufferedReader;
public class CTagsHeader {
final static String TAG_FILE_FORMAT =
"!_TAG_FILE_FORMAT\t2\t/extended format; --format=1 will not append ;\" to lines/"; //$NON-NLS-1$
final static String TAG_FILE_SORTED =
"!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/"; //$NON-NLS-1$
final static String TAG_PROGRAM_AUTHOR =
"!_TAG_PROGRAM_AUTHOR\tDarren Hiebert\t/dhiebert@users.sourceforge.net/"; //$NON-NLS-1$
final static String TAG_PROGRAM_NAME =
"!_TAG_PROGRAM_NAME\tExuberant Ctags\t//"; //$NON-NLS-1$
final static String TAG_PROGRAM_URL =
"!_TAG_PROGRAM_URL\thttp://ctags.sourceforge.net\t/official site/"; //$NON-NLS-1$
final static String TAG_PROGRAM_VERSION =
"!_TAG_PROGRAM_VERSION\t5.5.4\t//"; //$NON-NLS-1$
/* information about the structure of the tag file */
final String TAGS_PREFIX = "!_"; //$NON-NLS-1$
/* Format of tag file (1 = original, 2 = extended) */
String format;
/* Is the tag file sorted? (0 = unsorted, 1 = sorted) */
String sorted;
/* Information about the program which created this tag file */
/* Name of author of generating program (may be null) */
String author;
/* Name of program (may be null) */
String name;
/* URL of distribution (may be null) */
String url;
/* program version (may be null) */
String version;
void parse (BufferedReader in) throws IOException {
// !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
format = in.readLine();
//If we care about verifying header info we can put this back in
/*if (format == null || !format.equals(TAG_FILE_FORMAT)) {
throw new IOException("Wrong Tag Format Header");
}*/
// !_TAG_FILE_SORTED 0 /0=unsorted, 1=sorted/
sorted = in.readLine();
/*if (sorted == null || !sorted.equals(TAG_FILE_SORTED)) {
throw new IOException("Wrong Tag Format Header");
}*/
// !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
author = in.readLine();
/*if (author == null || !author.equals(TAG_PROGRAM_AUTHOR)) {
throw new IOException("Wrong Tag Format Header");
}*/
// !_TAG_PROGRAM_NAME Exuberant Ctags //
name = in.readLine();
/*if (name == null || !name.equals(TAG_PROGRAM_NAME)) {
throw new IOException("Wrong Tag Format Header");
}*/
// !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
url = in.readLine();
/*if (url == null || !url.equals(TAG_PROGRAM_URL)) {
throw new IOException("Wrong Tag Format Header");
}*/
// !_TAG_PROGRAM_VERSION 5.2.3 //
version = in.readLine();
/*if (version == null || !version.equals(TAG_PROGRAM_VERSION)) {
throw new IOException("Wrong Tag Format Header");
}*/
}
public String getHeader() {
return format + "\n" + sorted + "\n" + //$NON-NLS-1$//$NON-NLS-2$
author + "\n" + name + "\n" + //$NON-NLS-1$//$NON-NLS-2$
url + "\n" + version + "\n"; //$NON-NLS-1$//$NON-NLS-2$
}
}

View file

@ -0,0 +1,212 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.File;
import java.io.IOException;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.IQueryResult;
import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.cdt.internal.core.index.sourceindexer.CIndexStorage;
import org.eclipse.cdt.internal.core.search.SimpleLookupTable;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
/**
* @author Bogdan Gheorghe
*/
class CTagsIndexAll extends CTagsIndexRequest {
IProject project;
static String ctagsFile = CCorePlugin.getDefault().getStateLocation().toOSString() + "\\tempctags"; //$NON-NLS-1$
public CTagsIndexAll(IProject project, CTagsIndexer indexer) {
super(project.getFullPath(), indexer);
this.project = project;
}
public boolean equals(Object o) {
if (o instanceof CTagsIndexAll)
return this.project.equals(((CTagsIndexAll) o).project);
return false;
}
/**
* Ensure consistency of a project index. Need to walk all nested resources,
* and discover resources which have either been changed, added or deleted
* since the index was produced.
*/
public boolean execute(IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
if (!project.isAccessible()) return true; // nothing to do
String test = this.indexPath.toOSString();
IIndex index = indexer.getIndex(this.indexPath, true, /*reuse index file*/ true /*create if none*/);
if (index == null) return true;
ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
monitor.enterRead(); // ask permission to read
saveIfNecessary(index, monitor);
IQueryResult[] results = index.queryInDocumentNames(""); // all file names //$NON-NLS-1$
int max = results == null ? 0 : results.length;
final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11);
final String OK = "OK"; //$NON-NLS-1$
final String DELETED = "DELETED"; //$NON-NLS-1$
for (int i = 0; i < max; i++)
indexedFileNames.put(results[i].getPath(), DELETED);
project.accept( new IResourceProxyVisitor() {
public boolean visit(IResourceProxy proxy) throws CoreException {
switch(proxy.getType()){
case IResource.FILE:
IResource resource=proxy.requestResource();
indexedFileNames.put(resource.getFullPath().toString(), resource);
return false;
}
return true;
}},IResource.NONE);
/*Object[] names = indexedFileNames.keyTable;
Object[] values = indexedFileNames.valueTable;
boolean shouldSave = false;
for (int i = 0, length = names.length; i < length; i++) {
String name = (String) names[i];
if (name != null) {
if (this.isCancelled) return false;
Object value = values[i];
if (value != OK) {
shouldSave = true;
if (value == DELETED)
indexer.remove(name, this.indexPath);
else
indexer.addSource((IFile) value, this.indexPath);
}
}
}*/
//Timing support
long startTime=0, cTagsEndTime=0, endTime=0;
if (AbstractIndexer.TIMING)
startTime = System.currentTimeMillis();
//run CTags over project
boolean success = runCTags();
if (AbstractIndexer.TIMING){
cTagsEndTime = System.currentTimeMillis();
System.out.println("CTags Run: " + (cTagsEndTime - startTime)); //$NON-NLS-1$
}
if (success) {
//Parse the CTag File
CTagsFileReader reader = new CTagsFileReader(project,ctagsFile);
reader.setIndex(index);
reader.parse();
// request to save index when all cus have been indexed
indexer.request(new CTagsSaveIndex(this.indexPath, indexer));
if (AbstractIndexer.TIMING){
endTime = System.currentTimeMillis();
System.out.println("CTags Encoding Time: " + (endTime - cTagsEndTime)); //$NON-NLS-1$
System.out.println("CTagsIndexer Total Time: " + (endTime - startTime)); //$NON-NLS-1$
}
}
} catch (CoreException e) {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> failed to index " + this.project + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
e.printStackTrace();
}
indexer.removeIndex(this.indexPath);
return false;
} catch (IOException e) {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> failed to index " + this.project + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
e.printStackTrace();
}
indexer.removeIndex(this.indexPath);
return false;
} finally {
monitor.exitRead(); // free read lock
}
return true;
}
/**
* @return
*/
private boolean runCTags() {
String[] args = {"ctags", //$NON-NLS-1$
"--excmd=number", //$NON-NLS-1$
"--format=2", //$NON-NLS-1$
"--sort=no", //$NON-NLS-1$
"--fields=aiKlmnsz", //$NON-NLS-1$
"--c-types=cdefgmnpstuvx", //$NON-NLS-1$
"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
"--languages=c,c++", //$NON-NLS-1$
"-f",ctagsFile,"-R"}; //$NON-NLS-1$ //$NON-NLS-2$
try{
//Make sure that there is no ctags file leftover in the metadata
File tagsFile = new File(ctagsFile);
if (tagsFile.exists()){
tagsFile.delete();
}
CommandLauncher launcher = new CommandLauncher();
// Print the command for visual interaction.
launcher.showCommand(true);
IPath fileDirectory = project.getLocation();
//Process p = launcher.execute(fCompileCommand, args, setEnvironment(launcher), fWorkingDirectory);
Process p = launcher.execute(new Path(""), args, null, fileDirectory); //$NON-NLS-1$
p.waitFor();
} catch (InterruptedException e) {
return false;
}
return true;
}
public int hashCode() {
return this.project.hashCode();
}
protected Integer updatedIndexState() {
return CIndexStorage.REBUILDING_STATE;
}
public String toString() {
return "indexing project " + this.project.getFullPath(); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,79 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.IOException;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.sourceindexer.CIndexStorage;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
/**
* @author Bogdan Gheorghe
*/
public abstract class CTagsIndexRequest implements IIndexJob {
protected boolean isCancelled = false;
protected IPath indexPath = null;
protected CTagsIndexer indexer = null;
public CTagsIndexRequest(IPath indexPath, CTagsIndexer indexer) {
this.indexPath = indexPath;
this.indexer = indexer;
}
public boolean belongsTo(String projectName) {
return projectName.equals(this.indexPath.segment(0));
}
public void cancel() {
this.indexer.jobFinishedNotification( this );
this.indexer.jobWasCancelled(this.indexPath);
this.isCancelled = true;
}
public boolean isReadyToRun() {
IProject project = CCorePlugin.getWorkspace().getRoot().getProject(indexPath.segment(0));
if ( !project.isAccessible() || !this.indexer.isIndexEnabled( project ) )
return false;
// tag the index as inconsistent
indexer.aboutToUpdateIndex(indexPath, updatedIndexState());
return true;
}
/*
* This code is assumed to be invoked while monitor has read lock
*/
protected void saveIfNecessary(IIndex index, ReadWriteMonitor monitor) throws IOException {
/* if index has changed, commit these before querying */
if (index.hasChanged()) {
try {
monitor.exitRead(); // free read lock
monitor.enterWrite(); // ask permission to write
indexer.saveIndex(index);
} finally {
monitor.exitWriteEnterRead(); // finished writing and reacquire read permission
}
}
}
protected Integer updatedIndexState() {
return CIndexStorage.UPDATING_STATE;
}
public IPath getIndexPath(){
return indexPath;
}
}

View file

@ -0,0 +1,324 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.IOException;
import java.util.HashSet;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.index.IIndexStorage;
import org.eclipse.cdt.internal.core.index.IDocument;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.IIndexerOutput;
import org.eclipse.cdt.internal.core.index.sourceindexer.CIndexStorage;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.IIndexJob;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.IPath;
/**
* @author Bogdan Gheorghe
*/
public class CTagsIndexer extends AbstractCExtension implements ICDTIndexer {
private CIndexStorage indexStorage = null;
public ReadWriteMonitor storageMonitor = null;
private IndexManager indexManager = null;
private HashSet jobSet = null;
public CTagsIndexer(){
this.indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
this.indexStorage = (CIndexStorage) indexManager.getIndexStorageForIndexer(this);
this.jobSet = new HashSet();
this.storageMonitor = new ReadWriteMonitor();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index.ICDTIndexer#getIndexerFeatures()
*/
public int getIndexerFeatures() {
// TODO Auto-generated method stub
return 0;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index.ICDTIndexer#addRequest(org.eclipse.cdt.core.model.ICElement, org.eclipse.core.resources.IResourceDelta)
*/
public void addRequest(IProject project, IResourceDelta delta, int kind) {
switch (kind) {
/*
case ICDTIndexer.PROJECT:
this.indexAll(element.getCProject().getProject());
break;
case ICDTIndexer.FOLDER:
this.indexSourceFolder(element.getCProject().getProject(),element.getPath(),null);
break;
*/
case ICDTIndexer.COMPILATION_UNIT:
IFile file = (IFile) delta.getResource();
this.addSource(file, project.getFullPath());
break;
default:
this.indexAll(project);
break;
}
}
/**
* @param project
*/
public void indexAll(IProject project) {
CTagsIndexRequest request = new CTagsIndexAll(project, this);
for (int i = indexManager.getJobEnd(); i > indexManager.getJobStart(); i--) // NB: don't check job at jobStart, as it may have already started (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32488)
if (request.equals(indexManager.getAwaitingJobAt(i))) return;
indexManager.request(request);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index.ICDTIndexer#removeRequest(org.eclipse.cdt.core.model.ICElement, org.eclipse.core.resources.IResourceDelta)
*/
public void removeRequest(IProject project, IResourceDelta delta, int kind) {
switch (kind) {
/*
case ICDTIndexer.PROJECT:
this.indexAll(element.getCProject().getProject());
break;
case ICDTIndexer.FOLDER:
this.indexSourceFolder(element.getCProject().getProject(),element.getPath(),null);
break;
*/
case ICDTIndexer.COMPILATION_UNIT:
break;
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index.ICDTIndexer#indexJobFinishedNotification(org.eclipse.cdt.internal.core.search.processing.IIndexJob)
*/
public void indexJobFinishedNotification(IIndexJob job) {
((CIndexStorage)indexStorage).setNeedToSave(true);
if (job instanceof CTagsAddCompilationUnitToIndex){
CTagsAddCompilationUnitToIndex tempJob = (CTagsAddCompilationUnitToIndex) job;
jobSet.remove(tempJob.getResource().getLocation());
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index.ICDTIndexer#shutdown()
*/
public void shutdown() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index.ICDTIndexer#notifyIdle(long)
*/
public void notifyIdle(long idlingTime) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.IIndexer#index(org.eclipse.cdt.internal.core.index.IDocument, org.eclipse.cdt.internal.core.index.IIndexerOutput)
*/
public void index(IDocument document, IIndexerOutput output)
throws IOException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.IIndexer#shouldIndex(org.eclipse.core.resources.IFile)
*/
public boolean shouldIndex(IFile file) {
// TODO Auto-generated method stub
return false;
}
/**
* @param path
* @param reuseIndexFile
* @param createIfMissing
* @return
*/
public synchronized IIndex getIndex(IPath path, boolean reuseExistingFile, boolean createIfMissing) {
IIndex index = null;
try{
storageMonitor.enterRead();
index = indexStorage.getIndex(path,reuseExistingFile, createIfMissing);
}
finally{
storageMonitor.exitRead();
}
return index;
}
/**
* @param index
* @return
*/
public ReadWriteMonitor getMonitorFor(IIndex index) {
ReadWriteMonitor monitor = null;
try{
storageMonitor.enterRead();
monitor=indexStorage.getMonitorFor(index);
}
finally{
storageMonitor.exitRead();
}
return monitor;
}
/**
* @param index
*/
public void saveIndex(IIndex index) throws IOException {
try{
storageMonitor.enterWrite();
indexStorage.saveIndex(index);
}
finally {
storageMonitor.exitWrite();
}
}
/**
* Forward job request to Index Manager
* @param cleanHeaders
*/
public void request(IIndexJob indexJob) {
this.indexManager.request(indexJob);
}
/**
* @param indexPath
* @param integer
*/
public void aboutToUpdateIndex(IPath indexPath, Integer indexState) {
indexStorage.aboutToUpdateIndex(indexPath, indexState);
}
/**
* @param project
* @return
*/
public boolean isIndexEnabled(IProject project) {
//Return true for now
return true;
}
/**
* @param path
*/
public void jobWasCancelled(IPath path) {
try{
storageMonitor.enterWrite();
indexStorage.jobWasCancelled(path);
}
finally{
storageMonitor.exitWrite();
}
}
/**
* @param request
*/
public void jobFinishedNotification(CTagsIndexRequest request) {
this.indexJobFinishedNotification(request);
}
/**
* @param path
*/
public void removeIndex(IPath path) {
try{
storageMonitor.enterWrite();
indexStorage.removeIndex(path);
}
finally{
storageMonitor.exitWrite();
}
}
/**
* Trigger removal of a resource to an index
* Note: the actual operation is performed in background
*/
public void remove(String resourceName, IPath indexedContainer){
IProject project = CCorePlugin.getWorkspace().getRoot().getProject(indexedContainer.toString());
if( isIndexEnabled( project ) )
request(new CTagsRemoveFromIndex(resourceName, indexedContainer, this));
}
/**
* @param file
* @param path
*/
public void addSource(IFile resource, IPath indexedContainers) {
IProject project = resource.getProject();
boolean indexEnabled = false;
if (project != null)
indexEnabled = isIndexEnabled(project);
else
org.eclipse.cdt.internal.core.model.Util.log(null, "CTagsIndexer addSource: File has no project associated : " + resource.getName(), ICLogConstants.CDT); //$NON-NLS-1$
if (CCorePlugin.getDefault() == null) return;
if (indexEnabled){
CTagsAddCompilationUnitToIndex job = new CTagsAddCompilationUnitToIndex(resource, indexedContainers, this);
//If we are in WAITING mode, we need to kick ourselves into enablement
if (!jobSet.add(resource.getLocation()) &&
indexManager.enabledState()==IndexManager.ENABLED)
return;
if (indexManager.awaitingJobsCount() < CIndexStorage.MAX_FILES_IN_MEMORY) {
// reduces the chance that the file is open later on, preventing it from being deleted
if (!job.initializeContents()) return;
}
this.indexManager.request(job);
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index.ICDTIndexer#getIndexStorage()
*/
public IIndexStorage getIndexStorage() {
return indexStorage;
}
}

View file

@ -0,0 +1,136 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.IOException;
import java.io.OutputStream;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.core.IConsoleParser;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
import org.eclipse.cdt.internal.core.index.IDocument;
import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
/**
* @author Bogdan Gheorghe
*/
public class CTagsIndexerRunner extends AbstractIndexer {
IFile resourceFile;
private CTagsIndexer indexer;
/**
* @param resource
* @param indexer
*/
public CTagsIndexerRunner(IFile resource, CTagsIndexer indexer) {
this.resourceFile = resource;
this.indexer = indexer;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#getResourceFile()
*/
public IFile getResourceFile() {
return resourceFile;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#indexFile(org.eclipse.cdt.internal.core.index.IDocument)
*/
protected void indexFile(IDocument document) throws IOException {
output.addDocument(document);
String[] args = {"ctags", //$NON-NLS-1$
"--excmd=number", //$NON-NLS-1$
"--format=2", //$NON-NLS-1$
"--sort=no", //$NON-NLS-1$
"--fields=aiKlmnsz", //$NON-NLS-1$
"--c-types=cdefgmnpstuvx", //$NON-NLS-1$
"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
"--languages=c,c++", //$NON-NLS-1$
"-f", "-", resourceFile.getName()}; //$NON-NLS-1$ //$NON-NLS-2$
try {
IConsole console = CCorePlugin.getDefault().getConsole(null);
console.start(resourceFile.getProject());
OutputStream cos = console.getOutputStream();
String errMsg = null;
CommandLauncher launcher = new CommandLauncher();
// Print the command for visual interaction.
launcher.showCommand(true);
long startTime=0;
if (AbstractIndexer.TIMING)
startTime = System.currentTimeMillis();
CTagsConsoleParser parser = new CTagsConsoleParser(this);
IConsoleParser[] parsers = { parser };
ConsoleOutputSniffer sniffer = new ConsoleOutputSniffer(parsers);
OutputStream consoleOut = (sniffer == null ? cos : sniffer.getOutputStream());
OutputStream consoleErr = (sniffer == null ? cos : sniffer.getErrorStream());
IPath fileDirectory = resourceFile.getRawLocation().removeLastSegments(1);
//Process p = launcher.execute(fCompileCommand, args, setEnvironment(launcher), fWorkingDirectory);
Process p = launcher.execute(new Path(""), args, null, fileDirectory); //$NON-NLS-1$
if (p != null) {
try {
// Close the input of the Process explicitely.
// We will never write to it.
p.getOutputStream().close();
} catch (IOException e) {
}
if (launcher.waitAndRead(consoleOut, consoleErr, new NullProgressMonitor()) != CommandLauncher.OK) {
errMsg = launcher.getErrorMessage();
}
}
else {
errMsg = launcher.getErrorMessage();
}
if (errMsg != null) {
System.out.println(errMsg);
}
consoleOut.close();
consoleErr.close();
cos.close();
if (AbstractIndexer.TIMING){
System.out.println("CTagsIndexer Total Time: " + (System.currentTimeMillis() - startTime)); //$NON-NLS-1$
}
}
catch (Exception e) {
CCorePlugin.log(e);
}
finally {
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer#addMarkers(org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile, java.lang.Object)
*/
protected void addMarkers(IFile tempFile, IFile originator, Object problem) {
// TODO Auto-generated method stub
}
}

View file

@ -0,0 +1,61 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.IOException;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* @author Bogdan Gheorghe
*/
public class CTagsRemoveFromIndex extends CTagsIndexRequest {
String resourceName;
public CTagsRemoveFromIndex(String resourceName, IPath indexPath, CTagsIndexer indexer) {
super(indexPath, indexer);
this.resourceName = resourceName;
}
public boolean execute(IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
/* ensure no concurrent write access to index */
IIndex index = indexer.getIndex(this.indexPath, true, /*reuse index file*/ false /*create if none*/);
if (index == null) return true;
ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
monitor.enterWrite(); // ask permission to write
index.remove(resourceName);
} catch (IOException e) {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> failed to remove " + this.resourceName + " from index because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
e.printStackTrace();
}
return false;
} finally {
monitor.exitWrite(); // free write lock
}
return true;
}
public String toString() {
return "removing " + this.resourceName + " from index " + this.indexPath; //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -0,0 +1,57 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.internal.core.index.ctagsindexer;
import java.io.IOException;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
import org.eclipse.cdt.internal.core.search.processing.JobManager;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* @author Bogdan Gheorghe
*/
public class CTagsSaveIndex extends CTagsIndexRequest {
public CTagsSaveIndex(IPath indexPath, CTagsIndexer indexer) {
super(indexPath, indexer);
}
public boolean execute(IProgressMonitor progressMonitor) {
if (progressMonitor != null && progressMonitor.isCanceled()) return true;
/* ensure no concurrent write access to index */
IIndex index = indexer.getIndex(this.indexPath, true /*reuse index file*/, false /*don't create if none*/);
if (index == null) return true;
ReadWriteMonitor monitor = indexer.getMonitorFor(index);
if (monitor == null) return true; // index got deleted since acquired
try {
monitor.enterWrite(); // ask permission to write
indexer.saveIndex(index);
} catch (IOException e) {
if (IndexManager.VERBOSE) {
JobManager.verbose("-> failed to save index " + this.indexPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$
e.printStackTrace();
}
return false;
} finally {
monitor.exitWrite(); // free write lock
}
return true;
}
public String toString() {
return "saving index for " + this.indexPath; //$NON-NLS-1$
}
}

View file

@ -25,7 +25,6 @@ import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.internal.core.index.IDocument;
import org.eclipse.cdt.internal.core.index.IIndexerOutput;
import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IIndexEncodingConstants;
@ -57,10 +56,6 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
this.indexer = indexer;
}
public IIndexerOutput getOutput() {
return output;
}
public IFile getResourceFile() {
return resourceFile;
}
@ -87,10 +82,18 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
ParserLanguage.CPP : ParserLanguage.C;
try {
long startTime = 0, parseTime = 0, endTime = 0;
if (AbstractIndexer.TIMING)
startTime = System.currentTimeMillis();
IASTTranslationUnit tu = CDOM.getInstance().getASTService().getTranslationUnit(
resourceFile,
CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES));
if (AbstractIndexer.TIMING)
parseTime = System.currentTimeMillis();
// TODO Use new method to get ordered include directives instead of
// IASTTranslationUnit.getIncludeDirectives
processIncludeDirectives(tu.getIncludeDirectives());
@ -102,8 +105,15 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
} else {
visitor = new CGenerateIndexVisitor(this, resourceFile);
}
tu.accept(visitor);
if (AbstractIndexer.TIMING){
endTime = System.currentTimeMillis();
System.out.println("DOM Indexer - Total Parse Time for " + resourceFile.getName() + ": " + (parseTime - startTime)); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println("DOM Indexer - Total Visit Time for " + resourceFile.getName() + ": " + (endTime - parseTime)); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println("DOM Indexer - Total Index Time for " + resourceFile.getName() + ": " + (endTime - startTime)); //$NON-NLS-1$ //$NON-NLS-2$
}
if (AbstractIndexer.VERBOSE){
AbstractIndexer.verbose("DOM AST TRAVERSAL FINISHED " + resourceFile.getName().toString()); //$NON-NLS-1$
}

View file

@ -25,7 +25,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Path;
public class IndexEncoderUtil {
static final char[] encodeEntry(char[][] elementName, EntryType entryType, LimitTo encodeType) {
public static final char[] encodeEntry(char[][] elementName, EntryType entryType, LimitTo encodeType) {
int pos, nameLength = 0;
for (int i=0; i < elementName.length; i++){
char[] namePart = elementName[i];

View file

@ -57,11 +57,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSearchConstants {
protected static final String INDEXER_MARKER_PREFIX = Util.bind("indexerMarker.prefix" ) + " "; //$NON-NLS-1$ //$NON-NLS-2$
protected static final String INDEXER_MARKER_ORIGINATOR = ICModelMarker.INDEXER_MARKER + ".originator"; //$NON-NLS-1$
private static final String INDEXER_MARKER_PROCESSING = Util.bind( "indexerMarker.processing" ); //$NON-NLS-1$
protected IIndexerOutput output;
final static int CLASS = 1;
final static int STRUCT = 2;
final static int UNION = 3;
@ -75,10 +71,17 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
final static int FWD_UNION = 11;
public static boolean VERBOSE = false;
public static boolean TIMING = false;
// problem marker related
protected IIndexerOutput output;
//Index Markers
private int problemMarkersEnabled = 0;
private Map problemsMap = null;
protected static final String INDEXER_MARKER_PREFIX = Util.bind("indexerMarker.prefix" ) + " "; //$NON-NLS-1$ //$NON-NLS-2$
protected static final String INDEXER_MARKER_ORIGINATOR = ICModelMarker.INDEXER_MARKER + ".originator"; //$NON-NLS-1$
private static final String INDEXER_MARKER_PROCESSING = Util.bind( "indexerMarker.processing" ); //$NON-NLS-1$
//IDs defined in plugin.xml for file types
private final static String C_SOURCE_ID = "org.eclipse.cdt.core.fileType.c_source"; //$NON-NLS-1$
@ -86,6 +89,7 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
private final static String CPP_SOURCE_ID = "org.eclipse.cdt.core.fileType.cxx_source"; //$NON-NLS-1$
private final static String CPP_HEADER_ID = "org.eclipse.cdt.core.fileType.cxx_header"; //$NON-NLS-1$
public AbstractIndexer() {
super();
}
@ -94,6 +98,11 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
System.out.println("(" + Thread.currentThread() + ") " + log); //$NON-NLS-1$//$NON-NLS-2$
}
public IIndexerOutput getOutput() {
return output;
}
public void addClassSpecifier(IASTClassSpecifier classSpecification, int indexFlag){
if (classSpecification.getClassKind().equals(ASTClassKind.CLASS))
@ -863,6 +872,8 @@ public abstract class AbstractIndexer implements IIndexer,IIndexConstants, ICSea
this.output.addRef(encodeEntry(incName, INCLUDE_REF, INCLUDE_REF_LENGTH),fileNumber);
}
abstract private class Problem {
public IFile file;
public IFile originator;

View file

@ -72,15 +72,13 @@ public class CIndexStorage implements IIndexStorage {
public static boolean VERBOSE = false;
private SourceIndexer indexer = null;
private ICDTIndexer indexer = null;
private IndexManager indexManager = null;
public ReadWriteMonitor indexAccessMonitor = null;
public CIndexStorage(ICDTIndexer indexer){
if (indexer instanceof SourceIndexer)
this.indexer = (SourceIndexer) indexer;
this.indexer = indexer;
this.indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager();
}
@ -244,7 +242,8 @@ public class CIndexStorage implements IIndexStorage {
if (target instanceof IProject) {
IProject p = (IProject) target;
if( p.exists() && indexer.isIndexEnabled( p ) )
request = new IndexAllProject(p, indexer);
//request = new IndexAllProject(p, indexer);
indexer.addRequest(p, null, ICDTIndexer.PROJECT);
}
if (request != null)

View file

@ -25,7 +25,6 @@ import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.index.IIndexChangeListener;
import org.eclipse.cdt.core.index.IIndexStorage;
import org.eclipse.cdt.core.index.IndexChangeEvent;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.Util;
@ -105,7 +104,7 @@ public class SourceIndexer extends AbstractCExtension implements ICDTIndexer {
/**
* @return
*/
private IIndexStorage getIndexStorage() {
public IIndexStorage getIndexStorage() {
return indexStorage;
}
@ -459,21 +458,20 @@ public class SourceIndexer extends AbstractCExtension implements ICDTIndexer {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index2.IIndexer#addRequest(org.eclipse.cdt.core.model.ICElement, org.eclipse.core.resources.IResourceDelta, org.eclipse.core.resources.IResourceChangeEvent)
*/
public void addRequest(ICElement element, IResourceDelta delta) {
public void addRequest(IProject project, IResourceDelta delta, int kind) {
switch (element.getElementType()) {
case ICElement.C_PROJECT :
this.indexAll(element.getCProject().getProject());
switch (kind) {
case ICDTIndexer.PROJECT :
this.indexAll(project);
break;
case ICElement.C_CCONTAINER:
this.indexSourceFolder(element.getCProject().getProject(),element.getPath(),null);
case ICDTIndexer.FOLDER :
this.indexSourceFolder(project,project.getFullPath(),null);
break;
case ICElement.C_UNIT:
case ICDTIndexer.COMPILATION_UNIT:
IFile file = (IFile) delta.getResource();
IProject filesProject = file.getProject();
this.addSource(file, filesProject.getFullPath());
this.addSource(file, project.getFullPath());
break;
}
@ -483,10 +481,10 @@ public class SourceIndexer extends AbstractCExtension implements ICDTIndexer {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.index2.IIndexer#removeRequest(org.eclipse.cdt.core.model.ICElement, org.eclipse.core.resources.IResourceDelta, org.eclipse.core.resources.IResourceChangeEvent)
*/
public void removeRequest(ICElement element, IResourceDelta delta) {
switch (element.getElementType()) {
case ICElement.C_PROJECT :
IPath fullPath = element.getCProject().getProject().getFullPath();
public void removeRequest(IProject project, IResourceDelta delta, int kind) {
switch (kind) {
case ICDTIndexer.PROJECT :
IPath fullPath = project.getFullPath();
if( delta.getKind() == IResourceDelta.CHANGED )
indexManager.discardJobs(fullPath.segment(0));
indexStorage.removeIndexFamily(fullPath);
@ -495,11 +493,11 @@ public class SourceIndexer extends AbstractCExtension implements ICDTIndexer {
// NB: Update of index if project is opened, closed, or its c nature is added or removed
// is done in updateCurrentDeltaAndIndex
case ICElement.C_CCONTAINER:
this.removeSourceFolderFromIndex(element.getCProject().getProject(),element.getPath(),null);
case ICDTIndexer.FOLDER :
this.removeSourceFolderFromIndex(project,project.getFullPath(),null);
break;
case ICElement.C_UNIT:
case ICDTIndexer.COMPILATION_UNIT:
IFile file = (IFile) delta.getResource();
this.remove(file.getFullPath().toString(), file.getProject().getFullPath());
break;

View file

@ -112,8 +112,17 @@ public class SourceIndexerRunner extends AbstractIndexer {
}
try{
long startTime = 0;
if (AbstractIndexer.TIMING)
startTime = System.currentTimeMillis();
boolean retVal = parser.parse();
if (AbstractIndexer.TIMING){
System.out.println("Source Indexer - Total Index Time: " + (System.currentTimeMillis() - startTime)); //$NON-NLS-1$
}
if (AbstractIndexer.VERBOSE){
if (!retVal)
AbstractIndexer.verbose("PARSE FAILED " + resourceFile.getName().toString()); //$NON-NLS-1$

View file

@ -19,7 +19,7 @@ import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.index.IIndexStorage;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.index.ctagsindexer.CTagsIndexRequest;
import org.eclipse.cdt.internal.core.index.sourceindexer.CIndexStorage;
import org.eclipse.cdt.internal.core.index.sourceindexer.IndexRequest;
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
@ -89,18 +89,29 @@ public class IndexManager extends JobManager{
if (indexer != null)
indexer.indexJobFinishedNotification(job);
}
//TODO: Standardize on jobs
if (job instanceof CTagsIndexRequest){
CTagsIndexRequest indexRequest = (CTagsIndexRequest) job;
IPath path = indexRequest.getIndexPath();
IProject project= ResourcesPlugin.getWorkspace().getRoot().getProject(path.toOSString());
ICDTIndexer indexer = getIndexerForProject(project);
if (indexer != null)
indexer.indexJobFinishedNotification(job);
}
}
/**
* @param project
* @param element
* @param delta
*/
public void addResourceEvent(IProject project, ICElement element, IResourceDelta delta) {
public void addResourceEvent(IProject project, IResourceDelta delta, int kind) {
//Get indexer for this project
ICDTIndexer indexer = getIndexerForProject(project);
if (indexer != null)
indexer.addRequest(element, delta);
indexer.addRequest(project, delta, kind);
}
/**
@ -108,13 +119,13 @@ public class IndexManager extends JobManager{
* @param element
* @param delta
*/
public void removeResourceEvent(IProject project, ICElement element, IResourceDelta delta) {
public void removeResourceEvent(IProject project, IResourceDelta delta, int kind) {
//Get the indexer for this project
ICDTIndexer indexer = null;
indexer = (ICDTIndexer) indexerMap.get(project);
if (indexer != null)
indexer.removeRequest(element, delta);
indexer.removeRequest(project, delta, kind);
}
@ -311,4 +322,20 @@ public class IndexManager extends JobManager{
monitor.exitRead();
}
}
/**
* The indexer previously associated with this project has been changed to a
* new value. Next time project gets asked for indexer, a new one will be created
* of the new type.
*
* @param project
*/
public void indexerChangeNotification(IProject project) {
monitor.enterWrite();
try{
Object e = indexerMap.remove(project);
} finally {
monitor.exitWrite();
}
}
}

View file

@ -5,6 +5,7 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved.
*/
import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IArchive;
@ -607,7 +608,21 @@ public class DeltaProcessor {
if (indexManager == null)
return;
indexManager.addResourceEvent(element.getCProject().getProject(),element,delta);
switch (element.getElementType()){
case ICElement.C_PROJECT:
indexManager.addResourceEvent(element.getCProject().getProject(),delta, ICDTIndexer.PROJECT);
break;
case ICElement.C_CCONTAINER:
indexManager.addResourceEvent(element.getCProject().getProject(),delta, ICDTIndexer.FOLDER);
break;
case ICElement.C_UNIT:
indexManager.addResourceEvent(element.getCProject().getProject(),delta, ICDTIndexer.COMPILATION_UNIT);
break;
}
}
@ -616,8 +631,20 @@ public class DeltaProcessor {
if (indexManager == null)
return;
indexManager.removeResourceEvent(element.getCProject().getProject(),element,delta);
switch (element.getElementType()){
case ICElement.C_PROJECT:
indexManager.removeResourceEvent(element.getCProject().getProject(),delta, ICDTIndexer.PROJECT);
break;
case ICElement.C_CCONTAINER:
indexManager.removeResourceEvent(element.getCProject().getProject(),delta, ICDTIndexer.FOLDER);
break;
case ICElement.C_UNIT:
indexManager.removeResourceEvent(element.getCProject().getProject(),delta, ICDTIndexer.COMPILATION_UNIT);
break;
}
}

View file

@ -560,5 +560,15 @@
description="%cdt_pathentry_var.description">
</variable>
</extension>
<extension
id="ctagsindexer"
name="CTags Indexer"
point="org.eclipse.cdt.core.CIndexer">
<cextension>
<run
class="org.eclipse.cdt.internal.core.index.ctagsindexer.CTagsIndexer">
</run>
</cextension>
</extension>
</plugin>

View file

@ -1,3 +1,6 @@
2005-03-28 Bogdan Gheorghe
Modified IndexSelector and PatternSearchJob to work with all 3 indexers.
2005-03-12 Bogdan Gheorghe
Updated search to work with new index framework

View file

@ -18,6 +18,7 @@ import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.ctagsindexer.CTagsIndexer;
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IWorkspaceRoot;
@ -101,6 +102,10 @@ public class IndexSelector {
SourceIndexer sourceIndexer = (SourceIndexer) indexer;
index =sourceIndexer.getIndex(indexKeys[i], true /*reuse index file*/, false /*do not create if none*/);
}
else if (indexer instanceof CTagsIndexer){
CTagsIndexer ctagsIndexer = (CTagsIndexer) indexer;
index =ctagsIndexer.getIndex(indexKeys[i], true /*reuse index file*/, false /*do not create if none*/);
}
}
if (index != null) indexes[count++] = index; // only consider indexes which are ready yet
}

View file

@ -16,10 +16,12 @@ package org.eclipse.cdt.internal.core.search;
import java.io.IOException;
import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.index.IIndexStorage;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.impl.Index;
import org.eclipse.cdt.internal.core.index.sourceindexer.CIndexStorage;
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
@ -138,11 +140,12 @@ public class PatternSearchJob implements IIndexJob {
ICDTIndexer indexer =((Index) index).getIndexer();
if (!(indexer instanceof SourceIndexer))
IIndexStorage storage = indexer.getIndexStorage();
if (!(storage instanceof CIndexStorage))
return FAILED;
SourceIndexer sourceIndexer = (SourceIndexer) indexer;
ReadWriteMonitor monitor = sourceIndexer.getMonitorFor(index);
CIndexStorage cStorage = (CIndexStorage) storage;
ReadWriteMonitor monitor = cStorage.getMonitorFor(index);
if (monitor == null)
return COMPLETE; // index got deleted since acquired
try {
@ -153,7 +156,7 @@ public class PatternSearchJob implements IIndexJob {
try {
monitor.exitRead(); // free read lock
monitor.enterWrite(); // ask permission to write
sourceIndexer.saveIndex(index);
cStorage.saveIndex(index);
} catch (IOException e) {
return FAILED;
} finally {

View file

@ -864,6 +864,7 @@ public class CCorePlugin extends Plugin {
private static final String MODEL = CCorePlugin.PLUGIN_ID + "/debug/model" ; //$NON-NLS-1$
private static final String INDEXER = CCorePlugin.PLUGIN_ID + "/debug/indexer"; //$NON-NLS-1$
private static final String INDEX_MANAGER = CCorePlugin.PLUGIN_ID + "/debug/indexmanager"; //$NON-NLS-1$
private static final String INDEXER_TIMES = CCorePlugin.PLUGIN_ID + "/debug/indextimes"; //$NON-NLS-1$
private static final String SEARCH = CCorePlugin.PLUGIN_ID + "/debug/search" ; //$NON-NLS-1$
private static final String MATCH_LOCATOR = CCorePlugin.PLUGIN_ID + "/debug/matchlocator" ; //$NON-NLS-1$
private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$
@ -897,6 +898,9 @@ public class CCorePlugin extends Plugin {
option = Platform.getDebugOption(INDEXER);
if(option != null) AbstractIndexer.VERBOSE = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
option = Platform.getDebugOption(INDEXER_TIMES);
if (option != null) AbstractIndexer.TIMING = option.equalsIgnoreCase("true"); //$NON-NLS-1$
option = Platform.getDebugOption(SEARCH);
if(option != null) SearchEngine.VERBOSE = option.equalsIgnoreCase("true") ; //$NON-NLS-1$

View file

@ -1,3 +1,10 @@
2005-03-28 Bogdan Gheorghe
Added CTagsIndexer block - some more ironing of the indexer block.
* src/org/eclipse/cdt/ui/dialogs/IndexerBlock.java
* src/org/eclipse/cdt/ui/dialogs/NullIndexerBlock.java
* src/org/eclipse/cdt/ui/dialogs/CTagsIndexerBlock.java
* plugin.xml
2005-03-24 Vladimir Hirsl
Ironing of the Indexer property page block.
DOM AST based indexer property options page.

View file

@ -1342,6 +1342,11 @@
id="org.eclipse.cdt.ui.DOMASTSourceIndexerUI"
indexerID="org.eclipse.cdt.core.domsourceindexer"
name="DOM AST C/C++ Indexer"/>
<indexerUI
class="org.eclipse.cdt.ui.dialogs.CTagsIndexerBlock"
indexerID="org.eclipse.cdt.core.ctagsindexer"
name="CTags Indexer"
id="org.eclipse.cdt.ui.ctagsIndexerUI"/>
</extension>
<extension
point="org.eclipse.cdt.ui.completionContributors">

View file

@ -0,0 +1,159 @@
/**********************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.ui.dialogs;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.ui.index.AbstractIndexerPage;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
/**
* @author Bogdan Gheorghe
*/
public class CTagsIndexerBlock extends AbstractIndexerPage {
private Button indexerEnabled;
private boolean oldIndexerValue;
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.index.AbstractIndexerPage#initialize(org.eclipse.core.resources.IProject)
*/
public void initialize(IProject project) {
try {
loadPersistedValues(project);
this.currentProject = project;
} catch (CoreException e) {
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
*/
public void performApply(IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask(CUIMessages.getString("IndexerOptiosn.task.savingAttributes "), 1); //$NON-NLS-1$
ICOptionContainer container = getContainer();
IProject proj = null;
if (container != null){
proj = container.getProject();
}
else{
proj = currentProject;
}
if (proj != null) {
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj, false);
ICExtensionReference[] cext = cdesc.get(CCorePlugin.INDEXER_UNIQ_ID);
if (cext.length > 0) {
//initializeIndexerId();
for (int i = 0; i < cext.length; i++) {
String id = cext[i].getID();
//if (cext[i].getID().equals(parserID)) {
String orig = cext[i].getExtensionData("indexenabled"); //$NON-NLS-1$
String indexEnabled = getIndexerEnabledString();
if (orig == null || !orig.equals(indexEnabled)) {
cext[i].setExtensionData("indexenabled", indexEnabled); //$NON-NLS-1$
}
//}
}
}
} /*else {
Preferences store = null;
if (container != null){
store = container.getPreferences();
}
if (store != null) {
String indexEnabled = getIndexerEnabledString();
String indexMarkers = getIndexerProblemsValuesString();
store.setValue(PREF_INDEX_ENABLED, indexEnabled);
store.setValue(PREF_INDEX_MARKERS, indexMarkers);
}
}
boolean indexProject = getIndexerValue();
if ((indexProject != oldIndexerValue)
&& (currentProject != null)
&& indexProject) {
ICDTIndexer indexer = CCorePlugin.getDefault().getCoreModel().getIndexManager().getIndexerForProject(currentProject);
if (indexer instanceof SourceIndexer)
((SourceIndexer) indexer).indexAll(currentProject);
}*/
}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
*/
public void performDefaults() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
Composite page = ControlFactory.createComposite(parent, 1);
Group group = ControlFactory.createGroup(page,"CTags Indexer",1); //$NON-NLS-1$
GridData gd = (GridData) group.getLayoutData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = GridData.FILL;
indexerEnabled = ControlFactory.createCheckBox(group, "Enable Indexing" ); //$NON-NLS-1$
setControl(page);
}
public void loadPersistedValues(IProject project) throws CoreException {
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project, false);
ICExtensionReference[] cext = cdesc.get(CCorePlugin.INDEXER_UNIQ_ID);
if (cext.length > 0) {
for (int i = 0; i < cext.length; i++) {
String id = cext[i].getID();
String orig = cext[i].getExtensionData("indexenabled"); //$NON-NLS-1$
if (orig != null){
Boolean tempBool = new Boolean(orig);
oldIndexerValue = tempBool.booleanValue();
}
}
}
}
private String getIndexerEnabledString(){
if (indexerEnabled.getSelection())
return "true"; //$NON-NLS-1$
return "false"; //$NON-NLS-1$
}
}

View file

@ -158,10 +158,12 @@ public class IndexerBlock extends AbstractCOptionPage {
page.setContainer(getContainer());
page.createControl(parentComposite);
parentComposite.layout(true);
// parentComposite.pack(true);
} if (currentPage != null) {
}
if (currentPage != null){
currentPage.setVisible(false);
}
page.setVisible(true);
}
setCurrentPage(page);
@ -360,6 +362,7 @@ public class IndexerBlock extends AbstractCOptionPage {
}
};
CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(project, op, monitor);
CCorePlugin.getDefault().getCoreModel().getIndexManager().indexerChangeNotification(project);
} else {
if (initialSelected == null || !selected.equals(initialSelected)) {
if (container != null){

View file

@ -22,33 +22,13 @@ import org.eclipse.swt.widgets.Composite;
*/
public class NullIndexerBlock extends AbstractIndexerPage {
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.index.AbstractIndexerPage#initialize(org.eclipse.core.resources.IProject)
*/
public void initialize(IProject currentProject) {
// TODO Auto-generated method stub
}
public void initialize(IProject currentProject) {}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
*/
public void performApply(IProgressMonitor monitor) throws CoreException {
// TODO Auto-generated method stub
public void performApply(IProgressMonitor monitor) throws CoreException {}
}
public void performDefaults() {}
/* (non-Javadoc)
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
*/
public void performDefaults() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NULL);
setControl(comp);