use of org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newLocalVariableQuickfix.
protected void newLocalVariableQuickfix(final String variableName, XAbstractFeatureCall call, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
LightweightTypeReference variableType = getNewMemberType(call);
final StringBuilderBasedAppendable localVarDescriptionBuilder = new StringBuilderBasedAppendable();
localVarDescriptionBuilder.append("...").newLine();
final String defaultValueLiteral = getDefaultValueLiteral(variableType);
localVarDescriptionBuilder.append("val ").append(variableName).append(" = ").append(defaultValueLiteral);
localVarDescriptionBuilder.newLine().append("...");
issueResolutionAcceptor.accept(issue, "Create local variable '" + variableName + "'", localVarDescriptionBuilder.toString(), "fix_local_var.png", new SemanticModificationWrapper(issue.getUriToProblem(), new ISemanticModification() {
@Override
public void apply(/* @Nullable */
final EObject element, /* @Nullable */
final IModificationContext context) throws Exception {
if (element != null) {
XtendMember xtendMember = EcoreUtil2.getContainerOfType(element, XtendMember.class);
if (xtendMember != null) {
int offset = getFirstOffsetOfKeyword(xtendMember, "{");
IXtextDocument xtextDocument = context.getXtextDocument();
if (offset != -1 && xtextDocument != null) {
final ReplacingAppendable appendable = appendableFactory.create(xtextDocument, (XtextResource) element.eResource(), offset, 0, new OptionalParameters() {
{
baseIndentationLevel = 1;
}
});
appendable.increaseIndentation().newLine().append("val ").append(variableName).append(" = ").append(defaultValueLiteral);
appendable.commitChanges();
}
}
}
}
}));
}
use of org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method getMethodSignature.
public String getMethodSignature() {
StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
appendMethodSignature(appendable);
return appendable.toString();
}
use of org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newLocalVariableQuickfix.
protected void newLocalVariableQuickfix(final String variableName, boolean isFinal, XAbstractFeatureCall call, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
LightweightTypeReference variableType = getNewMemberType(call);
final StringBuilderBasedAppendable localVarDescriptionBuilder = new StringBuilderBasedAppendable();
localVarDescriptionBuilder.append("...").newLine();
final String defaultValueLiteral = getDefaultValueLiteral(variableType);
localVarDescriptionBuilder.append(isFinal ? "val " : "var ").append(variableName).append(" = ").append(defaultValueLiteral);
localVarDescriptionBuilder.newLine().append("...");
issueResolutionAcceptor.accept(issue, "Create local " + (isFinal ? "value" : "variable") + " '" + variableName + "'", localVarDescriptionBuilder.toString(), "fix_local_var.png", new SemanticModificationWrapper(issue.getUriToProblem(), new ISemanticModification() {
@Override
public void apply(/* @Nullable */
final EObject element, /* @Nullable */
final IModificationContext context) throws Exception {
if (element != null) {
XtendMember xtendMember = EcoreUtil2.getContainerOfType(element, XtendMember.class);
if (xtendMember != null) {
int offset = getFirstOffsetOfKeyword(xtendMember, "{");
IXtextDocument xtextDocument = context.getXtextDocument();
if (offset != -1 && xtextDocument != null) {
final ReplacingAppendable appendable = appendableFactory.create(xtextDocument, (XtextResource) element.eResource(), offset, 0, new OptionalParameters() {
{
baseIndentationLevel = 1;
}
});
appendable.increaseIndentation().newLine().append(isFinal ? "val " : "var ").append(variableName).append(" = ").append(defaultValueLiteral);
appendable.commitChanges();
}
}
}
}
}));
}
use of org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable in project xtext-xtend by eclipse.
the class CompilationContextImpl method toJavaCode.
@Override
public String toJavaCode(final TypeReference typeref) {
StringBuilderBasedAppendable _xifexpression = null;
if ((this.importManager != null)) {
_xifexpression = new StringBuilderBasedAppendable(this.importManager);
} else {
_xifexpression = new StringBuilderBasedAppendable();
}
final StringBuilderBasedAppendable appendable = _xifexpression;
final LightweightTypeReference typeRef = this.compilationUnit.toLightweightTypeReference(typeref);
appendable.append(typeRef);
return appendable.toString();
}
use of org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable in project xtext-xtend by eclipse.
the class SuperMemberImplementorTest method checkImplementConstructor.
protected void checkImplementConstructor(final String firstParamType, String implementCode) {
StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
JvmConstructor constructor = Iterables.find(superClass.getDeclaredConstructors(), new Predicate<JvmConstructor>() {
@Override
public boolean apply(JvmConstructor c) {
if (firstParamType == null)
return c.getParameters().isEmpty();
if (c.getParameters().size() >= 1) {
return firstParamType.equals(c.getParameters().get(0).getParameterType().getSimpleName());
}
return false;
}
});
LightweightTypeReference contextType = getContextType();
ResolvedConstructor resolvedConstructor = new ResolvedConstructor(constructor, contextType);
implementor.appendConstructorFromSuper(xtendClass, resolvedConstructor, appendable);
String code = appendable.toString();
if (!equalsIgnoreWhitespace(implementCode, code))
assertEquals(implementCode, code);
}
Aggregations