Frontend: fixed resolve annotation parameters on properties, accessors, accessor parameters, function parameters when not need complete analysis.

This commit is contained in:
Zalim Bashorov
2014-01-27 14:44:49 +04:00
parent f5499a93ed
commit d032b5589c
8 changed files with 98 additions and 29 deletions
@@ -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.<AnalyzerScriptParameter>emptyList());
}
@NotNull
public static AnalyzeExhaust analyzeFileWithoutBody(@NotNull JetFile file) {
return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(file.getProject(),
Collections.singleton(file),
Collections.<AnalyzerScriptParameter>emptyList(),
Predicates.<PsiFile>alwaysFalse());
}
@NotNull
public static JetCoreEnvironment createEnvironmentWithFullJdk(Disposable disposable) {
return createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(disposable,
@@ -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);
@@ -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)
}