Search in sources :

Example 1 with JavaConstructorBuilder

use of org.eclipse.xtend.ide.codebuilder.JavaConstructorBuilder 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

Consumer (java.util.function.Consumer)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 EObject (org.eclipse.emf.ecore.EObject)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 JdtHyperlink (org.eclipse.xtext.common.types.xtext.ui.JdtHyperlink)1 IModification (org.eclipse.xtext.ui.editor.model.edit.IModification)1 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)1 ImportManager (org.eclipse.xtext.xbase.compiler.ImportManager)1 StringBuilderBasedAppendable (org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1