AnnotationDescriptor refactoring: contains map of ValueParameterDescriptor and CompileTimeConstant for valueArgument.
DescriptorUtils: add method to get a list of sorted value arguments from AnnotationDescriptor
This commit is contained in:
@@ -172,7 +172,7 @@ public abstract class AnnotationCodegen {
|
|||||||
for (AnnotationDescriptor annotation : annotations) {
|
for (AnnotationDescriptor annotation : annotations) {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
if ("Intrinsic".equals(annotation.getType().getConstructor().getDeclarationDescriptor().getName().getName())) {
|
if ("Intrinsic".equals(annotation.getType().getConstructor().getDeclarationDescriptor().getName().getName())) {
|
||||||
value = (String) annotation.getValueArguments().get(0).getValue();
|
value = (String) annotation.getAllValueArguments().values().iterator().next().getValue();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ public class IntrinsicMethods {
|
|||||||
ClassifierDescriptor classifierDescriptor = annotation.getType().getConstructor().getDeclarationDescriptor();
|
ClassifierDescriptor classifierDescriptor = annotation.getType().getConstructor().getDeclarationDescriptor();
|
||||||
assert classifierDescriptor != null;
|
assert classifierDescriptor != null;
|
||||||
if ("Intrinsic".equals(classifierDescriptor.getName().getName())) {
|
if ("Intrinsic".equals(classifierDescriptor.getName().getName())) {
|
||||||
String value = (String) annotation.getValueArguments().get(0).getValue();
|
String value = (String) annotation.getAllValueArguments().values().iterator().next().getValue();
|
||||||
intrinsicMethod = namedMethods.get(value);
|
intrinsicMethod = namedMethods.get(value);
|
||||||
if (intrinsicMethod != null) {
|
if (intrinsicMethod != null) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
+21
-7
@@ -16,29 +16,38 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.descriptors.annotations;
|
package org.jetbrains.jet.lang.descriptors.annotations;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
|
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.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
import javax.rmi.CORBA.ClassDesc;
|
import java.util.Map;
|
||||||
import java.util.List;
|
import java.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class AnnotationDescriptor {
|
public class AnnotationDescriptor {
|
||||||
private JetType annotationType;
|
private JetType annotationType;
|
||||||
private List<CompileTimeConstant<?>> valueArguments;
|
private final Map<ValueParameterDescriptor, CompileTimeConstant<?>> valueArguments = Maps.newHashMap();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getType() {
|
public JetType getType() {
|
||||||
return annotationType;
|
return annotationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public CompileTimeConstant<?> getValueArgument(@NotNull ValueParameterDescriptor valueParameterDescriptor) {
|
||||||
|
return valueArguments.get(valueParameterDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<CompileTimeConstant<?>> getValueArguments() {
|
public Map<ValueParameterDescriptor, CompileTimeConstant<?>> getAllValueArguments() {
|
||||||
return valueArguments;
|
return Collections.unmodifiableMap(valueArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAnnotationType(@NotNull JetType annotationType) {
|
public void setAnnotationType(@NotNull JetType annotationType) {
|
||||||
@@ -48,7 +57,12 @@ public class AnnotationDescriptor {
|
|||||||
this.annotationType = annotationType;
|
this.annotationType = annotationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValueArguments(@NotNull List<CompileTimeConstant<?>> valueArguments) {
|
public void setValueArgument(@NotNull ValueParameterDescriptor name, @NotNull CompileTimeConstant<?> value) {
|
||||||
this.valueArguments = valueArguments;
|
valueArguments.put(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return annotationType.toString() + DescriptorUtils.getSortedValueArguments(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,17 +116,19 @@ public class AnnotationResolver {
|
|||||||
|
|
||||||
private void resolveArguments(@NotNull OverloadResolutionResults<FunctionDescriptor> results,
|
private void resolveArguments(@NotNull OverloadResolutionResults<FunctionDescriptor> results,
|
||||||
@NotNull AnnotationDescriptor descriptor, BindingTrace trace) {
|
@NotNull AnnotationDescriptor descriptor, BindingTrace trace) {
|
||||||
List<CompileTimeConstant<?>> arguments = Lists.newArrayList();
|
|
||||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> descriptorToArgument :
|
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> descriptorToArgument :
|
||||||
results.getResultingCall().getValueArguments().entrySet()) {
|
results.getResultingCall().getValueArguments().entrySet()) {
|
||||||
// TODO: are varargs supported here?
|
// TODO: are varargs supported here?
|
||||||
List<ValueArgument> valueArguments = descriptorToArgument.getValue().getArguments();
|
List<ValueArgument> valueArguments = descriptorToArgument.getValue().getArguments();
|
||||||
ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey();
|
ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey();
|
||||||
for (ValueArgument argument : valueArguments) {
|
for (ValueArgument argument : valueArguments) {
|
||||||
arguments.add(resolveAnnotationArgument(argument.getArgumentExpression(), parameterDescriptor.getType(), trace));
|
CompileTimeConstant<?> compileTimeConstant =
|
||||||
|
resolveAnnotationArgument(argument.getArgumentExpression(), parameterDescriptor.getType(), trace);
|
||||||
|
if (compileTimeConstant != null) {
|
||||||
|
descriptor.setValueArgument(parameterDescriptor, compileTimeConstant);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
descriptor.setValueArguments(arguments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ import com.google.common.collect.Maps;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
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.psi.JetElement;
|
import org.jetbrains.jet.lang.psi.JetElement;
|
||||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||||
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
@@ -376,4 +378,13 @@ public class DescriptorUtils {
|
|||||||
assert classKind == ClassKind.CLASS || classKind == ClassKind.TRAIT || classKind == ClassKind.ANNOTATION_CLASS;
|
assert classKind == ClassKind.CLASS || classKind == ClassKind.TRAIT || classKind == ClassKind.ANNOTATION_CLASS;
|
||||||
return Visibilities.PUBLIC;
|
return Visibilities.PUBLIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> getSortedValueArguments(AnnotationDescriptor descriptor) {
|
||||||
|
List<String> resultList = Lists.newArrayList();
|
||||||
|
for (Map.Entry<ValueParameterDescriptor, CompileTimeConstant<?>> entry : descriptor.getAllValueArguments().entrySet()) {
|
||||||
|
resultList.add(entry.getKey().getName().getName() + " = " + entry.getValue().toString());
|
||||||
|
}
|
||||||
|
Collections.sort(resultList);
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -534,7 +534,7 @@ public class NamespaceComparator {
|
|||||||
public void serialize(AnnotationDescriptor annotation) {
|
public void serialize(AnnotationDescriptor annotation) {
|
||||||
new TypeSerializer(sb).serialize(annotation.getType());
|
new TypeSerializer(sb).serialize(annotation.getType());
|
||||||
sb.append("(");
|
sb.append("(");
|
||||||
serializeCommaSeparated(annotation.getValueArguments());
|
serializeCommaSeparated(DescriptorUtils.getSortedValueArguments(annotation));
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ public final class AnnotationsUtils {
|
|||||||
AnnotationDescriptor annotationDescriptor = getAnnotationByName(declarationDescriptor, annotation);
|
AnnotationDescriptor annotationDescriptor = getAnnotationByName(declarationDescriptor, annotation);
|
||||||
assert annotationDescriptor != null;
|
assert annotationDescriptor != null;
|
||||||
//TODO: this is a quick fix for unsupported default args problem
|
//TODO: this is a quick fix for unsupported default args problem
|
||||||
if (annotationDescriptor.getValueArguments().isEmpty()) {
|
if (annotationDescriptor.getAllValueArguments().isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CompileTimeConstant<?> constant = annotationDescriptor.getValueArguments().iterator().next();
|
CompileTimeConstant<?> constant = annotationDescriptor.getAllValueArguments().values().iterator().next();
|
||||||
//TODO: this is a quick fix for unsupported default args problem
|
//TODO: this is a quick fix for unsupported default args problem
|
||||||
if (constant == null) {
|
if (constant == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user