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;
}
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);
}
}
Aggregations