Search in sources :

Example 6 with StringBuilderBasedAppendable

use of org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable in project xtext-xtend by eclipse.

the class SuperMemberImplementorTest method checkOverrideMethodCode.

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);
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) StringBuilderBasedAppendable(org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable) OverrideTester(org.eclipse.xtext.xbase.typesystem.override.OverrideTester) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation) BottomResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.BottomResolvedOperation)

Example 7 with StringBuilderBasedAppendable

use of org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable in project xtext-xtend by eclipse.

the class AbstractBuilderTest method assertBuilds.

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());
}
Also used : StringBuilderBasedAppendable(org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable)

Example 8 with StringBuilderBasedAppendable

use of org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable in project xtext-xtend by eclipse.

the class CodeBuilderQuickfix method getJavaModification.

protected IModification getJavaModification(final ICodeBuilder.Java builder) {
    final IModification _function = (IModificationContext it) -> {
        final IType type = builder.getIType();
        char _charAt = ".".charAt(0);
        final ImportManager importManager = new ImportManager(true, _charAt);
        final StringBuilderBasedAppendable content = new StringBuilderBasedAppendable(importManager);
        builder.build(content);
        final Consumer<String> _function_1 = (String it_1) -> {
            try {
                ICompilationUnit _compilationUnit = type.getCompilationUnit();
                NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
                _compilationUnit.createImport(it_1, null, _nullProgressMonitor);
            } catch (Throwable _e) {
                throw Exceptions.sneakyThrow(_e);
            }
        };
        importManager.getImports().forEach(_function_1);
        Object _switchResult = null;
        boolean _matched = false;
        if (builder instanceof JavaFieldBuilder) {
            _matched = true;
            String _string = content.toString();
            NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
            _switchResult = type.createField(_string, null, true, _nullProgressMonitor);
        }
        if (!_matched) {
            if (builder instanceof JavaConstructorBuilder) {
                _matched = true;
                String _string = content.toString();
                NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
                _switchResult = type.createMethod(_string, null, true, _nullProgressMonitor);
            }
        }
        if (!_matched) {
            if (builder instanceof JavaMethodBuilder) {
                _matched = true;
                String _string = content.toString();
                NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
                _switchResult = type.createMethod(_string, null, true, _nullProgressMonitor);
            }
        }
        if (!_matched) {
            _switchResult = null;
        }
        final Object element = ((Object) _switchResult);
        if ((element != null)) {
            JdtHyperlink _jdtHyperlink = new JdtHyperlink();
            final Procedure1<JdtHyperlink> _function_2 = (JdtHyperlink it_1) -> {
                it_1.setJavaElement(((IMember) element));
                it_1.open();
            };
            ObjectExtensions.<JdtHyperlink>operator_doubleArrow(_jdtHyperlink, _function_2);
        }
    };
    return _function;
}
Also used : ImportManager(org.eclipse.xtext.xbase.compiler.ImportManager) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaMethodBuilder(org.eclipse.xtend.ide.codebuilder.JavaMethodBuilder) JavaConstructorBuilder(org.eclipse.xtend.ide.codebuilder.JavaConstructorBuilder) IMember(org.eclipse.jdt.core.IMember) IType(org.eclipse.jdt.core.IType) Consumer(java.util.function.Consumer) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) StringBuilderBasedAppendable(org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable) EObject(org.eclipse.emf.ecore.EObject) JavaFieldBuilder(org.eclipse.xtend.ide.codebuilder.JavaFieldBuilder) JdtHyperlink(org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification)

Aggregations

StringBuilderBasedAppendable (org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable)8 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)5 EObject (org.eclipse.emf.ecore.EObject)3 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)3 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)2 ISemanticModification (org.eclipse.xtext.ui.editor.model.edit.ISemanticModification)2 SemanticModificationWrapper (org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper)2 ReplacingAppendable (org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable)2 OptionalParameters (org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters)2 Consumer (java.util.function.Consumer)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IMember (org.eclipse.jdt.core.IMember)1 IType (org.eclipse.jdt.core.IType)1 JavaConstructorBuilder (org.eclipse.xtend.ide.codebuilder.JavaConstructorBuilder)1 JavaFieldBuilder (org.eclipse.xtend.ide.codebuilder.JavaFieldBuilder)1 JavaMethodBuilder (org.eclipse.xtend.ide.codebuilder.JavaMethodBuilder)1 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)1 JdtHyperlink (org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink)1