use of org.eclipse.che.jdt.javaeditor.TextViewer 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.che.jdt.javaeditor.TextViewer in project che by eclipse.
the class CodeAssist method computeAssistProposals.
@SuppressWarnings("unchecked")
public Proposals computeAssistProposals(IJavaProject project, String fqn, int offset, List<Problem> problems) throws CoreException {
ICompilationUnit compilationUnit;
IType type = project.findType(fqn);
if (type == null) {
return null;
}
if (type.isBinary()) {
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.CORE_EXCEPTION, "Can't calculate Quick Assist on binary file"));
} else {
compilationUnit = type.getCompilationUnit();
}
IBuffer buffer = compilationUnit.getBuffer();
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
bufferManager.connect(compilationUnit.getPath(), LocationKind.IFILE, new NullProgressMonitor());
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(compilationUnit.getPath(), LocationKind.IFILE);
IDocument document = textFileBuffer.getDocument();
TextViewer viewer = new TextViewer(document, new Point(offset, 0));
AssistContext context = new AssistContext(compilationUnit, offset, 0);
ArrayList proposals = new ArrayList<>();
JavaCorrectionProcessor.collectProposals(context, problems, true, true, proposals);
return convertProposals(offset, compilationUnit, viewer, proposals);
}
use of org.eclipse.che.jdt.javaeditor.TextViewer 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