类org.eclipse.jface.text.contentassist.CompletionProposal源码实例Demo

下面列出了怎么用org.eclipse.jface.text.contentassist.CompletionProposal的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public ICompletionProposal[] computeCompletionProposals(
        IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
  List<CompletionProposal> proposals = new ArrayList<>();

  String basedir = "${basedir}"; //$NON-NLS-1$
  String projectLoc = "${project_loc}"; //$NON-NLS-1$
  String workspaceLoc = "${workspace_loc}"; //$NON-NLS-1$
  String configLoc = "${config_loc}"; //$NON-NLS-1$
  String samedir = "${samedir}"; //$NON-NLS-1$

  // TODO translate the descriptions

  proposals.add(new CompletionProposal(basedir, documentOffset, 0, basedir.length(), null,
          basedir, null, Messages.PropertiesContentAssistProcessor_basedir));
  proposals.add(new CompletionProposal(projectLoc, documentOffset, 0, projectLoc.length(), null,
          projectLoc, null, Messages.PropertiesContentAssistProcessor_projectLoc));
  proposals.add(new CompletionProposal(workspaceLoc, documentOffset, 0, workspaceLoc.length(),
          null, workspaceLoc, null, Messages.PropertiesContentAssistProcessor_workspaceLoc));
  proposals.add(new CompletionProposal(configLoc, documentOffset, 0, configLoc.length(), null,
          configLoc, null, Messages.PropertiesContentAssistProcessor_configLoc));
  proposals.add(new CompletionProposal(samedir, documentOffset, 0, samedir.length(), null,
          samedir, null, Messages.PropertiesContentAssistProcessor_samedir));

  return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
 
源代码2 项目: n4js   文件: JSDocCompletionProposalComputer.java
private void createLineTagProposal(String prefix, N4JSDocletParser docletParser,
		ArrayList<ICompletionProposal> proposals) {
	int replacementOffset = offset - prefix.length();
	// create line tag proposals
	for (ITagDefinition td : docletParser.getLineTagDictionary().getTagDefinitions()) {
		String tagString = '@' + td.getTitle() + ' ';
		if (tagString.startsWith(prefix)) {

			int replacementLength = prefix.length();
			int cursorPosition = tagString.length();
			ICompletionProposal proposal = new CompletionProposal(tagString, replacementOffset,
					replacementLength, cursorPosition);
			proposals.add(proposal);
		}
	}
}
 
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<ICompletionProposal> propList = new ArrayList<ICompletionProposal>();
    List<ICompletionProposal> newpropList = new ArrayList<ICompletionProposal>();
    List<IContextInformation> propList2 = new ArrayList<IContextInformation>();

    ICompletionProposal first;
    DataManager datamanger = new DataManager(context,monitor);
    Activator.applyoperationlist.add(new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList));
    List<String> list = new ArrayList();
    CompletionProposal proposal;
    propList = datamanger.JavaDefaultProposal();
    propList2 = datamanger.ContextInformation();
    ApplyOperation ao = new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList);
    System.out.println(ao.toString());
    return newpropList;
}
 
源代码4 项目: texlipse   文件: BibCompletionProcessor.java
/**
 * Computes the abbreviation completions available based on the prefix.
 * 
 * @param offset Cursor offset in the document
 * @param replacementLength Length of the text to be replaced
 * @param prefix The start of the abbreviation or ""
 * @return An array containing all possible completions
 */
private ICompletionProposal[] computeAbbrevCompletions(int offset, int replacementLength, String prefix) {
    ReferenceEntry[] abbrevs = abbrManager.getCompletions(prefix);
    if (abbrevs == null)
        return null;
    
    ICompletionProposal[] result = new ICompletionProposal[abbrevs.length];
    
    for (int i = 0; i < abbrevs.length; i++) {         
        result[i] = new CompletionProposal(abbrevs[i].key,
                offset - replacementLength, replacementLength,
                abbrevs[i].key.length(), null, abbrevs[i].key, null,
                abbrevs[i].info);
    }
    return result;
}
 
