Frontend: added the support file annotations to TopDownAnalyzer.
This commit is contained in:
@@ -85,6 +85,7 @@ public class DeclarationResolver {
|
|||||||
resolveConstructorHeaders(c);
|
resolveConstructorHeaders(c);
|
||||||
resolveAnnotationStubsOnClassesAndConstructors(c);
|
resolveAnnotationStubsOnClassesAndConstructors(c);
|
||||||
resolveFunctionAndPropertyHeaders(c);
|
resolveFunctionAndPropertyHeaders(c);
|
||||||
|
resolveAnnotationsOnFiles(c.getFileScopes());
|
||||||
|
|
||||||
// SCRIPT: Resolve script declarations
|
// SCRIPT: Resolve script declarations
|
||||||
resolveScriptDeclarations(c);
|
resolveScriptDeclarations(c);
|
||||||
@@ -96,6 +97,14 @@ public class DeclarationResolver {
|
|||||||
checkRedeclarationsInInnerClassNames(c);
|
checkRedeclarationsInInnerClassNames(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resolveAnnotationsOnFiles(@NotNull Map<JetFile, ? extends JetScope> file2scope) {
|
||||||
|
for (Map.Entry<JetFile, ? extends JetScope> entry : file2scope.entrySet()) {
|
||||||
|
JetFile file = entry.getKey();
|
||||||
|
JetScope fileScope = entry.getValue();
|
||||||
|
annotationResolver.resolveAnnotationsWithArguments(fileScope, file.getAnnotationEntries(), trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void resolveAnnotationConstructors(@NotNull TopDownAnalysisContext c) {
|
private void resolveAnnotationConstructors(@NotNull TopDownAnalysisContext c) {
|
||||||
for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry : c.getDeclaredClasses().entrySet()) {
|
for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry : c.getDeclaredClasses().entrySet()) {
|
||||||
JetClassOrObject classOrObject = entry.getKey();
|
JetClassOrObject classOrObject = entry.getKey();
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
[file: ANNOTATION]
|
||||||
|
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import test.MyEnum.*
|
import test.MyEnum.*
|
||||||
@@ -50,4 +52,4 @@ annotation class AnnClass(a: Class<*>)
|
|||||||
|
|
||||||
enum class MyEnum {
|
enum class MyEnum {
|
||||||
A
|
A
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-20
@@ -27,7 +27,9 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
|||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
@@ -66,8 +68,12 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void checkAnnotationOnAllExceptLocalDeclarations(String content, String expectedAnnotation) {
|
protected void checkAnnotationOnAllExceptLocalDeclarations(String content, String expectedAnnotation) {
|
||||||
PackageViewDescriptor test = getPackage(content);
|
JetFile testFile = getFile(content);
|
||||||
ClassDescriptor myClass = getClassDescriptor(test, "MyClass");
|
PackageFragmentDescriptor testPackage = getPackage(testFile);
|
||||||
|
|
||||||
|
checkAnnotationsOnFile(expectedAnnotation, testFile);
|
||||||
|
|
||||||
|
ClassDescriptor myClass = getClassDescriptor(testPackage, "MyClass");
|
||||||
checkDescriptor(expectedAnnotation, myClass);
|
checkDescriptor(expectedAnnotation, myClass);
|
||||||
checkDescriptor(expectedAnnotation, getClassObjectDescriptor(myClass));
|
checkDescriptor(expectedAnnotation, getClassObjectDescriptor(myClass));
|
||||||
checkDescriptor(expectedAnnotation, getInnerClassDescriptor(myClass, "InnerClass"));
|
checkDescriptor(expectedAnnotation, getInnerClassDescriptor(myClass, "InnerClass"));
|
||||||
@@ -85,18 +91,31 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
|||||||
PropertyDescriptor prop = getPropertyDescriptor(myClass, "prop");
|
PropertyDescriptor prop = getPropertyDescriptor(myClass, "prop");
|
||||||
checkAnnotationsOnProperty(expectedAnnotation, prop);
|
checkAnnotationsOnProperty(expectedAnnotation, prop);
|
||||||
|
|
||||||
FunctionDescriptor topFoo = getFunctionDescriptor(test, "topFoo");
|
FunctionDescriptor topFoo = getFunctionDescriptor(testPackage, "topFoo");
|
||||||
checkAnnotationsOnFunction(expectedAnnotation, topFoo);
|
checkAnnotationsOnFunction(expectedAnnotation, topFoo);
|
||||||
|
|
||||||
PropertyDescriptor topProp = getPropertyDescriptor(test, "topProp", true);
|
PropertyDescriptor topProp = getPropertyDescriptor(testPackage, "topProp", true);
|
||||||
checkAnnotationsOnProperty(expectedAnnotation, topProp);
|
checkAnnotationsOnProperty(expectedAnnotation, topProp);
|
||||||
|
|
||||||
checkDescriptor(expectedAnnotation, getClassDescriptor(test, "MyObject"));
|
checkDescriptor(expectedAnnotation, getClassDescriptor(testPackage, "MyObject"));
|
||||||
|
|
||||||
checkDescriptor(expectedAnnotation, getConstructorParameterDescriptor(myClass, "consProp"));
|
checkDescriptor(expectedAnnotation, getConstructorParameterDescriptor(myClass, "consProp"));
|
||||||
checkDescriptor(expectedAnnotation, getConstructorParameterDescriptor(myClass, "param"));
|
checkDescriptor(expectedAnnotation, getConstructorParameterDescriptor(myClass, "param"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkAnnotationsOnFile(String expectedAnnotation, JetFile file) {
|
||||||
|
String actualAnnotation = StringUtil.join(file.getAnnotationEntries(), new Function<JetAnnotationEntry, String>() {
|
||||||
|
@Override
|
||||||
|
public String fun(JetAnnotationEntry annotationEntry) {
|
||||||
|
AnnotationDescriptor annotationDescriptor = context.get(BindingContext.ANNOTATION, annotationEntry);
|
||||||
|
assertNotNull(annotationDescriptor);
|
||||||
|
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationDescriptor);
|
||||||
|
}
|
||||||
|
}, " ");
|
||||||
|
|
||||||
|
assertEquals(expectedAnnotation, actualAnnotation);
|
||||||
|
}
|
||||||
|
|
||||||
private void checkAnnotationOnLocalDeclarations(String expectedAnnotation) {
|
private void checkAnnotationOnLocalDeclarations(String expectedAnnotation) {
|
||||||
checkDescriptor(expectedAnnotation, getLocalClassDescriptor("LocalClass"));
|
checkDescriptor(expectedAnnotation, getLocalClassDescriptor("LocalClass"));
|
||||||
checkDescriptor(expectedAnnotation, getLocalObjectDescriptor("LocalObject"));
|
checkDescriptor(expectedAnnotation, getLocalObjectDescriptor("LocalObject"));
|
||||||
@@ -118,7 +137,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageViewDescriptor packageView, @NotNull String name) {
|
protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
|
||||||
Name functionName = Name.identifier(name);
|
Name functionName = Name.identifier(name);
|
||||||
JetScope memberScope = packageView.getMemberScope();
|
JetScope memberScope = packageView.getMemberScope();
|
||||||
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName);
|
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName);
|
||||||
@@ -136,7 +155,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageViewDescriptor packageView, @NotNull String name, boolean failOnMissing) {
|
protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name, boolean failOnMissing) {
|
||||||
Name propertyName = Name.identifier(name);
|
Name propertyName = Name.identifier(name);
|
||||||
JetScope memberScope = packageView.getMemberScope();
|
JetScope memberScope = packageView.getMemberScope();
|
||||||
Collection<VariableDescriptor> properties = memberScope.getProperties(propertyName);
|
Collection<VariableDescriptor> properties = memberScope.getProperties(propertyName);
|
||||||
@@ -172,7 +191,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static ClassDescriptor getClassDescriptor(@NotNull PackageViewDescriptor packageView, @NotNull String name) {
|
protected static ClassDescriptor getClassDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
|
||||||
Name className = Name.identifier(name);
|
Name className = Name.identifier(name);
|
||||||
ClassifierDescriptor aClass = packageView.getMemberScope().getClassifier(className);
|
ClassifierDescriptor aClass = packageView.getMemberScope().getClassifier(className);
|
||||||
assertNotNull("Failed to find class: " + packageView.getName() + "." + className, aClass);
|
assertNotNull("Failed to find class: " + packageView.getName() + "." + className, aClass);
|
||||||
@@ -296,14 +315,24 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected PackageViewDescriptor getPackage(@NotNull String content) {
|
protected JetFile getFile(@NotNull String content) {
|
||||||
JetFile ktFile = JetTestUtils.createFile("dummy.kt", content, getProject());
|
JetFile ktFile = JetTestUtils.createFile("dummy.kt", content, getProject());
|
||||||
AnalyzeExhaust analyzeExhaust = analyzeFile(ktFile);
|
AnalyzeExhaust analyzeExhaust = analyzeFile(ktFile);
|
||||||
context = analyzeExhaust.getBindingContext();
|
context = analyzeExhaust.getBindingContext();
|
||||||
|
|
||||||
PackageViewDescriptor packageView = analyzeExhaust.getModuleDescriptor().getPackage(PACKAGE);
|
return ktFile;
|
||||||
assertNotNull("Failed to find package: " + PACKAGE, packageView);
|
}
|
||||||
return packageView;
|
|
||||||
|
@NotNull
|
||||||
|
protected PackageFragmentDescriptor getPackage(@NotNull JetFile ktFile) {
|
||||||
|
PackageFragmentDescriptor packageFragment = context.get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, ktFile);
|
||||||
|
assertNotNull("Failed to find package: " + PACKAGE, packageFragment);
|
||||||
|
return packageFragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected PackageFragmentDescriptor getPackage(@NotNull String content) {
|
||||||
|
return getPackage(getFile(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -316,24 +345,23 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
|
|||||||
return JetTestUtils.doLoadFile(file).replaceAll("ANNOTATION", annotationText);
|
return JetTestUtils.doLoadFile(file).replaceAll("ANNOTATION", annotationText);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void checkDescriptor(String expectedAnnotation, DeclarationDescriptor member) {
|
private static String renderAnnotations(Annotations annotations) {
|
||||||
String actual = StringUtil.join(member.getAnnotations(), new Function<AnnotationDescriptor, String>() {
|
return StringUtil.join(annotations, new Function<AnnotationDescriptor, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String fun(AnnotationDescriptor annotationDescriptor) {
|
public String fun(AnnotationDescriptor annotationDescriptor) {
|
||||||
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationDescriptor);
|
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationDescriptor);
|
||||||
}
|
}
|
||||||
}, " ");
|
}, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void checkDescriptor(String expectedAnnotation, DeclarationDescriptor member) {
|
||||||
|
String actual = getAnnotations(member);
|
||||||
assertEquals("Failed to resolve annotation descriptor for " + member.toString(), expectedAnnotation, actual);
|
assertEquals("Failed to resolve annotation descriptor for " + member.toString(), expectedAnnotation, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static String getAnnotations(DeclarationDescriptor member) {
|
protected static String getAnnotations(DeclarationDescriptor member) {
|
||||||
return StringUtil.join(member.getAnnotations(), new Function<AnnotationDescriptor, String>() {
|
return renderAnnotations(member.getAnnotations());
|
||||||
@Override
|
|
||||||
public String fun(AnnotationDescriptor annotationDescriptor) {
|
|
||||||
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationDescriptor);
|
|
||||||
}
|
|
||||||
}, " ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user