Search in sources :

Example 1 with ConversionResult

use of org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult in project intellij-community by JetBrains.

the class GroovyTypeCheckVisitor method processAssignment.

private void processAssignment(@NotNull PsiType lType, @Nullable PsiType rType, @NotNull GroovyPsiElement context, @NotNull PsiElement elementToHighlight) {
    if (rType == null)
        return;
    final ConversionResult result = TypesUtil.canAssign(lType, rType, context, ApplicableTo.ASSIGNMENT);
    processResult(result, elementToHighlight, "cannot.assign", lType, rType);
}
Also used : ConversionResult(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult)

Example 2 with ConversionResult

use of org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult in project intellij-community by JetBrains.

the class GroovyTypeCheckVisitor method processAssignment.

private void processAssignment(@NotNull PsiType expectedType, @NotNull GrExpression expression, @NotNull PsiElement toHighlight, @NotNull @PropertyKey(resourceBundle = GroovyBundle.BUNDLE) String messageKey, @NotNull PsiElement context, @NotNull ApplicableTo position) {
    {
        // check if  current assignment is constructor call
        final GrListOrMap initializer = getTupleInitializer(expression);
        if (initializer != null) {
            processConstructorCall(new GrListOrMapInfo(initializer));
            return;
        }
    }
    if (PsiUtil.isRawClassMemberAccess(expression))
        return;
    if (checkForImplicitEnumAssigning(expectedType, expression, expression))
        return;
    final PsiType actualType = expression.getType();
    if (actualType == null)
        return;
    final ConversionResult result = TypesUtil.canAssign(expectedType, actualType, context, position);
    if (result == ConversionResult.OK)
        return;
    final List<LocalQuickFix> fixes = ContainerUtil.newArrayList();
    {
        fixes.add(new GrCastFix(expectedType, expression));
        final String varName = getLValueVarName(toHighlight);
        if (varName != null) {
            fixes.add(new GrChangeVariableType(actualType, varName));
        }
    }
    final String message = GroovyBundle.message(messageKey, actualType.getPresentableText(), expectedType.getPresentableText());
    registerError(toHighlight, message, fixes.toArray(new LocalQuickFix[fixes.size()]), result == ConversionResult.ERROR ? ProblemHighlightType.GENERIC_ERROR : ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
Also used : ConversionResult(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) GrListOrMap(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)

Example 3 with ConversionResult

use of org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult in project intellij-community by JetBrains.

the class GroovyTypeCheckVisitor method visitCastExpression.

@Override
public void visitCastExpression(@NotNull GrTypeCastExpression expression) {
    super.visitCastExpression(expression);
    final GrExpression operand = expression.getOperand();
    if (operand == null)
        return;
    final PsiType actualType = operand.getType();
    if (actualType == null)
        return;
    if (expression.getCastTypeElement() == null)
        return;
    final PsiType expectedType = expression.getCastTypeElement().getType();
    final ConversionResult result = TypesUtil.canCast(expectedType, actualType, expression);
    if (result == ConversionResult.OK)
        return;
    final ProblemHighlightType highlightType = result == ConversionResult.ERROR ? ProblemHighlightType.GENERIC_ERROR : ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
    final String message = GroovyBundle.message("cannot.cast", actualType.getPresentableText(), expectedType.getPresentableText());
    registerError(expression, highlightType, message);
}
Also used : ConversionResult(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString) ProblemHighlightType(com.intellij.codeInspection.ProblemHighlightType)

Example 4 with ConversionResult

use of org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult in project intellij-community by JetBrains.

the class GroovyTypeCheckVisitor method processAssignmentWithinMultipleAssignment.

protected void processAssignmentWithinMultipleAssignment(@NotNull GrExpression lhs, @NotNull GrExpression rhs, @NotNull GrExpression context) {
    final PsiType targetType = lhs.getType();
    final PsiType actualType = rhs.getType();
    if (targetType == null || actualType == null)
        return;
    final ConversionResult result = TypesUtil.canAssignWithinMultipleAssignment(targetType, actualType, context);
    if (result == ConversionResult.OK)
        return;
    registerError(rhs, GroovyBundle.message("cannot.assign", actualType.getPresentableText(), targetType.getPresentableText()), LocalQuickFix.EMPTY_ARRAY, result == ConversionResult.ERROR ? ProblemHighlightType.GENERIC_ERROR : ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
Also used : ConversionResult(org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult)

Aggregations

ConversionResult (org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.ConversionResult)4 GrString (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemHighlightType (com.intellij.codeInspection.ProblemHighlightType)1 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)1