diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/dom/CDOM.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/dom/CDOM.java index 6e117037ecf..648c4d32a71 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/dom/CDOM.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/dom/CDOM.java @@ -17,6 +17,8 @@ import org.eclipse.cdt.internal.core.dom.PartialWorkingCopyCodeReaderFactory; import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory; import org.eclipse.cdt.internal.core.dom.WorkingCopyCodeReaderFactory; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IStorage; /** * @author jcamelon @@ -156,4 +158,12 @@ public class CDOM implements IASTServiceProvider { this.provider = workingCopyProvider; } + public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project, ICodeReaderFactory fileCreator) throws UnsupportedDialectException { + return defaultService.getTranslationUnit( fileToParse, project, fileCreator ); + } + + public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project) throws UnsupportedDialectException { + return defaultService.getTranslationUnit( fileToParse, project ); + } + } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/dom/IASTServiceProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/dom/IASTServiceProvider.java index 975513630e3..dafdf3d6308 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/dom/IASTServiceProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/dom/IASTServiceProvider.java @@ -13,6 +13,8 @@ package org.eclipse.cdt.core.dom; import org.eclipse.cdt.core.dom.ast.ASTCompletionNode; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IStorage; /** * This is the mechanism that represents a parser service in the CDT. @@ -43,6 +45,26 @@ public interface IASTServiceProvider { */ public IASTTranslationUnit getTranslationUnit( IFile fileToParse) throws UnsupportedDialectException; + /** + * Returns a parse tree that represents the content provided as parameters. + * + * @param fileToParse the file in question + * @param project project handle to help us figure out build settings + * @param fileCreator @see CDOM#getCodeReaderFactory(int) + * @return syntactical parse tree + * @throws UnsupportedDialectException + */ + public IASTTranslationUnit getTranslationUnit( IStorage fileToParse, IProject project, ICodeReaderFactory fileCreator ) throws UnsupportedDialectException; + + /** + * Returns a parse tree that represents the content provided as parameters. + * + * @param fileToParse the file in question + * @param project project handle to help us figure out build settings + * @return syntactical parse tree + * @throws UnsupportedDialectException + */ + public IASTTranslationUnit getTranslationUnit( IStorage fileToParse, IProject project ) throws UnsupportedDialectException; /** * Returns a parse tree that represents the content provided as parameters. * @@ -63,7 +85,7 @@ public interface IASTServiceProvider { * @throws UnsupportedDialectException */ public IASTTranslationUnit getTranslationUnit( IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration )throws UnsupportedDialectException; - + /** * Returns a parse tree that represents the content provided as parameters. * diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java index 16188fa1f70..3046a01ca27 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java @@ -43,6 +43,8 @@ import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfigurat import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.IPath; /** * @author jcamelon @@ -68,14 +70,14 @@ public class InternalASTServiceProvider implements IASTServiceProvider { * @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit() */ public IASTTranslationUnit getTranslationUnit(IFile fileToParse) throws UnsupportedDialectException { - return getTranslationUnit( fileToParse, SavedCodeReaderFactory.getInstance(), null ); + return getTranslationUnit( fileToParse, fileToParse.getLocation().toOSString(), fileToParse.getProject(), SavedCodeReaderFactory.getInstance(), null ); } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.cdt.core.dom.ICodeReaderFactory) */ public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator) throws UnsupportedDialectException { - return getTranslationUnit( fileToParse, fileCreator, null ); + return getTranslationUnit( fileToParse, fileToParse.getLocation().toOSString(), fileToParse.getProject(), fileCreator, null ); } /* (non-Javadoc) @@ -83,15 +85,24 @@ public class InternalASTServiceProvider implements IASTServiceProvider { */ public IASTTranslationUnit getTranslationUnit( IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException { - //Get the scanner info - IProject currentProject = fileToParse.getProject(); + return getTranslationUnit( fileToParse, fileToParse.getLocation().toOSString(), fileToParse.getProject(), fileCreator, configuration ); + } + + public IASTTranslationUnit getTranslationUnit( + IStorage fileToParse, String os_path, IProject project, ICodeReaderFactory fileCreator, IParserConfiguration configuration ) throws UnsupportedDialectException + { IScannerInfo scanInfo = null; if( configuration == null ) { - IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject); + IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project); if (provider != null){ - IScannerInfo buildScanInfo = provider.getScannerInformation(fileToParse); + IScannerInfo buildScanInfo = null; + if( fileToParse instanceof IResource ) + buildScanInfo = provider.getScannerInformation( (IResource) fileToParse ); + else + buildScanInfo = provider.getScannerInformation( project); + if (buildScanInfo != null){ scanInfo = buildScanInfo; } @@ -103,13 +114,15 @@ public class InternalASTServiceProvider implements IASTServiceProvider { scanInfo = configuration.getScannerInfo(); - CodeReader reader = fileCreator.createCodeReaderForTranslationUnit( fileToParse.getLocation().toOSString() ); + CodeReader reader = fileCreator.createCodeReaderForTranslationUnit( os_path ); + if( reader == null ) + return null; IScanner scanner = null; ISourceCodeParser parser = null; if( configuration == null ) { - ParserLanguage l = getLanguage(fileToParse); + ParserLanguage l = getLanguage(fileToParse.getFullPath(), project); IScannerExtensionConfiguration scannerExtensionConfiguration = null; if( l == ParserLanguage.CPP ) scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION; @@ -187,7 +200,7 @@ public class InternalASTServiceProvider implements IASTServiceProvider { .createCodeReaderForTranslationUnit(fileToParse.getLocation() .toOSString()); - ParserLanguage l = getLanguage(fileToParse); + ParserLanguage l = getLanguage(fileToParse.getLocation(), currentProject); IScannerExtensionConfiguration scannerExtensionConfiguration = null; if (l == ParserLanguage.CPP) scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION; @@ -227,10 +240,9 @@ public class InternalASTServiceProvider implements IASTServiceProvider { return dialects; } - private ParserLanguage getLanguage( IResource resource ) + private ParserLanguage getLanguage( IPath path, IProject project ) { - IProject project = resource.getProject(); - ICFileType type = CCorePlugin.getDefault().getFileType(project, resource.getLocation().lastSegment()); + ICFileType type = CCorePlugin.getDefault().getFileType(project, path.lastSegment()); boolean isHeader= type.isHeader(); if( isHeader ) return ParserLanguage.CPP; // assumption @@ -241,4 +253,12 @@ public class InternalASTServiceProvider implements IASTServiceProvider { return ParserLanguage.C; return ParserLanguage.CPP; } + + public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project, ICodeReaderFactory fileCreator) throws UnsupportedDialectException{ + return getTranslationUnit( fileToParse, fileToParse.getFullPath().toOSString(), project, fileCreator, null ); + } + + public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project) throws UnsupportedDialectException { + return getTranslationUnit( fileToParse, fileToParse.getFullPath().toOSString(), project, SavedCodeReaderFactory.getInstance(), null ); + } }