1
/*******************************************************************************
2
* Copyright (c) 2008, 2009 Symbian Software Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Andrew Ferguson (Symbian) - Initial implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.ui.text.doctools.generic;
13
import java.util.ArrayList;
14
import java.util.Collections;
15
import java.util.List;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.jface.text.BadLocationException;
19
import org.eclipse.jface.text.IDocument;
20
import org.eclipse.jface.text.ITypedRegion;
21
import org.eclipse.jface.text.TextUtilities;
22
import org.eclipse.jface.text.contentassist.ICompletionProposal;
23
import org.eclipse.jface.text.contentassist.IContextInformation;
25
import org.eclipse.cdt.ui.text.ICPartitions;
26
import org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext;
27
import org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer;
29
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProposal;
32
* CompletionProposalComputer based on a specified set of GenericTag objects.
34
* @noextend This class is not intended to be subclassed by clients.
36
public class GenericTagCompletionProposalComputer implements ICompletionProposalComputer {
37
protected GenericDocTag[] tags;
38
protected char[] tagMarkers;
41
* Constructs a proposal computer for the specified tags
44
public GenericTagCompletionProposalComputer(GenericDocTag[] tags, char[] tagMarkers) {
46
this.tagMarkers= tagMarkers;
50
* @param c the character to test
51
* @return whether the specified character is a tag prefix marker
53
protected boolean isTagMarker(char c) {
54
for(char candidate : tagMarkers)
61
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
63
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
64
IDocument doc= context.getDocument();
65
int ivcOffset= context.getInvocationOffset();
67
ITypedRegion tr= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING, ivcOffset, false);
68
int firstNonWS= ivcOffset;
69
while(firstNonWS-1> tr.getOffset() && !Character.isWhitespace(doc.get(firstNonWS-1, 1).charAt(0)))
71
String prefix= doc.get(firstNonWS, ivcOffset-firstNonWS);
72
if(prefix.length()>0 && isTagMarker(prefix.charAt(0))) {
73
List<ICompletionProposal> proposals= new ArrayList<ICompletionProposal>();
74
char tagMarker= prefix.charAt(0);
75
for (GenericDocTag tag2 : tags) {
76
String tag= tag2.getTagName();
77
if(tag.toLowerCase().startsWith(prefix.substring(1).toLowerCase())) {
78
CCompletionProposal proposal= new CCompletionProposal(tagMarker+tag, ivcOffset-prefix.length(), prefix.length(), null, tagMarker+tag, 1, context.getViewer());
79
String description= tag2.getTagDescription();
80
if(description!=null && description.length()>0) {
81
proposal.setAdditionalProposalInfo(description);
83
proposals.add(proposal);
88
} catch(BadLocationException ble) {
89
// offset is zero, ignore
91
return Collections.emptyList();
95
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
97
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
98
return Collections.emptyList();
102
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#getErrorMessage()
104
public String getErrorMessage() {
109
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#sessionEnded()
111
public void sessionEnded() {}
114
* @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#sessionStarted()
116
public void sessionStarted() {}