Refactor: Remove context parameter from BindingContextUtils.descriptorToDeclaration utilities family
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
+3
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+1
-2
@@ -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()));
|
||||
|
||||
+2
-3
@@ -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) {
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
+3
-3
@@ -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)!!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user