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.swt.graphics.Image; 18 19 import org.eclipse.jface.contentassist.IContentAssistSubjectControl; 20 import org.eclipse.jface.contentassist.ISubjectControlContentAssistProcessor; 21 import org.eclipse.jface.text.ITextViewer; 22 import org.eclipse.jface.text.contentassist.ICompletionProposal; 23 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; 24 import org.eclipse.jface.text.contentassist.IContextInformation; 25 import org.eclipse.jface.text.contentassist.IContextInformationValidator; 26 import org.eclipse.jface.util.Assert; 27 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 import org.eclipse.jdt.internal.ui.JavaPluginImages; 30 import org.eclipse.jdt.internal.ui.JavaUIMessages; 31 import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal; 32 import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry; 33 34 public class TempNameProcessor implements IContentAssistProcessor, ISubjectControlContentAssistProcessor { 35 36 private String [] fTempNameProposals; 37 private String fErrorMessage; 38 private ImageDescriptorRegistry fImageRegistry= JavaPlugin.getImageDescriptorRegistry(); 39 40 public TempNameProcessor(String [] tempNameProposals) { 41 fTempNameProposals= (String []) tempNameProposals.clone(); 42 Arrays.sort(fTempNameProposals); 43 } 44 45 48 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { 49 Assert.isTrue(false, "ITextViewer not supported"); return null; 51 } 52 53 56 public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { 57 Assert.isTrue(false, "ITextViewer not supported"); return null; 59 } 60 61 64 public char[] getCompletionProposalAutoActivationCharacters() { 65 return null; 66 } 67 68 71 public char[] getContextInformationAutoActivationCharacters() { 72 return null; } 74 75 78 public String getErrorMessage() { 79 return fErrorMessage; 80 } 81 82 85 public IContextInformationValidator getContextInformationValidator() { 86 return null; } 88 89 92 public IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubject, int documentOffset) { 93 return null; } 95 96 99 public ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubject, int documentOffset) { 100 if (fTempNameProposals.length == 0) 101 return null; 102 String input= contentAssistSubject.getDocument().get(); 103 104 ArrayList proposals= new ArrayList (); 105 String prefix= input.substring(0, documentOffset); 106 Image image= fImageRegistry.get(JavaPluginImages.DESC_OBJS_LOCAL_VARIABLE); 107 for (int i= 0; i < fTempNameProposals.length; i++) { 108 String tempName= fTempNameProposals[i]; 109 if (tempName.length() == 0 || ! tempName.startsWith(prefix)) 110 continue; 111 JavaCompletionProposal proposal= new JavaCompletionProposal(tempName, 0, input.length(), image, tempName, 0); 112 proposals.add(proposal); 113 } 114 fErrorMessage= proposals.size() > 0 ? null : JavaUIMessages.getString("JavaEditor.codeassist.noCompletions"); return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); 116 } 117 118 } 119 | Popular Tags |