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
017 package org.jetbrains.jet.lang.resolve.java.kt;
018
019 import com.intellij.psi.PsiAnnotation;
020 import com.intellij.psi.PsiParameter;
021 import org.jetbrains.annotations.NotNull;
022 import org.jetbrains.annotations.Nullable;
023 import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
024 import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationResolver;
025
026 public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
027 private static final JetValueParameterAnnotation NULL_ANNOTATION = new JetValueParameterAnnotation(null);
028 static {
029 NULL_ANNOTATION.checkInitialized();
030 }
031
032 private String name;
033 private String type;
034 private boolean receiver;
035 private boolean hasDefaultValue;
036 private boolean vararg;
037
038 private JetValueParameterAnnotation(@Nullable PsiAnnotation psiAnnotation) {
039 super(psiAnnotation);
040 }
041
042 @Override
043 protected void initialize() {
044 name = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "");
045 type = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, "");
046 receiver = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, false);
047 hasDefaultValue = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, false);
048 vararg = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_VARARG, false);
049 }
050
051 @NotNull
052 public String name() {
053 checkInitialized();
054 return name;
055 }
056
057 @NotNull
058 public String type() {
059 checkInitialized();
060 return type;
061 }
062
063 public boolean receiver() {
064 checkInitialized();
065 return receiver;
066 }
067
068 public boolean hasDefaultValue() {
069 checkInitialized();
070 return hasDefaultValue;
071 }
072
073 public boolean vararg() {
074 checkInitialized();
075 return vararg;
076 }
077
078 public static JetValueParameterAnnotation get(PsiParameter psiParameter) {
079 PsiAnnotation annotation =
080 JavaAnnotationResolver.findOwnAnnotation(psiParameter, JvmStdlibNames.JET_VALUE_PARAMETER.getFqName().asString());
081 return annotation != null ? new JetValueParameterAnnotation(annotation) : NULL_ANNOTATION;
082 }
083 }