Java Code Examples for org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable

The following examples show how to use org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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);
}
 
Example 2
protected void checkOverrideMethodCode(String operationName, String overrideCode) {
	StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
	LightweightTypeReference contextType = getContextType();
	IResolvedOperation resolvedOperation = new BottomResolvedOperation((JvmOperation) findExecutable(implementedInterface, operationName), contextType, new OverrideTester());
	implementor.appendOverrideFunction(xtendClass, resolvedOperation, appendable);
	String code = appendable.toString();
	if (!equalsIgnoreWhitespace(overrideCode, code))
		assertEquals(overrideCode, code);
}
 
Example 3
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();
							}
						}
					}
				}
			}));
}
 
Example 4
Source Project: xtext-xtend   Source File: AbstractCodeBuilder.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String getPreview() {
  String _xblockexpression = null;
  {
    final StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
    this.build(appendable.append("...").newLine()).newLine().append("...");
    _xblockexpression = appendable.toString();
  }
  return _xblockexpression;
}
 
Example 5
protected String _getStringRepresentation(LightweightTypeReference object) {
	StringBuilderBasedAppendable appender = new StringBuilderBasedAppendable(importManager);
	LightweightTypeReferenceSerializer serializer = new LightweightTypeReferenceSerializer(appender);
	object.accept(serializer);
	return appender.toString();
}
 
Example 6
Source Project: xtext-xtend   Source File: AbstractBuilderTest.java    License: Eclipse Public License 2.0 4 votes vote down vote up
protected void assertBuilds(final ICodeBuilder builder, final String expectedCode) {
  Assert.assertTrue(builder.isValid());
  final StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
  builder.build(appendable);
  Assert.assertEquals(Strings.toUnixLineSeparator(expectedCode), appendable.toString());
}
 
Example 7
public String getMethodSignature() {
	StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
	appendMethodSignature(appendable);
	return appendable.toString();
}
 
Example 8
Source Project: sarl   Source File: DocumentationFormatter.java    License: Apache License 2.0 4 votes vote down vote up
@Pure
public String formatMultilineComment(String doc, String indentation) {
	IAppendable appendable = new StringBuilderBasedAppendable();
	formatMultilineComment(doc, indentation, appendable);
	return appendable.getContent();
}
 
Example 9
Source Project: sarl   Source File: DocumentationFormatter.java    License: Apache License 2.0 4 votes vote down vote up
@Pure
	public String formatSinglelineComment(String doc, String indentation) {
	StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
	formatSinglelineComment(doc, indentation, appendable);
	return appendable.getContent();
}