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.asJava; 018 019 import com.intellij.lang.Language; 020 import com.intellij.psi.PsiClass; 021 import com.intellij.psi.PsiField; 022 import com.intellij.psi.PsiManager; 023 import com.intellij.psi.PsiMethod; 024 import com.intellij.psi.impl.PsiClassImplUtil; 025 import com.intellij.psi.impl.light.AbstractLightClass; 026 import org.jetbrains.jet.asJava.light.LightField; 027 import com.intellij.psi.impl.light.LightMethod; 028 import com.intellij.psi.impl.source.ClassInnerStuffCache; 029 import com.intellij.psi.impl.source.PsiExtensibleClass; 030 import com.intellij.util.Function; 031 import com.intellij.util.containers.ContainerUtil; 032 import org.jetbrains.annotations.NotNull; 033 import org.jetbrains.jet.lang.psi.JetDeclaration; 034 035 import java.util.List; 036 037 public abstract class KotlinWrappingLightClass extends AbstractLightClass implements PsiExtensibleClass { 038 private final ClassInnerStuffCache myInnersCache = new ClassInnerStuffCache(this); 039 040 protected KotlinWrappingLightClass(PsiManager manager, Language language) { 041 super(manager, language); 042 } 043 044 @Override 045 @NotNull 046 public PsiField[] getFields() { 047 return myInnersCache.getFields(); 048 } 049 050 @Override 051 @NotNull 052 public PsiMethod[] getMethods() { 053 return myInnersCache.getMethods(); 054 } 055 056 @Override 057 @NotNull 058 public PsiMethod[] getConstructors() { 059 return myInnersCache.getConstructors(); 060 } 061 062 @Override 063 @NotNull 064 public PsiClass[] getInnerClasses() { 065 return myInnersCache.getInnerClasses(); 066 } 067 068 @Override 069 @NotNull 070 public PsiField[] getAllFields() { 071 return PsiClassImplUtil.getAllFields(this); 072 } 073 074 @Override 075 @NotNull 076 public PsiMethod[] getAllMethods() { 077 return PsiClassImplUtil.getAllMethods(this); 078 } 079 080 @Override 081 @NotNull 082 public PsiClass[] getAllInnerClasses() { 083 return PsiClassImplUtil.getAllInnerClasses(this); 084 } 085 086 @Override 087 public PsiField findFieldByName(String name, boolean checkBases) { 088 return myInnersCache.findFieldByName(name, checkBases); 089 } 090 091 @Override 092 @NotNull 093 public PsiMethod[] findMethodsByName(String name, boolean checkBases) { 094 return myInnersCache.findMethodsByName(name, checkBases); 095 } 096 097 @Override 098 public PsiClass findInnerClassByName(String name, boolean checkBases) { 099 return myInnersCache.findInnerClassByName(name, checkBases); 100 } 101 102 @NotNull 103 @Override 104 public List<PsiField> getOwnFields() { 105 return ContainerUtil.map(getDelegate().getFields(), new Function<PsiField, PsiField>() { 106 @Override 107 public PsiField fun(PsiField field) { 108 return new LightField(myManager, field, KotlinWrappingLightClass.this); 109 } 110 }); 111 } 112 113 @NotNull 114 @Override 115 public List<PsiMethod> getOwnMethods() { 116 return ContainerUtil.map(getDelegate().getMethods(), new Function<PsiMethod, PsiMethod>() { 117 @Override 118 public PsiMethod fun(PsiMethod method) { 119 JetDeclaration declaration = ClsWrapperStubPsiFactory.getOriginalDeclaration(method); 120 return declaration != null 121 ? new KotlinLightMethodForDeclaration(myManager, method, declaration, KotlinWrappingLightClass.this) 122 : new LightMethod(myManager, method, KotlinWrappingLightClass.this); 123 } 124 }); 125 } 126 }