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; 018 019 import com.intellij.psi.PsiElement; 020 import org.jetbrains.annotations.NotNull; 021 import org.jetbrains.jet.lang.diagnostics.Diagnostic; 022 023 import java.util.Collection; 024 import java.util.Iterator; 025 026 public class SimpleDiagnostics implements Diagnostics { 027 private final Collection<Diagnostic> diagnostics; 028 private final DiagnosticsElementsCache elementsCache = new DiagnosticsElementsCache(this); 029 030 public SimpleDiagnostics(@NotNull Collection<Diagnostic> diagnostics) { 031 this.diagnostics = diagnostics; 032 } 033 034 @NotNull 035 @Override 036 public Collection<Diagnostic> all() { 037 return diagnostics; 038 } 039 040 @NotNull 041 @Override 042 public Collection<Diagnostic> forElement(@NotNull PsiElement psiElement) { 043 return elementsCache.getDiagnostics(psiElement); 044 } 045 046 @NotNull 047 @Override 048 public Diagnostics noSuppression() { 049 return this; 050 } 051 052 @NotNull 053 @Override 054 public Iterator<Diagnostic> iterator() { 055 return all().iterator(); 056 } 057 058 @Override 059 public boolean isEmpty() { 060 return all().isEmpty(); 061 } 062 }