org.eclipse.jface.text.formatter.IContentFormatter Java Examples
The following examples show how to use
org.eclipse.jface.text.formatter.IContentFormatter.
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: XMLConfiguration.java From http4e with Apache License 2.0 | 6 votes |
public IContentFormatter getContentFormatter( ISourceViewer sourceViewer){ ContentFormatter formatter = new ContentFormatter(); XMLFormattingStrategy formattingStrategy = new XMLFormattingStrategy(); DefaultFormattingStrategy defaultStrategy = new DefaultFormattingStrategy(); TextFormattingStrategy textStrategy = new TextFormattingStrategy(); DocTypeFormattingStrategy doctypeStrategy = new DocTypeFormattingStrategy(); PIFormattingStrategy piStrategy = new PIFormattingStrategy(); formatter.setFormattingStrategy(defaultStrategy, IDocument.DEFAULT_CONTENT_TYPE); formatter.setFormattingStrategy(textStrategy, XMLPartitionScanner.XML_TEXT); formatter.setFormattingStrategy(doctypeStrategy, XMLPartitionScanner.XML_DOCTYPE); formatter.setFormattingStrategy(piStrategy, XMLPartitionScanner.XML_PI); formatter.setFormattingStrategy(textStrategy, XMLPartitionScanner.XML_CDATA); formatter.setFormattingStrategy(formattingStrategy, XMLPartitionScanner.XML_START_TAG); formatter.setFormattingStrategy(formattingStrategy, XMLPartitionScanner.XML_END_TAG); return formatter; }
Example #2
Source File: UiBinderFormatter.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public static IContentFormatter createFormatter(String partitioning) { /* * Ideally, we would have no master strategy and two slave strategies, one * for XML and one for CSS. The problem is, XMLFormattingStrategy won't work * properly since some paired opening and closing tags are spread across * different partitions (for example, the <ui:style> tag since the CSS * partition will be between the opening and closing tag.) */ IndependentMultiPassContentFormatter formatter = new IndependentMultiPassContentFormatter( partitioning, IXMLPartitions.XML_DEFAULT, new StructuredDocumentCloner( partitioning, UIBINDER_XML_PARTITIONER_FACTORY)); formatter.setMasterStrategy(new XMLFormattingStrategy()); formatter.setSlaveStrategy2(new InlinedCssFormattingStrategy(), ICSSPartitions.STYLE); /* * If the <ui:style> contains a '%' (for example, in something like * "width: 50%;"), the XML following the <ui:style> tag will not be * formatted. For the '%', the region type is UNDEFINED, and there is no * corresponding DOM node. Before formatting, the * DefaultXMLPartitionFormatter ensures the current region matches the * current DOM node's first region, and since there is no DOM node for the * UNDEFINED region, the formatting abruptly stops. To workaround this * issue, we replace the CSS with whitespace when the master formatter runs. */ formatter.setReplaceSlavePartitionsDuringMasterFormat(true); formatter.setCheckForNonwhitespaceChanges(true); return formatter; }
Example #3
Source File: GWTSourceViewerConfiguration.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
@Override public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { IndependentMultiPassContentFormatter formatter = new IndependentMultiPassContentFormatter( getConfiguredDocumentPartitioning(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE, JAVA_DOCUMENT_CLONER); formatter.setMasterStrategy(new JavaFormattingStrategy()); formatter.setSlaveStrategy2(new JsniFormattingStrategy(), GWTPartitions.JSNI_METHOD); return formatter; }
Example #4
Source File: SimpleJavaSourceViewerConfiguration.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { if (fConfigureFormatter) return super.getContentFormatter(sourceViewer); else return null; }
Example #5
Source File: CompilationUnitPreview.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void doFormatPreview() { if (fPreviewText == null) { fPreviewDocument.set(""); //$NON-NLS-1$ return; } fPreviewDocument.set(fPreviewText); fSourceViewer.setRedraw(false); final IFormattingContext context = new JavaFormattingContext(); try { final IContentFormatter formatter = fViewerConfiguration.getContentFormatter(fSourceViewer); if (formatter instanceof IContentFormatterExtension) { final IContentFormatterExtension extension = (IContentFormatterExtension) formatter; context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, fWorkingValues); context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.valueOf(true)); extension.format(fPreviewDocument, context); } else formatter.format(fPreviewDocument, new Region(0, fPreviewDocument.getLength())); } catch (Exception e) { final IStatus status= new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, FormatterMessages.JavaPreview_formatter_exception, e); JavaPlugin.log(status); } finally { context.dispose(); fSourceViewer.setRedraw(true); } }
Example #6
Source File: DocumentAutoFormatter.java From sarl with Apache License 2.0 | 5 votes |
@Override public void bind(IXtextDocument document, IContentFormatter contentFormatter) { assert document != null; assert contentFormatter != null; this.document = document; this.contentFormatter = contentFormatter; }
Example #7
Source File: ReadOnlySourceViewerConfiguration.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { return null; }
Example #8
Source File: ContentFormatterFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public IContentFormatter createConfiguredFormatter(SourceViewerConfiguration cfg, ISourceViewer sourceViewer) { return formatter.get(); }
Example #9
Source File: XtextSourceViewerConfiguration.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { if (contentFormatterFactory != null) return contentFormatterFactory.createConfiguredFormatter(this, sourceViewer); return super.getContentFormatter(sourceViewer); }
Example #10
Source File: ContentFormatterFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public IContentFormatter createConfiguredFormatter( SourceViewerConfiguration configuration, ISourceViewer sourceViewer) { return new ContentFormatter(); }
Example #11
Source File: TypeScriptSourceViewerConfiguration.java From typescript.java with MIT License | 4 votes |
@Override public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { IEditorInput input = getEditor().getEditorInput(); return input != null ? new TypeScriptContentFormatter(EditorUtils.getResource(input)) : null; }
Example #12
Source File: UiBinderXmlSourceViewerConfiguration.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
@Override public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { return UiBinderFormatter.createFormatter(getConfiguredDocumentPartitioning(sourceViewer)); }
Example #13
Source File: CommonSourceViewerConfiguration.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * Collects the code formatters by the supported content-types and returns a new {@link import * org.eclipse.jface.text.formatter.MultiPassContentFormatter} that holds them.<br> * The returned content formatter is computed from the result of {@link #getTopContentTypes()}. The first element in * the returned array should define the 'master' formatter. While the rest of the elements should contain the * 'slave' formatter. <br> * Note that each slave formatter is located in the last element of each inner-array that was returned from the * getTopContentTypes call. */ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { final String[][] contentTypes = getTopContentTypes(); final CommonMultiPassContentFormatter formatter = new CommonMultiPassContentFormatter( getConfiguredDocumentPartitioning(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE); boolean masterSet = false; Set<String> addedFormatters = new HashSet<String>(); for (String contentTypeArr[] : contentTypes) { // The first item in the array should contain the master formatter strategy // In case it starts with the HTML prefix (like in PHP, ERB etc.), we try to set // the master to the HTML formatter. if (!masterSet && contentTypeArr[0].startsWith(CONTENTTYPE_HTML_PREFIX)) { if (ScriptFormatterManager.hasFormatterFor(CONTENTTYPE_HTML_PREFIX)) { formatter.setMasterStrategy(CONTENTTYPE_HTML_PREFIX); masterSet = true; addedFormatters.add(CONTENTTYPE_HTML_PREFIX); } else { IdeLog.logWarning(CommonEditorPlugin.getDefault(), MessageFormat.format( "Could not located an expected code formatter for ''{0}''", CONTENTTYPE_HTML_PREFIX)); //$NON-NLS-1$ } } String contentType = contentTypeArr[contentTypeArr.length - 1]; if (!addedFormatters.contains(contentType) && ScriptFormatterManager.hasFormatterFor(contentType)) { if (!masterSet) { formatter.setMasterStrategy(contentType); masterSet = true; } else { formatter.setSlaveStrategy(contentType); } } } return formatter; }
Example #14
Source File: JavaSourceViewerConfiguration.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { final MultiPassContentFormatter formatter= new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE); formatter.setMasterStrategy(new JavaFormattingStrategy()); return formatter; }
Example #15
Source File: IDocumentAutoFormatter.java From sarl with Apache License 2.0 | 2 votes |
/** Create an instance of document auto formatter. * * @param document the Xtext document associated to this auto-formatter. * @param contentFormatter the formatter of content to be used. */ default void bind(IXtextDocument document, IContentFormatter contentFormatter) { // }
Example #16
Source File: IContentFormatterFactory.java From xtext-eclipse with Eclipse Public License 2.0 | votes |
IContentFormatter createConfiguredFormatter(SourceViewerConfiguration configuration, ISourceViewer sourceViewer);