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) {
|
||||
//noinspection ConstantConditions
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ public class IntrinsicMethods {
|
||||
ClassifierDescriptor classifierDescriptor = annotation.getType().getConstructor().getDeclarationDescriptor();
|
||||
assert classifierDescriptor != null;
|
||||
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);
|
||||
if (intrinsicMethod != null) {
|
||||
break;
|
||||
|
||||
+21
-7
@@ -16,29 +16,38 @@
|
||||
|
||||
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.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.types.JetType;
|
||||
|
||||
import javax.rmi.CORBA.ClassDesc;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class AnnotationDescriptor {
|
||||
private JetType annotationType;
|
||||
private List<CompileTimeConstant<?>> valueArguments;
|
||||
private final Map<ValueParameterDescriptor, CompileTimeConstant<?>> valueArguments = Maps.newHashMap();
|
||||
|
||||
@NotNull
|
||||
public JetType getType() {
|
||||
return annotationType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CompileTimeConstant<?> getValueArgument(@NotNull ValueParameterDescriptor valueParameterDescriptor) {
|
||||
return valueArguments.get(valueParameterDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<CompileTimeConstant<?>> getValueArguments() {
|
||||
return valueArguments;
|
||||
public Map<ValueParameterDescriptor, CompileTimeConstant<?>> getAllValueArguments() {
|
||||
return Collections.unmodifiableMap(valueArguments);
|
||||
}
|
||||
|
||||
public void setAnnotationType(@NotNull JetType annotationType) {
|
||||
@@ -48,7 +57,12 @@ public class AnnotationDescriptor {
|
||||
this.annotationType = annotationType;
|
||||
}
|
||||
|
||||
public void setValueArguments(@NotNull List<CompileTimeConstant<?>> valueArguments) {
|
||||
this.valueArguments = valueArguments;
|
||||
public void setValueArgument(@NotNull ValueParameterDescriptor name, @NotNull CompileTimeConstant<?> value) {
|
||||
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,
|
||||
@NotNull AnnotationDescriptor descriptor, BindingTrace trace) {
|
||||
List<CompileTimeConstant<?>> arguments = Lists.newArrayList();
|
||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> descriptorToArgument :
|
||||
results.getResultingCall().getValueArguments().entrySet()) {
|
||||
// TODO: are varargs supported here?
|
||||
List<ValueArgument> valueArguments = descriptorToArgument.getValue().getArguments();
|
||||
ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey();
|
||||
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
|
||||
|
||||
@@ -21,8 +21,10 @@ import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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.JetFunction;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
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;
|
||||
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) {
|
||||
new TypeSerializer(sb).serialize(annotation.getType());
|
||||
sb.append("(");
|
||||
serializeCommaSeparated(annotation.getValueArguments());
|
||||
serializeCommaSeparated(DescriptorUtils.getSortedValueArguments(annotation));
|
||||
sb.append(")");
|
||||
}
|
||||
|
||||
|
||||
@@ -48,10 +48,10 @@ public final class AnnotationsUtils {
|
||||
AnnotationDescriptor annotationDescriptor = getAnnotationByName(declarationDescriptor, annotation);
|
||||
assert annotationDescriptor != null;
|
||||
//TODO: this is a quick fix for unsupported default args problem
|
||||
if (annotationDescriptor.getValueArguments().isEmpty()) {
|
||||
if (annotationDescriptor.getAllValueArguments().isEmpty()) {
|
||||
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
|
||||
if (constant == null) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user