本文整理汇总了Java中org.eclipse.jdt.core.CompletionProposal类的典型用法代码示例。如果您正苦于以下问题:Java CompletionProposal类的具体用法?Java CompletionProposal怎么用?Java CompletionProposal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompletionProposal类属于org.eclipse.jdt.core包,在下文中一共展示了CompletionProposal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createParameterList
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
/**
* Creates and returns a parameter list of the given method or type proposal suitable for
* display. The list does not include parentheses. The lower bound of parameter types is
* returned.
* <p>
* Examples:
*
* <pre>
* "void method(int i, String s)" -> "int i, String s"
* "? extends Number method(java.lang.String s, ? super Number n)" -> "String s, Number n"
* </pre>
*
* </p>
*
* @param proposal the proposal to create the parameter list for
* @return the list of comma-separated parameters suitable for display
*/
public StringBuilder createParameterList(CompletionProposal proposal) {
int kind= proposal.getKind();
switch (kind) {
case CompletionProposal.METHOD_REF:
case CompletionProposal.CONSTRUCTOR_INVOCATION:
return appendUnboundedParameterList(new StringBuilder(), proposal);
case CompletionProposal.TYPE_REF:
case CompletionProposal.JAVADOC_TYPE_REF:
return appendTypeParameterList(new StringBuilder(), proposal);
case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
return appendUnboundedParameterList(new StringBuilder(), proposal);
default:
Assert.isLegal(false);
return null; // dummy
}
}
示例2: appendUnboundedParameterList
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
/**
* Appends the parameter list to <code>buffer</code>.
*
* @param buffer the buffer to append to
* @param methodProposal the method proposal
* @return the modified <code>buffer</code>
*/
private StringBuilder appendUnboundedParameterList(StringBuilder buffer, CompletionProposal methodProposal) {
// TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
// gets fixed.
char[] signature= SignatureUtil.fix83600(methodProposal.getSignature());
char[][] parameterNames= methodProposal.findParameterNames(null);
char[][] parameterTypes= Signature.getParameterTypes(signature);
for (int i= 0; i < parameterTypes.length; i++) {
parameterTypes[i]= createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i]));
}
if (Flags.isVarargs(methodProposal.getFlags())) {
int index= parameterTypes.length - 1;
parameterTypes[index]= convertToVararg(parameterTypes[index]);
}
return appendParameterSignature(buffer, parameterTypes, parameterNames);
}
示例3: createAnonymousTypeLabel
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
private void createAnonymousTypeLabel(CompletionProposal proposal, CompletionItem item) {
char[] declaringTypeSignature= proposal.getDeclarationSignature();
declaringTypeSignature= Signature.getTypeErasure(declaringTypeSignature);
String name = new String(Signature.getSignatureSimpleName(declaringTypeSignature));
item.setInsertText(name);
StringBuilder buf= new StringBuilder();
buf.append(name);
buf.append('(');
appendUnboundedParameterList(buf, proposal);
buf.append(')');
buf.append(" "); //$NON-NLS-1$
buf.append("Anonymous Inner Type"); //TODO: consider externalization
item.setLabel(buf.toString());
if (proposal.getRequiredProposals() != null) {
char[] signatureQualifier= Signature.getSignatureQualifier(declaringTypeSignature);
if (signatureQualifier.length > 0) {
item.setDetail(String.valueOf(signatureQualifier));
}
}
setDeclarationSignature(item, String.valueOf(declaringTypeSignature));
}
示例4: acceptPotentialMethodDeclaration
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
private void acceptPotentialMethodDeclaration(CompletionProposal proposal) {
try {
IJavaElement enclosingElement = null;
if (response.getContext().isExtended()) {
enclosingElement = response.getContext().getEnclosingElement();
} else if (unit != null) {
// kept for backward compatibility: CU is not reconciled at this moment, information is missing (bug 70005)
enclosingElement = unit.getElementAt(proposal.getCompletionLocation() + 1);
}
if (enclosingElement == null) {
return;
}
IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE);
if (type != null) {
String prefix = String.valueOf(proposal.getName());
int completionStart = proposal.getReplaceStart();
int completionEnd = proposal.getReplaceEnd();
int relevance = proposal.getRelevance() + 6;
GetterSetterCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance, proposals);
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Accept potential method declaration failed for completion ", e);
}
}
示例5: appendMethodOverrideReplacement
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
/**
* @param completionBuffer
* @param proposal
*/
private void appendMethodOverrideReplacement(StringBuilder completionBuffer, CompletionProposal proposal) {
IDocument document;
try {
document = JsonRpcHelpers.toDocument(this.compilationUnit.getBuffer());
String signature = String.valueOf(proposal.getSignature());
String[] types = Stream.of(Signature.getParameterTypes(signature)).map(t -> Signature.toString(t))
.toArray(String[]::new);
String methodName = String.valueOf(proposal.getName());
int offset = proposal.getReplaceStart();
String completion = new String(proposal.getCompletion());
OverrideCompletionProposal overrider = new OverrideCompletionProposal(compilationUnit, methodName, types,
completion);
String replacement = overrider.updateReplacementString(document, offset, importRewrite,
client.isCompletionSnippetsSupported());
completionBuffer.append(replacement);
} catch (BadLocationException | CoreException e) {
JavaLanguageServerPlugin.logException("Failed to compute override replacement", e);
}
}
示例6: appendMethodNameReplacement
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
private void appendMethodNameReplacement(StringBuilder buffer, CompletionProposal proposal) {
if (proposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) {
String coreCompletion = String.valueOf(proposal.getCompletion());
if (client.isCompletionSnippetsSupported()) {
coreCompletion = CompletionUtils.sanitizeCompletion(coreCompletion);
}
// String lineDelimiter = TextUtilities.getDefaultLineDelimiter(getTextViewer().getDocument());
// String replacement= CodeFormatterUtil.format(CodeFormatter.K_EXPRESSION, coreCompletion, 0, lineDelimiter, fInvocationContext.getProject());
// buffer.append(replacement.substring(0, replacement.lastIndexOf('.') + 1));
buffer.append(coreCompletion);
}
if (proposal.getKind() != CompletionProposal.CONSTRUCTOR_INVOCATION) {
String str = new String(proposal.getName());
if (client.isCompletionSnippetsSupported()) {
str = CompletionUtils.sanitizeCompletion(str);
}
buffer.append(str);
}
}
示例7: appendGuessingCompletion
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
private void appendGuessingCompletion(StringBuilder buffer, CompletionProposal proposal) {
char[][] parameterNames= proposal.findParameterNames(null);
int count= parameterNames.length;
if(client.isCompletionSnippetsSupported()){
for (int i= 0; i < count; i++) {
if (i != 0) {
buffer.append(COMMA);
buffer.append(SPACE);
}
char[] argument = parameterNames[i];
if (client.isCompletionSnippetsSupported()) {
String replace = new String(argument);
replace = CompletionUtils.sanitizeCompletion(replace);
argument = replace.toCharArray();
}
buffer.append("${");
buffer.append(Integer.toString(i+1));
buffer.append(":");
buffer.append(argument);
buffer.append("}");
}
}
}
示例8: appendUnboundedParameterList
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
/**
* Appends the parameter list to <code>buffer</code>.
*
* @param buffer the buffer to append to
* @param methodProposal the method proposal
* @return the modified <code>buffer</code>
*/
private StyledString appendUnboundedParameterList(
StyledString buffer, CompletionProposal methodProposal) {
// TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
// gets fixed.
char[] signature = SignatureUtil.fix83600(methodProposal.getSignature());
char[][] parameterNames = methodProposal.findParameterNames(null);
char[][] parameterTypes = Signature.getParameterTypes(signature);
for (int i = 0; i < parameterTypes.length; i++)
parameterTypes[i] = createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i]));
if (Flags.isVarargs(methodProposal.getFlags())) {
int index = parameterTypes.length - 1;
parameterTypes[index] = convertToVararg(parameterTypes[index]);
}
return appendParameterSignature(buffer, parameterTypes, parameterNames);
}
示例9: computeKeywordsAndContext
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
/**
* Fallback to retrieve a core context and keyword proposals when no collector is available. Runs
* code completion on the cu and collects keyword proposals. {@link #fKeywordProposals} is non-
* <code>null</code> after this call.
*
* @since 3.3
*/
private void computeKeywordsAndContext() {
ICompilationUnit cu = getCompilationUnit();
if (cu == null) {
if (fKeywordProposals == null) fKeywordProposals = new IJavaCompletionProposal[0];
return;
}
CompletionProposalCollector collector = new CompletionProposalCollector(cu, true);
collector.setIgnored(CompletionProposal.KEYWORD, false);
try {
cu.codeComplete(getInvocationOffset(), collector);
if (fCoreContext == null) fCoreContext = collector.getContext();
if (fKeywordProposals == null) fKeywordProposals = collector.getKeywordCompletionProposals();
if (fLabelProvider == null) fLabelProvider = collector.getLabelProvider();
} catch (JavaModelException x) {
if (!x.isDoesNotExist()
|| cu.getJavaProject() == null
|| cu.getJavaProject().isOnClasspath(cu)) JavaPlugin.log(x);
if (fKeywordProposals == null) fKeywordProposals = new IJavaCompletionProposal[0];
}
}
示例10: Autocomplete
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
private List<AutocompleteResponse.Completion> Autocomplete(ITypeRoot cu, int cursorPosition) throws JavaModelException
{
final List<AutocompleteResponse.Completion> proposals = new ArrayList<AutocompleteResponse.Completion>();
cu.codeComplete(cursorPosition, new CompletionRequestor()
{
@Override
public void accept(CompletionProposal proposal) {
try
{
System.out.println(proposal.toString());
proposals.add(translateToCompletion(proposal));
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
return proposals;
}
示例11: getLength
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
/**
* Returns the replacement length of a given completion proposal. The replacement length is
* usually the difference between the return values of <code>proposal.getReplaceEnd</code> and
* <code>proposal.getReplaceStart</code>, but this behavior may be overridden by calling {@link
* #setReplacementLength(int)}.
*
* @param proposal the completion proposal to get the replacement length for
* @return the replacement length for <code>proposal</code>
*/
protected final int getLength(CompletionProposal proposal) {
int start = proposal.getReplaceStart();
int end = proposal.getReplaceEnd();
int length;
if (fUserReplacementLength == -1) {
length = end - start;
} else {
length = fUserReplacementLength;
// extend length to begin at start
int behindCompletion = proposal.getCompletionLocation() + 1;
if (start < behindCompletion) {
length += behindCompletion - start;
}
}
return length;
}
示例12: createAnnotationAttributeReferenceProposal
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
private IJavaCompletionProposal createAnnotationAttributeReferenceProposal(
CompletionProposal proposal) {
StyledString displayString = fLabelProvider.createLabelWithTypeAndDeclaration(proposal);
ImageDescriptor descriptor = fLabelProvider.createMethodImageDescriptor(proposal);
String completion = String.valueOf(proposal.getCompletion());
JavaCompletionProposal javaProposal =
new JavaCompletionProposal(
completion,
proposal.getReplaceStart(),
getLength(proposal),
getImage(descriptor),
displayString,
computeRelevance(proposal));
if (fJavaProject != null)
javaProposal.setProposalInfo(new AnnotationAtttributeProposalInfo(fJavaProject, proposal));
return javaProposal;
}
示例13: CompilationUnitCompletion
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
/**
* Creates a compilation unit completion.
*
* @param unit the compilation unit, may be <code>null</code>.
*/
CompilationUnitCompletion(ICompilationUnit unit) {
reset(unit);
setIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, true);
setIgnored(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, true);
setIgnored(CompletionProposal.KEYWORD, true);
setIgnored(CompletionProposal.LABEL_REF, true);
setIgnored(CompletionProposal.METHOD_DECLARATION, true);
setIgnored(CompletionProposal.METHOD_NAME_REFERENCE, true);
setIgnored(CompletionProposal.METHOD_REF, true);
setIgnored(CompletionProposal.CONSTRUCTOR_INVOCATION, true);
setIgnored(CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER, true);
setIgnored(CompletionProposal.PACKAGE_REF, true);
setIgnored(CompletionProposal.POTENTIAL_METHOD_DECLARATION, true);
setIgnored(CompletionProposal.VARIABLE_DECLARATION, true);
setIgnored(CompletionProposal.TYPE_REF, true);
}
示例14: accept
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
@Override
public void accept(CompletionProposal proposal) {
String name = String.valueOf(proposal.getCompletion());
String signature = String.valueOf(proposal.getSignature());
switch (proposal.getKind()) {
case CompletionProposal.LOCAL_VARIABLE_REF:
// collect local variables
fLocalVariables.add(new Variable(name, signature));
break;
case CompletionProposal.FIELD_REF:
// collect local variables
fFields.add(new Variable(name, signature));
break;
default:
break;
}
}
示例15: ignoreAll
import org.eclipse.jdt.core.CompletionProposal; //导入依赖的package包/类
private void ignoreAll() {
int[] ignoredKinds = new int[] {
CompletionProposal.ANONYMOUS_CLASS_DECLARATION,
CompletionProposal.FIELD_REF, CompletionProposal.KEYWORD,
CompletionProposal.LABEL_REF, CompletionProposal.LOCAL_VARIABLE_REF,
CompletionProposal.METHOD_REF, CompletionProposal.METHOD_DECLARATION,
CompletionProposal.PACKAGE_REF, CompletionProposal.TYPE_REF,
CompletionProposal.VARIABLE_DECLARATION,
CompletionProposal.POTENTIAL_METHOD_DECLARATION,
CompletionProposal.METHOD_NAME_REFERENCE,
CompletionProposal.ANNOTATION_ATTRIBUTE_REF,
CompletionProposal.JAVADOC_FIELD_REF,
CompletionProposal.JAVADOC_METHOD_REF,
CompletionProposal.JAVADOC_TYPE_REF,
CompletionProposal.JAVADOC_VALUE_REF,
CompletionProposal.JAVADOC_PARAM_REF,
CompletionProposal.JAVADOC_BLOCK_TAG,
CompletionProposal.JAVADOC_INLINE_TAG, CompletionProposal.FIELD_IMPORT,
CompletionProposal.METHOD_IMPORT, CompletionProposal.TYPE_IMPORT};
for (int kind : ignoredKinds) {
setIgnored(kind, true);
}
}