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.structure.impl;
018
019 import com.intellij.psi.*;
020 import org.jetbrains.annotations.NotNull;
021 import org.jetbrains.annotations.Nullable;
022 import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotation;
023 import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationArgument;
024 import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
025 import org.jetbrains.jet.lang.resolve.name.FqName;
026 import org.jetbrains.jet.lang.resolve.name.Name;
027
028 import java.util.Collection;
029
030 import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.namedAnnotationArguments;
031
032 public class JavaAnnotationImpl extends JavaElementImpl<PsiAnnotation> implements JavaAnnotation {
033 public JavaAnnotationImpl(@NotNull PsiAnnotation psiAnnotation) {
034 super(psiAnnotation);
035 }
036
037 @Override
038 @Nullable
039 public JavaAnnotationArgument findArgument(@NotNull Name name) {
040 PsiAnnotationMemberValue attribute = getPsi().findAttributeValue(name.asString());
041 return attribute == null ? null : JavaAnnotationArgumentImpl.create(attribute, name);
042 }
043
044 @Override
045 @NotNull
046 public Collection<JavaAnnotationArgument> getArguments() {
047 return namedAnnotationArguments(getPsi().getParameterList().getAttributes());
048 }
049
050 @Override
051 @Nullable
052 public FqName getFqName() {
053 String qualifiedName = getPsi().getQualifiedName();
054 return qualifiedName == null ? null : new FqName(qualifiedName);
055 }
056
057 @Nullable
058 @Override
059 public JavaClass resolve() {
060 PsiJavaCodeReferenceElement referenceElement = getPsi().getNameReferenceElement();
061 if (referenceElement == null) return null;
062
063 PsiElement resolved = referenceElement.resolve();
064 if (!(resolved instanceof PsiClass)) return null;
065
066 return new JavaClassImpl((PsiClass) resolved);
067 }
068 }