Java packages are declared externally for the Kotlin PSI

Same for JetStandardLibrary classes
This commit is contained in:
Andrey Breslav
2012-07-04 19:08:55 +04:00
parent e42f91a7de
commit 2a1fd7e7d6
3 changed files with 97 additions and 2 deletions
@@ -0,0 +1,71 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.resolve.lazy;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetClassOrObject;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* @author abreslav
*/
public class EmptyPackageMemberDeclarationProvider implements PackageMemberDeclarationProvider {
public static final EmptyPackageMemberDeclarationProvider INSTANCE = new EmptyPackageMemberDeclarationProvider();
private EmptyPackageMemberDeclarationProvider() {}
@Override
public boolean isPackageDeclared(@NotNull Name name) {
return false;
}
@Override
public Collection<FqName> getAllDeclaredPackages() {
return Collections.emptyList();
}
@Override
public List<JetDeclaration> getAllDeclarations() {
return Collections.emptyList();
}
@NotNull
@Override
public Collection<JetNamedFunction> getFunctionDeclarations(@NotNull Name name) {
return Collections.emptyList();
}
@NotNull
@Override
public Collection<JetProperty> getPropertyDeclarations(@NotNull Name name) {
return Collections.emptyList();
}
@Override
public JetClassOrObject getClassOrObjectDeclaration(@NotNull Name name) {
return null;
}
}
@@ -0,0 +1,7 @@
package org.jetbrains.jet.lang.resolve.lazy;
/**
* @author abreslav
*/
public class ExternalNamespaceProvider {
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.lang.resolve.lazy;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -40,10 +41,17 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
private final Map<FqName, PackageMemberDeclarationProvider> packageDeclarationProviders = Maps.newHashMap();
//private final Map<JetClassOrObject, ClassMemberDeclarationProvider> classMemberDeclarationProviders = Maps.newHashMap();
private final Predicate<FqName> isPackageDeclaredExternally;
private boolean indexed = false;
public FileBasedDeclarationProviderFactory(@NotNull Collection<JetFile> files) {
this(files, Predicates.<FqName>alwaysFalse());
}
public FileBasedDeclarationProviderFactory(@NotNull Collection<JetFile> files, Predicate<FqName> isPackageDeclaredExternally) {
this.allFiles = files;
this.isPackageDeclaredExternally = isPackageDeclaredExternally;
}
private void createIndex() {
@@ -69,11 +77,15 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
}
}
/*package*/ boolean isPackageDeclared(@NotNull FqName packageFqName) {
/*package*/ boolean isPackageDeclaredExplicitly(@NotNull FqName packageFqName) {
createIndex();
return declaredPackages.contains(packageFqName);
}
/*package*/ boolean isPackageDeclared(@NotNull FqName packageFqName) {
return isPackageDeclaredExplicitly(packageFqName) || isPackageDeclaredExternally.apply(packageFqName);
}
/*package*/ Collection<FqName> getAllDeclaredSubPackagesOf(@NotNull final FqName parent) {
return Collections2.filter(declaredPackages, new Predicate<FqName>() {
@Override
@@ -92,7 +104,12 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
return declarationProvider;
}
if (!isPackageDeclared(packageFqName)) return null;
if (!isPackageDeclaredExplicitly(packageFqName)) {
if (isPackageDeclaredExternally.apply(packageFqName)) {
return EmptyPackageMemberDeclarationProvider.INSTANCE;
}
return null;
}
FileBasedPackageMemberDeclarationProvider provider =
new FileBasedPackageMemberDeclarationProvider(packageFqName, this, filesByPackage.get(packageFqName));