Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [Dltk-dev] How can I get module declaration from ScriptEditor?

HI Edgar,
> Hi, I need to access to ModuleDeclaration from my ScriptEditor, it is
> posible?
> Thanks.
>   
Each script editor has associated IModelElement object, so first you
need to get source module from editor. After you get ISourceModule
object you could obtain ModuleDeclaration using our helper class.

>>>>>>
ScriptEditor editor = ...   // This also could be done from derived class.
IModelElement element = editor.getInputModelElement(); // Get editor
input model element.
ISourceModule sourceModule = null;
if( element instanceof ISourceModule ) {
    sourceModule = (ISourceModule)element;
}
else {
    // get source module if we edit child, it will be possible in future.
    sourceModule = element.getAncestor(IModelElement.SOURCE_MODULE);
}
ModuleDeclaration moduleDeclaration =
SourceParserUtil.getModuleDeclaration(sourceModule, null);
>>>>>>
ModuleDeclaration will be obtained from cache.

Also: If you also want to use cache then build model you should also use
SourceParserUtil helper class to get ModuleDeclaration.

parseSourceModule method in your SourceElementParser class should look like:
>>>>>>
public ModuleDeclaration parseSourceModule(char[] contents,
            ISourceModuleInfo astCache, char[] filename) {

        ModuleDeclaration moduleDeclaration = SourceParserUtil
                .getModuleDeclaration(filename, contents,
                        PythonNature.NATURE_ID, this.fReporter, astCache);

        PythonSourceElementRequestor requestor = new
PythonSourceElementRequestor(
                this.fRequestor);

        try {
            moduleDeclaration.traverse(requestor);
        } catch (Exception e) {
            if (DLTKCore.DEBUG) {
                e.printStackTrace();
            }
        }
        return moduleDeclaration;
    }
>>>>>>

Best regards,
Andrei.

> --
> This message was scanned by ESVA and is believed to be clean.
> Click here to report this message as spam. 
> http://mail-gw-us.xored.com/cgi-bin/learn-msg.cgi?id=037C22821D.328E0
>
>
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> dltk-dev mailing list
> dltk-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/dltk-dev
>   



Back to the top