Changed language sematics: imports with '*' do not import packages anymore

This commit is contained in:
Valentin Kipyatkov
2014-12-24 20:05:15 +03:00
parent d540f3b724
commit 1f17d7adcd
16 changed files with 66 additions and 16 deletions
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2014 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
import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor
import org.jetbrains.jet.lang.resolve.name.Name
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
class ClassesInPackageScope(packageDescriptor: PackageViewDescriptor) : JetScope by packageDescriptor.getMemberScope() {
private val memberScope = packageDescriptor.getMemberScope()
override fun getPackage(name: Name): PackageViewDescriptor? = null
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
val modifiedFilter = kindFilter.withoutKinds(DescriptorKindFilter.PACKAGES_MASK)
if (modifiedFilter.kindMask == 0) return listOf()
return memberScope.getDescriptors(modifiedFilter, nameFilter).filter { it !is PackageViewDescriptor }
}
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
return memberScope.getOwnDeclaredDescriptors().filter { it !is PackageViewDescriptor }
}
}
@@ -24,9 +24,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.FilteringScope;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.*;
import java.util.ArrayList;
import java.util.Collection;
@@ -88,7 +86,7 @@ public interface Importer {
protected void importAllUnderDeclaration(@NotNull DeclarationDescriptor descriptor, @NotNull PlatformToKotlinClassMap platformToKotlinClassMap) {
List<JetScope> scopesToImport = new ArrayList<JetScope>(3);
if (descriptor instanceof PackageViewDescriptor) {
scopesToImport.add(((PackageViewDescriptor) descriptor).getMemberScope());
scopesToImport.add(new ClassesInPackageScope((PackageViewDescriptor) descriptor));
}
else if (descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() != ClassKind.OBJECT) {
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
@@ -4,8 +4,9 @@
package foobar.a
import java.*
val a : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>util.List<Int><!>? = null
val a1 : <!UNRESOLVED_REFERENCE!>ArrayList<!><Int>? = null
val a : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util.List<Int><!>? = null
val a2 : <!UNRESOLVED_REFERENCE!>util<!>.<!DEBUG_INFO_MISSING_UNRESOLVED!>List<!><Int>? = null
val a3 : <!UNRESOLVED_REFERENCE!>ArrayList<!><Int>? = null
// FILE: b.kt
package foobar
@@ -58,7 +58,8 @@ package foobar {
package foobar.a {
internal val a: java.util.List<kotlin.Int>? = null
internal val a1: [ERROR : ArrayList<Int>]?
internal val a2: [ERROR : util.List<Int>]?
internal val a3: [ERROR : ArrayList<Int>]?
internal val b: kotlin.List<kotlin.Int>? = null
internal val b1: [ERROR : util.List<Int>]?
}
@@ -1,5 +1,5 @@
// Fixpoint generic in Java: Enum<T extends Enum<T>>
fun test(<!UNUSED_PARAMETER!>a<!> : annotation.RetentionPolicy) {
fun test(<!UNUSED_PARAMETER!>a<!> : java.lang.annotation.RetentionPolicy) {
}
@@ -6,6 +6,7 @@ import <!UNRESOLVED_REFERENCE!>utils<!>.*
import java.io.PrintStream
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<!> as Com
import java.util
val l : MutableList<in Int> = ArrayList<Int>()
@@ -1,5 +1,6 @@
import `java::java`java.*
import java.`java::java.util`util.*
import java.util
fun foo(~a~a : `kotlin::Array`Array<`kotlin::Int`Int>) : `java::java.util.ArrayList`ArrayList {
`a`a.`kotlin::Array.get(Int)`get(1)
+1
View File
@@ -1,5 +1,6 @@
import java.*
import java.util.*
import java.util
import <error>utils</error>.*
import java.io.PrintStream
@@ -1,6 +1,6 @@
package some
import jettesting.*
import jettesting.data
fun other() {
data.topLevelFu<caret>
@@ -1,6 +1,6 @@
package some
import jettesting.*
import jettesting.data
fun other() {
data.topLevelFunction()
@@ -1,7 +1,7 @@
package testing.rename2
import testing.rename.Third
import testing.*
import testing.rename
import java.util.ArrayList
// Extends testing.rename.Third
@@ -1,7 +1,7 @@
package testing.rename2
import testing.rename.First
import testing.*
import testing.rename
import java.util.ArrayList
// Extends testing.rename.First
@@ -1,5 +1,7 @@
import java.io
fun File(): String = ""
class A {
val x = java.io.File()
val x = io.File()
}
@@ -1,5 +1,7 @@
import java.util
fun Random(): Int = 1
class A {
val x = java.util.Random()
val x = util.Random()
}
@@ -1,4 +1,6 @@
import java.util
fun foo(){
val Random = {}
val x = java.util.Random()
val x = util.Random()
}
@@ -1,6 +1,8 @@
import java.io
fun File(p: Int): String = ""
fun File(p: String): String = ""
class A {
val x = java.io.File()
val x = io.File()
}