Esempio n. 1
0
 @Nullable
 public static JetTypeInfo getRecordedTypeInfo(
     @NotNull JetExpression expression, @NotNull BindingContext context) {
   if (!context.get(BindingContext.PROCESSED, expression)) return null;
   DataFlowInfo dataFlowInfo = BindingContextUtilPackage.getDataFlowInfo(context, expression);
   JetType type = context.get(BindingContext.EXPRESSION_TYPE, expression);
   return JetTypeInfo.create(type, dataFlowInfo);
 }
Esempio n. 2
0
 @Nullable
 public static JetTypeInfo getRecordedTypeInfo(
     @NotNull JetExpression expression, @NotNull BindingContext context) {
   // noinspection ConstantConditions
   if (!context.get(BindingContext.PROCESSED, expression)) return null;
   // NB: should never return null if expression is already processed
   JetTypeInfo result = context.get(BindingContext.EXPRESSION_TYPE_INFO, expression);
   return result != null ? result : TypeInfoFactoryPackage.noTypeInfo(DataFlowInfo.EMPTY);
 }
Esempio n. 3
0
 public static boolean isVarCapturedInClosure(
     BindingContext bindingContext, DeclarationDescriptor descriptor) {
   if (!(descriptor instanceof VariableDescriptor) || descriptor instanceof PropertyDescriptor)
     return false;
   VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
   return bindingContext.get(CAPTURED_IN_CLOSURE, variableDescriptor) != null
       && variableDescriptor.isVar();
 }
Esempio n. 4
0
 @NotNull
 public static JetType getTypeNotNull(
     @NotNull BindingContext bindingContext, @NotNull JetExpression expression) {
   JetType result = bindingContext.getType(expression);
   if (result == null) {
     throw new IllegalStateException("Type must be not null for " + expression);
   }
   return result;
 }
Esempio n. 5
0
 @NotNull
 public static <K, V> V getNotNull(
     @NotNull BindingContext bindingContext,
     @NotNull ReadOnlySlice<K, V> slice,
     @NotNull K key,
     @NotNull String messageIfNull) {
   V value = bindingContext.get(slice, key);
   if (value == null) {
     throw new IllegalStateException(messageIfNull);
   }
   return value;
 }
Esempio n. 6
0
 @Nullable
 public static VariableDescriptor extractVariableDescriptorIfAny(
     @NotNull BindingContext bindingContext, @Nullable JetElement element, boolean onlyReference) {
   DeclarationDescriptor descriptor = null;
   if (!onlyReference
       && (element instanceof JetVariableDeclaration || element instanceof JetParameter)) {
     descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
   } else if (element instanceof JetSimpleNameExpression) {
     descriptor =
         bindingContext.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) element);
   } else if (element instanceof JetQualifiedExpression) {
     descriptor =
         extractVariableDescriptorIfAny(
             bindingContext,
             ((JetQualifiedExpression) element).getSelectorExpression(),
             onlyReference);
   }
   if (descriptor instanceof VariableDescriptor) {
     return (VariableDescriptor) descriptor;
   }
   return null;
 }
Esempio n. 7
0
 @NotNull
 public static DeclarationDescriptor getEnclosingDescriptor(
     @NotNull BindingContext context, @NotNull JetElement element) {
   JetNamedDeclaration declaration =
       PsiTreeUtil.getParentOfType(element, JetNamedDeclaration.class);
   if (declaration instanceof JetFunctionLiteral) {
     return getEnclosingDescriptor(context, declaration);
   }
   DeclarationDescriptor descriptor = context.get(DECLARATION_TO_DESCRIPTOR, declaration);
   assert descriptor != null
       : "No descriptor for named declaration: "
           + declaration.getText()
           + "\n(of type "
           + declaration.getClass()
           + ")";
   return descriptor;
 }
Esempio n. 8
0
 public static FunctionDescriptor getEnclosingFunctionDescriptor(
     @NotNull BindingContext context, @NotNull JetElement element) {
   JetFunction function = PsiTreeUtil.getParentOfType(element, JetFunction.class);
   return (FunctionDescriptor) context.get(DECLARATION_TO_DESCRIPTOR, function);
 }
Esempio n. 9
0
 @Nullable
 public static ResolvedCall<ConstructorDescriptor> getDelegationConstructorCall(
     @NotNull BindingContext bindingContext,
     @NotNull ConstructorDescriptor constructorDescriptor) {
   return bindingContext.get(CONSTRUCTOR_RESOLVED_DELEGATION_CALL, constructorDescriptor);
 }