源代码5 项目: texlipse   文件: TexSpellingEngine.java
@SuppressWarnings("unchecked")
@Override
public ICompletionProposal[] getProposals(IQuickAssistInvocationContext context) {
    List<Word> sugg = fError.getSuggestions();
    int length = fError.getInvalidWord().length();
    ICompletionProposal[] props = new ICompletionProposal[sugg.size() + 2];
    for (int i=0; i < sugg.size(); i++) {
        String suggestion = sugg.get(i).toString();
        String s = MessageFormat.format(CHANGE_TO,
                new Object[] { suggestion });
        props[i] = new CompletionProposal(suggestion, 
                fOffset, length, suggestion.length(), fCorrectionImage, s, null, null);
    }
    props[props.length - 2] = new IgnoreProposal(ignore, fError.getInvalidWord(), context.getSourceViewer());
    props[props.length - 1] = new AddToDictProposal(fError, fLang, context.getSourceViewer());
    return props;
}
 
源代码6 项目: texlipse   文件: TexCompletionProcessor.java
/**
 * Computes and returns reference-proposals (labels).
 * 
 * @param offset
 *            Current cursor offset
 * @param replacementLength
 *            The length of the string to be replaced
 * @param prefix
 *            The already typed prefix of the entry to assist with
 * @return An array of completion proposals to use directly or null
 */
private ICompletionProposal[] computeRefCompletions(int offset,
		int replacementLength, String prefix) {
	List<ReferenceEntry> refEntries = refManager.getCompletionsRef(prefix);
	if (refEntries == null)
		return null;

	ICompletionProposal[] result = new ICompletionProposal[refEntries
			.size()];

	for (int i = 0; i < refEntries.size(); i++) {

		String infoText = null;
		ReferenceEntry ref = refEntries.get(i);

		if (ref.info != null) {
			infoText = (ref.info.length() > assistLineLength) ? wrapString(
					ref.info, assistLineLength) : ref.info;
		}

		result[i] = new CompletionProposal(ref.key, offset
				- replacementLength, replacementLength, ref.key.length(),
				null, ref.key, null, infoText);
	}
	return result;
}
 
private Collection<? extends ICompletionProposal> addHeaderAttributes(String oldWord, int offset) {
	
	int bracketPos = StringUtils.lastIndexOf(oldWord, "[");
	int wordLength = oldWord.length();
	int replacementPos = wordLength - bracketPos;
	String word = StringUtils.substringAfterLast(oldWord, "[");
	List<String> keywords = Formatter.IMPEX_KEYWORDS_ATTRIBUTES;
	Collection<ICompletionProposal> result = Lists.newArrayList();
	
	for (String keyword : keywords) {
		if (keyword.toUpperCase(Locale.ENGLISH).startsWith(word.toUpperCase(Locale.ENGLISH)) && word.length() < keyword.length()) {
			
			result.add(new CompletionProposal(keyword + "=", (offset - replacementPos) + 1, word.length(), keyword.length() + 1));
		}
	}
	return result;
	
}
 
private ICompletionProposal[] attributeProposals(int cursorPosition, List<String> autoSuggests, String currentPart) {
	
	int counter = 0;
	ICompletionProposal[] proposals = new ICompletionProposal[autoSuggests.size()];
	for (Iterator<String> iter = autoSuggests.iterator(); iter.hasNext();) {
		String autoSuggest = (String)iter.next();
		
		if (currentPart.endsWith(";") || currentPart.endsWith("(")) {
			proposals[counter] = new CompletionProposal(autoSuggest, cursorPosition, 0, autoSuggest.length());
		}
		else {
			int bracketStart = currentPart.indexOf("(");
			if (bracketStart > 0) {
				int a = (cursorPosition + 1) - (currentPart.length() - bracketStart);
				int b = currentPart.length() - (bracketStart + 1);
				int c = autoSuggest.length();
				proposals[counter] = new CompletionProposal(autoSuggest, a, b, c);
			}
			else {
				proposals[counter] = new CompletionProposal(autoSuggest, cursorPosition - currentPart.length(), currentPart.length(), autoSuggest.length());
			}
		}
		counter++;
	}
	return proposals;
}
 
