1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Add support for IWorkingCopy in CDOM & ICodeReaderFactory.

This commit is contained in:
John Camelon 2005-02-10 18:44:08 +00:00
parent af477cff1d
commit 11f48787a5
4 changed files with 139 additions and 4 deletions

View file

@ -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;
}
}

View file

@ -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();
}
}

View file

@ -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());
}
}

View file

@ -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)