protected IContextInformation computeContextInformation() { try { fContextInformationPosition= getReplacementOffset() - 1; CompletionProposal proposal= ((MemberProposalInfo)getProposalInfo()).fProposal; // no context information for METHOD_NAME_REF proposals (e.g. for static imports) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94654 if (hasParameters() && (getReplacementString().endsWith(")") || getReplacementString().length() == 0)) { //$NON-NLS-1$ ProposalContextInformation contextInformation= new ProposalContextInformation(proposal); fContextInformationPosition= getReplacementOffset() + getCursorPosition(); if (fContextInformationPosition != 0 && proposal.getCompletion().length == 0) contextInformation.setContextInformationPosition(fContextInformationPosition); return contextInformation; } return null; } finally { fIsContextInformationComputed= true; } }
public AnonymousTypeCompletionProposal(IJavaProject jproject, ICompilationUnit cu, int start, int length, String constructorCompletion, String displayName, String declarationSignature, int relevance) { super(constructorCompletion, cu, start, length, null, displayName, relevance); Assert.isNotNull(declarationSignature); Assert.isNotNull(jproject); Assert.isNotNull(cu); fDeclarationSignature= declarationSignature; fSuperType= getDeclaringType(jproject, SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature))); setImage(getImageForType(fSuperType)); setCursorPosition(constructorCompletion.indexOf('(') + 1); }
@Override protected boolean isValidPrefix(String prefix) { CompletionProposal coreProposal= ((MemberProposalInfo)getProposalInfo()).fProposal; if (coreProposal.getKind() != CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION) return super.isValidPrefix(prefix); return super.isValidPrefix(prefix) || isPrefix(prefix, String.valueOf(coreProposal.getName())); }
@Override public Image getImage() { Image image= super.getImage(); if (image == null) { image= getImageForType(fSuperType); setImage(image); } return image; }
@Override protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException { fImportRewrite= impRewrite; String newBody= createNewBody(impRewrite); if (newBody == null) return false; CompletionProposal coreProposal= ((MemberProposalInfo)getProposalInfo()).fProposal; boolean isAnonymousConstructorInvoc= coreProposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION; boolean replacementStringEndsWithParentheses= isAnonymousConstructorInvoc || getReplacementString().endsWith(")"); //$NON-NLS-1$ IRegion lineInfo= document.getLineInformationOfOffset(getReplacementOffset()); int indent= Strings.computeIndentUnits(document.get(lineInfo.getOffset(), lineInfo.getLength()), project); if (isAnonymousConstructorInvoc && (insertCompletion() ^ isInsertModeToggled())) { String keepStr= document.get(pos, keepLength); replacementString= replacementString + keepStr; setCursorPosition(replacementString.length() - keepLength); setCursorPosition(replacementString.length()); setReplacementString(replacementString); int currentLength= getReplacementLength(); if (replacementStringEndsWithParentheses) setReplacementLength(currentLength + pos - offset); else setReplacementLength(currentLength + pos - offset + 1);
String dummyClassContent= createDummyType(name); } else { setReplacementString(""); //$NON-NLS-1$ setReplacementLength(0); return null; focusNode= NodeFinder.perform(astRoot, getReplacementOffset()+dummyClassContent.length(), 0); } else { focusNode= null;
protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException { String replacementString= getReplacementString(); if (!createStubs(buf, impRewrite)) { return false; IRegion region= document.getLineInformationOfOffset(getReplacementOffset()); int indent= Strings.computeIndentUnits(document.get(region.getOffset(), region.getLength()), project); setReplacementString(replacement.substring(replacement.indexOf('(') + 1)); setReplacementLength(pos - offset + 1);
/** * Returns <code>true</code> if the method being inserted has at least one parameter. Note * that this does not say anything about whether the argument list should be inserted. * * @return <code>true</code> if the method has any parameters, <code>false</code> if it has no parameters * @since 3.4 */ private boolean hasParameters() { CompletionProposal proposal= ((MemberProposalInfo)getProposalInfo()).fProposal; return Signature.getParameterCount(proposal.getSignature()) > 0; }
final boolean sameUnit= range != null && fCompilationUnit.equals(fSuperType.getCompilationUnit()); final StringBuffer dummy= new StringBuffer(); final int length= createDummy(name, dummy); contents.append(fCompilationUnit.getBuffer().getContents()); if (sameUnit) { setReplacementString(""); //$NON-NLS-1$ setReplacementLength(0); return false;
private IJavaCompletionProposal createAnonymousTypeProposal(CompletionProposal proposal) { if (fCompilationUnit == null || fJavaProject == null) return null; String completion= String.valueOf(proposal.getCompletion()); int start= proposal.getReplaceStart(); int length= getLength(proposal); int relevance= computeRelevance(proposal); String label= fLabelProvider.createAnonymousTypeLabel(proposal); JavaCompletionProposal javaProposal= new AnonymousTypeCompletionProposal(fJavaProject, fCompilationUnit, start, length, completion, label, String.valueOf(proposal.getDeclarationSignature()), relevance); javaProposal.setProposalInfo(new AnonymousTypeProposalInfo(fJavaProject, proposal)); return javaProposal; }
public AnonymousTypeCompletionProposal(IJavaProject jproject, ICompilationUnit cu, JavaContentAssistInvocationContext invocationContext, int start, int length, String constructorCompletion, StyledString displayName, String declarationSignature, IType superType, int relevance) { super(constructorCompletion, cu, start, length, null, displayName, relevance, null, invocationContext); Assert.isNotNull(declarationSignature); Assert.isNotNull(jproject); Assert.isNotNull(cu); Assert.isNotNull(superType); fDeclarationSignature= declarationSignature; fSuperType= superType; setCursorPosition(constructorCompletion.indexOf('(') + 1); }
@Override public boolean isPrefix(final String prefix, final String completion) { lastPrefix = prefix; if (mgr.prefixChanged(prefix)) { return true; } return super.isPrefix(prefix, completion); }
@Override protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException { fImportRewrite= impRewrite; String newBody= createNewBody(impRewrite, offset); if (newBody == null) return false; CompletionProposal coreProposal= ((MemberProposalInfo)getProposalInfo()).fProposal; boolean isAnonymousConstructorInvoc= coreProposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION; boolean replacementStringEndsWithParentheses= isAnonymousConstructorInvoc || getReplacementString().endsWith(")"); //$NON-NLS-1$ IRegion lineInfo= document.getLineInformationOfOffset(getReplacementOffset()); int indent= Strings.computeIndentUnits(document.get(lineInfo.getOffset(), lineInfo.getLength()), project); if (isAnonymousConstructorInvoc && (insertCompletion() ^ isInsertModeToggled())) { String keepStr= document.get(pos, keepLength); replacementString= replacementString + keepStr; setCursorPosition(replacementString.length() - keepLength); setCursorPosition(replacementString.length()); setReplacementString(replacementString); int currentLength= getReplacementLength(); if (replacementStringEndsWithParentheses) setReplacementLength(currentLength + pos - offset); else setReplacementLength(currentLength + pos - offset + 1);
String dummyClassContent= createDummyType(name); } else { setReplacementString(""); //$NON-NLS-1$ setReplacementLength(0); return null; ASTNode focusNode= NodeFinder.perform(astRoot, getReplacementOffset()+dummyClassContent.length(), 0); contextBinding= ASTNodes.getEnclosingDeclaration(focusNode);
/** * Returns <code>true</code> if the method being inserted has at least one parameter. Note * that this does not say anything about whether the argument list should be inserted. * * @return <code>true</code> if the method has any parameters, <code>false</code> if it has no parameters * @since 3.4 */ private boolean hasParameters() { CompletionProposal proposal= ((MemberProposalInfo)getProposalInfo()).fProposal; return Signature.getParameterCount(proposal.getSignature()) > 0; }
@Override public Image getImage() { Image image= super.getImage(); if (image == null) { image= getImageForType(fSuperType); setImage(image); } return image; }
private IJavaCompletionProposal createAnonymousTypeProposal(CompletionProposal proposal, JavaContentAssistInvocationContext invocationContext) { if (fCompilationUnit == null || fJavaProject == null) return null; char[] declarationKey= proposal.getDeclarationKey(); if (declarationKey == null) return null; try { IJavaElement element= fJavaProject.findElement(new String(declarationKey), null); if (!(element instanceof IType)) return null; IType type= (IType) element; String completion= String.valueOf(proposal.getCompletion()); int start= proposal.getReplaceStart(); int length= getLength(proposal); int relevance= computeRelevance(proposal); StyledString label= fLabelProvider.createAnonymousTypeLabel(proposal); JavaCompletionProposal javaProposal= new AnonymousTypeCompletionProposal(fJavaProject, fCompilationUnit, invocationContext, start, length, completion, label, String.valueOf(proposal .getDeclarationSignature()), type, relevance); javaProposal.setProposalInfo(new AnonymousTypeProposalInfo(fJavaProject, proposal)); return javaProposal; } catch (JavaModelException e) { return null; } }
public AnonymousTypeCompletionProposal(IJavaProject jproject, ICompilationUnit cu, JavaContentAssistInvocationContext invocationContext, int start, int length, String constructorCompletion, StyledString displayName, String declarationSignature, IType superType, int relevance) { super(constructorCompletion, cu, start, length, null, displayName, relevance, null, invocationContext); Assert.isNotNull(declarationSignature); Assert.isNotNull(jproject); Assert.isNotNull(cu); Assert.isNotNull(superType); fDeclarationSignature= declarationSignature; fSuperType= superType; setCursorPosition(constructorCompletion.indexOf('(') + 1); }
protected IContextInformation computeContextInformation() { try { fContextInformationPosition= getReplacementOffset() - 1; CompletionProposal proposal= ((MemberProposalInfo)getProposalInfo()).fProposal; // no context information for METHOD_NAME_REF proposals (e.g. for static imports) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94654 if (hasParameters() && (getReplacementString().endsWith(")") || getReplacementString().length() == 0)) { //$NON-NLS-1$ ProposalContextInformation contextInformation= new ProposalContextInformation(proposal); fContextInformationPosition= getReplacementOffset() + getCursorPosition(); if (fContextInformationPosition != 0 && proposal.getCompletion().length == 0) contextInformation.setContextInformationPosition(fContextInformationPosition); return contextInformation; } return null; } finally { fIsContextInformationComputed= true; } }
@Override public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) { CompletionProposal coreProposal= ((MemberProposalInfo)getProposalInfo()).fProposal; if (coreProposal.getKind() != CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION) return super.getPrefixCompletionText(document, completionOffset); return String.valueOf(coreProposal.getName()); }