Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[Dltk-dev] SourceModuleInfoCahce and folding

Hi,
 
 I upgrade ANTLR IDE to work with DLTK 1.0. I noted the parse method on AbstractASTFoldingStructureProvider

protected final ModuleDeclaration parse(String code, int offset) {
        if (offset == 0 && fInput instanceof ISourceModule) {
            final ISourceModule module = (ISourceModule) fInput;
            try {
                if (code.equals(module.getSource())) {
                    // use the cache luke! ;)
                    return SourceParserUtil.getModuleDeclaration(module);
                }
            } catch (ModelException e) {
                getLog().log(
                        new Status(IStatus.WARNING, DLTKUIPlugin.PLUGIN_ID, e
                                .getMessage(), e));
            }
        }
        return getSourceParser().parse(null, code.toCharArray(), null);
    }

This method is great because in almost cases it gets the cached ModuleDeclaration, so I don't need to parse the file again.
Now, when open one file I get two calls to my org.eclipse.dltk.ast.parser.AbstractSourceParser.parse method.
The first call is:

Thread [main] (Suspended (breakpoint at line 38 in AntlrSourceParser))   
    AntlrSourceParser.parse(char[], char[], IProblemReporter) line: 38   
    SourceParserUtil.getModuleDeclaration(ISourceModule, IProblemReporter, ISourceModuleInfoCache$ISourceModuleInfo, int) line: 84   
    SourceParserUtil.getModuleDeclaration(ISourceModule, IProblemReporter, ISourceModuleInfoCache$ISourceModuleInfo) line: 40   
    AntlrSourceElementParser.parse(ISourceModule, ISourceModuleInfoCache$ISourceModuleInfo) line: 112   
    AntlrSourceElementParser(AbstractSourceElementParser).parseSourceModule(ISourceModule, ISourceModuleInfoCache$ISourceModuleInfo) line: 28   
    AntlrSourceElementParser.parseSourceModule(ISourceModule, ISourceModuleInfoCache$ISourceModuleInfo) line: 68   
    SourceParserUtil.parseSourceModule(ISourceModule, ISourceElementParser) line: 187   
    SourceModule(AbstractSourceModule).buildStructure(OpenableElementInfo, IProgressMonitor, Map, IResource) line: 529   
    SourceModule(Openable).generateInfos(Object, HashMap, IProgressMonitor) line: 182   
    SourceModule(ModelElement).openWhenClosed(Object, IProgressMonitor) line: 177   

and it's perfectly OK, now the second call is:

Thread [main] (Suspended (breakpoint at line 38 in AntlrSourceParser))   
    AntlrSourceParser.parse(char[], char[], IProblemReporter) line: 38   
    SourceParserUtil.getModuleDeclaration(ISourceModule, IProblemReporter, ISourceModuleInfoCache$ISourceModuleInfo, int) line: 84   
    SourceParserUtil.getModuleDeclaration(ISourceModule, IProblemReporter, int) line: 35   
    SourceParserUtil.getModuleDeclaration(ISourceModule) line: 20   
    AntlrFoldingStructureProvider(AbstractASTFoldingStructureProvider).parse(String, int) line: 1239   

In this second call SourceParseUtil can't find the ModuleDeclaration in the cache because the cache was destroyed before the call. I don't know why but it's not right (I think).
The cache is destroyed in SourceModuleInfoCache line 110 and this is because the method isWorkingCopy returns true:
 if (delta.getKind() == IModelElementDelta.REMOVED
                            || isContentChanged(delta) || isWorkingCopy(delta)) {
                        ...
                        SourceModuleInfoCache.this
                                .remove((ISourceModule) element);


It could be fix it?

Thanks!
--
edgar

Back to the top