~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/generic/GenericTagCompletionProposalComputer.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 * Andrew Ferguson (Symbian) - Initial implementation
10
 
 *******************************************************************************/
11
 
package org.eclipse.cdt.ui.text.doctools.generic;
12
 
 
13
 
import java.util.ArrayList;
14
 
import java.util.Collections;
15
 
import java.util.List;
16
 
 
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;
24
 
 
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;
28
 
 
29
 
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProposal;
30
 
 
31
 
/**
32
 
 * CompletionProposalComputer based on a specified set of GenericTag objects.
33
 
 * @since 5.0
34
 
 * @noextend This class is not intended to be subclassed by clients.
35
 
 */
36
 
public class GenericTagCompletionProposalComputer implements ICompletionProposalComputer {
37
 
        protected GenericDocTag[] tags;
38
 
        protected char[] tagMarkers;
39
 
        
40
 
        /**
41
 
         * Constructs a proposal computer for the specified tags
42
 
         * @param tags
43
 
         */
44
 
        public GenericTagCompletionProposalComputer(GenericDocTag[] tags, char[] tagMarkers) {
45
 
                this.tags= tags;
46
 
                this.tagMarkers= tagMarkers;
47
 
        }
48
 
        
49
 
        /**
50
 
         * @param c the character to test
51
 
         * @return whether the specified character is a tag prefix marker 
52
 
         */
53
 
        protected boolean isTagMarker(char c) {
54
 
                for(char candidate : tagMarkers)
55
 
                        if(c == candidate)
56
 
                                return true;
57
 
                return false;
58
 
        }
59
 
        
60
 
        /*
61
 
         * @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
62
 
         */
63
 
        public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
64
 
                IDocument doc= context.getDocument();
65
 
                int ivcOffset= context.getInvocationOffset();
66
 
                try {
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)))
70
 
                                firstNonWS--;
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);
82
 
                                                }
83
 
                                                proposals.add(proposal);
84
 
                                        }
85
 
                                }
86
 
                                return proposals;
87
 
                        }
88
 
                } catch(BadLocationException ble) {
89
 
                        // offset is zero, ignore
90
 
                }
91
 
                return Collections.emptyList();
92
 
        }
93
 
 
94
 
        /*
95
 
         * @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.cdt.ui.text.contentassist.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
96
 
         */
97
 
        public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
98
 
                return Collections.emptyList();
99
 
        }
100
 
 
101
 
        /*
102
 
         * @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#getErrorMessage()
103
 
         */
104
 
        public String getErrorMessage() {
105
 
                return null;
106
 
        }
107
 
 
108
 
        /*
109
 
         * @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#sessionEnded()
110
 
         */
111
 
        public void sessionEnded() {}
112
 
        
113
 
        /*
114
 
         * @see org.eclipse.cdt.ui.text.contentassist.ICompletionProposalComputer#sessionStarted()
115
 
         */
116
 
        public void sessionStarted() {}
117
 
}