@Override public String getLineDelimiter() { if (fLineDelimiter == null) fLineDelimiter= TextUtilities.getDefaultLineDelimiter(fDocument); return fLineDelimiter; }
/** * Determines which one of default line delimiters appears first in the list. If none of them the * hint is returned. * * @param text the text to be checked * @param hint the line delimiter hint * @return the line delimiter */ public static String determineLineDelimiter(String text, String hint) { try { int[] info= indexOf(DELIMITERS, text, 0); return DELIMITERS[info[1]]; } catch (ArrayIndexOutOfBoundsException x) { } return hint; }
private boolean isLineDelimiter(IDocument document, String text) { String[] delimiters= document.getLegalLineDelimiters(); if (delimiters != null) return TextUtilities.equals(delimiters, text) > -1; return false; }
@Override public void format() { super.format(); final IDocument document= fDocuments.removeFirst(); final TypedPosition partition= fPartitions.removeFirst(); final String path= fPaths.removeFirst(); if (document != null && partition != null) { Map<String, IDocumentPartitioner> partitioners= null; try { final boolean isModuleInfo= path != null && path.endsWith(JavaModelUtil.MODULE_INFO_JAVA); final int kind= (isModuleInfo ? CodeFormatter.K_MODULE_INFO : CodeFormatter.K_COMPILATION_UNIT) | CodeFormatter.F_INCLUDE_COMMENTS; final TextEdit edit= CodeFormatterUtil.reformat(kind, document.get(), partition.getOffset(), partition.getLength(), 0, TextUtilities.getDefaultLineDelimiter(document), getPreferences()); if (edit != null) { if (edit.getChildrenSize() > 20) partitioners= TextUtilities.removeDocumentPartitioners(document); edit.apply(document); } } catch (MalformedTreeException exception) { JavaPlugin.log(exception); } catch (BadLocationException exception) { // Can only happen on concurrent document modification - log and bail out JavaPlugin.log(exception); } finally { if (partitioners != null) TextUtilities.addDocumentPartitioners(document, partitioners); } } }
try { final ITypedRegion[] partitions= TextUtilities.computePartitioning(document, fPartitioning, offset, length, false); partitions[0]= TextUtilities.getPartition(document, fPartitioning, partitions[0].getOffset(), false); partitions[partitions.length - 1]= TextUtilities.getPartition(document, fPartitioning, partitions[partitions.length - 1].getOffset(), false); ITypedRegion partition= null; partitioners= TextUtilities.removeDocumentPartitioners(document); TextUtilities.addDocumentPartitioners(document, partitioners);
private String getTokenContentType(int invocationOffset) throws BadLocationException { if (fContentAssistSubjectControl != null) { IDocument document= fContentAssistSubjectControl.getDocument(); if (document != null) { return TextUtilities.getContentType(document, fContentAssistant.getDocumentPartitioning(), invocationOffset, true); } } else { return TextUtilities.getContentType(fViewer.getDocument(), fContentAssistant.getDocumentPartitioning(), invocationOffset, true); } return IDocument.DEFAULT_CONTENT_TYPE; }
fRewriteTarget.beginCompoundChange(); Map partitioners= TextUtilities.removeDocumentPartitioners(document); TextUtilities.addDocumentPartitioners(document, partitioners);
ITextSelection selection= (ITextSelection) getSelection(); IRegion block= getTextBlockFromSelection(selection); ITypedRegion[] regions= TextUtilities.computePartitioning(d, getDocumentPartitioning(), block.getOffset(), block.getLength(), false); partitioners= TextUtilities.removeDocumentPartitioners(d); TextUtilities.addDocumentPartitioners(d, partitioners);
/** * {@inheritDoc} * <p> * May be replaced or extended by subclasses. * </p> */ @Override public String[] getLegalContentTypes() { return TextUtilities.copy(fLegalContentTypes); }
/** * Returns the partition for the given offset in the given document. * * @param document the document * @param offset the offset * @return the partition * @throws BadLocationException if offset is invalid in the given document * @since 3.0 */ private ITypedRegion getPartition(IDocument document, int offset) throws BadLocationException { return TextUtilities.getPartition(document, getDocumentPartitioning(), offset, false); } }
private void stopRewriteSession(ITextFileBuffer fileBuffer, Map<String, IDocumentPartitioner> stateData) { IDocument document= fileBuffer.getDocument(); if (document instanceof IDocumentExtension4) { IDocumentExtension4 extension= (IDocumentExtension4) document; extension.stopRewriteSession(fDocumentRewriteSession); fDocumentRewriteSession= null; } else if (stateData != null) TextUtilities.addDocumentPartitioners(document, stateData); }
private Object startRewriteSession(ITextFileBuffer fileBuffer) { Object stateData= null; IDocument document= fileBuffer.getDocument(); if (document instanceof IDocumentExtension4) { IDocumentExtension4 extension= (IDocumentExtension4) document; fDocumentRewriteSession= extension.startRewriteSession(getDocumentRewriteSessionType()); } else stateData= TextUtilities.removeDocumentPartitioners(document); return stateData; }
public void format() { super.format(); final IDocument document= (IDocument)fDocuments.removeFirst(); final TypedPosition partition= (TypedPosition)fPartitions.removeFirst(); if (document != null && partition != null) { Map partitioners= null; try { final TextEdit edit= CodeFormatterUtil.reformat(CodeFormatter.K_COMPILATION_UNIT, document.get(), partition.getOffset(), partition.getLength(), 0, TextUtilities.getDefaultLineDelimiter(document), getPreferences()); if (edit != null) { if (edit.getChildrenSize() > 20) partitioners= TextUtilities.removeDocumentPartitioners(document); edit.apply(document); } } catch (MalformedTreeException exception) { JavaPlugin.log(exception); } catch (BadLocationException exception) { // Can only happen on concurrent document modification - log and bail out JavaPlugin.log(exception); } finally { if (partitioners != null) TextUtilities.addDocumentPartitioners(document, partitioners); } } }
try { final ITypedRegion[] partitions= TextUtilities.computePartitioning(document, fPartitioning, offset, length, false); partitions[0]= TextUtilities.getPartition(document, fPartitioning, partitions[0].getOffset(), false); partitions[partitions.length - 1]= TextUtilities.getPartition(document, fPartitioning, partitions[partitions.length - 1].getOffset(), false); ITypedRegion partition= null; partitioners= TextUtilities.removeDocumentPartitioners(document); TextUtilities.addDocumentPartitioners(document, partitioners);
/** * Returns <code>true</code> if the character at the specified offset is a less-than sign, rather than * the opening angle bracket of a type parameter list. * * @param document a document * @param offset an offset within the document * @return <code>true</code> if the character at the specified offset is a less-than sign * @throws BadLocationException if offset is invalid in the document */ private boolean isLessThanOperator(IDocument document, int offset) throws BadLocationException { if (offset < 0) return false; String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, false); if (!IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { return false; } JavaHeuristicScanner scanner= new JavaHeuristicScanner(document, IJavaPartitions.JAVA_PARTITIONING, contentType); return !isTypeParameterOpeningBracket(offset, document, scanner); }
fRewriteTarget.beginCompoundChange(); Map<String, IDocumentPartitioner> partitioners= TextUtilities.removeDocumentPartitioners(document); TextUtilities.addDocumentPartitioners(document, partitioners);
ITextSelection selection= (ITextSelection) getSelection(); IRegion block= getTextBlockFromSelection(selection); ITypedRegion[] regions= TextUtilities.computePartitioning(d, getDocumentPartitioning(), block.getOffset(), block.getLength(), false); partitioners= TextUtilities.removeDocumentPartitioners(d); TextUtilities.addDocumentPartitioners(d, partitioners);
/** * {@inheritDoc} * <p> * May be replaced or extended by subclasses. * </p> */ @Override public String[] getLegalContentTypes() { return TextUtilities.copy(fLegalContentTypes); }
/** * Returns the partition for the given offset in the given document. * * @param document the document * @param offset the offset * @return the partition * @throws BadLocationException if offset is invalid in the given document * @since 3.0 */ private ITypedRegion getPartition(IDocument document, int offset) throws BadLocationException { return TextUtilities.getPartition(document, getDocumentPartitioning(), offset, false); } }
private void stopRewriteSession(ITextFileBuffer fileBuffer, Object stateData) { IDocument document= fileBuffer.getDocument(); if (document instanceof IDocumentExtension4) { IDocumentExtension4 extension= (IDocumentExtension4) document; extension.stopRewriteSession(fDocumentRewriteSession); fDocumentRewriteSession= null; } else if (stateData instanceof Map) TextUtilities.addDocumentPartitioners(document, (Map) stateData); }