use of org.eclipse.jdt.core.CompletionContext in project che by eclipse.
the class JavaContentAssistInvocationContext method getRHSHistory.
/**
* Returns the content assist type history for the expected type.
*
* @return the content assist type history for the expected type
*/
private RHSHistory getRHSHistory() {
if (fRHSHistory == null) {
CompletionContext context = getCoreContext();
if (context != null) {
char[][] expectedTypes = context.getExpectedTypesSignatures();
if (expectedTypes != null && expectedTypes.length > 0) {
String expected = SignatureUtil.stripSignatureToFQN(String.valueOf(expectedTypes[0]));
fRHSHistory = JavaPlugin.getDefault().getContentAssistHistory().getHistory(expected);
}
}
if (fRHSHistory == null)
fRHSHistory = JavaPlugin.getDefault().getContentAssistHistory().getHistory(null);
}
return fRHSHistory;
}
use of org.eclipse.jdt.core.CompletionContext in project che by eclipse.
the class JavaTypeCompletionProposalComputer method computeCompletionProposals.
/*
* @see org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposalComputer#computeCompletionProposals(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
List<ICompletionProposal> types = super.computeCompletionProposals(context, monitor);
if (!(context instanceof JavaContentAssistInvocationContext))
return types;
JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context;
CompletionContext coreContext = javaContext.getCoreContext();
if (coreContext != null && coreContext.getTokenLocation() != CompletionContext.TL_CONSTRUCTOR_START)
return types;
try {
if (types.size() > 0 && context.computeIdentifierPrefix().length() == 0) {
IType expectedType = javaContext.getExpectedType();
if (expectedType != null) {
// empty prefix completion - insert LRU types if known, but prune if they already occur in the core list
// compute minmimum relevance and already proposed list
int relevance = Integer.MAX_VALUE;
Set<String> proposed = new HashSet<String>();
for (Iterator<ICompletionProposal> it = types.iterator(); it.hasNext(); ) {
AbstractJavaCompletionProposal p = (AbstractJavaCompletionProposal) it.next();
IJavaElement element = p.getJavaElement();
if (element instanceof IType)
proposed.add(((IType) element).getFullyQualifiedName());
relevance = Math.min(relevance, p.getRelevance());
}
// insert history types
List<String> history = JavaPlugin.getDefault().getContentAssistHistory().getHistory(expectedType.getFullyQualifiedName()).getTypes();
relevance -= history.size() + 1;
for (Iterator<String> it = history.iterator(); it.hasNext(); ) {
String type = it.next();
if (proposed.contains(type))
continue;
IJavaCompletionProposal proposal = createTypeProposal(relevance, type, javaContext);
if (proposal != null)
types.add(proposal);
relevance++;
}
}
}
} catch (BadLocationException x) {
// log & ignore
JavaPlugin.log(x);
} catch (JavaModelException x) {
// log & ignore
JavaPlugin.log(x);
}
return types;
}
use of org.eclipse.jdt.core.CompletionContext in project jbosstools-hibernate by jbosstools.
the class FieldPropertyHandler method attributeCompletionProposals.
public ICompletionProposal[] attributeCompletionProposals(IJavaProject project, Node node, String attributeName, String start, int offset) {
// TODO: should also try to find properties getXXX()
if (project != null) {
Node parentNode = node.getParentNode();
String typename = null;
typename = this.extractor.getNearestType(project, parentNode);
if (typename == null) {
// could not locate type
return new IJavaCompletionProposal[0];
}
HibernateResultCollector rc = null;
try {
IType type = project.findType(typename);
// nothing to look for then
if (type == null)
return new ICompletionProposal[0];
rc = new HibernateResultCollector(project);
rc.acceptContext(new CompletionContext());
// TODO: only handle properties ?
rc.setAccepts(false, false, false, false, true, false);
// rc.reset(offset, javaProject, null);
type.codeComplete(start.toCharArray(), -1, start.length(), new char[0][0], new char[0][0], new int[0], false, rc);
} catch (JavaModelException jme) {
// TODO: report
}
IJavaCompletionProposal[] results = rc.getJavaCompletionProposals();
CompletionHelper.transpose(start, offset, results);
return results;
}
return new ICompletionProposal[0];
}
use of org.eclipse.jdt.core.CompletionContext in project jbosstools-hibernate by jbosstools.
the class CompletionHelper method completeOnJavaTypes.
public static ICompletionProposal[] completeOnJavaTypes(IJavaProject javaProject, Settings settings, String packageName, String start, int offset) {
if (javaProject != null) {
IEvaluationContext context = javaProject.newEvaluationContext();
if (packageName != null) {
context.setPackageName(packageName);
}
HibernateResultCollector rc = new HibernateResultCollector(javaProject);
rc.acceptContext(new CompletionContext());
// rc.reset(offset, javaProject, null);
rc.setAccepts(settings);
try {
// cannot send in my own document as it won't compile as
// java - so we just send in
// the smallest snippet possible
context.codeComplete(start, start.length(), rc);
} catch (JavaModelException jme) {
HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.CompletionHelper_could_not_complete_java_types, jme);
}
IJavaCompletionProposal[] results = rc.getJavaCompletionProposals();
transpose(start, offset, results);
return results;
}
return new ICompletionProposal[0];
}
use of org.eclipse.jdt.core.CompletionContext in project jbosstools-hibernate by jbosstools.
the class JavaCompletionProcessor method computeCompletionProposals.
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int position) {
try {
setErrorMessage(null);
if (editor.getConsoleConfiguration() == null) {
setErrorMessage(HibernateConsoleMessages.JavaCompletionProcessor_no_console_configuration_found);
return new ICompletionProposal[0];
}
// has to do this because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=141518
String prefix = HibernateConsoleMessages.JavaCompletionProcessor_session_session;
IJavaCompletionProposal[] results = new IJavaCompletionProposal[0];
IJavaProject[] projects = null;
// try {
projects = ProjectUtils.findJavaProjects(editor.getConsoleConfiguration());
/*} catch (RuntimeException e){
String mess = NLS.bind(HibernateConsoleMessages.JavaCompletionProcessor_error_find_project,
editor.getConsoleConfiguration().getName());
HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
}*/
for (int i = 0; projects != null && i < projects.length && results.length <= 0; i++) {
IJavaProject javaProject = projects[i];
collector = new CompletionProposalCollector(javaProject);
collector.acceptContext(new CompletionContext());
try {
editor.codeComplete(prefix, collector, position, javaProject);
} catch (JavaModelException x) {
Shell shell = viewer.getTextWidget().getShell();
ErrorDialog.openError(shell, HibernateConsoleMessages.JavaCompletionProcessor_error, HibernateConsoleMessages.JavaCompletionProcessor_error_while_performing_code_completion, x.getStatus());
HibernateConsolePlugin.getDefault().log(x);
}
results = collector.getJavaCompletionProposals();
}
CompletionHelper.transpose(null, -prefix.length(), results);
return results;
} finally {
if (collector != null) {
setErrorMessage(collector.getErrorMessage());
collector = null;
}
}
}
Aggregations