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 31 public final class ExperimentalResultCollector extends CompletionProposalCollector { 32 33 private final boolean fIsGuessArguments; 34 35 public ExperimentalResultCollector(JavaContentAssistInvocationContext context) { 36 super(context.getCompilationUnit()); 37 setInvocationContext(context); 38 IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore(); 39 fIsGuessArguments= preferenceStore.getBoolean(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS); 40 } 41 42 45 protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) { 46 switch (proposal.getKind()) { 47 case CompletionProposal.METHOD_REF: 48 return createMethodReferenceProposal(proposal); 49 case CompletionProposal.TYPE_REF: 50 return createTypeProposal(proposal); 51 default: 52 return super.createJavaCompletionProposal(proposal); 53 } 54 } 55 56 private IJavaCompletionProposal createMethodReferenceProposal(CompletionProposal methodProposal) { 57 String completion= String.valueOf(methodProposal.getCompletion()); 58 if ((completion.length() == 0) || ((completion.length() == 1) && completion.charAt(0) == ')') || Signature.getParameterCount(methodProposal.getSignature()) == 0 || getContext().isInJavadoc()) 61 return super.createJavaCompletionProposal(methodProposal); 62 63 LazyJavaCompletionProposal proposal; 64 ICompilationUnit compilationUnit= getCompilationUnit(); 65 if (compilationUnit != null && fIsGuessArguments) 66 proposal= new ParameterGuessingProposal(methodProposal, getInvocationContext()); 67 else 68 proposal= new ExperimentalProposal(methodProposal, getInvocationContext()); 69 return proposal; 70 } 71 72 75 private IJavaCompletionProposal createTypeProposal(CompletionProposal typeProposal) { 76 final ICompilationUnit cu= getCompilationUnit(); 77 if (cu == null || getContext().isInJavadoc()) 78 return super.createJavaCompletionProposal(typeProposal); 79 80 IJavaProject project= cu.getJavaProject(); 81 if (!shouldProposeGenerics(project)) 82 return super.createJavaCompletionProposal(typeProposal); 83 84 char[] completion= typeProposal.getCompletion(); 85 if (completion.length == 0 || completion[completion.length - 1] == ';' || completion[completion.length - 1] == '.') 87 return super.createJavaCompletionProposal(typeProposal); 88 89 LazyJavaCompletionProposal newProposal= new GenericJavaTypeProposal(typeProposal, getInvocationContext()); 90 return newProposal; 91 } 92 93 102 private final boolean shouldProposeGenerics(IJavaProject project) { 103 String sourceVersion; 104 if (project != null) 105 sourceVersion= project.getOption(JavaCore.COMPILER_SOURCE, true); 106 else 107 sourceVersion= JavaCore.getOption(JavaCore.COMPILER_SOURCE); 108 109 return sourceVersion != null && JavaCore.VERSION_1_5.compareTo(sourceVersion) <= 0; 110 } 111 } 112 | Popular Tags |