mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed Bug 92915 - [Parser] CDOM doesn't support parse of external files (IStorage)
This commit is contained in:
parent
47135c2117
commit
75c231fe01
3 changed files with 65 additions and 13 deletions
|
@ -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.SavedCodeReaderFactory;
|
||||||
import org.eclipse.cdt.internal.core.dom.WorkingCopyCodeReaderFactory;
|
import org.eclipse.cdt.internal.core.dom.WorkingCopyCodeReaderFactory;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
|
@ -156,4 +158,12 @@ public class CDOM implements IASTServiceProvider {
|
||||||
this.provider = workingCopyProvider;
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.ASTCompletionNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.core.resources.IFile;
|
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.
|
* 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;
|
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.
|
* Returns a parse tree that represents the content provided as parameters.
|
||||||
*
|
*
|
||||||
|
|
|
@ -43,6 +43,8 @@ import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfigurat
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.IStorage;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
|
@ -68,14 +70,14 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit()
|
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit()
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit getTranslationUnit(IFile fileToParse) throws UnsupportedDialectException {
|
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)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.cdt.core.dom.ICodeReaderFactory)
|
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.cdt.core.dom.ICodeReaderFactory)
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
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)
|
/* (non-Javadoc)
|
||||||
|
@ -83,15 +85,24 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit getTranslationUnit(
|
public IASTTranslationUnit getTranslationUnit(
|
||||||
IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException {
|
IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException {
|
||||||
//Get the scanner info
|
return getTranslationUnit( fileToParse, fileToParse.getLocation().toOSString(), fileToParse.getProject(), fileCreator, configuration );
|
||||||
IProject currentProject = fileToParse.getProject();
|
}
|
||||||
|
|
||||||
|
public IASTTranslationUnit getTranslationUnit(
|
||||||
|
IStorage fileToParse, String os_path, IProject project, ICodeReaderFactory fileCreator, IParserConfiguration configuration ) throws UnsupportedDialectException
|
||||||
|
{
|
||||||
IScannerInfo scanInfo = null;
|
IScannerInfo scanInfo = null;
|
||||||
|
|
||||||
if( configuration == null )
|
if( configuration == null )
|
||||||
{
|
{
|
||||||
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject);
|
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
|
||||||
if (provider != null){
|
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){
|
if (buildScanInfo != null){
|
||||||
scanInfo = buildScanInfo;
|
scanInfo = buildScanInfo;
|
||||||
}
|
}
|
||||||
|
@ -103,13 +114,15 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
scanInfo = configuration.getScannerInfo();
|
scanInfo = configuration.getScannerInfo();
|
||||||
|
|
||||||
|
|
||||||
CodeReader reader = fileCreator.createCodeReaderForTranslationUnit( fileToParse.getLocation().toOSString() );
|
CodeReader reader = fileCreator.createCodeReaderForTranslationUnit( os_path );
|
||||||
|
if( reader == null )
|
||||||
|
return null;
|
||||||
IScanner scanner = null;
|
IScanner scanner = null;
|
||||||
ISourceCodeParser parser = null;
|
ISourceCodeParser parser = null;
|
||||||
|
|
||||||
if( configuration == null )
|
if( configuration == null )
|
||||||
{
|
{
|
||||||
ParserLanguage l = getLanguage(fileToParse);
|
ParserLanguage l = getLanguage(fileToParse.getFullPath(), project);
|
||||||
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
||||||
if( l == ParserLanguage.CPP )
|
if( l == ParserLanguage.CPP )
|
||||||
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
||||||
|
@ -187,7 +200,7 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
.createCodeReaderForTranslationUnit(fileToParse.getLocation()
|
.createCodeReaderForTranslationUnit(fileToParse.getLocation()
|
||||||
.toOSString());
|
.toOSString());
|
||||||
|
|
||||||
ParserLanguage l = getLanguage(fileToParse);
|
ParserLanguage l = getLanguage(fileToParse.getLocation(), currentProject);
|
||||||
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
||||||
if (l == ParserLanguage.CPP)
|
if (l == ParserLanguage.CPP)
|
||||||
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
||||||
|
@ -227,10 +240,9 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
return dialects;
|
return dialects;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ParserLanguage getLanguage( IResource resource )
|
private ParserLanguage getLanguage( IPath path, IProject project )
|
||||||
{
|
{
|
||||||
IProject project = resource.getProject();
|
ICFileType type = CCorePlugin.getDefault().getFileType(project, path.lastSegment());
|
||||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, resource.getLocation().lastSegment());
|
|
||||||
boolean isHeader= type.isHeader();
|
boolean isHeader= type.isHeader();
|
||||||
if( isHeader )
|
if( isHeader )
|
||||||
return ParserLanguage.CPP; // assumption
|
return ParserLanguage.CPP; // assumption
|
||||||
|
@ -241,4 +253,12 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
return ParserLanguage.C;
|
return ParserLanguage.C;
|
||||||
return ParserLanguage.CPP;
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue