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 b3a35808993..3c096546ea0 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 @@ -9,9 +9,12 @@ * IBM - Initial API and implementation **********************************************************************/ package org.eclipse.cdt.core.dom; +import org.eclipse.cdt.core.browser.IWorkingCopyProvider; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.internal.core.dom.InternalASTServiceProvider; +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; /** @@ -36,6 +39,12 @@ public class CDOM implements IASTServiceProvider { public IASTServiceProvider getASTService() { + //CDOM itself is not so much "the" AST service as it acts as a proxy + //to different AST services + //Should we see the need to provide an extension point for this + //rather than purely proxying the calls to IASTServiceProvider#* + //we would have to do some discovery and co-ordination on behalf of the + //client return this; } @@ -43,17 +52,20 @@ public class CDOM implements IASTServiceProvider { public static final int PARSE_SAVED_RESOURCES = 0; public static final int PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS = 1; public static final int PARSE_WORKING_COPY_WHENEVER_POSSIBLE = 2; + private IWorkingCopyProvider provider; public ICodeReaderFactory getCodeReaderFactory( int key ) { + //TODO - eventually these factories will need to hook into the + //CodeReader caches switch( key ) { case PARSE_SAVED_RESOURCES: return SavedCodeReaderFactory.getInstance(); case PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS: - return null; //TODO + return new PartialWorkingCopyCodeReaderFactory( provider ); case PARSE_WORKING_COPY_WHENEVER_POSSIBLE: - return null; //TODO + return new WorkingCopyCodeReaderFactory( provider ); } return null; } @@ -79,4 +91,11 @@ public class CDOM implements IASTServiceProvider { return defaultService.getTranslationUnit(fileToParse, fileCreator, configuration ); } + /** + * @param workingCopyProvider + */ + public void setWorkingCopyProvider(IWorkingCopyProvider workingCopyProvider) { + this.provider = workingCopyProvider; + } + } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/PartialWorkingCopyCodeReaderFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/PartialWorkingCopyCodeReaderFactory.java new file mode 100644 index 00000000000..9a42e070bd2 --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/PartialWorkingCopyCodeReaderFactory.java @@ -0,0 +1,67 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom; + +import java.util.Arrays; +import java.util.Iterator; + +import org.eclipse.cdt.core.browser.IWorkingCopyProvider; +import org.eclipse.cdt.core.dom.CDOM; +import org.eclipse.cdt.core.dom.ICodeReaderFactory; +import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.ParserUtil; +import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; + +/** + * @author jcamelon + */ +public class PartialWorkingCopyCodeReaderFactory + implements ICodeReaderFactory { + + private final IWorkingCopyProvider provider; + + /** + * @param provider + */ + public PartialWorkingCopyCodeReaderFactory(IWorkingCopyProvider provider) { + this.provider = provider; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getUniqueIdentifier() + */ + public int getUniqueIdentifier() { + return CDOM.PARSE_WORKING_COPY_WITH_SAVED_INCLUSIONS; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForTranslationUnit(java.lang.String) + */ + public CodeReader createCodeReaderForTranslationUnit(String path) { + return ParserUtil.createReader( path, createWorkingCopyIterator() ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String) + */ + public CodeReader createCodeReaderForInclusion(String path) { + return ParserUtil.createReader( path, EmptyIterator.EMPTY_ITERATOR ); + } + + /** + * @return + */ + protected Iterator createWorkingCopyIterator() { + if( provider == null ) return EmptyIterator.EMPTY_ITERATOR; + return Arrays.asList( provider.getWorkingCopies() ).iterator(); + } + +} diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/WorkingCopyCodeReaderFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/WorkingCopyCodeReaderFactory.java new file mode 100644 index 00000000000..baf9d4b237c --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/WorkingCopyCodeReaderFactory.java @@ -0,0 +1,46 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.core.dom; + +import org.eclipse.cdt.core.browser.IWorkingCopyProvider; +import org.eclipse.cdt.core.dom.CDOM; +import org.eclipse.cdt.core.dom.ICodeReaderFactory; +import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.ParserUtil; + +/** + * @author jcamelon + */ +public class WorkingCopyCodeReaderFactory extends + PartialWorkingCopyCodeReaderFactory implements ICodeReaderFactory { + + /** + * @param provider + */ + public WorkingCopyCodeReaderFactory(IWorkingCopyProvider provider) { + super(provider); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getUniqueIdentifier() + */ + public int getUniqueIdentifier() { + return CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String) + */ + public CodeReader createCodeReaderForInclusion(String path) { + return ParserUtil.createReader(path, createWorkingCopyIterator()); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java index 522f78ecde0..9c7a7642b5a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java @@ -430,11 +430,14 @@ public class CUIPlugin extends AbstractUIPlugin { configurePluginDebugOptions(); registerAdapters(); - AllTypesCache.initialize(new IWorkingCopyProvider() { + IWorkingCopyProvider workingCopyProvider = new IWorkingCopyProvider() { public IWorkingCopy[] getWorkingCopies() { return CUIPlugin.getSharedWorkingCopies(); } - }); + }; + AllTypesCache.initialize(workingCopyProvider); + CCorePlugin.getDefault().getDOM().setWorkingCopyProvider(workingCopyProvider); + } /* (non-Javadoc)