Search in sources :

Example 1 with SubtypeConstraint

use of org.jetbrains.plugins.groovy.lang.psi.expectedTypes.SubtypeConstraint in project intellij-community by JetBrains.

the class ChooseTypeExpression method createItems.

@NotNull
private static List<SmartTypePointer> createItems(@NotNull TypeConstraint[] constraints, @NotNull SmartTypePointerManager typePointerManager) {
    List<SmartTypePointer> result = ContainerUtil.newArrayList();
    for (TypeConstraint constraint : constraints) {
        if (constraint instanceof SubtypeConstraint) {
            PsiType type = constraint.getDefaultType();
            result.add(typePointerManager.createSmartTypePointer(type));
        } else if (constraint instanceof SupertypeConstraint) {
            processSuperTypes(constraint.getType(), result, typePointerManager);
        }
    }
    return result;
}
Also used : SubtypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.SubtypeConstraint) SupertypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.SupertypeConstraint) TypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.TypeConstraint) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SubtypeConstraint

use of org.jetbrains.plugins.groovy.lang.psi.expectedTypes.SubtypeConstraint in project intellij-community by JetBrains.

the class ExpressionGenerator method visitLiteralExpression.

@Override
public //doesn't visit GrString and regexps
void visitLiteralExpression(@NotNull GrLiteral literal) {
    final TypeConstraint[] constraints = GroovyExpectedTypesProvider.calculateTypeConstraints(literal);
    boolean isChar = false;
    for (TypeConstraint constraint : constraints) {
        if (constraint instanceof SubtypeConstraint && PsiType.CHAR.equals(TypesUtil.unboxPrimitiveTypeWrapper(constraint.getDefaultType()))) {
            isChar = true;
        }
    }
    final String text = literal.getText();
    if (text.startsWith("'''") || text.startsWith("\"\"\"")) {
        String string = GrStringUtil.removeQuotes(text).replace("\n", "\\n").replace("\r", "\\r");
        builder.append('"').append(string).append('"');
    } else if (text.startsWith("'")) {
        if (isChar) {
            builder.append(text);
        } else {
            builder.append('"').append(StringUtil.escapeQuotes(StringUtil.trimEnd(text.substring(1, text.length()), "'"))).append('"');
        }
    } else if (text.startsWith("\"")) {
        if (isChar) {
            builder.append('\'').append(StringUtil.escapeQuotes(StringUtil.trimEnd(text.substring(1, text.length()), "\""))).append('\'');
        } else {
            builder.append(text);
        }
    } else {
        builder.append(text);
    }
}
Also used : SubtypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.SubtypeConstraint) TypeConstraint(org.jetbrains.plugins.groovy.lang.psi.expectedTypes.TypeConstraint) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)

Aggregations

SubtypeConstraint (org.jetbrains.plugins.groovy.lang.psi.expectedTypes.SubtypeConstraint)2 TypeConstraint (org.jetbrains.plugins.groovy.lang.psi.expectedTypes.TypeConstraint)2 NotNull (org.jetbrains.annotations.NotNull)1 GrString (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)1 SupertypeConstraint (org.jetbrains.plugins.groovy.lang.psi.expectedTypes.SupertypeConstraint)1