diff options
author | Tom Schindl | 2014-06-15 19:03:56 +0000 |
---|---|---|
committer | Tom Schindl | 2014-06-15 19:03:56 +0000 |
commit | f84fa844e0502f3d597a4b8f170aa7935e8259ef (patch) | |
tree | 820b4709f02582ab35548d598549f15f7126bfd6 /experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor | |
parent | 5c3100ea1af2e1ae3e977e8c8a590c09760d8d89 (diff) | |
download | org.eclipse.efxclipse-f84fa844e0502f3d597a4b8f170aa7935e8259ef.tar.gz org.eclipse.efxclipse-f84fa844e0502f3d597a4b8f170aa7935e8259ef.tar.xz org.eclipse.efxclipse-f84fa844e0502f3d597a4b8f170aa7935e8259ef.zip |
initial source for the compensator projects
Diffstat (limited to 'experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor')
10 files changed, 456 insertions, 0 deletions
diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/.DS_Store b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/.DS_Store Binary files differnew file mode 100644 index 000000000..d8dcc41fa --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/.DS_Store diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/IXMLColorConstants.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/IXMLColorConstants.java new file mode 100644 index 000000000..3d56b75e4 --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/IXMLColorConstants.java @@ -0,0 +1,21 @@ +/******************************************************************************* +* Copyright (c) 2014 BestSolution.at and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation +*******************************************************************************/ +package org.eclipse.fx.code.compensator.editor.xml; + +import javafx.scene.paint.Color; + +public interface IXMLColorConstants { + Color XML_COMMENT = Color.rgb(128, 0, 0); + Color PROC_INSTR = Color.rgb(128, 128, 128); + Color STRING = Color.rgb(0, 128, 0); + Color DEFAULT = Color.rgb(0, 0, 0); + Color TAG = Color.rgb(0, 0, 128); +} diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/NonRuleBasedDamagerRepairer.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/NonRuleBasedDamagerRepairer.java new file mode 100644 index 000000000..1bfe309c8 --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/NonRuleBasedDamagerRepairer.java @@ -0,0 +1,148 @@ +/******************************************************************************* +* Copyright (c) 2014 BestSolution.at and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation +*******************************************************************************/ +package org.eclipse.fx.code.compensator.editor.xml; + +import org.eclipse.fx.ui.controls.styledtext.StyleRange; +import org.eclipse.jface.text.Assert; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.TextPresentation; +import org.eclipse.jface.text.presentation.IPresentationDamager; +import org.eclipse.jface.text.presentation.IPresentationRepairer; + +public class NonRuleBasedDamagerRepairer + implements IPresentationDamager, IPresentationRepairer { + + /** The document this object works on */ + protected IDocument fDocument; + /** The default text attribute if non is returned as data by the current token */ + protected TextAttribute fDefaultTextAttribute; + + /** + * Constructor for NonRuleBasedDamagerRepairer. + */ + public NonRuleBasedDamagerRepairer(TextAttribute defaultTextAttribute) { + Assert.isNotNull(defaultTextAttribute); + + fDefaultTextAttribute = defaultTextAttribute; + } + + /** + * @see IPresentationRepairer#setDocument(IDocument) + */ + public void setDocument(IDocument document) { + fDocument = document; + } + + /** + * Returns the end offset of the line that contains the specified offset or + * if the offset is inside a line delimiter, the end offset of the next line. + * + * @param offset the offset whose line end offset must be computed + * @return the line end offset for the given offset + * @exception BadLocationException if offset is invalid in the current document + */ + protected int endOfLineOf(int offset) throws BadLocationException { + + IRegion info = fDocument.getLineInformationOfOffset(offset); + if (offset <= info.getOffset() + info.getLength()) + return info.getOffset() + info.getLength(); + + int line = fDocument.getLineOfOffset(offset); + try { + info = fDocument.getLineInformation(line + 1); + return info.getOffset() + info.getLength(); + } catch (BadLocationException x) { + return fDocument.getLength(); + } + } + + /** + * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean) + */ + public IRegion getDamageRegion( + ITypedRegion partition, + DocumentEvent event, + boolean documentPartitioningChanged) { + if (!documentPartitioningChanged) { + try { + + IRegion info = + fDocument.getLineInformationOfOffset(event.getOffset()); + int start = Math.max(partition.getOffset(), info.getOffset()); + + int end = + event.getOffset() + + (event.getText() == null + ? event.getLength() + : event.getText().length()); + + if (info.getOffset() <= end + && end <= info.getOffset() + info.getLength()) { + // optimize the case of the same line + end = info.getOffset() + info.getLength(); + } else + end = endOfLineOf(end); + + end = + Math.min( + partition.getOffset() + partition.getLength(), + end); + return new Region(start, end - start); + + } catch (BadLocationException x) { + } + } + + return partition; + } + + /** + * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion) + */ + public void createPresentation( + TextPresentation presentation, + ITypedRegion region) { + addRange( + presentation, + region.getOffset(), + region.getLength(), + fDefaultTextAttribute); + } + + /** + * Adds style information to the given text presentation. + * + * @param presentation the text presentation to be extended + * @param offset the offset of the range to be styled + * @param length the length of the range to be styled + * @param attr the attribute describing the style of the range to be styled + */ + protected void addRange( + TextPresentation presentation, + int offset, + int length, + TextAttribute attr) { + if (attr != null) + presentation.addStyleRange( + new StyleRange( + offset, + length, + attr.getForeground(), + attr.getBackground(), + attr.getStyle())); + } +}
\ No newline at end of file diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/TagRule.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/TagRule.java new file mode 100644 index 000000000..ba497f708 --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/TagRule.java @@ -0,0 +1,41 @@ +/******************************************************************************* +* Copyright (c) 2014 BestSolution.at and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation +*******************************************************************************/ +package org.eclipse.fx.code.compensator.editor.xml; + +import org.eclipse.jface.text.rules.*; + +public class TagRule extends MultiLineRule { + + public TagRule(IToken token) { + super("<", ">", token); + } + protected boolean sequenceDetected( + ICharacterScanner scanner, + char[] sequence, + boolean eofAllowed) { + int c = scanner.read(); + if (sequence[0] == '<') { + if (c == '?') { + // processing instruction - abort + scanner.unread(); + return false; + } + if (c == '!') { + scanner.unread(); + // comment - abort + return false; + } + } else if (sequence[0] == '>') { + scanner.unread(); + } + return super.sequenceDetected(scanner, sequence, eofAllowed); + } +} diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLComponent.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLComponent.java new file mode 100644 index 000000000..4e9cc9642 --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLComponent.java @@ -0,0 +1,46 @@ +/******************************************************************************* +* Copyright (c) 2014 BestSolution.at and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation +*******************************************************************************/ +package org.eclipse.fx.code.compensator.editor.xml; + +import org.eclipse.fx.code.compensator.editor.ContentTypeProvider; +import org.eclipse.fx.code.compensator.editor.Input; +import org.eclipse.fx.code.compensator.editor.services.PartitionerFactory; +import org.eclipse.fx.code.compensator.editor.services.SourceViewerConfigurationFactory; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.rules.FastPartitioner; +import org.eclipse.jface.text.source.SourceViewerConfiguration; + +public class XMLComponent implements PartitionerFactory, SourceViewerConfigurationFactory { + + @Override + public SourceViewerConfiguration createConfiguration(Input<?> input) { + return new XMLConfiguration(); + } + + @Override + public boolean applies(Input<?> input) { + if( input instanceof ContentTypeProvider ) { + String contentType = ((ContentTypeProvider) input).getContentType(); + return ContentTypeProvider.XML.equals(contentType); + } + return false; + } + + @Override + public IDocumentPartitioner createPartitioner(Input<?> input) { + return new FastPartitioner( + new XMLPartitionScanner(), + new String[] { + XMLPartitionScanner.XML_TAG, + XMLPartitionScanner.XML_COMMENT }); + } + +} diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLConfiguration.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLConfiguration.java new file mode 100644 index 000000000..cc977d8f9 --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLConfiguration.java @@ -0,0 +1,83 @@ +/******************************************************************************* +* Copyright (c) 2014 BestSolution.at and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation +*******************************************************************************/ +package org.eclipse.fx.code.compensator.editor.xml; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; + +public class XMLConfiguration extends SourceViewerConfiguration { +// private XMLDoubleClickStrategy doubleClickStrategy; + private XMLTagScanner tagScanner; + private XMLScanner scanner; + + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return new String[] { + IDocument.DEFAULT_CONTENT_TYPE, + XMLPartitionScanner.XML_COMMENT, + XMLPartitionScanner.XML_TAG }; + } +// public ITextDoubleClickStrategy getDoubleClickStrategy( +// ISourceViewer sourceViewer, +// String contentType) { +// if (doubleClickStrategy == null) +// doubleClickStrategy = new XMLDoubleClickStrategy(); +// return doubleClickStrategy; +// } + + protected XMLScanner getXMLScanner() { + if (scanner == null) { + scanner = new XMLScanner(); + scanner.setDefaultReturnToken( + new Token( + new TextAttribute(IXMLColorConstants.DEFAULT))); + } + return scanner; + } + protected XMLTagScanner getXMLTagScanner() { + if (tagScanner == null) { + tagScanner = new XMLTagScanner(); + tagScanner.setDefaultReturnToken( + new Token( + new TextAttribute( + IXMLColorConstants.TAG))); + } + return tagScanner; + } + + public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { + PresentationReconciler reconciler = new PresentationReconciler(); + + DefaultDamagerRepairer dr = + new DefaultDamagerRepairer(getXMLTagScanner()); + reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG); + reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG); + + dr = new DefaultDamagerRepairer(getXMLScanner()); + reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + + NonRuleBasedDamagerRepairer ndr = + new NonRuleBasedDamagerRepairer( + new TextAttribute( + IXMLColorConstants.XML_COMMENT)); + reconciler.setDamager(ndr, XMLPartitionScanner.XML_COMMENT); + reconciler.setRepairer(ndr, XMLPartitionScanner.XML_COMMENT); + + return reconciler; + } + +}
\ No newline at end of file diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLPartitionScanner.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLPartitionScanner.java new file mode 100644 index 000000000..d61c8ce96 --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLPartitionScanner.java @@ -0,0 +1,31 @@ +/******************************************************************************* +* Copyright (c) 2014 BestSolution.at and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation +*******************************************************************************/ +package org.eclipse.fx.code.compensator.editor.xml; + +import org.eclipse.jface.text.rules.*; + +public class XMLPartitionScanner extends RuleBasedPartitionScanner { + public final static String XML_COMMENT = "__xml_comment"; + public final static String XML_TAG = "__xml_tag"; + + public XMLPartitionScanner() { + + IToken xmlComment = new Token(XML_COMMENT); + IToken tag = new Token(XML_TAG); + + IPredicateRule[] rules = new IPredicateRule[2]; + + rules[0] = new MultiLineRule("<!--", "-->", xmlComment); + rules[1] = new TagRule(tag); + + setPredicateRules(rules); + } +} diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLScanner.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLScanner.java new file mode 100644 index 000000000..9fc1e1b0b --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLScanner.java @@ -0,0 +1,32 @@ +/******************************************************************************* +* Copyright (c) 2014 BestSolution.at and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation +*******************************************************************************/ +package org.eclipse.fx.code.compensator.editor.xml; + +import org.eclipse.jface.text.rules.*; +import org.eclipse.jface.text.*; + +public class XMLScanner extends RuleBasedScanner { + + public XMLScanner() { + IToken procInstr = + new Token( + new TextAttribute( + IXMLColorConstants.PROC_INSTR)); + + IRule[] rules = new IRule[2]; + //Add rule for processing instructions + rules[0] = new SingleLineRule("<?", "?>", procInstr); + // Add generic whitespace rule. + rules[1] = new WhitespaceRule(new XMLWhitespaceDetector()); + + setRules(rules); + } +} diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLTagScanner.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLTagScanner.java new file mode 100644 index 000000000..7b51b8cfa --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLTagScanner.java @@ -0,0 +1,34 @@ +/******************************************************************************* +* Copyright (c) 2014 BestSolution.at and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation +*******************************************************************************/ +package org.eclipse.fx.code.compensator.editor.xml; + +import org.eclipse.jface.text.*; +import org.eclipse.jface.text.rules.*; + +public class XMLTagScanner extends RuleBasedScanner { + + public XMLTagScanner() { + IToken string = + new Token( + new TextAttribute(IXMLColorConstants.STRING)); + + IRule[] rules = new IRule[3]; + + // Add rule for double quotes + rules[0] = new SingleLineRule("\"", "\"", string, '\\'); + // Add a rule for single quotes + rules[1] = new SingleLineRule("'", "'", string, '\\'); + // Add generic whitespace rule. + rules[2] = new WhitespaceRule(new XMLWhitespaceDetector()); + + setRules(rules); + } +} diff --git a/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLWhitespaceDetector.java b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLWhitespaceDetector.java new file mode 100644 index 000000000..8e74c7f4f --- /dev/null +++ b/experimental/compensator/org.eclipse.fx.code.compensator.editor.xml/src/org/eclipse/fx/code/compensator/editor/xml/XMLWhitespaceDetector.java @@ -0,0 +1,20 @@ +/******************************************************************************* +* Copyright (c) 2014 BestSolution.at and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Tom Schindl<tom.schindl@bestsolution.at> - initial API and implementation +*******************************************************************************/ +package org.eclipse.fx.code.compensator.editor.xml; + +import org.eclipse.jface.text.rules.IWhitespaceDetector; + +public class XMLWhitespaceDetector implements IWhitespaceDetector { + + public boolean isWhitespace(char c) { + return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); + } +} |