private void checkFunction( JetDeclarationWithBody function, final @NotNull JetType expectedReturnType) { assert function instanceof JetDeclaration; JetExpression bodyExpression = function.getBodyExpression(); if (bodyExpression == null) return; JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider((JetDeclaration) function, trace); boolean isPropertyAccessor = function instanceof JetPropertyAccessor; if (!isPropertyAccessor) { flowInformationProvider.recordInitializedVariables(); } if (topDownAnalysisParameters.isDeclaredLocally()) return; flowInformationProvider.checkDefiniteReturn(expectedReturnType); if (!isPropertyAccessor) { // Property accessor is checked through initialization of a class/object or package properties // (at 'checkDeclarationContainer') flowInformationProvider.markUninitializedVariables(); } flowInformationProvider.markUnusedVariables(); flowInformationProvider.markUnusedLiteralsInBlock(); }
public ReplInterpreter( @NotNull Disposable disposable, @NotNull CompilerConfiguration configuration) { jetCoreEnvironment = JetCoreEnvironment.createForProduction(disposable, configuration); Project project = jetCoreEnvironment.getProject(); trace = new BindingTraceContext(); module = AnalyzerFacadeForJVM.createJavaModule("<repl>"); TopDownAnalysisParameters topDownAnalysisParameters = TopDownAnalysisParameters.createForLocalDeclarations( new LockBasedStorageManager(), new ExceptionTracker(), // dummy Predicates.<PsiFile>alwaysTrue()); injector = new InjectorForTopDownAnalyzerForJvm( project, topDownAnalysisParameters, trace, module, MemberFilter.ALWAYS_TRUE); topDownAnalysisContext = new TopDownAnalysisContext(topDownAnalysisParameters); module.addFragmentProvider(SOURCES, injector.getTopDownAnalyzer().getPackageFragmentProvider()); module.addFragmentProvider( BUILT_INS, KotlinBuiltIns.getInstance().getBuiltInsModule().getPackageFragmentProvider()); module.addFragmentProvider( BINARIES, injector.getJavaDescriptorResolver().getPackageFragmentProvider()); List<URL> classpath = Lists.newArrayList(); for (File file : configuration.getList(JVMConfigurationKeys.CLASSPATH_KEY)) { try { classpath.add(file.toURI().toURL()); } catch (MalformedURLException e) { throw UtilsPackage.rethrow(e); } } classLoader = new ReplClassLoader(new URLClassLoader(classpath.toArray(new URL[0]))); }
@Override public boolean completeAnalysisNeeded(@NotNull PsiElement element) { PsiFile containingFile = element.getContainingFile(); boolean result = containingFile != null && topDownAnalysisParameters.getAnalyzeCompletely().apply(containingFile); if (!result) { debug(containingFile); } return result; }
private void checkDeclarationContainer(JetDeclarationContainer declarationContainer) { // A pseudocode of class/object initialization corresponds to a class/object // or initialization of properties corresponds to a package declared in a file JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider((JetElement) declarationContainer, trace); flowInformationProvider.recordInitializedVariables(); if (topDownAnalysisParameters.isDeclaredLocally()) return; flowInformationProvider.markUninitializedVariables(); }
public void resolveBehaviorDeclarationBodies() { resolveDelegationSpecifierLists(); resolveClassAnnotations(); resolvePropertyDeclarationBodies(); resolveAnonymousInitializers(); resolvePrimaryConstructorParameters(); resolveSecondaryConstructorBodies(); resolveFunctionBodies(); if (!topDownAnalysisParameters.isDeclaredLocally()) { computeDeferredTypes(); } }