
org.jetbrains.jet.lang.resolve.BindingContext Maven / Gradle / Ivy
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.ImmutableMap;
import com.intellij.psi.PsiElement;
import jet.runtime.typeinfo.KotlinSignature;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.ReadOnly;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.TailRecursionKind;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.expressions.CaptureKind;
import org.jetbrains.jet.util.Box;
import org.jetbrains.jet.util.slicedmap.*;
import java.util.Collection;
import java.util.Collections;
import static org.jetbrains.jet.util.slicedmap.RewritePolicy.DO_NOTHING;
public interface BindingContext {
BindingContext EMPTY = new BindingContext() {
@NotNull
@Override
public Diagnostics getDiagnostics() {
return Diagnostics.EMPTY;
}
@Override
public V get(ReadOnlySlice slice, K key) {
return null;
}
@NotNull
@Override
public Collection getKeys(WritableSlice slice) {
return Collections.emptyList();
}
@NotNull
@TestOnly
@Override
public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) {
return ImmutableMap.of();
}
};
WritableSlice ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT = Slices.createSimpleSlice();
WritableSlice ANNOTATION =
Slices.sliceBuilder().setOpposite(ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT).build();
WritableSlice> COMPILE_TIME_VALUE = Slices.createSimpleSlice();
WritableSlice TYPE = Slices.createSimpleSlice();
WritableSlice EXPRESSION_TYPE = new BasicWritableSlice(DO_NOTHING);
WritableSlice EXPECTED_EXPRESSION_TYPE = new BasicWritableSlice(DO_NOTHING);
WritableSlice EXPRESSION_DATA_FLOW_INFO = new BasicWritableSlice(DO_NOTHING);
WritableSlice DATAFLOW_INFO_AFTER_CONDITION = Slices.createSimpleSlice();
WritableSlice REFERENCE_TARGET =
new BasicWritableSlice(DO_NOTHING);
@KotlinSignature("val RESOLVED_CALL: WritableSlice>")
WritableSlice> RESOLVED_CALL = new BasicWritableSlice>(DO_NOTHING);
WritableSlice, TailRecursionKind> TAIL_RECURSION_CALL = Slices.createSimpleSlice();
WritableSlice CONSTRAINT_SYSTEM_COMPLETER = new BasicWritableSlice(DO_NOTHING);
WritableSlice CALL = new BasicWritableSlice(DO_NOTHING);
@KotlinSignature("val AMBIGUOUS_REFERENCE_TARGET: WritableSlice>")
WritableSlice> AMBIGUOUS_REFERENCE_TARGET =
new BasicWritableSlice>(DO_NOTHING);
WritableSlice TRACE_DELTAS_CACHE = Slices.createSimpleSlice();
WritableSlice> LOOP_RANGE_ITERATOR_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice LOOP_RANGE_ITERATOR_CALL = Slices.createSimpleSlice();
WritableSlice> LOOP_RANGE_HAS_NEXT_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice> LOOP_RANGE_NEXT_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice> DELEGATED_PROPERTY_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice DELEGATED_PROPERTY_CALL = Slices.createSimpleSlice();
WritableSlice> COMPONENT_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice> INDEXED_LVALUE_GET = Slices.createSimpleSlice();
WritableSlice> INDEXED_LVALUE_SET = Slices.createSimpleSlice();
WritableSlice AUTOCAST = Slices.createSimpleSlice();
WritableSlice EXHAUSTIVE_WHEN = Slices.createSimpleSlice();
/**
* A scope where type of expression has been resolved
*/
WritableSlice TYPE_RESOLUTION_SCOPE = Slices.createSimpleSlice();
WritableSlice RESOLUTION_SCOPE = Slices.createSimpleSlice();
WritableSlice SCRIPT_SCOPE = Slices.createSimpleSlice();
/**
* Collected during analyze, used in IDE in auto-cast completion
*/
WritableSlice NON_DEFAULT_EXPRESSION_DATA_FLOW = Slices.createSimpleSlice();
WritableSlice VARIABLE_REASSIGNMENT = Slices.createSimpleSetSlice();
WritableSlice AUTO_CREATED_IT = Slices.createSimpleSetSlice();
/**
* Has type of current expression has been already resolved
*/
WritableSlice PROCESSED = Slices.createSimpleSetSlice();
WritableSlice STATEMENT = Slices.createRemovableSetSlice();
WritableSlice CAPTURED_IN_CLOSURE = new BasicWritableSlice(DO_NOTHING);
WritableSlice NEED_SYNTHETIC_ACCESSOR = new BasicWritableSlice(DO_NOTHING);
WritableSlice, Boolean> DEFERRED_TYPE = Slices.createCollectiveSetSlice();
WritableSlice BACKING_FIELD_REQUIRED = new Slices.SetSlice(DO_NOTHING) {
@Override
public Boolean computeValue(
SlicedMap map,
PropertyDescriptor propertyDescriptor,
Boolean backingFieldRequired,
boolean valueNotFound
) {
if (propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
return false;
}
backingFieldRequired = valueNotFound ? false : backingFieldRequired;
assert backingFieldRequired != null;
// TODO: user BindingContextAccessors
PsiElement declarationPsiElement = map.get(BindingContextUtils.DESCRIPTOR_TO_DECLARATION, propertyDescriptor);
if (declarationPsiElement instanceof JetParameter) {
JetParameter jetParameter = (JetParameter) declarationPsiElement;
return jetParameter.getValOrVarNode() != null ||
backingFieldRequired; // this part is unused because we do not allow access to constructor parameters in member bodies
}
if (propertyDescriptor.getModality() == Modality.ABSTRACT) return false;
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
if (getter == null) {
return true;
}
else if (propertyDescriptor.isVar() && setter == null) {
return true;
}
else if (setter != null && !setter.hasBody() && setter.getModality() != Modality.ABSTRACT) {
return true;
}
else if (!getter.hasBody() && getter.getModality() != Modality.ABSTRACT) {
return true;
}
return backingFieldRequired;
}
};
WritableSlice IS_INITIALIZED = Slices.createSimpleSetSlice();
WritableSlice BLOCK = new Slices.SetSlice(DO_NOTHING) {
@Override
public Boolean computeValue(SlicedMap map, JetFunctionLiteralExpression expression, Boolean isBlock, boolean valueNotFound) {
isBlock = valueNotFound ? false : isBlock;
assert isBlock != null;
return isBlock && !expression.getFunctionLiteral().hasParameterSpecification();
}
};
WritableSlice CLASS =
Slices.sliceBuilder().setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION)
.build();
WritableSlice SCRIPT =
Slices.sliceBuilder().setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION)
.build();
WritableSlice TYPE_PARAMETER =
Slices.sliceBuilder()
.setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION).build();
/**
* @see BindingContextUtils#recordFunctionDeclarationToDescriptor(BindingTrace, PsiElement, SimpleFunctionDescriptor)}
*/
WritableSlice FUNCTION = Slices.sliceBuilder()
.setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION).build();
WritableSlice CONSTRUCTOR = Slices.sliceBuilder()
.setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION).build();
WritableSlice VARIABLE =
Slices.sliceBuilder().setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION)
.build();
WritableSlice VALUE_PARAMETER = Slices.sliceBuilder()
.setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION).build();
WritableSlice PROPERTY_ACCESSOR =
Slices.sliceBuilder()
.setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION).build();
// normalize value to getOriginal(value)
WritableSlice PRIMARY_CONSTRUCTOR_PARAMETER =
Slices.sliceBuilder().setOpposite((WritableSlice) BindingContextUtils.DESCRIPTOR_TO_DECLARATION)
.build();
WritableSlice[] DECLARATIONS_TO_DESCRIPTORS = new WritableSlice[] {
CLASS, TYPE_PARAMETER, FUNCTION, CONSTRUCTOR, VARIABLE, VALUE_PARAMETER, PROPERTY_ACCESSOR,
PRIMARY_CONSTRUCTOR_PARAMETER
};
ReadOnlySlice DECLARATION_TO_DESCRIPTOR = Slices.sliceBuilder()
.setFurtherLookupSlices(DECLARATIONS_TO_DESCRIPTORS).build();
WritableSlice LABEL_TARGET = Slices.sliceBuilder().build();
@KotlinSignature("val AMBIGUOUS_LABEL_TARGET: WritableSlice>")
WritableSlice> AMBIGUOUS_LABEL_TARGET =
Slices.>sliceBuilder().build();
WritableSlice VALUE_PARAMETER_AS_PROPERTY =
Slices.sliceBuilder().build();
WritableSlice DATA_CLASS_COMPONENT_FUNCTION =
Slices.sliceBuilder().build();
WritableSlice DATA_CLASS_COPY_FUNCTION =
Slices.sliceBuilder().build();
WritableSlice FQNAME_TO_CLASS_DESCRIPTOR = new BasicWritableSlice(DO_NOTHING, true);
WritableSlice FILE_TO_PACKAGE_FRAGMENT = Slices.createSimpleSlice();
WritableSlice> PACKAGE_TO_FILES = Slices.createSimpleSlice();
WritableSlice INCOMPLETE_HIERARCHY = Slices.createCollectiveSetSlice();
@SuppressWarnings("UnusedDeclaration")
@Deprecated // This field is needed only for the side effects of its initializer
Void _static_initializer = BasicWritableSlice.initSliceDebugNames(BindingContext.class);
@NotNull
Diagnostics getDiagnostics();
@Nullable
V get(ReadOnlySlice slice, K key);
// slice.isCollective() must be true
@NotNull
@ReadOnly
Collection getKeys(WritableSlice slice);
/** This method should be used only for debug and testing */
@TestOnly
@NotNull
ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy