diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java index f509192a43d..fd95a6770fe 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java @@ -117,6 +117,7 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { return new ResolveSession(project, storageManager, module, declarationProviderFactory, trace); } + @NotNull public static AnalyzeExhaust analyzeOneFileWithJavaIntegrationAndCheckForErrors( JetFile file, List scriptParameters) { AnalyzingUtils.checkForSyntacticErrors(file); @@ -128,12 +129,14 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { return analyzeExhaust; } + @NotNull public static AnalyzeExhaust analyzeOneFileWithJavaIntegration( JetFile file, List scriptParameters) { return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file), scriptParameters, Predicates.alwaysTrue()); } + @NotNull public static AnalyzeExhaust analyzeFilesWithJavaIntegrationAndCheckForErrors( Project project, Collection files, @@ -152,6 +155,7 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { return analyzeExhaust; } + @NotNull public static AnalyzeExhaust analyzeFilesWithJavaIntegration( Project project, Collection files, @@ -162,6 +166,7 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { project, files, scriptParameters, filesToAnalyzeCompletely, false); } + @NotNull public static AnalyzeExhaust analyzeFilesWithJavaIntegration( Project project, Collection files, List scriptParameters, Predicate filesToAnalyzeCompletely, boolean storeContextForBodiesResolve) { @@ -171,6 +176,7 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { storeContextForBodiesResolve); } + @NotNull public static AnalyzeExhaust analyzeFilesWithJavaIntegration( Project project, Collection files, @@ -183,6 +189,7 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { storeContextForBodiesResolve, createJavaModule("")); } + @NotNull public static AnalyzeExhaust analyzeFilesWithJavaIntegration( Project project, Collection files, diff --git a/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java b/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java index 5f376e442a8..1ef876a6617 100644 --- a/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java +++ b/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java @@ -30,6 +30,7 @@ public class AnalyzeExhaust { return new AnalyzeExhaust(bindingContext, module, null, null); } + @NotNull public static AnalyzeExhaust success(@NotNull BindingContext bindingContext, @Nullable BodiesResolveContext bodiesResolveContext, @NotNull ModuleDescriptor module @@ -37,6 +38,7 @@ public class AnalyzeExhaust { return new AnalyzeExhaust(bindingContext, module, bodiesResolveContext, null); } + @NotNull public static AnalyzeExhaust error(@NotNull BindingContext bindingContext, @NotNull Throwable error) { return new AnalyzeExhaust(bindingContext, ErrorUtils.getErrorModule(), null, error); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java index 28c3940aecd..b9a05dd5c7c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java @@ -428,7 +428,6 @@ public class BodyResolver { for (Map.Entry entry : context.getClasses().entrySet()) { if (!(entry.getKey() instanceof JetClass)) continue; JetClass jetClass = (JetClass) entry.getKey(); - if (!context.completeAnalysisNeeded(jetClass)) continue; MutableClassDescriptor classDescriptor = entry.getValue(); for (JetProperty property : jetClass.getProperties()) { @@ -462,7 +461,6 @@ public class BodyResolver { // Top-level properties & properties of objects for (Map.Entry entry : this.context.getProperties().entrySet()) { JetProperty property = entry.getKey(); - if (!context.completeAnalysisNeeded(property)) continue; if (processed.contains(property)) continue; PropertyDescriptor propertyDescriptor = entry.getValue(); @@ -611,20 +609,22 @@ public class BodyResolver { @NotNull BindingTrace trace, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, - @NotNull JetScope declaringScope) { - if (!context.completeAnalysisNeeded(function)) return; - - JetExpression bodyExpression = function.getBodyExpression(); + @NotNull JetScope declaringScope + ) { JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(declaringScope, functionDescriptor, trace); - if (bodyExpression != null) { - expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.getOuterDataFlowInfo(), null, trace); - } List valueParameters = function.getValueParameters(); List valueParameterDescriptors = functionDescriptor.getValueParameters(); expressionTypingServices.resolveValueParameters(valueParameters, valueParameterDescriptors, functionInnerScope, context.getOuterDataFlowInfo(), trace); + if (!context.completeAnalysisNeeded(function)) return; + + JetExpression bodyExpression = function.getBodyExpression(); + if (bodyExpression != null) { + expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.getOuterDataFlowInfo(), null, trace); + } + assert functionDescriptor.getReturnType() != null; } diff --git a/compiler/testData/resolveAnnotations/testFile.kt b/compiler/testData/resolveAnnotations/testFile.kt index 498c7d6d49c..7f184dfa9f5 100644 --- a/compiler/testData/resolveAnnotations/testFile.kt +++ b/compiler/testData/resolveAnnotations/testFile.kt @@ -8,7 +8,7 @@ ANNOTATION class MyClass [ANNOTATION]([ANNOTATION] param: Int, [ANNOTATION] val ANNOTATION var prop: Int = 1 [ANNOTATION] get - [ANNOTATION] set + [ANNOTATION] set([ANNOTATION] param) = $prop = param ANNOTATION fun foo([ANNOTATION] param: Int) { [ANNOTATION] class LocalClass { } @@ -29,7 +29,7 @@ ANNOTATION object MyObject { ANNOTATION var topProp: Int = 1 [ANNOTATION] get - [ANNOTATION] set + [ANNOTATION] set([ANNOTATION] param) = $topProp = param ANNOTATION fun topFoo([ANNOTATION] param: Int) { } diff --git a/compiler/tests/org/jetbrains/jet/JetTestUtils.java b/compiler/tests/org/jetbrains/jet/JetTestUtils.java index ffd2b1b7708..ab3a30caa6c 100644 --- a/compiler/tests/org/jetbrains/jet/JetTestUtils.java +++ b/compiler/tests/org/jetbrains/jet/JetTestUtils.java @@ -16,6 +16,7 @@ package org.jetbrains.jet; +import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -28,6 +29,7 @@ import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.CharsetToolkit; +import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; import com.intellij.psi.impl.PsiFileFactoryImpl; import com.intellij.rt.execution.junit.FileComparisonFailure; @@ -221,10 +223,19 @@ public class JetTestUtils { private JetTestUtils() { } + @NotNull public static AnalyzeExhaust analyzeFile(@NotNull JetFile file) { return AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(file, Collections.emptyList()); } + @NotNull + public static AnalyzeExhaust analyzeFileWithoutBody(@NotNull JetFile file) { + return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(file.getProject(), + Collections.singleton(file), + Collections.emptyList(), + Predicates.alwaysFalse()); + } + @NotNull public static JetCoreEnvironment createEnvironmentWithFullJdk(Disposable disposable) { return createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(disposable, diff --git a/compiler/tests/org/jetbrains/jet/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java b/compiler/tests/org/jetbrains/jet/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java index a1221200cff..e72c7825615 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java +++ b/compiler/tests/org/jetbrains/jet/resolve/annotation/AbstractAnnotationDescriptorResolveTest.java @@ -60,6 +60,11 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix } protected void doTest(@NotNull String content, @NotNull String expectedAnnotation) { + checkAnnotationOnAllExceptLocalDeclarations(content, expectedAnnotation); + checkAnnotationOnLocalDeclarations(expectedAnnotation); + } + + protected void checkAnnotationOnAllExceptLocalDeclarations(String content, String expectedAnnotation) { PackageViewDescriptor test = getPackage(content); ClassDescriptor myClass = getClassDescriptor(test, "MyClass"); checkDescriptor(expectedAnnotation, myClass); @@ -67,13 +72,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix checkDescriptor(expectedAnnotation, getInnerClassDescriptor(myClass, "InnerClass")); FunctionDescriptor foo = getFunctionDescriptor(myClass, "foo"); - checkDescriptor(expectedAnnotation, foo); - checkDescriptor(expectedAnnotation, getFunctionParameterDescriptor(foo, "param")); - - checkDescriptor(expectedAnnotation, getLocalClassDescriptor("LocalClass")); - checkDescriptor(expectedAnnotation, getLocalObjectDescriptor("LocalObject")); - checkDescriptor(expectedAnnotation, getLocalFunDescriptor("localFun")); - checkDescriptor(expectedAnnotation, getLocalVarDescriptor("localVar")); + checkAnnotationsOnFunction(expectedAnnotation, foo); SimpleFunctionDescriptor anonymousFun = getAnonymousFunDescriptor(); if (anonymousFun instanceof AnonymousFunctionDescriptor) { @@ -83,18 +82,13 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix } PropertyDescriptor prop = getPropertyDescriptor(myClass, "prop"); - checkDescriptor(expectedAnnotation, prop); - checkDescriptor(expectedAnnotation, prop.getGetter()); - checkDescriptor(expectedAnnotation, prop.getSetter()); + checkAnnotationsOnProperty(expectedAnnotation, prop); FunctionDescriptor topFoo = getFunctionDescriptor(test, "topFoo"); - checkDescriptor(expectedAnnotation, topFoo); - checkDescriptor(expectedAnnotation, getFunctionParameterDescriptor(topFoo, "param")); + checkAnnotationsOnFunction(expectedAnnotation, topFoo); PropertyDescriptor topProp = getPropertyDescriptor(test, "topProp"); - checkDescriptor(expectedAnnotation, topProp); - checkDescriptor(expectedAnnotation, topProp.getGetter()); - checkDescriptor(expectedAnnotation, topProp.getSetter()); + checkAnnotationsOnProperty(expectedAnnotation, topProp); checkDescriptor(expectedAnnotation, getClassDescriptor(test, "MyObject")); @@ -102,6 +96,26 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix checkDescriptor(expectedAnnotation, getConstructorParameterDescriptor(myClass, "param")); } + private void checkAnnotationOnLocalDeclarations(String expectedAnnotation) { + checkDescriptor(expectedAnnotation, getLocalClassDescriptor("LocalClass")); + checkDescriptor(expectedAnnotation, getLocalObjectDescriptor("LocalObject")); + checkDescriptor(expectedAnnotation, getLocalFunDescriptor("localFun")); + checkDescriptor(expectedAnnotation, getLocalVarDescriptor("localVar")); + } + + private static void checkAnnotationsOnProperty(String expectedAnnotation, PropertyDescriptor prop) { + checkDescriptor(expectedAnnotation, prop); + checkDescriptor(expectedAnnotation, prop.getGetter()); + PropertySetterDescriptor propSetter = prop.getSetter(); + assertNotNull(propSetter); + checkAnnotationsOnFunction(expectedAnnotation, propSetter); + } + + private static void checkAnnotationsOnFunction(String expectedAnnotation, FunctionDescriptor foo) { + checkDescriptor(expectedAnnotation, foo); + checkDescriptor(expectedAnnotation, getFunctionParameterDescriptor(foo, "param")); + } + @NotNull protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageViewDescriptor packageView, @NotNull String name) { Name functionName = Name.identifier(name); @@ -265,7 +279,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix @NotNull protected PackageViewDescriptor getPackage(@NotNull String content) { JetFile ktFile = JetTestUtils.createFile("dummy.kt", content, getProject()); - AnalyzeExhaust analyzeExhaust = JetTestUtils.analyzeFile(ktFile); + AnalyzeExhaust analyzeExhaust = analyzeFile(ktFile); context = analyzeExhaust.getBindingContext(); PackageViewDescriptor packageView = analyzeExhaust.getModuleDescriptor().getPackage(PACKAGE); @@ -273,6 +287,11 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix return packageView; } + @NotNull + protected AnalyzeExhaust analyzeFile(@NotNull JetFile ktFile) { + return JetTestUtils.analyzeFile(ktFile); + } + protected static String getContent(@NotNull String annotationText) throws IOException { File file = new File(PATH); return JetTestUtils.doLoadFile(file).replaceAll("ANNOTATION", annotationText); diff --git a/compiler/tests/org/jetbrains/jet/resolve/annotation/AnnotationDescriptorResolveWithoutAnalyzeBodyTest.kt b/compiler/tests/org/jetbrains/jet/resolve/annotation/AnnotationDescriptorResolveWithoutAnalyzeBodyTest.kt new file mode 100644 index 00000000000..73dacba9a65 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/resolve/annotation/AnnotationDescriptorResolveWithoutAnalyzeBodyTest.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.resolve.annotation + +import org.jetbrains.jet.analyzer.AnalyzeExhaust +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.JetTestUtils + +class AnnotationDescriptorResolveWithoutAnalyzeBodyTest : AnnotationDescriptorResolveTest() { + + override fun doTest(content: String, expectedAnnotation: String) { + checkAnnotationOnAllExceptLocalDeclarations(content, expectedAnnotation) + } + + override fun analyzeFile(ktFile: JetFile): AnalyzeExhaust = JetTestUtils.analyzeFileWithoutBody(ktFile) +} \ No newline at end of file diff --git a/idea/testData/checker/RecursiveTypeInference.kt b/idea/testData/checker/RecursiveTypeInference.kt index 006b2ad306b..fff8972fd72 100644 --- a/idea/testData/checker/RecursiveTypeInference.kt +++ b/idea/testData/checker/RecursiveTypeInference.kt @@ -1,7 +1,7 @@ //package a { - val afoo = abar() + val afoo = abar() - fun abar() = afoo + fun abar() = afoo //} //package b {