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.psi.PsiClass;
020 import com.intellij.psi.PsiElement;
021 import com.intellij.psi.PsiFile;
022 import com.intellij.psi.PsiManager;
023 import com.intellij.psi.impl.light.AbstractLightClass;
024 import org.jetbrains.annotations.NotNull;
025 import org.jetbrains.annotations.Nullable;
026 import org.jetbrains.jet.lang.psi.JetClassOrObject;
027 import org.jetbrains.jet.lang.psi.JetFile;
028 import org.jetbrains.jet.lang.resolve.java.jetAsJava.JetJavaMirrorMarker;
029 import org.jetbrains.jet.lang.resolve.name.FqName;
030
031 /**
032 * This class serves as a workaround for usages of {@link JavaElementFinder#findClasses} which eventually only need names of files
033 * containing the class. When queried for a package class (e.g. test/TestPackage), {@code findClasses} along with a
034 * {@link KotlinLightClassForPackage} would also return multiple instances of this class for each file present in the package. The client
035 * code can make use of every file in the package then, since {@code getContainingFile} of these instances will represent the whole package.
036 * <p/>
037 * See {@link LineBreakpoint#findClassCandidatesInSourceContent} for the primary usage this was introduced
038 */
039 public class FakeLightClassForFileOfPackage extends AbstractLightClass implements KotlinLightClass, JetJavaMirrorMarker {
040 private final KotlinLightClassForPackage delegate;
041 private final JetFile file;
042
043 public FakeLightClassForFileOfPackage(
044 @NotNull PsiManager manager, @NotNull KotlinLightClassForPackage delegate, @NotNull JetFile file
045 ) {
046 super(manager);
047 this.delegate = delegate;
048 this.file = file;
049 }
050
051 @Nullable
052 @Override
053 public JetClassOrObject getOrigin() {
054 return null;
055 }
056
057 @Override
058 public PsiFile getContainingFile() {
059 return file;
060 }
061
062 @Override
063 public boolean isValid() {
064 // This is intentionally false to prevent using this as a real class
065 return false;
066 }
067
068
069 @NotNull
070 @Override
071 public FqName getFqName() {
072 return delegate.getFqName();
073 }
074
075 @NotNull
076 @Override
077 public PsiClass getDelegate() {
078 return delegate;
079 }
080
081 @NotNull
082 @Override
083 public PsiElement copy() {
084 return new FakeLightClassForFileOfPackage(getManager(), delegate, file);
085 }
086
087 @Override
088 public String getText() {
089 return null;
090 }
091 }