@Override public int getInvocationOffset() { return javaContext.getInvocationOffset(); }
@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(); }
@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(); }
public List computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) { if (context instanceof JavaContentAssistInvocationContext) { JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context; ICompilationUnit cu= javaContext.getCompilationUnit(); int offset= javaContext.getInvocationOffset(); ArrayList 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.EMPTY_LIST; }
@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; } }
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(); }
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); }
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); }
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); }
@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; } }
fEngine.complete(javaContext.getViewer(), javaContext.getInvocationOffset(), unit);
fEngine.complete(javaContext.getViewer(), javaContext.getInvocationOffset(), unit);
private ImportRewrite createImportRewrite() { if (fCompilationUnit != null && allowAddingImports()) { try { CompilationUnit cu= getASTRoot(fCompilationUnit); if (cu == null) { ImportRewrite rewrite= StubUtility.createImportRewrite(fCompilationUnit, true); fImportContext= null; return rewrite; } else { ImportRewrite rewrite= StubUtility.createImportRewrite(cu, true); fImportContext= new ContextSensitiveImportRewriteContext(cu, fInvocationContext.getInvocationOffset(), rewrite); return rewrite; } } catch (CoreException x) { JavaPlugin.log(x); } } return null; }
/** * Creates and returns the import rewrite * if imports should be added at all. * * @return the import rewrite or <code>null</code> if no imports can or should be added */ private ImportRewrite createImportRewrite() { if (fCompilationUnit != null && shouldAddImports()) { try { CompilationUnit cu= getASTRoot(fCompilationUnit); if (cu == null) { ImportRewrite rewrite= StubUtility.createImportRewrite(fCompilationUnit, true); fImportContext= null; return rewrite; } else { ImportRewrite rewrite= StubUtility.createImportRewrite(cu, true); fImportContext= new ContextSensitiveImportRewriteContext(cu, fInvocationContext.getInvocationOffset(), rewrite); return rewrite; } } catch (CoreException x) { JavaPlugin.log(x); } } return null; }
/** * Creates and returns the import rewrite * if imports should be added at all. * * @return the import rewrite or <code>null</code> if no imports can or should be added */ private ImportRewrite createImportRewrite() { if (fCompilationUnit != null && shouldAddImports()) { try { CompilationUnit cu= getASTRoot(fCompilationUnit); if (cu == null) { ImportRewrite rewrite= StubUtility.createImportRewrite(fCompilationUnit, true); fImportContext= null; return rewrite; } else { ImportRewrite rewrite= StubUtility.createImportRewrite(cu, true); fImportContext= new ContextSensitiveImportRewriteContext(cu, fInvocationContext.getInvocationOffset(), rewrite); return rewrite; } } catch (CoreException x) { JavaPlugin.log(x); } } return null; }
/** * Creates and returns the import rewrite * if imports should be added at all. * * @return the import rewrite or <code>null</code> if no imports can or should be added */ private ImportRewrite createImportRewrite() { if (fCompilationUnit != null && shouldAddImports()) { try { CompilationUnit cu= getASTRoot(fCompilationUnit); if (cu == null) { ImportRewrite rewrite= StubUtility.createImportRewrite(fCompilationUnit, true); fImportContext= null; return rewrite; } else { ImportRewrite rewrite= StubUtility.createImportRewrite(cu, true); fImportContext= new ContextSensitiveImportRewriteContext(cu, fInvocationContext.getInvocationOffset(), rewrite); return rewrite; } } catch (CoreException x) { JavaPlugin.log(x); } } return null; }
private ImportRewrite createImportRewrite() { if (fCompilationUnit != null && allowAddingImports() && !JavaModelUtil.isPackageInfo(fCompilationUnit)) { try { CompilationUnit cu= getASTRoot(fCompilationUnit); if (cu == null) { ImportRewrite rewrite= StubUtility.createImportRewrite(fCompilationUnit, true); fImportContext= null; return rewrite; } else { ImportRewrite rewrite= StubUtility.createImportRewrite(cu, true); fImportContext= new ContextSensitiveImportRewriteContext(cu, fInvocationContext.getInvocationOffset(), rewrite); return rewrite; } } catch (CoreException x) { JavaPlugin.log(x); } } return null; }
private ImportRewrite createImportRewrite() { if (fCompilationUnit != null && allowAddingImports() && !JavaModelUtil.isPackageInfo(fCompilationUnit)) { try { CompilationUnit cu= getASTRoot(fCompilationUnit); if (cu == null) { ImportRewrite rewrite= StubUtility.createImportRewrite(fCompilationUnit, true); fImportContext= null; return rewrite; } else { ImportRewrite rewrite= StubUtility.createImportRewrite(cu, true); fImportContext= new ContextSensitiveImportRewriteContext(cu, fInvocationContext.getInvocationOffset(), rewrite); return rewrite; } } catch (CoreException x) { JavaPlugin.log(x); } } return null; }
cu.codeComplete(getInvocationOffset(), collector); if (fCoreContext == null) fCoreContext= collector.getContext();
cu.codeComplete(getInvocationOffset(), collector); if (fCoreContext == null) fCoreContext= collector.getContext();