AnnotationDescriptor interface extracted
This commit is contained in:
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
@@ -111,9 +112,9 @@ public class AnnotationResolver {
|
||||
if (annotationEntryElements.isEmpty()) return Collections.emptyList();
|
||||
List<AnnotationDescriptor> result = Lists.newArrayList();
|
||||
for (JetAnnotationEntry entryElement : annotationEntryElements) {
|
||||
AnnotationDescriptor descriptor = trace.get(BindingContext.ANNOTATION, entryElement);
|
||||
AnnotationDescriptorImpl descriptor = trace.get(BindingContext.ANNOTATION, entryElement);
|
||||
if (descriptor == null) {
|
||||
descriptor = new AnnotationDescriptor();
|
||||
descriptor = new AnnotationDescriptorImpl();
|
||||
resolveAnnotationStub(scope, entryElement, descriptor, trace);
|
||||
trace.record(BindingContext.ANNOTATION, entryElement, descriptor);
|
||||
}
|
||||
@@ -130,7 +131,7 @@ public class AnnotationResolver {
|
||||
public void resolveAnnotationStub(
|
||||
@NotNull JetScope scope,
|
||||
@NotNull JetAnnotationEntry entryElement,
|
||||
@NotNull AnnotationDescriptor annotationDescriptor,
|
||||
@NotNull AnnotationDescriptorImpl annotationDescriptor,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
TemporaryBindingTrace temporaryBindingTrace = new TemporaryBindingTrace(trace, "Trace for resolve annotation type");
|
||||
@@ -196,14 +197,14 @@ public class AnnotationResolver {
|
||||
) {
|
||||
OverloadResolutionResults<FunctionDescriptor> results = resolveAnnotationCall(annotationEntry, scope, trace);
|
||||
if (results.isSingleResult()) {
|
||||
AnnotationDescriptor annotationDescriptor = trace.getBindingContext().get(BindingContext.ANNOTATION, annotationEntry);
|
||||
AnnotationDescriptorImpl annotationDescriptor = trace.getBindingContext().get(BindingContext.ANNOTATION, annotationEntry);
|
||||
assert annotationDescriptor != null : "Annotation descriptor should be created before resolving arguments for " + annotationEntry.getText();
|
||||
resolveAnnotationArgument(annotationDescriptor, results.getResultingCall(), trace);
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveAnnotationArgument(
|
||||
@NotNull AnnotationDescriptor annotationDescriptor,
|
||||
@NotNull AnnotationDescriptorImpl annotationDescriptor,
|
||||
@NotNull ResolvedCall<? extends CallableDescriptor> call,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
@@ -336,7 +337,7 @@ public class AnnotationResolver {
|
||||
JetType constructorReturnType = resultingDescriptor.getReturnType();
|
||||
assert constructorReturnType != null : "Constructor should have return type";
|
||||
if (DescriptorUtils.isAnnotationClass(constructorReturnType.getConstructor().getDeclarationDescriptor())) {
|
||||
AnnotationDescriptor descriptor = new AnnotationDescriptor();
|
||||
AnnotationDescriptorImpl descriptor = new AnnotationDescriptorImpl();
|
||||
descriptor.setAnnotationType(constructorReturnType);
|
||||
resolveAnnotationArgument(descriptor, call, trace);
|
||||
return new AnnotationValue(descriptor);
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter;
|
||||
@@ -69,8 +70,8 @@ public interface BindingContext {
|
||||
};
|
||||
|
||||
WritableSlice<AnnotationDescriptor, JetAnnotationEntry> ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT = Slices.createSimpleSlice();
|
||||
WritableSlice<JetAnnotationEntry, AnnotationDescriptor> ANNOTATION =
|
||||
Slices.<JetAnnotationEntry, AnnotationDescriptor>sliceBuilder().setOpposite(ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT).build();
|
||||
WritableSlice<JetAnnotationEntry, AnnotationDescriptorImpl> ANNOTATION =
|
||||
Slices.<JetAnnotationEntry, AnnotationDescriptorImpl>sliceBuilder().setOpposite(ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT).build();
|
||||
|
||||
WritableSlice<JetExpression, CompileTimeConstant<?>> COMPILE_TIME_VALUE = Slices.createSimpleSlice();
|
||||
WritableSlice<PropertyDescriptor, CompileTimeConstant<?>> COMPILE_TIME_INITIALIZER = Slices.createSimpleSlice();
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
@@ -105,7 +106,7 @@ public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements
|
||||
|
||||
@NotNull
|
||||
private static AnnotationDescriptor getAnnotationDescriptorForJavaLangDeprecated(@NotNull ClassDescriptor annotationClass) {
|
||||
AnnotationDescriptor annotation = new AnnotationDescriptor();
|
||||
AnnotationDescriptorImpl annotation = new AnnotationDescriptorImpl();
|
||||
annotation.setAnnotationType(annotationClass.getDefaultType());
|
||||
ValueParameterDescriptor value = DescriptorResolverUtils.getAnnotationParameterByName(
|
||||
JavaAnnotationResolver.DEFAULT_ANNOTATION_MEMBER_NAME, annotationClass);
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
||||
@@ -97,7 +98,7 @@ public final class JavaAnnotationResolver {
|
||||
|
||||
@Nullable
|
||||
public AnnotationDescriptor resolveAnnotation(@NotNull JavaAnnotation javaAnnotation, @NotNull PostponedTasks postponedTasks) {
|
||||
final AnnotationDescriptor annotation = new AnnotationDescriptor();
|
||||
final AnnotationDescriptorImpl annotation = new AnnotationDescriptorImpl();
|
||||
FqName fqName = javaAnnotation.getFqName();
|
||||
if (fqName == null) {
|
||||
return null;
|
||||
|
||||
+2
-1
@@ -25,6 +25,7 @@ import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
|
||||
import org.jetbrains.jet.descriptors.serialization.descriptors.AnnotationDeserializer;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.EnumValue;
|
||||
@@ -157,7 +158,7 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
|
||||
if (ignoreAnnotation(className)) return null;
|
||||
|
||||
final ClassDescriptor annotationClass = resolveClass(className);
|
||||
final AnnotationDescriptor annotation = new AnnotationDescriptor();
|
||||
final AnnotationDescriptorImpl annotation = new AnnotationDescriptorImpl();
|
||||
annotation.setAnnotationType(annotationClass.getDefaultType());
|
||||
|
||||
return new KotlinJvmBinaryClass.AnnotationArgumentVisitor() {
|
||||
|
||||
+5
-46
@@ -1,61 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.lang.descriptors.annotations;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class AnnotationDescriptor {
|
||||
private JetType annotationType;
|
||||
private final Map<ValueParameterDescriptor, CompileTimeConstant<?>> valueArguments = Maps.newHashMap();
|
||||
|
||||
public interface AnnotationDescriptor {
|
||||
@NotNull
|
||||
public JetType getType() {
|
||||
return annotationType;
|
||||
}
|
||||
JetType getType();
|
||||
|
||||
@Nullable
|
||||
public CompileTimeConstant<?> getValueArgument(@NotNull ValueParameterDescriptor valueParameterDescriptor) {
|
||||
return valueArguments.get(valueParameterDescriptor);
|
||||
}
|
||||
|
||||
CompileTimeConstant<?> getValueArgument(@NotNull ValueParameterDescriptor valueParameterDescriptor);
|
||||
|
||||
@NotNull
|
||||
public Map<ValueParameterDescriptor, CompileTimeConstant<?>> getAllValueArguments() {
|
||||
return Collections.unmodifiableMap(valueArguments);
|
||||
}
|
||||
|
||||
public void setAnnotationType(@NotNull JetType annotationType) {
|
||||
this.annotationType = annotationType;
|
||||
}
|
||||
|
||||
public void setValueArgument(@NotNull ValueParameterDescriptor name, @NotNull CompileTimeConstant<?> value) {
|
||||
valueArguments.put(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return annotationType.toString() + DescriptorUtils.getSortedValueArguments(this, null);
|
||||
}
|
||||
Map<ValueParameterDescriptor, CompileTimeConstant<?>> getAllValueArguments();
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.lang.descriptors.annotations;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class AnnotationDescriptorImpl implements AnnotationDescriptor {
|
||||
private JetType annotationType;
|
||||
private final Map<ValueParameterDescriptor, CompileTimeConstant<?>> valueArguments = Maps.newHashMap();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetType getType() {
|
||||
return annotationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public CompileTimeConstant<?> getValueArgument(@NotNull ValueParameterDescriptor valueParameterDescriptor) {
|
||||
return valueArguments.get(valueParameterDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<ValueParameterDescriptor, CompileTimeConstant<?>> getAllValueArguments() {
|
||||
return Collections.unmodifiableMap(valueArguments);
|
||||
}
|
||||
|
||||
public void setAnnotationType(@NotNull JetType annotationType) {
|
||||
this.annotationType = annotationType;
|
||||
}
|
||||
|
||||
public void setValueArgument(@NotNull ValueParameterDescriptor name, @NotNull CompileTimeConstant<?> value) {
|
||||
valueArguments.put(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return annotationType.toString() + DescriptorUtils.getSortedValueArguments(this, null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user