001 /* 002 * Copyright 2010-2015 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.kotlin.resolve.lazy.data; 018 019 import com.intellij.psi.PsiElement; 020 import com.intellij.psi.PsiFile; 021 import org.jetbrains.annotations.NotNull; 022 import org.jetbrains.annotations.Nullable; 023 import org.jetbrains.kotlin.psi.*; 024 import org.jetbrains.kotlin.name.FqName; 025 026 import java.util.Collections; 027 import java.util.List; 028 029 public abstract class JetClassOrObjectInfo<E extends JetClassOrObject> implements JetClassLikeInfo { 030 protected final E element; 031 032 protected JetClassOrObjectInfo(@NotNull E element) { 033 this.element = element; 034 } 035 036 @Override 037 public JetClassOrObject getCorrespondingClassOrObject() { 038 return element; 039 } 040 041 @Override 042 @Nullable 043 public JetModifierList getModifierList() { 044 return element.getModifierList(); 045 } 046 047 @Override 048 @NotNull 049 public List<JetDeclaration> getDeclarations() { 050 return element.getDeclarations(); 051 } 052 053 @NotNull 054 @Override 055 public List<JetClassObject> getClassObjects() { 056 JetClassBody body = element.getBody(); 057 if (body == null) { 058 return Collections.emptyList(); 059 } 060 return body.getAllClassObjects(); 061 } 062 063 @NotNull 064 @Override 065 public PsiElement getScopeAnchor() { 066 return element; 067 } 068 069 @NotNull 070 @Override 071 public FqName getContainingPackageFqName() { 072 PsiFile file = element.getContainingFile(); 073 if (file instanceof JetFile) { 074 JetFile jetFile = (JetFile) file; 075 return jetFile.getPackageFqName(); 076 } 077 throw new IllegalArgumentException("Not in a JetFile: " + element); 078 } 079 080 @NotNull 081 @Override 082 public List<JetAnnotationEntry> getDanglingAnnotations() { 083 JetClassBody body = element.getBody(); 084 return body == null ? Collections.<JetAnnotationEntry>emptyList() : body.getDanglingAnnotations(); 085 } 086 087 @Override 088 public String toString() { 089 return "info for " + element.getText(); 090 } 091 }