1 11 12 package org.eclipse.jdt.internal.ui.refactoring.contentassist; 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 17 import org.eclipse.core.runtime.Assert; 18 19 import org.eclipse.swt.graphics.Image; 20 21 import org.eclipse.jface.contentassist.IContentAssistSubjectControl; 22 import org.eclipse.jface.contentassist.ISubjectControlContentAssistProcessor; 23 import org.eclipse.jface.text.ITextViewer; 24 import org.eclipse.jface.text.contentassist.ICompletionProposal; 25 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; 26 import org.eclipse.jface.text.contentassist.IContextInformation; 27 import org.eclipse.jface.text.contentassist.IContextInformationValidator; 28 29 import org.eclipse.jface.resource.ImageDescriptor; 30 31 import org.eclipse.jdt.internal.ui.JavaPlugin; 32 import org.eclipse.jdt.internal.ui.JavaPluginImages; 33 import org.eclipse.jdt.internal.ui.JavaUIMessages; 34 import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal; 35 import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry; 36 37 public class VariableNamesProcessor implements IContentAssistProcessor, ISubjectControlContentAssistProcessor { 38 39 private String fErrorMessage; 40 41 private String [] fTempNameProposals; 42 43 private ImageDescriptorRegistry fImageRegistry; 44 private ImageDescriptor fProposalImageDescriptor; 45 46 public VariableNamesProcessor(String [] tempNameProposals) { 47 fTempNameProposals= (String []) tempNameProposals.clone(); 48 Arrays.sort(fTempNameProposals); 49 fImageRegistry= JavaPlugin.getImageDescriptorRegistry(); 50 fProposalImageDescriptor= JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE; 51 52 } 53 54 public void setProposalImageDescriptor(ImageDescriptor proposalImageDescriptor) { 55 fProposalImageDescriptor= proposalImageDescriptor; 56 } 57 58 61 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { 62 Assert.isTrue(false, "ITextViewer not supported"); return null; 64 } 65 66 69 public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { 70 Assert.isTrue(false, "ITextViewer not supported"); return null; 72 } 73 74 77 public char[] getCompletionProposalAutoActivationCharacters() { 78 return null; 79 } 80 81 84 public char[] getContextInformationAutoActivationCharacters() { 85 return null; } 87 88 91 public String getErrorMessage() { 92 return fErrorMessage; 93 } 94 95 98 public IContextInformationValidator getContextInformationValidator() { 99 return null; } 101 102 105 public IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubject, int documentOffset) { 106 return null; } 108 109 112 public ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubject, int documentOffset) { 113 if (fTempNameProposals.length == 0) 114 return null; 115 String input= contentAssistSubject.getDocument().get(); 116 117 ArrayList proposals= new ArrayList (); 118 String prefix= input.substring(0, documentOffset); 119 Image image= fImageRegistry.get(fProposalImageDescriptor); 120 for (int i= 0; i < fTempNameProposals.length; i++) { 121 String tempName= fTempNameProposals[i]; 122 if (tempName.length() == 0 || ! tempName.startsWith(prefix)) 123 continue; 124 JavaCompletionProposal proposal= new JavaCompletionProposal(tempName, 0, input.length(), image, tempName, 0); 125 proposals.add(proposal); 126 } 127 fErrorMessage= proposals.size() > 0 ? null : JavaUIMessages.JavaEditor_codeassist_noCompletions; 128 return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); 129 } 130 131 } 132 | Popular Tags |