use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method createMethodDeclarationEdit.
protected void createMethodDeclarationEdit(DocumentRewriter.Section declarationSection, int expressionIndentLevel, ITextRegion expressionsRegion) throws BadLocationException {
String expressionsAsString = getExtractedMethodBody(expressionsRegion);
declarationSection.newLine().newLine();
appendMethodSignature(declarationSection);
if (firstExpression.eContainer() instanceof RichString && !isRichStringXExpressionOrVarDeclaration()) {
declarationSection.increaseIndentation().newLine().append("'''");
} else {
declarationSection.append(" {").increaseIndentation().newLine();
}
declarationSection.append(expressionsAsString, Math.min(0, -expressionIndentLevel));
if (isNeedsReturnExpression())
declarationSection.newLine().append(((XFeatureCall) returnExpression).getFeature().getSimpleName());
if (firstExpression.eContainer() instanceof RichString && !isRichStringXExpressionOrVarDeclaration()) {
declarationSection.append("'''").decreaseIndentation().newLine();
} else {
declarationSection.decreaseIndentation().newLine().append("}");
}
}
use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.
the class XtendTypeComputer method _computeTypes.
protected void _computeTypes(RichString object, ITypeComputationState state) {
List<XExpression> expressions = object.getExpressions();
if (!expressions.isEmpty()) {
for (XExpression expression : expressions) {
ITypeComputationState expressionState = state.withoutExpectation();
expressionState.computeTypes(expression);
if (expression instanceof XVariableDeclaration) {
addLocalToCurrentScope((XVariableDeclaration) expression, state);
}
}
}
for (ITypeExpectation expectation : state.getExpectations()) {
LightweightTypeReference expectedType = expectation.getExpectedType();
if (expectedType != null && expectedType.isType(StringConcatenation.class)) {
expectation.acceptActualType(expectedType, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION);
} else if (expectedType != null && expectedType.isType(StringConcatenationClient.class)) {
expectation.acceptActualType(expectedType, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION);
} else if (expectedType != null && expectedType.isType(String.class)) {
expectation.acceptActualType(expectedType, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION);
// TODO this special treatment here should become obsolete as soon as the expectations are properly propagated
} else if (!(object.eContainer() instanceof XCastedExpression) && object.eContainingFeature() != XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET && (expectedType != null && !expectedType.isResolved() || expectedType == null && !expectation.isVoidTypeAllowed())) {
LightweightTypeReference type = getRawTypeForName(String.class, state);
expectation.acceptActualType(type, ConformanceFlags.UNCHECKED | ConformanceFlags.DEMAND_CONVERSION);
} else {
LightweightTypeReference type = getRawTypeForName(CharSequence.class, state);
expectation.acceptActualType(type, ConformanceFlags.UNCHECKED);
}
}
}
use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method createMethodCallEdit.
protected void createMethodCallEdit(DocumentRewriter.Section methodCallSection, ITextRegion expressionRegion) throws BadLocationException {
if (firstExpression.eContainer() instanceof RichString) {
methodCallSection.append("�");
}
if (isNeedsReturnExpression()) {
JvmIdentifiableElement returnFeature = ((XFeatureCall) returnExpression).getFeature();
if (isFinalFeature(returnFeature))
methodCallSection.append("val ");
else
methodCallSection.append("var ");
methodCallSection.append(returnFeature.getSimpleName()).append(" = ");
}
boolean needsSurroundingParentheses = false;
if (firstExpression.eContainer() instanceof XMemberFeatureCall) {
if (((XMemberFeatureCall) firstExpression.eContainer()).getMemberCallArguments().size() == 1) {
String expressionExpanded = document.get(expressionRegion.getOffset() - 1, expressionRegion.getLength() + 2);
if (!expressionExpanded.startsWith("(") || !expressionExpanded.endsWith(")")) {
needsSurroundingParentheses = true;
methodCallSection.append("(");
}
}
}
methodCallSection.append(methodName).append("(");
boolean isFirst = true;
for (ParameterInfo parameterInfo : getParameterInfos()) {
if (!isFirst)
methodCallSection.append(", ");
isFirst = false;
methodCallSection.append(parameterInfo.getOldName());
}
methodCallSection.append(")");
if (needsSurroundingParentheses)
methodCallSection.append(")");
if (lastExpression.eContainer() instanceof RichString) {
methodCallSection.append("�");
}
}
use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.
the class JavaConverterTest method testRichStringSpecialCase3.
@Test
public void testRichStringSpecialCase3() throws Exception {
XtendClass clazz = this.toValidXtendClass("class Z {String richTxt = \"x(p1)} def dispatch x(int s) {\'int\'} def dispatch x(boolean s)\"+\" {\'boolean\'} def dispatch x(double s) {\'double\'\";}");
Assert.assertNotNull(clazz);
XtendMember _get = clazz.getMembers().get(0);
XtendField xtendMember = ((XtendField) _get);
Assert.assertEquals("richTxt", xtendMember.getName());
XExpression _initialValue = xtendMember.getInitialValue();
Assert.assertTrue((_initialValue instanceof RichString));
}
use of org.eclipse.xtend.core.xtend.RichString in project xtext-xtend by eclipse.
the class ParserTest method testRichString_00.
@Test
public void testRichString_00() throws Exception {
XtendFunction function = function("def foo() ''' foo '''");
assertTrue(function.getExpression() instanceof RichString);
RichString richString = (RichString) function.getExpression();
assertEquals(1, richString.getExpressions().size());
RichStringLiteral stringLiteral = (RichStringLiteral) richString.getExpressions().get(0);
assertEquals(" foo ", stringLiteral.getValue());
}
Aggregations