private ICompletionProposal[] attributeProposals(int cursorPosition, List<String> autoSuggests, String thisAttrib, String currentPart, boolean endingSemiColon) {
	
	int counter = 0;
	ICompletionProposal[] suggestions = new ICompletionProposal[autoSuggests.size()];
	for (Iterator<String> iter = autoSuggests.iterator(); iter.hasNext();) {
		String autoSuggest = (String)iter.next();
		
		//Each proposal contains the text to propose, as well as information about where to insert the text into the document.
		if (thisAttrib.endsWith(";") || thisAttrib.endsWith("(") || !endingSemiColon) {
			suggestions[counter] = new CompletionProposal(autoSuggest, cursorPosition, 0, autoSuggest.length());
		}
		else {
			suggestions[counter] = new CompletionProposal(autoSuggest, cursorPosition - currentPart.length(), currentPart.length(), autoSuggest.length());
		}
		counter++;
	}
	return suggestions;
}
 
/**
 * addCompletionProposalsForCategory
 * 
 * @param viewer
 * @param offset
 * @param index
 * @param completionProposals
 * @param category
 */
protected void addCompletionProposalsForCategory(ITextViewer viewer, int offset, Index index,
		List<ICompletionProposal> completionProposals, String category)
{
	List<QueryResult> queryResults = index.query(new String[] { category }, "", SearchPattern.PREFIX_MATCH); //$NON-NLS-1$

	if (queryResults != null)
	{
		for (QueryResult queryResult : queryResults)
		{
			String text = queryResult.getWord();
			int length = text.length();
			String info = category + " : " + text; //$NON-NLS-1$

			completionProposals.add(new CompletionProposal(text, offset, 0, length, null, text, null, info));
		}
	}
}
 
源代码11 项目: birt   文件: JdbcSQLContentAssistProcessor.java
/**
 * @param columns
 * @return
 */
private ICompletionProposal[] convertColumnsToCompletionProposals(
		ArrayList columns, int offset )
{
	if ( columns.size( ) > 0 )
	{
		ICompletionProposal[] proposals = new ICompletionProposal[columns.size( )];
		Iterator iter = columns.iterator( );
		int n = 0;
		while ( iter.hasNext( ) )
		{
			Column column = (Column) iter.next( );
			proposals[n++] = new CompletionProposal( addQuotes( column.getName( ) ),
					offset,
					0,
					column.getName( ).length( ) );
		}
		return proposals;
	}
	return null;
}
 
源代码12 项目: birt   文件: JdbcSQLContentAssistProcessor.java
/**
 * @param tables
 * @return
 */
private ICompletionProposal[] convertTablesToCompletionProposals(
		ArrayList tables, int offset )
{
	if ( tables.size( ) > 0 )
	{
		ICompletionProposal[] proposals = new ICompletionProposal[tables.size( )];
		Iterator iter = tables.iterator( );
		int n = 0;
		while ( iter.hasNext( ) )
		{
			Table table = (Table) iter.next( );
			proposals[n++] = new CompletionProposal( addQuotes( table.getName( ) ),
					offset,
					0,
					table.getName( ).length( ) );
		}
		return proposals;
	}
	return null;
}
 
