mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Changed the PDOM delete method to clear since it doesn't really delete the database, much... Also added visitors to the PDOMBinding hierarchy to facilitate easier searching.
This commit is contained in:
parent
ab7dcca459
commit
d431889736
13 changed files with 143 additions and 11 deletions
|
@ -31,7 +31,20 @@ public interface IPDOM extends IAdaptable {
|
|||
|
||||
public IASTName[] getDeclarations(IBinding binding);
|
||||
|
||||
public void delete() throws CoreException;
|
||||
/**
|
||||
* Recursively visit the nodes in this PDOM using the given visitor.
|
||||
*
|
||||
* @param visitor
|
||||
* @throws CoreException
|
||||
*/
|
||||
public void accept(IPDOMVisitor visitor) throws CoreException;
|
||||
|
||||
/**
|
||||
* Clear all the contents of this PDOM.
|
||||
*
|
||||
* @throws CoreException
|
||||
*/
|
||||
public void clear() throws CoreException;
|
||||
|
||||
/**
|
||||
* Looks to see if anything has been stored in this PDOM.
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.dom;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public interface IPDOMNode {
|
||||
|
||||
/**
|
||||
* Visit the children of this node.
|
||||
*
|
||||
* @param visitor
|
||||
* @throws CoreException
|
||||
*/
|
||||
public void accept(IPDOMVisitor visitor) throws CoreException;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.dom;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
public interface IPDOMVisitor {
|
||||
|
||||
/**
|
||||
* Walk the nodes in a PDOM. Return true to visit the children of
|
||||
* this node, or false to skip to the next sibling of this node.
|
||||
* Throw CoreException to stop the visit.
|
||||
*
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
public boolean visit(IPDOMNode node) throws CoreException;
|
||||
|
||||
}
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.IPDOM;
|
||||
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
@ -109,6 +110,11 @@ public class PDOM extends PlatformObject implements IPDOM {
|
|||
indexer.reindex();
|
||||
}
|
||||
|
||||
public void accept(IPDOMVisitor visitor) throws CoreException {
|
||||
for (PDOMLinkage linkage = getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage())
|
||||
linkage.accept(visitor);
|
||||
}
|
||||
|
||||
public static interface IListener {
|
||||
public void handleChange(PDOM pdom);
|
||||
}
|
||||
|
@ -220,7 +226,7 @@ public class PDOM extends PlatformObject implements IPDOM {
|
|||
file.clear();
|
||||
}
|
||||
|
||||
public void delete() throws CoreException {
|
||||
public void clear() throws CoreException {
|
||||
getDB().clear();
|
||||
fileIndex = null;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
|
|||
IProject rproject = project.getProject();
|
||||
IPDOM pdom = (IPDOM)rproject.getSessionProperty(pdomProperty);
|
||||
rproject.setSessionProperty(pdomProperty, null);
|
||||
pdom.delete();
|
||||
pdom.clear();
|
||||
}
|
||||
|
||||
public IElementChangedListener getElementChangedListener() {
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
|
@ -107,6 +108,23 @@ public abstract class PDOMLinkage extends PDOMNode {
|
|||
return new BTree(pdom.getDB(), record + INDEX_OFFSET);
|
||||
}
|
||||
|
||||
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
||||
super.accept(visitor);
|
||||
getIndex().visit(new IBTreeVisitor() {
|
||||
public int compare(int record) throws CoreException {
|
||||
return 1;
|
||||
};
|
||||
public boolean visit(int record) throws CoreException {
|
||||
PDOMBinding binding = pdom.getBinding(record);
|
||||
if (binding != null) {
|
||||
if (visitor.visit(binding))
|
||||
binding.accept(visitor);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public PDOMLinkage getLinkage() throws CoreException {
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.pdom.dom;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -41,6 +42,14 @@ public class PDOMMemberOwner extends PDOMBinding {
|
|||
return RECORD_SIZE;
|
||||
}
|
||||
|
||||
public void accept(IPDOMVisitor visitor) throws CoreException {
|
||||
super.accept(visitor);
|
||||
for (PDOMMember member = getFirstMember(); member != null; member = member.getNextMember())
|
||||
if (visitor.visit(member))
|
||||
member.accept(visitor);
|
||||
|
||||
}
|
||||
|
||||
public void addMember(PDOMMember member) throws CoreException {
|
||||
PDOMMember last = getLastMember();
|
||||
if (last != null) {
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||
|
@ -24,7 +26,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
* PDOM nodes form a multi-root tree with linkages being the roots.
|
||||
* This class managed the parent pointer.
|
||||
*/
|
||||
public abstract class PDOMNode {
|
||||
public abstract class PDOMNode implements IPDOMNode{
|
||||
|
||||
private static final int PARENT_OFFSET = 0;
|
||||
private static final int NAME_OFFSET = 4;
|
||||
|
@ -67,6 +69,10 @@ public abstract class PDOMNode {
|
|||
return record;
|
||||
}
|
||||
|
||||
public void accept(IPDOMVisitor visitor) throws CoreException {
|
||||
// No children here.
|
||||
}
|
||||
|
||||
public PDOMLinkage getLinkage() throws CoreException {
|
||||
return getLinkage(pdom, record);
|
||||
}
|
||||
|
@ -120,10 +126,10 @@ public abstract class PDOMNode {
|
|||
};
|
||||
}
|
||||
|
||||
public abstract static class NodeVisitor implements IBTreeVisitor {
|
||||
public abstract static class NodeFinder implements IBTreeVisitor {
|
||||
protected final PDOM pdom;
|
||||
protected final char[] name;
|
||||
protected NodeVisitor(PDOM pdom, char [] name) {
|
||||
protected NodeFinder(PDOM pdom, char [] name) {
|
||||
this.pdom = pdom;
|
||||
this.name = name;
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
return pdomBinding;
|
||||
}
|
||||
|
||||
private static final class FindBinding extends PDOMNode.NodeVisitor {
|
||||
private static final class FindBinding extends PDOMNode.NodeFinder {
|
||||
PDOMBinding pdomBinding;
|
||||
final int desiredType;
|
||||
public FindBinding(PDOM pdom, char[] name, int desiredType) {
|
||||
|
|
|
@ -130,7 +130,7 @@ public class PDOMCPPLinkage extends PDOMLinkage {
|
|||
return pdomBinding;
|
||||
}
|
||||
|
||||
private static final class FindBinding extends PDOMNode.NodeVisitor {
|
||||
private static final class FindBinding extends PDOMNode.NodeFinder {
|
||||
PDOMBinding pdomBinding;
|
||||
final int desiredType;
|
||||
public FindBinding(PDOM pdom, char[] name, int desiredType) {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
|
@ -25,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||
|
@ -57,6 +59,23 @@ public class PDOMCPPNamespace extends PDOMBinding
|
|||
return new BTree(pdom.getDB(), record + INDEX_OFFSET);
|
||||
}
|
||||
|
||||
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
||||
super.accept(visitor);
|
||||
getIndex().visit(new IBTreeVisitor() {
|
||||
public int compare(int record) throws CoreException {
|
||||
return 1;
|
||||
};
|
||||
public boolean visit(int record) throws CoreException {
|
||||
PDOMBinding binding = pdom.getBinding(record);
|
||||
if (binding != null) {
|
||||
if (visitor.visit(binding))
|
||||
binding.accept(visitor);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public void addChild(PDOMNode child) throws CoreException {
|
||||
getIndex().insert(child.getRecord(), child.getIndexComparator());
|
||||
}
|
||||
|
@ -106,7 +125,7 @@ public class PDOMCPPNamespace extends PDOMBinding
|
|||
throw new PDOMNotImplementedError();
|
||||
}
|
||||
|
||||
private static final class FindBinding extends PDOMNode.NodeVisitor {
|
||||
private static final class FindBinding extends PDOMNode.NodeFinder {
|
||||
PDOMBinding pdomBinding;
|
||||
final int desiredType;
|
||||
public FindBinding(PDOM pdom, char[] name, int desiredType) {
|
||||
|
|
|
@ -52,7 +52,7 @@ public class PDOMFastReindex extends Job {
|
|||
final List addedTUs = new ArrayList();
|
||||
|
||||
// First clear out the DB
|
||||
pdom.delete();
|
||||
pdom.clear();
|
||||
|
||||
// Now repopulate it
|
||||
pdom.getProject().getProject().accept(new IResourceProxyVisitor() {
|
||||
|
|
|
@ -35,7 +35,7 @@ public class PDOMNullIndexer implements IPDOMIndexer {
|
|||
|
||||
public void reindex() throws CoreException {
|
||||
// Just clear out the old index
|
||||
pdom.delete();
|
||||
pdom.clear();
|
||||
((PDOM)pdom).fireChange();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue