/** * Get the active contexts for the given position in the document. * <p> * FIXME: should trigger code assist to get the context. * </p> * * @param document the document * @param offset the offset * @return an array of valid context id */ @Override protected String[] getContextTypeIds(IDocument document, int offset) { try { String partition= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, true); String[] ids= new String[] { JavaContextType.ID_ALL, JavaContextType.ID_MEMBERS, JavaContextType.ID_STATEMENTS, SWTContextType.ID_ALL, SWTContextType.ID_STATEMENTS, SWTContextType.ID_MEMBERS}; if (partition.equals(IJavaPartitions.JAVA_DOC)) ids= new String[] { JavaDocContextType.ID }; return ids; } catch (BadLocationException e) { return new String[0]; } }
private String getTokenContentType(int invocationOffset) throws BadLocationException { if (fContentAssistSubjectControl != null) { IDocument document= fContentAssistSubjectControl.getDocument(); if (document != null) { return TextUtilities.getContentType(document, fContentAssistant.getDocumentPartitioning(), invocationOffset, true); } } else { return TextUtilities.getContentType(fViewer.getDocument(), fContentAssistant.getDocumentPartitioning(), invocationOffset, true); } return IDocument.DEFAULT_CONTENT_TYPE; }
/** * Returns <code>true</code> if the character at the specified offset is a less-than sign, rather than * the opening angle bracket of a type parameter list. * * @param document a document * @param offset an offset within the document * @return <code>true</code> if the character at the specified offset is a less-than sign * @throws BadLocationException if offset is invalid in the document */ private boolean isLessThanOperator(IDocument document, int offset) throws BadLocationException { if (offset < 0) return false; String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, false); if (!IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { return false; } JavaHeuristicScanner scanner= new JavaHeuristicScanner(document, IJavaPartitions.JAVA_PARTITIONING, contentType); return !isTypeParameterOpeningBracket(offset, document, scanner); }
/** * Returns true if the character at the specified offset is a greater-than sign, rather than an * type parameter list close angle bracket. * * @param document a document * @param offset an offset within the document * @return true if the character at the specified offset is a greater-than sign * @throws BadLocationException if offset is invalid in the document */ private boolean isGreaterThanOperator(IDocument document, int offset) throws BadLocationException { if (offset < 0) return false; String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, false); if (!IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { return false; } JavaHeuristicScanner scanner= new JavaHeuristicScanner(document, IJavaPartitions.JAVA_PARTITIONING, contentType); return !isTypeParameterClosingBracket(offset, document, scanner); }
/** * Returns true if the character at the specified offset is a greater-than sign, rather than an * type parameter list close angle bracket. * * @param document a document * @param offset an offset within the document * @return true if the character at the specified offset is a greater-than sign * @throws BadLocationException if offset is invalid in the document */ private boolean isGreaterThanOperator(IDocument document, int offset) throws BadLocationException { if (offset < 0) return false; String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, false); if (!IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { return false; } JavaHeuristicScanner scanner= new JavaHeuristicScanner(document, IJavaPartitions.JAVA_PARTITIONING, contentType); return !isTypeParameterClosingBracket(offset, document, scanner); }
/** * Returns <code>true</code> if the character at the specified offset is a less-than sign, rather than * the opening angle bracket of a type parameter list. * * @param document a document * @param offset an offset within the document * @return <code>true</code> if the character at the specified offset is a less-than sign * @throws BadLocationException if offset is invalid in the document */ private boolean isLessThanOperator(IDocument document, int offset) throws BadLocationException { if (offset < 0) return false; String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, false); if (!IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) { return false; } JavaHeuristicScanner scanner= new JavaHeuristicScanner(document, IJavaPartitions.JAVA_PARTITIONING, contentType); return !isTypeParameterOpeningBracket(offset, document, scanner); }
/** * Returns true if the character at the specified offset is a * less-than sign, rather than an type parameter list open * angle bracket. * * @param document a document * @param offset an offset within the document * @return true if the character at the specified offset is not * a type parameter start bracket * @throws BadLocationException */ private boolean isLessThanOperator(IDocument document, int offset) throws BadLocationException { if (offset < 0) return false; JavaHeuristicScanner scanner= new JavaHeuristicScanner(document, IJavaPartitions.JAVA_PARTITIONING, TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, false)); return !isTypeParameterBracket(offset, document, scanner); }
public ITextHover getTextHover(int offset, int stateMask) { if (fTextHovers == null) return null; IDocument document= getDocument(); if (document == null) return null; try { String contentType = TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); TextHoverKey key= new TextHoverKey(contentType, stateMask); Object textHover= fTextHovers.get(key); if (textHover == null) { // Use default text hover key.setStateMask(ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK); textHover= fTextHovers.get(key); } return (ITextHover) textHover; } catch (BadLocationException x) { // if (TRACE_ERRORS) // System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$ } return null; }
/** * Returns the content assist processor for the content * type of the specified document position. * * @param viewer the text viewer * @param offset a offset within the document * @return a content-assist processor or <code>null</code> if none exists */ private IContentAssistProcessor getProcessor(ITextViewer viewer, int offset) { try { String type= TextUtilities.getContentType(viewer.getDocument(), getDocumentPartitioning(), offset, true); return getContentAssistProcessor(type); } catch (BadLocationException x) { } return null; }
/** * Returns the content assist processor for the content type of the specified document position. * * @param viewer the text viewer * @param offset a offset within the document * @return a content-assist processor or <code>null</code> if none exists * @since 3.0 */ private IContentAssistProcessor getProcessor(ITextViewer viewer, int offset) { try { IDocument document= viewer.getDocument(); String type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); return getContentAssistProcessor(type); } catch (BadLocationException x) { } return null; }
/** * Returns the content assist processor for the content * type of the specified document position. * * @param viewer the text viewer * @param offset a offset within the document * @return a content-assist processor or <code>null</code> if none exists */ private IContentAssistProcessor getProcessor(ITextViewer viewer, int offset) { try { String type= TextUtilities.getContentType(viewer.getDocument(), getDocumentPartitioning(), offset, true); return getContentAssistProcessor(type); } catch (BadLocationException x) { } return null; }
private static boolean isInJavadoc(JavaEditor editor) { ITextSelection selection= getTextSelection(editor); if (selection == null) return false; IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput()); try { String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, selection.getOffset(), true); return contentType.equals(IJavaPartitions.JAVA_DOC); } catch (BadLocationException e) { return false; } }
/** * Returns the content assist processor for the content type of the specified document position. * * @param viewer the text viewer * @param offset a offset within the document * @return the content-assist processors or <code>null</code> if none exists * @since 3.13 */ private Set<IContentAssistProcessor> getProcessors(ITextViewer viewer, int offset) { try { IDocument document= viewer.getDocument(); String type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); return getContentAssistProcessors(type); } catch (BadLocationException x) { } return null; }
private static boolean isInJavadoc(JavaEditor editor) { ITextSelection selection= getTextSelection(editor); if (selection == null) return false; IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput()); try { String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, selection.getOffset(), true); return contentType.equals(IJavaPartitions.JAVA_DOC); } catch (BadLocationException e) { return false; } }
/** * Selects from the given map the one which is registered under the content type of the * partition in which the given offset is located. * * @param offset the offset for which to find the plug-in * @param plugins the map from which to choose * @return the plug-in registered under the offset's content type or <code>null</code> if none */ protected Object selectContentTypePlugin(int offset, Map<String, ?> plugins) { final IDocument document= getDocument(); if (document == null) return null; try { return selectContentTypePlugin(TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true), plugins); } catch (BadLocationException x) { if (TRACE_ERRORS) System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$ } return null; }
/** * Computes the partition type at the selection start and checks whether the proposal category * has any computers for this partition. * * @param selection the selection * @return <code>true</code> if there are any computers for the selection */ private boolean isValidSelection(ISelection selection) { if (!(selection instanceof ITextSelection)) return false; int offset= ((ITextSelection) selection).getOffset(); IDocument document= getDocument(); if (document == null) return false; String contentType; try { contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, true); } catch (BadLocationException x) { return false; } return fCategory.hasComputers(contentType); }
/** * Selects from the given map the one which is registered under the content type of the * partition in which the given offset is located. * * @param offset the offset for which to find the plug-in * @param plugins the map from which to choose * @return the plug-in registered under the offset's content type or <code>null</code> if none */ protected Object selectContentTypePlugin(int offset, Map<String, ?> plugins) { final IDocument document= getDocument(); if (document == null) return null; try { return selectContentTypePlugin(TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true), plugins); } catch (BadLocationException x) { if (TRACE_ERRORS) System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$ } return null; }
@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; } }
/** * Returns the content assist processors for the content type of the specified document position. * * @param contentAssistSubjectControl the content assist subject control * @param offset a offset within the document * @return the content-assist processors or <code>null</code> if none exists * @since 3.13 */ private Set<IContentAssistProcessor> getProcessors(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { try { IDocument document= contentAssistSubjectControl.getDocument(); String type; if (document != null) type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); else type= IDocument.DEFAULT_CONTENT_TYPE; return getContentAssistProcessors(type); } catch (BadLocationException x) { } return null; }
/** * Returns the content assist processor for the content type of the specified document position. * * @param contentAssistSubjectControl the content assist subject control * @param offset a offset within the document * @return a content-assist processor or <code>null</code> if none exists * @since 3.0 */ private IContentAssistProcessor getProcessor(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { try { IDocument document= contentAssistSubjectControl.getDocument(); String type; if (document != null) type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); else type= IDocument.DEFAULT_CONTENT_TYPE; return getContentAssistProcessor(type); } catch (BadLocationException x) { } return null; }