@Override public Object getAdditionalProposalInfo(IProgressMonitor monitor) { if (fAdditionalInfo != null) return fAdditionalInfo; return super.getAdditionalProposalInfo(monitor); }
/** * Sets the proposal's relevance. * @param relevance The relevance to set */ @Override public final void setRelevance(int relevance) { fRelevanceComputed= true; super.setRelevance(relevance); }
if (!isInJavadoc() && !validate(document, offset, null)) { setCursorPosition(offset); if (trigger != '\0') { try { document.replace(offset, 0, String.valueOf(trigger)); setCursorPosition(getCursorPosition() + 1); if (trigger == '(' && autocloseBrackets()) { document.replace(getReplacementOffset() + getCursorPosition(), 0, ")"); //$NON-NLS-1$ setUpLinkedMode(document, ')'); int newLength= selection.x + selection.y - getReplacementOffset(); if ((insertCompletion() ^ fToggleEating) && newLength >= 0) setReplacementLength(newLength); apply(document, trigger, offset); fToggleEating= false;
@Override public int getContextInformationPosition() { if (getContextInformation() == null) return getReplacementOffset() - 1; return getReplacementOffset() + getCursorPosition(); }
@Override public final void apply(IDocument document) { // not used any longer apply(document, (char) 0, getReplacementOffset() + getReplacementLength()); }
@Override public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) { if (!isCamelCaseMatching()) return getReplacementString(); String prefix= getPrefix(document, completionOffset); return getCamelCaseCompound(prefix, getReplacementString()); }
if (isSupportingRequiredProposals()) { CompletionProposal coreProposal= ((MemberProposalInfo)getProposalInfo()).fProposal; CompletionProposal[] requiredProposals= coreProposal.getRequiredProposals(); for (int i= 0; requiredProposals != null && i < requiredProposals.length; i++) { LazyJavaCompletionProposal proposal= new LazyJavaTypeCompletionProposal(requiredProposals[i], fInvocationContext); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.TYPE_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.METHOD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.FIELD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else { int delta= offset - (getReplacementOffset() + getReplacementLength()); if (delta > 0) setReplacementLength(getReplacementLength() + delta);
/** * Creates a style range for the text viewer. * * @param viewer the text viewer * @return the new style range for the text viewer or <code>null</code> * @since 3.6 */ private StyleRange createStyleRange(ITextViewer viewer) { StyledText text= viewer.getTextWidget(); if (text == null || text.isDisposed()) return null; int widgetCaret= text.getCaretOffset(); int modelCaret= 0; if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; modelCaret= extension.widgetOffset2ModelOffset(widgetCaret); } else { IRegion visibleRegion= viewer.getVisibleRegion(); modelCaret= widgetCaret + visibleRegion.getOffset(); } if (modelCaret >= getReplacementOffset() + getReplacementLength()) return null; int length= getReplacementOffset() + getReplacementLength() - modelCaret; Color foreground= getForegroundColor(); Color background= getBackgroundColor(); return new StyleRange(modelCaret, length, foreground, background); }
if (getTextViewer() != null && autocloseBrackets()) { int offset= getReplacementOffset() + getCursorPosition(); int exit= getReplacementOffset() + getReplacementString().length(); try { LinkedPositionGroup group= new LinkedPositionGroup(); model.forceInstall(); LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer()); ui.setSimpleMode(true); ui.setExitPolicy(new ExitPolicy(closingCharacter, document)); ui.setExitPosition(getTextViewer(), exit, 0, Integer.MAX_VALUE); ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER); ui.enter();
private void handleSmartTrigger(IDocument document, char trigger, int referenceOffset) throws BadLocationException { DocumentCommand cmd= new DocumentCommand() { }; cmd.offset= referenceOffset; cmd.length= 0; cmd.text= Character.toString(trigger); cmd.doit= true; cmd.shiftsCaret= true; cmd.caretOffset= getReplacementOffset() + getCursorPosition(); SmartSemicolonAutoEditStrategy strategy= new SmartSemicolonAutoEditStrategy(IJavaPartitions.JAVA_PARTITIONING); strategy.customizeDocumentCommand(document, cmd); replace(document, cmd.offset, cmd.length, cmd.text); setCursorPosition(cmd.caretOffset - getReplacementOffset() + cmd.text.length()); }
/** * Returns the java element proposed by the receiver, possibly <code>null</code>. * * @return the java element proposed by the receiver, possibly <code>null</code> */ public IJavaElement getJavaElement() { if (getProposalInfo() != null) try { return getProposalInfo().getJavaElement(); } catch (JavaModelException x) { JavaPlugin.log(x); } return null; }
public Object getAdditionalProposalInfo(IProgressMonitor monitor) { if (getProposalInfo() != null) { String info= getProposalInfo().getInfo(monitor); if (info != null && info.length() > 0) { StringBuffer buffer= new StringBuffer(); HTMLPrinter.insertPageProlog(buffer, 0, getCSSStyles()); buffer.append(info); HTMLPrinter.addPageEpilog(buffer); info= buffer.toString(); } return info; } return null; }
@Override public Point getSelection(IDocument document) { if (!fIsValidated) return null; return new Point(getReplacementOffset() + getCursorPosition(), 0); }
@Override public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { Point selection= viewer.getSelectedRange(); boolean smartToggle= (stateMask & SWT.CTRL) != 0; if (!(insertCompletion() ^ smartToggle) && selection.y > 0) fReplacementLengthComputed= false; super.apply(viewer, trigger, stateMask, offset); }
@Override protected final int getCursorPosition() { if (!fCursorPositionComputed) setCursorPosition(computeCursorPosition()); return super.getCursorPosition(); }
public final IContextInformation getContextInformation() { if (!fContextInformationComputed) setContextInformation(computeContextInformation()); return super.getContextInformation(); }
if (isSupportingRequiredProposals()) { CompletionProposal coreProposal= ((MemberProposalInfo)getProposalInfo()).fProposal; CompletionProposal[] requiredProposals= coreProposal.getRequiredProposals(); for (int i= 0; requiredProposals != null && i < requiredProposals.length; i++) { int oldLen= document.getLength(); if (requiredProposals[i].getKind() == CompletionProposal.TYPE_REF) { LazyJavaCompletionProposal proposal= createRequiredTypeCompletionProposal(requiredProposals[i], fInvocationContext); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.TYPE_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen - proposal.getLengthOfImportsAddedBehindReplacementOffset()); } else if (requiredProposals[i].getKind() == CompletionProposal.METHOD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen - proposal.getLengthOfImportsAddedBehindReplacementOffset()); } else if (requiredProposals[i].getKind() == CompletionProposal.FIELD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen - proposal.getLengthOfImportsAddedBehindReplacementOffset()); } else { boolean isSmartTrigger= isSmartTrigger(trigger); int referenceOffset= getReplacementOffset() + getReplacementLength();
/** * Creates a style range for the text viewer. * * @param viewer the text viewer * @return the new style range for the text viewer or <code>null</code> * @since 3.6 */ private StyleRange createStyleRange(ITextViewer viewer) { StyledText text= viewer.getTextWidget(); if (text == null || text.isDisposed()) return null; int widgetCaret= text.getCaretOffset(); int modelCaret= 0; if (viewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; modelCaret= extension.widgetOffset2ModelOffset(widgetCaret); } else { IRegion visibleRegion= viewer.getVisibleRegion(); modelCaret= widgetCaret + visibleRegion.getOffset(); } if (modelCaret >= getReplacementOffset() + getReplacementLength()) return null; int length= getReplacementOffset() + getReplacementLength() - modelCaret; Color foreground= getForegroundColor(); Color background= getBackgroundColor(); return new StyleRange(modelCaret, length, foreground, background); }
/** * Sets up a simple linked mode at {@link #getCursorPosition()} and an exit policy that will * exit the mode when <code>closingCharacter</code> is typed and an exit position at * <code>getCursorPosition() + 1</code>. * * @param document the document * @param closingCharacter the exit character */ protected void setUpLinkedMode(IDocument document, char closingCharacter) { if (getTextViewer() != null && autocloseBrackets()) { int offset= getReplacementOffset() + getCursorPosition(); int exit= getReplacementOffset() + getReplacementString().length(); try { LinkedPositionGroup group= new LinkedPositionGroup(); group.addPosition(new LinkedPosition(document, offset, 0, LinkedPositionGroup.NO_STOP)); LinkedModeModel model= new LinkedModeModel(); model.addGroup(group); model.forceInstall(); LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer()); ui.setSimpleMode(true); ui.setExitPolicy(new ExitPolicy(closingCharacter, document)); ui.setExitPosition(getTextViewer(), exit, 0, Integer.MAX_VALUE); ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER); ui.enter(); } catch (BadLocationException x) { JavaPlugin.log(x); } } }
public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) { if (!isCamelCaseMatching()) return getReplacementString(); String prefix= getPrefix(document, completionOffset); return getCamelCaseCompound(prefix, getReplacementString()); }