Refactor: Remove context parameter from BindingContextUtils.descriptorToDeclaration utilities family

This commit is contained in:
Pavel V. Talanov
2014-07-08 18:17:04 +04:00
parent 723b3d75c9
commit d988256831
87 changed files with 225 additions and 310 deletions
@@ -105,7 +105,7 @@ public abstract class AnnotationCodegen {
psiElement = null;
}
else {
psiElement = descriptorToDeclaration(bindingContext, (DeclarationDescriptor) annotated);
psiElement = descriptorToDeclaration((DeclarationDescriptor) annotated);
}
JetModifierList modifierList = null;
@@ -32,7 +32,7 @@ public interface DefaultParameterValueLoader {
ValueParameterDescriptor descriptor,
ExpressionCodegen codegen
) {
JetParameter jetParameter = (JetParameter) descriptorToDeclaration(codegen.getBindingContext(), descriptor);
JetParameter jetParameter = (JetParameter) descriptorToDeclaration(descriptor);
assert jetParameter != null;
Type propertyType = codegen.typeMapper.mapType(descriptor.getType());
codegen.gen(jetParameter.getDefaultValue(), propertyType);
@@ -1614,13 +1614,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (expression.getLabelName() == null) {
//non labeled return couldn't be local in lambda
FunctionDescriptor containingFunction =
BindingContextUtils.getContainingFunctionSkipFunctionLiterals(bindingContext, descriptor, true).getFirst();
BindingContextUtils.getContainingFunctionSkipFunctionLiterals(descriptor, true).getFirst();
//ROOT_LABEL to prevent clashing with existing labels
return new NonLocalReturnInfo(typeMapper.mapReturnType(containingFunction), InlineCodegenUtil.ROOT_LABEL);
}
PsiElement element = bindingContext.get(LABEL_TARGET, expression.getTargetLabel());
if (element != callableDescriptorToDeclaration(bindingContext, context.getContextDescriptor())) {
if (element != callableDescriptorToDeclaration(context.getContextDescriptor())) {
DeclarationDescriptor elementDescriptor = typeMapper.getBindingContext().get(DECLARATION_TO_DESCRIPTOR, element);
assert element != null : "Expression should be not null " + expression.getText();
assert elementDescriptor != null : "Descriptor should be not null: " + element.getText();
@@ -450,7 +450,7 @@ public class FunctionCodegen extends ParentCodegenAware {
);
if (!bridgesToGenerate.isEmpty()) {
PsiElement origin = descriptor.getKind() == DECLARATION ? callableDescriptorToDeclaration(bindingContext, descriptor) : null;
PsiElement origin = descriptor.getKind() == DECLARATION ? callableDescriptorToDeclaration(descriptor) : null;
for (Bridge<Method> bridge : bridgesToGenerate) {
generateBridge(origin, descriptor, bridge.getFrom(), bridge.getTo());
}
@@ -570,7 +570,7 @@ public class FunctionCodegen extends ParentCodegenAware {
if (this.owner instanceof PackageFacadeContext) {
mv.visitCode();
generateStaticDelegateMethodBody(mv, defaultMethod, (PackageFacadeContext) this.owner);
endVisit(mv, "default method delegation", callableDescriptorToDeclaration(state.getBindingContext(), functionDescriptor));
endVisit(mv, "default method delegation", callableDescriptorToDeclaration(functionDescriptor));
}
else {
generateDefaultImpl(owner, signature, functionDescriptor, isStatic(kind), mv, loadStrategy, function);
@@ -589,7 +589,7 @@ public class FunctionCodegen extends ParentCodegenAware {
) {
mv.visitCode();
generateDefaultImplBody(methodContext, signature, functionDescriptor, isStatic, mv, loadStrategy, function, getParentCodegen(), state);
endVisit(mv, "default method", callableDescriptorToDeclaration(state.getBindingContext(), functionDescriptor));
endVisit(mv, "default method", callableDescriptorToDeclaration(functionDescriptor));
}
public static void generateDefaultImplBody(
@@ -1530,7 +1530,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private void generateDelegationToTraitImpl(@NotNull final FunctionDescriptor traitFun, @NotNull FunctionDescriptor inheritedFun) {
functionCodegen.generateMethod(
DelegationToTraitImpl(descriptorToDeclaration(bindingContext, traitFun), traitFun),
DelegationToTraitImpl(descriptorToDeclaration(traitFun), traitFun),
typeMapper.mapSignature(inheritedFun),
inheritedFun,
new FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, inheritedFun) {
@@ -186,7 +186,7 @@ public class CodegenBinding {
MutableClosure closure = new MutableClosure(superCall, enclosing, enclosingReceiver);
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace.getBindingContext(), classDescriptor, asmType);
assert PsiCodegenPredictor.checkPredictedNameFromPsi(classDescriptor, asmType);
bindingTrace.record(ASM_TYPE, classDescriptor, asmType);
bindingTrace.record(CLOSURE, classDescriptor, closure);
@@ -290,7 +290,7 @@ public class CodegenBinding {
}
Type asmType = Type.getObjectType(getAsmTypeImpl(bindingContext, klass));
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingContext, klass, asmType);
assert PsiCodegenPredictor.checkPredictedNameFromPsi(klass, asmType);
return asmType;
}
@@ -48,10 +48,8 @@ public final class PsiCodegenPredictor {
private PsiCodegenPredictor() {
}
public static boolean checkPredictedNameFromPsi(
@NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor descriptor, @Nullable Type nameFromDescriptors
) {
PsiElement element = descriptorToDeclaration(bindingContext, descriptor);
public static boolean checkPredictedNameFromPsi(@NotNull DeclarationDescriptor descriptor, @Nullable Type nameFromDescriptors) {
PsiElement element = descriptorToDeclaration(descriptor);
if (element instanceof JetDeclaration) {
String classNameFromPsi = getPredefinedJvmInternalName((JetDeclaration) element);
assert classNameFromPsi == null || Type.getObjectType(classNameFromPsi).equals(nameFromDescriptors) :
@@ -126,7 +126,7 @@ public class InlineCodegen implements CallGenerator {
}
catch (Exception e) {
boolean generateNodeText = !(e instanceof InlineException);
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, this.codegen.getContext().getContextDescriptor());
PsiElement element = BindingContextUtils.descriptorToDeclaration(this.codegen.getContext().getContextDescriptor());
throw new CompilationException("Couldn't inline method call '" +
functionDescriptor.getName() +
"' into \n" + (element != null ? element.getText() : "null psi element " + this.codegen.getContext().getContextDescriptor()) +
@@ -165,7 +165,7 @@ public class InlineCodegen implements CallGenerator {
}
}
else {
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, functionDescriptor);
PsiElement element = BindingContextUtils.descriptorToDeclaration(functionDescriptor);
if (element == null) {
throw new RuntimeException("Couldn't find declaration for function " + descriptorName(functionDescriptor));
@@ -155,7 +155,7 @@ public class InlineCodegenUtil {
private static String getInlineName(@NotNull CodegenContext codegenContext, @NotNull DeclarationDescriptor currentDescriptor, @NotNull JetTypeMapper typeMapper) {
if (currentDescriptor instanceof PackageFragmentDescriptor) {
PsiFile file = getContainingFile(codegenContext, typeMapper);
PsiFile file = getContainingFile(codegenContext);
Type packagePartType;
if (file == null) {
@@ -245,9 +245,9 @@ public class InlineCodegenUtil {
}
@Nullable
public static PsiFile getContainingFile(CodegenContext codegenContext, JetTypeMapper typeMapper) {
public static PsiFile getContainingFile(CodegenContext codegenContext) {
DeclarationDescriptor contextDescriptor = codegenContext.getContextDescriptor();
PsiElement psiElement = BindingContextUtils.descriptorToDeclaration(typeMapper.getBindingContext(), contextDescriptor);
PsiElement psiElement = BindingContextUtils.descriptorToDeclaration(contextDescriptor);
if (psiElement != null) {
return psiElement.getContainingFile();
}
@@ -34,7 +34,7 @@ import org.jetbrains.jet.lang.resolve.java.descriptor.SamAdapterDescriptor
class BuilderFactoryForDuplicateSignatureDiagnostics(
builderFactory: ClassBuilderFactory,
private val bindingContext: BindingContext,
bindingContext: BindingContext,
private val diagnostics: DiagnosticHolder
) : SignatureCollectingClassBuilderFactory(builderFactory) {
@@ -79,9 +79,9 @@ class BuilderFactoryForDuplicateSignatureDiagnostics(
if (member.getKind() != DELEGATION) {
// Delegates don't have declarations in the code
memberElement = BindingContextUtils.callableDescriptorToDeclaration(bindingContext, member)
memberElement = BindingContextUtils.callableDescriptorToDeclaration(member)
if (memberElement == null && member is PropertyAccessorDescriptor) {
memberElement = BindingContextUtils.callableDescriptorToDeclaration(bindingContext, member.getCorrespondingProperty())
memberElement = BindingContextUtils.callableDescriptorToDeclaration(member.getCorrespondingProperty())
}
}
}
@@ -310,12 +310,12 @@ public class JetTypeMapper {
@NotNull
private String generateErrorMessageForErrorType(@NotNull JetType type, @NotNull DeclarationDescriptor descriptor) {
PsiElement declarationElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
PsiElement declarationElement = BindingContextUtils.descriptorToDeclaration(descriptor);
PsiElement parentDeclarationElement = null;
if (declarationElement != null) {
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
if (containingDeclaration != null) {
parentDeclarationElement = BindingContextUtils.descriptorToDeclaration(bindingContext, containingDeclaration);
parentDeclarationElement = BindingContextUtils.descriptorToDeclaration(containingDeclaration);
}
}
@@ -117,7 +117,7 @@ public final class AnalyzerWithCompilerReport {
if (!descriptorsWithErrors.isEmpty()) {
StringBuilder message = new StringBuilder("The following Java entities have annotations with wrong Kotlin signatures:\n");
for (DeclarationDescriptor descriptor : descriptorsWithErrors) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bc, descriptor);
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(descriptor);
assert declaration instanceof PsiModifierListOwner;
List<String> errors = bc.get(JavaBindingContext.LOAD_FROM_JAVA_SIGNATURE_ERRORS, descriptor);
@@ -125,7 +125,7 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
public Collection<JetClassOrObject> findClassOrObjectDeclarations(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) {
ClassDescriptor classDescriptor = getTrace().get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, fqName.toUnsafe());
if (classDescriptor != null) {
PsiElement element = BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
PsiElement element = BindingContextUtils.classDescriptorToDeclaration(classDescriptor);
if (element != null && PsiSearchScopeUtil.isInScope(searchScope, element)) {
return Collections.singletonList((JetClassOrObject) element);
}
@@ -469,7 +469,7 @@ public class JetFlowInformationProvider {
if (variableDescriptor instanceof PropertyDescriptor && !ctxt.enterInitState.isInitialized && ctxt.exitInitState.isInitialized) {
if (!variableDescriptor.isVar()) return false;
if (!trace.get(BindingContext.BACKING_FIELD_REQUIRED, (PropertyDescriptor) variableDescriptor)) return false;
PsiElement property = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), variableDescriptor);
PsiElement property = BindingContextUtils.descriptorToDeclaration(variableDescriptor);
assert property instanceof JetProperty;
if (((PropertyDescriptor) variableDescriptor).getModality() == Modality.FINAL && ((JetProperty) property).getSetter() == null) {
return false;
@@ -505,7 +505,7 @@ public class JetFlowInformationProvider {
report(Errors.NOT_PROPERTY_BACKING_FIELD.on(element), cxtx);
return true;
}
PsiElement property = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), variableDescriptor);
PsiElement property = BindingContextUtils.descriptorToDeclaration(variableDescriptor);
boolean insideSelfAccessors = PsiTreeUtil.isAncestor(property, element, false);
if (!trace.get(BindingContext.BACKING_FIELD_REQUIRED, (PropertyDescriptor) variableDescriptor) &&
// not to generate error in accessors of abstract properties, there is one: declared accessor of abstract property
@@ -51,10 +51,10 @@ public class DiagnosticUtils {
private DiagnosticUtils() {
}
public static String atLocation(BindingContext bindingContext, DeclarationDescriptor descriptor) {
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
public static String atLocation(DeclarationDescriptor descriptor) {
PsiElement element = BindingContextUtils.descriptorToDeclaration(descriptor);
if (element == null) {
element = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor.getOriginal());
element = BindingContextUtils.descriptorToDeclaration(descriptor.getOriginal());
}
if (element == null && descriptor instanceof ASTNode) {
element = DiagnosticUtils.getClosestPsiElement((ASTNode) descriptor);
@@ -156,9 +156,7 @@ public interface BindingContext {
return false;
}
backingFieldRequired = valueNotFound ? false : backingFieldRequired;
assert backingFieldRequired != null;
// TODO: user BindingContextAccessors
PsiElement declarationPsiElement = BindingContextUtils.descriptorToDeclaration(null, propertyDescriptor);
PsiElement declarationPsiElement = BindingContextUtils.descriptorToDeclaration(propertyDescriptor);
if (declarationPsiElement instanceof JetParameter) {
JetParameter jetParameter = (JetParameter) declarationPsiElement;
return jetParameter.hasValOrVarNode() ||
@@ -74,7 +74,7 @@ public class BindingContextUtils {
DeclarationDescriptor descriptor = findTopLevelParent(declarationDescriptor);
if (descriptor == null) return null;
PsiElement declaration = descriptorToDeclaration(context, descriptor);
PsiElement declaration = descriptorToDeclaration(descriptor);
if (declaration == null) return null;
PsiFile containingFile = declaration.getContainingFile();
@@ -105,12 +105,12 @@ public class BindingContextUtils {
// NOTE this is also used by KDoc
@Nullable
public static PsiElement descriptorToDeclaration(@Nullable BindingContext context, @NotNull DeclarationDescriptor descriptor) {
public static PsiElement descriptorToDeclaration(@NotNull DeclarationDescriptor descriptor) {
if (descriptor instanceof CallableMemberDescriptor) {
return callableDescriptorToDeclaration(context, (CallableMemberDescriptor) descriptor);
return callableDescriptorToDeclaration((CallableMemberDescriptor) descriptor);
}
else if (descriptor instanceof ClassDescriptor) {
return classDescriptorToDeclaration(context, (ClassDescriptor) descriptor);
return classDescriptorToDeclaration((ClassDescriptor) descriptor);
}
else {
return doGetDescriptorToDeclaration(descriptor);
@@ -118,12 +118,12 @@ public class BindingContextUtils {
}
@NotNull
public static List<PsiElement> descriptorToDeclarations(@NotNull BindingContext context, @NotNull DeclarationDescriptor descriptor) {
public static List<PsiElement> descriptorToDeclarations(@NotNull DeclarationDescriptor descriptor) {
if (descriptor instanceof CallableMemberDescriptor) {
return callableDescriptorToDeclarations(context, (CallableMemberDescriptor) descriptor);
return callableDescriptorToDeclarations((CallableMemberDescriptor) descriptor);
}
else {
PsiElement psiElement = descriptorToDeclaration(context, descriptor);
PsiElement psiElement = descriptorToDeclaration(descriptor);
if (psiElement != null) {
return Lists.newArrayList(psiElement);
} else {
@@ -133,7 +133,7 @@ public class BindingContextUtils {
}
@Nullable
public static PsiElement callableDescriptorToDeclaration(@Nullable BindingContext context, @NotNull CallableMemberDescriptor callable) {
public static PsiElement callableDescriptorToDeclaration(@NotNull CallableMemberDescriptor callable) {
if (callable.getKind() == DECLARATION || callable.getKind() == SYNTHESIZED) {
return doGetDescriptorToDeclaration(callable);
}
@@ -146,10 +146,7 @@ public class BindingContextUtils {
}
@NotNull
public static List<PsiElement> callableDescriptorToDeclarations(
@NotNull BindingContext context,
@NotNull CallableMemberDescriptor callable
) {
public static List<PsiElement> callableDescriptorToDeclarations(@NotNull CallableMemberDescriptor callable) {
if (callable.getKind() == DECLARATION || callable.getKind() == SYNTHESIZED) {
PsiElement psiElement = doGetDescriptorToDeclaration(callable);
return psiElement != null ? Lists.newArrayList(psiElement) : Lists.<PsiElement>newArrayList();
@@ -158,13 +155,13 @@ public class BindingContextUtils {
List<PsiElement> r = new ArrayList<PsiElement>();
Set<? extends CallableMemberDescriptor> overriddenDescriptors = callable.getOverriddenDescriptors();
for (CallableMemberDescriptor overridden : overriddenDescriptors) {
r.addAll(callableDescriptorToDeclarations(context, overridden));
r.addAll(callableDescriptorToDeclarations(overridden));
}
return r;
}
@Nullable
public static PsiElement classDescriptorToDeclaration(@NotNull BindingContext context, @NotNull ClassDescriptor clazz) {
public static PsiElement classDescriptorToDeclaration(@NotNull ClassDescriptor clazz) {
return doGetDescriptorToDeclaration(clazz);
}
@@ -224,7 +221,7 @@ public class BindingContextUtils {
) {
Collection<PsiElement> targets = Lists.newArrayList();
for (DeclarationDescriptor descriptor : declarationsByLabel) {
PsiElement element = descriptorToDeclaration(trace.getBindingContext(), descriptor);
PsiElement element = descriptorToDeclaration(descriptor);
assert element != null : "Label can only point to something in the same lexical scope";
targets.add(element);
}
@@ -279,16 +276,15 @@ public class BindingContextUtils {
@NotNull
public static Pair<FunctionDescriptor, PsiElement> getContainingFunctionSkipFunctionLiterals(
@NotNull BindingContext context,
@Nullable DeclarationDescriptor startDescriptor,
boolean strict
) {
FunctionDescriptor containingFunctionDescriptor = DescriptorUtils.getParentOfType(startDescriptor, FunctionDescriptor.class, strict);
PsiElement containingFunction = containingFunctionDescriptor != null ? callableDescriptorToDeclaration(context, containingFunctionDescriptor) : null;
PsiElement containingFunction =
containingFunctionDescriptor != null ? callableDescriptorToDeclaration(containingFunctionDescriptor) : null;
while (containingFunction instanceof JetFunctionLiteral) {
containingFunctionDescriptor = DescriptorUtils.getParentOfType(containingFunctionDescriptor, FunctionDescriptor.class);
containingFunction = containingFunctionDescriptor != null ? callableDescriptorToDeclaration(context,
containingFunctionDescriptor) : null;
containingFunction = containingFunctionDescriptor != null ? callableDescriptorToDeclaration(containingFunctionDescriptor) : null;
}
return new Pair<FunctionDescriptor, PsiElement>(containingFunctionDescriptor, containingFunction);
@@ -330,7 +330,7 @@ public class DeclarationResolver {
});
}
else {
declarations = Collections.singletonList(BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), declarationDescriptor));
declarations = Collections.singletonList(BindingContextUtils.descriptorToDeclaration(declarationDescriptor));
}
return declarations;
}
@@ -379,12 +379,12 @@ public class DeclarationResolver {
}
redeclarations.add(Pair.create(
BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), (ClassDescriptor) descriptor),
descriptor.getName()));
BindingContextUtils.classDescriptorToDeclaration((ClassDescriptor) descriptor), descriptor.getName()
));
if (descriptor2 instanceof PropertyDescriptor) {
redeclarations.add(Pair.create(
BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor2),
descriptor2.getName()));
BindingContextUtils.descriptorToDeclaration(descriptor2), descriptor2.getName()
));
}
}
}
@@ -203,8 +203,7 @@ public class DeclarationsChecker {
if (conflictingTypes.size() > 1) {
DeclarationDescriptor containingDeclaration = typeParameterDescriptor.getContainingDeclaration();
assert containingDeclaration instanceof ClassDescriptor : containingDeclaration;
JetClassOrObject psiElement = (JetClassOrObject) BindingContextUtils
.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
JetClassOrObject psiElement = (JetClassOrObject) BindingContextUtils.classDescriptorToDeclaration(classDescriptor);
JetDelegationSpecifierList delegationSpecifierList = psiElement.getDelegationSpecifierList();
assert delegationSpecifierList != null;
// trace.getErrorHandler().genericError(delegationSpecifierList.getNode(), "Type parameter " + typeParameterDescriptor.getName() + " of " + containingDeclaration.getName() + " has inconsistent values: " + conflictingTypes);
@@ -322,7 +321,7 @@ public class DeclarationsChecker {
private void checkOpenMembers(ClassDescriptorWithResolutionScopes classDescriptor) {
for (CallableMemberDescriptor memberDescriptor : classDescriptor.getDeclaredCallableMembers()) {
if (memberDescriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) continue;
JetNamedDeclaration member = (JetNamedDeclaration) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), memberDescriptor);
JetNamedDeclaration member = (JetNamedDeclaration) BindingContextUtils.descriptorToDeclaration(memberDescriptor);
if (member != null && classDescriptor.getModality() == Modality.FINAL && member.hasModifier(JetTokens.OPEN_KEYWORD)) {
trace.report(NON_FINAL_MEMBER_IN_FINAL_CLASS.on(member));
}
@@ -70,7 +70,7 @@ public class InlineDescriptorUtils {
containingFunctionDescriptor = getContainingClassOrFunctionDescriptor(containingFunctionDescriptor, true);
containingFunction = containingFunctionDescriptor != null
? BindingContextUtils.descriptorToDeclaration(bindingContext, containingFunctionDescriptor)
? BindingContextUtils.descriptorToDeclaration(containingFunctionDescriptor)
: null;
}
@@ -36,17 +36,17 @@ public class LibrarySourceHacks {
public static final Key<Boolean> SKIP_TOP_LEVEL_MEMBERS = Key.create("SKIP_TOP_LEVEL_MEMBERS"); // used when analyzing library source
public static <D extends CallableDescriptor> List<D> filterOutMembersFromLibrarySource(Collection<D> members, BindingTrace trace) {
public static <D extends CallableDescriptor> List<D> filterOutMembersFromLibrarySource(Collection<D> members) {
List<D> filteredMembers = Lists.newArrayList();
for (D member : members) {
if (!shouldSkip(member, trace)) {
if (!shouldSkip(member)) {
filteredMembers.add(member);
}
}
return filteredMembers;
}
private static boolean shouldSkip(CallableDescriptor member, BindingTrace trace) {
private static boolean shouldSkip(CallableDescriptor member) {
CallableDescriptor original = member.getOriginal();
if (!(original instanceof CallableMemberDescriptor)) {
return false;
@@ -55,8 +55,7 @@ public class LibrarySourceHacks {
return false;
}
PsiElement declaration = callableDescriptorToDeclaration(trace.getBindingContext(),
(CallableMemberDescriptor) original);
PsiElement declaration = callableDescriptorToDeclaration((CallableMemberDescriptor) original);
if (declaration == null) {
return false;
}
@@ -170,8 +170,7 @@ public class OverloadResolver {
OverloadUtil.OverloadCompatibilityInfo overloadable = OverloadUtil.isOverloadable(member, member2);
if (!overloadable.isSuccess()) {
JetDeclaration jetDeclaration = (JetDeclaration) BindingContextUtils
.descriptorToDeclaration(trace.getBindingContext(), member);
JetDeclaration jetDeclaration = (JetDeclaration) BindingContextUtils.descriptorToDeclaration(member);
if (jetDeclaration != null) {
redeclarations.add(Pair.create(jetDeclaration, member));
}
@@ -110,8 +110,7 @@ public class OverrideResolver {
}
}
JetClassOrObject classOrObject = (JetClassOrObject) BindingContextUtils
.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
JetClassOrObject classOrObject = (JetClassOrObject) BindingContextUtils.classDescriptorToDeclaration(classDescriptor);
if (classOrObject != null) {
DelegationResolver.generateDelegatesInAClass(classDescriptor, trace, classOrObject);
}
@@ -155,8 +154,7 @@ public class OverrideResolver {
@Override
public void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent) {
JetDeclaration declaration =
(JetDeclaration) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), fromCurrent);
JetDeclaration declaration = (JetDeclaration) BindingContextUtils.descriptorToDeclaration(fromCurrent);
//noinspection ConstantConditions
trace.report(CONFLICTING_OVERLOADS.on(declaration, fromCurrent, fromCurrent.getContainingDeclaration().getName().asString()));
}
@@ -190,7 +188,7 @@ public class OverrideResolver {
reportOn = descriptor;
}
//noinspection ConstantConditions
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), reportOn);
PsiElement element = BindingContextUtils.descriptorToDeclaration(reportOn);
if (element instanceof JetDeclaration) {
trace.report(CANNOT_INFER_VISIBILITY.on((JetDeclaration) element, descriptor));
}
@@ -611,7 +609,7 @@ public class OverrideResolver {
return;
}
final JetNamedDeclaration member = (JetNamedDeclaration) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), declared);
final JetNamedDeclaration member = (JetNamedDeclaration) BindingContextUtils.descriptorToDeclaration(declared);
if (member == null) {
throw new IllegalStateException("declared descriptor is not resolved to declaration: " + declared);
}
@@ -864,8 +862,7 @@ public class OverrideResolver {
boolean isDeclaration = declared.getKind() == CallableMemberDescriptor.Kind.DECLARATION;
if (isDeclaration) {
// No check if the function is not marked as 'override'
JetModifierListOwner declaration =
(JetModifierListOwner) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), declared);
JetModifierListOwner declaration = (JetModifierListOwner) BindingContextUtils.descriptorToDeclaration(declared);
if (declaration != null && !declaration.hasModifier(JetTokens.OVERRIDE_KEYWORD)) {
return;
}
@@ -895,7 +892,7 @@ public class OverrideResolver {
}
private void checkNameAndDefaultForDeclaredParameter(@NotNull ValueParameterDescriptor descriptor, boolean multipleDefaultsInSuper) {
JetParameter parameter = (JetParameter) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor);
JetParameter parameter = (JetParameter) BindingContextUtils.descriptorToDeclaration(descriptor);
assert parameter != null : "Declaration not found for parameter: " + descriptor;
if (descriptor.declaresDefaultValue()) {
@@ -924,8 +921,7 @@ public class OverrideResolver {
boolean multipleDefaultsInSuper
) {
DeclarationDescriptor containingClass = containingFunction.getContainingDeclaration();
JetClassOrObject classElement =
(JetClassOrObject) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), containingClass);
JetClassOrObject classElement = (JetClassOrObject) BindingContextUtils.descriptorToDeclaration(containingClass);
assert classElement != null : "Declaration not found for class: " + containingClass;
if (multipleDefaultsInSuper) {
@@ -37,7 +37,7 @@ public class TraceBasedRedeclarationHandler implements RedeclarationHandler {
}
private void report(DeclarationDescriptor descriptor) {
PsiElement firstElement = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor);
PsiElement firstElement = BindingContextUtils.descriptorToDeclaration(descriptor);
if (firstElement != null) {
trace.report(REDECLARATION.on(firstElement, descriptor.getName().asString()));
}
@@ -284,7 +284,7 @@ public class TypeHierarchyResolver {
@NotNull ClassDescriptor classDescriptor,
@NotNull ClassDescriptor superclass
) {
PsiElement psiElement = BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
PsiElement psiElement = BindingContextUtils.classDescriptorToDeclaration(classDescriptor);
PsiElement elementToMark = null;
if (psiElement instanceof JetClassOrObject) {
@@ -184,19 +184,19 @@ public class CallableDescriptorCollectors<D extends CallableDescriptor> implemen
@NotNull
@Override
public Collection<D> getNonExtensionsByName(JetScope scope, Name name, @NotNull BindingTrace bindingTrace) {
return filterOutMembersFromLibrarySource(delegate.getNonExtensionsByName(scope, name, bindingTrace), bindingTrace);
return filterOutMembersFromLibrarySource(delegate.getNonExtensionsByName(scope, name, bindingTrace));
}
@NotNull
@Override
public Collection<D> getMembersByName(@NotNull JetType receiver, Name name, @NotNull BindingTrace bindingTrace) {
return filterOutMembersFromLibrarySource(delegate.getMembersByName(receiver, name, bindingTrace), bindingTrace);
return filterOutMembersFromLibrarySource(delegate.getMembersByName(receiver, name, bindingTrace));
}
@NotNull
@Override
public Collection<D> getNonMembersByName(JetScope scope, Name name, @NotNull BindingTrace bindingTrace) {
return filterOutMembersFromLibrarySource(delegate.getNonMembersByName(scope, name, bindingTrace), bindingTrace);
return filterOutMembersFromLibrarySource(delegate.getNonMembersByName(scope, name, bindingTrace));
}
@Override
@@ -121,8 +121,7 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
@Override
public void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent) {
JetDeclaration declaration = (JetDeclaration) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(),
fromCurrent);
JetDeclaration declaration = (JetDeclaration) BindingContextUtils.descriptorToDeclaration(fromCurrent);
assert declaration != null : "fromCurrent can not be a fake override";
trace.report(Errors.CONFLICTING_OVERLOADS
.on(declaration, fromCurrent, fromCurrent.getContainingDeclaration().getName().asString()));
@@ -366,7 +366,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
VariableDescriptor olderVariable = context.scope.getLocalVariable(variableDescriptor.getName());
if (olderVariable != null && isLocal(context.scope.getContainingDeclaration(), olderVariable)) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context.trace.getBindingContext(), variableDescriptor);
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(variableDescriptor);
context.trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().asString()));
}
}
@@ -450,8 +450,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
assert parentDeclaration != null;
DeclarationDescriptor declarationDescriptor = context.trace.get(DECLARATION_TO_DESCRIPTOR, parentDeclaration);
Pair<FunctionDescriptor, PsiElement> containingFunInfo =
BindingContextUtils.getContainingFunctionSkipFunctionLiterals(context.trace.getBindingContext(), declarationDescriptor,
false);
BindingContextUtils.getContainingFunctionSkipFunctionLiterals(declarationDescriptor, false);
FunctionDescriptor containingFunctionDescriptor = containingFunInfo.getFirst();
if (containingFunctionDescriptor != null) {
@@ -142,7 +142,7 @@ public class ExpressionTypingUtils {
@NotNull DeclarationDescriptor scopeContainer,
@NotNull DeclarationDescriptor variableParent
) {
PsiElement scopeDeclaration = BindingContextUtils.descriptorToDeclaration(context, scopeContainer);
PsiElement scopeDeclaration = BindingContextUtils.descriptorToDeclaration(scopeContainer);
if (!(scopeDeclaration instanceof JetFunctionLiteral)) {
return false;
}
@@ -429,7 +429,7 @@ public class ExpressionTypingUtils {
public static void checkVariableShadowing(@NotNull ExpressionTypingContext context, @NotNull VariableDescriptor variableDescriptor, VariableDescriptor oldDescriptor) {
if (oldDescriptor != null && isLocal(variableDescriptor.getContainingDeclaration(), oldDescriptor)) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context.trace.getBindingContext(), variableDescriptor);
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(variableDescriptor);
if (declaration != null) {
context.trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().asString()));
}
@@ -142,7 +142,7 @@ public class LabelResolver {
DeclarationDescriptor declarationDescriptor = declarationsByLabel.iterator().next();
JetElement element;
if (declarationDescriptor instanceof FunctionDescriptor || declarationDescriptor instanceof ClassDescriptor) {
element = (JetElement) BindingContextUtils.descriptorToDeclaration(context.trace.getBindingContext(), declarationDescriptor);
element = (JetElement) BindingContextUtils.descriptorToDeclaration(declarationDescriptor);
}
else {
throw new UnsupportedOperationException(declarationDescriptor.getClass().toString()); // TODO
@@ -198,7 +198,7 @@ public class LabelResolver {
else {
throw new UnsupportedOperationException("Unsupported descriptor: " + declarationDescriptor); // TODO
}
PsiElement element = BindingContextUtils.descriptorToDeclaration(context.trace.getBindingContext(), declarationDescriptor);
PsiElement element = BindingContextUtils.descriptorToDeclaration(declarationDescriptor);
assert element != null : "No PSI element for descriptor: " + declarationDescriptor;
context.trace.record(LABEL_TARGET, targetLabel, element);
context.trace.record(REFERENCE_TARGET, referenceExpression, declarationDescriptor);
@@ -61,6 +61,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
public class KotlinJavaFileStubProvider<T extends WithFileStubAndExtraDiagnostics> implements CachedValueProvider<T> {
@NotNull
@@ -166,9 +168,7 @@ public class KotlinJavaFileStubProvider<T extends WithFileStubAndExtraDiagnostic
Map<JetClassOrObject, InnerKotlinClassLightClassData> innerClassesMap = ContainerUtil.newHashMap();
for (ClassDescriptor innerClassDescriptor : allInnerClasses) {
JetClassOrObject innerClass = (JetClassOrObject) BindingContextUtils.descriptorToDeclaration(
bindingContext, innerClassDescriptor
);
JetClassOrObject innerClass = (JetClassOrObject) descriptorToDeclaration(innerClassDescriptor);
if (innerClass == null) continue;
InnerKotlinClassLightClassData innerLightClassData = new InnerKotlinClassLightClassData(
@@ -279,7 +279,7 @@ public abstract class ExpectedResolveData {
PsiElement actual = referenceTarget == null
? bindingContext.get(BindingContext.LABEL_TARGET, referenceExpression)
: BindingContextUtils.descriptorToDeclaration(bindingContext, referenceTarget);
: BindingContextUtils.descriptorToDeclaration(referenceTarget);
if (actual instanceof JetSimpleNameExpression) {
actual = ((JetSimpleNameExpression)actual).getIdentifier();
}
@@ -30,7 +30,7 @@ import org.jetbrains.jet.lang.types.JetTypeImpl
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
public class MyDeclarations(
private val context: BindingContext,
context: BindingContext,
private val project: Project,
private val typeResolver: TypeResolver
) {
@@ -40,7 +40,7 @@ public class MyDeclarations(
{
val functions = context.getSliceContents(BindingContext.FUNCTION)
functionFoo = findFunctionByName(functions.values(), "foo")
val function = (BindingContextUtils.descriptorToDeclaration(context, functionFoo) as JetFunction)
val function = BindingContextUtils.descriptorToDeclaration(functionFoo) as JetFunction
val fooBody = function.getBodyExpression()
scopeToResolveTypeParameters = context.get(BindingContext.RESOLUTION_SCOPE, fooBody)!!
}
@@ -37,7 +37,6 @@ import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetClassBody;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.plugin.JetBundle;
@@ -57,31 +56,21 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
private final List<FunctionDescriptor> functionsToAdd;
private final Project project;
private final Editor editor;
private final BindingContext bindingContext;
/**
* @param project Project where action takes place.
* @param editor Editor where modification should be done.
* @param bindingContext BindingContext to be used for finding type declarations.
* @param functionsToAdd List of possible functions to add.
*/
public JetAddFunctionToClassifierAction(
@NotNull Project project,
@NotNull Editor editor,
@NotNull BindingContext bindingContext,
@NotNull List<FunctionDescriptor> functionsToAdd
) {
this.project = project;
this.editor = editor;
this.bindingContext = bindingContext;
this.functionsToAdd = new ArrayList<FunctionDescriptor>(functionsToAdd);
}
private static void addFunction(
@NotNull final Project project,
@NotNull final ClassDescriptor typeDescriptor,
@NotNull final FunctionDescriptor functionDescriptor,
@NotNull BindingContext bindingContext
@NotNull final FunctionDescriptor functionDescriptor
) {
final String signatureString = CodeInsightUtils.createFunctionSignatureStringFromDescriptor(
functionDescriptor,
@@ -89,7 +78,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
PsiDocumentManager.getInstance(project).commitAllDocuments();
final JetClass classifierDeclaration = (JetClass) DescriptorToDeclarationUtil.getDeclaration(project, typeDescriptor, bindingContext);
final JetClass classifierDeclaration = (JetClass) DescriptorToDeclarationUtil.getDeclaration(project, typeDescriptor);
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
@Override
public void run() {
@@ -177,7 +166,6 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
}
private void addFunction(FunctionDescriptor functionToAdd) {
addFunction(project, (ClassDescriptor) functionToAdd.getContainingDeclaration(),
functionToAdd, bindingContext);
addFunction(project, (ClassDescriptor) functionToAdd.getContainingDeclaration(), functionToAdd);
}
}
@@ -23,7 +23,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.plugin.libraries.DecompiledNavigationUtils;
import org.jetbrains.jet.plugin.references.BuiltInsReferenceResolver;
@@ -36,23 +35,15 @@ public final class DescriptorToDeclarationUtil {
}
@Nullable
public static PsiElement getDeclaration(
@NotNull JetFile file,
@NotNull DeclarationDescriptor descriptor,
@NotNull BindingContext bindingContext
) {
return getDeclaration(file.getProject(), descriptor, bindingContext);
public static PsiElement getDeclaration(@NotNull JetFile file, @NotNull DeclarationDescriptor descriptor) {
return getDeclaration(file.getProject(), descriptor);
}
@Nullable
public static PsiElement getDeclaration(
@NotNull Project project,
@NotNull DeclarationDescriptor descriptor,
@NotNull BindingContext bindingContext
) {
Collection<PsiElement> elements = BindingContextUtils.descriptorToDeclarations(bindingContext, descriptor);
public static PsiElement getDeclaration(@NotNull Project project, @NotNull DeclarationDescriptor descriptor) {
Collection<PsiElement> elements = BindingContextUtils.descriptorToDeclarations(descriptor);
if (elements.isEmpty()) {
elements = findDeclarationsForDescriptorWithoutTrace(project, descriptor);
elements = findDecompiledAndBuiltInDeclarations(project, descriptor);
}
if (!elements.isEmpty()) {
return elements.iterator().next();
@@ -61,7 +52,7 @@ public final class DescriptorToDeclarationUtil {
}
@NotNull
public static Collection<PsiElement> findDeclarationsForDescriptorWithoutTrace(
public static Collection<PsiElement> findDecompiledAndBuiltInDeclarations(
@NotNull Project project,
@NotNull DeclarationDescriptor descriptor
) {
@@ -60,7 +60,7 @@ public class GotoSuperActionHandler implements CodeInsightActionHandler {
JetObjectDeclaration.class);
if (declaration == null) return;
final BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(declaration);
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(declaration);
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
@@ -102,7 +102,7 @@ public class GotoSuperActionHandler implements CodeInsightActionHandler {
if (KotlinBuiltIns.getInstance().getAny() == descriptor) {
return null;
}
return BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
return BindingContextUtils.descriptorToDeclaration(descriptor);
}
});
if (superDeclarations.isEmpty()) return;
@@ -40,7 +40,7 @@ public class JetTypeDeclarationProvider implements TypeDeclarationProvider {
if (type != null) {
ClassifierDescriptor classifierDescriptor = type.getConstructor().getDeclarationDescriptor();
if (classifierDescriptor != null) {
PsiElement typeElement = BindingContextUtils.descriptorToDeclaration(bindingContext, classifierDescriptor);
PsiElement typeElement = BindingContextUtils.descriptorToDeclaration(classifierDescriptor);
if (typeElement != null) {
return new PsiElement[] {typeElement};
}
@@ -57,16 +57,15 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
private static final Logger LOG = Logger.getInstance(OverrideImplementMethodsHandler.class.getCanonicalName());
public static List<DescriptorClassMember> membersFromDescriptors(
JetFile file, Iterable<CallableMemberDescriptor> missingImplementations,
BindingContext bindingContext
JetFile file, Iterable<CallableMemberDescriptor> missingImplementations
) {
List<DescriptorClassMember> members = new ArrayList<DescriptorClassMember>();
for (CallableMemberDescriptor memberDescriptor : missingImplementations) {
PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(file, memberDescriptor, bindingContext);
PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(file, memberDescriptor);
if (declaration == null) {
LOG.error("Can not find declaration for descriptor " + memberDescriptor);
} else {
}
else {
DescriptorClassMember member = new DescriptorClassMember(declaration, memberDescriptor);
members.add(member);
}
@@ -254,7 +253,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
HintManager.getInstance().showErrorHint(editor, getNoMethodsFoundHint());
return;
}
List<DescriptorClassMember> members = membersFromDescriptors((JetFile) file, missingImplementations, bindingContext);
List<DescriptorClassMember> members = membersFromDescriptors((JetFile) file, missingImplementations);
final List<DescriptorClassMember> selectedElements;
if (implementAll) {
@@ -122,24 +122,21 @@ public final class DescriptorLookupConverter {
}
@NotNull
public static LookupElement createLookupElement(
@NotNull KotlinCodeAnalyzer analyzer,
@NotNull BindingContext bindingContext,
@NotNull DeclarationDescriptor descriptor) {
public static LookupElement createLookupElement(@NotNull KotlinCodeAnalyzer analyzer, @NotNull DeclarationDescriptor descriptor) {
if (descriptor instanceof CallableMemberDescriptor) {
descriptor = DescriptorUtils.unwrapFakeOverride((CallableMemberDescriptor) descriptor);
}
return createLookupElement(analyzer, descriptor, BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor));
return createLookupElement(analyzer, descriptor, BindingContextUtils.descriptorToDeclaration(descriptor));
}
public static LookupElement[] collectLookupElements(
@NotNull KotlinCodeAnalyzer analyzer,
@NotNull BindingContext bindingContext,
@NotNull Iterable<DeclarationDescriptor> descriptors) {
@NotNull Iterable<DeclarationDescriptor> descriptors
) {
List<LookupElement> result = Lists.newArrayList();
for (DeclarationDescriptor descriptor : descriptors) {
result.add(createLookupElement(analyzer, bindingContext, descriptor));
result.add(createLookupElement(analyzer, descriptor));
}
return result.toArray(new LookupElement[result.size()]);
@@ -78,7 +78,7 @@ public class JetCompletionResultSet {
return;
}
addElement(DescriptorLookupConverter.createLookupElement(resolveSession, bindingContext, descriptor));
addElement(DescriptorLookupConverter.createLookupElement(resolveSession, descriptor));
// add special item for function with one argument of function type with more than one parameter
if (descriptor instanceof FunctionDescriptor) {
@@ -89,7 +89,7 @@ public class JetCompletionResultSet {
if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(parameterType)) {
int parameterCount = KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(parameterType).size();
if (parameterCount > 1) {
LookupElement lookupElement = DescriptorLookupConverter.createLookupElement(resolveSession, bindingContext, descriptor);
LookupElement lookupElement = DescriptorLookupConverter.createLookupElement(resolveSession, descriptor);
addElement(new LookupElementDecorator<LookupElement>(lookupElement) {
@Override
public void renderElement(@NotNull LookupElementPresentation presentation) {
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetPackageDirective;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -33,6 +34,8 @@ import org.jetbrains.jet.plugin.codeInsight.TipsManager;
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
import org.jetbrains.jet.plugin.references.JetSimpleNameReference;
import java.util.Collection;
/**
* Performs completion in package directive. Should suggest only packages and avoid showing fake package produced by
* DUMMY_IDENTIFIER.
@@ -75,8 +78,9 @@ public class JetPackagesContributor extends CompletionContributor {
ResolvePackage.getLazyResolveSession(simpleNameReference.getExpression());
BindingContext bindingContext = resolveSession.resolveToElement(simpleNameReference.getExpression());
for (LookupElement variant : DescriptorLookupConverter.collectLookupElements(
resolveSession, bindingContext, TipsManager.getPackageReferenceVariants(simpleNameReference.getExpression(), bindingContext))) {
Collection<DeclarationDescriptor> variants =
TipsManager.getPackageReferenceVariants(simpleNameReference.getExpression(), bindingContext);
for (LookupElement variant : DescriptorLookupConverter.collectLookupElements(resolveSession, variants)) {
if (!variant.getLookupString().contains(DUMMY_IDENTIFIER)) {
result.addElement(variant);
}
@@ -96,7 +96,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
else -> ExpectedInfoClassification.NOT_MATCHES
}
}
result.addLookupElements(expectedInfos, classifier, { createLookupElement(descriptor, resolveSession, bindingContext) })
result.addLookupElements(expectedInfos, classifier, { createLookupElement(descriptor, resolveSession) })
if (receiver == null) {
toFunctionReferenceLookupElement(descriptor, functionExpectedInfos)?.let { result.add(it) }
@@ -104,7 +104,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
}
if (receiver == null) {
TypeInstantiationItems(bindingContext, resolveSession, visibilityFilter).addToCollection(result, expectedInfos)
TypeInstantiationItems(resolveSession, visibilityFilter).addToCollection(result, expectedInfos)
StaticMembers(bindingContext, resolveSession).addToCollection(result, expectedInfos, expression, itemsToSkip)
@@ -177,7 +177,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
val matchedExpectedInfos = functionExpectedInfos.filter { functionType.isSubtypeOf(it.`type`) }
if (matchedExpectedInfos.isEmpty()) return null
var lookupElement = createLookupElement(descriptor, resolveSession, bindingContext)
var lookupElement = createLookupElement(descriptor, resolveSession)
val text = "::" + (if (descriptor is ConstructorDescriptor) descriptor.getContainingDeclaration().getName() else descriptor.getName())
lookupElement = object: LookupElementDecorator<LookupElement>(lookupElement) {
override fun getLookupString() = text
@@ -107,7 +107,7 @@ class StaticMembers(val bindingContext: BindingContext, val resolveSession: Reso
}
private fun createLookupElement(memberDescriptor: DeclarationDescriptor, classDescriptor: ClassDescriptor): LookupElement {
val lookupElement = createLookupElement(memberDescriptor, resolveSession, bindingContext)
val lookupElement = createLookupElement(memberDescriptor, resolveSession)
val qualifierPresentation = classDescriptor.getName().asString()
val lookupString = qualifierPresentation + "." + lookupElement.getLookupString()
val qualifierText = DescriptorUtils.getFqName(classDescriptor).asString() //TODO: escape keywords
@@ -68,7 +68,7 @@ class ThisItems(val bindingContext: BindingContext) {
val name: Name = descriptor.getName()
if (!name.isSpecial()) return name.asString()
val psiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor)
val psiElement = BindingContextUtils.descriptorToDeclaration(descriptor)
val expression: JetExpression? = when (psiElement) {
is JetFunctionLiteral -> psiElement.getParent() as? JetFunctionLiteralExpression
is JetObjectDeclaration -> psiElement.getParent() as? JetObjectLiteralExpression
@@ -38,9 +38,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.descriptors.Visibilities
import org.jetbrains.jet.plugin.util.makeNotNullable
class TypeInstantiationItems(val bindingContext: BindingContext,
val resolveSession: ResolveSessionForBodies,
val visibilityFilter: (DeclarationDescriptor) -> Boolean) {
class TypeInstantiationItems(val resolveSession: ResolveSessionForBodies, val visibilityFilter: (DeclarationDescriptor) -> Boolean) {
public fun addToCollection(collection: MutableCollection<LookupElement>, expectedInfos: Collection<ExpectedInfo>) {
val expectedInfosGrouped: Map<JetType, List<ExpectedInfo>> = expectedInfos.groupBy { it.`type`.makeNotNullable() }
for ((jetType, types) in expectedInfosGrouped) {
@@ -65,7 +63,7 @@ class TypeInstantiationItems(val bindingContext: BindingContext,
}
if (allConstructors.isNotEmpty() && visibleConstructors.isEmpty()) return
var lookupElement = createLookupElement(classifier, resolveSession, bindingContext)
var lookupElement = createLookupElement(classifier, resolveSession)
var lookupString = lookupElement.getLookupString()
@@ -167,8 +167,8 @@ fun functionType(function: FunctionDescriptor): JetType? {
function.getReturnType() ?: return null)
}
fun createLookupElement(descriptor: DeclarationDescriptor, resolveSession: ResolveSessionForBodies, bindingContext: BindingContext): LookupElement {
val element = DescriptorLookupConverter.createLookupElement(resolveSession, bindingContext, descriptor)
fun createLookupElement(descriptor: DeclarationDescriptor, resolveSession: ResolveSessionForBodies): LookupElement {
val element = DescriptorLookupConverter.createLookupElement(resolveSession, descriptor)
return if (descriptor is FunctionDescriptor && descriptor.getValueParameters().isNotEmpty()) element.keepOldArgumentListOnTab() else element
}
@@ -131,7 +131,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
if (getterDescriptor != null && !getterDescriptor.isDefault()) {
val delegatedResolvedCall = bindingContext[BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, getterDescriptor]
if (delegatedResolvedCall == null) {
val getter = BindingContextUtils.callableDescriptorToDeclaration(bindingContext, getterDescriptor)
val getter = BindingContextUtils.callableDescriptorToDeclaration(getterDescriptor)
if (getter is JetPropertyAccessor && (getter.getBodyExpression() != null || getter.getEqualsToken() != null)) {
val psiMethod = LightClassUtil.getLightClassAccessorMethod(getter)
if (psiMethod != null) {
@@ -142,7 +142,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
else {
val delegatedPropertyGetterDescriptor = delegatedResolvedCall.getResultingDescriptor()
if (delegatedPropertyGetterDescriptor is CallableMemberDescriptor) {
val function = BindingContextUtils.callableDescriptorToDeclaration(bindingContext, delegatedPropertyGetterDescriptor)
val function = BindingContextUtils.callableDescriptorToDeclaration(delegatedPropertyGetterDescriptor)
if (function is JetNamedFunction) {
val psiMethod = LightClassUtil.getLightClassMethod(function)
if (psiMethod != null) {
@@ -163,7 +163,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
val descriptor = resolvedCall.getResultingDescriptor()
if (descriptor is CallableMemberDescriptor) {
val function = BindingContextUtils.callableDescriptorToDeclaration(bindingContext, descriptor)
val function = BindingContextUtils.callableDescriptorToDeclaration(descriptor)
if (function is JetNamedFunction) {
val psiMethod = LightClassUtil.getLightClassMethod(function)
if (psiMethod != null) {
@@ -50,7 +50,7 @@ public abstract class CalleeReferenceVisitorBase extends JetTreeVisitorVoid {
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
if (descriptor == null) return;
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(descriptor);
if (declaration == null) return;
if (isProperty(descriptor, declaration) || isCallable(descriptor, declaration, expression)) {
@@ -299,7 +299,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
if (overriddenMembers.isEmpty()) return;
List<PsiElement> list = Lists.newArrayList();
for (CallableMemberDescriptor overriddenMember : overriddenMembers) {
PsiElement declarationPsiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, overriddenMember);
PsiElement declarationPsiElement = BindingContextUtils.descriptorToDeclaration(overriddenMember);
list.add(declarationPsiElement);
}
if (list.isEmpty()) {
@@ -78,8 +78,7 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa
if (variableDescriptor != null) {
val containingDescriptor = variableDescriptor.getContainingDeclaration()
if (containingDescriptor is AnonymousFunctionDescriptor) {
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
return BindingContextUtils.descriptorToDeclaration(context, containingDescriptor) as? JetFunctionLiteral
return BindingContextUtils.descriptorToDeclaration(containingDescriptor) as? JetFunctionLiteral
}
}
@@ -41,8 +41,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : PsiElementBa
val simpleNameReference = simpleNameExpression.getReference() as JetReference?
val target = simpleNameReference?.resolveToDescriptors()?.first()!!
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(simpleNameExpression)
val funcExpr = BindingContextUtils.descriptorToDeclaration(bindingContext, target.getContainingDeclaration()!!) as JetFunctionLiteral
val funcExpr = BindingContextUtils.descriptorToDeclaration(target.getContainingDeclaration()!!) as JetFunctionLiteral
val newExpr = JetPsiFactory.createExpression(project, "{ it -> 42 }") as JetFunctionLiteralExpression
funcExpr.addRangeAfter(newExpr.getFunctionLiteral().getValueParameterList(),
@@ -83,7 +83,7 @@ public abstract class BaseJetVariableMacro extends Macro {
List<JetNamedDeclaration> declarations = new ArrayList<JetNamedDeclaration>();
for (DeclarationDescriptor declarationDescriptor : TipsManager.excludeNotCallableExtensions(filteredDescriptors, scope)) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bc, declarationDescriptor);
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(declarationDescriptor);
assert declaration == null || declaration instanceof PsiNamedElement;
if (declaration instanceof JetProperty || declaration instanceof JetParameter) {
@@ -102,7 +102,7 @@ public class JetAnonymousSuperMacro extends Macro {
if (!classDescriptor.getModality().isOverridable()) continue;
ClassKind kind = classDescriptor.getKind();
if (kind == ClassKind.TRAIT || kind == ClassKind.CLASS) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bc, descriptor);
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(descriptor);
if (declaration != null) {
result.add((PsiNamedElement) declaration);
}
@@ -151,7 +151,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
return true;
}
private static String renderParameter(ValueParameterDescriptor parameter, boolean named, BindingContext bindingContext) {
private static String renderParameter(ValueParameterDescriptor parameter, boolean named) {
StringBuilder builder = new StringBuilder();
if (named) builder.append("[");
if (parameter.getVarargElementType() != null) {
@@ -161,7 +161,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
.append(": ")
.append(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(getActualParameterType(parameter)));
if (parameter.hasDefaultValue()) {
PsiElement parameterDeclaration = BindingContextUtils.descriptorToDeclaration(bindingContext, parameter);
PsiElement parameterDeclaration = BindingContextUtils.descriptorToDeclaration(parameter);
builder.append(" = ").append(getDefaultExpressionString(parameterDeclaration));
}
if (named) builder.append("]");
@@ -258,7 +258,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
}
else {
ValueParameterDescriptor param = valueParameters.get(i);
builder.append(renderParameter(param, false, bindingContext));
builder.append(renderParameter(param, false));
if (i <= currentParameterIndex && !isArgumentTypeValid(bindingContext, argument, param)) {
isGrey = true;
}
@@ -267,7 +267,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
}
else {
ValueParameterDescriptor param = valueParameters.get(i);
builder.append(renderParameter(param, false, bindingContext));
builder.append(renderParameter(param, false));
}
}
@@ -282,7 +282,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
if (referenceExpression != null && !usedIndexes[j] && param.getName().equals(referenceExpression.getReferencedNameAsName())) {
takeAnyArgument = false;
usedIndexes[j] = true;
builder.append(renderParameter(param, true, bindingContext));
builder.append(renderParameter(param, true));
if (i < currentParameterIndex && !isArgumentTypeValid(bindingContext, argument, param)) {
isGrey = true;
}
@@ -301,7 +301,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
ValueParameterDescriptor param = valueParameters.get(j);
if (!usedIndexes[j]) {
usedIndexes[j] = true;
builder.append(renderParameter(param, true, bindingContext));
builder.append(renderParameter(param, true));
break;
}
}
@@ -28,7 +28,6 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
@@ -152,8 +151,7 @@ public class AddFunctionToSupertypeFix extends JetHintAction<JetNamedFunction> {
@NotNull
private JetAddFunctionToClassifierAction createAction(Project project, Editor editor, JetFile file) {
BindingContext bindingContext = ResolvePackage.getBindingContext(element);
return new JetAddFunctionToClassifierAction(project, editor, bindingContext, functionsToAdd);
return new JetAddFunctionToClassifierAction(project, editor, functionsToAdd);
}
public static JetIntentionActionsFactory createFactory() {
@@ -145,7 +145,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
BindingContext context = ResolvePackage.getBindingContext((JetFile) entry.getContainingFile().getContainingFile());
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
if (resolvedCall == null) return null;
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
JetType expectedType = context.get(BindingContext.TYPE, entry.getTypeRef());
if (componentFunction != null && expectedType != null) {
return new ChangeFunctionReturnTypeFix(componentFunction, expectedType);
@@ -166,7 +166,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
BindingContext context = ResolvePackage.getBindingContext(expression.getContainingJetFile());
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, expression);
if (resolvedCall == null) return null;
JetFunction hasNextFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
JetFunction hasNextFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
if (hasNextFunction != null) {
return new ChangeFunctionReturnTypeFix(hasNextFunction, KotlinBuiltIns.getInstance().getBooleanType());
}
@@ -186,7 +186,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
BindingContext context = ResolvePackage.getBindingContext(expression.getContainingJetFile());
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
if (resolvedCall == null) return null;
PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
if (!(compareTo instanceof JetFunction)) return null;
return new ChangeFunctionReturnTypeFix((JetFunction) compareTo, KotlinBuiltIns.getInstance().getIntType());
}
@@ -224,7 +224,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
}
if (overriddenMismatchingFunctions.size() == 1) {
PsiElement overriddenFunction = BindingContextUtils.descriptorToDeclaration(context, overriddenMismatchingFunctions.get(0));
PsiElement overriddenFunction = BindingContextUtils.descriptorToDeclaration(overriddenMismatchingFunctions.get(0));
if (overriddenFunction instanceof JetFunction) {
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) overriddenFunction, functionType));
}
@@ -79,8 +79,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
return false;
}
BindingContext bindingContext = ResolvePackage.getBindingContext((JetFile) file);
List<PsiElement> declarations = BindingContextUtils.callableDescriptorToDeclarations(bindingContext, functionDescriptor);
List<PsiElement> declarations = BindingContextUtils.callableDescriptorToDeclarations(functionDescriptor);
if (declarations.isEmpty()) {
return false;
}
@@ -73,7 +73,7 @@ public class ChangeVariableMutabilityFix implements IntentionAction {
BindingContext bindingContext = ResolvePackage.getBindingContext(file);
VariableDescriptor descriptor = BindingContextUtils.extractVariableDescriptorIfAny(bindingContext, simpleNameExpression, true);
if (descriptor != null) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(descriptor);
if (declaration instanceof JetProperty) {
return (JetProperty) declaration;
}
@@ -112,7 +112,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
BindingContext context = ResolvePackage.getBindingContext(entry.getContainingJetFile());
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
if (resolvedCall == null) return null;
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
if (componentFunction == null) return null;
JetType expectedType = resolvedCall.getCandidateDescriptor().getReturnType();
return expectedType == null ? null : new ChangeVariableTypeFix(entry, expectedType);
@@ -168,7 +168,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
}
if (overriddenMismatchingProperties.size() == 1 && canChangeOverriddenPropertyType) {
PsiElement overriddenProperty = BindingContextUtils.descriptorToDeclaration(context, overriddenMismatchingProperties.get(0));
PsiElement overriddenProperty = BindingContextUtils.descriptorToDeclaration(overriddenMismatchingProperties.get(0));
if (overriddenProperty instanceof JetProperty) {
actions.add(new ChangeVariableTypeFix((JetProperty) overriddenProperty, propertyType));
}
@@ -110,11 +110,9 @@ private class TypeCandidate(public val theType: JetType, scope: JetScope? = null
/**
* Represents an element in the class selection list.
*/
private class ClassCandidate(public val typeCandidate: TypeCandidate, file: JetFile, context: BindingContext) {
private class ClassCandidate(public val typeCandidate: TypeCandidate, file: JetFile) {
public val jetClass: JetClass = DescriptorToDeclarationUtil.getDeclaration(
file,
DescriptorUtils.getClassDescriptorForType(typeCandidate.theType),
context
file, DescriptorUtils.getClassDescriptorForType(typeCandidate.theType)
) as JetClass
}
@@ -550,7 +548,7 @@ public class CreateFunctionFromUsageFix internal (
}
else {
// class selection
val list = JBList(ownerTypeCandidates.map { ClassCandidate(it, currentFile, currentFileContext) })
val list = JBList(ownerTypeCandidates.map { ClassCandidate(it, currentFile) })
val renderer = QuickFixUtil.ClassCandidateListCellRenderer()
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
list.setCellRenderer(renderer)
@@ -574,7 +572,7 @@ public class CreateFunctionFromUsageFix internal (
// gather relevant information
ownerClassDescriptor = DescriptorUtils.getClassDescriptorForType(selectedReceiverType.theType)
val receiverType = ownerClassDescriptor.getDefaultType()
val classDeclaration = BindingContextUtils.classDescriptorToDeclaration(currentFileContext, ownerClassDescriptor)
val classDeclaration = BindingContextUtils.classDescriptorToDeclaration(ownerClassDescriptor)
if (classDeclaration is JetClass) {
ownerClass = classDeclaration
isExtension = !ownerClass.isWritable()
@@ -67,7 +67,7 @@ public class MakeOverriddenMemberOpenFix extends JetIntentionAction<JetDeclarati
for (CallableMemberDescriptor overriddenDescriptor : getAllDeclaredNonOverridableOverriddenDescriptors(
(CallableMemberDescriptor) descriptor)) {
assert overriddenDescriptor.getKind() == DECLARATION : "Can only be applied to declarations.";
PsiElement overriddenMember = descriptorToDeclaration(resolveSession.getBindingContext(), overriddenDescriptor);
PsiElement overriddenMember = descriptorToDeclaration(overriddenDescriptor);
if (overriddenMember == null || !QuickFixUtil.canModifyElement(overriddenMember)) {
return false;
}
@@ -73,7 +73,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
if (expression instanceof JetOperationExpression) {
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
if (resolvedCall != null) {
JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
JetFunction declaration = getFunctionDeclaration(resolvedCall);
if (declaration != null) {
actions.add(new ChangeFunctionReturnTypeFix(declaration, expectedType));
}
@@ -84,7 +84,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
if (parentBinary.getRight() == expression) {
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(parentBinary, context);
if (resolvedCall != null) {
JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
JetFunction declaration = getFunctionDeclaration(resolvedCall);
if (declaration != null) {
JetParameter binaryOperatorParameter = declaration.getValueParameterList().getParameters().get(0);
actions.add(new ChangeParameterTypeFix(binaryOperatorParameter, expressionType));
@@ -97,7 +97,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
if (expression instanceof JetCallExpression) {
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
if (resolvedCall != null) {
JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
JetFunction declaration = getFunctionDeclaration(resolvedCall);
if (declaration != null) {
actions.add(new ChangeFunctionReturnTypeFix(declaration, expectedType));
}
@@ -131,8 +131,8 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
}
@Nullable
private static JetFunction getFunctionDeclaration(@NotNull BindingContext context, @NotNull ResolvedCall<?> resolvedCall) {
PsiElement result = QuickFixUtil.safeGetDeclaration(context, resolvedCall);
private static JetFunction getFunctionDeclaration(@NotNull ResolvedCall<?> resolvedCall) {
PsiElement result = QuickFixUtil.safeGetDeclaration(resolvedCall);
if (result instanceof JetFunction) {
return (JetFunction) result;
}
@@ -110,7 +110,7 @@ public class QuickFixUtil {
BindingContext context = ResolvePackage.getBindingContext(callExpression.getContainingJetFile());
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(callExpression, context);
if (resolvedCall == null) return null;
PsiElement declaration = safeGetDeclaration(context, resolvedCall);
PsiElement declaration = safeGetDeclaration(resolvedCall);
if (declaration instanceof JetFunction) {
return ((JetFunction) declaration).getValueParameterList();
}
@@ -121,8 +121,8 @@ public class QuickFixUtil {
}
@Nullable
public static PsiElement safeGetDeclaration(@NotNull BindingContext context, @NotNull ResolvedCall<?> resolvedCall) {
List<PsiElement> declarations = BindingContextUtils.descriptorToDeclarations(context, resolvedCall.getResultingDescriptor());
public static PsiElement safeGetDeclaration(@NotNull ResolvedCall<?> resolvedCall) {
List<PsiElement> declarations = BindingContextUtils.descriptorToDeclarations(resolvedCall.getResultingDescriptor());
//do not create fix if descriptor has more than one overridden declaration
if (declarations.size() == 1) {
return declarations.iterator().next();
@@ -141,7 +141,7 @@ public class JetRefactoringUtil {
@Override
public Pair<PsiElement, CallableDescriptor> fun(CallableDescriptor descriptor) {
return new Pair<PsiElement, CallableDescriptor>(
DescriptorToDeclarationUtil.getDeclaration(project, descriptor, bindingContext),
DescriptorToDeclarationUtil.getDeclaration(project, descriptor),
descriptor
);
}
@@ -220,12 +220,8 @@ public class JetRefactoringUtil {
}
@NotNull
public static String formatClass(
@NotNull DeclarationDescriptor classDescriptor,
@NotNull BindingContext bindingContext,
boolean inCode
) {
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, classDescriptor);
public static String formatClass(@NotNull DeclarationDescriptor classDescriptor, boolean inCode) {
PsiElement element = BindingContextUtils.descriptorToDeclaration(classDescriptor);
if (element instanceof PsiClass) {
return formatPsiClass((PsiClass) element, false, inCode);
}
@@ -234,12 +230,8 @@ public class JetRefactoringUtil {
}
@NotNull
public static String formatFunction(
@NotNull DeclarationDescriptor functionDescriptor,
@NotNull BindingContext bindingContext,
boolean inCode
) {
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, functionDescriptor);
public static String formatFunction(@NotNull DeclarationDescriptor functionDescriptor, boolean inCode) {
PsiElement element = BindingContextUtils.descriptorToDeclaration(functionDescriptor);
if (element instanceof PsiMethod) {
return formatPsiMethod((PsiMethod) element, false, inCode);
}
@@ -135,7 +135,7 @@ public class JetChangeSignature(val project: Project,
fun createChangeSignatureDialog(descriptorsForSignatureChange: Collection<FunctionDescriptor>): JetChangeSignatureDialog? {
val baseDescriptor = preferContainedInClass(descriptorsForSignatureChange)
val functionDeclaration = DescriptorToDeclarationUtil.getDeclaration(project, baseDescriptor, bindingContext)
val functionDeclaration = DescriptorToDeclarationUtil.getDeclaration(project, baseDescriptor)
if (functionDeclaration == null) {
LOG.error("Could not find declaration for $baseDescriptor")
return null
@@ -145,7 +145,7 @@ public class JetChangeSignature(val project: Project,
return null
}
val changeSignatureData = JetChangeSignatureData(baseDescriptor, functionDeclaration, bindingContext, descriptorsForSignatureChange)
val changeSignatureData = JetChangeSignatureData(baseDescriptor, functionDeclaration, descriptorsForSignatureChange)
configuration.configure(changeSignatureData, bindingContext)
return JetChangeSignatureDialog(project, changeSignatureData, defaultValueContext, commandName)
}
@@ -49,20 +49,16 @@ public final class JetChangeSignatureData implements JetMethodDescriptor {
@NotNull
private final List<JetParameterInfo> parameters;
@NotNull
private final BindingContext bindingContext;
@NotNull
private final Collection<FunctionDescriptor> descriptorsForSignatureChange;
private Collection<PsiElement> affectedFunctions = null;
public JetChangeSignatureData(
@NotNull FunctionDescriptor baseDescriptor,
@NotNull PsiElement baseDeclaration,
@NotNull BindingContext bindingContext,
@NotNull Collection<FunctionDescriptor> descriptorsForSignatureChange
) {
this.baseDescriptor = baseDescriptor;
this.baseDeclaration = baseDeclaration;
this.bindingContext = bindingContext;
this.descriptorsForSignatureChange = descriptorsForSignatureChange;
final List<JetParameter> valueParameters = this.baseDeclaration instanceof JetFunction
? ((JetFunction) this.baseDeclaration).getValueParameters()
@@ -110,7 +106,7 @@ public final class JetChangeSignatureData implements JetMethodDescriptor {
@NotNull
private Collection<PsiElement> computeHierarchyFrom(@NotNull FunctionDescriptor baseDescriptor) {
PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(baseDeclaration.getProject(), baseDescriptor, bindingContext);
PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(baseDeclaration.getProject(), baseDescriptor);
Set<PsiElement> result = Sets.newHashSet();
result.add(declaration);
if (!(declaration instanceof JetNamedFunction)) {
@@ -146,7 +146,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
if (!changeInfo.isConstructor() && functionScope != null && !info.getNewName().isEmpty()) {
for (FunctionDescriptor conflict : functionScope.getFunctions(Name.identifier(info.getNewName()))) {
if (conflict != oldDescriptor && getFunctionParameterTypes(conflict).equals(getFunctionParameterTypes(oldDescriptor))) {
PsiElement conflictElement = BindingContextUtils.descriptorToDeclaration(bindingContext, conflict);
PsiElement conflictElement = BindingContextUtils.descriptorToDeclaration(conflict);
result.putValue(conflictElement, "Function already exists: '" + DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(conflict) + "'");
break;
}
@@ -163,7 +163,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
if (parametersScope != null) {
if (changeInfo.isConstructor() && valOrVar != JetValVar.None) {
for (VariableDescriptor property : parametersScope.getProperties(Name.identifier(parameterName))) {
PsiElement propertyDeclaration = BindingContextUtils.descriptorToDeclaration(bindingContext, property);
PsiElement propertyDeclaration = BindingContextUtils.descriptorToDeclaration(property);
if (propertyDeclaration != null && !(propertyDeclaration.getParent() instanceof JetParameterList)) {
result.putValue(propertyDeclaration, "Duplicating property '" + parameterName + "'");
@@ -175,7 +175,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
VariableDescriptor variable = parametersScope.getLocalVariable(Name.identifier(parameterName));
if (variable != null && !(variable instanceof ValueParameterDescriptor)) {
PsiElement conflictElement = BindingContextUtils.descriptorToDeclaration(bindingContext, variable);
PsiElement conflictElement = BindingContextUtils.descriptorToDeclaration(variable);
result.putValue(conflictElement, "Duplicating local variable '" + parameterName + "'");
}
}
@@ -190,7 +190,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
if (containingDeclaration instanceof ClassDescriptor)
return ((ClassDescriptor) containingDeclaration).getMemberScope(ContainerUtil.<TypeProjection>emptyList());
else if (containingDeclaration instanceof FunctionDescriptorImpl) {
PsiElement container = BindingContextUtils.descriptorToDeclaration(bindingContext, containingDeclaration);
PsiElement container = BindingContextUtils.descriptorToDeclaration(containingDeclaration);
if (container instanceof JetFunction)
return getFunctionBodyScope((JetFunction) container, bindingContext);
@@ -105,7 +105,7 @@ class ExtractionData(
val refOffsetToDeclaration by Delegates.lazy {
fun isExtractableIt(descriptor: DeclarationDescriptor, context: BindingContext): Boolean {
if (!(descriptor is ValueParameterDescriptor && (context[BindingContext.AUTO_CREATED_IT, descriptor] ?: false))) return false
val function = BindingContextUtils.descriptorToDeclaration(context, descriptor.getContainingDeclaration()) as? JetFunctionLiteral
val function = BindingContextUtils.descriptorToDeclaration(descriptor.getContainingDeclaration()) as? JetFunctionLiteral
return function == null || !function.isInsideOf(originalElements)
}
@@ -122,7 +122,7 @@ class ExtractionData(
val descriptor = context[BindingContext.REFERENCE_TARGET, ref]
if (descriptor == null) continue
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor, context) as? PsiNamedElement
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor) as? PsiNamedElement
?: if (isExtractableIt(descriptor, context)) itFakeDeclaration else continue
val offset = ref.getTextRange()!!.getStartOffset() - originalStartOffset
@@ -284,7 +284,6 @@ fun TypeParameter.collectReferencedTypes(bindingContext: BindingContext): List<J
}
private fun JetType.processTypeIfExtractable(
bindingContext: BindingContext,
typeParameters: MutableSet<TypeParameter>,
nonDenotableTypes: MutableSet<JetType>,
processTypeArguments: Boolean = true
@@ -292,7 +291,7 @@ private fun JetType.processTypeIfExtractable(
return collectReferencedTypes(processTypeArguments).fold(true) { (extractable, typeToCheck) ->
val parameterTypeDescriptor = typeToCheck.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor
val typeParameter = parameterTypeDescriptor?.let {
BindingContextUtils.descriptorToDeclaration(bindingContext, it)
BindingContextUtils.descriptorToDeclaration(it)
} as? JetTypeParameter
when {
@@ -411,9 +410,7 @@ private fun ExtractionData.inferParametersInfo(
}
if (referencedClassDescriptor != null) {
if (!referencedClassDescriptor.getDefaultType().processTypeIfExtractable(
bindingContext, typeParameters, nonDenotableTypes, false
)) continue
if (!referencedClassDescriptor.getDefaultType().processTypeIfExtractable(typeParameters, nonDenotableTypes, false)) continue
val replacingDescriptor = (originalDescriptor as? ConstructorDescriptor)?.getContainingDeclaration() ?: originalDescriptor
replacementMap[refInfo.offsetInBody] = FqNameReplacement(DescriptorUtils.getFqNameSafe(replacingDescriptor))
@@ -436,7 +433,7 @@ private fun ExtractionData.inferParametersInfo(
?: DEFAULT_PARAMETER_TYPE
}
if (!parameterType.processTypeIfExtractable(bindingContext, typeParameters, nonDenotableTypes)) continue
if (!parameterType.processTypeIfExtractable(typeParameters, nonDenotableTypes)) continue
val parameterTypePredicate =
pseudocode.getElementValue(originalRef)?.let { getExpectedTypePredicate(it, valueUsageMap, bindingContext) } ?: AllTypes
@@ -470,7 +467,7 @@ private fun ExtractionData.inferParametersInfo(
}
for (typeToCheck in typeParameters.flatMapTo(HashSet<JetType>()) { it.collectReferencedTypes(bindingContext) }) {
typeToCheck.processTypeIfExtractable(bindingContext, typeParameters, nonDenotableTypes)
typeToCheck.processTypeIfExtractable(typeParameters, nonDenotableTypes)
}
parameters.addAll(extractedDescriptorToParameter.values())
@@ -489,7 +486,7 @@ private fun ExtractionData.checkLocalDeclarationsWithNonLocalUsages(
pseudocode.traverse(TraversalOrder.FORWARD) { instruction ->
if (instruction !in localInstructions) {
PseudocodeUtil.extractVariableDescriptorIfAny(instruction, true, bindingContext)?.let { descriptor ->
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor, bindingContext)
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor)
if (declaration is JetNamedDeclaration && declaration.isInsideOf(originalElements)) {
declarations.add(declaration)
}
@@ -572,7 +569,7 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
val (controlFlow, controlFlowMessage) = localInstructions.analyzeControlFlow(pseudocode, bindingContext, options, parameters)
controlFlowMessage?.let { messages.add(it) }
controlFlow.returnType.processTypeIfExtractable(bindingContext, typeParameters, nonDenotableTypes)
controlFlow.returnType.processTypeIfExtractable(typeParameters, nonDenotableTypes)
if (nonDenotableTypes.isNotEmpty()) {
val typeStr = nonDenotableTypes.map {DescriptorRenderer.HTML.renderType(it)}.sort()
@@ -633,9 +630,8 @@ fun ExtractionDescriptor.validate(): ExtractionDescriptorWithConflicts {
val diagnostics = bindingContext.getDiagnostics().forElement(currentRefExpr)
val currentDescriptor = bindingContext[BindingContext.REFERENCE_TARGET, currentRefExpr]
val currentTarget = currentDescriptor?.let {
DescriptorToDeclarationUtil.getDeclaration(extractionData.project, it, bindingContext)
} as? PsiNamedElement
val currentTarget =
currentDescriptor?.let { DescriptorToDeclarationUtil.getDeclaration(extractionData.project, it) } as? PsiNamedElement
if (currentTarget is JetParameter && currentTarget.getParent() == function.getValueParameterList()) continue
if (currentDescriptor is LocalVariableDescriptor
&& parameters.any { it.mirrorVarName == currentDescriptor.getName().asString() }) continue
@@ -179,7 +179,7 @@ public class MoveKotlinTopLevelDeclarationsProcessor(project: Project, val optio
val referenceToContext = JetFileReferencesResolver.resolve(element = declaration, visitReceivers = false)
for ((refExpr, bindingContext) in referenceToContext) {
val refTarget = bindingContext[BindingContext.REFERENCE_TARGET, refExpr]?.let { descriptor ->
DescriptorToDeclarationUtil.getDeclaration(declaration.getProject(), descriptor, bindingContext)
DescriptorToDeclarationUtil.getDeclaration(declaration.getProject(), descriptor)
}
if (refTarget == null || refTarget.isInsideOf(elementsToMove)) continue
@@ -64,7 +64,7 @@ public fun JetElement.updateInternalReferencesOnPackageNameChange(
}
if (descriptor == null || !descriptor.canBeReferencedViaImport()) continue
val declaration = DescriptorToDeclarationUtil.getDeclaration(file, descriptor, bindingContext)
val declaration = DescriptorToDeclarationUtil.getDeclaration(file, descriptor)
if (declaration == null || isAncestor(declaration, true)) continue
val fqName = DescriptorUtils.getFqName(descriptor)
@@ -185,7 +185,7 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() {
// Take one of supers for now - API doesn't support substitute to several elements (IDEA-48796)
val deepest = supers.first()
if (deepest != descriptor) {
val superPsiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, deepest)
val superPsiElement = BindingContextUtils.descriptorToDeclaration(deepest)
return superPsiElement as? JetProperty
}
}
@@ -57,7 +57,7 @@ public class KotlinJavaSafeDeleteDelegate : JavaSafeDeleteDelegate {
val originalDeclaration = method.unwrapped
if (originalDeclaration !is PsiMethod && originalDeclaration !is JetDeclaration) return
if (originalDeclaration != BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor)) return
if (originalDeclaration != BindingContextUtils.descriptorToDeclaration(descriptor)) return
val args = callExpression.getValueArguments()
@@ -219,10 +219,10 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
.mapTo(ArrayList<String>()) { overridenDescriptor ->
JetBundle.message(
"x.implements.y",
JetRefactoringUtil.formatFunction(declarationDescriptor, bindingContext, true),
JetRefactoringUtil.formatClass(declarationDescriptor.getContainingDeclaration(), bindingContext, true),
JetRefactoringUtil.formatFunction(overridenDescriptor, bindingContext, true),
JetRefactoringUtil.formatClass(overridenDescriptor.getContainingDeclaration(), bindingContext, true)
JetRefactoringUtil.formatFunction(declarationDescriptor, true),
JetRefactoringUtil.formatClass(declarationDescriptor.getContainingDeclaration(), true),
JetRefactoringUtil.formatFunction(overridenDescriptor, true),
JetRefactoringUtil.formatClass(overridenDescriptor.getContainingDeclaration(), true)
)
}
}
@@ -231,13 +231,9 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent {
@NotNull
public Collection<PsiElement> resolveBuiltInSymbol(@NotNull DeclarationDescriptor declarationDescriptor) {
if (bindingContext == null) {
return Collections.emptyList();
}
DeclarationDescriptor descriptor = findCurrentDescriptor(declarationDescriptor.getOriginal());
if (descriptor != null) {
return BindingContextUtils.descriptorToDeclarations(bindingContext, descriptor);
return BindingContextUtils.descriptorToDeclarations(descriptor);
}
return Collections.emptyList();
}
@@ -95,12 +95,12 @@ abstract class AbstractJetReference<T : JetElement>(element: T)
override fun resolveMap(): Map<DeclarationDescriptor, Collection<PsiElement>> {
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
return getTargetDescriptors(context) keysToMap { resolveToPsiElements(context, it) }
return getTargetDescriptors(context) keysToMap { resolveToPsiElements(it) }
}
private fun resolveToPsiElements(context: BindingContext, targetDescriptors: Collection<DeclarationDescriptor>): Collection<PsiElement> {
if (targetDescriptors.isNotEmpty()) {
return targetDescriptors flatMap { target -> resolveToPsiElements(context, target) }
return targetDescriptors flatMap { target -> resolveToPsiElements(target) }
}
val labelTargets = getLabelTargets(context)
@@ -111,11 +111,11 @@ abstract class AbstractJetReference<T : JetElement>(element: T)
return Collections.emptySet()
}
private fun resolveToPsiElements(context: BindingContext, targetDescriptor: DeclarationDescriptor): Collection<PsiElement> {
private fun resolveToPsiElements(targetDescriptor: DeclarationDescriptor): Collection<PsiElement> {
val result = HashSet<PsiElement>()
val project = expression.getProject()
result.addAll(BindingContextUtils.descriptorToDeclarations(context, targetDescriptor))
result.addAll(DescriptorToDeclarationUtil.findDeclarationsForDescriptorWithoutTrace(project, targetDescriptor))
result.addAll(BindingContextUtils.descriptorToDeclarations(targetDescriptor))
result.addAll(DescriptorToDeclarationUtil.findDecompiledAndBuiltInDeclarations(project, targetDescriptor))
if (targetDescriptor is PackageViewDescriptor) {
val psiFacade = JavaPsiFacade.getInstance(project)
@@ -103,7 +103,7 @@ fun PsiReference.isConstructorUsage(jetClassOrObject: JetClassOrObject): Boolean
val descriptor = getCallDescriptor(bindingContext)
if (descriptor !is ConstructorDescriptor) return false
return BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor.getContainingDeclaration()) == jetClassOrObject
return BindingContextUtils.descriptorToDeclaration(descriptor.getContainingDeclaration()) == jetClassOrObject
}
checkJavaUsage() || checkKotlinUsage()
@@ -52,7 +52,7 @@ public class KotlinInheritedMembersNodeProvider: InheritedMembersNodeProvider<Tr
when (memberDescriptor.getKind()) {
CallableMemberDescriptor.Kind.FAKE_OVERRIDE,
CallableMemberDescriptor.Kind.DELEGATION -> {
val superTypeMember = DescriptorToDeclarationUtil.getDeclaration(project, memberDescriptor, context)
val superTypeMember = DescriptorToDeclarationUtil.getDeclaration(project, memberDescriptor)
if (superTypeMember is NavigatablePsiElement) {
children.add(JetStructureViewElement(superTypeMember, memberDescriptor, true))
}
@@ -165,10 +165,9 @@ public abstract class AbstractOverrideImplementTest extends JetLightCodeInsightF
new WriteCommandAction(myFixture.getProject(), myFixture.getFile()) {
@Override
protected void run(Result result) throws Throwable {
OverrideImplementMethodsHandler.generateMethods(
myFixture.getEditor(), classOrObject,
OverrideImplementMethodsHandler
.membersFromDescriptors(jetFile, Collections.singletonList(singleToOverride), resolveSession.getBindingContext()));
OverrideImplementMethodsHandler.generateMethods(myFixture.getEditor(), classOrObject,
OverrideImplementMethodsHandler.membersFromDescriptors(jetFile, Collections.singletonList(singleToOverride))
);
}
}.execute();
}
@@ -179,7 +178,7 @@ public abstract class AbstractOverrideImplementTest extends JetLightCodeInsightF
assertNotNull("Caret should be inside class or object", classOrObject);
final JetFile jetFile = classOrObject.getContainingJetFile();
final BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(classOrObject);
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(classOrObject);
Set<CallableMemberDescriptor> descriptors = handler.collectMethodsToGenerate(classOrObject, bindingContext);
final ArrayList<CallableMemberDescriptor> descriptorsList = new ArrayList<CallableMemberDescriptor>(descriptors);
@@ -195,7 +194,7 @@ public abstract class AbstractOverrideImplementTest extends JetLightCodeInsightF
protected void run(Result result) throws Throwable {
OverrideImplementMethodsHandler.generateMethods(
myFixture.getEditor(), classOrObject,
OverrideImplementMethodsHandler.membersFromDescriptors(jetFile, descriptorsList, bindingContext));
OverrideImplementMethodsHandler.membersFromDescriptors(jetFile, descriptorsList));
}
}.execute();
}
@@ -190,7 +190,7 @@ public abstract class AbstractRenameTest : MultiFileTestCase() {
val bindingContext = jetFile.getBindingContext()
val classDescriptor = bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, classFqName)!!
val psiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, findDescriptorToRename(classDescriptor))!!
val psiElement = BindingContextUtils.descriptorToDeclaration(findDescriptorToRename(classDescriptor))!!
val substitution = RenamePsiElementProcessor.forElement(psiElement).substituteElementToRename(psiElement, null)
@@ -50,7 +50,7 @@ trait CallInfo {
fun constructSafeCallIsNeeded(result: JsExpression): JsExpression
override fun toString(): String {
val location = DiagnosticUtils.atLocation(context.bindingContext(), callableDescriptor)
val location = DiagnosticUtils.atLocation(callableDescriptor)
val name = callableDescriptor.getName().asString()
return "callableDescriptor: $name at $location; thisObject: $thisObject; receiverObject: $receiverObject"
}
@@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.config.LibrarySourcesConfig;
@@ -37,6 +36,7 @@ import org.jetbrains.k2js.translate.utils.JsAstUtils;
import java.util.Map;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.getNameForAnnotatedObjectWithOverrides;
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.isLibraryObject;
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.*;
@@ -448,10 +448,9 @@ public final class StaticContext {
}
private String getExternalModuleName(DeclarationDescriptor descriptor) {
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
PsiElement element = descriptorToDeclaration(descriptor);
if (element == null && descriptor instanceof PropertyAccessorDescriptor) {
element = BindingContextUtils.descriptorToDeclaration(bindingContext, ((PropertyAccessorDescriptor) descriptor)
.getCorrespondingProperty());
element = descriptorToDeclaration(((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty());
}
if (element == null) {
@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.Modality;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression;
import org.jetbrains.k2js.translate.context.AliasingContext;
import org.jetbrains.k2js.translate.context.Namer;
@@ -70,7 +69,7 @@ public final class FunctionTranslator extends AbstractTranslator {
this.functionDeclaration = functionDeclaration;
this.functionObject = context().getFunctionObject(descriptor);
assert this.functionObject.getParameters().isEmpty()
: message(bindingContext(), descriptor, "Function " + functionDeclaration.getText() + " processed for the second time.");
: message(descriptor, "Function " + functionDeclaration.getText() + " processed for the second time.");
//NOTE: it's important we compute the context before we start the computation
this.functionBodyContext = getFunctionBodyContext();
}
@@ -88,7 +88,7 @@ public final class InlinedCallExpressionTranslator extends AbstractCallExpressio
@NotNull
private JetFunction getFunctionBody() {
return getFunctionForDescriptor(bindingContext(), getFunctionDescriptor());
return getFunctionForDescriptor(getFunctionDescriptor());
}
@NotNull
@@ -75,20 +75,16 @@ public final class BindingUtils {
}
@NotNull
public static JetFunction getFunctionForDescriptor(@NotNull BindingContext context,
@NotNull SimpleFunctionDescriptor descriptor) {
PsiElement result = BindingContextUtils.callableDescriptorToDeclaration(context, descriptor);
assert result instanceof JetFunction
: message(context, descriptor, "SimpleFunctionDescriptor should have declaration of type JetFunction");
public static JetFunction getFunctionForDescriptor(@NotNull SimpleFunctionDescriptor descriptor) {
PsiElement result = BindingContextUtils.callableDescriptorToDeclaration(descriptor);
assert result instanceof JetFunction : message(descriptor, "SimpleFunctionDescriptor should have declaration of type JetFunction");
return (JetFunction) result;
}
@NotNull
private static JetParameter getParameterForDescriptor(@NotNull BindingContext context,
@NotNull ValueParameterDescriptor descriptor) {
PsiElement result = BindingContextUtils.descriptorToDeclaration(context, descriptor);
assert result instanceof JetParameter :
message(context, descriptor, "ValueParameterDescriptor should have corresponding JetParameter");
private static JetParameter getParameterForDescriptor(@NotNull ValueParameterDescriptor descriptor) {
PsiElement result = BindingContextUtils.descriptorToDeclaration(descriptor);
assert result instanceof JetParameter : message(descriptor, "ValueParameterDescriptor should have corresponding JetParameter");
return (JetParameter) result;
}
@@ -183,21 +179,20 @@ public final class BindingUtils {
}
@NotNull
public static JetExpression getDefaultArgument(@NotNull BindingContext context,
@NotNull ValueParameterDescriptor parameterDescriptor) {
public static JetExpression getDefaultArgument(@NotNull ValueParameterDescriptor parameterDescriptor) {
ValueParameterDescriptor descriptorWhichDeclaresDefaultValue =
getOriginalDescriptorWhichDeclaresDefaultValue(context, parameterDescriptor);
JetParameter psiParameter = getParameterForDescriptor(context, descriptorWhichDeclaresDefaultValue);
getOriginalDescriptorWhichDeclaresDefaultValue(parameterDescriptor);
JetParameter psiParameter = getParameterForDescriptor(descriptorWhichDeclaresDefaultValue);
JetExpression defaultValue = psiParameter.getDefaultValue();
assert defaultValue != null : message(context, parameterDescriptor, "No default value found in PSI");
assert defaultValue != null : message(parameterDescriptor, "No default value found in PSI");
return defaultValue;
}
private static ValueParameterDescriptor getOriginalDescriptorWhichDeclaresDefaultValue(
BindingContext context, @NotNull ValueParameterDescriptor parameterDescriptor) {
@NotNull ValueParameterDescriptor parameterDescriptor
) {
ValueParameterDescriptor result = parameterDescriptor;
assert result.hasDefaultValue() :
message(context, parameterDescriptor, "Unsupplied parameter must have default value");
assert result.hasDefaultValue() : message(parameterDescriptor, "Unsupplied parameter must have default value");
while (!result.declaresDefaultValue()) {
result = result.getOverriddenDescriptors().iterator().next();
}
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.BindingContext;
public final class ErrorReportingUtils {
private ErrorReportingUtils() {
@@ -43,21 +42,12 @@ public final class ErrorReportingUtils {
}
@NotNull
public static String message(@NotNull BindingContext context,
@NotNull DeclarationDescriptor descriptor,
@NotNull String explainingMessage) {
return explainingMessage + " at " + DiagnosticUtils.atLocation(context, descriptor) + ".";
public static String message(@NotNull DeclarationDescriptor descriptor, @NotNull String explainingMessage) {
return explainingMessage + " at " + DiagnosticUtils.atLocation(descriptor) + ".";
}
@NotNull
public static String message(@NotNull PsiElement element) {
return "Error at " + DiagnosticUtils.atLocation(element) + ".";
}
@NotNull
public static RuntimeException reportErrorWithLocation(@NotNull RuntimeException e,
@NotNull DeclarationDescriptor descriptor,
@NotNull BindingContext bindingContext) {
throw reportErrorWithLocation(e, DiagnosticUtils.atLocation(bindingContext, descriptor));
}
}
@@ -54,7 +54,7 @@ public final class FunctionBodyTranslator extends AbstractTranslator {
for (ValueParameterDescriptor valueParameter : descriptor.getValueParameters()) {
if (valueParameter.hasDefaultValue()) {
JsNameRef jsNameRef = functionBodyContext.getNameForDescriptor(valueParameter).makeRef();
JetExpression defaultArgument = getDefaultArgument(functionBodyContext.bindingContext(), valueParameter);
JetExpression defaultArgument = getDefaultArgument(valueParameter);
JsExpression defaultValue = Translation.translateAsExpression(defaultArgument, functionBodyContext);
JsBinaryOperation checkArgIsUndefined = equality(jsNameRef, functionBodyContext.namer().getUndefinedExpression());