@Override protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) { try { String partition= TextUtilities.getContentType(context.getDocument(), IJavaPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true); if (partition.equals(IJavaPartitions.JAVA_DOC)) return fJavadocTemplateEngine; else { CompletionContext coreContext= context.getCoreContext(); if (coreContext != null) { int tokenLocation= coreContext.getTokenLocation(); if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) { return fJavaMembersTemplateEngine; } if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) { return fJavaStatementsTemplateEngine; } } if (JavaModelUtil.MODULE_INFO_JAVA.equals(context.getCompilationUnit().getElementName())) { return fJavaModuleTemplateEngine; } else { return fJavaTemplateEngine; } } } catch (BadLocationException x) { return null; } }
@Override public IJavaProject getProject() { return javaContext.getProject(); };
protected StyledString computeDisplayString() { return fInvocationContext.getLabelProvider().createStyledLabel(fProposal); }
public final ICompilationUnit getCompilationUnit(final ContentAssistInvocationContext context) { ICompilationUnit cunit = null; if (context instanceof JavaContentAssistInvocationContext) { JavaContentAssistInvocationContext jcontext = (JavaContentAssistInvocationContext) context; if (jcontext.getCoreContext() != null) { cunit = jcontext.getCompilationUnit(); } } return cunit; }
@Override protected TemplateEngine computeCompletionEngine(JavaContentAssistInvocationContext context) { try { String partition= TextUtilities.getContentType(context.getDocument(), IJavaPartitions.JAVA_PARTITIONING, context.getInvocationOffset(), true); if (partition.equals(IJavaPartitions.JAVA_DOC)) return fJavadocTemplateEngine; else { CompletionContext coreContext= context.getCoreContext(); if (coreContext != null) { int tokenLocation= coreContext.getTokenLocation(); if ((tokenLocation & CompletionContext.TL_MEMBER_START) != 0) { return fJavaMembersTemplateEngine; } if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) { return fJavaStatementsTemplateEngine; } } return fJavaTemplateEngine; } } catch (BadLocationException x) { return null; } }
return Collections.EMPTY_LIST; IJavaProject project = jcontext.getProject(); if(project == null || !Util.isApiProject(project)) { return Collections.EMPTY_LIST; CompletionContext corecontext = jcontext.getCoreContext(); if(!corecontext.isInJavadoc()) { return Collections.EMPTY_LIST; ICompilationUnit cunit = jcontext.getCompilationUnit(); if(cunit != null) { try { int offset = jcontext.getInvocationOffset(); IJavaElement element = cunit.getElementAt(offset); if (element == null) { return Collections.EMPTY_LIST; ImageDescriptor imagedesc = jcontext.getLabelProvider().createImageDescriptor( org.eclipse.jdt.core.CompletionProposal.create(org.eclipse.jdt.core.CompletionProposal.JAVADOC_BLOCK_TAG, offset)); if(appliesToContext(jcontext.getDocument(), completiontext, tokenstart, (length > 0 ? length : 1))) { if(list == null) { list = new ArrayList(tagcount-i);
ICompilationUnit unit= javaContext.getCompilationUnit(); if (unit == null) return Collections.emptyList(); fEngine.complete(javaContext.getViewer(), javaContext.getInvocationOffset(), unit); IJavaCompletionProposal[] keyWordResults= javaContext.getKeywordProposals(); if (keyWordResults.length == 0) return result;
private IJavaCompletionProposal createTypeProposal(int relevance, String fullyQualifiedType, JavaContentAssistInvocationContext context) throws JavaModelException { IType type= context.getCompilationUnit().getJavaProject().findType(fullyQualifiedType); if (type == null) return null; CompletionProposal proposal= CompletionProposal.create(CompletionProposal.TYPE_REF, context.getInvocationOffset()); proposal.setCompletion(fullyQualifiedType.toCharArray()); proposal.setDeclarationSignature(type.getPackageFragment().getElementName().toCharArray()); proposal.setFlags(type.getFlags()); proposal.setRelevance(relevance); proposal.setReplaceRange(context.getInvocationOffset(), context.getInvocationOffset()); proposal.setSignature(Signature.createTypeSignature(fullyQualifiedType, true).toCharArray()); if (shouldProposeGenerics(context.getProject())) return new LazyGenericTypeProposal(proposal, context); else return new LazyJavaTypeCompletionProposal(proposal, context); }
public LazyJavaTypeCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context) { super(proposal, context); fCompilationUnit= context.getCompilationUnit(); fQualifiedName= null; }
@Override public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) { if (context instanceof JavaContentAssistInvocationContext) { JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context; ICompilationUnit cu= javaContext.getCompilationUnit(); int offset= javaContext.getInvocationOffset(); ArrayList<IContextInformation> result= new ArrayList<>(); IJavadocCompletionProcessor[] processors= getContributedProcessors(); String error= null; for (int i= 0; i < processors.length; i++) { IJavadocCompletionProcessor curr= processors[i]; IContextInformation[] contextInfos= curr.computeContextInformation(cu, offset); if (contextInfos != null) { for (int k= 0; k < contextInfos.length; k++) { result.add(contextInfos[k]); } } else if (error == null) { error= curr.getErrorMessage(); } } fErrorMessage= error; return result; } return Collections.emptyList(); }
protected ProcessableParameterGuessingProposal(final CompletionProposal proposal, final JavaContentAssistInvocationContext context, final boolean fillBestGuess) { super(proposal, context); coreProposal = proposal; fCoreContext = context.getCoreContext(); fFillBestGuess = fillBestGuess; }
ICompilationUnit cunit = jcontext.getCompilationUnit(); if (cunit != null) { try { int offset = jcontext.getInvocationOffset(); IJavaElement element = cunit.getElementAt(offset); if (!isVisible(element)) { return Collections.EMPTY_LIST; ImageDescriptor imagedesc = jcontext.getLabelProvider().createImageDescriptor(org.eclipse.jdt.core.CompletionProposal.create(org.eclipse.jdt.core.CompletionProposal.JAVADOC_BLOCK_TAG, offset)); fImageHandle = (imagedesc == null ? null : imagedesc.createImage()); int type = getType(element); if (appliesToContext(jcontext.getDocument(), completiontext, tokenstart, (length > 0 ? length : 1))) { if (list == null) { list = new ArrayList<>(tagcount - i);
private List<IJavaCompletionProposal> findSubwordMatchingProposals(IProgressMonitor monitor) { final String token = getToken(); final SubwordsCompletionRequestor requestor = new SubwordsCompletionRequestor(token, ctx); final ITextViewer viewer = ctx.getViewer(); final Point selection = viewer.getSelectedRange(); if (selection.y > 0) { requestor.setReplacementLength(selection.y); } final ICompilationUnit cu = ctx.getCompilationUnit(); final int offsetBeforeTokenBegin = ctx.getInvocationOffset() - token.length(); try { // first on the original position cu.codeComplete(ctx.getInvocationOffset(), requestor, monitor); if (token.length() > 0) { // then on the 'virtual' position cu.codeComplete(offsetBeforeTokenBegin, requestor, monitor); } } catch (final Exception e) { RecommendersUtilsPlugin.logWarning(e, "Code completion failed: %s", e.getMessage()); //$NON-NLS-1$ } return requestor.getProposals(); }
protected List<ICompletionProposal> computeProposals(JavaContentAssistInvocationContext context) { List<ICompletionProposal> proposals = new ArrayList<>(); int offset = context.getInvocationOffset(); IDocument doc = context.getDocument(); if (doc == null || offset > doc.getLength()) { return proposals; IType contextType = findContextType(context.getCompilationUnit(), offset); if (S2eUtils.exists(contextType)) { INlsProject nlsProject = NlsCore.getNlsWorkspace().getNlsProject(new Object[]{contextType, contextType});
if (fProposal.getKind() == CompletionProposal.TYPE_REF && fInvocationContext.getCoreContext().isInJavadocText()) return getSimpleTypeName(); IDocument document= fInvocationContext.getDocument(); if (document != null) { String prefix= getPrefix(document, getReplacementOffset() + getReplacementLength());
private List internalComputeCompletionProposals(int offset, JavaContentAssistInvocationContext context, IProgressMonitor monitor) { ICompilationUnit unit= context.getCompilationUnit(); if (unit == null) return Collections.EMPTY_LIST; ITextViewer viewer= context.getViewer();
public ProcessableAnonymousTypeCompletionProposal(CompletionProposal coreProposal, JavaCompletionProposal uiProposal, JavaContentAssistInvocationContext context) throws JavaModelException { super(context.getProject(), context.getCompilationUnit(), context, coreProposal.getReplaceStart(), uiProposal .getReplacementLength(), String.valueOf(coreProposal.getCompletion()), uiProposal .getStyledDisplayString(), String.valueOf(coreProposal.getDeclarationSignature()), (IType) context .getProject().findElement(String.valueOf(coreProposal.getDeclarationKey()), null), uiProposal .getRelevance()); this.coreProposal = coreProposal; }
@Override public int getInvocationOffset() { return javaContext.getInvocationOffset(); }
@Override public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) { JavaContentAssistInvocationContext jcontext = null; if (context instanceof JavaContentAssistInvocationContext) { jcontext = (JavaContentAssistInvocationContext) context; IJavaProject project = jcontext.getProject(); if (Util.isApiProject(project)) { CompletionContext corecontext = jcontext.getCoreContext(); if (corecontext.isInJavadoc()) { return computeJavadocProposals(jcontext, corecontext); } } } return Collections.EMPTY_LIST; }
CompletionContext coreContext= javaContext.getCoreContext(); if (coreContext != null && coreContext.getTokenLocation() != CompletionContext.TL_CONSTRUCTOR_START) return types; IType expectedType= javaContext.getExpectedType(); if (expectedType != null) {