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 017package org.jetbrains.jet.lang.resolve.lazy.data; 018 019import com.google.common.base.Predicate; 020import com.google.common.collect.Collections2; 021import com.google.common.collect.Lists; 022import com.intellij.openapi.util.Computable; 023import com.intellij.psi.PsiElement; 024import org.jetbrains.annotations.NotNull; 025import org.jetbrains.annotations.Nullable; 026import org.jetbrains.jet.lang.descriptors.ClassKind; 027import org.jetbrains.jet.lang.psi.*; 028import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue; 029import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager; 030import org.jetbrains.jet.lang.resolve.name.FqName; 031 032import java.util.List; 033 034public class FilteringClassLikeInfo implements JetClassLikeInfo { 035 private final JetClassLikeInfo delegate; 036 private final NotNullLazyValue<List<JetDeclaration>> filteredDeclarations; 037 038 public FilteringClassLikeInfo( 039 @NotNull StorageManager storageManager, 040 @NotNull final JetClassLikeInfo delegate, 041 @NotNull final Predicate<? super JetDeclaration> declarationFilter 042 ) { 043 this.delegate = delegate; 044 this.filteredDeclarations = storageManager.createLazyValue(new Computable<List<JetDeclaration>>() { 045 @Override 046 public List<JetDeclaration> compute() { 047 return Lists.newArrayList(Collections2.filter(delegate.getDeclarations(), declarationFilter)); 048 } 049 }); 050 } 051 052 @NotNull 053 @Override 054 public FqName getContainingPackageFqName() { 055 return delegate.getContainingPackageFqName(); 056 } 057 058 @Override 059 @NotNull 060 public List<JetDelegationSpecifier> getDelegationSpecifiers() { 061 return delegate.getDelegationSpecifiers(); 062 } 063 064 @Override 065 @Nullable 066 public JetModifierList getModifierList() { 067 return delegate.getModifierList(); 068 } 069 070 @Override 071 @Nullable 072 public JetClassObject getClassObject() { 073 return delegate.getClassObject(); 074 } 075 076 @Override 077 @NotNull 078 public PsiElement getScopeAnchor() { 079 return delegate.getScopeAnchor(); 080 } 081 082 @Override 083 @Nullable 084 public JetClassOrObject getCorrespondingClassOrObject() { 085 return delegate.getCorrespondingClassOrObject(); 086 } 087 088 @Override 089 @NotNull 090 public List<JetTypeParameter> getTypeParameters() { 091 return delegate.getTypeParameters(); 092 } 093 094 @Override 095 @NotNull 096 public List<? extends JetParameter> getPrimaryConstructorParameters() { 097 return delegate.getPrimaryConstructorParameters(); 098 } 099 100 @Override 101 @NotNull 102 public ClassKind getClassKind() { 103 return delegate.getClassKind(); 104 } 105 106 @Override 107 @NotNull 108 public List<JetDeclaration> getDeclarations() { 109 return filteredDeclarations.compute(); 110 } 111 112 @Override 113 public String toString() { 114 return "filtering " + delegate.toString(); 115 } 116}