'isVisible' strategy added to Visibility interface
This commit is contained in:
@@ -139,7 +139,7 @@ public abstract class CodegenContext {
|
|||||||
public ConstructorContext intoConstructor(ConstructorDescriptor descriptor, JetTypeMapper typeMapper) {
|
public ConstructorContext intoConstructor(ConstructorDescriptor descriptor, JetTypeMapper typeMapper) {
|
||||||
if(descriptor == null) {
|
if(descriptor == null) {
|
||||||
descriptor = new ConstructorDescriptorImpl(getThisDescriptor(), Collections.<AnnotationDescriptor>emptyList(), true)
|
descriptor = new ConstructorDescriptorImpl(getThisDescriptor(), Collections.<AnnotationDescriptor>emptyList(), true)
|
||||||
.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(), Visibility.PUBLIC);
|
.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(), Visibilities.PUBLIC);
|
||||||
}
|
}
|
||||||
return new ConstructorContext(descriptor, getContextKind(), this, typeMapper);
|
return new ConstructorContext(descriptor, getContextKind(), this, typeMapper);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class CodegenUtil {
|
|||||||
fd.getValueParameters(),
|
fd.getValueParameters(),
|
||||||
fd.getReturnType(),
|
fd.getReturnType(),
|
||||||
Modality.FINAL,
|
Modality.FINAL,
|
||||||
Visibility.PUBLIC,
|
Visibilities.PUBLIC,
|
||||||
/*isInline = */false
|
/*isInline = */false
|
||||||
);
|
);
|
||||||
return invokeDescriptor;
|
return invokeDescriptor;
|
||||||
|
|||||||
@@ -1020,7 +1020,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
final boolean directToField = expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER && contextKind() != OwnerKind.TRAIT_IMPL ;
|
final boolean directToField = expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER && contextKind() != OwnerKind.TRAIT_IMPL ;
|
||||||
JetExpression r = getReceiverForSelector(expression);
|
JetExpression r = getReceiverForSelector(expression);
|
||||||
final boolean isSuper = r instanceof JetSuperExpression;
|
final boolean isSuper = r instanceof JetSuperExpression;
|
||||||
if(propertyDescriptor.getVisibility() == Visibility.PRIVATE && !CodegenUtil.isClassObject(propertyDescriptor.getContainingDeclaration())) {
|
if(propertyDescriptor.getVisibility() == Visibilities.PRIVATE && !CodegenUtil.isClassObject(propertyDescriptor.getContainingDeclaration())) {
|
||||||
if(context.getClassOrNamespaceDescriptor() != propertyDescriptor.getContainingDeclaration()) {
|
if(context.getClassOrNamespaceDescriptor() != propertyDescriptor.getContainingDeclaration()) {
|
||||||
DeclarationDescriptor enclosed = propertyDescriptor.getContainingDeclaration();
|
DeclarationDescriptor enclosed = propertyDescriptor.getContainingDeclaration();
|
||||||
if(enclosed != null && enclosed != context.getThisDescriptor()) {
|
if(enclosed != null && enclosed != context.getThisDescriptor()) {
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
|
|
||||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
if(original.getVisibility() == Visibility.PRIVATE)
|
if(original.getVisibility() == Visibilities.PRIVATE)
|
||||||
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getReturnType().getDescriptor());
|
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getReturnType().getDescriptor());
|
||||||
else
|
else
|
||||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor());
|
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor());
|
||||||
@@ -349,7 +349,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
//noinspection AssignmentToForLoopParameter
|
//noinspection AssignmentToForLoopParameter
|
||||||
reg += argType.getSize();
|
reg += argType.getSize();
|
||||||
}
|
}
|
||||||
if(original.getVisibility() == Visibility.PRIVATE && original.getModality() == Modality.FINAL)
|
if(original.getVisibility() == Visibilities.PRIVATE && original.getModality() == Modality.FINAL)
|
||||||
iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getArgumentTypes()[0].getDescriptor());
|
iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getArgumentTypes()[0].getDescriptor());
|
||||||
else
|
else
|
||||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor());
|
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor());
|
||||||
|
|||||||
@@ -757,13 +757,13 @@ public class JetTypeMapper {
|
|||||||
if(CodegenUtil.isInterface(declaration)) {
|
if(CodegenUtil.isInterface(declaration)) {
|
||||||
return ACC_PUBLIC;
|
return ACC_PUBLIC;
|
||||||
}
|
}
|
||||||
if (p.getVisibility() == Visibility.PUBLIC) {
|
if (p.getVisibility() == Visibilities.PUBLIC) {
|
||||||
return ACC_PUBLIC;
|
return ACC_PUBLIC;
|
||||||
}
|
}
|
||||||
else if (p.getVisibility() == Visibility.PROTECTED) {
|
else if (p.getVisibility() == Visibilities.PROTECTED) {
|
||||||
return ACC_PROTECTED;
|
return ACC_PROTECTED;
|
||||||
}
|
}
|
||||||
else if (p.getVisibility() == Visibility.PRIVATE) {
|
else if (p.getVisibility() == Visibilities.PRIVATE) {
|
||||||
if(CodegenUtil.isClassObject(declaration)) {
|
if(CodegenUtil.isClassObject(declaration)) {
|
||||||
return defaultFlags;
|
return defaultFlags;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class PropertyCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isExternallyAccessible(PropertyDescriptor p) {
|
private static boolean isExternallyAccessible(PropertyDescriptor p) {
|
||||||
return p.getVisibility() != Visibility.PRIVATE || CodegenUtil.isClassObject(p.getContainingDeclaration());
|
return p.getVisibility() != Visibilities.PRIVATE || CodegenUtil.isClassObject(p.getContainingDeclaration());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateSetter(JetProperty p, PropertyDescriptor propertyDescriptor) {
|
private void generateSetter(JetProperty p, PropertyDescriptor propertyDescriptor) {
|
||||||
|
|||||||
+6
-6
@@ -453,7 +453,7 @@ public class JavaDescriptorResolver {
|
|||||||
// TODO: wrong: class objects do not need visible constructors
|
// TODO: wrong: class objects do not need visible constructors
|
||||||
ConstructorDescriptorImpl constructor = new ConstructorDescriptorImpl(classData.classDescriptor, new ArrayList<AnnotationDescriptor>(0), true);
|
ConstructorDescriptorImpl constructor = new ConstructorDescriptorImpl(classData.classDescriptor, new ArrayList<AnnotationDescriptor>(0), true);
|
||||||
constructor.setReturnType(classData.classDescriptor.getDefaultType());
|
constructor.setReturnType(classData.classDescriptor.getDefaultType());
|
||||||
constructor.initialize(new ArrayList<TypeParameterDescriptor>(0), new ArrayList<ValueParameterDescriptor>(0), Visibility.PUBLIC);
|
constructor.initialize(new ArrayList<TypeParameterDescriptor>(0), new ArrayList<ValueParameterDescriptor>(0), Visibilities.PUBLIC);
|
||||||
|
|
||||||
classData.classDescriptor.addConstructor(constructor, null);
|
classData.classDescriptor.addConstructor(constructor, null);
|
||||||
return classData.classDescriptor;
|
return classData.classDescriptor;
|
||||||
@@ -1158,10 +1158,10 @@ public class JavaDescriptorResolver {
|
|||||||
PropertyGetterDescriptor getterDescriptor = null;
|
PropertyGetterDescriptor getterDescriptor = null;
|
||||||
PropertySetterDescriptor setterDescriptor = null;
|
PropertySetterDescriptor setterDescriptor = null;
|
||||||
if (members.getter != null) {
|
if (members.getter != null) {
|
||||||
getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, resolveAnnotations(members.getter.getMember().psiMember), Modality.OPEN, Visibility.PUBLIC, true, false, CallableMemberDescriptor.Kind.DECLARATION);
|
getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, resolveAnnotations(members.getter.getMember().psiMember), Modality.OPEN, Visibilities.PUBLIC, true, false, CallableMemberDescriptor.Kind.DECLARATION);
|
||||||
}
|
}
|
||||||
if (members.setter != null) {
|
if (members.setter != null) {
|
||||||
setterDescriptor = new PropertySetterDescriptor(propertyDescriptor, resolveAnnotations(members.setter.getMember().psiMember), Modality.OPEN, Visibility.PUBLIC, true, false, CallableMemberDescriptor.Kind.DECLARATION);
|
setterDescriptor = new PropertySetterDescriptor(propertyDescriptor, resolveAnnotations(members.setter.getMember().psiMember), Modality.OPEN, Visibilities.PUBLIC, true, false, CallableMemberDescriptor.Kind.DECLARATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
propertyDescriptor.initialize(getterDescriptor, setterDescriptor);
|
propertyDescriptor.initialize(getterDescriptor, setterDescriptor);
|
||||||
@@ -1625,9 +1625,9 @@ public class JavaDescriptorResolver {
|
|||||||
|
|
||||||
private static Visibility resolveVisibilityFromPsiModifiers(PsiModifierListOwner modifierListOwner) {
|
private static Visibility resolveVisibilityFromPsiModifiers(PsiModifierListOwner modifierListOwner) {
|
||||||
//TODO report error
|
//TODO report error
|
||||||
return modifierListOwner.hasModifierProperty(PsiModifier.PUBLIC) ? Visibility.PUBLIC :
|
return modifierListOwner.hasModifierProperty(PsiModifier.PUBLIC) ? Visibilities.PUBLIC :
|
||||||
(modifierListOwner.hasModifierProperty(PsiModifier.PRIVATE) ? Visibility.PRIVATE :
|
(modifierListOwner.hasModifierProperty(PsiModifier.PRIVATE) ? Visibilities.PRIVATE :
|
||||||
(modifierListOwner.hasModifierProperty(PsiModifier.PROTECTED) ? Visibility.PROTECTED : Visibility.INTERNAL));
|
(modifierListOwner.hasModifierProperty(PsiModifier.PROTECTED) ? Visibilities.PROTECTED : Visibilities.PUBLIC));//todo
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ClassDescriptor> resolveInnerClasses(DeclarationDescriptor owner, PsiClass psiClass, boolean staticMembers) {
|
public List<ClassDescriptor> resolveInnerClasses(DeclarationDescriptor owner, PsiClass psiClass, boolean staticMembers) {
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.types.JetType;
|
|||||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Visibility getVisibility() {
|
public Visibility getVisibility() {
|
||||||
return Visibility.PUBLIC;
|
return Visibilities.PUBLIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
-3
@@ -17,12 +17,9 @@
|
|||||||
package org.jetbrains.jet.lang.descriptors;
|
package org.jetbrains.jet.lang.descriptors;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
|
||||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
+1
-1
@@ -126,7 +126,7 @@ public class FunctionDescriptorUtil {
|
|||||||
Collections.<TypeParameterDescriptor>emptyList(),
|
Collections.<TypeParameterDescriptor>emptyList(),
|
||||||
JetStandardClasses.getValueParameters(functionDescriptor, functionType),
|
JetStandardClasses.getValueParameters(functionDescriptor, functionType),
|
||||||
JetStandardClasses.getReturnTypeFromFunctionType(functionType),
|
JetStandardClasses.getReturnTypeFromFunctionType(functionType),
|
||||||
Modality.FINAL, Visibility.LOCAL);
|
Modality.FINAL, Visibilities.LOCAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D extends CallableDescriptor> D alphaConvertTypeParameters(D candidate) {
|
public static <D extends CallableDescriptor> D alphaConvertTypeParameters(D candidate) {
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* 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.descriptors;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author svtk
|
||||||
|
*/
|
||||||
|
public class Visibilities {
|
||||||
|
public static final Visibility PRIVATE = new Visibility(false) {
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(DeclarationDescriptorWithVisibility what, DeclarationDescriptor from) {
|
||||||
|
DeclarationDescriptor parent = what;
|
||||||
|
while (parent != null) {
|
||||||
|
parent = parent.getContainingDeclaration();
|
||||||
|
if ((parent instanceof ClassDescriptor && ((ClassDescriptor)parent).getKind() != ClassKind.OBJECT) ||
|
||||||
|
parent instanceof NamespaceDescriptor) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DeclarationDescriptor fromParent = from;
|
||||||
|
while (fromParent != null) {
|
||||||
|
if (parent == fromParent) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
fromParent = fromParent.getContainingDeclaration();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Visibility PROTECTED = new Visibility(true) {
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(DeclarationDescriptorWithVisibility what, DeclarationDescriptor from) {
|
||||||
|
ClassDescriptor classDescriptor = DescriptorUtils.getParentOfType(what, ClassDescriptor.class);
|
||||||
|
if (classDescriptor == null) return false;
|
||||||
|
|
||||||
|
ClassDescriptor fromClass = DescriptorUtils.getParentOfType(from, ClassDescriptor.class);
|
||||||
|
if (fromClass == null) return false;
|
||||||
|
if (DescriptorUtils.isSubclass(fromClass, classDescriptor)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Visibility INTERNAL = new Visibility(false) {
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(DeclarationDescriptorWithVisibility what, DeclarationDescriptor from) {
|
||||||
|
ModuleDescriptor parentModule = DescriptorUtils.getParentOfType(what, ModuleDescriptor.class, false);
|
||||||
|
ModuleDescriptor fromModule = DescriptorUtils.getParentOfType(from, ModuleDescriptor.class, false);
|
||||||
|
return parentModule == fromModule;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Visibility PUBLIC = new Visibility(true) {
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(DeclarationDescriptorWithVisibility what, DeclarationDescriptor from) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Visibility INTERNAL_PROTECTED = new Visibility(false) {
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(DeclarationDescriptorWithVisibility what, DeclarationDescriptor from) {
|
||||||
|
return PROTECTED.isVisible(what, from) && INTERNAL.isVisible(what, from);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Visibility LOCAL = new Visibility(false) {
|
||||||
|
@Override
|
||||||
|
public boolean isVisible(DeclarationDescriptorWithVisibility what, DeclarationDescriptor from) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Set<Visibility> INTERNAL_VISIBILITIES = Sets.newHashSet(PRIVATE, INTERNAL, INTERNAL_PROTECTED, LOCAL);
|
||||||
|
}
|
||||||
@@ -16,28 +16,19 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.descriptors;
|
package org.jetbrains.jet.lang.descriptors;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public enum Visibility {
|
public abstract class Visibility {
|
||||||
PRIVATE(false),
|
private final boolean isPublicAPI;
|
||||||
PROTECTED(true),
|
|
||||||
INTERNAL(false),
|
|
||||||
PUBLIC(true),
|
|
||||||
INTERNAL_PROTECTED(false),
|
|
||||||
LOCAL(false);
|
|
||||||
|
|
||||||
public static final EnumSet<Visibility> INTERNAL_VISIBILITIES = EnumSet.of(PRIVATE, INTERNAL, INTERNAL_PROTECTED, LOCAL);
|
protected Visibility(boolean api) {
|
||||||
|
isPublicAPI = api;
|
||||||
private final boolean isAPI;
|
|
||||||
|
|
||||||
private Visibility(boolean visibleOutside) {
|
|
||||||
isAPI = visibleOutside;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAPI() {
|
public boolean isPublicAPI() {
|
||||||
return isAPI;
|
return isPublicAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract boolean isVisible(DeclarationDescriptorWithVisibility what, DeclarationDescriptor from);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,8 +216,7 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean hasBody = function.getBodyExpression() != null;
|
boolean hasBody = function.getBodyExpression() != null;
|
||||||
Modality defaultModality = getDefaultModality(containingDescriptor, hasBody);
|
Modality modality = resolveModalityFromModifiers(function.getModifierList(), getDefaultModality(containingDescriptor, hasBody));
|
||||||
Modality modality = resolveModalityFromModifiers(function.getModifierList(), defaultModality);
|
|
||||||
Visibility visibility = resolveVisibilityFromModifiers(function.getModifierList());
|
Visibility visibility = resolveVisibilityFromModifiers(function.getModifierList());
|
||||||
JetModifierList modifierList = function.getModifierList();
|
JetModifierList modifierList = function.getModifierList();
|
||||||
boolean isInline = (modifierList != null) && modifierList.hasModifier(JetTokens.INLINE_KEYWORD);
|
boolean isInline = (modifierList != null) && modifierList.hasModifier(JetTokens.INLINE_KEYWORD);
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ public class TypeHierarchyResolver {
|
|||||||
private void createPrimaryConstructorForObject(@Nullable JetDeclaration object, MutableClassDescriptor mutableClassDescriptor) {
|
private void createPrimaryConstructorForObject(@Nullable JetDeclaration object, MutableClassDescriptor mutableClassDescriptor) {
|
||||||
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(mutableClassDescriptor, Collections.<AnnotationDescriptor>emptyList(), true);
|
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(mutableClassDescriptor, Collections.<AnnotationDescriptor>emptyList(), true);
|
||||||
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(),
|
||||||
Visibility.INTERNAL);//TODO check set mutableClassDescriptor.getVisibility()
|
Visibilities.INTERNAL);//TODO check set mutableClassDescriptor.getVisibility()
|
||||||
// TODO : make the constructor private?
|
// TODO : make the constructor private?
|
||||||
mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor, trace);
|
mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor, trace);
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
|||||||
@@ -89,140 +89,140 @@ public class ResolutionTask<D extends CallableDescriptor> extends ResolutionCont
|
|||||||
public interface DescriptorCheckStrategy {
|
public interface DescriptorCheckStrategy {
|
||||||
<D extends CallableDescriptor> boolean performAdvancedChecks(D descriptor, BindingTrace trace, TracingStrategy tracing);
|
<D extends CallableDescriptor> boolean performAdvancedChecks(D descriptor, BindingTrace trace, TracingStrategy tracing);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final TracingStrategy tracing = new TracingStrategy() {
|
public final TracingStrategy tracing = new TracingStrategy() {
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void bindReference(@NotNull BindingTrace trace, @NotNull ResolvedCallImpl<D> resolvedCall) {
|
public <D extends CallableDescriptor> void bindReference(@NotNull BindingTrace trace, @NotNull ResolvedCallImpl<D> resolvedCall) {
|
||||||
D descriptor = resolvedCall.getCandidateDescriptor();
|
D descriptor = resolvedCall.getCandidateDescriptor();
|
||||||
// if (descriptor instanceof VariableAsFunctionDescriptor) {
|
// if (descriptor instanceof VariableAsFunctionDescriptor) {
|
||||||
// VariableAsFunctionDescriptor variableAsFunctionDescriptor = (VariableAsFunctionDescriptor) descriptor;
|
// VariableAsFunctionDescriptor variableAsFunctionDescriptor = (VariableAsFunctionDescriptor) descriptor;
|
||||||
// trace.record(REFERENCE_TARGET, reference, variableAsFunctionDescriptor.getVariableDescriptor());
|
// trace.record(REFERENCE_TARGET, reference, variableAsFunctionDescriptor.getVariableDescriptor());
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
// }
|
// }
|
||||||
trace.record(RESOLVED_CALL, call.getCalleeExpression(), resolvedCall);
|
trace.record(RESOLVED_CALL, call.getCalleeExpression(), resolvedCall);
|
||||||
trace.record(REFERENCE_TARGET, reference, descriptor);
|
trace.record(REFERENCE_TARGET, reference, descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void recordAmbiguity(BindingTrace trace, Collection<ResolvedCallImpl<D>> candidates) {
|
public <D extends CallableDescriptor> void recordAmbiguity(BindingTrace trace, Collection<ResolvedCallImpl<D>> candidates) {
|
||||||
Collection<D> descriptors = Sets.newHashSet();
|
Collection<D> descriptors = Sets.newHashSet();
|
||||||
for (ResolvedCallImpl<D> candidate : candidates) {
|
for (ResolvedCallImpl<D> candidate : candidates) {
|
||||||
descriptors.add(candidate.getCandidateDescriptor());
|
descriptors.add(candidate.getCandidateDescriptor());
|
||||||
}
|
}
|
||||||
trace.record(AMBIGUOUS_REFERENCE_TARGET, reference, descriptors);
|
trace.record(AMBIGUOUS_REFERENCE_TARGET, reference, descriptors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unresolvedReference(@NotNull BindingTrace trace) {
|
public void unresolvedReference(@NotNull BindingTrace trace) {
|
||||||
trace.report(UNRESOLVED_REFERENCE.on(reference));
|
trace.report(UNRESOLVED_REFERENCE.on(reference));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noValueForParameter(@NotNull BindingTrace trace, @NotNull ValueParameterDescriptor valueParameter) {
|
public void noValueForParameter(@NotNull BindingTrace trace, @NotNull ValueParameterDescriptor valueParameter) {
|
||||||
PsiElement reportOn;
|
PsiElement reportOn;
|
||||||
JetValueArgumentList valueArgumentList = call.getValueArgumentList();
|
JetValueArgumentList valueArgumentList = call.getValueArgumentList();
|
||||||
if (valueArgumentList != null) {
|
if (valueArgumentList != null) {
|
||||||
reportOn = valueArgumentList;
|
reportOn = valueArgumentList;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reportOn = reference;
|
reportOn = reference;
|
||||||
}
|
}
|
||||||
trace.report(NO_VALUE_FOR_PARAMETER.on(reportOn, valueParameter));
|
trace.report(NO_VALUE_FOR_PARAMETER.on(reportOn, valueParameter));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void missingReceiver(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor expectedReceiver) {
|
public void missingReceiver(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor expectedReceiver) {
|
||||||
trace.report(MISSING_RECEIVER.on(reference, expectedReceiver.getType()));
|
trace.report(MISSING_RECEIVER.on(reference, expectedReceiver.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void wrongReceiverType(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor receiverParameter, @NotNull ReceiverDescriptor receiverArgument) {
|
public void wrongReceiverType(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor receiverParameter, @NotNull ReceiverDescriptor receiverArgument) {
|
||||||
if (receiverArgument instanceof ExpressionReceiver) {
|
if (receiverArgument instanceof ExpressionReceiver) {
|
||||||
ExpressionReceiver expressionReceiver = (ExpressionReceiver) receiverArgument;
|
ExpressionReceiver expressionReceiver = (ExpressionReceiver)receiverArgument;
|
||||||
trace.report(TYPE_MISMATCH.on(expressionReceiver.getExpression(), receiverParameter.getType(), receiverArgument.getType()));
|
trace.report(TYPE_MISMATCH.on(expressionReceiver.getExpression(), receiverParameter.getType(), receiverArgument.getType()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
trace.report(TYPE_MISMATCH.on(reference, receiverParameter.getType(), receiverArgument.getType()));
|
trace.report(TYPE_MISMATCH.on(reference, receiverParameter.getType(), receiverArgument.getType()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void noReceiverAllowed(@NotNull BindingTrace trace) {
|
||||||
|
trace.report(NO_RECEIVER_ADMITTED.on(reference));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) {
|
||||||
|
JetTypeArgumentList typeArgumentList = call.getTypeArgumentList();
|
||||||
|
if (typeArgumentList != null) {
|
||||||
|
trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(typeArgumentList, expectedTypeArgumentCount));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(reference, expectedTypeArgumentCount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <D extends CallableDescriptor> void ambiguity(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors) {
|
||||||
|
trace.report(OVERLOAD_RESOLUTION_AMBIGUITY.on(call.getCallElement(), descriptors));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <D extends CallableDescriptor> void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors) {
|
||||||
|
trace.report(NONE_APPLICABLE.on(reference, descriptors));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void instantiationOfAbstractClass(@NotNull BindingTrace trace) {
|
||||||
|
trace.report(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS.on(call.getCallElement()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void typeInferenceFailed(@NotNull BindingTrace trace, SolutionStatus status) {
|
||||||
|
assert !status.isSuccessful();
|
||||||
|
trace.report(TYPE_INFERENCE_FAILED.on(call.getCallElement(), status));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unsafeCall(@NotNull BindingTrace trace, @NotNull JetType type) {
|
||||||
|
ASTNode callOperationNode = call.getCallOperationNode();
|
||||||
|
if (callOperationNode != null) {
|
||||||
|
trace.report(UNSAFE_CALL.on(callOperationNode.getPsi(), type));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PsiElement callElement = call.getCallElement();
|
||||||
|
if (callElement instanceof JetBinaryExpression) {
|
||||||
|
JetBinaryExpression binaryExpression = (JetBinaryExpression)callElement;
|
||||||
|
JetSimpleNameExpression operationReference = binaryExpression.getOperationReference();
|
||||||
|
|
||||||
|
String operationString = operationReference.getReferencedNameElementType() == JetTokens.IDENTIFIER ?
|
||||||
|
operationReference.getText() :
|
||||||
|
OperatorConventions.getNameForOperationSymbol((JetToken)operationReference.getReferencedNameElementType());
|
||||||
|
|
||||||
|
JetExpression right = binaryExpression.getRight();
|
||||||
|
if (right != null) {
|
||||||
|
trace.report(UNSAFE_INFIX_CALL.on(reference, binaryExpression.getLeft().getText(), operationString, right.getText()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
@Override
|
trace.report(UNSAFE_CALL.on(reference, type));
|
||||||
public void noReceiverAllowed(@NotNull BindingTrace trace) {
|
|
||||||
trace.report(NO_RECEIVER_ADMITTED.on(reference));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) {
|
|
||||||
JetTypeArgumentList typeArgumentList = call.getTypeArgumentList();
|
@Override
|
||||||
if (typeArgumentList != null) {
|
public void unnecessarySafeCall(@NotNull BindingTrace trace, @NotNull JetType type) {
|
||||||
trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(typeArgumentList, expectedTypeArgumentCount));
|
ASTNode callOperationNode = call.getCallOperationNode();
|
||||||
}
|
assert callOperationNode != null;
|
||||||
else {
|
trace.report(UNNECESSARY_SAFE_CALL.on(callOperationNode.getPsi(), type));
|
||||||
trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(reference, expectedTypeArgumentCount));
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
|
public void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List<JetExpression> functionLiteralArguments) {
|
||||||
@Override
|
for (JetExpression functionLiteralArgument : functionLiteralArguments) {
|
||||||
public <D extends CallableDescriptor> void ambiguity(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors) {
|
trace.report(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED.on(functionLiteralArgument));
|
||||||
trace.report(OVERLOAD_RESOLUTION_AMBIGUITY.on(call.getCallElement(), descriptors));
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
@Override
|
|
||||||
public <D extends CallableDescriptor> void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors) {
|
|
||||||
trace.report(NONE_APPLICABLE.on(reference, descriptors));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void instantiationOfAbstractClass(@NotNull BindingTrace trace) {
|
|
||||||
trace.report(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS.on(call.getCallElement()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void typeInferenceFailed(@NotNull BindingTrace trace, SolutionStatus status) {
|
|
||||||
assert !status.isSuccessful();
|
|
||||||
trace.report(TYPE_INFERENCE_FAILED.on(call.getCallElement(), status));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unsafeCall(@NotNull BindingTrace trace, @NotNull JetType type) {
|
|
||||||
ASTNode callOperationNode = call.getCallOperationNode();
|
|
||||||
if (callOperationNode != null) {
|
|
||||||
trace.report(UNSAFE_CALL.on(callOperationNode.getPsi(), type));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
PsiElement callElement = call.getCallElement();
|
|
||||||
if (callElement instanceof JetBinaryExpression) {
|
|
||||||
JetBinaryExpression binaryExpression = (JetBinaryExpression) callElement;
|
|
||||||
JetSimpleNameExpression operationReference = binaryExpression.getOperationReference();
|
|
||||||
|
|
||||||
String operationString = operationReference.getReferencedNameElementType() == JetTokens.IDENTIFIER ?
|
|
||||||
operationReference.getText() :
|
|
||||||
OperatorConventions.getNameForOperationSymbol((JetToken) operationReference.getReferencedNameElementType());
|
|
||||||
|
|
||||||
JetExpression right = binaryExpression.getRight();
|
|
||||||
if (right != null) {
|
|
||||||
trace.report(UNSAFE_INFIX_CALL.on(reference, binaryExpression.getLeft().getText(), operationString, right.getText()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
trace.report(UNSAFE_CALL.on(reference, type));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unnecessarySafeCall(@NotNull BindingTrace trace, @NotNull JetType type) {
|
|
||||||
ASTNode callOperationNode = call.getCallOperationNode();
|
|
||||||
assert callOperationNode != null;
|
|
||||||
trace.report(UNNECESSARY_SAFE_CALL.on(callOperationNode.getPsi(), type));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List<JetExpression> functionLiteralArguments) {
|
|
||||||
for (JetExpression functionLiteralArgument : functionLiteralArguments) {
|
|
||||||
trace.report(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED.on(functionLiteralArgument));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -142,7 +142,7 @@ public class DataFlowValueFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInternal(@NotNull DeclarationDescriptorWithVisibility descriptor) {
|
private static boolean isInternal(@NotNull DeclarationDescriptorWithVisibility descriptor) {
|
||||||
if (Visibility.INTERNAL_VISIBILITIES.contains(descriptor.getVisibility())) return true;
|
if (Visibilities.INTERNAL_VISIBILITIES.contains(descriptor.getVisibility())) return true;
|
||||||
|
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
if (!(containingDeclaration instanceof DeclarationDescriptorWithVisibility)) {
|
if (!(containingDeclaration instanceof DeclarationDescriptorWithVisibility)) {
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class ErrorUtils {
|
|||||||
ERROR_CLASS,
|
ERROR_CLASS,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
Modality.OPEN,
|
Modality.OPEN,
|
||||||
Visibility.INTERNAL,
|
Visibilities.INTERNAL,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
@@ -172,7 +172,7 @@ public class ErrorUtils {
|
|||||||
Collections.<ValueParameterDescriptor>emptyList(), // TODO
|
Collections.<ValueParameterDescriptor>emptyList(), // TODO
|
||||||
createErrorType("<ERROR FUNCTION RETURN TYPE>"),
|
createErrorType("<ERROR FUNCTION RETURN TYPE>"),
|
||||||
Modality.OPEN,
|
Modality.OPEN,
|
||||||
Visibility.INTERNAL,
|
Visibilities.INTERNAL,
|
||||||
/*isInline = */ false
|
/*isInline = */ false
|
||||||
);
|
);
|
||||||
return function;
|
return function;
|
||||||
@@ -183,7 +183,7 @@ public class ErrorUtils {
|
|||||||
r.initialize(
|
r.initialize(
|
||||||
Collections.<TypeParameterDescriptor>emptyList(), // TODO
|
Collections.<TypeParameterDescriptor>emptyList(), // TODO
|
||||||
Collections.<ValueParameterDescriptor>emptyList(), // TODO
|
Collections.<ValueParameterDescriptor>emptyList(), // TODO
|
||||||
Visibility.INTERNAL
|
Visibilities.INTERNAL
|
||||||
);
|
);
|
||||||
r.setReturnType(createErrorType("<ERROR RETURN TYPE>"));
|
r.setReturnType(createErrorType("<ERROR RETURN TYPE>"));
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
+1
-1
@@ -151,7 +151,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
valueParameterDescriptors,
|
valueParameterDescriptors,
|
||||||
/*unsubstitutedReturnType = */ null,
|
/*unsubstitutedReturnType = */ null,
|
||||||
Modality.FINAL,
|
Modality.FINAL,
|
||||||
Visibility.LOCAL,
|
Visibilities.LOCAL,
|
||||||
/*isInline = */ false
|
/*isInline = */ false
|
||||||
);
|
);
|
||||||
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor);
|
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor);
|
||||||
|
|||||||
@@ -155,9 +155,9 @@ public class JetStandardClasses {
|
|||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
true, Variance.OUT_VARIANCE, "T" + (j + 1), j);
|
true, Variance.OUT_VARIANCE, "T" + (j + 1), j);
|
||||||
parameters.add(typeParameterDescriptor);
|
parameters.add(typeParameterDescriptor);
|
||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibility.PUBLIC, false, false, "_" + (j + 1), CallableMemberDescriptor.Kind.DECLARATION);
|
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);
|
propertyDescriptor.setType(typeParameterDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), classDescriptor.getImplicitReceiver(), ReceiverDescriptor.NO_RECEIVER);
|
||||||
PropertyGetterDescriptor getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibility.PUBLIC, false, true, CallableMemberDescriptor.Kind.DECLARATION);
|
PropertyGetterDescriptor getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, true, CallableMemberDescriptor.Kind.DECLARATION);
|
||||||
getterDescriptor.initialize(typeParameterDescriptor.getDefaultType());
|
getterDescriptor.initialize(typeParameterDescriptor.getDefaultType());
|
||||||
propertyDescriptor.initialize(getterDescriptor, null);
|
propertyDescriptor.initialize(getterDescriptor, null);
|
||||||
writableScope.addPropertyDescriptor(propertyDescriptor);
|
writableScope.addPropertyDescriptor(propertyDescriptor);
|
||||||
|
|||||||
Reference in New Issue
Block a user