源代码13 项目: birt   文件: JSCompletionProcessor.java
protected CompletionProposal[] getCompletionProposals(
		JSObjectMetaData[] metas, int offset )
{
	List<CompletionProposal> proposals = new ArrayList<CompletionProposal>( );
	int wordLength = currentWord == null ? 0 : currentWord.length( );
	for ( int i = 0; i < metas.length; i++ )
	{
		if ( currentWord == null || currentWord.equals( "" ) //$NON-NLS-1$
				|| metas[i].getName( )
						.toLowerCase( )
						.startsWith( currentWord.toLowerCase( ) ) )
		{
			proposals.add( new CompletionProposal( metas[i].getName( ),
					offset - wordLength,
					wordLength,
					metas[i].getName( ).length( ),
					null,
					metas[i].getName( ),
					null,
					metas[i].getDescription( ) ) );
		}
	}
	return proposals.toArray( new CompletionProposal[proposals.size( )] );
}
 
源代码14 项目: eclipse-cs   文件: RegExContentAssistProcessor.java
/**
 * Adds a proposal. Ensures that existing pre- and postfixes are not duplicated.
 *
 * @param proposal
 *          the string to be inserted
 * @param cursorPosition
 *          the cursor position after insertion, relative to the start of the proposal
 * @param displayString
 *          the proposal's label
 * @param additionalInfo
 *          the additional information
 */
private void addBracketProposal(String proposal, int cursorPosition, String displayString,
        String additionalInfo) {
  String prolog = fExpression.substring(0, fDocumentOffset);
  if (!fIsEscape && prolog.endsWith("\\") && proposal.startsWith("\\")) { //$NON-NLS-1$//$NON-NLS-2$
    fProposals.add(new CompletionProposal(proposal, fDocumentOffset, 0, cursorPosition, null,
            displayString, null, additionalInfo));
    return;
  }
  for (int i = 1; i <= cursorPosition; i++) {
    String prefix = proposal.substring(0, i);
    if (prolog.endsWith(prefix)) {
      String postfix = proposal.substring(cursorPosition);
      String epilog = fExpression.substring(fDocumentOffset);
      if (epilog.startsWith(postfix)) {
        fPriorityProposals.add(
                new CompletionProposal(proposal.substring(i, cursorPosition), fDocumentOffset,
                        0, cursorPosition - i, null, displayString, null, additionalInfo));
      } else {
        fPriorityProposals.add(new CompletionProposal(proposal.substring(i), fDocumentOffset, 0,
                cursorPosition - i, null, displayString, null, additionalInfo));
      }
      return;
    }
  }
  fProposals.add(new CompletionProposal(proposal, fDocumentOffset, 0, cursorPosition, null,
          displayString, null, additionalInfo));
}
 
源代码15 项目: http4e   文件: AssistUtils.java
/**
 * Adding http 1.1 headers proposals
 */
public static void doHttpHeadersProposals( int offset, String qualifier, List proposalsList){
    List httpHeaders = LazyObjects.getHttpHeaders();
    int qlen = qualifier.length();
    
    for (Iterator iter = httpHeaders.iterator(); iter.hasNext();) {
      String text = (String) iter.next();
      if (text.toLowerCase().startsWith(qualifier.toLowerCase())) {
         int cursor = text.length();
         CompletionProposal cp = new CompletionProposal(text + AssistConstants.BRACKETS_COMPLETION, offset - qlen, qlen, cursor + 4, ResourceUtils.getImage(CoreConstants.PLUGIN_CORE, CoreImages.ASSIST_HEADER), text, null, LazyObjects.getInfoMap("Headers").getInfo(text));
         proposalsList.add(cp);
      }
    }
}
 
源代码16 项目: http4e   文件: AssistUtils.java
private static void buildWordTrackProposals( List suggestions, String replacedWord, int offset, List proposalsList){
   int index = 0;
   for (Iterator i = suggestions.iterator(); i.hasNext();) {
      String currSuggestion = (String) i.next();
      proposalsList.add( new CompletionProposal(currSuggestion, offset, replacedWord.length(), currSuggestion.length(), ResourceUtils.getImage(CoreConstants.PLUGIN_CORE, CoreImages.ASSIST_HEADER_CACHED), currSuggestion, null, LazyObjects.getInfoMap("Headers").getInfo(currSuggestion)));
      index++;
   }
}
 
