use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class WhenTranslator method isExhaustive.
private boolean isExhaustive() {
KotlinType type = bindingContext().getType(whenExpression);
boolean isStatement = type != null && KotlinBuiltIns.isUnit(type) && !type.isMarkedNullable();
return CodegenUtil.isExhaustive(bindingContext(), whenExpression, isStatement);
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class WhenTranslator method translateExpressionCondition.
@NotNull
private JsExpression translateExpressionCondition(@NotNull KtWhenConditionWithExpression condition, @NotNull TranslationContext context) {
KtExpression patternExpression = condition.getExpression();
assert patternExpression != null : "Expression pattern should have an expression.";
JsExpression expressionToMatch = getExpressionToMatch();
if (expressionToMatch == null) {
return Translation.patternTranslator(context).translateExpressionForExpressionPattern(patternExpression);
} else {
KtExpression subject = whenExpression.getSubjectExpression();
assert subject != null : "Subject must be non-null since expressionToMatch is non-null: " + PsiUtilsKt.getTextWithLocation(condition);
KotlinType type = BindingUtils.getTypeForExpression(bindingContext(), whenExpression.getSubjectExpression());
return Translation.patternTranslator(context).translateExpressionPattern(type, expressionToMatch, patternExpression);
}
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class JetTestFunctionDetector method isTest.
private static boolean isTest(@NotNull FunctionDescriptor functionDescriptor) {
Annotations annotations = functionDescriptor.getAnnotations();
for (AnnotationDescriptor annotation : annotations) {
// TODO ideally we should find the fully qualified name here...
KotlinType type = annotation.getType();
String name = type.toString();
if (name.equals("Test")) {
return true;
}
}
/*
if (function.getName().startsWith("test")) {
List<JetParameter> parameters = function.getValueParameters();
return parameters.size() == 0;
}
*/
return false;
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class Translation method translateExpression.
@NotNull
public static JsNode translateExpression(@NotNull KtExpression expression, @NotNull TranslationContext context, @NotNull JsBlock block) {
JsExpression aliasForExpression = context.aliasingContext().getAliasForExpression(expression);
if (aliasForExpression != null) {
return aliasForExpression;
}
CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, context.bindingContext());
if (compileTimeValue != null) {
KotlinType type = context.bindingContext().getType(expression);
if (type != null) {
if (KotlinBuiltIns.isLong(type) || (KotlinBuiltIns.isInt(type) && expression instanceof KtUnaryExpression)) {
JsExpression constantResult = translateConstant(compileTimeValue, expression, context);
if (constantResult != null)
return constantResult;
}
}
}
TranslationContext innerContext = context.innerBlock();
JsNode result = doTranslateExpression(expression, innerContext);
context.moveVarsFrom(innerContext);
block.getStatements().addAll(innerContext.dynamicContext().jsBlock().getStatements());
return result;
}
use of org.jetbrains.kotlin.types.KotlinType in project kotlin by JetBrains.
the class Translation method translateAsExpression.
@NotNull
public static JsExpression translateAsExpression(@NotNull KtExpression expression, @NotNull TranslationContext context, @NotNull JsBlock block) {
JsNode jsNode = translateExpression(expression, context, block);
if (jsNode instanceof JsExpression) {
KotlinType expressionType = context.bindingContext().getType(expression);
return unboxIfNeeded((JsExpression) jsNode, expressionType != null && KotlinBuiltIns.isCharOrNullableChar(expressionType));
}
assert jsNode instanceof JsStatement : "Unexpected node of type: " + jsNode.getClass().toString();
if (BindingContextUtilsKt.isUsedAsExpression(expression, context.bindingContext())) {
TemporaryVariable result = context.declareTemporary(null);
AssignToExpressionMutator saveResultToTemporaryMutator = new AssignToExpressionMutator(result.reference());
block.getStatements().add(mutateLastExpression(jsNode, saveResultToTemporaryMutator));
return result.reference();
}
block.getStatements().add(convertToStatement(jsNode));
return JsLiteral.NULL;
}
Aggregations