001/* 002 * Copyright 2010-2013 JetBrains s.r.o. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.jetbrains.jet.lang.descriptors.annotations; 018 019import com.google.common.collect.Maps; 020import org.jetbrains.annotations.NotNull; 021import org.jetbrains.annotations.Nullable; 022import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; 023import org.jetbrains.jet.lang.resolve.DescriptorUtils; 024import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; 025import org.jetbrains.jet.lang.types.JetType; 026 027import java.util.Collections; 028import java.util.Map; 029 030public class AnnotationDescriptor { 031 private JetType annotationType; 032 private final Map<ValueParameterDescriptor, CompileTimeConstant<?>> valueArguments = Maps.newHashMap(); 033 034 @NotNull 035 public JetType getType() { 036 return annotationType; 037 } 038 039 @Nullable 040 public CompileTimeConstant<?> getValueArgument(@NotNull ValueParameterDescriptor valueParameterDescriptor) { 041 return valueArguments.get(valueParameterDescriptor); 042 } 043 044 @NotNull 045 public Map<ValueParameterDescriptor, CompileTimeConstant<?>> getAllValueArguments() { 046 return Collections.unmodifiableMap(valueArguments); 047 } 048 049 public void setAnnotationType(@NotNull JetType annotationType) { 050 this.annotationType = annotationType; 051 } 052 053 public void setValueArgument(@NotNull ValueParameterDescriptor name, @NotNull CompileTimeConstant<?> value) { 054 valueArguments.put(name, value); 055 } 056 057 @Override 058 public String toString() { 059 return annotationType.toString() + DescriptorUtils.getSortedValueArguments(this, null); 060 } 061}