源代码17 项目: http4e   文件: Ch5CompletionEditor.java
private ICompletionProposal[] buildProposals( List suggestions, String replacedWord, int offset){
   ICompletionProposal[] proposals = new ICompletionProposal[suggestions.size()];
   int index = 0;
   for (Iterator i = suggestions.iterator(); i.hasNext();) {
      String currSuggestion = (String) i.next();
      proposals[index] = new CompletionProposal(currSuggestion, offset, replacedWord.length(), currSuggestion.length());
      index++;
   }
   return proposals;
}
 
private void proposeHeaderOperands(int offset, IDocument document, List<ICompletionProposal> proposals) {
	
	String line = getCurrentLine(document, offset);
	if (!containsHeader(line)) {
		
		for (String keyword : Formatter.HEADER_MODE_PROPOSALS) {
			proposals.add(new CompletionProposal(keyword + " ", offset, 0, keyword.length() + 1));
		}
	}
}
 
private ICompletionProposal[] typeProposals(int cursorPosition, List<String> autoSuggests, String currentPart) {
	
	int counter = 0;
	ICompletionProposal[] proposals = new ICompletionProposal[autoSuggests.size()];
	for (Iterator<String> iter = autoSuggests.iterator(); iter.hasNext();) {
		String autoSuggest = (String)iter.next();
		//Each proposal contains the text to propose, as well as information about where to insert the text into the document. 
		proposals[counter] = new CompletionProposal(autoSuggest + ";", cursorPosition - currentPart.length(), currentPart.length(), autoSuggest.length() + 1);
		counter++;
	}
	return proposals;
}
 
private ICompletionProposal[] keywordProposals(int cursorPosition, List<String> autoSuggests, String currentPart, boolean includeEquals, boolean includesComma) {
	
	int counter = 0;
	ICompletionProposal[] proposals = new ICompletionProposal[autoSuggests.size()];
	for (Iterator<String> iter = autoSuggests.iterator(); iter.hasNext();) {
		String autoSuggest = (String)iter.next();
		
		if (currentPart.endsWith("[")) {
			proposals[counter] = new CompletionProposal(autoSuggest + "=", cursorPosition, 0, autoSuggest.length() + 1);
		}
		else {
			if (includeEquals) {
				if (includesComma) {
					proposals[counter] = new CompletionProposal(autoSuggest + "=", cursorPosition, 0, autoSuggest.length() + 1);
				}
				else {
					proposals[counter] = new CompletionProposal(autoSuggest + "=", cursorPosition - currentPart.length(), currentPart.length(), autoSuggest.length() + 1);
				}
			}
			else if (includesComma) {
				if (currentPart.endsWith("=")) {
					proposals[counter] = new CompletionProposal(autoSuggest, cursorPosition, 0, autoSuggest.length());
				}
				else {
					proposals[counter] = new CompletionProposal(autoSuggest, cursorPosition - currentPart.length(), currentPart.length(), autoSuggest.length() + 1);
				}
			}
			else {
				proposals[counter] = new CompletionProposal(autoSuggest, cursorPosition, 0, autoSuggest.length());
			}
		}
		counter++;
	}
	return proposals;
}
 
private ICompletionProposal[] typeProposals(int cursorPosition, List<String> autoSuggests, String thisAttrib, String currentPart) {
	
	int counter = 0;
	ICompletionProposal[] suggestions = new ICompletionProposal[autoSuggests.size()];
	for (Iterator<String> iter = autoSuggests.iterator(); iter.hasNext();) {
		String autoSuggest = (String)iter.next();
		
		//Each proposal contains the text to propose, as well as information about where to insert the text into the document. 
		suggestions[counter] = new CompletionProposal(autoSuggest + ";", cursorPosition - thisAttrib.length(), thisAttrib.length(), autoSuggest.length() + 1);
		counter++;
	}
	return suggestions;
}
 
