use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project che by eclipse.
the class AbstractTemplateCompletionProposalComputer method computeCompletionProposals.
/*
* @see org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
if (!(context instanceof JavaContentAssistInvocationContext))
return Collections.emptyList();
JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context;
ICompilationUnit unit = javaContext.getCompilationUnit();
if (unit == null)
return Collections.emptyList();
fEngine = computeCompletionEngine(javaContext);
if (fEngine == null)
return Collections.emptyList();
fEngine.reset();
fEngine.complete(javaContext.getViewer(), javaContext.getInvocationOffset(), unit);
TemplateProposal[] templateProposals = fEngine.getResults();
List<ICompletionProposal> result = new ArrayList<ICompletionProposal>(Arrays.asList(templateProposals));
IJavaCompletionProposal[] keyWordResults = javaContext.getKeywordProposals();
if (keyWordResults.length == 0)
return result;
/* Update relevance of template proposals that match with a keyword
* give those templates slightly more relevance than the keyword to
* sort them first.
*/
for (int k = 0; k < templateProposals.length; k++) {
TemplateProposal curr = templateProposals[k];
String name = curr.getTemplate().getPattern();
for (int i = 0; i < keyWordResults.length; i++) {
String keyword = keyWordResults[i].getDisplayString();
if (name.startsWith(keyword)) {
String content = curr.getTemplate().getPattern();
if (content.startsWith(keyword)) {
curr.setRelevance(keyWordResults[i].getRelevance() + 1);
break;
}
}
}
}
return result;
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal 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.ui.text.java.IJavaCompletionProposal in project lombok by rzwitserloot.
the class PatchExtensionMethodCompletionProposal method getJavaCompletionProposals.
public static IJavaCompletionProposal[] getJavaCompletionProposals(IJavaCompletionProposal[] javaCompletionProposals, CompletionProposalCollector completionProposalCollector) {
List<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>(Arrays.asList(javaCompletionProposals));
if (canExtendCodeAssist(proposals)) {
IJavaCompletionProposal firstProposal = proposals.get(0);
int replacementOffset = getReplacementOffset(firstProposal);
for (Extension extension : getExtensionMethods(completionProposalCollector)) {
for (MethodBinding method : extension.extensionMethods) {
ExtensionMethodCompletionProposal newProposal = new ExtensionMethodCompletionProposal(replacementOffset);
copyNameLookupAndCompletionEngine(completionProposalCollector, firstProposal, newProposal);
ASTNode node = getAssistNode(completionProposalCollector);
newProposal.setMethodBinding(method, node);
createAndAddJavaCompletionProposal(completionProposalCollector, newProposal, proposals);
}
}
}
return proposals.toArray(new IJavaCompletionProposal[proposals.size()]);
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project liferay-ide by liferay.
the class LiferayDependencyQuickFix method _processImportNotFoundProposals.
private List<IJavaCompletionProposal> _processImportNotFoundProposals(IInvocationContext context, IProblemLocation problem) {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode == null) {
return null;
}
ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION);
if (importDeclaration == null) {
return null;
}
String importName = importDeclaration.getName().toString();
List<String> serviceWrapperList;
List<String> servicesList;
List<IJavaCompletionProposal> proposals = new ArrayList<>();
try {
serviceWrapperList = TargetPlatformUtil.getServiceWrapperList().getServiceList();
servicesList = TargetPlatformUtil.getServicesList().getServiceList();
if (serviceWrapperList.contains(importName)) {
ServiceContainer bundle = TargetPlatformUtil.getServiceWrapperBundle(importName);
proposals.add(_createDepProposal(context, bundle));
}
if (servicesList.contains(importName)) {
ServiceContainer bundle = TargetPlatformUtil.getServiceBundle(importName);
proposals.add(_createDepProposal(context, bundle));
}
if (TargetPlatformUtil.getThirdPartyBundleList(importName) != null) {
ServiceContainer bundle = TargetPlatformUtil.getThirdPartyBundleList(importName);
proposals.add(_createDepProposal(context, bundle));
}
} catch (Exception e) {
ProjectCore.logError("Error processing import not found proposals", e);
}
return proposals;
}
use of org.eclipse.jdt.ui.text.java.IJavaCompletionProposal in project liferay-ide by liferay.
the class LiferayDependencyQuickFix method _processUndefinedTypeProposals.
private List<IJavaCompletionProposal> _processUndefinedTypeProposals(IInvocationContext context, IProblemLocation problem) {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
String fullyQualifiedName = null;
if (selectedNode instanceof Name) {
Name node = (Name) selectedNode;
fullyQualifiedName = node.getFullyQualifiedName();
}
List<String> serviceWrapperList;
List<String> servicesList;
boolean depWrapperCanFixed = false;
List<IJavaCompletionProposal> proposals = new ArrayList<>();
try {
serviceWrapperList = TargetPlatformUtil.getServiceWrapperList().getServiceList();
servicesList = TargetPlatformUtil.getServicesList().getServiceList();
for (String wrapper : serviceWrapperList) {
if (wrapper.endsWith(fullyQualifiedName)) {
ServiceContainer bundle = TargetPlatformUtil.getServiceWrapperBundle(wrapper);
proposals.add(_createDepProposal(context, bundle));
}
}
if (!depWrapperCanFixed) {
for (String service : servicesList) {
if (service.endsWith(fullyQualifiedName)) {
ServiceContainer bundle = TargetPlatformUtil.getServiceBundle(service);
proposals.add(_createDepProposal(context, bundle));
}
}
}
} catch (Exception e) {
ProjectCore.logError("Error processing undefined type proposals", e);
}
return proposals;
}
Aggregations