use of org.eclipse.jface.text.Document in project che by eclipse.
the class TemplateProposal method getAdditionalProposalInfo.
/*
* @see ICompletionProposal#getAdditionalProposalInfo()
*/
public String getAdditionalProposalInfo() {
try {
fContext.setReadOnly(true);
TemplateBuffer templateBuffer;
try {
templateBuffer = fContext.evaluate(fTemplate);
} catch (TemplateException e) {
return null;
}
IDocument document = new Document(templateBuffer.getString());
IndentUtil.indentLines(document, new LineRange(0, document.getNumberOfLines()), null, null);
StringBuffer buffer = new StringBuffer();
HTMLPrinter.insertPageProlog(buffer, 0, JavadocFinder.getStyleSheet());
HTMLPrinter.addParagraph(buffer, document.get());
HTMLPrinter.addPageEpilog(buffer);
return buffer.toString();
} catch (BadLocationException e) {
// handleException(
// JavaPlugin.getActiveWorkbenchShell(), new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "", e))); //$NON-NLS-1$
JavaPlugin.log(e);
return null;
}
}
use of org.eclipse.jface.text.Document in project che by eclipse.
the class InlineTempRefactoring method createParameterizedInvocation.
private String createParameterizedInvocation(Expression invocation, ITypeBinding[] typeArguments, CompilationUnitRewrite cuRewrite) throws JavaModelException {
ASTRewrite rewrite = ASTRewrite.create(invocation.getAST());
ListRewrite typeArgsRewrite = Invocations.getInferredTypeArgumentsRewrite(rewrite, invocation);
for (int i = 0; i < typeArguments.length; i++) {
Type typeArgumentNode = cuRewrite.getImportRewrite().addImport(typeArguments[i], cuRewrite.getAST());
typeArgsRewrite.insertLast(typeArgumentNode, null);
}
if (invocation instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) invocation;
Expression expression = methodInvocation.getExpression();
if (expression == null) {
IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
if (methodBinding != null && Modifier.isStatic(methodBinding.getModifiers())) {
expression = cuRewrite.getAST().newName(cuRewrite.getImportRewrite().addImport(methodBinding.getDeclaringClass().getTypeDeclaration()));
} else {
expression = invocation.getAST().newThisExpression();
}
rewrite.set(invocation, MethodInvocation.EXPRESSION_PROPERTY, expression, null);
}
}
IDocument document = new Document(fCu.getBuffer().getContents());
final RangeMarker marker = new RangeMarker(invocation.getStartPosition(), invocation.getLength());
IJavaProject project = fCu.getJavaProject();
TextEdit[] rewriteEdits = rewrite.rewriteAST(document, project.getOptions(true)).removeChildren();
marker.addChildren(rewriteEdits);
try {
marker.apply(document, TextEdit.UPDATE_REGIONS);
String rewrittenInitializer = document.get(marker.getOffset(), marker.getLength());
IRegion region = document.getLineInformation(document.getLineOfOffset(marker.getOffset()));
int oldIndent = Strings.computeIndentUnits(document.get(region.getOffset(), region.getLength()), project);
//$NON-NLS-1$
return Strings.changeIndent(rewrittenInitializer, oldIndent, project, "", TextUtilities.getDefaultLineDelimiter(document));
} catch (MalformedTreeException e) {
JavaPlugin.log(e);
} catch (BadLocationException e) {
JavaPlugin.log(e);
}
//fallback:
return fCu.getBuffer().getText(invocation.getStartPosition(), invocation.getLength());
}
use of org.eclipse.jface.text.Document in project che by eclipse.
the class MultiStateTextFileChange method getPreviewDocument.
/**
* Returns a document representing the preview of the refactored buffer,
* after the application of the change object.
*
* @param monitor
* the progress monitor to use, or <code>null</code>
* @return the preview document, or an empty document
* @throws CoreException
* if no document could be acquired
*/
public final IDocument getPreviewDocument(IProgressMonitor monitor) throws CoreException {
if (monitor == null)
monitor = new NullProgressMonitor();
IDocument result = null;
IDocument document = null;
try {
document = acquireDocument(new SubProgressMonitor(monitor, 1));
if (document != null) {
result = new Document(document.get());
performChanges(result, null, true);
}
} catch (BadLocationException exception) {
throw Changes.asCoreException(exception);
} finally {
if (document != null) {
releaseDocument(document, new SubProgressMonitor(monitor, 1));
}
monitor.done();
}
if (result == null)
result = new Document();
return result;
}
use of org.eclipse.jface.text.Document in project che by eclipse.
the class TextChange method getPreviewDocument.
//---- private helper methods --------------------------------------------------
private PreviewAndRegion getPreviewDocument(TextEditBasedChangeGroup[] changes, IProgressMonitor pm) throws CoreException {
IDocument document = new Document(getCurrentDocument(pm).get());
boolean trackChanges = getKeepPreviewEdits();
setKeepPreviewEdits(true);
TextEditProcessor processor = changes == ALL_EDITS ? createTextEditProcessor(document, TextEdit.NONE, true) : createTextEditProcessor(document, TextEdit.NONE, changes);
try {
processor.performEdits();
return new PreviewAndRegion(document, getNewRegion(changes));
} catch (BadLocationException e) {
throw Changes.asCoreException(e);
} finally {
setKeepPreviewEdits(trackChanges);
}
}
use of org.eclipse.jface.text.Document in project che by eclipse.
the class QuickFixTest method getWizardPreviewContent.
protected static String getWizardPreviewContent(NewCUUsingWizardProposal newCUWizard) throws CoreException, BadLocationException {
newCUWizard.setShowDialog(false);
newCUWizard.apply(null);
IType createdType = newCUWizard.getCreatedType();
assertTrue("Nothing created", createdType.exists());
String preview = createdType.getCompilationUnit().getSource();
IJavaElement parent = createdType.getParent();
if (parent instanceof IType) {
createdType.delete(true, null);
} else {
JavaProjectHelper.delete(parent);
}
StringBuffer res = new StringBuffer();
IDocument doc = new Document(preview);
int nLines = doc.getNumberOfLines();
for (int i = 0; i < nLines; i++) {
IRegion lineInformation = doc.getLineInformation(i);
res.append(doc.get(lineInformation.getOffset(), lineInformation.getLength()));
if (i != nLines - 1) {
res.append('\n');
}
}
return res.toString();
}
Aggregations