private ICompletionProposal[] keywordProposals(int cursorPosition, List<String> autoSuggests, String thisAttrib, String currentPart, boolean includeEquals, boolean includesComma) {
	
	int counter = 0;
	ICompletionProposal[] suggestions = new ICompletionProposal[autoSuggests.size()];
	for (Iterator<String> iter = autoSuggests.iterator(); iter.hasNext();) {
		String autoSuggest = (String)iter.next();
		
		//Each proposal contains the text to propose, as well as information about where to insert the text into the document.
		if (thisAttrib.endsWith("[")) {
			suggestions[counter] = new CompletionProposal(autoSuggest + "=", cursorPosition, 0, autoSuggest.length() + 1);
		}
		else {
			if (includeEquals) {
				if (includesComma) {
					suggestions[counter] = new CompletionProposal(autoSuggest + "=", cursorPosition, 0, autoSuggest.length() + 1);
				}
				else {
					suggestions[counter] = new CompletionProposal(autoSuggest + "=", cursorPosition - currentPart.length(), currentPart.length(), autoSuggest.length() + 1);
				}
			}
			else if (includesComma) {
				if (thisAttrib.endsWith("=")) {
					suggestions[counter] = new CompletionProposal(autoSuggest, cursorPosition, 0, autoSuggest.length());
				}
				else {
					suggestions[counter] = new CompletionProposal(autoSuggest, cursorPosition - currentPart.length(), currentPart.length(), autoSuggest.length() + 1);
				}
			}
			else {
				suggestions[counter] = new CompletionProposal(autoSuggest, cursorPosition, 0, autoSuggest.length());
			}
		}
		counter++;
	}
	return suggestions;
}
 
@Override
public void apply(IDocument document) {
	initIfNeeded();
	CompletionProposal proposal = new CompletionProposal(getReplacementString(), getReplacementOffset(),
			getReplacementLength(), getCursorPosition(), getImage(), getDisplayString(), getContextInformation(),
			getAdditionalProposalInfo());
	proposal.apply(document);
}
 
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {

	IDocument document = viewer.getDocument();

	try {
		int lineOfOffset = document.getLineOfOffset(offset);
		int lineOffset = document.getLineOffset(lineOfOffset);

		// do not show any content assist in case the offset is not at the
		// beginning of a line
		if (offset != lineOffset) {
			return new ICompletionProposal[0];
		}
	} catch (BadLocationException e) {
		// ignore here and just continue
	}

	List<ICompletionProposal> completionProposals = new ArrayList<ICompletionProposal>();

	for (String c : proposals) {
		// Only add proposal if it is not already present
		if (!(viewer.getDocument().get().contains(c))) {
			completionProposals.add(new CompletionProposal(c, offset, 0, c.length()));
		}
	}

	return completionProposals.toArray(new ICompletionProposal[completionProposals.size()]);
}
 
源代码25 项目: birt   文件: JdbcSQLContentAssistProcessor.java
private ICompletionProposal[] getRelevantProposals( ITextViewer viewer,
		int offset ) throws BadLocationException
{
	if ( lastProposals != null )
	{
		ArrayList relevantProposals = new ArrayList( 10 );

		String word = ( findWord( viewer, offset - 1 ) ).toLowerCase( );
		//Search for this word in the list

		for ( int n = 0; n < lastProposals.length; n++ )
		{
			if ( stripQuotes( lastProposals[n].getDisplayString( )
					.toLowerCase( ) ).startsWith( word ) )
			{
				CompletionProposal proposal = new CompletionProposal( lastProposals[n].getDisplayString( ),
						offset - word.length( ),
						word.length( ),
						lastProposals[n].getDisplayString( ).length( ) );
				relevantProposals.add( proposal );
			}
		}

		if ( relevantProposals.size( ) > 0 )
		{
			return (ICompletionProposal[]) relevantProposals.toArray( new ICompletionProposal[]{} );
		}
	}

	return null;
}
 
