org.eclipse.jface.text.contentassist.CompletionProposal Java Examples

The following examples show how to use org.eclipse.jface.text.contentassist.CompletionProposal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TexSpellingEngine.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: CommonContentAssistProcessor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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));
		}
	}
}
 
Example #3
Source File: ImpexTypeAttributeContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: ImpexTypeSystemContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: ImpexCommandContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
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;
	
}
 
Example #6
Source File: PropertiesContentAssistProcessor.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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()]);
}
 
Example #7
Source File: TexCompletionProcessor.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: BibCompletionProcessor.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: JavaCompletionProposalComputer1.java    From ContentAssist with MIT License 6 votes vote down vote up
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;
}
 
Example #10
Source File: JSCompletionProcessor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
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( )] );
}
 
Example #11
Source File: JSDocCompletionProposalComputer.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
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);
		}
	}
}
 
Example #12
Source File: JdbcSQLContentAssistProcessor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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;
}
 
Example #13
Source File: JdbcSQLContentAssistProcessor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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;
}
 
Example #14
Source File: AssistUtils.java    From http4e with Apache License 2.0 5 votes vote down vote up
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++;
   }
}
 
Example #15
Source File: TypeScriptCompletionProposal.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void apply(IDocument document) {
	initIfNeeded();
	CompletionProposal proposal = new CompletionProposal(getReplacementString(), getReplacementOffset(),
			getReplacementLength(), getCursorPosition(), getImage(), getDisplayString(), getContextInformation(),
			getAdditionalProposalInfo());
	proposal.apply(document);
}
 
Example #16
Source File: ImpexTypeAttributeContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: ImpexTypeAttributeContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #18
Source File: ImpexTypeSystemContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #19
Source File: ImpexTypeSystemContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #20
Source File: ImpexCommandContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
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));
		}
	}
}
 
Example #21
Source File: RegExContentAssistProcessor.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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));
}
 
Example #22
Source File: TaskCompletionProcessor.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
@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()]);
}
 
Example #23
Source File: JdbcSQLContentAssistProcessor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: Ch5CompletionEditor.java    From http4e with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #25
Source File: AssistUtils.java    From http4e with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
      }
    }
}
 
Example #26
Source File: ImpexCommandContentAssistProcessor.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
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;

}
 
Example #27
Source File: JSCompletionProcessor.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
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( )] );
}
 
Example #28
Source File: TexCompletionProcessor.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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);
}
 
Example #29
Source File: TexStyleCompletionManager.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #30
Source File: RegExContentAssistProcessor.java    From eclipse-cs with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * 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);
  }
}