use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.
the class CompileKotlinAgainstCustomBinariesTest method testDuplicateObjectInBinaryAndSources.
public void testDuplicateObjectInBinaryAndSources() throws Exception {
Collection<DeclarationDescriptor> allDescriptors = analyzeAndGetAllDescriptors(compileLibrary("library"));
assertEquals(allDescriptors.toString(), 2, allDescriptors.size());
for (DeclarationDescriptor descriptor : allDescriptors) {
assertTrue("Wrong name: " + descriptor, descriptor.getName().asString().equals("Lol"));
assertTrue("Should be an object: " + descriptor, isObject(descriptor));
}
}
use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.
the class KotlinOverridingDialog method formatElement.
private static String formatElement(PsiElement element) {
element = KtPsiUtil.ascendIfPropertyAccessor(element);
if (element instanceof KtNamedFunction || element instanceof KtProperty) {
BindingContext bindingContext = ResolutionUtils.analyze((KtElement) element, BodyResolveMode.FULL);
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
if (declarationDescriptor instanceof CallableMemberDescriptor) {
DeclarationDescriptor containingDescriptor = declarationDescriptor.getContainingDeclaration();
if (containingDescriptor instanceof ClassDescriptor) {
return KotlinBundle.message("x.in.y", DescriptorRenderer.COMPACT.render(declarationDescriptor), IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.render(containingDescriptor));
}
}
}
assert element instanceof PsiMethod : "Method accepts only kotlin functions/properties and java methods, but '" + element.getText() + "' was found";
return RenderingUtilsKt.formatPsiMethod((PsiMethod) element, true, false);
}
use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.
the class JsInliner method inline.
private void inline(@NotNull JsInvocation call, @NotNull JsContext context) {
DeclarationDescriptor callDescriptor = MetadataProperties.getDescriptor(call);
if (isSuspendWithCurrentContinuation(callDescriptor)) {
inlineSuspendWithCurrentContinuation(call, context);
return;
}
JsInliningContext inliningContext = getInliningContext();
InlineableResult inlineableResult = getInlineableCallReplacement(call, inliningContext);
JsStatement inlineableBody = inlineableResult.getInlineableBody();
JsExpression resultExpression = inlineableResult.getResultExpression();
JsContext<JsStatement> statementContext = inliningContext.getStatementContext();
// body of inline function can contain call to lambdas that need to be inlined
JsStatement inlineableBodyWithLambdasInlined = accept(inlineableBody);
assert inlineableBody == inlineableBodyWithLambdasInlined;
statementContext.addPrevious(flattenStatement(inlineableBody));
/*
* Assumes, that resultExpression == null, when result is not needed.
* @see FunctionInlineMutator.isResultNeeded()
*/
if (resultExpression == null) {
statementContext.removeMe();
return;
}
resultExpression = accept(resultExpression);
MetadataProperties.setSynthetic(resultExpression, true);
context.replaceMe(resultExpression);
}
use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.
the class BuiltInsReferenceResolverTest method getAllStandardDescriptors.
private static Collection<DeclarationDescriptor> getAllStandardDescriptors() {
final List<DeclarationDescriptor> descriptors = new ArrayList<DeclarationDescriptor>();
PackageFragmentDescriptor builtinsPackageFragment = DefaultBuiltIns.getInstance().getBuiltInsPackageFragment();
for (DeclarationDescriptor packageMember : DescriptorUtils.getAllDescriptors(builtinsPackageFragment.getMemberScope())) {
packageMember.acceptVoid(new DeclarationDescriptorVisitorEmptyBodies<Void, Void>() {
@Override
public Void visitClassDescriptor(ClassDescriptor descriptor, Void data) {
descriptors.add(descriptor);
for (DeclarationDescriptor classMember : DescriptorUtils.getAllDescriptors(descriptor.getDefaultType().getMemberScope())) {
classMember.acceptVoid(this);
}
return null;
}
@Override
public Void visitDeclarationDescriptor(DeclarationDescriptor descriptor, Void data) {
descriptors.add(descriptor);
return null;
}
});
}
return descriptors;
}
use of org.jetbrains.kotlin.descriptors.DeclarationDescriptor in project kotlin by JetBrains.
the class AssignmentTranslator method isReferenceToBackingFieldFromConstructor.
private static boolean isReferenceToBackingFieldFromConstructor(@NotNull KtExpression expression, @NotNull TranslationContext context) {
if (expression instanceof KtSimpleNameExpression) {
KtSimpleNameExpression nameExpression = (KtSimpleNameExpression) expression;
DeclarationDescriptor descriptor = getDescriptorForReferenceExpression(context.bindingContext(), nameExpression);
return isReferenceToBackingFieldFromConstructor(descriptor, context);
} else if (expression instanceof KtDotQualifiedExpression) {
KtDotQualifiedExpression qualifiedExpression = (KtDotQualifiedExpression) expression;
if (qualifiedExpression.getReceiverExpression() instanceof KtThisExpression && qualifiedExpression.getSelectorExpression() instanceof KtSimpleNameExpression) {
KtSimpleNameExpression nameExpression = (KtSimpleNameExpression) qualifiedExpression.getSelectorExpression();
DeclarationDescriptor descriptor = getDescriptorForReferenceExpression(context.bindingContext(), nameExpression);
return isReferenceToBackingFieldFromConstructor(descriptor, context);
}
}
return false;
}
Aggregations