源代码26 项目: texlipse   文件: TexStyleCompletionManager.java
/**
 * Returns the style completion proposals
 * 
 * @param selectedText The selected text
 * @param selectedRange The selected range
 * @return An array of completion proposals
 */
public ICompletionProposal[] getStyleCompletions(String selectedText, Point selectedRange) {

    /*
    ICompletionProposal[] result = new ICompletionProposal[keyValue.size()];
    int i=0;
    for (Iterator iter = keyValue.keySet().iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        String value = (String) keyValue.get(key);
        
        
        String replacement = "{" + key + " " + selectedText + "}";
        int cursor = key.length() + 2;
        IContextInformation contextInfo = new ContextInformation(null, value+" Style");
        result[i] = new CompletionProposal(replacement, 
                selectedRange.x, selectedRange.y,
                cursor, null, value,
                contextInfo, replacement);
        i++;
    }
    */
    
    ICompletionProposal[] result = new ICompletionProposal[STYLELABELS.length];
    // Loop through all styles
    for (int i = 0; i < STYLETAGS.length; i++) {
        String tag = STYLETAGS[i];
        
        // Compute replacement text
        String replacement = tag + selectedText + "}";
        
        // Derive cursor position
        int cursor = tag.length() + selectedText.length() + 1;
        
        // Compute a suitable context information
        IContextInformation contextInfo = 
            new ContextInformation(null, STYLELABELS[i]+" Style");
        
        // Construct proposal
        result[i] = new CompletionProposal(replacement, 
                selectedRange.x, selectedRange.y,
                cursor, null, STYLELABELS[i], 
                contextInfo, replacement);
    }
    return result;
}
 
源代码27 项目: texlipse   文件: TexCompletionProcessor.java
/**
 * Computes and returns BibTeX-proposals.
 * 
 * @param offset
 *            Current cursor offset
 * @param replacementLength
 *            The length of the string to be replaced
 * @param prefix
 *            The already typed prefix of the entry to assist with
 * @return An array of completion proposals to use directly or null
 */
private ICompletionProposal[] computeBibCompletions(int offset,
		int replacementLength, String prefix) {

	List<ICompletionProposal> resultAsList = new ArrayList<ICompletionProposal>();
	List<ReferenceEntry> bibEntries = refManager.getCompletionsBib(prefix);
	//add the entries of the .bib file(s) to the results
	if (bibEntries != null) {
		for (int i = 0; i < bibEntries.size(); i++) {
			ReferenceEntry bib = bibEntries.get(i);
			String infoText = bib.info.length() > assistLineLength ? wrapString(
					bib.info, assistLineLength)
					: bib.info;
					resultAsList.add(new CompletionProposal(bib.key, offset
							- replacementLength, replacementLength, bib.key.length(),
							null, bib.key, null, infoText));
		}
	}
	//the extension points
	IConfigurationElement[] configuration = Platform.getExtensionRegistry()
			.getConfigurationElementsFor(
					"org.eclipse.texlipse.CiteAutocompleteExtension");
	if (configuration.length > 0) {
		for (IConfigurationElement elem : configuration) {
			try {
				//fetches the BibProvider and updates the result
				BibProvider prov = (BibProvider) elem
						.createExecutableExtension("class");
				resultAsList = prov.getCompletions(offset, replacementLength,
						prefix, refManager.getBibContainer());

			} catch (CoreException e) {
				// e.printStackTrace();
				//log
			}
		}
	}

	//if there are no entries, return null
	if (resultAsList == null || resultAsList.size() == 0)
		return null;
	ICompletionProposal[] result = new ICompletionProposal[resultAsList
			.size()];
	return resultAsList.toArray(result);
}
 
