Search in sources :

Example 1 with IFormatter2

use of org.eclipse.xtext.formatting2.IFormatter2 in project xtext-core by eclipse.

the class FormattingService method format2.

protected List<ITextReplacement> format2(final XtextResource resource, final ITextRegion selection, final ITypedPreferenceValues preferences) {
    final FormatterRequest request = this.formatterRequestProvider.get();
    request.setAllowIdentityEdits(false);
    request.setFormatUndefinedHiddenRegionsOnly(false);
    if ((selection != null)) {
        request.setRegions(Collections.<ITextRegion>unmodifiableList(CollectionLiterals.<ITextRegion>newArrayList(selection)));
    }
    if ((preferences != null)) {
        request.setPreferences(preferences);
    }
    final ITextRegionAccess regionAccess = this.regionBuilder.forNodeModel(resource).create();
    request.setTextRegionAccess(regionAccess);
    final IFormatter2 formatter2 = this.formatter2Provider.get();
    final List<ITextReplacement> replacements = formatter2.format(request);
    return replacements;
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IFormatter2(org.eclipse.xtext.formatting2.IFormatter2) ITextRegion(org.eclipse.xtext.util.ITextRegion) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest)

Example 2 with IFormatter2

use of org.eclipse.xtext.formatting2.IFormatter2 in project xtext-core by eclipse.

the class Formatter2Fragment2 method generate.

@Override
public void generate() {
    boolean _isGenerateStub = this.isGenerateStub();
    boolean _not = (!_isGenerateStub);
    if (_not) {
        return;
    }
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append("binder.bind(");
            _builder.append(IPreferenceValuesProvider.class);
            _builder.append(".class).annotatedWith(");
            _builder.append(FormatterPreferences.class);
            _builder.append(".class).to(");
            _builder.append(FormatterPreferenceValuesProvider.class);
            _builder.append(".class);");
        }
    };
    final StringConcatenationClient statement = _client;
    new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IFormatter2.class), this.getFormatter2Stub(this.getLanguage().getGrammar())).addConfiguredBinding(FormatterPreferences.class.getSimpleName(), statement).contributeTo(this.getLanguage().getRuntimeGenModule());
    new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory"), TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory")).contributeTo(this.getLanguage().getEclipsePluginGenModule());
    ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
    boolean _tripleNotEquals = (_manifest != null);
    if (_tripleNotEquals) {
        Set<String> _exportedPackages = this.getProjectConfig().getRuntime().getManifest().getExportedPackages();
        String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
        String _plus = (_runtimeBasePackage + ".formatting2");
        _exportedPackages.add(_plus);
    }
    this.doGenerateStubFile();
}
Also used : GuiceModuleAccess(org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess) IFormatter2(org.eclipse.xtext.formatting2.IFormatter2) ManifestAccess(org.eclipse.xtext.xtext.generator.model.ManifestAccess) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient)

Example 3 with IFormatter2

use of org.eclipse.xtext.formatting2.IFormatter2 in project xtext-core by eclipse.

the class Serializer method serialize.

protected void serialize(EObject obj, Appendable appendable, SaveOptions options) throws IOException {
    ITextRegionAccess regionAccess = serializeToRegions(obj);
    FormatterRequest request = formatterRequestProvider.get();
    request.setFormatUndefinedHiddenRegionsOnly(!options.isFormatting());
    request.setTextRegionAccess(regionAccess);
    IFormatter2 formatter2 = formatter2Provider.get();
    List<ITextReplacement> replacements = formatter2.format(request);
    regionAccess.getRewriter().renderToAppendable(replacements, appendable);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IFormatter2(org.eclipse.xtext.formatting2.IFormatter2) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest)

Example 4 with IFormatter2

use of org.eclipse.xtext.formatting2.IFormatter2 in project xtext-core by eclipse.

the class RegionDiffFormatter method format.

public List<ITextReplacement> format(ITextRegionAccess regions) {
    IFormatter2 fmt = getFormatter();
    if (regions instanceof ITextRegionAccessDiff) {
        ITextRegionAccessDiff diff = (ITextRegionAccessDiff) regions;
        FormatterRequest request = createFormatterRequest(diff);
        List<ITextReplacement> replacements = fmt.format(request);
        List<ITextReplacement> merged = mergeReplacements(diff, replacements);
        return merged;
    } else {
        FormatterRequest request = createFormatterRequest(regions);
        List<ITextReplacement> replacements = fmt.format(request);
        return replacements;
    }
}
Also used : ITextRegionAccessDiff(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff) IFormatter2(org.eclipse.xtext.formatting2.IFormatter2) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest)

Aggregations

IFormatter2 (org.eclipse.xtext.formatting2.IFormatter2)4 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)3 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)3 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)2 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)1 ITextRegionAccessDiff (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1 GuiceModuleAccess (org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess)1 ManifestAccess (org.eclipse.xtext.xtext.generator.model.ManifestAccess)1