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.PsiMethod;
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 JetMethodAnnotation extends PsiAnnotationWithFlags {
027 private static final JetMethodAnnotation NULL_ANNOTATION = new JetMethodAnnotation(null);
028 static {
029 NULL_ANNOTATION.checkInitialized();
030 }
031
032 private String typeParameters;
033 private String returnType;
034 private String propertyType;
035
036 private JetMethodAnnotation(@Nullable PsiAnnotation psiAnnotation) {
037 super(psiAnnotation);
038 }
039
040 @Override
041 protected void initialize() {
042 super.initialize();
043 typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, "");
044 returnType = getStringAttribute(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, "");
045 propertyType = getStringAttribute(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, "");
046 }
047
048 public int kind() {
049 return flags() & JvmStdlibNames.FLAG_METHOD_KIND_MASK;
050 }
051
052 @NotNull
053 public String typeParameters() {
054 checkInitialized();
055 return typeParameters;
056 }
057
058 @NotNull
059 public String returnType() {
060 checkInitialized();
061 return returnType;
062 }
063
064 @NotNull
065 public String propertyType() {
066 checkInitialized();
067 return propertyType;
068 }
069
070 public static JetMethodAnnotation get(PsiMethod psiMethod) {
071 PsiAnnotation annotation =
072 JavaAnnotationResolver.findOwnAnnotation(psiMethod, JvmStdlibNames.JET_METHOD.getFqName().asString());
073 return annotation != null ? new JetMethodAnnotation(annotation) : NULL_ANNOTATION;
074 }
075 }