org.eclipse.xtext.formatting2.IFormatter2 Java Examples

The following examples show how to use org.eclipse.xtext.formatting2.IFormatter2. 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
Source File: ContentFormatter.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected TextEdit exec(IXtextDocument document, IRegion region, XtextResource resource) throws Exception {
	try {
		IParseResult parseResult = resource.getParseResult();
		if (parseResult != null && parseResult.getRootASTElement() != null) {
			FormatterRequest request = requestProvider.get();
			initRequest(document, region, resource, request);
			IFormatter2 formatter = formatterProvider.get();
			List<ITextReplacement> replacements = formatter.format(request);
			final TextEdit mte = createTextEdit(replacements);
			return mte;
		}
	} catch (Exception e) {
		LOG.error("Error formatting " + resource.getURI() + ": " + e.getMessage(), e);
	}
	return new MultiTextEdit();
}
 
Example #2
Source File: FormattingService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected List<ITextReplacement> format2(XtextResource resource, ITextRegion selection,
		ITypedPreferenceValues preferences) {
	FormatterRequest request = formatterRequestProvider.get();
	request.setAllowIdentityEdits(false);
	request.setFormatUndefinedHiddenRegionsOnly(false);
	if (selection != null) {
		request.setRegions(Collections.singletonList(selection));
	}
	if (preferences != null) {
		request.setPreferences(preferences);
	}
	ITextRegionAccess regionAccess = regionBuilder.forNodeModel(resource).create();
	request.setTextRegionAccess(regionAccess);
	IFormatter2 formatter2 = formatter2Provider.get();
	List<ITextReplacement> replacements = formatter2.format(request);
	return replacements;
}
 
Example #3
Source File: FormattingService.java    From xtext-web with Eclipse Public License 2.0 6 votes vote down vote up
protected String format2(XtextResource resource, ITextRegion selection, ITypedPreferenceValues preferences) {
	FormatterRequest request = formatterRequestProvider.get();
	request.setAllowIdentityEdits(false);
	request.setFormatUndefinedHiddenRegionsOnly(false);
	if (selection != null) {
		request.setRegions(Lists.newArrayList(selection));
	}
	if (preferences != null) {
		request.setPreferences(preferences);
	}
	ITextRegionAccess regionAccess = regionBuilder.forNodeModel(resource).create();
	request.setTextRegionAccess(regionAccess);
	IFormatter2 formatter2 = formatter2Provider.get();
	List<ITextReplacement> replacements = formatter2.format(request);
	if (selection != null) {
		return regionAccess.getRewriter().renderToString(
				new TextSegment(regionAccess, selection.getOffset(), selection.getLength()), replacements);
	} else {
		return regionAccess.getRewriter().renderToString(replacements);
	}
}
 
Example #4
Source File: Formatter2Fragment.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Set<Binding> getGuiceBindingsRt(Grammar grammar) {
	StringBuilder cfg = new StringBuilder();
	cfg.append("binder.bind(");
	cfg.append(IPreferenceValuesProvider.class.getName());
	cfg.append(".class)");
	cfg.append(".annotatedWith(");
	cfg.append(FormatterPreferences.class.getName());
	cfg.append(".class)");
	cfg.append(".to(");
	cfg.append(FormatterPreferenceValuesProvider.class.getName());
	cfg.append(".class);");
	BindFactory bf = new BindFactory();
	bf.addTypeToType(IFormatter2.class.getName(), stubGenerator.getStubQualifiedName());
	bf.addConfiguredBinding(FormatterPreferences.class.getName(), cfg.toString());
	return bf.getBindings();
}
 
Example #5
Source File: Serializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example #6
Source File: Formatter2Fragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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();
}
 
Example #7
Source File: XbaseFormatterTestInjectorProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Injector createInjector() {
	return Guice.createInjector(new XbaseTestRuntimeModule() {
		@Override
		public void configure(com.google.inject.Binder binder) {
			super.configure(binder);
			binder.bind(IFormatter2.class).to(XbaseFormatter.class);
		}
	});
}
 
Example #8
Source File: AbstractNoJdtTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return NoJdtTestLanguageFormatter.class;
}
 
Example #9
Source File: AbstractExBeeLangTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return ExBeeLangTestLanguageFormatter.class;
}
 
Example #10
Source File: FormatterTesterWithImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected IFormatter2 createFormatter(FormatterTestRequest req) {
	return ((GenericFormatterTestRequest) req).getFormatter();
}
 
Example #11
Source File: FormatterSerializerIntegrationTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
  return FormatterSerializerIntegrationTest.Formatter.class;
}
 
Example #12
Source File: AbstractBeeLangTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return BeeLangTestLanguageFormatter.class;
}
 
Example #13
Source File: AbstractSimpleBeeLangTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return SimpleBeeLangTestLanguageFormatter.class;
}
 
Example #14
Source File: AbstractFileAwareTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return FileAwareTestLanguageFormatter.class;
}
 
Example #15
Source File: FormatterTestHelper.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected IFormatter2 createFormatter(FormatterTestRequest request) {
	checkNotNull(formatter, "There is a Guice Binding missing for " + IFormatter2.class.getName());
	return formatter.get();
}
 
Example #16
Source File: RegionDiffFormatter.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected IFormatter2 getFormatter() {
	if (formatter != null) {
		return formatter.get();
	}
	return nullFormatter.get();
}
 
Example #17
Source File: AbstractSARLRuntimeModule.java    From sarl with Apache License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return SARLFormatter.class;
}
 
Example #18
Source File: AbstractPartialSerializationTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return PartialSerializationTestLanguageFormatter.class;
}
 
Example #19
Source File: TestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return TestLanguageFormatter.class;
}
 
Example #20
Source File: FormatterTester.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected IFormatter2 createFormatter(FormatterTestRequest request) {
	checkNotNull(formatter, "There is a Guice Binding missing for " + IFormatter2.class.getName());
	return formatter.get();
}
 
Example #21
Source File: AbstractXtendRuntimeModule.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return XtendFormatter.class;
}
 
Example #22
Source File: AbstractTypeExpressionsRuntimeModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return TypeExpressionsFormatter.class;
}
 
Example #23
Source File: AbstractRuleEngineRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return RuleEngineFormatter.class;
}
 
Example #24
Source File: AbstractStatemachineRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return StatemachineFormatter.class;
}
 
Example #25
Source File: AbstractDomainmodelRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return DomainmodelFormatter.class;
}
 
Example #26
Source File: AbstractEntitiesRuntimeModule.java    From xtext-web with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return EntitiesFormatter.class;
}
 
Example #27
Source File: AbstractStatemachineRuntimeModule.java    From xtext-web with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return StatemachineFormatter.class;
}
 
Example #28
Source File: FormatterTester.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected IFormatter2 createFormatter(FormatterTestRequest request) {
	checkNotNull(formatter, "There is a Guice Binding missing for " + IFormatter2.class.getName());
	return formatter.get();
}
 
Example #29
Source File: AbstractXtypeRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return XtypeFormatter.class;
}
 
Example #30
Source File: AbstractXbaseWithAnnotationsRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IFormatter2> bindIFormatter2() {
	return XbaseWithAnnotationsFormatter.class;
}