void () { // vfile is problematic, but we need an SDK to check builtins final Project project = myFixture.getProject(); runWithLanguageLevel( LanguageLevel.PYTHON26, // we need 2.6+ for @foo.setter () -> { final PyFile file = getTestFile(); final List<PyClass> classes = file.getTopLevelClasses(); assertEquals(3, classes.size()); PyClass pyClass = classes.get(0); assertEquals("FooClass", pyClass.getName()); assertEquals("StubStructure.FooClass", pyClass.getQualifiedName()); final List<PyTargetExpression> attrs = pyClass.getClassAttributes(); assertEquals(2, attrs.size()); assertEquals("staticField", attrs.get(0).getName()); assertTrue(attrs.get(0).getAssignedQName().matches("deco")); final PyFunction[] methods = pyClass.getMethods(); assertEquals(2, methods.length); assertEquals("__init__", methods [0].getName()); assertEquals("fooFunction", methods [1].getName()); final PyParameter[] parameters = methods[1].getParameterList().getParameters(); assertFalse(parameters [0].hasDefaultValue()); assertTrue(parameters [1].hasDefaultValue()); // decorators PyFunction decorated = methods[1]; PyDecoratorList decos = decorated.getDecoratorList(); assertNotNull(decos); assertNotParsed(file); PyDecorator[] da = decos.getDecorators(); assertNotNull(da); assertEquals(1, da.length); assertNotParsed(file); PyDecorator deco = da[0]; assertNotNull(deco); assertEquals("deco", deco.getName()); assertNotParsed(file); final List<PyTargetExpression> instanceAttrs = pyClass.getInstanceAttributes(); assertEquals(1, instanceAttrs.size()); assertEquals("instanceField", instanceAttrs.get(0).getName()); final List<PyFunction> functions = file.getTopLevelFunctions(); assertEquals(2, functions.size()); // "deco" and "topLevelFunction" PyFunction func = functions.get(0); assertEquals("deco", func.getName()); func = functions.get(1); assertEquals("topLevelFunction", func.getName()); final List<PyTargetExpression> exprs = file.getTopLevelAttributes(); assertEquals(2, exprs.size()); assertEquals("top1", exprs.get(0).getName()); assertEquals("top2", exprs.get(1).getName()); // properties by call pyClass = classes.get(1); assertEquals("BarClass", pyClass.getName()); Property prop = pyClass.findProperty("value", true, null); Maybe<PyCallable> maybe_function = prop.getGetter(); assertTrue(maybe_function.isDefined()); assertEquals(pyClass.getMethods()[0], maybe_function.value()); Property setvalueProp = pyClass.findProperty("setvalue", true, null); Maybe<PyCallable> setter = setvalueProp.getSetter(); assertTrue(setter.isDefined()); assertEquals("__set", setter.value().getName()); // properties by decorator pyClass = classes.get(2); assertEquals("BazClass", pyClass.getName()); prop = pyClass.findProperty("x", true, null); maybe_function = prop.getGetter(); assertTrue(maybe_function.isDefined()); assertEquals(pyClass.getMethods()[0], maybe_function.value()); maybe_function = prop.getSetter(); assertTrue(maybe_function.isDefined()); assertEquals(pyClass.getMethods()[1], maybe_function.value()); // ...and the juice: assertNotParsed(file); } ); }