mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Fixed an NPE in the IndexingJob. Fixed support for multiple languages in a project. Changed the index view to not use virtual trees (way to slow). We'll keep an eye on memory consumption before deciding which way to go.
This commit is contained in:
parent
720cdaacbb
commit
6535d63ad3
6 changed files with 258 additions and 79 deletions
|
@ -192,9 +192,10 @@ public class PDOMDatabase implements IPDOM {
|
||||||
String id = language.getId();
|
String id = language.getId();
|
||||||
int linkrec = db.getInt(LINKAGES);
|
int linkrec = db.getInt(LINKAGES);
|
||||||
while (linkrec != 0) {
|
while (linkrec != 0) {
|
||||||
if (id.equals(PDOMLinkage.getId(this, linkrec))) {
|
if (id.equals(PDOMLinkage.getId(this, linkrec)))
|
||||||
return factory.getLinkage(this, linkrec);
|
return factory.getLinkage(this, linkrec);
|
||||||
}
|
else
|
||||||
|
linkrec = PDOMLinkage.getNextLinkageRecord(this, linkrec);
|
||||||
}
|
}
|
||||||
|
|
||||||
return factory.createLinkage(this);
|
return factory.createLinkage(this);
|
||||||
|
|
|
@ -57,6 +57,10 @@ public abstract class PDOMLinkage extends PDOMNode {
|
||||||
return db.getString(namerec);
|
return db.getString(namerec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getNextLinkageRecord(PDOMDatabase pdom, int record) throws CoreException {
|
||||||
|
return pdom.getDB().getInt(record + NEXT_OFFSET);
|
||||||
|
}
|
||||||
|
|
||||||
public PDOMLinkage getNextLinkage() throws CoreException {
|
public PDOMLinkage getNextLinkage() throws CoreException {
|
||||||
return pdom.getLinkage(pdom.getDB().getInt(record + NEXT_OFFSET));
|
return pdom.getLinkage(pdom.getDB().getInt(record + NEXT_OFFSET));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,10 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
package org.eclipse.cdt.internal.core.pdom.dom.c;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IField;
|
import org.eclipse.cdt.core.dom.ast.IField;
|
||||||
|
@ -49,20 +52,26 @@ public class PDOMCLinkage extends PDOMLinkage {
|
||||||
public static final int CFIELD = 4;
|
public static final int CFIELD = 4;
|
||||||
|
|
||||||
public PDOMNode getParent(IBinding binding) throws CoreException {
|
public PDOMNode getParent(IBinding binding) throws CoreException {
|
||||||
PDOMNode parent = this;
|
|
||||||
|
|
||||||
IScope scope = binding.getScope();
|
IScope scope = binding.getScope();
|
||||||
if (scope != null) {
|
if (scope == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
IASTNode scopeNode = scope.getPhysicalNode();
|
||||||
|
if (scopeNode instanceof IASTCompoundStatement)
|
||||||
|
return null;
|
||||||
|
else if (scopeNode instanceof IASTTranslationUnit)
|
||||||
|
return this;
|
||||||
|
else {
|
||||||
IASTName scopeName = scope.getScopeName();
|
IASTName scopeName = scope.getScopeName();
|
||||||
if (scopeName != null) {
|
if (scopeName != null) {
|
||||||
IBinding scopeBinding = scopeName.resolveBinding();
|
IBinding scopeBinding = scopeName.resolveBinding();
|
||||||
PDOMBinding scopePDOMBinding = adaptBinding(scopeBinding);
|
PDOMBinding scopePDOMBinding = adaptBinding(scopeBinding);
|
||||||
if (scopePDOMBinding != null)
|
if (scopePDOMBinding != null)
|
||||||
parent = scopePDOMBinding;
|
return scopePDOMBinding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMBinding addName(IASTName name) throws CoreException {
|
public PDOMBinding addName(IASTName name) throws CoreException {
|
||||||
|
@ -76,9 +85,11 @@ public class PDOMCLinkage extends PDOMLinkage {
|
||||||
PDOMBinding pdomBinding = adaptBinding(binding);
|
PDOMBinding pdomBinding = adaptBinding(binding);
|
||||||
if (pdomBinding == null) {
|
if (pdomBinding == null) {
|
||||||
PDOMNode parent = getParent(binding);
|
PDOMNode parent = getParent(binding);
|
||||||
|
if (parent == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
if (binding instanceof IParameter)
|
if (binding instanceof IParameter)
|
||||||
; // skip parameters
|
return null; // skip parameters
|
||||||
else if (binding instanceof IField) { // must be before IVariable
|
else if (binding instanceof IField) { // must be before IVariable
|
||||||
if (parent instanceof PDOMMemberOwner)
|
if (parent instanceof PDOMMemberOwner)
|
||||||
pdomBinding = new PDOMCField(pdom, (PDOMMemberOwner)parent, name);
|
pdomBinding = new PDOMCField(pdom, (PDOMMemberOwner)parent, name);
|
||||||
|
|
|
@ -57,7 +57,8 @@ public class IndexingJob extends Job {
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
progressMonitor = monitor;
|
progressMonitor = monitor;
|
||||||
setThread( indexThread );
|
setThread( indexThread );
|
||||||
progressMonitor.beginTask( "", 100 ); //$NON-NLS-1$
|
if (progressMonitor != null)
|
||||||
|
progressMonitor.beginTask( "", 100 ); //$NON-NLS-1$
|
||||||
return ASYNC_FINISH;
|
return ASYNC_FINISH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.indexview;
|
package org.eclipse.cdt.internal.ui.indexview;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.IPDOM;
|
||||||
import org.eclipse.cdt.core.dom.PDOM;
|
import org.eclipse.cdt.core.dom.PDOM;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
@ -50,6 +53,7 @@ import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||||
import org.eclipse.jface.viewers.ILazyTreeContentProvider;
|
import org.eclipse.jface.viewers.ILazyTreeContentProvider;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||||
import org.eclipse.jface.viewers.LabelProvider;
|
import org.eclipse.jface.viewers.LabelProvider;
|
||||||
import org.eclipse.jface.viewers.TreeViewer;
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
import org.eclipse.jface.viewers.Viewer;
|
import org.eclipse.jface.viewers.Viewer;
|
||||||
|
@ -77,10 +81,10 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
||||||
private IndexAction rebuildAction;
|
private IndexAction rebuildAction;
|
||||||
private IndexAction openDefinitionAction;
|
private IndexAction openDefinitionAction;
|
||||||
|
|
||||||
private static class BTreeCounter implements IBTreeVisitor {
|
private static class Counter implements IBTreeVisitor {
|
||||||
int count;
|
int count;
|
||||||
PDOMDatabase pdom;
|
PDOMDatabase pdom;
|
||||||
public BTreeCounter(PDOMDatabase pdom) {
|
public Counter(PDOMDatabase pdom) {
|
||||||
this.pdom = pdom;
|
this.pdom = pdom;
|
||||||
}
|
}
|
||||||
public int compare(int record) throws CoreException {
|
public int compare(int record) throws CoreException {
|
||||||
|
@ -93,14 +97,13 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class BTreeIndex implements IBTreeVisitor {
|
private static class Children implements IBTreeVisitor {
|
||||||
final int index;
|
final PDOMDatabase pdom;
|
||||||
int count;
|
final PDOMBinding[] bindings;
|
||||||
int result;
|
int index;
|
||||||
PDOMDatabase pdom;
|
public Children(PDOMDatabase pdom, PDOMBinding[] bindings) {
|
||||||
public BTreeIndex(PDOMDatabase pdom, int index) {
|
|
||||||
this.pdom = pdom;
|
this.pdom = pdom;
|
||||||
this.index = index;
|
this.bindings = bindings;
|
||||||
}
|
}
|
||||||
public int compare(int record) throws CoreException {
|
public int compare(int record) throws CoreException {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -109,15 +112,12 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
||||||
if (record == 0 || PDOMBinding.isOrphaned(pdom, record))
|
if (record == 0 || PDOMBinding.isOrphaned(pdom, record))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (count++ == index) {
|
bindings[index++] = pdom.getBinding(record);
|
||||||
result = record;
|
return true;
|
||||||
return false;
|
|
||||||
} else
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private class IndexContentProvider implements ILazyTreeContentProvider {
|
private class IndexLazyContentProvider implements ILazyTreeContentProvider {
|
||||||
|
|
||||||
public Object getParent(Object element) {
|
public Object getParent(Object element) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -154,17 +154,12 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
||||||
if (linkage == null)
|
if (linkage == null)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
viewer.replace(parent, index, linkage);
|
LinkageCache linkageCache = new LinkageCache(pdom, linkage);
|
||||||
|
viewer.replace(parent, index, linkageCache);
|
||||||
BTreeCounter counter = new BTreeCounter(pdom);
|
viewer.setChildCount(linkageCache, linkageCache.getCount());
|
||||||
linkage.getIndex().visit(counter);
|
} else if (parent instanceof LinkageCache) {
|
||||||
viewer.setChildCount(linkage, counter.count);
|
LinkageCache linkageCache = (LinkageCache)parent;
|
||||||
} else if (parent instanceof PDOMLinkage) {
|
PDOMBinding binding = linkageCache.getItem(index);
|
||||||
PDOMLinkage linkage = (PDOMLinkage)parent;
|
|
||||||
PDOMDatabase pdom = linkage.getPDOM();
|
|
||||||
BTreeIndex visitor = new BTreeIndex(pdom, index);
|
|
||||||
linkage.getIndex().visit(visitor);
|
|
||||||
PDOMBinding binding = pdom.getBinding(visitor.result);
|
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
viewer.replace(parent, index, binding);
|
viewer.replace(parent, index, binding);
|
||||||
if (binding instanceof PDOMMemberOwner) {
|
if (binding instanceof PDOMMemberOwner) {
|
||||||
|
@ -192,6 +187,104 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class IndexContentProvider implements ITreeContentProvider {
|
||||||
|
|
||||||
|
public Object[] getChildren(Object parentElement) {
|
||||||
|
if (parentElement instanceof ICProject) {
|
||||||
|
try {
|
||||||
|
PDOMDatabase pdom = (PDOMDatabase)PDOM.getPDOM(((ICProject)parentElement).getProject());
|
||||||
|
int n = 0;
|
||||||
|
for (PDOMLinkage linkage = pdom.getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage())
|
||||||
|
++n;
|
||||||
|
PDOMLinkage[] linkages = new PDOMLinkage[n];
|
||||||
|
int i = 0;
|
||||||
|
for (PDOMLinkage linkage = pdom.getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage())
|
||||||
|
linkages[i++] = linkage;
|
||||||
|
return linkages;
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
}
|
||||||
|
} else if (parentElement instanceof PDOMLinkage) {
|
||||||
|
try {
|
||||||
|
PDOMLinkage linkage = (PDOMLinkage)parentElement;
|
||||||
|
PDOMDatabase pdom = linkage.getPDOM();
|
||||||
|
Counter counter = new Counter(pdom);
|
||||||
|
linkage.getIndex().visit(counter);
|
||||||
|
PDOMBinding[] bindings = new PDOMBinding[counter.count];
|
||||||
|
Children children = new Children(pdom, bindings);
|
||||||
|
linkage.getIndex().visit(children);
|
||||||
|
return bindings;
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
}
|
||||||
|
} else if (parentElement instanceof PDOMMemberOwner) {
|
||||||
|
try {
|
||||||
|
PDOMMemberOwner owner = (PDOMMemberOwner)parentElement;
|
||||||
|
int n = 0;
|
||||||
|
for (PDOMMember member = owner.getFirstMember(); member != null; member = member.getNextMember())
|
||||||
|
++n;
|
||||||
|
PDOMMember[] members = new PDOMMember[n];
|
||||||
|
int i = 0;
|
||||||
|
for (PDOMMember member = owner.getFirstMember(); member != null; member = member.getNextMember())
|
||||||
|
members[i++] = member;
|
||||||
|
return members;
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Object[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getParent(Object element) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasChildren(Object element) {
|
||||||
|
if (element instanceof ICProject) {
|
||||||
|
IPDOM ipdom = PDOM.getPDOM(((ICProject)element).getProject());
|
||||||
|
if (ipdom == null || !(ipdom instanceof PDOMDatabase))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
PDOMDatabase pdom = (PDOMDatabase)ipdom;
|
||||||
|
return pdom.getFirstLinkage() != null;
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
}
|
||||||
|
} else if (element instanceof PDOMLinkage) {
|
||||||
|
return true;
|
||||||
|
} else if (element instanceof PDOMMemberOwner) {
|
||||||
|
try {
|
||||||
|
PDOMMemberOwner owner = (PDOMMemberOwner)element;
|
||||||
|
return owner.getFirstMember() != null;
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getElements(Object inputElement) {
|
||||||
|
try {
|
||||||
|
if (inputElement instanceof ICModel) {
|
||||||
|
|
||||||
|
ICModel model = (ICModel)inputElement;
|
||||||
|
return model.getCProjects();
|
||||||
|
}
|
||||||
|
} catch (CModelException e) { }
|
||||||
|
|
||||||
|
return new Object[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispose() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private class IndexLabelProvider extends LabelProvider {
|
private class IndexLabelProvider extends LabelProvider {
|
||||||
public String getText(Object element) {
|
public String getText(Object element) {
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
|
@ -202,6 +295,12 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
return e.getMessage();
|
return e.getMessage();
|
||||||
}
|
}
|
||||||
|
} else if (element instanceof LinkageCache) {
|
||||||
|
try {
|
||||||
|
return ((LinkageCache)element).getName();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
return super.getText(element);
|
return super.getText(element);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +332,8 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createPartControl(Composite parent) {
|
public void createPartControl(Composite parent) {
|
||||||
viewer = new TreeViewer(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||||
|
// viewer = new TreeViewer(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||||
// drillDownAdapter = new DrillDownAdapter(viewer);
|
// drillDownAdapter = new DrillDownAdapter(viewer);
|
||||||
viewer.setContentProvider(new IndexContentProvider());
|
viewer.setContentProvider(new IndexContentProvider());
|
||||||
viewer.setLabelProvider(new IndexLabelProvider());
|
viewer.setLabelProvider(new IndexLabelProvider());
|
||||||
|
@ -280,6 +380,7 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
||||||
private abstract static class IndexAction extends Action {
|
private abstract static class IndexAction extends Action {
|
||||||
public abstract boolean valid();
|
public abstract boolean valid();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeActions() {
|
private void makeActions() {
|
||||||
rebuildAction = new IndexAction() {
|
rebuildAction = new IndexAction() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -412,50 +513,23 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
||||||
public void handleChange(PDOMDatabase pdom) {
|
public void handleChange(PDOMDatabase pdom) {
|
||||||
viewer.getControl().getDisplay().asyncExec(new Runnable() {
|
viewer.getControl().getDisplay().asyncExec(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
ICModel model = CoreModel.getDefault().getCModel();
|
viewer.refresh();
|
||||||
viewer.setInput(model);
|
// ICModel model = CoreModel.getDefault().getCModel();
|
||||||
try {
|
// viewer.setInput(model);
|
||||||
ICProject[] cprojects = model.getCProjects();
|
// try {
|
||||||
int n = 0;
|
// ICProject[] cprojects = model.getCProjects();
|
||||||
for (int i = 0; i < cprojects.length; ++i) {
|
// int n = 0;
|
||||||
PDOMDatabase pdom = (PDOMDatabase)PDOM.getPDOM(cprojects[i].getProject());
|
// for (int i = 0; i < cprojects.length; ++i) {
|
||||||
if (pdom != null)
|
// PDOMDatabase pdom = (PDOMDatabase)PDOM.getPDOM(cprojects[i].getProject());
|
||||||
++n;
|
// if (pdom != null)
|
||||||
}
|
// ++n;
|
||||||
viewer.setChildCount(model, n);
|
// }
|
||||||
} catch (CModelException e) {
|
// viewer.setChildCount(model, n);
|
||||||
CUIPlugin.getDefault().log(e);
|
// } catch (CModelException e) {
|
||||||
}
|
// CUIPlugin.getDefault().log(e);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// try {
|
|
||||||
// final ICModel model = (ICModel)viewer.getInput();
|
|
||||||
// if (model == null)
|
|
||||||
// return;
|
|
||||||
// ICProject[] cprojects = model.getCProjects();
|
|
||||||
// int n = -1;
|
|
||||||
// for (int i = 0; i < cprojects.length; ++i) {
|
|
||||||
// final ICProject cproject = cprojects[i];
|
|
||||||
// IPDOM pp = PDOM.getPDOM(cproject.getProject());
|
|
||||||
// if (pp != null) {
|
|
||||||
// ++n;
|
|
||||||
// if (pp == pdom){
|
|
||||||
// final int index = n;
|
|
||||||
// viewer.getControl().getDisplay().asyncExec(new Runnable() {
|
|
||||||
// public void run() {
|
|
||||||
// viewer.replace(model, index, cproject);
|
|
||||||
// viewer.getControl().redraw();
|
|
||||||
// viewer.getControl().update();
|
|
||||||
// };
|
|
||||||
// });
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } catch (CoreException e) {
|
|
||||||
// CUIPlugin.getDefault().log(e);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.internal.ui.indexview;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
|
||||||
|
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.PDOMLinkage;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Doug Schaefer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LinkageCache {
|
||||||
|
|
||||||
|
private final PDOMDatabase pdom;
|
||||||
|
private final PDOMLinkage linkage;
|
||||||
|
private int[] cache;
|
||||||
|
|
||||||
|
private static class Counter implements IBTreeVisitor {
|
||||||
|
int count;
|
||||||
|
PDOMDatabase pdom;
|
||||||
|
public Counter(PDOMDatabase pdom) {
|
||||||
|
this.pdom = pdom;
|
||||||
|
}
|
||||||
|
public int compare(int record) throws CoreException {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
public boolean visit(int record) throws CoreException {
|
||||||
|
if (record != 0 && ! PDOMBinding.isOrphaned(pdom, record))
|
||||||
|
++count;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FillCache implements IBTreeVisitor {
|
||||||
|
final PDOMDatabase pdom;
|
||||||
|
final int[] cache;
|
||||||
|
int index;
|
||||||
|
public FillCache(PDOMDatabase pdom, int [] cache) {
|
||||||
|
this.pdom = pdom;
|
||||||
|
this.cache = cache;
|
||||||
|
}
|
||||||
|
public int compare(int record) throws CoreException {
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
public boolean visit(int record) throws CoreException {
|
||||||
|
if (record == 0 || PDOMBinding.isOrphaned(pdom, record))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
cache[index++] = record;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkageCache(PDOMDatabase pdom, PDOMLinkage linkage) throws CoreException {
|
||||||
|
this.pdom = pdom;
|
||||||
|
this.linkage = linkage;
|
||||||
|
|
||||||
|
Counter counter = new Counter(pdom);
|
||||||
|
linkage.getIndex().visit(counter);
|
||||||
|
cache = new int[counter.count];
|
||||||
|
FillCache fillCache = new FillCache(pdom, cache);
|
||||||
|
linkage.getIndex().visit(fillCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return cache.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMBinding getItem(int index) throws CoreException {
|
||||||
|
return pdom.getBinding(cache[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() throws CoreException {
|
||||||
|
return linkage.getName();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue