mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Restructure IASTServiceProvider & CDOM to encapsulate more the process of matching up a parse request w/an AST Service provider.
Clients should not need to figure out what provider fits them best, we can do that for them.
This commit is contained in:
parent
b385ee2234
commit
4e7213552c
3 changed files with 30 additions and 43 deletions
|
@ -9,8 +9,10 @@
|
|||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.core.dom;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.InternalASTServiceProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -18,7 +20,7 @@ import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
|
|||
* This class serves as the manager of the AST/DOM mechanisms for the CDT.
|
||||
* It should be eventually added to CCorePlugin for startup.
|
||||
*/
|
||||
public class CDOM {
|
||||
public class CDOM implements IASTServiceProvider {
|
||||
|
||||
private CDOM()
|
||||
{
|
||||
|
@ -29,45 +31,14 @@ public class CDOM {
|
|||
{
|
||||
return instance;
|
||||
}
|
||||
private IASTServiceProvider [] services = { new InternalASTServiceProvider() };
|
||||
|
||||
private IASTServiceProvider defaultService = new InternalASTServiceProvider();
|
||||
|
||||
public IASTServiceProvider[] getASTServices() {
|
||||
return services;
|
||||
|
||||
public IASTServiceProvider getASTService() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public IASTServiceProvider getDefaultASTService() {
|
||||
IASTServiceProvider [] factories = getASTServices();
|
||||
if( factories != null && factories.length > 0 )
|
||||
return factories[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
public IASTServiceProvider getASTServiceByName(String name) {
|
||||
IASTServiceProvider [] factories = getASTServices();
|
||||
if( factories == null || factories.length == 0 )
|
||||
return null;
|
||||
for( int i = 0; i < factories.length; ++i )
|
||||
if( factories[i] != null && factories[i].getName().equals( name ) )
|
||||
return factories[i];
|
||||
return null;
|
||||
}
|
||||
|
||||
public IASTServiceProvider getASTServiceByDialect( String dialect )
|
||||
{
|
||||
IASTServiceProvider [] factories = getASTServices();
|
||||
if( factories == null || factories.length == 0 )
|
||||
return null;
|
||||
for( int i = 0; i < factories.length; ++i )
|
||||
if( factories[i] != null )
|
||||
{
|
||||
String [] dialects = factories[i].getSupportedDialects();
|
||||
if( dialects != null )
|
||||
for( int j = 0; j < dialects.length; ++j )
|
||||
if( dialects[j].equals( dialect ))
|
||||
return factories[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final int PARSE_SAVED_RESOURCES = 0;
|
||||
public static final int PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS = 1;
|
||||
|
@ -86,7 +57,26 @@ public class CDOM {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.core.resources.IFile)
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit(IFile fileToParse) throws UnsupportedDialectException {
|
||||
return defaultService.getTranslationUnit(fileToParse);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.core.resources.IFile, org.eclipse.cdt.core.dom.ICodeReaderFactory)
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
|
||||
return defaultService.getTranslationUnit(fileToParse, fileCreator );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.core.resources.IFile, org.eclipse.cdt.core.dom.ICodeReaderFactory, org.eclipse.cdt.core.dom.IParserConfiguration)
|
||||
*/
|
||||
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException {
|
||||
return defaultService.getTranslationUnit(fileToParse, fileCreator, configuration );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,13 +22,10 @@ public interface IASTServiceProvider {
|
|||
{
|
||||
}
|
||||
|
||||
public String getName();
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit( IFile fileToParse) throws UnsupportedDialectException;
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit( IFile fileToParse, ICodeReaderFactory fileCreator )throws UnsupportedDialectException;
|
||||
|
||||
public IASTTranslationUnit getTranslationUnit( IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration )throws UnsupportedDialectException;
|
||||
|
||||
public String [] getSupportedDialects();
|
||||
|
||||
}
|
||||
|
|
|
@ -207,7 +207,7 @@ private static final String DOMAST_FILTER_GROUP_ID = "org.eclipse.cdt.ui.tests.D
|
|||
IPopulateDOMASTAction action = null;
|
||||
IASTTranslationUnit tu = null;
|
||||
try {
|
||||
tu = CDOM.getInstance().getDefaultASTService().getTranslationUnit(
|
||||
tu = CDOM.getInstance().getASTService().getTranslationUnit(
|
||||
aFile,
|
||||
CDOM.getInstance().getCodeReaderFactory(
|
||||
CDOM.PARSE_SAVED_RESOURCES));
|
||||
|
|
Loading…
Add table
Reference in a new issue