1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Introduces an API to access the PDOM, bug 149565.

This commit is contained in:
Markus Schorn 2006-10-12 13:31:32 +00:00
parent f5a4ba1d76
commit 2119729ff7
24 changed files with 642 additions and 752 deletions

View file

@ -23,14 +23,14 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
@ -132,55 +132,53 @@ public class CallHierarchyUI {
}
private static ICElement[] findDefinitions(ICProject project, IEditorInput editorInput, ITextSelection sel) throws CoreException {
CIndexQueries index= CIndexQueries.getInstance();
IPDOM pdom= CCorePlugin.getPDOMManager().getPDOM(project);
if (pdom != null) {
try {
pdom.acquireReadLock();
} catch (InterruptedException e) {
return null;
}
}
try {
IASTName name= getSelectedName(editorInput, sel);
if (name != null) {
IBinding binding= name.resolveBinding();
if (CIndexQueries.isRelevantForCallHierarchy(binding)) {
if (name.isDefinition()) {
ICElement elem= index.findDefinition(project, name);
if (elem != null) {
return new ICElement[]{elem};
}
}
else {
ICElement[] elems= index.findAllDefinitions(project, name);
if (elems.length == 0) {
ICProject[] allProjects= CoreModel.getDefault().getCModel().getCProjects();
elems= index.findAllDefinitions(allProjects, name);
if (elems.length == 0) {
ICElement elem= index.findAnyDeclaration(project, name);
if (elem == null) {
elem= index.findAnyDeclaration(allProjects, name);
}
if (elem != null) {
elems= new ICElement[] {elem};
}
CIndexQueries indexq= CIndexQueries.getInstance();
IIndex index= CCorePlugin.getIndexManager().getIndex(project, IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
index.acquireReadLock();
try {
IASTName name= getSelectedName(index, editorInput, sel);
if (name != null) {
IBinding binding= name.resolveBinding();
if (CIndexQueries.isRelevantForCallHierarchy(binding)) {
if (name.isDefinition()) {
ICElement elem= indexq.getCElementForName(project, name);
if (elem != null) {
return new ICElement[]{elem};
}
}
return elems;
else {
ICElement[] elems= indexq.findAllDefinitions(index, name);
if (elems.length == 0) {
elems= indexq.findAllDefinitions(index, name);
if (elems.length == 0) {
ICElement elem= indexq.findAnyDeclaration(index, project, name);
if (elems != null) {
elems= new ICElement[]{elem};
}
}
}
return elems;
}
}
}
}
}
finally {
if (pdom != null) {
pdom.releaseReadLock();
finally {
if (index != null) {
index.releaseReadLock();
}
}
}
catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
catch (InterruptedException e) {
}
return null;
}
private static IASTName getSelectedName(IEditorInput editorInput, ITextSelection selection) throws CoreException {
private static IASTName getSelectedName(IIndex index, IEditorInput editorInput, ITextSelection selection) throws CoreException {
int selectionStart = selection.getOffset();
int selectionLength = selection.getLength();
@ -188,8 +186,8 @@ public class CallHierarchyUI {
if (workingCopy == null)
return null;
int options= ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, options);
int options= ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
IASTTranslationUnit ast = workingCopy.getAST(index, options);
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
ast.accept(finder);
return finder.getSelectedName();

View file

@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor;
@ -28,11 +29,12 @@ import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IPositionConverter;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
@ -47,6 +49,10 @@ import org.eclipse.cdt.ui.CUIPlugin;
*/
public final class ASTProvider {
public static interface ASTRunnable {
IStatus runOnAST(IASTTranslationUnit tu);
}
/**
* Wait flag.
*/
@ -97,7 +103,7 @@ public final class ASTProvider {
/** Full parse mode (no PDOM) */
public static int PARSE_MODE_FULL= 0;
/** Fast parse mode (use PDOM) */
public static int PARSE_MODE_FAST= ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
public static int PARSE_MODE_FAST= ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
/**
* Tells whether this class is in debug mode.
@ -241,6 +247,8 @@ public final class ASTProvider {
protected int fParseMode= PARSE_MODE_FAST;
private long fLastWriteOnIndex= -1;
/**
* Returns the C plug-in's AST provider.
*
@ -409,6 +417,7 @@ public final class ASTProvider {
disposeAST();
fAST= ast;
fLastWriteOnIndex= fAST == null ? 0 : fAST.getIndex().getLastWriteAccess();
fActivePositionConverter= converter;
// Signal AST change
@ -426,11 +435,12 @@ public final class ASTProvider {
* </p>
*
* @param cElement the C element
* @param index the index used to create the AST, needs to be read-locked.
* @param waitFlag {@link #WAIT_YES}, {@link #WAIT_NO} or {@link #WAIT_ACTIVE_ONLY}
* @param progressMonitor the progress monitor or <code>null</code>
* @return the AST or <code>null</code> if the AST is not available
*/
public IASTTranslationUnit getAST(ICElement cElement, WAIT_FLAG waitFlag, IProgressMonitor progressMonitor) {
public IASTTranslationUnit getAST(ICElement cElement, IIndex index, WAIT_FLAG waitFlag, IProgressMonitor progressMonitor) {
if (cElement == null)
return null;
@ -444,10 +454,15 @@ public final class ASTProvider {
isActiveElement= cElement.equals(fActiveCElement);
if (isActiveElement) {
if (fAST != null) {
if (DEBUG)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning cached AST:" + toString(fAST) + " for: " + cElement.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (fLastWriteOnIndex < index.getLastWriteAccess()) {
disposeAST();
}
else {
if (DEBUG)
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning cached AST:" + toString(fAST) + " for: " + cElement.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return fAST;
return fAST;
}
}
if (waitFlag == WAIT_NO) {
if (DEBUG)
@ -479,7 +494,7 @@ public final class ASTProvider {
return fAST;
}
}
return getAST(cElement, waitFlag, progressMonitor);
return getAST(cElement, index, waitFlag, progressMonitor);
} catch (InterruptedException e) {
return null; // thread has been interrupted don't compute AST
}
@ -494,7 +509,7 @@ public final class ASTProvider {
IASTTranslationUnit ast= null;
try {
ast= createAST(cElement, progressMonitor);
ast= createAST(cElement, index, progressMonitor);
if (progressMonitor != null && progressMonitor.isCanceled())
ast= null;
else if (DEBUG && ast != null)
@ -509,7 +524,6 @@ public final class ASTProvider {
reconciled(ast, null, cElement, null);
}
}
return ast;
}
@ -530,10 +544,11 @@ public final class ASTProvider {
* Creates a new translation unit AST.
*
* @param cElement the C element for which to create the AST
* @param index for AST generation, needs to be read-locked.
* @param progressMonitor the progress monitor
* @return AST
*/
IASTTranslationUnit createAST(ICElement cElement, final IProgressMonitor progressMonitor) {
IASTTranslationUnit createAST(ICElement cElement, final IIndex index, final IProgressMonitor progressMonitor) {
if (!hasSource(cElement))
return null;
@ -552,7 +567,7 @@ public final class ASTProvider {
if (progressMonitor != null && progressMonitor.isCanceled()) {
root[0]= null;
} else {
root[0]= tu.getLanguage().getASTTranslationUnit(tu, fParseMode);
root[0]= tu.getAST(index, fParseMode);
}
} catch (OperationCanceledException ex) {
root[0]= null;
@ -649,5 +664,25 @@ public final class ASTProvider {
return null;
}
public IStatus runOnAST(ICElement cElement, WAIT_FLAG waitFlag, IProgressMonitor monitor,
ASTRunnable astRunnable) {
IIndex index;
try {
index = CCorePlugin.getIndexManager().getIndex(cElement.getCProject());
index.acquireReadLock();
} catch (CoreException e) {
return e.getStatus();
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
try {
IASTTranslationUnit ast= getAST(cElement, index, waitFlag, monitor);
return astRunnable.runOnAST(ast);
}
finally {
index.releaseReadLock();
}
}
}

View file

@ -19,7 +19,6 @@ import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@ -45,17 +44,16 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.browser.QualifiedTypeName;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
@ -65,11 +63,6 @@ import org.eclipse.cdt.ui.IRequiredInclude;
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter;
@ -152,9 +145,24 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
public void run() {
ITranslationUnit tu= getTranslationUnit();
if (tu != null) {
extractIncludes(fEditor);
addInclude(tu);
IIndex index;
try {
index = CCorePlugin.getIndexManager().getIndex(tu.getCProject(), IIndexManager.ADD_DEPENDENCIES);
index.acquireReadLock();
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
return;
} catch (InterruptedException e) {
return;
}
try {
if (tu != null) {
extractIncludes(fEditor, index);
addInclude(tu);
}
}
finally {
index.releaseReadLock();
}
fUsings = null;
fRequiredIncludes = null;
@ -164,18 +172,19 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
* To be used by ElementListSelectionDialog for user to choose which declarations/
* definitions for "add include" when there are more than one to choose from.
*/
private class DisplayName extends Object
private static class DisplayName extends Object
{
private IIndexName name;
private IIndexBinding binding;
public DisplayName(IIndexName name) {
public DisplayName(IIndexName name, IIndexBinding binding) {
this.name = name;
this.binding= binding;
}
public String toString()
{
try {
PDOMBinding binding = (PDOMBinding) name.resolveBinding();
if (binding != null)
{
return getBindingQualifiedName(binding) + " - " + name.getFileName(); //$NON-NLS-1$
@ -188,11 +197,14 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
}
}
public IIndexName getPDOMName()
{
public IIndexName getName() {
return name;
}
public IIndexBinding getBinding() {
return binding;
}
}
@ -200,8 +212,9 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
* Extract the includes for the given selection. This can be both used to perform
* the work as well as being invoked when there is a change. The actual results
* can and should be cached as the lookup process could be potentially costly.
* @param index
*/
private void extractIncludes(ITextEditor editor) {
private void extractIncludes(ITextEditor editor, IIndex index) {
if (editor == null) {
return;
}
@ -234,125 +247,79 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
}
}
IPDOMManager pdomManager = CCorePlugin.getPDOMManager();
try {
ITranslationUnit unit = getTranslationUnit();
//get all referenced projects
if (unit != null)
Pattern pattern = Pattern.compile(name);
IndexFilter filter= new IndexFilter() {
};
IIndexBinding[] bindings= index.findBindings(pattern, false, filter, new NullProgressMonitor());
ArrayList pdomNames= new ArrayList();
for (int i = 0; i < bindings.length; ++i) {
IIndexBinding binding= bindings[i];
IIndexName[] defs= null;
// class, struct union, enumeration
if (binding instanceof ICompositeType || binding instanceof IEnumeration) {
defs= index.findDefinitions(binding);
}
else if (binding instanceof ITypedef || binding instanceof IFunction) {
defs= index.findDeclarations(binding);
}
if (defs != null) {
for (int j = 0; j < defs.length; j++) {
pdomNames.add(new DisplayName(defs[j], binding));
}
}
}
if (pdomNames.size() > 1)
{
ICProject cProj = unit.getCProject();
if (cProj != null)
{
IProject proj = cProj.getProject();
if (proj != null)
{
IProjectDescription projectDescription = proj.getDescription();
if (projectDescription != null)
{
IProject[] projects = projectDescription.getReferencedProjects();
List cProjectsToSearch = new ArrayList();
//get all the ICProjects for the referenced projects
for(int i = 0; i < projects.length; i++)
ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_ONLY));
dialog.setElements(pdomNames.toArray());
dialog.setTitle(CEditorMessages.getString("AddIncludeOnSelection.label")); //$NON-NLS-1$
dialog.setMessage(CEditorMessages.getString("AddIncludeOnSelection.description")); //$NON-NLS-1$
if (dialog.open() == Window.OK) {
//get selection
Object[] selects = dialog.getResult();
fRequiredIncludes = new IRequiredInclude[selects.length];
List usings = new ArrayList(selects.length);
for (int i = 0; i < fRequiredIncludes.length; i++) {
IRequiredInclude include = getRequiredInclude(((DisplayName)selects[i]).getName().getFileName(), getTranslationUnit());
if (include != null) {
fRequiredIncludes[i] = include;
IIndexBinding binding = ((DisplayName)selects[i]).getBinding();
if (binding instanceof ICPPBinding)
{
IProject project = projects[i];
try {
ICProject[] cProjects = CoreModel.getDefault().getCModel().getCProjects();
if (cProjects != null) {
for (int j = 0; j < cProjects.length; j++) {
ICProject cProject = cProjects[j];
if (project.equals(cProjects[j].getProject()))
cProjectsToSearch.add(cProject);
}
}
} catch (CModelException e) {
}
}
cProjectsToSearch.add(cProj); //current project
Pattern pattern = Pattern.compile(name);
List pdomNames = new ArrayList();
//search the projects and get name matching bindings
for (int n = 0; n < cProjectsToSearch.size(); n++)
{
PDOM pdom = (PDOM)pdomManager.getPDOM((ICProject) cProjectsToSearch.get(n));
IBinding[] bindings = pdom.findBindings(pattern, new NullProgressMonitor());
for (int i = 0; i < bindings.length; ++i) {
PDOMBinding binding = (PDOMBinding)bindings[i];
PDOMBinding pdomBinding = pdom.getLinkage(getTranslationUnit().getLanguage()).adaptBinding(binding);
IName[] defs= null;
if (pdomBinding instanceof IPDOMMemberOwner //class or struct
|| pdomBinding instanceof IEnumeration)
{
defs= pdom.getDefinitions(pdomBinding);
}
else if (pdomBinding instanceof ITypedef || pdomBinding instanceof IFunction)
{
defs= pdom.getDeclarations(pdomBinding);
}
if (defs != null) {
for (int j = 0; j < defs.length; j++) {
pdomNames.add(new DisplayName((IIndexName)defs[j]));
}
}
}
}
if (pdomNames.size() > 1)
{
ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_ONLY));
dialog.setElements(pdomNames.toArray());
dialog.setTitle(CEditorMessages.getString("AddIncludeOnSelection.label")); //$NON-NLS-1$
dialog.setMessage(CEditorMessages.getString("AddIncludeOnSelection.description")); //$NON-NLS-1$
if (dialog.open() == Window.OK) {
//get selection
Object[] selects = dialog.getResult();
fRequiredIncludes = new IRequiredInclude[selects.length];
List usings = new ArrayList(selects.length);
for (int i = 0; i < fRequiredIncludes.length; i++) {
IRequiredInclude include = getRequiredInclude(((DisplayName)selects[i]).getPDOMName().getFileName(), getTranslationUnit());
if (include != null) {
fRequiredIncludes[i] = include;
PDOMBinding pdomBinding = ((PDOMBinding)(((DisplayName)selects[i]).getPDOMName().resolveBinding()));
if (pdomBinding instanceof ICPPBinding)
{
//find the enclosing namespace, if there's one
IQualifiedTypeName qualifiedName = new QualifiedTypeName(getBindingQualifiedName(pdomBinding));
String qualifiedEnclosingName = (new QualifiedTypeName(qualifiedName.getEnclosingNames())).getFullyQualifiedName();
if (!qualifiedEnclosingName.equals("")) //$NON-NLS-1$
usings.add(qualifiedEnclosingName);
}
}
}
if(usings.size() > 0)
{
fUsings = new String[usings.size()];
for (int i = 0; i < usings.size(); i++)
{
fUsings[i] = (String) usings.get(i);
}
}
}
}
else if (pdomNames.size() == 1)
{
String fileName = ((DisplayName)pdomNames.get(0)).getPDOMName().getFileName();
fRequiredIncludes = new IRequiredInclude[] {getRequiredInclude(fileName, getTranslationUnit())};
PDOMBinding pdomBinding = (PDOMBinding) ((DisplayName)pdomNames.get(0)).getPDOMName().resolveBinding();
if (pdomBinding instanceof ICPPBinding)
{
//find the enclosing namespace, if there's one
IQualifiedTypeName qualifiedName = new QualifiedTypeName(getBindingQualifiedName(pdomBinding));
String qualifiedEnclosingName = new QualifiedTypeName(qualifiedName.getEnclosingNames()).getFullyQualifiedName();
if (!qualifiedEnclosingName.equals("")) //$NON-NLS-1$
fUsings = new String[] {qualifiedEnclosingName};
}
//find the enclosing namespace, if there's one
IQualifiedTypeName qualifiedName = new QualifiedTypeName(getBindingQualifiedName(binding));
String qualifiedEnclosingName = (new QualifiedTypeName(qualifiedName.getEnclosingNames())).getFullyQualifiedName();
if (!qualifiedEnclosingName.equals("")) //$NON-NLS-1$
usings.add(qualifiedEnclosingName);
}
}
}
if(usings.size() > 0)
{
fUsings = new String[usings.size()];
for (int i = 0; i < usings.size(); i++)
{
fUsings[i] = (String) usings.get(i);
}
}
}
}
else if (pdomNames.size() == 1)
{
String fileName = ((DisplayName)pdomNames.get(0)).getName().getFileName();
fRequiredIncludes = new IRequiredInclude[] {getRequiredInclude(fileName, getTranslationUnit())};
IIndexBinding binding = ((DisplayName)pdomNames.get(0)).getBinding();
if (binding instanceof ICPPBinding) {
//find the enclosing namespace, if there's one
IQualifiedTypeName qualifiedName = new QualifiedTypeName(getBindingQualifiedName(binding));
String qualifiedEnclosingName = new QualifiedTypeName(qualifiedName.getEnclosingNames()).getFullyQualifiedName();
if (!qualifiedEnclosingName.equals("")) //$NON-NLS-1$
fUsings = new String[] {qualifiedEnclosingName};
}
}
} catch (CoreException e) {
@ -471,17 +438,13 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
* @return binding's fully qualified name
* @throws CoreException
*/
private String getBindingQualifiedName(PDOMBinding pdomBinding) throws CoreException
private static String getBindingQualifiedName(IIndexBinding binding) throws CoreException
{
StringBuffer buf = new StringBuffer(pdomBinding.getName());
PDOMNode parent = pdomBinding.getParentNode();
while (parent != null)
{
if (parent instanceof PDOMBinding)
{
buf.insert(0, ((PDOMBinding)parent).getName() + "::"); //$NON-NLS-1$
}
parent = parent.getParentNode();
StringBuffer buf = new StringBuffer(binding.getName());
binding= binding.getParentBinding();
while (binding != null) {
buf.insert(0, binding.getName() + "::"); //$NON-NLS-1$
binding= binding.getParentBinding();
}
return buf.toString();
}

View file

@ -154,6 +154,7 @@ import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.core.IPositionConverter;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
@ -2893,10 +2894,22 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
SimplePositionTracker positionTracker= new SimplePositionTracker();
positionTracker.startTracking(doc);
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
IIndex index;
try {
IASTTranslationUnit ast= CUIPlugin.getDefault().getASTProvider().createAST(cElement, null);
index = CCorePlugin.getIndexManager().getIndex(cElement.getCProject());
index.acquireReadLock();
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
return;
} catch (InterruptedException e) {
return;
}
try {
IASTTranslationUnit ast= astProvider.createAST(cElement, index, null);
reconciled(ast, positionTracker, null);
} finally {
index.releaseReadLock();
positionTracker.stopTracking();
}
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor;
@ -40,6 +41,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.LineBackgroundPainter;
import org.eclipse.cdt.internal.ui.editor.ASTProvider.ASTRunnable;
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
/**
@ -95,11 +97,16 @@ public class InactiveCodeHighlighting implements ICReconcilingListener {
synchronized (fJobLock) {
if (fUpdateJob == null) {
fUpdateJob = new Job(CEditorMessages.getString("InactiveCodeHighlighting_job")) { //$NON-NLS-1$
protected IStatus run(IProgressMonitor monitor) {
protected IStatus run(final IProgressMonitor monitor) {
IStatus result = Status.OK_STATUS;
if (fTranslationUnit != null) {
IASTTranslationUnit ast= CUIPlugin.getDefault().getASTProvider().getAST(fTranslationUnit, ASTProvider.WAIT_YES, monitor);
reconciled(ast, null, monitor);
final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
result= astProvider.runOnAST(fTranslationUnit, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
public IStatus runOnAST(IASTTranslationUnit ast) {
reconciled(ast, null, monitor);
return Status.OK_STATUS;
}
});
}
if (monitor.isCanceled()) {
result = Status.CANCEL_STATUS;

View file

@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor;
@ -40,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.editor.ASTProvider.ASTRunnable;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedPosition;
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
@ -420,7 +422,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
if (element != null) {
fJob= new Job(CEditorMessages.getString("SemanticHighlighting_job")) { //$NON-NLS-1$
protected IStatus run(IProgressMonitor monitor) {
protected IStatus run(final IProgressMonitor monitor) {
if (oldJob != null) {
try {
oldJob.join();
@ -431,14 +433,21 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
}
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
IASTTranslationUnit ast= CUIPlugin.getDefault().getASTProvider().getAST(element, ASTProvider.WAIT_YES, monitor);
reconciled(ast, null, monitor);
synchronized (fJobLock) {
// allow the job to be gc'ed
if (fJob == this)
fJob= null;
}
return Status.OK_STATUS;
final Job me= this;
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
IStatus status= astProvider.runOnAST(element, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
public IStatus runOnAST(IASTTranslationUnit ast) {
reconciled(ast, null, monitor);
synchronized (fJobLock) {
// allow the job to be gc'ed
if (fJob == me)
fJob= null;
}
return Status.OK_STATUS;
}
});
return status;
}
};
// fJob.setSystem(true);

View file

@ -183,18 +183,11 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
try {
if (parentElement instanceof ICProject) {
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM((ICProject)parentElement);
int n = 0;
PDOMLinkage firstLinkage = pdom.getFirstLinkage();
for (PDOMLinkage linkage = firstLinkage; linkage != null; linkage = linkage.getNextLinkage())
++n;
if (n == 1) {
PDOMLinkage[] linkages= pdom.getLinkages();
if (linkages.length == 1) {
// Skip linkages in hierarchy if there is only one
return getChildren(firstLinkage);
return getChildren(linkages[0]);
}
PDOMLinkage[] linkages = new PDOMLinkage[n];
int i = 0;
for (PDOMLinkage linkage = pdom.getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage())
linkages[i++] = linkage;
return linkages;
} else if (parentElement instanceof IPDOMNode) {
IPDOMNode node = (IPDOMNode)parentElement;

View file

@ -15,7 +15,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
import org.eclipse.cdt.core.index.IIndexInclude;
/**
* Represents an include relation found in the index.
@ -25,9 +25,9 @@ public class CIndexIncludeRelation {
private IPath fIncludedBy;
private IPath fIncludes;
CIndexIncludeRelation(PDOMInclude include) throws CoreException {
fIncludedBy= Path.fromOSString(include.getIncludedBy().getFileName().getString());
fIncludes= Path.fromOSString(include.getIncludes().getFileName().getString());
CIndexIncludeRelation(IIndexInclude include) throws CoreException {
fIncludedBy= Path.fromOSString(include.getIncludedByLocation());
fIncludes= Path.fromOSString(include.getIncludesLocation());
}
public boolean isSystemInclude() {
return false;

View file

@ -12,12 +12,9 @@
package org.eclipse.cdt.internal.ui.missingapi;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@ -28,7 +25,6 @@ import org.eclipse.jface.text.Region;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IPositionConverter;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -37,6 +33,10 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
@ -48,10 +48,6 @@ import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.corext.util.CModelUtil;
/**
@ -59,7 +55,7 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil;
* @since 4.0
*/
public class CIndexQueries {
private static final int ASTTU_OPTIONS = ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
private static final int ASTTU_OPTIONS = ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
private static final ICElement[] EMPTY_ELEMENTS = new ICElement[0];
private static final CIndexIncludeRelation[] EMPTY_INCLUDES = new CIndexIncludeRelation[0];
private static final CIndexQueries sInstance= new CIndexQueries();
@ -113,76 +109,37 @@ public class CIndexQueries {
*/
public CIndexIncludeRelation[] findIncludedBy(ICProject[] scope, ITranslationUnit tu, IProgressMonitor pm) {
HashMap result= new HashMap();
ICProject projectOfTU= tu.getCProject();
try {
IIndex index= CCorePlugin.getIndexManager().getIndex(scope);
index.acquireReadLock();
// mstodo progress monitor
for (int i = scope.length-1; i >= 0; i--) {
ICProject cproject = scope[i];
// prefer the project of the translation unit.
if (i != 0) {
if (cproject.equals(projectOfTU)) {
System.arraycopy(scope, 0, scope, 1, i);
scope[0]= projectOfTU;
cproject= scope[i];
try {
IPath location= tu.getLocation();
if (location != null) {
IIndexFile file= index.getFile(location);
if (file != null) {
IIndexInclude[] includes= index.findIncludedBy(file);
for (int i = 0; i < includes.length; i++) {
IIndexInclude include = includes[i];
CIndexIncludeRelation rel= new CIndexIncludeRelation(include);
result.put(rel.getIncludedBy(), rel);
}
}
}
}
CIndexIncludeRelation[] includes= findIncludedBy(cproject, tu);
for (int j = 0; j < includes.length; j++) {
CIndexIncludeRelation include = includes[j];
result.put(include.getIncludedBy(), include);
finally {
index.releaseReadLock();
}
}
catch (InterruptedException e) {
}
catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
Collection includes= result.values();
return (CIndexIncludeRelation[]) includes.toArray(new CIndexIncludeRelation[includes.size()]);
}
/**
* Searches for all include-relations in a project that include the given translation unit.
* @param project the project to be searched.
* @param tu a translation unit
* @return an array of include relations.
* @since 4.0
*/
public CIndexIncludeRelation[] findIncludedBy(ICProject project, ITranslationUnit tu) {
try {
PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
if (pdom != null) {
pdom.acquireReadLock();
try {
PDOMFile fileTarget= pdom.getFile(locationForTU(tu));
if (fileTarget != null) {
ArrayList result= new ArrayList();
PDOMInclude include= fileTarget.getFirstIncludedBy();
while (include != null) {
try {
result.add(new CIndexIncludeRelation(include));
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
include= include.getNextInIncludedBy();
}
return (CIndexIncludeRelation[]) result.toArray(new CIndexIncludeRelation[result.size()]);
}
}
finally {
pdom.releaseReadLock();
}
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
}
return EMPTY_INCLUDES;
}
private IPath locationForTU(ITranslationUnit tu) {
IResource r= tu.getResource();
if (r != null) {
return r.getLocation();
}
return tu.getPath();
}
/**
* Searches for all include-relations defined in the given translation unit.
* @param tu a translation unit.
@ -191,37 +148,36 @@ public class CIndexQueries {
* @since 4.0
*/
public CIndexIncludeRelation[] findIncludesTo(ITranslationUnit tu, IProgressMonitor pm) {
ICProject cproject= tu.getCProject();
if (cproject != null) {
try {
PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(cproject);
if (pdom != null) {
pdom.acquireReadLock();
try {
PDOMFile fileTarget= pdom.getFile(locationForTU(tu));
if (fileTarget != null) {
try {
ICProject cproject= tu.getCProject();
if (cproject != null) {
IIndex index= CCorePlugin.getIndexManager().getIndex(cproject, IIndexManager.ADD_DEPENDENCIES);
index.acquireReadLock();
try {
IPath location= tu.getLocation();
if (location != null) {
IIndexFile file= index.getFile(location);
if (file != null) {
IIndexInclude includes[]= index.findIncludes(file);
ArrayList result= new ArrayList();
PDOMInclude include= fileTarget.getFirstInclude();
while (include != null) {
try {
result.add(new CIndexIncludeRelation(include));
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
include= include.getNextInIncludes();
for (int i = 0; i < includes.length; i++) {
IIndexInclude include = includes[i];
result.add(new CIndexIncludeRelation(include));
}
return (CIndexIncludeRelation[]) result.toArray(new CIndexIncludeRelation[result.size()]);
}
}
finally {
pdom.releaseReadLock();
}
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
finally {
index.releaseReadLock();
}
}
}
catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
catch (InterruptedException e) {
}
return EMPTY_INCLUDES;
}
@ -255,13 +211,11 @@ public class CIndexQueries {
ISourceRange range;
range = sf.getSourceRange();
ITranslationUnit tu= sf.getTranslationUnit();
IPDOM pdom= CCorePlugin.getPDOMManager().getPDOM(tu.getCProject());
if (pdom != null) {
pdom.acquireReadLock();
}
IIndex index= CCorePlugin.getIndexManager().getIndex(scope);
index.acquireReadLock();
try {
ILanguage language = tu.getLanguage();
IASTTranslationUnit ast= language.getASTTranslationUnit(tu, ASTTU_OPTIONS);
IASTTranslationUnit ast= tu.getAST(index, ASTTU_OPTIONS);
if (ast == null) {
return;
}
@ -272,58 +226,28 @@ public class CIndexQueries {
IASTName name= names[names.length-1];
for (int i = 0; i < scope.length; i++) {
ICProject project = scope[i];
findCalledBy(name, project, result);
findCalledBy(index, name, project, result);
}
}
finally {
if (pdom != null) {
pdom.releaseReadLock();
}
index.releaseReadLock();
}
}
private void findCalledBy(IASTName name, ICProject project, CalledByResult result) {
try {
PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
if (pdom != null) {
pdom.acquireReadLock();
try {
IBinding binding= getPDOMBinding(pdom, name);
if (binding != null) {
IName[] names= pdom.getReferences(binding);
for (int i = 0; i < names.length; i++) {
IName rname = names[i];
ITranslationUnit tu= getTranslationUnit(project, rname);
CIndexReference ref= new CIndexReference(tu, rname);
ICElement elem = findCalledBy(ref);
if (elem != null) {
result.add(elem, ref);
}
}
}
}
finally {
pdom.releaseReadLock();
}
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
}
}
private IBinding getPDOMBinding(PDOM pdom, IASTName name) {
private void findCalledBy(IIndex index, IASTName name, ICProject project, CalledByResult result) throws CoreException {
IBinding binding= name.resolveBinding();
IASTTranslationUnit tu= name.getTranslationUnit();
ILanguage lang= tu.getLanguage();
PDOMLinkage linkage;
try {
linkage = pdom.getLinkage(lang);
return linkage.adaptBinding(binding);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
if (binding != null) {
IName[] names= index.findReferences(binding);
for (int i = 0; i < names.length; i++) {
IName rname = names[i];
ITranslationUnit tu= getTranslationUnit(project, rname);
CIndexReference ref= new CIndexReference(tu, rname);
ICElement elem = findCalledBy(ref);
if (elem != null) {
result.add(elem, ref);
}
}
}
return null;
}
private ICElement findCalledBy(CIndexReference reference) {
@ -399,13 +323,10 @@ public class CIndexQueries {
private void findCallsInRange(ICProject[] scope, ITranslationUnit tu, IRegion range, IProgressMonitor pm, CallsToResult result)
throws CoreException, InterruptedException {
IPDOM pdom= CCorePlugin.getPDOMManager().getPDOM(tu.getCProject());
if (pdom != null) {
pdom.acquireReadLock();
}
IIndex index= CCorePlugin.getIndexManager().getIndex(scope);
index.acquireReadLock();
try {
ILanguage language = tu.getLanguage();
IASTTranslationUnit astTU= language.getASTTranslationUnit(tu, ASTTU_OPTIONS);
IASTTranslationUnit astTU= tu.getAST(index, ASTTU_OPTIONS);
if (astTU != null) {
ReferenceVisitor refVisitor= new ReferenceVisitor(astTU.getFilePath(), range.getOffset(), range.getLength());
astTU.accept(refVisitor);
@ -415,9 +336,9 @@ public class CIndexQueries {
IASTName name = refs[i];
IBinding binding= name.resolveBinding();
if (isRelevantForCallHierarchy(binding)) {
ICElement[] defs = findAllDefinitions(scope, name);
ICElement[] defs = findAllDefinitions(index, name);
if (defs.length == 0) {
ICElement elem = findAnyDeclaration(scope, name);
ICElement elem = findAnyDeclaration(index, null, name);
if (elem != null) {
defs = new ICElement[] { elem };
}
@ -431,67 +352,32 @@ public class CIndexQueries {
}
}
finally {
if (pdom != null) {
pdom.releaseReadLock();
}
index.releaseReadLock();
}
}
public ICElement[] findAllDefinitions(ICProject[] projectsToSearch, IASTName name) {
ArrayList result= new ArrayList();
for (int i = 0; i < projectsToSearch.length; i++) {
ICProject project = projectsToSearch[i];
ICElement[] definitions= findAllDefinitions(project, name);
if (definitions != null && definitions.length > 0) {
result.addAll(Arrays.asList(definitions));
}
}
return (ICElement[]) result.toArray(new ICElement[result.size()]);
}
public ICElement[] findAllDefinitions(IIndex index, IASTName name) throws CoreException {
IBinding binding= name.resolveBinding();
if (binding != null) {
IIndexName[] defs= index.findDefinitions(binding);
public ICElement[] findAllDefinitions(ICProject project, IASTName name) {
PDOM pdom;
try {
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
if (pdom != null) {
pdom.acquireReadLock();
try {
IBinding binding= getPDOMBinding(pdom, name);
if (binding != null) {
return getCElementsForNames(project, pdom.getDefinitions(binding));
}
}
finally {
pdom.releaseReadLock();
}
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
}
return EMPTY_ELEMENTS;
}
private ICElement[] getCElementsForNames(ICProject project, IName[] defs) {
if (defs != null && defs.length > 0) {
HashSet result= new HashSet(defs.length);
ArrayList result= new ArrayList();
for (int i = 0; i < defs.length; i++) {
IName defName = defs[i];
assert !defName.isReference();
ICElement elem= getCElementForName(project, defName);
if (elem != null) {
result.add(elem);
IIndexName in = defs[i];
ICElement definition= getCElementForName(null, in);
if (definition != null) {
result.add(definition);
}
}
return (ICElement[]) result.toArray(new ICElement[result.size()]);
}
return EMPTY_ELEMENTS;
}
private ICElement getCElementForName(ICProject project, IName declName) {
public ICElement getCElementForName(ICProject preferProject, IName declName) {
assert !declName.isReference();
ITranslationUnit tu= getTranslationUnit(project, declName);
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
if (tu != null) {
IRegion region= null;
if (declName instanceof IIndexName) {
@ -553,55 +439,12 @@ public class CIndexQueries {
return deltaOffset >= 0 && deltaEndoffset <= 0;
}
public ICElement findDefinition(ICProject[] projectsToSearch, IASTName name) {
name.resolveBinding();
for (int i = 0; i < projectsToSearch.length; i++) {
ICProject project = projectsToSearch[i];
ICElement definition= findDefinition(project, name);
if (definition != null) {
return definition;
}
}
return null;
}
public ICElement findDefinition(ICProject project, IASTName name) {
if (name.isDefinition()) {
return getCElementForName(project, name);
}
PDOM pdom;
try {
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
if (pdom != null) {
pdom.acquireReadLock();
try {
IBinding binding= getPDOMBinding(pdom, name);
if (binding != null) {
ICElement elem= getFirstCElementForNames(project, pdom.getDefinitions(binding));
if (elem != null) {
return elem;
}
}
}
finally {
pdom.releaseReadLock();
}
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
}
return null;
}
private ICElement getFirstCElementForNames(ICProject project, IName[] defs) {
if (defs != null) {
for (int i = 0; i < defs.length; i++) {
IName defName = defs[i];
ICElement elem= getCElementForName(project, defName);
public ICElement findAnyDeclaration(IIndex index, ICProject preferProject, IASTName name) throws CoreException {
IBinding binding= name.resolveBinding();
if (binding != null) {
IIndexName[] names= index.findNames(binding, IIndex.FIND_DECLARATIONS);
for (int i = 0; i < names.length; i++) {
ICElement elem= getCElementForName(preferProject, names[i]);
if (elem != null) {
return elem;
}
@ -609,48 +452,4 @@ public class CIndexQueries {
}
return null;
}
public ICElement findAnyDeclaration(ICProject[] projectsToSearch, IASTName name) {
name.resolveBinding();
for (int i = 0; i < projectsToSearch.length; i++) {
ICProject project = projectsToSearch[i];
ICElement declaration= findAnyDeclaration(project, name);
if (declaration != null) {
return declaration;
}
}
return null;
}
public ICElement findAnyDeclaration(ICProject project, IASTName name) {
PDOM pdom;
try {
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
if (pdom != null) {
pdom.acquireReadLock();
try {
IBinding binding= getPDOMBinding(pdom, name);
if (binding != null) {
ICElement elem= getFirstCElementForNames(project, pdom.getDefinitions(binding));
if (elem != null) {
return elem;
}
elem= getFirstCElementForNames(project, pdom.getDeclarations(binding));
if (elem != null) {
return elem;
}
}
}
finally {
pdom.releaseReadLock();
}
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
}
return null;
}
}

View file

@ -7,19 +7,22 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
/**
* @author Doug Schaefer
*
@ -27,16 +30,16 @@ import org.eclipse.core.runtime.Status;
*/
public class PDOMSearchBindingQuery extends PDOMSearchQuery {
private PDOMBinding binding;
private IIndexBinding binding;
public PDOMSearchBindingQuery(ICElement[] scope, PDOMBinding binding, int flags) {
public PDOMSearchBindingQuery(ICElement[] scope, IIndexBinding binding, int flags) {
super(scope, flags);
this.binding = binding;
}
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
try {
createMatches(binding.getLinkage().getLanguage(), binding);
createMatches(index, binding);
return Status.OK_STATUS;
} catch (CoreException e) {
return new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e);

View file

@ -7,14 +7,16 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
/**
* Element class used to group matches.
*
@ -22,14 +24,14 @@ import org.eclipse.core.runtime.CoreException;
*/
public class PDOMSearchElement {
private final PDOMBinding binding;
private final IIndexBinding binding;
private final String name;
private final String filename;
public PDOMSearchElement(PDOMName name) throws CoreException {
binding = name.getPDOMBinding();
public PDOMSearchElement(IIndexName name, IIndexBinding binding) throws CoreException {
this.binding= binding;
this.name = binding.getName();
filename = name.getFile().getFileName().getString();
filename = name.getFileName();
}
public int hashCode() {
@ -50,7 +52,7 @@ public class PDOMSearchElement {
return filename;
}
public PDOMBinding getBinding() {
public IIndexBinding getBinding() {
return binding;
}

View file

@ -7,24 +7,27 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
/**
* @author Doug Schaefer
*
@ -38,17 +41,17 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery {
this.element = element;
}
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
try {
ISourceRange range = element.getSourceRange();
ITranslationUnit tu = element.getTranslationUnit();
IASTTranslationUnit ast= tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
ILanguage language = tu.getLanguage();
IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
IASTName[] names = language.getSelectedNames(ast, range.getIdStartPos(), range.getIdLength());
for (int i = 0; i < names.length; ++i) {
IBinding binding = names[i].resolveBinding();
createMatches(language, binding);
createMatches(index, binding);
}
return Status.OK_STATUS;
} catch (CoreException e) {

View file

@ -7,22 +7,25 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.search.ui.text.Match;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
/**
* @author Doug Schaefer
*
*/
public class PDOMSearchMatch extends Match {
public PDOMSearchMatch(PDOMName name, int offset, int length) throws CoreException {
super(new PDOMSearchElement(name), offset, length);
public PDOMSearchMatch(IIndexBinding binding, IIndexName name, int offset, int length) throws CoreException {
super(new PDOMSearchElement(name, binding), offset, length);
}
public String getFileName() throws CoreException {

View file

@ -24,9 +24,6 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
@ -38,10 +35,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.ui.util.Messages;
@ -122,29 +119,12 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
pattern = (Pattern[])patternList.toArray(new Pattern[patternList.size()]);
}
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
try {
for (int i = 0; i < projects.length; ++i)
searchProject(projects[i], monitor);
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
}
}
private void searchProject(ICProject project, IProgressMonitor monitor) throws CoreException {
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(project);
try {
pdom.acquireReadLock();
} catch (InterruptedException e) {
return;
}
try {
IBinding[] bindings = pdom.findBindings(pattern, monitor);
IndexFilter filter= new IndexFilter();
IIndexBinding[] bindings = index.findBindings(pattern, false, filter, monitor);
for (int i = 0; i < bindings.length; ++i) {
PDOMBinding pdomBinding = (PDOMBinding)bindings[i];
IIndexBinding pdomBinding = bindings[i];
//check for the element type of this binding and create matches if
//the element type checkbox is checked in the C/C++ Search Page
@ -192,12 +172,13 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
matches= (flags & FIND_TYPEDEF) != 0;
}
if (matches) {
createMatches(pdomBinding.getLinkage().getLanguage(), pdomBinding);
createMatches(index, pdomBinding);
}
}
} finally {
pdom.releaseReadLock();
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
}
public String getLabel() {

View file

@ -7,6 +7,7 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@ -14,21 +15,24 @@ package org.eclipse.cdt.internal.ui.search;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
/**
* @author Doug Schaefer
@ -101,37 +105,46 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
* @param name
* @return true to filter name out of the match list
*/
protected boolean filterName(PDOMName name) {
protected boolean filterName(IIndexName name) {
return false; // i.e. keep it
}
private void collectNames(PDOMName name) throws CoreException {
while (name != null) {
private void collectNames(IIndex index, IIndexName[] names) throws CoreException {
for (int i = 0; i < names.length; i++) {
IIndexName name = names[i];
if (!filterName(name)) {
IASTFileLocation loc = name.getFileLocation();
result.addMatch(new PDOMSearchMatch(name, loc.getNodeOffset(), loc.getNodeLength()));
name = name.getNextInBinding();
IIndexBinding binding= index.findBinding(name);
result.addMatch(new PDOMSearchMatch(binding, name, loc.getNodeOffset(), loc.getNodeLength()));
}
}
}
protected void createMatches(ILanguage language, IBinding binding) throws CoreException {
IPDOMManager manager = CCorePlugin.getPDOMManager();
for (int i = 0; i < projects.length; ++i) {
PDOM pdom = (PDOM)manager.getPDOM(projects[i]);
PDOMBinding pdomBinding = pdom.getLinkage(language).adaptBinding(binding);
if (pdomBinding != null) {
if ((flags & FIND_DECLARATIONS) != 0) {
collectNames(pdomBinding.getFirstDeclaration());
}
if ((flags & FIND_DEFINITIONS) != 0) {
collectNames(pdomBinding.getFirstDefinition());
}
if ((flags & FIND_REFERENCES) != 0) {
collectNames(pdomBinding.getFirstReference());
}
}
protected void createMatches(IIndex index, IBinding binding) throws CoreException {
if (binding != null) {
IIndexName[] names= index.findNames(binding, flags);
collectNames(index, names);
}
}
public final IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
IIndex index= CCorePlugin.getIndexManager().getIndex(projects, 0);
try {
index.acquireReadLock();
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
try {
return runWithIndex(index, monitor);
}
finally {
index.releaseReadLock();
}
} catch (CoreException e) {
return e.getStatus();
}
}
abstract protected IStatus runWithIndex(IIndex index, IProgressMonitor monitor);
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@ -14,10 +15,6 @@ package org.eclipse.cdt.internal.ui.search;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@ -33,6 +30,11 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
/**
* @author Doug Schaefer
*
@ -117,10 +119,9 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
}
public IFile getFile(Object element) {
if (element instanceof PDOMName) {
PDOMName name = (PDOMName)element;
IASTFileLocation loc = name.getFileLocation();
IPath path = new Path(loc.getFileName());
if (element instanceof IIndexName) {
IIndexName name = (IIndexName)element;
IPath path = new Path(name.getFileName());
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
if (files.length > 0)
return files[0];

View file

@ -7,23 +7,25 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
/**
* @author Doug Schaefer
*
@ -39,16 +41,16 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
this.selection = selection;
}
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
protected IStatus runWithIndex(IIndex index, IProgressMonitor monitor) {
try {
IASTTranslationUnit ast= tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
ILanguage language = tu.getLanguage();
IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
for (int i = 0; i < names.length; ++i) {
IBinding binding = names[i].resolveBinding();
if (binding != null)
createMatches(language, binding);
createMatches(index, binding);
}
return Status.OK_STATUS;
} catch (CoreException e) {

View file

@ -29,8 +29,6 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
@ -65,8 +63,8 @@ public class OpenDeclarationsAction extends SelectionParseAction {
int style = 0;
// IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
// if (!pdom.isEmpty())
// style |= ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX;
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, style);
// style |= ITranslationUnit.AST_SKIP_ALL_HEADERS;
IASTTranslationUnit ast = workingCopy.getAST(null, style);
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
@ -85,24 +83,32 @@ public class OpenDeclarationsAction extends SelectionParseAction {
}
}
});
} else if (binding instanceof PDOMBinding) {
PDOMBinding pdomBinding = (PDOMBinding)binding;
IName name = pdomBinding.getFirstDefinition();
if (name == null)
name = pdomBinding.getFirstDeclaration();
if (name != null) {
final IName dname = name;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
open(dname);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
});
}
}
// mstodo revisit
// else if (binding instanceof IIndexBinding) {
// IIndexBinding pdomBinding = (IIndexBinding)binding;
// IName name = pdomBinding.getFirstDefinition();
// if (name == null)
// name = pdomBinding.getFirstDeclaration();
// // no source location - TODO spit out an error in the status bar
// if (name != null) {
// IASTFileLocation fileloc = name.getFileLocation();
// if (fileloc != null) {
// final IPath path = new Path(fileloc.getFileName());
// final int offset = fileloc.getNodeOffset();
// final int length = fileloc.getNodeLength();
// Display.getDefault().asyncExec(new Runnable() {
// public void run() {
// try {
// open(path, offset, length);
// } catch (CoreException e) {
// CUIPlugin.getDefault().log(e);
// }
// }
// });
// }
// }
// }
}
}

View file

@ -12,19 +12,25 @@
package org.eclipse.cdt.internal.ui.search.actions;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
@ -65,28 +71,48 @@ public class OpenDefinitionAction extends SelectionParseAction {
if (workingCopy == null)
return Status.CANCEL_STATUS;
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
IIndex index= CCorePlugin.getIndexManager().getIndex(workingCopy.getCProject(),
IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
try {
index.acquireReadLock();
} catch (InterruptedException e1) {
return Status.CANCEL_STATUS;
}
try {
IASTTranslationUnit ast = workingCopy.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
IASTName searchName = selectedNames[0];
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
IASTName searchName = selectedNames[0];
IBinding binding = searchName.resolveBinding();
if (binding != null) {
final IName[] declNames = ast.getDefinitions(binding);
if (declNames.length > 0) {
runInUIThread(new Runnable() {
public void run() {
try {
open(declNames[0]);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
});
IBinding binding = searchName.resolveBinding();
if (binding != null) {
final IName[] declNames = ast.getDefinitions(binding);
if (declNames.length > 0) {
IASTFileLocation fileloc = declNames[0].getFileLocation();
// no source location - TODO spit out an error in the status bar
if (fileloc != null) {
final IPath path = new Path(fileloc.getFileName());
final int offset = fileloc.getNodeOffset();
final int length = fileloc.getNodeLength();
runInUIThread(new Runnable() {
public void run() {
try {
open(path, offset, length);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
});
}
}
}
}
}
finally {
index.releaseReadLock();
}
return Status.OK_STATUS;
} catch (CoreException e) {

View file

@ -32,6 +32,7 @@ import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
@ -459,10 +460,15 @@ public class SelectionParseAction extends Action {
if (fileloc == null)
// no source location - TODO spit out an error in the status bar
return;
IPath path = new Path(fileloc.getFileName());
int currentOffset = fileloc.getNodeOffset();
int currentLength = fileloc.getNodeLength();
IPath path = new Path(fileloc.getFileName());
open(path, currentOffset, currentLength);
}
protected void open(IPath path, int currentOffset, int currentLength) throws PartInitException {
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
if (files.length > 0) {
IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]);
@ -484,8 +490,7 @@ public class SelectionParseAction extends Action {
textEditor.selectAndReveal(currentOffset, currentLength);
}
}
}
}
public void update() {
setEnabled(getSelectedStringFromEditor() != null);

View file

@ -744,11 +744,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
}
}
if (contentType != null) {
try {
return LanguageManager.getInstance().getLanguage(contentType);
} catch (CoreException exc) {
CUIPlugin.getDefault().log(exc.getStatus());
}
return LanguageManager.getInstance().getLanguage(contentType);
}
}
return null;

View file

@ -7,14 +7,17 @@
*
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
@ -28,13 +31,12 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.ITextViewer;
/**
* @author Doug Schaefer
@ -59,7 +61,7 @@ public class PDOMCompletionContributor extends DOMCompletionContributor implemen
return;
try {
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
PDOM pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
IASTName[] names = completionNode.getNames();
for (int i = 0; i < names.length; ++i) {
IASTName name = names[i];
@ -88,7 +90,7 @@ public class PDOMCompletionContributor extends DOMCompletionContributor implemen
IType type = expression.getExpressionType();
if (type != null && type instanceof IBinding) {
IBinding binding = (IBinding)type;
PDOMLinkage linkage = ((PDOM)pdom).getLinkage(workingCopy.getLanguage());
PDOMLinkage linkage = pdom.getLinkage(name.getLinkage().getID());
PDOMBinding pdomBinding = linkage.adaptBinding(binding);
if (pdomBinding != null) {
pdomBinding.accept(new IPDOMVisitor() {

View file

@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.folding;
@ -24,7 +25,9 @@ import java.util.Map;
import java.util.Stack;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.BadLocationException;
@ -71,6 +74,7 @@ import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.ASTProvider.ASTRunnable;
import org.eclipse.cdt.internal.ui.text.DocumentCharacterIterator;
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
@ -1060,7 +1064,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
}
private void computeFoldingStructure(FoldingStructureComputationContext ctx) {
private void computeFoldingStructure(final FoldingStructureComputationContext ctx) {
if (fCommentFoldingEnabled) {
// compute comment positions from partitioning
try {
@ -1079,12 +1083,19 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
if (fPreprocessorBranchFoldingEnabled) {
IASTTranslationUnit ast= ctx.getAST();
if (ast == null) {
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
ast= astProvider.getAST(getInputElement(), ASTProvider.WAIT_ACTIVE_ONLY, null);
if (ast != null) {
ctx.fAST= ast;
ctx.fASTPositionConverter= astProvider.getActivePositionConverter(getInputElement());
fInitialASTReconcile= false;
final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
IStatus status= astProvider.runOnAST(getInputElement(), ASTProvider.WAIT_ACTIVE_ONLY, null, new ASTRunnable() {
public IStatus runOnAST(IASTTranslationUnit ast) {
if (ast != null) {
ctx.fAST= ast;
ctx.fASTPositionConverter= astProvider.getActivePositionConverter(getInputElement());
fInitialASTReconcile= false;
}
return Status.OK_STATUS;
}
});
if (!status.isOK()) {
CUIPlugin.getDefault().log(status);
}
}
computeFoldingStructure(ast, ctx);

View file

@ -8,6 +8,7 @@
* Contributors:
* QNX Software Systems - initial API and implementation
* IBM Corporation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.classwizard;
@ -23,6 +24,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.viewers.IStructuredSelection;
@ -37,13 +39,15 @@ import org.eclipse.cdt.core.browser.IQualifiedTypeName;
import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.browser.TypeSearchScope;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer;
@ -56,12 +60,10 @@ import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
import org.eclipse.cdt.internal.ui.wizards.filewizard.NewSourceFileGenerator;
import org.eclipse.core.runtime.NullProgressMonitor;
public class NewClassWizardUtil {
@ -381,59 +383,76 @@ public class NewClassWizardUtil {
* {@link #SEARCH_MATCH_NOTFOUND}.
*/
public static int searchForCppType(IQualifiedTypeName typeName, ICProject project, Class queryType) {
if(project == null) {
return SEARCH_MATCH_ERROR;
}
String fullyQualifiedTypeName = typeName.getFullyQualifiedName();
IPDOMManager pdomManager = CCorePlugin.getPDOMManager();
IIndex index= null;
try {
PDOM pdom = (PDOM)pdomManager.getPDOM(project);
IBinding[] bindings = pdom.findBindings(Pattern.compile(typeName.getName()), new NullProgressMonitor());
boolean sameTypeNameExists = false;
boolean sameNameDifferentTypeExists = false;
for (int i = 0; i < bindings.length; ++i) {
ICPPBinding binding = (ICPPBinding)bindings[i];
//get the fully qualified name of this binding
String bindingFullName = CPPVisitor.renderQualifiedName(binding.getQualifiedName());
Class currentNodeType = binding.getClass();
// full binding
if (queryType.isAssignableFrom(currentNodeType)) {
if (bindingFullName.equals(fullyQualifiedTypeName)) {
return SEARCH_MATCH_FOUND_EXACT;
} else {
// same type , same name , but different name space
// see if there is an exact match;
sameTypeNameExists = true;
}
} else if(ICPPClassType.class.isAssignableFrom(currentNodeType) ||
IEnumeration.class.isAssignableFrom(currentNodeType) || // TODO - this should maybe be ICPPEnumeration
ICPPNamespace.class.isAssignableFrom(currentNodeType) ||
ITypeDef.class.isAssignableFrom(currentNodeType) ||
ICPPBasicType.class.isAssignableFrom(currentNodeType))
{
if (bindingFullName.equals(fullyQualifiedTypeName)) {
return SEARCH_MATCH_FOUND_EXACT_ANOTHER_TYPE;
} else {
// different type , same name , but different name space
sameNameDifferentTypeExists = true;
}
}
}
if(sameTypeNameExists){
return SEARCH_MATCH_FOUND_ANOTHER_NAMESPACE;
}
if(sameNameDifferentTypeExists){
return SEARCH_MATCH_FOUND_ANOTHER_TYPE;
if (project != null) {
index = CCorePlugin.getIndexManager().getIndex(project);
index.acquireReadLock();
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
return SEARCH_MATCH_ERROR;
} catch (InterruptedException e) {
}
if (index == null) {
return SEARCH_MATCH_ERROR;
}
return SEARCH_MATCH_NOTFOUND;
try {
String fullyQualifiedTypeName = typeName.getFullyQualifiedName();
try {
IndexFilter filter= new IndexFilter() {
public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID() == ILinkage.CPP_LINKAGE_ID;
}
};
// mstodo revisit, the pattern must be split
IBinding[] bindings = index.findBindings(Pattern.compile(typeName.getName()), true, filter, new NullProgressMonitor());
boolean sameTypeNameExists = false;
boolean sameNameDifferentTypeExists = false;
for (int i = 0; i < bindings.length; ++i) {
ICPPBinding binding = (ICPPBinding)bindings[i];
//get the fully qualified name of this binding
String bindingFullName = CPPVisitor.renderQualifiedName(binding.getQualifiedName());
Class currentNodeType = binding.getClass();
// full binding
if (queryType.isAssignableFrom(currentNodeType)) {
if (bindingFullName.equals(fullyQualifiedTypeName)) {
return SEARCH_MATCH_FOUND_EXACT;
} else {
// same type , same name , but different name space
// see if there is an exact match;
sameTypeNameExists = true;
}
} else if(ICPPClassType.class.isAssignableFrom(currentNodeType) ||
IEnumeration.class.isAssignableFrom(currentNodeType) || // TODO - this should maybe be ICPPEnumeration
ICPPNamespace.class.isAssignableFrom(currentNodeType) ||
ITypeDef.class.isAssignableFrom(currentNodeType) ||
ICPPBasicType.class.isAssignableFrom(currentNodeType))
{
if (bindingFullName.equals(fullyQualifiedTypeName)) {
return SEARCH_MATCH_FOUND_EXACT_ANOTHER_TYPE;
} else {
// different type , same name , but different name space
sameNameDifferentTypeExists = true;
}
}
}
if(sameTypeNameExists){
return SEARCH_MATCH_FOUND_ANOTHER_NAMESPACE;
}
if(sameNameDifferentTypeExists){
return SEARCH_MATCH_FOUND_ANOTHER_TYPE;
}
} catch (CoreException e) {
return SEARCH_MATCH_ERROR;
}
return SEARCH_MATCH_NOTFOUND;
}
finally {
index.releaseReadLock();
}
}
}