Re: [Pydev-code] Analyse python class
Brought to you by:
fabioz
From: Marek J. <mar...@gm...> - 2015-11-08 19:12:20
|
Thanks Fabio, It works excellent! I will let you know when I will be releasing a new version with python support. Thank you for your great work you are doing with PyDev. Marek 2015-11-08 10:19 GMT+01:00 Fabio Zadrozny <fa...@gm...>: > Hi Marek, > > Yes, there's code to do that... The idea is that you get the AST for a > module and then work in the AST (usually through a visitor) to get the > information you want (the AdditionalInfoAndIInfo isn't the actual API you > want for that... what it gives is a global view of module names and tokens, > but it has only the names and path... when you want to do some analysis you > need the full AST). > > It goes something like: > > > PythonNature nature = PythonNature.getPythonNature(project); > IResource resource = null; > if(nature != null){ > IModulesManager modulesManager = > nature.getAstManager().getModulesManager(); > String moduleName = nature.resolveModule(resource); > if(moduleName != null){ > IModule module = modulesManager.getModule(moduleName, > nature, true); > if(module != null){ > if(module instanceof SourceModule){ > SourceModule sourceModule = (SourceModule) module; > SimpleNode ast = sourceModule.getAst(); > EasyASTIteratorVisitor visitor = > EasyASTIteratorVisitor.create(ast); > Iterator<ASTEntry> it = > visitor.getClassesAndMethodsIterator(); > while(it.hasNext()){ > ASTEntry entry = it.next(); > if(entry.node instanceof ClassDef){ > ClassDef classDef = (ClassDef) entry.node; > // Check classDef.decs for decorators > > }else if(entry.node instanceof FunctionDef){ > FunctionDef functionDef = (FunctionDef) > entry.node; > // Check functionDef.body for assignments > to InputPort/OutputPort > // if functionDef.name == __init_ports__ > } > } > } > } > } > } > > > > On Sat, Nov 7, 2015 at 11:02 PM, Marek Jagielski < > mar...@gm...> wrote: > >> Hi, >> I develop an eclipse environment for workflow engine: >> http://systemincloud.com/. I am integrating python into it, now. >> I force a dependency of PyDev for my plugin to reuse as much as possible >> what gives already PyDev. >> >> I would like to know if in PyDev there is a code that I can reuse to >> analyse a python class. >> I already able to find module: >> >> IProject p = >> ResourcesPlugin.getWorkspace().getRoot().getProject(EclipseUtil.getProjectNameFromDiagram(getDiagram())); >> AdditionalInfoAndIInfo pinfo = FindPythonTask.INSTANCE.find(p, className); >> >> FindPythonTask is based on based on GlobalsTwoPanelElementSelector2. >> Python Module looks like this: >> >> from sicpythontask.PythonTaskInfo import PythonTaskInfo >> from sicpythontask.PythonTask import PythonTask >> from sicpythontask.InputPort import InputPort >> from sicpythontask.OutputPort import OutputPort >> from sicpythontask.data.Bool import Bool >> >> @PythonTaskInfo >> class MyPythonTask(PythonTask): >> >> def __init_ports__(self): >> self.ttt = InputPort(name="ttt", data_type=Bool) >> self.yyy = OutputPort(name="yyy", data_type=Bool) >> >> def execute(self, grp): >> """ this will run when all synchronous ports >> from group receive data """ >> >> I would like now: >> 1. check if there is decorator @PythonTaskInfo and read eventual >> attributes. >> 2. from method __init_ports__ list all InputPort and OutputPort with >> their attributes >> >> Is it possible with PyDev api to do what I need? Do you do such an >> analyse in PyDev? Where can I find any example of code analyse? >> >> To note. For Java analyseI use org.eclipse.jdt.internal.core.NamedMember. >> >> Thanks for any help and hint, >> >> Marek Jagielski >> >> >> >> ------------------------------------------------------------------------------ >> >> _______________________________________________ >> pydev-code mailing list >> pyd...@li... >> https://lists.sourceforge.net/lists/listinfo/pydev-code >> >> > > > ------------------------------------------------------------------------------ > > _______________________________________________ > pydev-code mailing list > pyd...@li... > https://lists.sourceforge.net/lists/listinfo/pydev-code > > -- Marek Jagielski +48 513 402 596 |