mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +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();
|
||||
int linkrec = db.getInt(LINKAGES);
|
||||
while (linkrec != 0) {
|
||||
if (id.equals(PDOMLinkage.getId(this, linkrec))) {
|
||||
if (id.equals(PDOMLinkage.getId(this, linkrec)))
|
||||
return factory.getLinkage(this, linkrec);
|
||||
}
|
||||
else
|
||||
linkrec = PDOMLinkage.getNextLinkageRecord(this, linkrec);
|
||||
}
|
||||
|
||||
return factory.createLinkage(this);
|
||||
|
|
|
@ -57,6 +57,10 @@ public abstract class PDOMLinkage extends PDOMNode {
|
|||
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 {
|
||||
return pdom.getLinkage(pdom.getDB().getInt(record + NEXT_OFFSET));
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@
|
|||
|
||||
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.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
|
@ -49,20 +52,26 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
public static final int CFIELD = 4;
|
||||
|
||||
public PDOMNode getParent(IBinding binding) throws CoreException {
|
||||
PDOMNode parent = this;
|
||||
|
||||
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();
|
||||
if (scopeName != null) {
|
||||
IBinding scopeBinding = scopeName.resolveBinding();
|
||||
PDOMBinding scopePDOMBinding = adaptBinding(scopeBinding);
|
||||
if (scopePDOMBinding != null)
|
||||
parent = scopePDOMBinding;
|
||||
return scopePDOMBinding;
|
||||
}
|
||||
}
|
||||
|
||||
return parent;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public PDOMBinding addName(IASTName name) throws CoreException {
|
||||
|
@ -76,9 +85,11 @@ public class PDOMCLinkage extends PDOMLinkage {
|
|||
PDOMBinding pdomBinding = adaptBinding(binding);
|
||||
if (pdomBinding == null) {
|
||||
PDOMNode parent = getParent(binding);
|
||||
if (parent == null)
|
||||
return null;
|
||||
|
||||
if (binding instanceof IParameter)
|
||||
; // skip parameters
|
||||
return null; // skip parameters
|
||||
else if (binding instanceof IField) { // must be before IVariable
|
||||
if (parent instanceof PDOMMemberOwner)
|
||||
pdomBinding = new PDOMCField(pdom, (PDOMMemberOwner)parent, name);
|
||||
|
|
|
@ -57,7 +57,8 @@ public class IndexingJob extends Job {
|
|||
protected IStatus run(IProgressMonitor monitor) {
|
||||
progressMonitor = monitor;
|
||||
setThread( indexThread );
|
||||
progressMonitor.beginTask( "", 100 ); //$NON-NLS-1$
|
||||
if (progressMonitor != null)
|
||||
progressMonitor.beginTask( "", 100 ); //$NON-NLS-1$
|
||||
return ASYNC_FINISH;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
|
||||
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.ast.IASTFileLocation;
|
||||
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.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
@ -77,10 +81,10 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
|||
private IndexAction rebuildAction;
|
||||
private IndexAction openDefinitionAction;
|
||||
|
||||
private static class BTreeCounter implements IBTreeVisitor {
|
||||
private static class Counter implements IBTreeVisitor {
|
||||
int count;
|
||||
PDOMDatabase pdom;
|
||||
public BTreeCounter(PDOMDatabase pdom) {
|
||||
public Counter(PDOMDatabase pdom) {
|
||||
this.pdom = pdom;
|
||||
}
|
||||
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 {
|
||||
final int index;
|
||||
int count;
|
||||
int result;
|
||||
PDOMDatabase pdom;
|
||||
public BTreeIndex(PDOMDatabase pdom, int index) {
|
||||
private static class Children implements IBTreeVisitor {
|
||||
final PDOMDatabase pdom;
|
||||
final PDOMBinding[] bindings;
|
||||
int index;
|
||||
public Children(PDOMDatabase pdom, PDOMBinding[] bindings) {
|
||||
this.pdom = pdom;
|
||||
this.index = index;
|
||||
this.bindings = bindings;
|
||||
}
|
||||
public int compare(int record) throws CoreException {
|
||||
return 1;
|
||||
|
@ -109,15 +112,12 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
|||
if (record == 0 || PDOMBinding.isOrphaned(pdom, record))
|
||||
return true;
|
||||
|
||||
if (count++ == index) {
|
||||
result = record;
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
bindings[index++] = pdom.getBinding(record);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
private class IndexContentProvider implements ILazyTreeContentProvider {
|
||||
private class IndexLazyContentProvider implements ILazyTreeContentProvider {
|
||||
|
||||
public Object getParent(Object element) {
|
||||
return null;
|
||||
|
@ -154,17 +154,12 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
|||
if (linkage == null)
|
||||
return;
|
||||
}
|
||||
viewer.replace(parent, index, linkage);
|
||||
|
||||
BTreeCounter counter = new BTreeCounter(pdom);
|
||||
linkage.getIndex().visit(counter);
|
||||
viewer.setChildCount(linkage, counter.count);
|
||||
} else if (parent instanceof PDOMLinkage) {
|
||||
PDOMLinkage linkage = (PDOMLinkage)parent;
|
||||
PDOMDatabase pdom = linkage.getPDOM();
|
||||
BTreeIndex visitor = new BTreeIndex(pdom, index);
|
||||
linkage.getIndex().visit(visitor);
|
||||
PDOMBinding binding = pdom.getBinding(visitor.result);
|
||||
LinkageCache linkageCache = new LinkageCache(pdom, linkage);
|
||||
viewer.replace(parent, index, linkageCache);
|
||||
viewer.setChildCount(linkageCache, linkageCache.getCount());
|
||||
} else if (parent instanceof LinkageCache) {
|
||||
LinkageCache linkageCache = (LinkageCache)parent;
|
||||
PDOMBinding binding = linkageCache.getItem(index);
|
||||
if (binding != null) {
|
||||
viewer.replace(parent, index, binding);
|
||||
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 {
|
||||
public String getText(Object element) {
|
||||
if (element == null) {
|
||||
|
@ -202,6 +295,12 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
|||
} catch (CoreException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
} else if (element instanceof LinkageCache) {
|
||||
try {
|
||||
return ((LinkageCache)element).getName();
|
||||
} catch (CoreException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
} else
|
||||
return super.getText(element);
|
||||
}
|
||||
|
@ -233,7 +332,8 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
|||
}
|
||||
|
||||
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);
|
||||
viewer.setContentProvider(new IndexContentProvider());
|
||||
viewer.setLabelProvider(new IndexLabelProvider());
|
||||
|
@ -280,6 +380,7 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
|||
private abstract static class IndexAction extends Action {
|
||||
public abstract boolean valid();
|
||||
}
|
||||
|
||||
private void makeActions() {
|
||||
rebuildAction = new IndexAction() {
|
||||
public void run() {
|
||||
|
@ -412,50 +513,23 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
|
|||
public void handleChange(PDOMDatabase pdom) {
|
||||
viewer.getControl().getDisplay().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
ICModel model = CoreModel.getDefault().getCModel();
|
||||
viewer.setInput(model);
|
||||
try {
|
||||
ICProject[] cprojects = model.getCProjects();
|
||||
int n = 0;
|
||||
for (int i = 0; i < cprojects.length; ++i) {
|
||||
PDOMDatabase pdom = (PDOMDatabase)PDOM.getPDOM(cprojects[i].getProject());
|
||||
if (pdom != null)
|
||||
++n;
|
||||
}
|
||||
viewer.setChildCount(model, n);
|
||||
} catch (CModelException e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
}
|
||||
viewer.refresh();
|
||||
// ICModel model = CoreModel.getDefault().getCModel();
|
||||
// viewer.setInput(model);
|
||||
// try {
|
||||
// ICProject[] cprojects = model.getCProjects();
|
||||
// int n = 0;
|
||||
// for (int i = 0; i < cprojects.length; ++i) {
|
||||
// PDOMDatabase pdom = (PDOMDatabase)PDOM.getPDOM(cprojects[i].getProject());
|
||||
// if (pdom != null)
|
||||
// ++n;
|
||||
// }
|
||||
// viewer.setChildCount(model, n);
|
||||
// } 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