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.resource.ImageDescriptor; 24 import org.eclipse.jface.text.ITextViewer; 25 import org.eclipse.jface.text.contentassist.ICompletionProposal; 26 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; 27 import org.eclipse.jface.text.contentassist.IContextInformation; 28 import org.eclipse.jface.text.contentassist.IContextInformationValidator; 29 30 import org.eclipse.jdt.internal.corext.refactoring.code.PromoteTempToFieldRefactoring; 31 32 import org.eclipse.jdt.internal.ui.JavaPlugin; 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 import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider; 37 38 public class FieldNameProcessor implements IContentAssistProcessor, ISubjectControlContentAssistProcessor { 39 40 private String [] fFieldNameProposals; 41 private String fErrorMessage; 42 private ImageDescriptorRegistry fImageRegistry= JavaPlugin.getImageDescriptorRegistry(); 43 private PromoteTempToFieldRefactoring fRefactoring; 44 45 public FieldNameProcessor(String [] guessedFieldNames, PromoteTempToFieldRefactoring refactoring) { 46 fRefactoring= refactoring; 47 fFieldNameProposals= refactoring.guessFieldNames(); 48 Arrays.sort(fFieldNameProposals); 49 } 50 51 54 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { 55 Assert.isTrue(false, "ITextViewer not supported"); return null; 57 } 58 59 62 public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { 63 Assert.isTrue(false, "ITextViewer not supported"); return null; 65 } 66 67 70 public char[] getCompletionProposalAutoActivationCharacters() { 71 return null; 72 } 73 74 77 public char[] getContextInformationAutoActivationCharacters() { 78 return null; } 80 81 84 public String getErrorMessage() { 85 return fErrorMessage; 86 } 87 88 91 public IContextInformationValidator getContextInformationValidator() { 92 return null; } 94 95 98 public IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubject, int documentOffset) { 99 return null; } 101 102 105 public ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubject, int documentOffset) { 106 if (fFieldNameProposals.length == 0) 107 return null; 108 String input= contentAssistSubject.getDocument().get(); 109 110 ArrayList proposals= new ArrayList (); 111 String prefix= input.substring(0, documentOffset); 112 ImageDescriptor imageDescriptor= JavaElementImageProvider.getFieldImageDescriptor(false, fRefactoring.getVisibility()); 113 Image image= fImageRegistry.get(imageDescriptor); 114 for (int i= 0; i < fFieldNameProposals.length; i++) { 115 String tempName= fFieldNameProposals[i]; 116 if (tempName.length() == 0 || ! tempName.startsWith(prefix)) 117 continue; 118 JavaCompletionProposal proposal= new JavaCompletionProposal(tempName, 0, input.length(), image, tempName, 0); 119 proposals.add(proposal); 120 } 121 fErrorMessage= proposals.size() > 0 ? null : JavaUIMessages.JavaEditor_codeassist_noCompletions; 122 return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); 123 } 124 125 } 126 | Popular Tags |