private void addAllTags(String prefix) { String htmlPrefix= "<" + prefix; //$NON-NLS-1$ for (int i= 0; i < fgHTMLProposals.length; i++) { String curr= fgHTMLProposals[i]; if (prefixMatches(htmlPrefix, curr)) { fResult.add(createCompletion(curr, prefix, curr, JavaPluginImages.get(JavaPluginImages.IMG_OBJS_HTMLTAG), 0)); } } }
private JavaCompletionProposal createCompletion(String newText, String oldText, StyledString labelText, Image image, int severity) { int offset= fCurrentPos - oldText.length(); int length= fCurrentLength + oldText.length(); if (fCurrentLength == 0) length= findReplaceEndPos(fDocument, newText, oldText, fCurrentPos) - offset; // bump opening over closing tags if (!newText.startsWith(IHtmlTagConstants.HTML_CLOSE_PREFIX)) severity++; JavaCompletionProposal proposal= new JavaCompletionProposal(newText, offset, length, image, labelText, severity, true); proposal.setTriggerCharacters( new char[] { '>' }); return proposal; }
private static int findCharBeforeWord(IDocument doc, int lineBeginPos, int pos) { int currPos= pos - 1; if (currPos > lineBeginPos) { try { while (currPos > lineBeginPos && isWordPart(doc.getChar(currPos))) { currPos--; } return currPos; } catch (BadLocationException e) { // ignore } } return pos; }
private void evalProposals() { try { IRegion info= fDocument.getLineInformationOfOffset(fCurrentPos); int lineBeginPos= info.getOffset(); int word1Begin= findCharBeforeWord(fDocument, lineBeginPos, fCurrentPos); if (word1Begin == fCurrentPos) return; char firstChar= fDocument.getChar(word1Begin); if (firstChar == '<') { String prefix= fDocument.get(word1Begin, fCurrentPos - word1Begin); addProposals(prefix, fgHTMLProposals, JavaPluginImages.IMG_OBJS_HTMLTAG); return; } else if (!Character.isWhitespace(firstChar)) { return; } // TODO really show all tags when there is no prefix? // TODO find any unclosed open tag and offer the corresponding close tag String prefix= fDocument.get(word1Begin + 1, fCurrentPos - word1Begin - 1); addAllTags(prefix); } catch (BadLocationException e) { // ignore } }
private static int findReplaceEndPos(IDocument doc, String newText, String oldText, int pos) { if (oldText.length() == 0 || oldText.equals(newText)) { return pos; } try { IRegion lineInfo= doc.getLineInformationOfOffset(pos); int end= lineInfo.getOffset() + lineInfo.getLength(); // for html, search the tag end character return findClosingCharacter(doc, pos, end, '>'); } catch (BadLocationException e) { // ignore } return pos; }
@Override public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) { if (!(context instanceof JavadocContentAssistInvocationContext)) return Collections.emptyList(); JavadocContentAssistInvocationContext docContext= (JavadocContentAssistInvocationContext) context; int flags= docContext.getFlags(); fCurrentPos= docContext.getInvocationOffset(); fCurrentLength= docContext.getSelectionLength(); fRestrictToMatchingCase= (flags & IJavadocCompletionProcessor.RESTRICT_TO_MATCHING_CASE) != 0; ICompilationUnit cu= docContext.getCompilationUnit(); if (cu == null) return Collections.emptyList(); fDocument= docContext.getDocument(); if (fDocument == null) { return Collections.emptyList(); } try { fResult= new ArrayList<>(100); evalProposals(); return fResult; } finally { fResult= null; } }
private void evalProposals() throws JavaModelException { try { IRegion info= fDocument.getLineInformationOfOffset(fCurrentPos); int lineBeginPos= info.getOffset(); int word1Begin= findCharBeforeWord(fDocument, lineBeginPos, fCurrentPos); if (word1Begin == fCurrentPos) return; char firstChar= fDocument.getChar(word1Begin); if (firstChar == '<') { String prefix= fDocument.get(word1Begin, fCurrentPos - word1Begin); addProposals(prefix, fgHTMLProposals, JavaPluginImages.IMG_OBJS_HTMLTAG); return; } else if (!Character.isWhitespace(firstChar)) { return; } // TODO really show all tags when there is no prefix? // TODO find any unclosed open tag and offer the corresponding close tag String prefix= fDocument.get(word1Begin + 1, fCurrentPos - word1Begin - 1); addAllTags(prefix); } catch (BadLocationException e) { // ignore } }
private static int findReplaceEndPos(IDocument doc, String newText, String oldText, int pos) { if (oldText.length() == 0 || oldText.equals(newText)) { return pos; } try { IRegion lineInfo= doc.getLineInformationOfOffset(pos); int end= lineInfo.getOffset() + lineInfo.getLength(); // for html, search the tag end character return findClosingCharacter(doc, pos, end, '>'); } catch (BadLocationException e) { // ignore } return pos; }
@Override public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) { if (!(context instanceof JavadocContentAssistInvocationContext)) return Collections.emptyList(); JavadocContentAssistInvocationContext docContext= (JavadocContentAssistInvocationContext) context; int flags= docContext.getFlags(); fCurrentPos= docContext.getInvocationOffset(); fCurrentLength= docContext.getSelectionLength(); fRestrictToMatchingCase= (flags & IJavadocCompletionProcessor.RESTRICT_TO_MATCHING_CASE) != 0; ICompilationUnit cu= docContext.getCompilationUnit(); if (cu == null) return Collections.emptyList(); fDocument= docContext.getDocument(); if (fDocument == null) { return Collections.emptyList(); } try { fResult= new ArrayList<>(100); evalProposals(); return fResult; } finally { fResult= null; } }
private void evalProposals() { try { IRegion info= fDocument.getLineInformationOfOffset(fCurrentPos); int lineBeginPos= info.getOffset(); int word1Begin= findCharBeforeWord(fDocument, lineBeginPos, fCurrentPos); if (word1Begin == fCurrentPos) return; char firstChar= fDocument.getChar(word1Begin); if (firstChar == '<') { String prefix= fDocument.get(word1Begin, fCurrentPos - word1Begin); addProposals(prefix, fgHTMLProposals, JavaPluginImages.IMG_OBJS_HTMLTAG); return; } else if (!Character.isWhitespace(firstChar)) { return; } // TODO really show all tags when there is no prefix? // TODO find any unclosed open tag and offer the corresponding close tag String prefix= fDocument.get(word1Begin + 1, fCurrentPos - word1Begin - 1); addAllTags(prefix); } catch (BadLocationException e) { // ignore } }
private void addProposals(String prefix, String[] choices, String imageName) { for (int i= 0; i < choices.length; i++) { String curr= choices[i]; if (prefixMatches(prefix, curr)) { fResult.add(createCompletion(curr, prefix, curr, JavaPluginImages.get(imageName), 0)); } } }
private JavaCompletionProposal createCompletion(String newText, String oldText, StyledString labelText, Image image, int severity) { int offset= fCurrentPos - oldText.length(); int length= fCurrentLength + oldText.length(); if (fCurrentLength == 0) length= findReplaceEndPos(fDocument, newText, oldText, fCurrentPos) - offset; // bump opening over closing tags if (!newText.startsWith(IHtmlTagConstants.HTML_CLOSE_PREFIX)) severity++; JavaCompletionProposal proposal= new JavaCompletionProposal(newText, offset, length, image, labelText, severity, true); proposal.setTriggerCharacters( new char[] { '>' }); return proposal; }
private static int findCharBeforeWord(IDocument doc, int lineBeginPos, int pos) { int currPos= pos - 1; if (currPos > lineBeginPos) { try { while (currPos > lineBeginPos && isWordPart(doc.getChar(currPos))) { currPos--; } return currPos; } catch (BadLocationException e) { // ignore } } return pos; }
private static int findReplaceEndPos(IDocument doc, String newText, String oldText, int pos) { if (oldText.length() == 0 || oldText.equals(newText)) { return pos; } try { IRegion lineInfo= doc.getLineInformationOfOffset(pos); int end= lineInfo.getOffset() + lineInfo.getLength(); // for html, search the tag end character return findClosingCharacter(doc, pos, end, '>'); } catch (BadLocationException e) { // ignore } return pos; }
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) { if (!(context instanceof JavadocContentAssistInvocationContext)) return Collections.EMPTY_LIST; JavadocContentAssistInvocationContext docContext= (JavadocContentAssistInvocationContext) context; int flags= docContext.getFlags(); fCurrentPos= docContext.getInvocationOffset(); fCurrentLength= docContext.getSelectionLength(); fRestrictToMatchingCase= (flags & IJavadocCompletionProcessor.RESTRICT_TO_MATCHING_CASE) != 0; ICompilationUnit cu= docContext.getCompilationUnit(); if (cu == null) return Collections.EMPTY_LIST; IEditorInput editorInput= new FileEditorInput((IFile) cu.getResource()); fDocument= JavaUI.getDocumentProvider().getDocument(editorInput); if (fDocument == null) { return null; } try { fResult= new ArrayList(100); evalProposals(); return fResult; } catch (JavaModelException e) { fErrorMessage= e.getLocalizedMessage(); } finally { fResult= null; } return null; }
private void addAllTags(String prefix) { String htmlPrefix= "<" + prefix; //$NON-NLS-1$ for (int i= 0; i < fgHTMLProposals.length; i++) { String curr= fgHTMLProposals[i]; if (prefixMatches(htmlPrefix, curr)) { fResult.add(createCompletion(curr, prefix, new StyledString(curr), JavaPluginImages.get(JavaPluginImages.IMG_OBJS_HTMLTAG), 0)); } } }
private JavaCompletionProposal createCompletion(String newText, String oldText, String labelText, Image image, int severity) { int offset= fCurrentPos - oldText.length(); int length= fCurrentLength + oldText.length(); if (fCurrentLength == 0) length= findReplaceEndPos(fDocument, newText, oldText, fCurrentPos) - offset; // bump opening over closing tags if (!newText.startsWith(IHtmlTagConstants.HTML_CLOSE_PREFIX)) severity++; JavaCompletionProposal proposal= new JavaCompletionProposal(newText, offset, length, image, labelText, severity, true); proposal.setTriggerCharacters( new char[] { '>' }); return proposal; }
private static int findCharBeforeWord(IDocument doc, int lineBeginPos, int pos) { int currPos= pos - 1; if (currPos > lineBeginPos) { try { while (currPos > lineBeginPos && isWordPart(doc.getChar(currPos))) { currPos--; } return currPos; } catch (BadLocationException e) { // ignore } } return pos; }
private void addProposals(String prefix, String[] choices, String imageName) { for (int i= 0; i < choices.length; i++) { String curr= choices[i]; if (prefixMatches(prefix, curr)) { fResult.add(createCompletion(curr, prefix, new StyledString(curr), JavaPluginImages.get(imageName), 0)); } } }
private void addAllTags(String prefix) { String htmlPrefix= "<" + prefix; //$NON-NLS-1$ for (int i= 0; i < fgHTMLProposals.length; i++) { String curr= fgHTMLProposals[i]; if (prefixMatches(htmlPrefix, curr)) { fResult.add(createCompletion(curr, prefix, new StyledString(curr), JavaPluginImages.get(JavaPluginImages.IMG_OBJS_HTMLTAG), 0)); } } }