KT-1717 Don't make member visibility inherit when it is not declared explicitly
#KT-1717 Fixed
This commit is contained in:
@@ -251,12 +251,12 @@ public abstract class CodegenContext {
|
||||
PropertyDescriptor myAccessor = new PropertyDescriptor(contextType,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
pd.getModality(),
|
||||
pd.getVisibility(),
|
||||
pd.isVar(),
|
||||
pd.isObjectDeclaration(),
|
||||
pd.getName() + "$bridge$" + accessors.size(),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
myAccessor.setVisibility(pd.getVisibility());
|
||||
JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null;
|
||||
myAccessor.setType(pd.getType(), Collections.<TypeParameterDescriptor>emptyList(), pd.getExpectedThisObject(), receiverType);
|
||||
|
||||
|
||||
+1
-1
@@ -1150,11 +1150,11 @@ public class JavaDescriptorResolver {
|
||||
owner,
|
||||
resolveAnnotations(anyMember.getMember().psiMember),
|
||||
modality,
|
||||
resolveVisibilityFromPsiModifiers(anyMember.getMember().psiMember),
|
||||
isVar,
|
||||
false,
|
||||
propertyName,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setVisibility(resolveVisibilityFromPsiModifiers(anyMember.getMember().psiMember));
|
||||
|
||||
PropertyGetterDescriptor getterDescriptor = null;
|
||||
PropertySetterDescriptor setterDescriptor = null;
|
||||
|
||||
+1
-2
@@ -48,8 +48,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
|
||||
//isStatic - for java only
|
||||
public ConstructorDescriptorImpl initialize(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, Visibility visibility, boolean isStatic) {
|
||||
super.initialize(null, isStatic ? ReceiverDescriptor.NO_RECEIVER : getExpectedThisObject(getContainingDeclaration()), typeParameters, unsubstitutedValueParameters, null, Modality.FINAL);
|
||||
setVisibility(visibility);
|
||||
super.initialize(null, isStatic ? ReceiverDescriptor.NO_RECEIVER : getExpectedThisObject(getContainingDeclaration()), typeParameters, unsubstitutedValueParameters, null, Modality.FINAL, visibility);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+6
-7
@@ -78,11 +78,13 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@Nullable JetType unsubstitutedReturnType,
|
||||
@Nullable Modality modality) {
|
||||
@Nullable Modality modality,
|
||||
@NotNull Visibility visibility) {
|
||||
this.typeParameters = typeParameters;
|
||||
this.unsubstitutedValueParameters = unsubstitutedValueParameters;
|
||||
this.unsubstitutedReturnType = unsubstitutedReturnType;
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.receiver = receiverType == null ? NO_RECEIVER : new ExtensionReceiver(this, receiverType);
|
||||
this.expectedThisObject = expectedThisObject;
|
||||
|
||||
@@ -104,10 +106,6 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setVisibility(@NotNull Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
public void setReturnType(@NotNull JetType unsubstitutedReturnType) {
|
||||
this.unsubstitutedReturnType = unsubstitutedReturnType;
|
||||
}
|
||||
@@ -223,8 +221,9 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
substitutedTypeParameters,
|
||||
substitutedValueParameters,
|
||||
substitutedReturnType,
|
||||
newModality);
|
||||
substitutedDescriptor.setVisibility(visibility);
|
||||
newModality,
|
||||
visibility
|
||||
);
|
||||
if (copyOverrides) {
|
||||
for (FunctionDescriptor overriddenFunction : overriddenFunctions) {
|
||||
substitutedDescriptor.addOverriddenDescriptor(overriddenFunction.substitute(substitutor));
|
||||
|
||||
+2
-2
@@ -126,8 +126,8 @@ public class FunctionDescriptorUtil {
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
JetStandardClasses.getValueParameters(functionDescriptor, functionType),
|
||||
JetStandardClasses.getReturnTypeFromFunctionType(functionType),
|
||||
Modality.FINAL);
|
||||
functionDescriptor.setVisibility(Visibilities.LOCAL);
|
||||
Modality.FINAL,
|
||||
Visibilities.LOCAL);
|
||||
}
|
||||
|
||||
public static <D extends CallableDescriptor> D alphaConvertTypeParameters(D candidate) {
|
||||
|
||||
@@ -67,6 +67,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
boolean isObject,
|
||||
@NotNull String name,
|
||||
@@ -75,6 +76,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
this.isVar = isVar;
|
||||
this.isObject = isObject;
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.original = original == null ? this : original.getOriginal();
|
||||
this.kind = kind;
|
||||
}
|
||||
@@ -83,11 +85,12 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
boolean isObject,
|
||||
@NotNull String name,
|
||||
Kind kind) {
|
||||
this(null, containingDeclaration, annotations, modality, isVar, isObject, name, kind);
|
||||
this(null, containingDeclaration, annotations, modality, visibility, isVar, isObject, name, kind);
|
||||
}
|
||||
|
||||
public PropertyDescriptor(
|
||||
@@ -103,7 +106,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@NotNull JetType outType,
|
||||
Kind kind
|
||||
) {
|
||||
this(containingDeclaration, annotations, modality, isVar, isObject, name, kind);
|
||||
this(containingDeclaration, annotations, modality, visibility, isVar, isObject, name, kind);
|
||||
setType(outType, Collections.<TypeParameterDescriptor>emptyList(), expectedThisObject, receiverType);
|
||||
}
|
||||
|
||||
@@ -128,10 +131,6 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
this.setter = setter;
|
||||
}
|
||||
|
||||
public void setVisibility(@NotNull Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getTypeParameters() {
|
||||
@@ -207,16 +206,8 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
|
||||
private PropertyDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
final PropertyDescriptor thisProperty = this;
|
||||
PropertyDescriptor substitutedDescriptor = new PropertyDescriptor(preserveOriginal ? getOriginal() : this, newOwner,
|
||||
getAnnotations(), newModality, isVar(), isObjectDeclaration(), getName(), kind) {
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
// visibility of property can be not set yet
|
||||
return thisProperty.getVisibility();
|
||||
}
|
||||
};
|
||||
getAnnotations(), newModality, getVisibility(), isVar(), isObjectDeclaration(), getName(), kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
|
||||
+1
-2
@@ -59,8 +59,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
@Nullable Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isInline) {
|
||||
super.initialize(receiverType, expectedThisObject, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType, modality);
|
||||
setVisibility(visibility);
|
||||
super.initialize(receiverType, expectedThisObject, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType, modality, visibility);
|
||||
this.isInline = isInline;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -125,6 +125,11 @@ public class PositioningStrategies {
|
||||
result.add(element.getModifierList().getModifierNode(token).getTextRange());
|
||||
}
|
||||
}
|
||||
if (result.isEmpty()) {
|
||||
if (element.hasModifier(JetTokens.OVERRIDE_KEYWORD)) {
|
||||
result.add(element.getModifierList().getModifierNode(JetTokens.OVERRIDE_KEYWORD).getTextRange());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -486,12 +486,12 @@ public class DescriptorResolver {
|
||||
containingDeclaration,
|
||||
annotationResolver.createAnnotationStubs(modifierList, trace),
|
||||
Modality.FINAL,
|
||||
resolveVisibilityFromModifiers(modifierList),
|
||||
false,
|
||||
true,
|
||||
JetPsiUtil.safeName(objectDeclaration.getName()),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
propertyDescriptor.setVisibility(resolveVisibilityFromModifiers(modifierList));
|
||||
propertyDescriptor.setType(classDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), ReceiverDescriptor.NO_RECEIVER);
|
||||
propertyDescriptor.initialize(createDefaultGetter(propertyDescriptor), null);
|
||||
JetObjectDeclarationName nameAsDeclaration = objectDeclaration.getNameAsDeclaration();
|
||||
@@ -543,12 +543,12 @@ public class DescriptorResolver {
|
||||
containingDeclaration,
|
||||
annotationResolver.resolveAnnotations(scope, modifierList, trace),
|
||||
resolveModalityFromModifiers(property.getModifierList(), defaultModality),
|
||||
resolveVisibilityFromModifiers(property.getModifierList()),
|
||||
isVar,
|
||||
false,
|
||||
JetPsiUtil.safeName(property.getName()),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
propertyDescriptor.setVisibility(resolveVisibilityFromModifiers(property.getModifierList()));
|
||||
|
||||
List<TypeParameterDescriptor> typeParameterDescriptors;
|
||||
JetScope scopeWithTypeParameters;
|
||||
@@ -861,12 +861,12 @@ public class DescriptorResolver {
|
||||
classDescriptor,
|
||||
annotationResolver.resolveAnnotations(scope, modifierList, trace),
|
||||
resolveModalityFromModifiers(parameter.getModifierList(), Modality.FINAL),
|
||||
resolveVisibilityFromModifiers(parameter.getModifierList()),
|
||||
isMutable,
|
||||
false,
|
||||
name == null ? "<no name>" : name,
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
propertyDescriptor.setVisibility(resolveVisibilityFromModifiers(parameter.getModifierList()));
|
||||
propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(), DescriptorUtils.getExpectedThisObjectIfNeeded(classDescriptor), ReceiverDescriptor.NO_RECEIVER);
|
||||
|
||||
PropertyGetterDescriptor getter = createDefaultGetter(propertyDescriptor);
|
||||
|
||||
@@ -69,9 +69,7 @@ public class OverrideResolver {
|
||||
public void process() {
|
||||
generateOverrides();
|
||||
checkOverrides();
|
||||
//functions and properties visibility can be inherited when overriding, so it can be resolved only after overrides resolve is finished
|
||||
//also invisible overridden descriptors are removed here
|
||||
resolveVisibilityForFunctionsAndProperties();
|
||||
checkVisibilityForOverriddenMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,69 +419,31 @@ public class OverrideResolver {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void resolveVisibilityForFunctionsAndProperties() {
|
||||
private void checkVisibilityForOverriddenMembers() {
|
||||
for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry : context.getFunctions().entrySet()) {
|
||||
JetNamedFunction function = entry.getKey();
|
||||
SimpleFunctionDescriptor functionDescriptor = entry.getValue();
|
||||
|
||||
Visibility visibility = resolveVisibilityForMember(function, functionDescriptor);
|
||||
((SimpleFunctionDescriptorImpl) functionDescriptor).setVisibility(visibility);
|
||||
checkVisibilityForMember(functionDescriptor.getVisibility(), function, functionDescriptor.getOverriddenDescriptors());
|
||||
}
|
||||
for (Map.Entry<JetProperty, PropertyDescriptor> entry : context.getProperties().entrySet()) {
|
||||
JetProperty property = entry.getKey();
|
||||
PropertyDescriptor propertyDescriptor = entry.getValue();
|
||||
|
||||
Visibility visibility = resolveVisibilityForMember(property, propertyDescriptor);
|
||||
propertyDescriptor.setVisibility(visibility);
|
||||
checkVisibilityForMember(propertyDescriptor.getVisibility(), property, propertyDescriptor.getOverriddenDescriptors());
|
||||
}
|
||||
}
|
||||
|
||||
private Visibility resolveVisibilityForMember(JetDeclaration member, CallableMemberDescriptor memberDescriptor) {
|
||||
removeInvisibleOverriddenDescriptors(memberDescriptor);
|
||||
Visibility defaultVisibility = findMaxVisibility(memberDescriptor.getOverriddenDescriptors());
|
||||
Visibility visibility = DescriptorResolver.resolveVisibilityFromModifiers(member.getModifierList(), defaultVisibility);
|
||||
checkMaxVisibility(visibility, member, memberDescriptor.getOverriddenDescriptors());
|
||||
return visibility;
|
||||
}
|
||||
|
||||
private void removeInvisibleOverriddenDescriptors(@NotNull CallableDescriptor descriptor) {
|
||||
Set<? extends CallableDescriptor> overriddenDescriptors = descriptor.getOverriddenDescriptors();
|
||||
for (Iterator<? extends CallableDescriptor> iterator = overriddenDescriptors.iterator(); iterator.hasNext(); ) {
|
||||
CallableDescriptor superDescriptor = iterator.next();
|
||||
if (!Visibilities.isVisible(superDescriptor, descriptor)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Visibility findMaxVisibility(@NotNull Collection<? extends DeclarationDescriptorWithVisibility> descriptors) {
|
||||
Visibility maxVisibility = null;
|
||||
for (DeclarationDescriptorWithVisibility descriptor : descriptors) {
|
||||
Visibility visibility = descriptor.getVisibility();
|
||||
if (maxVisibility == null) {
|
||||
maxVisibility = visibility;
|
||||
continue;
|
||||
}
|
||||
Integer compare = Visibilities.compare(visibility, maxVisibility);
|
||||
if (compare == null) {
|
||||
maxVisibility = Visibilities.PUBLIC; //todo error or warning when inference only from incomparable visibilities
|
||||
continue;
|
||||
}
|
||||
if (compare > 0) {
|
||||
maxVisibility = visibility;
|
||||
}
|
||||
}
|
||||
return maxVisibility != null ? maxVisibility : Visibilities.INTERNAL;
|
||||
}
|
||||
|
||||
private void checkMaxVisibility(@NotNull Visibility visibility, @NotNull JetModifierListOwner modifierListOwner, @NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
|
||||
private void checkVisibilityForMember(@NotNull Visibility visibility,
|
||||
@NotNull JetModifierListOwner modifierListOwner,
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
Integer compare = Visibilities.compare(visibility, descriptor.getVisibility());
|
||||
if (compare == null) {
|
||||
trace.report(CANNOT_CHANGE_ACCESS_PRIVILEGE.on(modifierListOwner, descriptor.getVisibility(), descriptor, descriptor.getContainingDeclaration()));
|
||||
return;
|
||||
}
|
||||
else if (compare < 0) {
|
||||
if (compare < 0) {
|
||||
trace.report(CANNOT_WEAKEN_ACCESS_PRIVILEGE.on(modifierListOwner, descriptor.getVisibility(), descriptor, descriptor.getContainingDeclaration()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,9 @@ public class OverridingUtil {
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo isOverridableBy(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) {
|
||||
if (!Visibilities.isVisible(superDescriptor, subDescriptor)) {
|
||||
return OverrideCompatibilityInfo.invisibleMember();
|
||||
}
|
||||
if (superDescriptor instanceof FunctionDescriptor) {
|
||||
if (subDescriptor instanceof PropertyDescriptor) return OverrideCompatibilityInfo.memberKindMismatch();
|
||||
}
|
||||
@@ -318,6 +321,11 @@ public class OverridingUtil {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "varOverriddenByVal"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo invisibleMember() {
|
||||
return new OverrideCompatibilityInfo(Result.INCOMPATIBLE, "invisibleMember");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private final Result overridable;
|
||||
|
||||
@@ -155,8 +155,7 @@ public class JetStandardClasses {
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
true, Variance.OUT_VARIANCE, "T" + (j + 1), j);
|
||||
parameters.add(typeParameterDescriptor);
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, false, false, "_" + (j + 1), CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setVisibility(Visibilities.PUBLIC);
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, false, "_" + (j + 1), CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(typeParameterDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), classDescriptor.getImplicitReceiver(), ReceiverDescriptor.NO_RECEIVER);
|
||||
PropertyGetterDescriptor getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, true, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
getterDescriptor.initialize(typeParameterDescriptor.getDefaultType());
|
||||
|
||||
@@ -2,7 +2,7 @@ class C() {
|
||||
fun getInstance(): Runnable = C
|
||||
|
||||
class object: Runnable {
|
||||
override fun run(): Unit { }
|
||||
public override fun run(): Unit { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,25 +78,25 @@ fun box() : String {
|
||||
}
|
||||
|
||||
class MyCollection1(): java.lang.Iterable<Int> {
|
||||
override fun iterator(): java.util.Iterator<Int> = MyIterator()
|
||||
public override fun iterator(): java.util.Iterator<Int> = MyIterator()
|
||||
|
||||
class MyIterator(): java.util.Iterator<Int> {
|
||||
var k : Int = 5
|
||||
|
||||
override fun next() : Int = k--
|
||||
override fun hasNext() = k > 0
|
||||
override fun remove() {}
|
||||
public override fun next() : Int = k--
|
||||
public override fun hasNext() = k > 0
|
||||
public override fun remove() {}
|
||||
}
|
||||
}
|
||||
|
||||
class MyCollection2(): Iterable<Int> {
|
||||
override fun iterator(): Iterator<Int> = MyIterator()
|
||||
public override fun iterator(): Iterator<Int> = MyIterator()
|
||||
|
||||
class MyIterator(): Iterator<Int> {
|
||||
var k : Int = 5
|
||||
|
||||
override fun next() : Int = k--
|
||||
override val hasNext : Boolean
|
||||
public override fun next() : Int = k--
|
||||
public override val hasNext : Boolean
|
||||
get() = k > 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import java.util.concurrent.atomic.*
|
||||
|
||||
fun thread(block: ()->Unit ) {
|
||||
val thread = object: Thread() {
|
||||
override fun run() {
|
||||
public override fun run() {
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class C(x: Int, val y : Int) {
|
||||
fun initChild(var x: Int) : java.lang.Object {
|
||||
return object : java.lang.Object() {
|
||||
override fun toString(): String? {
|
||||
public override fun toString(): String? {
|
||||
x = x + y
|
||||
return "child" + x
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package p
|
||||
class C(val y : Int) {
|
||||
val initChild = { ->
|
||||
object : java.lang.Object() {
|
||||
override fun toString(): String {
|
||||
public override fun toString(): String {
|
||||
return "child" + y
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import java.util.ArrayList
|
||||
|
||||
public object SomeObject {
|
||||
private val workerThread = object : Thread() {
|
||||
override fun run() {
|
||||
public override fun run() {
|
||||
foo()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ public object SomeClass {
|
||||
var bug: Any = ""
|
||||
|
||||
private val workerThread = object : Thread() {
|
||||
override fun run() {
|
||||
public override fun run() {
|
||||
try {
|
||||
foo()
|
||||
bug = "none"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
public object RefreshQueue {
|
||||
private val workerThread: Thread = Thread(object : Runnable {
|
||||
override fun run() {
|
||||
public override fun run() {
|
||||
workerThread.isInterrupted()
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,9 +7,9 @@ public abstract class BaseClass() {
|
||||
}
|
||||
|
||||
public class Subclass : BaseClass() {
|
||||
override val kind : String = "Physical"
|
||||
protected override val kind : String = "Physical"
|
||||
|
||||
override val kind2 : String = " kind2"
|
||||
protected override val kind2 : String = " kind2"
|
||||
}
|
||||
|
||||
fun box():String = if(Subclass().debug() == "Physical kind2") "OK" else "fail"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MyRange1() : Range<Int> {
|
||||
override fun contains(item: Int) = true
|
||||
public override fun contains(item: Int) = true
|
||||
}
|
||||
|
||||
class MyRange2() {
|
||||
|
||||
@@ -163,7 +163,7 @@ fun t11(var x: Int) : Int {
|
||||
fun t12(x: Int) : Int {
|
||||
var y = x
|
||||
val runnable = object : Runnable {
|
||||
override fun run () {
|
||||
public override fun run () {
|
||||
y = y + 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,11 +95,11 @@ fun LinkedList<Int>.sum(f : (Int, Int) -> Int) : Int {
|
||||
}
|
||||
|
||||
fun <T> List<T>.backwards() : Iterable<T> = object : Iterable<T> {
|
||||
override fun iterator() : jet.Iterator<T> =
|
||||
public override fun iterator() : jet.Iterator<T> =
|
||||
object : jet.Iterator<T> {
|
||||
var current = size()
|
||||
override fun next() : T = get(--current)
|
||||
override val hasNext : Boolean get() = current > 0
|
||||
public override fun next() : T = get(--current)
|
||||
public override val hasNext : Boolean get() = current > 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Book(val name: String) : Comparable<Book> {
|
||||
override fun compareTo(other: Book) = name.compareTo(other.name)
|
||||
public override fun compareTo(other: Book) = name.compareTo(other.name)
|
||||
}
|
||||
|
||||
fun box() = if(Book("239").compareTo(Book("932")) != 0) "OK" else "fail"
|
||||
@@ -3,13 +3,13 @@ import java.util.*
|
||||
fun box() : String {
|
||||
val w = object : Comparator<String?> {
|
||||
|
||||
override fun compare(o1 : String?, o2 : String?) : Int {
|
||||
public override fun compare(o1 : String?, o2 : String?) : Int {
|
||||
val l1 : Int = o1?.length ?: 0
|
||||
val l2 = o2?.length ?: 0
|
||||
return l1 - l2
|
||||
}
|
||||
|
||||
override fun equals(obj: Any?): Boolean = obj === this
|
||||
public override fun equals(obj: Any?): Boolean = obj === this
|
||||
}
|
||||
|
||||
w.compare("aaa", "bbb")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
class N() : ArrayList<Any>() {
|
||||
override fun add(el: Any) : Boolean {
|
||||
public override fun add(el: Any) : Boolean {
|
||||
if (!super<ArrayList>.add(el)) {
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ trait SimpleClass : java.lang.Object {
|
||||
}
|
||||
|
||||
class SimpleClassImpl() : SimpleClass {
|
||||
override fun toString() = "SimpleClassImpl"
|
||||
public override fun toString() = "SimpleClassImpl"
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
|
||||
@@ -3,7 +3,7 @@ trait ISized {
|
||||
}
|
||||
|
||||
trait javaUtilIterator<T> : java.util.Iterator<T> {
|
||||
override fun remove() : Unit {
|
||||
public override fun remove() : Unit {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,9 @@ trait javaUtilIterator<T> : java.util.Iterator<T> {
|
||||
class MyIterator<T>(val array : ReadOnlyArray<T>) : javaUtilIterator<T> {
|
||||
private var index = 0
|
||||
|
||||
override fun hasNext() : Boolean = index < array.size
|
||||
public override fun hasNext() : Boolean = index < array.size
|
||||
|
||||
override fun next() : T = array.get(index++)
|
||||
public override fun next() : T = array.get(index++)
|
||||
}
|
||||
|
||||
trait ReadOnlyArray<out T> : ISized, java.lang.Iterable<T> {
|
||||
@@ -23,7 +23,7 @@ trait ReadOnlyArray<out T> : ISized, java.lang.Iterable<T> {
|
||||
fun check(v: Any) = v is T
|
||||
}
|
||||
|
||||
override fun iterator() : java.util.Iterator<T> = MyIterator<T>(this)
|
||||
public override fun iterator() : java.util.Iterator<T> = MyIterator<T>(this)
|
||||
}
|
||||
|
||||
trait WriteOnlyArray<in T> : ISized {
|
||||
|
||||
@@ -18,12 +18,12 @@ class Z : Y() {
|
||||
|
||||
class MyIterable<T> : Iterable<T>
|
||||
{
|
||||
override fun iterator(): Iterator<T> = MyIterator()
|
||||
public override fun iterator(): Iterator<T> = MyIterator()
|
||||
|
||||
class MyIterator : Iterator<T>
|
||||
{
|
||||
override val hasNext: Boolean = false
|
||||
override fun next(): T {
|
||||
public override val hasNext: Boolean = false
|
||||
public override fun next(): T {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import java.util.Enumeration
|
||||
|
||||
inline fun <T> java.util.Enumeration<T>.iterator() = object: Iterator<T> {
|
||||
override val hasNext: Boolean
|
||||
public override val hasNext: Boolean
|
||||
get() = hasMoreElements()
|
||||
|
||||
override fun next() = nextElement()
|
||||
public override fun next() = nextElement()
|
||||
}
|
||||
|
||||
fun a(e : java.util.Enumeration<Int>) {
|
||||
|
||||
@@ -6,7 +6,7 @@ class Test() : Thread("Test") {
|
||||
|
||||
}
|
||||
}
|
||||
override fun run() {
|
||||
public override fun run() {
|
||||
init2() // unresolved
|
||||
Test.init2() // ok
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class Q {
|
||||
}
|
||||
}
|
||||
|
||||
//check that 'toString' can be invoked without specifying 'public' and ': String'
|
||||
//check that 'toString' can be invoked without specifying return type
|
||||
class NewClass : java.util.ArrayList<Integer>() {
|
||||
override fun toString() = "a"
|
||||
public override fun toString() = "a"
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ open class D {
|
||||
}
|
||||
|
||||
class E : D() {
|
||||
internal override fun self() = this
|
||||
internal <!NOTHING_TO_OVERRIDE!>override<!> fun self() = this
|
||||
|
||||
fun test() {
|
||||
val <!UNUSED_VARIABLE!>s<!> : E = self()
|
||||
@@ -31,11 +31,7 @@ open class F {
|
||||
}
|
||||
|
||||
class G : F() {
|
||||
override fun protected_fun() {}
|
||||
}
|
||||
|
||||
fun test_fun_stays_protected(g: G) {
|
||||
g.<!UNRESOLVED_REFERENCE!>protected_fun<!>()
|
||||
<!CANNOT_CHANGE_ACCESS_PRIVILEGE!>override<!> fun protected_fun() {}
|
||||
}
|
||||
|
||||
//------------
|
||||
@@ -61,11 +57,11 @@ trait T {
|
||||
}
|
||||
|
||||
open class L : T {
|
||||
override fun foo() {}
|
||||
<!CANNOT_WEAKEN_ACCESS_PRIVILEGE!>override<!> fun foo() {}
|
||||
}
|
||||
|
||||
class M : L() {
|
||||
<!CANNOT_WEAKEN_ACCESS_PRIVILEGE!>internal<!> override fun foo() {}
|
||||
internal override fun foo() {}
|
||||
}
|
||||
//---------------
|
||||
trait R {
|
||||
@@ -82,4 +78,4 @@ trait Q : R {
|
||||
|
||||
class S : P, Q {
|
||||
<!CANNOT_CHANGE_ACCESS_PRIVILEGE!>internal<!> override fun foo() {}
|
||||
}
|
||||
}
|
||||
@@ -4,23 +4,23 @@ import kotlin.test.Asserter
|
||||
import org.junit.Assert
|
||||
|
||||
class JUnitAsserter : Asserter {
|
||||
override fun assertEquals(message : String, expected : Any?, actual : Any?) {
|
||||
public override fun assertEquals(message : String, expected : Any?, actual : Any?) {
|
||||
Assert.assertEquals(message, expected, actual)
|
||||
}
|
||||
|
||||
override fun assertNotNull(message : String, actual : Any?) {
|
||||
public override fun assertNotNull(message : String, actual : Any?) {
|
||||
Assert.assertNotNull(message, actual)
|
||||
}
|
||||
|
||||
override fun assertNull(message : String, actual : Any?) {
|
||||
public override fun assertNull(message : String, actual : Any?) {
|
||||
Assert.assertNull(message, actual)
|
||||
}
|
||||
|
||||
override fun assertTrue(message : String, actual : Boolean) {
|
||||
public override fun assertTrue(message : String, actual : Boolean) {
|
||||
Assert.assertTrue(message, actual)
|
||||
}
|
||||
|
||||
override fun fail(message : String) {
|
||||
public override fun fail(message : String) {
|
||||
Assert.fail(message)
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public inline fun <T> java.util.Iterator<T>.iterator() : java.util.Iterator<T> =
|
||||
Helper to make java.util.Enumeration usable in for
|
||||
*/
|
||||
public fun <erased T> java.util.Enumeration<T>.iterator(): Iterator<T> = object: Iterator<T> {
|
||||
override val hasNext: Boolean
|
||||
public override val hasNext: Boolean
|
||||
get() = hasMoreElements()
|
||||
|
||||
public override fun next() : T = nextElement().sure()
|
||||
|
||||
@@ -35,15 +35,15 @@ abstract class FunctionalList<T>(public val size: Int) {
|
||||
return head
|
||||
}
|
||||
|
||||
override val hasNext: Boolean
|
||||
public override val hasNext: Boolean
|
||||
get() = !cur.empty
|
||||
}
|
||||
|
||||
class object {
|
||||
class Empty<T>() : FunctionalList<T>(0) {
|
||||
override val head: T
|
||||
public override val head: T
|
||||
get() = throw java.util.NoSuchElementException()
|
||||
override val tail: FunctionalList<T>
|
||||
public override val tail: FunctionalList<T>
|
||||
get() = throw java.util.NoSuchElementException()
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ fun Node.nextSiblings() : Iterator<Node> = NextSiblingIterator(this)
|
||||
|
||||
class NextSiblingIterator(var node: Node) : AbstractIterator<Node>() {
|
||||
|
||||
override fun computeNext(): Unit {
|
||||
protected override fun computeNext(): Unit {
|
||||
val next = node.getNextSibling()
|
||||
if (next != null) {
|
||||
setNext(next)
|
||||
@@ -215,7 +215,7 @@ fun Node.previousSiblings() : Iterator<Node> = PreviousSiblingIterator(this)
|
||||
|
||||
class PreviousSiblingIterator(var node: Node) : AbstractIterator<Node>() {
|
||||
|
||||
override fun computeNext(): Unit {
|
||||
protected override fun computeNext(): Unit {
|
||||
val next = node.getPreviousSibling()
|
||||
if (next != null) {
|
||||
setNext(next)
|
||||
@@ -323,7 +323,7 @@ fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
|
||||
}
|
||||
|
||||
class NodeListAsList(val nodeList: NodeList): AbstractList<Node>() {
|
||||
override fun get(index: Int): Node {
|
||||
public override fun get(index: Int): Node {
|
||||
val node = nodeList.item(index)
|
||||
if (node == null) {
|
||||
throw IndexOutOfBoundsException("NodeList does not contain a node at index: " + index)
|
||||
@@ -332,11 +332,11 @@ class NodeListAsList(val nodeList: NodeList): AbstractList<Node>() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun size(): Int = nodeList.getLength()
|
||||
public override fun size(): Int = nodeList.getLength()
|
||||
}
|
||||
|
||||
class ElementListAsList(val nodeList: NodeList): AbstractList<Element>() {
|
||||
override fun get(index: Int): Element {
|
||||
public override fun get(index: Int): Element {
|
||||
val node = nodeList.item(index)
|
||||
if (node is Element) {
|
||||
return node
|
||||
@@ -349,7 +349,7 @@ class ElementListAsList(val nodeList: NodeList): AbstractList<Element>() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun size(): Int = nodeList.getLength()
|
||||
public override fun size(): Int = nodeList.getLength()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ public inline fun <T: Closeable, R> T.use(block: (T)-> R) : R {
|
||||
/** Returns an [Iterator] of bytes over an input stream */
|
||||
public fun InputStream.iterator() : ByteIterator =
|
||||
object: ByteIterator() {
|
||||
override val hasNext : Boolean
|
||||
public override val hasNext : Boolean
|
||||
get() = available() > 0
|
||||
|
||||
public override fun nextByte() : Byte = read().toByte()
|
||||
@@ -236,7 +236,7 @@ class LineIterator(val reader: BufferedReader) : Iterator<String> {
|
||||
private var nextValue: String? = null
|
||||
private var done = false
|
||||
|
||||
override val hasNext: Boolean
|
||||
public override val hasNext: Boolean
|
||||
get() {
|
||||
if (nextValue == null && !done) {
|
||||
nextValue = reader.readLine()
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class AbstractIterator<T>: java.util.Iterator<T> {
|
||||
private var state: State = State.NotReady
|
||||
private var next: T? = null
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
public override fun hasNext(): Boolean {
|
||||
require(state != State.Failed)
|
||||
return when (state) {
|
||||
State.Done -> false
|
||||
@@ -26,13 +26,13 @@ public abstract class AbstractIterator<T>: java.util.Iterator<T> {
|
||||
}
|
||||
}
|
||||
|
||||
override fun next(): T {
|
||||
public override fun next(): T {
|
||||
if (!hasNext()) throw NoSuchElementException()
|
||||
state = State.NotReady
|
||||
return next.sure()
|
||||
}
|
||||
|
||||
override fun remove() {
|
||||
public override fun remove() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
|
||||
@@ -406,7 +406,7 @@ class CollectionTest {
|
||||
class IterableWrapper<T>(collection : java.lang.Iterable<T>) : java.lang.Iterable<T> {
|
||||
private val collection = collection
|
||||
|
||||
override fun iterator(): java.util.Iterator<T> {
|
||||
public override fun iterator(): java.util.Iterator<T> {
|
||||
return collection.iterator().sure()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,10 @@ class CompareTest {
|
||||
|
||||
Test fun sortUsingCustomComparator() {
|
||||
val c = object : Comparator<Item>{
|
||||
override fun compare(o1: Item?, o2: Item?): Int {
|
||||
public override fun compare(o1: Item?, o2: Item?): Int {
|
||||
return compareBy(o1, o2, {(it: Item) -> it.name}, {(it: Item) -> it.rating})
|
||||
}
|
||||
override fun equals(obj: Any?): Boolean {
|
||||
public override fun equals(obj: Any?): Boolean {
|
||||
return this == obj
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ class TestBuilt<T>(name: String, val builder: TestBuilder<T>, val test: TestBuil
|
||||
get() = myState.sure()
|
||||
set(newState: T) { myState = newState }
|
||||
|
||||
override fun countTestCases(): Int = 1
|
||||
public override fun countTestCases(): Int = 1
|
||||
|
||||
override fun setUp() = this.(builder.setUp)()
|
||||
protected override fun setUp() = this.(builder.setUp)()
|
||||
|
||||
override fun tearDown() = this.(builder.tearDown)()
|
||||
protected override fun tearDown() = this.(builder.tearDown)()
|
||||
|
||||
override fun runTest() = this.(test)()
|
||||
protected override fun runTest() = this.(test)()
|
||||
}
|
||||
|
||||
open class TestBuilder<T>(name: String) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import junit.framework.TestCase
|
||||
import junit.framework.Assert
|
||||
|
||||
class Serial(val a : String) : java.lang.Object(), Serializable {
|
||||
override fun toString() = a
|
||||
public override fun toString() = a
|
||||
}
|
||||
|
||||
class SerialTest() : TestCase() {
|
||||
|
||||
@@ -28,7 +28,7 @@ class Customer() : ChangeSupport() {
|
||||
class MyChangeListener() : ChangeListener {
|
||||
val events = ArrayList<ChangeEvent>()
|
||||
|
||||
override fun onPropertyChange(event: ChangeEvent): Unit {
|
||||
public override fun onPropertyChange(event: ChangeEvent): Unit {
|
||||
println("Property changed: $event")
|
||||
events.add(event)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user