@Override protected void inputChanged(Object newInput, Object oldInput) { if (oldInput instanceof IDocumentExtension3) { IDocumentExtension3 doc = (IDocumentExtension3) oldInput; doc.setDocumentPartitioner(SQLEditorCommonDocumentProvider.SQL_PARTITIONING, null); partitioner.disconnect(); } if (newInput instanceof IDocumentExtension3) { IDocumentExtension3 extension3 = (IDocumentExtension3) newInput; partitioner.connect((IDocument) newInput); extension3.setDocumentPartitioner( SQLEditorCommonDocumentProvider.SQL_PARTITIONING, partitioner); } super.inputChanged(newInput, oldInput); }
private ITypedRegion getPartition(final String partitionContentType) { final IDocumentExtension3 extension = (IDocumentExtension3) this.document; ITypedRegion[] computePartitioning = null; try { computePartitioning = extension.computePartitioning(IDocumentExtension3.DEFAULT_PARTITIONING, 0, this.document.getLength(), false); } catch (BadLocationException | BadPartitioningException e) { e.printStackTrace(); } for (final ITypedRegion iTypedRegion : computePartitioning) { if (iTypedRegion.getType().equals(partitionContentType)) { return iTypedRegion; } } return null; }
@Override protected IDocument createDocument(Object element) throws CoreException { IDocument document = super.createDocument(element); //IDocumentPartitioner partitioner = createDocumentPartitioner(); IDocumentPartitioner partitioner = new ImpexDocumentPartitioner(); if ((document instanceof IDocumentExtension3)) { IDocumentExtension3 extension3 = (IDocumentExtension3) document; extension3.setDocumentPartitioner(Activator.IMPEX_PARTITIONING, partitioner); } else { document.setDocumentPartitioner(partitioner); } partitioner.connect(document); return document; }
@Override protected void configureSourceViewerDecorationSupport( SourceViewerDecorationSupport support) { super.configureSourceViewerDecorationSupport(support); char[] matchChars = { '<', '>' }; // which brackets to match ICharacterPairMatcher matcher = new DefaultCharacterPairMatcher( matchChars, IDocumentExtension3.DEFAULT_PARTITIONING); support.setCharacterPairMatcher(matcher); support.setMatchingCharacterPainterPreferenceKeys( EDITOR_MATCHING_BRACKETS, EDITOR_MATCHING_BRACKETS_COLOR); // Enable bracket highlighting in the preference store IPreferenceStore store = getPreferenceStore(); store.setDefault(EDITOR_MATCHING_BRACKETS, true); store.setDefault(EDITOR_MATCHING_BRACKETS_COLOR, "128,128,128"); }
@Override protected String extractPrefix(ITextViewer viewer, int offset) { try { if (offset == 0) { return ""; } if (!(viewer.getDocument() instanceof IDocumentExtension3)) { return super.extractPrefix(viewer, offset); } IDocumentExtension3 document3 = (IDocumentExtension3) viewer.getDocument(); ITypedRegion previousRegion = document3.getPartition(EditorConstants.BF_PARTITIONING, offset - 1, false); if (EditorConstants.PARTITION_TYPE_TEMPLATE_PARAMETERS.equals(previousRegion.getType())) { return viewer.getDocument().get(previousRegion.getOffset(), previousRegion.getLength()); } } catch (BadLocationException | BadPartitioningException ex) { BfActivator.getDefault().logError("Prefix for Template could not be computed", ex); } return super.extractPrefix(viewer, offset); }
@Override public IRegion getHoverRegion(ITextViewer textViewer, int offset) { IRegion region = new Region(offset, 0); try { IDocument doc = textViewer.getDocument(); if (doc instanceof IDocumentExtension3) { IDocumentExtension3 ext3 = (IDocumentExtension3) doc; region = ext3.getPartition(EditorConstants.BF_PARTITIONING, offset, true); } else { region = doc.getPartition(offset); } } catch (BadPartitioningException | BadLocationException ex) { BfActivator.getDefault().logError("Partitioning Problem", ex); } return region; }
/** * Setup the TrafficScript Partitioner for .zts files */ /* Override */ public void setup( IDocument document ) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3 = (IDocumentExtension3) document; IDocumentPartitioner partitioner = new FastPartitioner( ZXTMPlugin.getDefault().getTrafficScriptPartitioner(), Partition.getAllPartitionIds() ); extension3.setDocumentPartitioner( TrafficScriptPartitioner.TS_PARTITIONER, partitioner ); partitioner.connect( document ); } }
public boolean isWordStart(char c) { if ('=' != c && ':' != c || fDocument == null) return false; try { // check whether it is the first '=' in the logical line int i=fOffset-2; while (Character.isWhitespace(fDocument.getChar(i))) { i--; } ITypedRegion partition= null; if (fDocument instanceof IDocumentExtension3) partition= ((IDocumentExtension3)fDocument).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, i, false); return partition != null && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()); } catch (BadLocationException ex) { return false; } catch (BadPartitioningException e) { return false; } }
@Override protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException { int selectionOffset= selection.getOffset(); int selectionEndOffset= selectionOffset + selection.getLength(); List<Edit> edits= new LinkedList<Edit>(); ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, selectionOffset, false); handleFirstPartition(partition, edits, factory, selectionOffset); while (partition.getOffset() + partition.getLength() < selectionEndOffset) { partition= handleInteriorPartition(partition, edits, factory, docExtension); } handleLastPartition(partition, edits, factory, selectionEndOffset); executeEdits(edits); }
@Override public boolean isWordStart(char c) { if ('=' != c && ':' != c || fDocument == null) return false; try { // check whether it is the first '=' in the logical line int i = fOffset - 2; while (Character.isWhitespace(fDocument.getChar(i))) { i--; } ITypedRegion partition = null; if (fDocument instanceof IDocumentExtension3) partition = ((IDocumentExtension3) fDocument) .getPartition(IEditorConfigPartitions.EDITOR_CONFIG_PARTITIONING, i, false); return partition != null && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()); } catch (BadLocationException ex) { return false; } catch (BadPartitioningException e) { return false; } }
@Override protected FileInfo createFileInfo(Object element) throws CoreException { FileInfo info = super.createFileInfo(element); if(info==null){ info = createEmptyFileInfo(); } IDocument document = info.fTextFileBuffer.getDocument(); if (document != null) { /* register your partitioner and other things here same way as in your first document provider */ if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3= (IDocumentExtension3) document; IDocumentPartitioner partitioner= new FastPartitioner(RustCorePlugin.getDefault().scanners().rustPartitionScanner(), RustPartitionScanner.PARTITION_TYPES); extension3.setDocumentPartitioner(RustConstants.RUST_PARTITIONING, partitioner); partitioner.connect(document); } } return info; }
@Override protected @Nullable IDocument createDocument(@Nullable Object element) throws CoreException { // IDocument document = super.createDocument(element); // if (document != null) { // IDocumentPartitioner partitioner = // new FastPartitioner( // new RustPartitionScanner(), // new String[] { // RustPartitionScanner.RUST_MULTILINE_COMMENT }); // partitioner.connect(document); // document.setDocumentPartitioner(partitioner); // } // return document; IDocument document = super.createDocument(element); if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3= (IDocumentExtension3) document; IDocumentPartitioner partitioner= new FastPartitioner(RustCorePlugin.getDefault().scanners().rustPartitionScanner(), RustPartitionScanner.PARTITION_TYPES); extension3.setDocumentPartitioner(RustConstants.RUST_PARTITIONING, partitioner); partitioner.connect(document); } return document; }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static String[] getAllDocumentContentTypes(IDocument document) throws BadPartitioningException { if (document instanceof IDocumentExtension3) { IDocumentExtension3 ext = (IDocumentExtension3) document; String[] partitionings = ext.getPartitionings(); Set contentTypes = new HashSet(); contentTypes.add(IDocument.DEFAULT_CONTENT_TYPE); int len = partitionings.length; for (int i = 0; i < len; i++) { String[] legalContentTypes = ext.getLegalContentTypes(partitionings[i]); int len2 = legalContentTypes.length; for (int j = 0; j < len2; j++) { contentTypes.add(legalContentTypes[j]); } contentTypes.addAll(Arrays.asList(legalContentTypes)); } return (String[]) contentTypes.toArray(new String[contentTypes.size()]); } return document.getLegalContentTypes(); }
/** * Checks if the partitioner is correctly set in the document. * @return the partitioner that is set in the document */ public static IDocumentPartitioner checkPartitionScanner(IDocument document, IGrammarVersionProvider grammarVersionProvider) { if (document == null) { return null; } IDocumentExtension3 docExtension = (IDocumentExtension3) document; IDocumentPartitioner partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE); if (partitioner == null) { addPartitionScanner(document, grammarVersionProvider); //get it again for the next check partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE); } if (!(partitioner instanceof PyPartitioner)) { Log.log("Partitioner should be subclass of PyPartitioner. It is " + partitioner.getClass()); } return partitioner; }
/** * @see http://help.eclipse.org/help31/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_documents.htm * @see http://jroller.com/page/bobfoster - Saturday July 16, 2005 * @param document the document where we want to add the partitioner * @return the added document partitioner (or null) */ public static IDocumentPartitioner addPartitionScanner(IDocument document, IGrammarVersionProvider grammarVersionProvider) { if (document != null) { IDocumentExtension3 docExtension = (IDocumentExtension3) document; IDocumentPartitioner curr = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE); if (curr == null) { //set the new one PyPartitioner partitioner = createPyPartitioner(); partitioner.connect(document); docExtension.setDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE, partitioner); return partitioner; } else { return curr; } } return null; }
protected AbstractDocumentScanner(IDocument document, String partitioning, String contentType) { this.document = assertNotNull(document); this.partitioning = partitioning; this.source = document.get(); if(partitioning == null) { this.contentType = IDocument.DEFAULT_CONTENT_TYPE; this.documentExt3 = null; this.partitioner = null; } else { Assert.isLegal(partitioning != null); Assert.isLegal(contentType != null); this.contentType = contentType; this.documentExt3 = tryCast(document, IDocumentExtension3.class); Assert.isLegal(documentExt3 != null, "document must support IDocumentExtension3"); this.partitioner = documentExt3.getDocumentPartitioner(partitioning); Assert.isLegal(partitioner != null, "document must have a partitioner for " + partitioning); } }
void setupDocument(IDocument document) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 ext= (IDocumentExtension3) document; IDocumentPartitioner partitioner= createRecipePartitioner(); partitioner.connect(document); ext.setDocumentPartitioner(SQL_PARTITIONING, partitioner); } }
/** * Indique si l'offset d'un document donné se trouve dans une région donnée. * * @param document Document. * @param offset Offset. * @param contentType Content type de la région. * @return */ public static boolean isContentType(IDocument document, int offset, KspRegionType regionType) { try { /* Extrait le type de la partition. */ IDocumentExtension3 de3 = (IDocumentExtension3) document; String regionContentType = de3.getContentType(KspRegionType.PARTITIONING, offset, true); /* Vérifie que la région correspond. */ return regionType.getContentType().equals(regionContentType); } catch (BadLocationException | BadPartitioningException e) { ErrorUtils.handle(e); } return false; }
/** * Indique si une sélection d'un document représente exactement une région de string (aux double quote près). * * @param document Document. * @param selection Sélection de texte. * @return <code>true</code> si c'est exactement une région de string. */ public static boolean isExactKspString(IDocument document, ITextSelection selection) { IDocumentExtension3 extension = (IDocumentExtension3) document; try { /* Charge les régions du document couverte par la sélecion. */ ITypedRegion[] regions = extension.computePartitioning(KspRegionType.PARTITIONING, selection.getOffset(), selection.getLength(), false); /* Vérifie qu'on a une seule région. */ if (regions.length != 1) { return false; } /* Charge la région entière */ ITypedRegion region = extension.getPartition(KspRegionType.PARTITIONING, selection.getOffset(), false); /* Vérifie que c'est une région de string KSP. */ if (!region.getType().equals(KspRegionType.STRING.getContentType())) { return false; } /* Vérifie que la région couvre exactement la sélection */ int selectionWithQuoteOffset = selection.getOffset() - 1; // Prend en compte la double quote ouvrante. int selectionWithQuoteLength = selection.getLength() + 2; // Prend en compte les deux double quote. if (region.getOffset() == selectionWithQuoteOffset && region.getLength() == selectionWithQuoteLength) { return true; } } catch (BadLocationException | BadPartitioningException e) { ErrorUtils.handle(e); } return false; }
@Override public void setup(IDocument document) { /* Définit un partitionnement du document. */ IDocumentPartitioner p = new FastPartitioner(createKspPartitionScanner(), TYPES); IDocumentExtension3 de3 = (IDocumentExtension3) document; de3.setDocumentPartitioner(KspRegionType.PARTITIONING, p); p.connect(document); }
@Override protected IDocument createDocument(Object element) throws CoreException { IDocument document = super.createDocument(element); if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3 = (IDocumentExtension3) document; IDocumentPartitioner partitioner = new FastPartitioner(EiffelEditorPlugin .getPartitionScanner(), EiffelPartitionScanner.PARTITION_TYPE); extension3.setDocumentPartitioner(EiffelEditorPlugin.MY_PARTITIONING, partitioner); partitioner.connect(document); } return document; }
@Override protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) { super.configureSourceViewerDecorationSupport(support); char[] matchChars = { '(', ')', '[', ']', '{', '}' }; // which brackets // to match matcher = new DefaultCharacterPairMatcher(matchChars, IDocumentExtension3.DEFAULT_PARTITIONING); support.setCharacterPairMatcher(matcher); support.setMatchingCharacterPainterPreferenceKeys(EDITOR_MATCHING_BRACKETS, EDITOR_MATCHING_BRACKETS_COLOR); // Enable bracket highlighting in the preference store IPreferenceStore store = getPreferenceStore(); store.setDefault(EDITOR_MATCHING_BRACKETS, true); store.setDefault(EDITOR_MATCHING_BRACKETS_COLOR, "128,128,128"); }
/** * Returns all possible content types of <code>document</code>. * * @param document * the document * @return all possible content types of <code>document</code> * @throws BadPartitioningException * if partitioning is invalid for this document * @since 3.1 */ private String[] getContentTypes(IDocument document) throws BadPartitioningException { if (document instanceof IDocumentExtension3) { IDocumentExtension3 ext = (IDocumentExtension3) document; String[] partitionings = ext.getPartitionings(); Set contentTypes = new HashSet(20); for (int i = 0; i < partitionings.length; i++) { contentTypes.addAll(Arrays.asList(ext.getLegalContentTypes(partitionings[i]))); } contentTypes.add(IDocument.DEFAULT_CONTENT_TYPE); return (String[]) contentTypes.toArray(new String[contentTypes.size()]); } return document.getLegalContentTypes(); }
@Override public void setup(IDocument document) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3= (IDocumentExtension3) document; IDocumentPartitioner partitioner= new FastPartitioner(SqlCommentPartitionScanner.getDefault(), SqlCommentPartitionScanner.partition_types); extension3.setDocumentPartitioner(FtcPlugin.SQL_PARTITIONING, partitioner); partitioner.connect(document); } }
public void setup(IDocument document) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3 = (IDocumentExtension3) document; IDocumentPartitioner partitioner = new FastPartitioner(new BibPartitionScanner(), BibPartitionScanner.BIB_PARTITION_TYPES); extension3.setDocumentPartitioner(BibEditor.BIB_PARTITIONING, partitioner); partitioner.connect(document); } }
public void setup(IDocument document) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3= (IDocumentExtension3) document; IDocumentPartitioner partitioner = new FastPartitioner( new FastLaTeXPartitionScanner(), FastLaTeXPartitionScanner.TEX_PARTITION_TYPES); extension3.setDocumentPartitioner(TexEditor.TEX_PARTITIONING, partitioner); partitioner.connect(document); } }
public void customizeDocumentCommand(IDocument document, DocumentCommand command) { if (this.indent) { if (itemSetted && autoItem && command.length == 0 && command.text != null && TextUtilities.endsWith(document.getLegalLineDelimiters(), command.text) != -1) { dropItem(document, command); } else if (command.length == 0 && command.text != null && TextUtilities.endsWith(document.getLegalLineDelimiters(), command.text) != -1) { smartIndentAfterNewLine(document, command); } else if ("}".equals(command.text)) { smartIndentAfterBrace(document, command); } else { itemSetted = false; } } if (TexAutoIndentStrategy.hardWrap && command.length == 0 && command.text != null) { try { final String contentType = ((IDocumentExtension3) document).getContentType( TexEditor.TEX_PARTITIONING, command.offset, true); // Do not wrap in verbatim partitions if (!FastLaTeXPartitionScanner.TEX_VERBATIM.equals(contentType)) { hlw.doWrapB(document, command, lineLength); } } catch (Exception e) { // If we cannot retrieve the current content type, do not break lines } } }
public void setup(IDocument document) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3= (IDocumentExtension3) document; IDocumentPartitioner partitioner= new TLAFastPartitioner(TLAEditorActivator.getDefault().getTLAPartitionScanner(), TLAPartitionScanner.TLA_PARTITION_TYPES); // Changed from FastPartitioner by LL on 12 Aug 2012 extension3.setDocumentPartitioner(TLAPartitionScanner.TLA_PARTITIONING, partitioner); partitioner.connect(document); } }
private void connectPartitioningToElement(IEditorInput input, IDocument document) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension = (IDocumentExtension3) document; if (extension.getDocumentPartitioner(Partitions.MK_PARTITIONING) == null) { FluentMkDocumentSetupParticipant participant = new FluentMkDocumentSetupParticipant(tools); participant.setup(document); } } }
/** * Sets up the document partitioner for the given document for the given partitioning. */ public void setupDocumentPartitioner(IDocument document, String partitioning) { IDocumentPartitioner partitioner = createDocumentPartitioner(); if (partitioner != null) { partitioner.connect(document); if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3 = (IDocumentExtension3) document; extension3.setDocumentPartitioner(partitioning, partitioner); } else { document.setDocumentPartitioner(partitioner); } } }
@Override protected int getLineStartPosition(final IDocument document, final String line, final int length, final int offset) { String type = IDocument.DEFAULT_CONTENT_TYPE; try { type = TextUtilities.getContentType(document, IDocumentExtension3.DEFAULT_PARTITIONING, offset, false); } catch (BadLocationException exception) { // Should not happen } int lineStartPosition = super.getLineStartPosition(document, line, length, offset); if (tokenTypeToPartitionTypeMapperExtension.isMultiLineComment(type) || tokenTypeToPartitionTypeMapperExtension.isSingleLineComment(type)) { try { IRegion lineInformation = document.getLineInformationOfOffset(offset); int offsetInLine = offset - lineInformation.getOffset(); return getCommentLineStartPosition(line, length, offsetInLine, lineStartPosition); } catch(BadLocationException e) { // Should not happen } } if (type.equals(IDocument.DEFAULT_CONTENT_TYPE)) { if (isStartOfSingleLineComment(line, length, lineStartPosition) && !isStartOfMultiLineComment(line, length, lineStartPosition)) { return getTextStartPosition(line, length, lineStartPosition + 1); } } return lineStartPosition; }
protected void connectPartitioningToElement(IEditorInput input, IDocument document) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension = (IDocumentExtension3) document; if (extension.getDocumentPartitioner(JuliaPartition.JULIA_PARTITIONING) == null) { JuliaTextTools tools = JuliaEditorPlugin.getDefault().getTextTools(); tools.setupDocumentPartitioner(document, JuliaPartition.JULIA_PARTITIONING); } } }
public IStructuredDocument clone(IDocument original) { IModelManager modelManager = StructuredModelManager.getModelManager(); String modelId = getModelId(original); if (modelId == null) { GWTPluginLog.logError("Could not get a model ID for the document to be formatted."); return null; } /* * The XML formatter requires a managed model (discovered by it crashing * when given an unmanaged model.) Unfortunately, we cannot create a managed * in-memory (i.e. non-file backed) model via IModelManager API (there is * one method that may work, but it is deprecated.) Instead, we copy the * existing model into a temp model with ID "temp". */ try { IStructuredModel modelClone = modelManager.copyModelForEdit(modelId, "structuredDocumentClonerModel" + nextId.getAndIncrement()); modelClone.setBaseLocation(getModelBaseLocation(original)); IStructuredDocument documentClone = modelClone.getStructuredDocument(); documentClone.set(original.get()); // Create and connect the partitioner to the document IDocumentPartitioner tempPartitioner = documentPartitionerFactory.createDocumentPartitioner(); ((IDocumentExtension3) documentClone).setDocumentPartitioner( partitioning, tempPartitioner); tempPartitioner.connect(documentClone); // Save the cloned model so we can release it later modelClones.put(documentClone, modelClone); return documentClone; } catch (ResourceInUse e1) { GWTPluginLog.logError(e1, "Could not copy the original model to be formatted."); return null; } }
@Override public void setup(IDocument document) { if (document instanceof IDocumentExtension3) { final IDocumentExtension3 ext3 = (IDocumentExtension3) document; IDocumentPartitioner partitioner = new FastPartitioner(new BfPartitionScanner(), EditorConstants.BRAINFUCK_PARTITION_TYPES); partitioner.connect(document); ext3.setDocumentPartitioner(EditorConstants.BF_PARTITIONING, partitioner); } }