use of org.eclipse.jdt.internal.core.DocumentAdapter in project che by eclipse.
the class SearchManager method getDocument.
private IDocument getDocument(ICompilationUnit ancestor) throws JavaModelException {
IDocument document;
IBuffer buffer = ancestor.getBuffer();
if (buffer instanceof org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) {
document = ((org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) buffer).getDocument();
} else {
document = new DocumentAdapter(buffer);
}
return document;
}
use of org.eclipse.jdt.internal.core.DocumentAdapter in project che by eclipse.
the class CompletionJavadocTest method computeProposals.
private static List<ICompletionProposal> computeProposals(ICompilationUnit compilationUnit, int offset) throws JavaModelException {
IBuffer buffer = compilationUnit.getBuffer();
IDocument document;
if (buffer instanceof org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) {
document = ((org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) buffer).getDocument();
} else {
document = new DocumentAdapter(buffer);
}
TextViewer viewer = new TextViewer(document, new Point(offset, 0));
JavaContentAssistInvocationContext context = new JavaContentAssistInvocationContext(viewer, offset, compilationUnit);
List<ICompletionProposal> proposals = new ArrayList<>();
proposals.addAll(new JavaAllCompletionProposalComputer().computeCompletionProposals(context, null));
// proposals.addAll(new TemplateCompletionProposalComputer().computeCompletionProposals(context, null));
Collections.sort(proposals, new RelevanceSorter());
return proposals;
}
use of org.eclipse.jdt.internal.core.DocumentAdapter in project flux by eclipse.
the class QuickAssistService method applyProposals.
private JSONObject applyProposals(int offset, int length, boolean applyFix, ICompilationUnit liveEditUnit, IProblemLocation problem) throws CoreException, JavaModelException, JSONException {
IInvocationContext context = new AssistContext(liveEditUnit, offset, length);
QuickFixProcessor processor = new QuickFixProcessor();
IJavaCompletionProposal[] proposals = processor.getCorrections(context, new IProblemLocation[] { problem });
if (proposals == null || proposals.length == 0) {
return null;
}
if (applyFix) {
IBuffer buffer = liveEditUnit.getBuffer();
if (buffer != null) {
IDocument document = buffer instanceof IDocument ? (IDocument) buffer : new DocumentAdapter(buffer);
if (proposals[0] instanceof CUCorrectionProposal) {
CUCorrectionProposal proposal = (CUCorrectionProposal) proposals[0];
String preview = proposal.getPreviewContent();
System.out.println(document.getLength());
System.out.println(preview.length());
try {
document.addDocumentListener(this.documentListener);
document.replace(0, preview.length(), preview);
// proposal.apply(document);
liveEditUnit.getBuffer().setContents(proposal.getPreviewContent());
liveEditUnit.reconcile(ICompilationUnit.NO_AST, true, null, null);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
return null;
} else {
List<JSONObject> jsonProposals = new ArrayList<JSONObject>(proposals.length);
for (IJavaCompletionProposal proposal : proposals) {
JSONObject jsonDescription = getDescription(proposal);
JSONObject jsonProposal = new JSONObject();
jsonProposal.put("description", jsonDescription);
jsonProposal.put("relevance", proposal.getRelevance());
jsonProposals.add(jsonProposal);
}
JSONObject result = new JSONObject();
result.put("quickfix", jsonProposals);
return result;
}
}
use of org.eclipse.jdt.internal.core.DocumentAdapter in project che by eclipse.
the class CodeAssist method computeProposals.
public Proposals computeProposals(IJavaProject project, String fqn, int offset, final String content) throws JavaModelException {
WorkingCopyOwner copyOwner = new WorkingCopyOwner() {
@Override
public IBuffer createBuffer(ICompilationUnit workingCopy) {
return new org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter(workingCopy, workingCopy.getPath(), content);
}
};
ICompilationUnit compilationUnit;
IType type = project.findType(fqn);
if (type == null) {
return null;
}
if (type.isBinary()) {
compilationUnit = type.getClassFile().getWorkingCopy(copyOwner, null);
} else {
compilationUnit = type.getCompilationUnit().getWorkingCopy(copyOwner, null);
}
IBuffer buffer = compilationUnit.getBuffer();
IDocument document;
if (buffer instanceof org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) {
document = ((org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) buffer).getDocument();
} else {
document = new DocumentAdapter(buffer);
}
TextViewer viewer = new TextViewer(document, new Point(offset, 0));
JavaContentAssistInvocationContext context = new JavaContentAssistInvocationContext(viewer, offset, compilationUnit);
List<ICompletionProposal> proposals = new ArrayList<>();
proposals.addAll(new JavaAllCompletionProposalComputer().computeCompletionProposals(context, null));
proposals.addAll(new TemplateCompletionProposalComputer().computeCompletionProposals(context, null));
Collections.sort(proposals, new RelevanceSorter());
return convertProposals(offset, compilationUnit, viewer, proposals);
}
Aggregations