jtl-eclipse-master/ASPT.resource.aspt.ui/src-gen/ASPT/resource/aspt/ui/AsptCompletionProcessor.java
/**
 * <copyright>
 * </copyright>
 *
 * 
 */
package ASPT.resource.aspt.ui;

public class AsptCompletionProcessor implements org.eclipse.jface.text.contentassist.IContentAssistProcessor {
	
	private ASPT.resource.aspt.IAsptResourceProvider resourceProvider;
	private ASPT.resource.aspt.ui.IAsptBracketHandlerProvider bracketHandlerProvider;
	
	public AsptCompletionProcessor(ASPT.resource.aspt.IAsptResourceProvider resourceProvider, ASPT.resource.aspt.ui.IAsptBracketHandlerProvider bracketHandlerProvider) {
		this.resourceProvider = resourceProvider;
		this.bracketHandlerProvider = bracketHandlerProvider;
	}
	
	public org.eclipse.jface.text.contentassist.ICompletionProposal[] computeCompletionProposals(org.eclipse.jface.text.ITextViewer viewer, int offset) {
		ASPT.resource.aspt.IAsptTextResource textResource = resourceProvider.getResource();
		if (textResource == null) {
			return new org.eclipse.jface.text.contentassist.ICompletionProposal[0];
		}
		String content = viewer.getDocument().get();
		ASPT.resource.aspt.ui.AsptCodeCompletionHelper helper = new ASPT.resource.aspt.ui.AsptCodeCompletionHelper();
		ASPT.resource.aspt.ui.AsptCompletionProposal[] computedProposals = helper.computeCompletionProposals(textResource, content, offset);
		
		// call completion proposal post processor to allow for customizing the proposals
		ASPT.resource.aspt.ui.AsptProposalPostProcessor proposalPostProcessor = new ASPT.resource.aspt.ui.AsptProposalPostProcessor();
		java.util.List<ASPT.resource.aspt.ui.AsptCompletionProposal> computedProposalList = java.util.Arrays.asList(computedProposals);
		java.util.List<ASPT.resource.aspt.ui.AsptCompletionProposal> extendedProposalList = proposalPostProcessor.process(computedProposalList);
		if (extendedProposalList == null) {
			extendedProposalList = java.util.Collections.emptyList();
		}
		java.util.List<ASPT.resource.aspt.ui.AsptCompletionProposal> finalProposalList = new java.util.ArrayList<ASPT.resource.aspt.ui.AsptCompletionProposal>();
		for (ASPT.resource.aspt.ui.AsptCompletionProposal proposal : extendedProposalList) {
			if (proposal.getMatchesPrefix()) {
				finalProposalList.add(proposal);
			}
		}
		org.eclipse.jface.text.contentassist.ICompletionProposal[] result = new org.eclipse.jface.text.contentassist.ICompletionProposal[finalProposalList.size()];
		int i = 0;
		for (ASPT.resource.aspt.ui.AsptCompletionProposal proposal : finalProposalList) {
			String proposalString = proposal.getInsertString();
			String displayString = proposal.getDisplayString();
			String prefix = proposal.getPrefix();
			org.eclipse.swt.graphics.Image image = proposal.getImage();
			org.eclipse.jface.text.contentassist.IContextInformation info;
			info = new org.eclipse.jface.text.contentassist.ContextInformation(image, proposalString, proposalString);
			int begin = offset - prefix.length();
			int replacementLength = prefix.length();
			// if a closing bracket was automatically inserted right before, we enlarge the
			// replacement length in order to overwrite the bracket.
			ASPT.resource.aspt.ui.IAsptBracketHandler bracketHandler = bracketHandlerProvider.getBracketHandler();
			String closingBracket = bracketHandler.getClosingBracket();
			if (bracketHandler.addedClosingBracket() && proposalString.endsWith(closingBracket)) {
				replacementLength += closingBracket.length();
			}
			result[i++] = new org.eclipse.jface.text.contentassist.CompletionProposal(proposalString, begin, replacementLength, proposalString.length(), image, displayString, info, proposalString);
		}
		return result;
	}
	
	public org.eclipse.jface.text.contentassist.IContextInformation[] computeContextInformation(org.eclipse.jface.text.ITextViewer viewer, int offset) {
		return null;
	}
	
	public char[] getCompletionProposalAutoActivationCharacters() {
		return null;
	}
	
	public char[] getContextInformationAutoActivationCharacters() {
		return null;
	}
	
	public org.eclipse.jface.text.contentassist.IContextInformationValidator getContextInformationValidator() {
		return null;
	}
	
	public String getErrorMessage() {
		return null;
	}
}
