AnnotationDescriptor interface extracted

This commit is contained in:
Andrey Breslav
2013-10-15 18:21:30 +04:00
parent 71a0d4cc45
commit d52f2e25b0
7 changed files with 85 additions and 57 deletions
@@ -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);
@@ -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;
@@ -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() {
@@ -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();
}
@@ -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);
}
}