@Override public void format() { super.format(); final IDocument document = fDocuments.removeFirst(); final TypedPosition partition = fPartitions.removeFirst(); if (document == null || partition == null) { return; } try { String formatted = formatElement(document, partition); String partitionText = document.get(partition.getOffset(), partition.getLength()); if (formatted != null && !formatted.equals(partitionText)) { document.replace(partition.getOffset(), partition.getLength(), formatted); } } catch (BadLocationException e) { // do nothing } }
private void removeRangeMarkers(List<TypedPosition> positions, IDocument document, TemplateVariable[] variables) throws MalformedTreeException, BadLocationException, BadPositionCategoryException { // revert previous changes for (Iterator<TypedPosition> it= positions.iterator(); it.hasNext();) { TypedPosition position= it.next(); // remove and re-add in order to not confuse ExclusivePositionUpdater document.removePosition(CATEGORY, position); final String original= position.getType(); if (original != null) { document.replace(position.getOffset(), position.getLength(), original); position.setLength(original.length()); } document.addPosition(position); } Iterator<TypedPosition> it= positions.iterator(); for (int i= 0; i != variables.length; i++) { TemplateVariable variable= variables[i]; int[] offsets= new int[variable.getOffsets().length]; for (int j= 0; j != offsets.length; j++) offsets[j]= it.next().getOffset(); variable.setOffsets(offsets); } } }
private void removeRangeMarkers(List<TypedPosition> positions, IDocument document, TemplateVariable[] variables) throws MalformedTreeException, BadLocationException, BadPositionCategoryException { // revert previous changes for (Iterator<TypedPosition> it= positions.iterator(); it.hasNext();) { TypedPosition position= it.next(); // remove and re-add in order to not confuse ExclusivePositionUpdater document.removePosition(CATEGORY, position); final String original= position.getType(); if (original != null) { document.replace(position.getOffset(), position.getLength(), original); position.setLength(original.length()); } document.addPosition(position); } Iterator<TypedPosition> it= positions.iterator(); for (int i= 0; i != variables.length; i++) { TemplateVariable variable= variables[i]; int[] offsets= new int[variable.getOffsets().length]; for (int j= 0; j != offsets.length; j++) offsets[j]= it.next().getOffset(); variable.setOffsets(offsets); } } }
private String formatElement(IDocument document, TypedPosition partition) throws BadLocationException { String partitionText = document.get(partition.getOffset(), partition.getLength()); IRegion line = document.getLineInformationOfOffset(partition.getOffset()); int indentLength = partition.getOffset() - line.getOffset(); String lineDelimiter = document.getLineDelimiter(document.getLineOfOffset(line.getOffset())); if (lineDelimiter == null) { lineDelimiter = TextUtilities.getDefaultLineDelimiter(document); } return XmlTagFormatter.format(partitionText, prefs, document.get(line.getOffset(), indentLength), lineDelimiter); }
private void removeRangeMarkers(List positions, IDocument document, TemplateVariable[] variables) throws MalformedTreeException, BadLocationException, BadPositionCategoryException { // revert previous changes for (Iterator it= positions.iterator(); it.hasNext();) { TypedPosition position= (TypedPosition) it.next(); // remove and re-add in order to not confuse ExclusivePositionUpdater document.removePosition(CATEGORY, position); final String original= position.getType(); if (original != null) { document.replace(position.getOffset(), position.getLength(), original); position.setLength(original.length()); } document.addPosition(position); } Iterator it= positions.iterator(); for (int i= 0; i != variables.length; i++) { TemplateVariable variable= variables[i]; int[] offsets= new int[variable.getOffsets().length]; for (int j= 0; j != offsets.length; j++) offsets[j]= ((Position) it.next()).getOffset(); variable.setOffsets(offsets); } } }
@Override public ITypedRegion getPartition(int offset) { try { Position[] category = fDocument.getPositions(fPositionCategory); if (category == null || category.length == 0) return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); int index= fDocument.computeIndexInCategory(fPositionCategory, offset); if (index < category.length) { TypedPosition next= (TypedPosition) category[index]; if (offset == next.offset) return new TypedRegion(next.getOffset(), next.getLength(), next.getType()); if (index == 0) return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE); TypedPosition previous= (TypedPosition) category[index - 1]; if (previous.includes(offset)) return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); } TypedPosition previous= (TypedPosition) category[category.length - 1]; if (previous.includes(offset)) return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); } catch (BadPositionCategoryException x) { } catch (BadLocationException x) { } return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); }
@Override public ITypedRegion getPartition(int offset) { try { Position[] category = fDocument.getPositions(fPositionCategory); if (category == null || category.length == 0) return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); int index= fDocument.computeIndexInCategory(fPositionCategory, offset); if (index < category.length) { TypedPosition next= (TypedPosition) category[index]; if (offset == next.offset) return new TypedRegion(next.getOffset(), next.getLength(), next.getType()); if (index == 0) return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE); TypedPosition previous= (TypedPosition) category[index - 1]; if (previous.includes(offset)) return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); } TypedPosition previous= (TypedPosition) category[category.length - 1]; if (previous.includes(offset)) return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); } catch (BadPositionCategoryException x) { } catch (BadLocationException x) { } return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); }
@Override public ITypedRegion getPartition(int offset) { checkInitialization(); try { Position[] category = fDocument.getPositions(fPositionCategory); if (category == null || category.length == 0) return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); int index= fDocument.computeIndexInCategory(fPositionCategory, offset); if (index < category.length) { TypedPosition next= (TypedPosition) category[index]; if (offset == next.offset) return new TypedRegion(next.getOffset(), next.getLength(), next.getType()); if (index == 0) return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE); TypedPosition previous= (TypedPosition) category[index - 1]; if (previous.includes(offset)) return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); } TypedPosition previous= (TypedPosition) category[category.length - 1]; if (previous.includes(offset)) return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); } catch (BadPositionCategoryException x) { } catch (BadLocationException x) { } return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); }
@Override public ITypedRegion getPartition(int offset) { checkInitialization(); try { Position[] category = fDocument.getPositions(fPositionCategory); if (category == null || category.length == 0) return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); int index= fDocument.computeIndexInCategory(fPositionCategory, offset); if (index < category.length) { TypedPosition next= (TypedPosition) category[index]; if (offset == next.offset) return new TypedRegion(next.getOffset(), next.getLength(), next.getType()); if (index == 0) return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE); TypedPosition previous= (TypedPosition) category[index - 1]; if (previous.includes(offset)) return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); } TypedPosition previous= (TypedPosition) category[category.length - 1]; if (previous.includes(offset)) return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); } catch (BadPositionCategoryException x) { } catch (BadLocationException x) { } return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); }
return new TypedRegion(next.getOffset(), next.getLength(), next.getType()); return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
return new TypedRegion(next.getOffset(), next.getLength(), next.getType()); return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
return new TypedRegion(next.getOffset(), next.getLength(), next.getType()); return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE); return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType()); int endOffset= previous.getOffset() + previous.getLength(); return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
@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); } } }
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); } } }
@Override public void format() { super.format(); final IDocument document= fDocuments.removeFirst(); final TypedPosition partition= fPartitions.removeFirst(); if (document != null && partition != null) { Map<String, IDocumentPartitioner> partitioners= null; try { final TextEdit edit= CodeFormatterUtil.reformat(CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 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 int offset= region.getOffset(); int length= region.getLength();
try { final int offset= region.getOffset(); int length= region.getLength();
return -1; int end= fRememberedPosition == null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength(); if (endOffset < end && end < d.getLength()) partition= getPartition(d, end);
return -1; int end= fRememberedPosition == null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength(); if (endOffset < end && end < d.getLength()) partition= getPartition(d, end);
return -1; int end= fRememberedPosition == null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength(); if (endOffset < end && end < d.getLength()) partition= getPartition(d, end);