1 11 package org.eclipse.jdt.internal.ui.text.java; 12 13 import org.eclipse.jface.preference.IPreferenceStore; 14 15 import org.eclipse.jdt.core.CompletionProposal; 16 import org.eclipse.jdt.core.ICompilationUnit; 17 import org.eclipse.jdt.core.IJavaProject; 18 import org.eclipse.jdt.core.JavaCore; 19 import org.eclipse.jdt.core.Signature; 20 21 import org.eclipse.jdt.ui.PreferenceConstants; 22 import org.eclipse.jdt.ui.text.java.CompletionProposalCollector; 23 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; 24 import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext; 25 26 import org.eclipse.jdt.internal.ui.JavaPlugin; 27 28 36 public final class FillArgumentNamesCompletionProposalCollector extends CompletionProposalCollector { 37 38 private final boolean fIsGuessArguments; 39 40 public FillArgumentNamesCompletionProposalCollector(JavaContentAssistInvocationContext context) { 41 super(context.getCompilationUnit()); 42 setInvocationContext(context); 43 IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore(); 44 fIsGuessArguments= preferenceStore.getBoolean(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS); 45 } 46 47 50 protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) { 51 switch (proposal.getKind()) { 52 case CompletionProposal.METHOD_REF: 53 return createMethodReferenceProposal(proposal); 54 case CompletionProposal.TYPE_REF: 55 return createTypeProposal(proposal); 56 default: 57 return super.createJavaCompletionProposal(proposal); 58 } 59 } 60 61 private IJavaCompletionProposal createMethodReferenceProposal(CompletionProposal methodProposal) { 62 String completion= String.valueOf(methodProposal.getCompletion()); 63 if ((completion.length() == 0) || ((completion.length() == 1) && completion.charAt(0) == ')') || Signature.getParameterCount(methodProposal.getSignature()) == 0 || getContext().isInJavadoc()) 66 return super.createJavaCompletionProposal(methodProposal); 67 68 LazyJavaCompletionProposal proposal; 69 ICompilationUnit compilationUnit= getCompilationUnit(); 70 if (compilationUnit != null && fIsGuessArguments) 71 proposal= new ParameterGuessingProposal(methodProposal, getInvocationContext()); 72 else 73 proposal= new FilledArgumentNamesMethodProposal(methodProposal, getInvocationContext()); 74 return proposal; 75 } 76 77 80 private IJavaCompletionProposal createTypeProposal(CompletionProposal typeProposal) { 81 final ICompilationUnit cu= getCompilationUnit(); 82 if (cu == null || getContext().isInJavadoc()) 83 return super.createJavaCompletionProposal(typeProposal); 84 85 IJavaProject project= cu.getJavaProject(); 86 if (!shouldProposeGenerics(project)) 87 return super.createJavaCompletionProposal(typeProposal); 88 89 char[] completion= typeProposal.getCompletion(); 90 if (completion.length > 0 && (completion[completion.length - 1] == ';' || completion[completion.length - 1] == '.')) 92 return super.createJavaCompletionProposal(typeProposal); 93 94 LazyJavaCompletionProposal newProposal= new LazyGenericTypeProposal(typeProposal, getInvocationContext()); 95 return newProposal; 96 } 97 98 108 private final boolean shouldProposeGenerics(IJavaProject project) { 109 String sourceVersion; 110 if (project != null) 111 sourceVersion= project.getOption(JavaCore.COMPILER_SOURCE, true); 112 else 113 sourceVersion= JavaCore.getOption(JavaCore.COMPILER_SOURCE); 114 115 return sourceVersion != null && JavaCore.VERSION_1_5.compareTo(sourceVersion) <= 0; 116 } 117 } 118 | Popular Tags |