1
/*******************************************************************************
2
* Copyright (c) 2004, 2009 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.core.dom;
12
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
13
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
14
import org.eclipse.cdt.core.model.IWorkingCopyProvider;
15
import org.eclipse.cdt.internal.core.dom.InternalASTServiceProvider;
16
import org.eclipse.cdt.internal.core.dom.PartialWorkingCopyCodeReaderFactory;
17
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
18
import org.eclipse.cdt.internal.core.dom.WorkingCopyCodeReaderFactory;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IStorage;
26
* This class serves as the manager of the AST/DOM mechanisms for the CDT.
27
* It should be eventually added to CCorePlugin for startup.
29
* @noextend This class is not intended to be subclassed by clients.
30
* @noinstantiate This class is not intended to be instantiated by clients.
31
* @deprecated This class does not take into account language mappings. Use
32
* org.eclipse.cdt.core.model.ILanguage instead.
35
public class CDOM implements IASTServiceProvider {
38
* Singleton - Constructor is private.
45
* <code>instance</code> is the singleton.
47
private static CDOM instance = new CDOM();
50
* accessor for singleton instance
53
public static CDOM getInstance()
59
* Currently, only one AST Service is provided.
61
private IASTServiceProvider defaultService = new InternalASTServiceProvider();
65
* @return IASTServiceProvider, the mechanism for obtaining an AST
67
public IASTServiceProvider getASTService() {
68
//CDOM itself is not so much "the" AST service as it acts as a proxy
69
//to different AST services
70
//Should we see the need to provide an extension point for this
71
//rather than purely proxying the calls to IASTServiceProvider#*
72
//we would have to do some discovery and co-ordination on behalf of the
79
* Constant <code>PARSE_SAVED_RESOURCES</code> - Parse saved resources in the workspace
81
public static final int PARSE_SAVED_RESOURCES = 0;
83
* Constant <code>PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS</code> - Parse working copy for
84
* translation unit, saved resources for all header files.
86
public static final int PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS = 1;
88
* Constant <code>PARSE_WORKING_COPY_WHENEVER_POSSIBLE</code> - Parse working copy whenever possible for both
89
* header files and the file in question as a translation unit.
91
public static final int PARSE_WORKING_COPY_WHENEVER_POSSIBLE = 2;
95
* <code>provider</code> is registered by the UI as a IWorkingCopyProvider.
97
private IWorkingCopyProvider provider;
100
* This is the factory function that returns an ICodeReaderFactory instance based upon the key provided.
102
* @param key one of PARSE_SAVED_RESOURCES, PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS, PARSE_WORKING_COPY_WHENEVER_POSSIBLE
103
* @return an implementation that works according to the key specified or null for an invalid key
105
public ICodeReaderFactory getCodeReaderFactory( int key )
107
//TODO - eventually these factories will need to hook into the
111
case PARSE_SAVED_RESOURCES:
112
return SavedCodeReaderFactory.getInstance();
113
case PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS:
114
return new PartialWorkingCopyCodeReaderFactory(provider, null);
115
case PARSE_WORKING_COPY_WHENEVER_POSSIBLE:
116
return new WorkingCopyCodeReaderFactory( provider, null );
122
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.core.resources.IFile)
124
public IASTTranslationUnit getTranslationUnit(IFile fileToParse) throws UnsupportedDialectException {
125
//TODO - At this time, we purely delegate blindly
126
//In the future, we may need to delegate based upon context provided
127
return defaultService.getTranslationUnit(fileToParse);
131
* @see org.eclipse.cdt.core.dom.IASTServiceProvider#getTranslationUnit(org.eclipse.core.resources.IFile, org.eclipse.cdt.core.dom.ICodeReaderFactory)
133
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
134
//TODO - At this time, we purely delegate blindly
135
//In the future, we may need to delegate based upon context provided
136
return defaultService.getTranslationUnit(fileToParse, fileCreator );
140
* @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)
142
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator, IParserConfiguration configuration) throws UnsupportedDialectException {
143
//TODO - At this time, we purely delegate blindly
144
//In the future, we may need to delegate based upon context provided
145
return defaultService.getTranslationUnit(fileToParse, fileCreator, configuration );
148
public IASTCompletionNode getCompletionNode(IFile fileToParse, int offset,
149
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
150
//TODO - At this time, we purely delegate blindly
151
//In the future, we may need to delegate based upon context provided
152
return defaultService.getCompletionNode(fileToParse, offset, fileCreator);
155
public IASTCompletionNode getCompletionNode(IStorage fileToParse, IProject project, int offset,
156
ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
157
//TODO - At this time, we purely delegate blindly
158
//In the future, we may need to delegate based upon context provided
159
return defaultService.getCompletionNode(fileToParse, project, offset, fileCreator);
163
* This method allows a UI component to register its IWorkingCopyProvider to the CDOM.
165
* @param workingCopyProvider - UI components buffer manager
167
public void setWorkingCopyProvider(IWorkingCopyProvider workingCopyProvider) {
168
this.provider = workingCopyProvider;
171
public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project, ICodeReaderFactory fileCreator) throws UnsupportedDialectException {
172
return defaultService.getTranslationUnit( fileToParse, project, fileCreator );
175
public IASTTranslationUnit getTranslationUnit(IStorage fileToParse, IProject project) throws UnsupportedDialectException {
176
return defaultService.getTranslationUnit( fileToParse, project );
179
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, boolean parseComments) throws UnsupportedDialectException {
180
return defaultService.getTranslationUnit(fileToParse, parseComments);
183
public IASTTranslationUnit getTranslationUnit(IFile fileToParse, ICodeReaderFactory fileCreator, boolean parseComments) throws UnsupportedDialectException {
184
return defaultService.getTranslationUnit(fileToParse, fileCreator, parseComments);