private ICompletionProposal[] standardMethod(ITextViewer viewer, int offset, List<String> keywords, List<ICompletionProposal> autoCompProposals) {
	
	int index = offset - 1;
	StringBuffer prefix = new StringBuffer();
	IDocument document = viewer.getDocument();
			
	while (index > 0) {
		try {
			char prev = document.getChar(index);
			if (Character.isWhitespace(prev)) {
				break;
			}
			prefix.insert(0, prev);
			index--;
		}
		catch (BadLocationException ble) {
			Activator.getDefault().log("could not get char", ble);
		}
	}

	if (prefix.length() > 0) {
		String word = prefix.toString();
		// limit to attributes
		if (containsOpenBracket(word)) {
			autoCompProposals.addAll(addHeaderAttributes(word, offset));
		}
		for (String keyword : keywords) {
			if (keyword.toUpperCase(Locale.ENGLISH).startsWith(word.toUpperCase(Locale.ENGLISH)) && word.length() < keyword.length()) {
				autoCompProposals.add(new CompletionProposal(keyword + " ", index + 1, offset - (index + 1), keyword.length() + 1));
			}
		}
	}
	else {
		// propose header keywords
		proposeHeaderOperands(offset, document, autoCompProposals);
	}
	
	if (!autoCompProposals.isEmpty()) {
		return (ICompletionProposal[]) autoCompProposals.toArray(new ICompletionProposal[autoCompProposals.size()]);
	}
	return null;

}
 
源代码29 项目: birt   文件: JSCompletionProcessor.java
protected CompletionProposal[] getCompletionProposals(
		JSObjectMetaData meta, int offset )
{
	List<CompletionProposal> proposals = new ArrayList<CompletionProposal>( );
	int wordLength = currentWord == null ? 0 : currentWord.length( );

	JSField[] members = meta.getFields( );
	if ( members != null )
	{
		for ( int i = 0; i < members.length; i++ )
		{
			if ( currentWord == null || currentWord.equals( "" ) //$NON-NLS-1$
					|| members[i].getName( )
							.toLowerCase( )
							.startsWith( currentWord.toLowerCase( ) ) )
			{
				proposals.add( new CompletionProposal( members[i].getName( ),
						offset - wordLength,
						wordLength,
						members[i].getName( ).length( ),
						getMemberImage( members[i].getVisibility( ) ),
						members[i].getDisplayText( ),
						null,
						members[i].getDescription( ) ) );
			}
		}
	}

	JSMethod[] methods = meta.getMethods( );
	if ( methods != null )
	{
		for ( int i = 0; i < methods.length; i++ )
		{
			if ( currentWord == null || currentWord.equals( "" ) //$NON-NLS-1$
					|| methods[i].getName( )
							.toLowerCase( )
							.startsWith( currentWord.toLowerCase( ) ) )
			{
				JSObjectMetaData[] args = methods[i].getArguments( );

				boolean hasArg = args != null && args.length > 0;

				proposals.add( new CompletionProposal( "." //$NON-NLS-1$
						+ methods[i].getName( )
						+ "()", //$NON-NLS-1$
						offset - wordLength - 1,
						wordLength + 1,
						methods[i].getName( ).length( ) + ( hasArg ? 2 : 3 ),
						getMethodImage( methods[i].getVisibility( ) ),
						methods[i].getDisplayText( ),
						null,
						methods[i].getDescription( ) ) );
			}
		}
	}
	return proposals.toArray( new CompletionProposal[proposals.size( )] );
}
 
源代码30 项目: eclipse-cs   文件: RegExContentAssistProcessor.java
/**
 * Adds a proposal that starts with a backslash.
 *
 * @param proposal
 *          the string to be inserted
 * @param displayString
 *          the proposal's label
 * @param additionalInfo
 *          the additional information
 */
private void addBsProposal(String proposal, String displayString, String additionalInfo) {
  if (fIsEscape) {
    fPriorityProposals.add(new CompletionProposal(proposal.substring(1), fDocumentOffset, 0,
            proposal.length() - 1, null, displayString, null, additionalInfo));
  } else {
    addProposal(proposal, displayString, additionalInfo);
  }
}
 
 类所在包
 类方法
 同包方法