mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Getting ready to PDOM-ize the completion processor.
This commit is contained in:
parent
21dde9f148
commit
9b82414491
6 changed files with 113 additions and 210 deletions
|
@ -78,14 +78,19 @@ public interface ILanguage extends IAdaptable {
|
|||
int style) throws CoreException;
|
||||
|
||||
/**
|
||||
* Return the AST Completion Node for the given working copy at the given
|
||||
* offset.
|
||||
* Return the AST completion node for the given offset.
|
||||
*
|
||||
* @param workingCopy
|
||||
* @param reader
|
||||
* @param scanInfo
|
||||
* @param fileCreator
|
||||
* @param index
|
||||
* @param log
|
||||
* @param offset
|
||||
* @return
|
||||
* @throws CoreException
|
||||
*/
|
||||
public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) throws CoreException;
|
||||
public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException;
|
||||
|
||||
|
||||
/**
|
||||
* Gather the list of IASTNames that appear the selection with the given start offset
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.core.model;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
|
@ -456,4 +457,15 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
|||
* @since 4.0
|
||||
*/
|
||||
public IASTTranslationUnit getAST(IIndex index, int style) throws CoreException;
|
||||
|
||||
/**
|
||||
* Return the completion node using the given index and parsing style at the given offset.
|
||||
*
|
||||
* @param index
|
||||
* @param style
|
||||
* @param offset
|
||||
* @return
|
||||
* @throws CoreException
|
||||
*/
|
||||
public ASTCompletionNode getCompletionNode(IIndex index, int style, int offset) throws CoreException;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
|
@ -303,47 +304,29 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceManipulation#copy(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void copy(ICElement container, ICElement sibling, String rename, boolean force,
|
||||
IProgressMonitor monitor) throws CModelException {
|
||||
getSourceManipulationInfo().copy(container, sibling, rename, force, monitor);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceManipulation#delete(boolean, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void delete(boolean force, IProgressMonitor monitor) throws CModelException {
|
||||
getSourceManipulationInfo().delete(force, monitor);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceManipulation#move(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void move(ICElement container, ICElement sibling, String rename, boolean force,
|
||||
IProgressMonitor monitor) throws CModelException {
|
||||
getSourceManipulationInfo().move(container, sibling, rename, force, monitor);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceManipulation#rename(java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void rename(String name, boolean force, IProgressMonitor monitor)
|
||||
throws CModelException {
|
||||
getSourceManipulationInfo().rename(name, force, monitor);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceReference#getSource()
|
||||
*/
|
||||
public String getSource() throws CModelException {
|
||||
return getSourceManipulationInfo().getSource();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ISourceReference#getSourceRange()
|
||||
*/
|
||||
public ISourceRange getSourceRange() throws CModelException {
|
||||
return getSourceManipulationInfo().getSourceRange();
|
||||
}
|
||||
|
@ -376,9 +359,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return super.equals(o) && !((ITranslationUnit) o).isWorkingCopy();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#findSharedWorkingCopy(org.eclipse.cdt.internal.core.model.IBufferFactory)
|
||||
*/
|
||||
public IWorkingCopy findSharedWorkingCopy(IBufferFactory factory) {
|
||||
|
||||
// if factory is null, default factory must be used
|
||||
|
@ -394,23 +374,14 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return (WorkingCopy) perFactoryWorkingCopies.get(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.core.model.Openable#isOpen()
|
||||
*/
|
||||
public synchronized boolean isOpen() {
|
||||
return super.isOpen();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.core.model.CElement#getElementInfo(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public synchronized CElementInfo getElementInfo(IProgressMonitor monitor) throws CModelException {
|
||||
return super.getElementInfo(monitor);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.model.Openable#buildStructure(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource)
|
||||
*/
|
||||
protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException {
|
||||
TranslationUnitInfo unitInfo = (TranslationUnitInfo) info;
|
||||
|
||||
|
@ -436,9 +407,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return unitInfo.isStructureKnown();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#getContents()
|
||||
*/
|
||||
public char[] getContents() {
|
||||
try {
|
||||
IBuffer buffer = this.getBuffer();
|
||||
|
@ -448,17 +416,11 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#getSharedWorkingCopy(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.cdt.internal.core.model.IBufferFactory)
|
||||
*/
|
||||
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory)
|
||||
throws CModelException {
|
||||
return getSharedWorkingCopy(monitor, factory, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#getSharedWorkingCopy(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.cdt.internal.core.model.IBufferFactory, org.eclipse.cdt.core.model.IProblemRequestor)
|
||||
*/
|
||||
public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory, IProblemRequestor requestor)
|
||||
throws CModelException {
|
||||
|
||||
|
@ -487,16 +449,10 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return (IWorkingCopy) op.getResultElements()[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy()
|
||||
*/
|
||||
public IWorkingCopy getWorkingCopy() throws CModelException {
|
||||
return this.getWorkingCopy(null, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.cdt.internal.core.model.IBufferFactory)
|
||||
*/
|
||||
public IWorkingCopy getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory)throws CModelException{
|
||||
WorkingCopy workingCopy = new WorkingCopy(getParent(), getFile(), getContentTypeId(), factory);
|
||||
// open the working copy now to ensure contents are that of the current state of this element
|
||||
|
@ -511,9 +467,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see Openable#openParent
|
||||
*/
|
||||
protected void openParent(Object childInfo, Map newElements, IProgressMonitor pm) throws CModelException {
|
||||
try {
|
||||
super.openParent(childInfo, newElements, pm);
|
||||
|
@ -525,16 +478,10 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.IOpenable#isConsistent()
|
||||
*/
|
||||
public boolean isConsistent() throws CModelException {
|
||||
return CModelManager.getDefault().getElementsOutOfSynchWithBuffers().get(this) == null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.core.model.Openable#makeConsistent(org.eclipse.core.runtime.IProgressMonitor, boolean)
|
||||
*/
|
||||
public void makeConsistent(IProgressMonitor monitor, boolean forced) throws CModelException {
|
||||
makeConsistent(false, monitor);
|
||||
}
|
||||
|
@ -584,23 +531,14 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.model.Openable#isSourceElement()
|
||||
*/
|
||||
protected boolean isSourceElement() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#isWorkingCopy()
|
||||
*/
|
||||
public boolean isWorkingCopy() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.model.Openable#openBuffer(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException {
|
||||
|
||||
// create buffer - translation units only use default buffer factory
|
||||
|
@ -626,9 +564,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#parse()
|
||||
*/
|
||||
public Map parse() {
|
||||
throw new UnsupportedOperationException("Deprecated method"); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -681,9 +616,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return problemRequestor;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#isHeaderUnit()
|
||||
*/
|
||||
public boolean isHeaderUnit() {
|
||||
return (
|
||||
CCorePlugin.CONTENT_TYPE_CHEADER.equals(contentTypeId)
|
||||
|
@ -691,9 +623,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#isSourceUnit()
|
||||
*/
|
||||
public boolean isSourceUnit() {
|
||||
if (isHeaderUnit())
|
||||
return false;
|
||||
|
@ -706,9 +635,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#isCLanguage()
|
||||
*/
|
||||
public boolean isCLanguage() {
|
||||
return (
|
||||
CCorePlugin.CONTENT_TYPE_CSOURCE.equals(contentTypeId)
|
||||
|
@ -716,9 +642,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#isCXXLanguage()
|
||||
*/
|
||||
public boolean isCXXLanguage() {
|
||||
return (
|
||||
CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(contentTypeId)
|
||||
|
@ -726,17 +649,10 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#isASMLanguage()
|
||||
*/
|
||||
public boolean isASMLanguage() {
|
||||
return CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(contentTypeId);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ICElement#exists()
|
||||
*/
|
||||
public boolean exists() {
|
||||
IResource res = getResource();
|
||||
if (res != null)
|
||||
|
@ -763,9 +679,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#getContentTypeId()
|
||||
*/
|
||||
public String getContentTypeId() {
|
||||
return contentTypeId;
|
||||
}
|
||||
|
@ -774,9 +687,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
contentTypeId = id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.model.Openable#closing(java.lang.Object)
|
||||
*/
|
||||
protected void closing(Object info) throws CModelException {
|
||||
IContentType cType = CCorePlugin.getContentType(getCProject().getProject(), getElementName());
|
||||
if (cType != null) {
|
||||
|
@ -799,16 +709,10 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#getAST()
|
||||
*/
|
||||
public IASTTranslationUnit getAST() throws CoreException {
|
||||
return getAST(null, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.core.model.ITranslationUnit#getAST(org.eclipse.cdt.core.index.IIndex, int)
|
||||
*/
|
||||
public IASTTranslationUnit getAST(IIndex index, int style) throws CoreException {
|
||||
ICodeReaderFactory codeReaderFactory;
|
||||
if (index != null && (style & (ITranslationUnit.AST_SKIP_INDEXED_HEADERS | ITranslationUnit.AST_SKIP_ALL_HEADERS)) != 0) {
|
||||
|
@ -833,6 +737,30 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
return null;
|
||||
}
|
||||
|
||||
public ASTCompletionNode getCompletionNode(IIndex index, int style, int offset) throws CoreException {
|
||||
ICodeReaderFactory codeReaderFactory;
|
||||
if (index != null && (style & (ITranslationUnit.AST_SKIP_INDEXED_HEADERS | ITranslationUnit.AST_SKIP_ALL_HEADERS)) != 0) {
|
||||
codeReaderFactory= new IndexBasedCodeReaderFactory(index);
|
||||
}
|
||||
else {
|
||||
codeReaderFactory = SavedCodeReaderFactory.getInstance();
|
||||
}
|
||||
|
||||
IScannerInfo scanInfo = getScannerInfo( (style & ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO) == 0);
|
||||
if (scanInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CodeReader reader;
|
||||
reader = getCodeReader();
|
||||
|
||||
ILanguage language= getLanguage();
|
||||
if (language != null) {
|
||||
return language.getCompletionNode(reader, scanInfo, codeReaderFactory, index, ParserUtil.getParserLogService(), offset);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CodeReader getCodeReader() {
|
||||
CodeReader reader;
|
||||
IPath location= getLocation();
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.CDOM;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -26,20 +25,16 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IContributedModelBuilder;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
||||
|
@ -48,8 +43,6 @@ import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfigur
|
|||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -93,33 +86,7 @@ public class GCCLanguage extends AbstractLanguage {
|
|||
return ast;
|
||||
}
|
||||
|
||||
public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) throws CoreException {
|
||||
IResource resource = workingCopy.getResource();
|
||||
ICProject project = workingCopy.getCProject();
|
||||
IProject rproject = project.getProject();
|
||||
|
||||
IScannerInfo scanInfo = null;
|
||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(rproject);
|
||||
if (provider != null){
|
||||
IResource infoResource = resource != null ? resource : rproject;
|
||||
IScannerInfo buildScanInfo = provider.getScannerInformation(infoResource);
|
||||
if (buildScanInfo != null)
|
||||
scanInfo = buildScanInfo;
|
||||
else
|
||||
scanInfo = new ScannerInfo();
|
||||
}
|
||||
|
||||
// TODO use the pdom once we get enough info into it
|
||||
// PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject()).getAdapter(PDOM.class);
|
||||
// ICodeReaderFactory fileCreator = new PDOMCodeReaderFactory(pdom);
|
||||
|
||||
ICodeReaderFactory fileCreator = CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE);
|
||||
|
||||
String path
|
||||
= resource != null
|
||||
? resource.getLocation().toOSString()
|
||||
: workingCopy.getOriginalElement().getPath().toOSString();
|
||||
CodeReader reader = new CodeReader(path, workingCopy.getContents());
|
||||
public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
|
||||
IScannerExtensionConfiguration scannerExtensionConfiguration
|
||||
= C_GNU_SCANNER_EXTENSION;
|
||||
IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.CDOM;
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -26,20 +25,16 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IContributedModelBuilder;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ISourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
|
@ -48,8 +43,6 @@ import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfigur
|
|||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -93,29 +86,7 @@ public class GPPLanguage extends AbstractLanguage {
|
|||
return ast;
|
||||
}
|
||||
|
||||
public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) throws CoreException {
|
||||
IResource resource = workingCopy.getResource();
|
||||
ICProject project = workingCopy.getCProject();
|
||||
IProject rproject = project.getProject();
|
||||
|
||||
IScannerInfo scanInfo = null;
|
||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(rproject);
|
||||
if (provider != null){
|
||||
IResource infoResource = resource != null ? resource : rproject;
|
||||
IScannerInfo buildScanInfo = provider.getScannerInformation(infoResource);
|
||||
if (buildScanInfo != null)
|
||||
scanInfo = buildScanInfo;
|
||||
else
|
||||
scanInfo = new ScannerInfo();
|
||||
}
|
||||
|
||||
// TODO use the pdom once we get enough info into it
|
||||
// PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject()).getAdapter(PDOM.class);
|
||||
// ICodeReaderFactory fileCreator = new PDOMCodeReaderFactory(pdom);
|
||||
|
||||
ICodeReaderFactory fileCreator = CDOM.getInstance().getCodeReaderFactory(CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE);
|
||||
|
||||
CodeReader reader = new CodeReader(resource.getLocation().toOSString(), workingCopy.getContents());
|
||||
public ASTCompletionNode getCompletionNode(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log, int offset) throws CoreException {
|
||||
IScannerExtensionConfiguration scannerExtensionConfiguration
|
||||
= CPP_GNU_SCANNER_EXTENSION;
|
||||
IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
||||
|
|
|
@ -13,15 +13,6 @@ package org.eclipse.cdt.internal.ui.text.contentassist;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.internal.ui.CUIMessages;
|
||||
import org.eclipse.cdt.internal.ui.preferences.ProposalFilterPreferencesUtil;
|
||||
import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
|
||||
import org.eclipse.cdt.ui.text.contentassist.IProposalFilter;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtension;
|
||||
|
@ -37,6 +28,20 @@ import org.eclipse.jface.text.contentassist.IContextInformation;
|
|||
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.ICCompletionProposal;
|
||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
|
||||
import org.eclipse.cdt.ui.text.contentassist.IProposalFilter;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CUIMessages;
|
||||
import org.eclipse.cdt.internal.ui.preferences.ProposalFilterPreferencesUtil;
|
||||
import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
|
||||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*/
|
||||
|
@ -60,46 +65,61 @@ public class CCompletionProcessor2 implements IContentAssistProcessor {
|
|||
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, int offset) {
|
||||
try {
|
||||
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
|
||||
String prefix = null;
|
||||
|
||||
if (workingCopy != null) {
|
||||
fCurrentCompletionNode = workingCopy.getLanguage().getCompletionNode(workingCopy, offset);
|
||||
|
||||
if (fCurrentCompletionNode != null)
|
||||
prefix = fCurrentCompletionNode.getPrefix();
|
||||
}
|
||||
|
||||
if (prefix == null)
|
||||
prefix = scanPrefix(viewer.getDocument(), offset);
|
||||
|
||||
errorMessage = CUIMessages.getString(noCompletions);
|
||||
IIndex index = CCorePlugin.getIndexManager().getIndex(workingCopy.getCProject(),
|
||||
IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
|
||||
|
||||
List proposals = new ArrayList();
|
||||
|
||||
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "completionContributors"); //$NON-NLS-1$
|
||||
if (point == null)
|
||||
try {
|
||||
index.acquireReadLock();
|
||||
} catch (InterruptedException e) {
|
||||
return null;
|
||||
IExtension[] extensions = point.getExtensions();
|
||||
for (int i = 0; i < extensions.length; ++i) {
|
||||
IConfigurationElement[] elements = extensions[i].getConfigurationElements();
|
||||
for (int j = 0; j < elements.length; ++j) {
|
||||
IConfigurationElement element = elements[j];
|
||||
if (!"contributor".equals(element.getName())) //$NON-NLS-1$
|
||||
continue;
|
||||
Object contribObject = element.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
if (!(contribObject instanceof ICompletionContributor))
|
||||
continue;
|
||||
ICompletionContributor contributor = (ICompletionContributor)contribObject;
|
||||
contributor.contributeCompletionProposals(viewer, offset, workingCopy, fCurrentCompletionNode, prefix, proposals);
|
||||
}
|
||||
}
|
||||
|
||||
IProposalFilter filter = getCompletionFilter();
|
||||
ICCompletionProposal[] proposalsInput = (ICCompletionProposal[]) proposals.toArray(new ICCompletionProposal[proposals.size()]) ;
|
||||
ICCompletionProposal[] proposalsFiltered = filter.filterProposals(proposalsInput);
|
||||
|
||||
return proposalsFiltered;
|
||||
|
||||
try {
|
||||
String prefix = null;
|
||||
|
||||
if (workingCopy != null) {
|
||||
// TODO, to improve performance, we want to skip all headers
|
||||
// But right now we're not getting any completions
|
||||
// fCurrentCompletionNode = workingCopy.getCompletionNode(index, ITranslationUnit.AST_SKIP_ALL_HEADERS, offset);
|
||||
fCurrentCompletionNode = workingCopy.getCompletionNode(index, 0, offset);
|
||||
|
||||
if (fCurrentCompletionNode != null)
|
||||
prefix = fCurrentCompletionNode.getPrefix();
|
||||
}
|
||||
|
||||
if (prefix == null)
|
||||
prefix = scanPrefix(viewer.getDocument(), offset);
|
||||
|
||||
errorMessage = CUIMessages.getString(noCompletions);
|
||||
|
||||
List proposals = new ArrayList();
|
||||
|
||||
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "completionContributors"); //$NON-NLS-1$
|
||||
if (point == null)
|
||||
return null;
|
||||
IExtension[] extensions = point.getExtensions();
|
||||
for (int i = 0; i < extensions.length; ++i) {
|
||||
IConfigurationElement[] elements = extensions[i].getConfigurationElements();
|
||||
for (int j = 0; j < elements.length; ++j) {
|
||||
IConfigurationElement element = elements[j];
|
||||
if (!"contributor".equals(element.getName())) //$NON-NLS-1$
|
||||
continue;
|
||||
Object contribObject = element.createExecutableExtension("class"); //$NON-NLS-1$
|
||||
if (!(contribObject instanceof ICompletionContributor))
|
||||
continue;
|
||||
ICompletionContributor contributor = (ICompletionContributor)contribObject;
|
||||
contributor.contributeCompletionProposals(viewer, offset, workingCopy, fCurrentCompletionNode, prefix, proposals);
|
||||
}
|
||||
}
|
||||
|
||||
IProposalFilter filter = getCompletionFilter();
|
||||
ICCompletionProposal[] proposalsInput = (ICCompletionProposal[]) proposals.toArray(new ICCompletionProposal[proposals.size()]) ;
|
||||
ICCompletionProposal[] proposalsFiltered = filter.filterProposals(proposalsInput);
|
||||
|
||||
return proposalsFiltered;
|
||||
} finally {
|
||||
index.releaseReadLock();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
errorMessage = e.toString();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue