public String apply(String contents) { final TextEdit edit = codeFormatter.format( CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, contents, 0, contents.length(), 0, Constants.LINE_SEPARATOR); if (edit == null) { // TODO log a fatal or warning here. Throwing an exception is causing the actual freemarker error to be lost return contents; } IDocument document = new Document(contents); try { edit.apply(document); } catch (Exception e) { throw new RuntimeException( "Failed to format the generated source code.", e); } return document.get(); } }
@Override public synchronized String get(int pos, int length) throws BadLocationException { return super.get(pos, length); } /* (non-Javadoc)
@Override public synchronized void replace(int pos, int length, String text) throws BadLocationException { super.replace(pos, length, text); } /* (non-Javadoc)
@Override protected String getLine(Document d, int line) throws BadLocationException { return d.get(d.getLineOffset(line), d.getLineLength(line)); }
protected static String getSourceFormatted(String unformattedJavaSource, IJavaProject settings, IProgressMonitor monitor, IWorkingCopyManager workingCopyManager) throws CoreException { SourceFormatOperation op = new SourceFormatOperation(settings, new Document(unformattedJavaSource)); op.validate(); op.run(monitor, workingCopyManager); return op.getDocument().get(); }
@Override public boolean isLineInformationRepairNeeded(int offset, int length, String text) throws BadLocationException { if ((0 > offset) || (0 > length) || (offset + length > getLength())) throw new BadLocationException(); return isLineInformationRepairNeeded(text) || isLineInformationRepairNeeded(get(offset, length)); }
@Override public synchronized void set(String text) { super.set(text); } /* (non-Javadoc)
protected String getIndent(Document sourceDocument, ISourceRange replaceRange) throws BadLocationException { IRegion line = sourceDocument.getLineInformationOfOffset(replaceRange.getOffset()); Matcher matcher = REGEX_WHITE_SPACE_START.matcher(sourceDocument.get(line.getOffset(), line.getLength())); if (matcher.find()) { return matcher.group(1); } return ""; }
protected IRegion check(String before, int start, int replaceLength, String text) throws Exception { Document doc = createDocument(before); damager.setDocument(doc); doc.addDocumentListener(this); doc.replace(start, replaceLength, text); return lastRegion; }
@Override public synchronized void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException { super.addPosition(category, position); } /* (non-Javadoc)
@Override public boolean isLineInformationRepairNeeded(int offset, int length, String text) throws BadLocationException { if ((0 > offset) || (0 > length) || (offset + length > getLength())) throw new BadLocationException(); return isLineInformationRepairNeeded(text) || isLineInformationRepairNeeded(get(offset, length)); }
public synchronized void set(String text) { super.set(text); } /* (non-Javadoc)
protected String getLine(Document d, int line) throws BadLocationException { return d.get(d.getLineOffset(line), d.getLineLength(line)); }
protected IRegion check(String before, int start, int replaceLength, String text) throws Exception { Document doc = createDocument(before); damager.setDocument(doc); doc.addDocumentListener(this); doc.replace(start, replaceLength, text); return lastRegion; }
public synchronized void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException { super.addPosition(category, position); } /* (non-Javadoc)
public PDESourceViewer(PDEFormPage page) { // Create the underlying document fDocument = new Document(); fPage = page; }
public synchronized String get(int pos, int length) throws BadLocationException { return super.get(pos, length); } /* (non-Javadoc)
public synchronized void replace(int pos, int length, String text) throws BadLocationException { super.replace(pos, length, text); } /* (non-Javadoc)