From 6ad34a2f752498f698c00cfb26be69ff4b2ec5bf Mon Sep 17 00:00:00 2001 From: John Camelon Date: Thu, 24 Mar 2005 00:49:51 +0000 Subject: [PATCH] Fixed Bug 88927 - Bug 88927 - EmptyCodeReaderCache ignores working copies --- .../eclipse/cdt/core/parser/ParserUtil.java | 14 ++++++++++++++ .../PartialWorkingCopyCodeReaderFactory.java | 18 ++++++++++++++---- .../core/dom/WorkingCopyCodeReaderFactory.java | 3 +-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java index 3c38880ec01..acd3eb195e7 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java @@ -49,6 +49,20 @@ public class ParserUtil return scannerLogService; } + public static char [] findWorkingCopyBuffer( String path, Iterator workingCopies ) + { + IResource resultingResource = getResourceForFilename(path); + + if( resultingResource != null && resultingResource.getType() == IResource.FILE ) + { + // this is the file for sure + // check the working copy + if( workingCopies.hasNext() ) + return findWorkingCopy( resultingResource, workingCopies ); + } + return null; + } + public static CodeReader createReader( String finalPath, Iterator workingCopies ) { // check to see if the file which this path points to points to an 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 index f1e6442e637..cbfe816ccb7 100644 --- 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 @@ -12,13 +12,12 @@ 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.ICodeReaderCache; -import org.eclipse.cdt.internal.core.dom.parser.EmptyCodeReaderCache; +import org.eclipse.cdt.core.parser.ParserUtil; import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator; /** @@ -35,7 +34,7 @@ public class PartialWorkingCopyCodeReaderFactory */ public PartialWorkingCopyCodeReaderFactory(IWorkingCopyProvider provider) { this.provider = provider; - cache = new EmptyCodeReaderCache(); + cache = SavedCodeReaderFactory.getInstance().getCodeReaderCache(); } /* (non-Javadoc) @@ -49,9 +48,20 @@ public class PartialWorkingCopyCodeReaderFactory * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForTranslationUnit(java.lang.String) */ public CodeReader createCodeReaderForTranslationUnit(String path) { - return ((EmptyCodeReaderCache)cache).createReader( path, createWorkingCopyIterator() ); + return checkWorkingCopyThenCache(path); } + /** + * @param path + * @return + */ + protected CodeReader checkWorkingCopyThenCache(String path) { + char [] buffer = ParserUtil.findWorkingCopyBuffer( path, createWorkingCopyIterator() ); + if( buffer != null ) + return new CodeReader(path, buffer); + return cache.get( path ); + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String) */ 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 index baf9d4b237c..541b89d572b 100644 --- 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 @@ -14,7 +14,6 @@ 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 @@ -40,7 +39,7 @@ public class WorkingCopyCodeReaderFactory extends * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String) */ public CodeReader createCodeReaderForInclusion(String path) { - return ParserUtil.createReader(path, createWorkingCopyIterator()); + return checkWorkingCopyThenCache(path); } }