本文整理汇总了Java中org.eclipse.jdt.core.CompletionProposal.getRequiredProposals方法的典型用法代码示例。如果您正苦于以下问题:Java CompletionProposal.getRequiredProposals方法的具体用法?Java CompletionProposal.getRequiredProposals怎么用?Java CompletionProposal.getRequiredProposals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.CompletionProposal
的用法示例。
在下文中一共展示了CompletionProposal.getRequiredProposals方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: createAnonymousTypeLabel
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
StyledString createAnonymousTypeLabel(CompletionProposal proposal) {
char[] declaringTypeSignature = proposal.getDeclarationSignature();
declaringTypeSignature = Signature.getTypeErasure(declaringTypeSignature);
StyledString buffer = new StyledString();
buffer.append(Signature.getSignatureSimpleName(declaringTypeSignature));
buffer.append('(');
appendUnboundedParameterList(buffer, proposal);
buffer.append(')');
buffer.append(" "); // $NON-NLS-1$
buffer.append(JavaTextMessages.ResultCollector_anonymous_type);
if (proposal.getRequiredProposals() != null) {
char[] signatureQualifier = Signature.getSignatureQualifier(declaringTypeSignature);
if (signatureQualifier.length > 0) {
buffer.append(JavaElementLabels.CONCAT_STRING, StyledString.QUALIFIER_STYLER);
buffer.append(signatureQualifier, StyledString.QUALIFIER_STYLER);
}
}
return Strings.markJavaElementLabelLTR(buffer);
}
示例3: createMethodProposalLabel
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
/**
* Updates a display label for the given method proposal to item. The display label
* consists of:
* <ul>
* <li>the method name</li>
* <li>the parameter list (see {@link #createParameterList(CompletionProposal)})</li>
* <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})</li>
* <li>the raw simple name of the declaring type</li>
* </ul>
* <p>
* Examples:
* For the <code>get(int)</code> method of a variable of type <code>List<? extends Number></code>, the following
* display name is returned: <code>get(int index) Number - List</code>.<br>
* For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the following
* display name is returned: <code>add(Number o) void - List</code>.<br>
* </p>
*
* @param methodProposal the method proposal to display
* @param item to update
*/
private void createMethodProposalLabel(CompletionProposal methodProposal, CompletionItem item) {
StringBuilder description = this.createMethodProposalDescription(methodProposal);
item.setLabel(description.toString());
item.setInsertText(String.valueOf(methodProposal.getName()));
// declaring type
StringBuilder typeInfo = new StringBuilder();
String declaringType= extractDeclaringTypeFQN(methodProposal);
if (methodProposal.getRequiredProposals() != null) {
String qualifier= Signature.getQualifier(declaringType);
if (qualifier.length() > 0) {
typeInfo.append(qualifier);
typeInfo.append('.');
}
}
declaringType= Signature.getSimpleName(declaringType);
typeInfo.append(declaringType);
item.setDetail(typeInfo.toString());
setSignature(item, String.valueOf(methodProposal.getSignature()));
setDeclarationSignature(item, String.valueOf(methodProposal.getDeclarationSignature()));
setName(item, String.valueOf(methodProposal.getName()));
}
示例4: createLabelWithTypeAndDeclaration
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
private void createLabelWithTypeAndDeclaration(CompletionProposal proposal, CompletionItem item) {
char[] name= proposal.getCompletion();
if (!isThisPrefix(name)) {
name= proposal.getName();
}
StringBuilder buf= new StringBuilder();
buf.append(name);
item.setInsertText(buf.toString());
char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature());
if (typeName.length > 0) {
buf.append(VAR_TYPE_SEPARATOR);
buf.append(typeName);
}
item.setLabel(buf.toString());
char[] declaration= proposal.getDeclarationSignature();
if (declaration != null) {
setDeclarationSignature(item, String.valueOf(declaration));
StringBuilder declBuf = new StringBuilder();
declaration= Signature.getSignatureSimpleName(declaration);
if (declaration.length > 0) {
if (proposal.getRequiredProposals() != null) {
String declaringType= extractDeclaringTypeFQN(proposal);
String qualifier= Signature.getQualifier(declaringType);
if (qualifier.length() > 0) {
declBuf.append(qualifier);
declBuf.append('.');
}
}
declBuf.append(declaration);
item.setDetail(declBuf.toString());
}
}
setName(item,String.valueOf(name));
}
示例5: createMethodProposalLabel
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
/**
* Creates a display label for the given method proposal. The display label consists of:
*
* <ul>
* <li>the method name
* <li>the parameter list (see {@link
* #createParameterList(org.eclipse.jdt.core.CompletionProposal)})
* <li>the upper bound of the return type (see {@link SignatureUtil#getUpperBound(String)})
* <li>the raw simple name of the declaring type
* </ul>
*
* <p>Examples: For the <code>get(int)</code> method of a variable of type <code>
* List<? extends Number></code>, the following display name is returned: <code>
* get(int index) Number - List</code>.<br>
* For the <code>add(E)</code> method of a variable of type <code>List<? super Number></code>, the
* following display name is returned: <code>add(Number o) void - List</code>.<br>
*
* @param methodProposal the method proposal to display
* @return the display label for the given method proposal
*/
StyledString createMethodProposalLabel(CompletionProposal methodProposal) {
StyledString nameBuffer = new StyledString();
// method name
nameBuffer.append(methodProposal.getName());
// parameters
nameBuffer.append('(');
appendUnboundedParameterList(nameBuffer, methodProposal);
nameBuffer.append(')');
// return type
if (!methodProposal.isConstructor()) {
// TODO remove SignatureUtil.fix83600 call when bugs are fixed
char[] returnType =
createTypeDisplayName(
SignatureUtil.getUpperBound(
Signature.getReturnType(SignatureUtil.fix83600(methodProposal.getSignature()))));
nameBuffer.append(RETURN_TYPE_SEPARATOR);
nameBuffer.append(returnType);
}
// declaring type
nameBuffer.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER);
String declaringType = extractDeclaringTypeFQN(methodProposal);
if (methodProposal.getRequiredProposals() != null) {
String qualifier = Signature.getQualifier(declaringType);
if (qualifier.length() > 0) {
nameBuffer.append(qualifier, StyledString.QUALIFIER_STYLER);
nameBuffer.append('.', StyledString.QUALIFIER_STYLER);
}
}
declaringType = Signature.getSimpleName(declaringType);
nameBuffer.append(declaringType, StyledString.QUALIFIER_STYLER);
return Strings.markJavaElementLabelLTR(nameBuffer);
}
示例6: createLabelWithTypeAndDeclaration
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
StyledString createLabelWithTypeAndDeclaration(CompletionProposal proposal) {
char[] name = proposal.getCompletion();
if (!isThisPrefix(name)) name = proposal.getName();
StyledString buf = new StyledString();
buf.append(name);
char[] typeName = Signature.getSignatureSimpleName(proposal.getSignature());
if (typeName.length > 0) {
buf.append(VAR_TYPE_SEPARATOR);
buf.append(typeName);
}
char[] declaration = proposal.getDeclarationSignature();
if (declaration != null) {
declaration = Signature.getSignatureSimpleName(declaration);
if (declaration.length > 0) {
buf.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER);
if (proposal.getRequiredProposals() != null) {
String declaringType = extractDeclaringTypeFQN(proposal);
String qualifier = Signature.getQualifier(declaringType);
if (qualifier.length() > 0) {
buf.append(qualifier, StyledString.QUALIFIER_STYLER);
buf.append('.', StyledString.QUALIFIER_STYLER);
}
}
buf.append(declaration, StyledString.QUALIFIER_STYLER);
}
}
return Strings.markJavaElementLabelLTR(buf);
}
示例7: updateReplacement
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
/**
* Updates the replacement and any additional replacement for the given item.
*
* @param proposal
* @param item
* @param trigger
*/
public void updateReplacement(CompletionProposal proposal, CompletionItem item, char trigger) {
// reset importRewrite
this.importRewrite = TypeProposalUtils.createImportRewrite(compilationUnit);
List<org.eclipse.lsp4j.TextEdit> additionalTextEdits = new ArrayList<>();
StringBuilder completionBuffer = new StringBuilder();
Range range = null;
if (isSupportingRequiredProposals(proposal)) {
CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
if (requiredProposals != null) {
for (CompletionProposal requiredProposal : requiredProposals) {
switch(requiredProposal.getKind()) {
case CompletionProposal.TYPE_IMPORT:
case CompletionProposal.METHOD_IMPORT:
case CompletionProposal.FIELD_IMPORT:
appendImportProposal(completionBuffer, requiredProposal, proposal.getKind());
break;
case CompletionProposal.TYPE_REF:
org.eclipse.lsp4j.TextEdit edit = toRequiredTypeEdit(requiredProposal, trigger, proposal.canUseDiamond(context));
if (proposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION || proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION
|| proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_DECLARATION) {
completionBuffer.append(edit.getNewText());
range = edit.getRange();
} else {
additionalTextEdits.add(edit);
}
break;
default:
/*
* In 3.3 we only support the above required proposals, see
* CompletionProposal#getRequiredProposals()
*/
Assert.isTrue(false);
}
}
}
}
if (range == null) {
range = toReplacementRange(proposal);
}
if(proposal.getKind() == CompletionProposal.METHOD_DECLARATION){
appendMethodOverrideReplacement(completionBuffer, proposal);
} else if (proposal.getKind() == CompletionProposal.POTENTIAL_METHOD_DECLARATION && proposal instanceof GetterSetterCompletionProposal) {
appendMethodPotentialReplacement(completionBuffer, (GetterSetterCompletionProposal) proposal);
} else if (proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION || proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_DECLARATION) {
appendAnonymousClass(completionBuffer, proposal, range);
} else {
appendReplacementString(completionBuffer, proposal);
}
//select insertTextFormat.
if( client.isCompletionSnippetsSupported()){
item.setInsertTextFormat(InsertTextFormat.Snippet);
}else{
item.setInsertTextFormat(InsertTextFormat.PlainText);
}
String text = completionBuffer.toString();
if(range != null){
item.setTextEdit(new org.eclipse.lsp4j.TextEdit(range, text));
}else{
// fallback
item.setInsertText(text);
}
addImports(additionalTextEdits);
if(!additionalTextEdits.isEmpty()){
item.setAdditionalTextEdits(additionalTextEdits);
}
}
示例8: getStaticImportFavorites
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
public static String[] getStaticImportFavorites(ICompilationUnit cu, final String elementName, boolean isMethod, String[] favorites) throws JavaModelException {
StringBuffer dummyCU= new StringBuffer();
String packName= cu.getParent().getElementName();
IType type= cu.findPrimaryType();
if (type == null) {
return new String[0];
}
if (packName.length() > 0) {
dummyCU.append("package ").append(packName).append(';'); //$NON-NLS-1$
}
dummyCU.append("public class ").append(type.getElementName()).append("{\n static {\n").append(elementName); // static initializer //$NON-NLS-1$//$NON-NLS-2$
int offset= dummyCU.length();
dummyCU.append("\n}\n }"); //$NON-NLS-1$
ICompilationUnit newCU= null;
try {
newCU= cu.getWorkingCopy(null);
newCU.getBuffer().setContents(dummyCU.toString());
final HashSet<String> result= new HashSet<>();
CompletionRequestor requestor= new CompletionRequestor(true) {
@Override
public void accept(CompletionProposal proposal) {
if (elementName.equals(new String(proposal.getName()))) {
CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
for (int i= 0; i < requiredProposals.length; i++) {
CompletionProposal curr= requiredProposals[i];
if (curr.getKind() == CompletionProposal.METHOD_IMPORT || curr.getKind() == CompletionProposal.FIELD_IMPORT) {
result.add(JavaModelUtil.concatenateName(Signature.toCharArray(curr.getDeclarationSignature()), curr.getName()));
}
}
}
}
};
if (isMethod) {
requestor.setIgnored(CompletionProposal.METHOD_REF, false);
requestor.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true);
} else {
requestor.setIgnored(CompletionProposal.FIELD_REF, false);
requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true);
}
requestor.setFavoriteReferences(favorites);
newCU.codeComplete(offset, requestor);
return result.toArray(new String[result.size()]);
} finally {
if (newCU != null) {
newCU.discardWorkingCopy();
}
}
}
示例9: decorateImageDescriptor
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
/**
* Returns a version of <code>descriptor</code> decorated according to the passed <code>modifier
* </code> flags.
*
* @param descriptor the image descriptor to decorate
* @param proposal the proposal
* @return an image descriptor for a method proposal
* @see org.eclipse.jdt.core.Flags
*/
private ImageDescriptor decorateImageDescriptor(
ImageDescriptor descriptor, CompletionProposal proposal) {
int adornments = 0;
int flags = proposal.getFlags();
int kind = proposal.getKind();
boolean deprecated = Flags.isDeprecated(flags);
if (!deprecated) {
CompletionProposal[] requiredProposals = proposal.getRequiredProposals();
if (requiredProposals != null) {
for (int i = 0; i < requiredProposals.length; i++) {
CompletionProposal requiredProposal = requiredProposals[i];
if (requiredProposal.getKind() == CompletionProposal.TYPE_REF) {
deprecated |= Flags.isDeprecated(requiredProposal.getFlags());
}
}
}
}
if (deprecated) adornments |= JavaElementImageDescriptor.DEPRECATED;
if (kind == CompletionProposal.FIELD_REF
|| kind == CompletionProposal.METHOD_DECLARATION
|| kind == CompletionProposal.METHOD_NAME_REFERENCE
|| kind == CompletionProposal.METHOD_REF
|| kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
if (Flags.isStatic(flags)) adornments |= JavaElementImageDescriptor.STATIC;
if (kind == CompletionProposal.METHOD_DECLARATION
|| kind == CompletionProposal.METHOD_NAME_REFERENCE
|| kind == CompletionProposal.METHOD_REF
|| kind == CompletionProposal.CONSTRUCTOR_INVOCATION)
if (Flags.isSynchronized(flags)) adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
if (kind == CompletionProposal.METHOD_DECLARATION
|| kind == CompletionProposal.METHOD_NAME_REFERENCE
|| kind == CompletionProposal.METHOD_REF)
if (Flags.isDefaultMethod(flags)) adornments |= JavaElementImageDescriptor.DEFAULT_METHOD;
if (kind == CompletionProposal.ANNOTATION_ATTRIBUTE_REF)
if (Flags.isAnnnotationDefault(flags))
adornments |= JavaElementImageDescriptor.ANNOTATION_DEFAULT;
if (kind == CompletionProposal.TYPE_REF && Flags.isAbstract(flags) && !Flags.isInterface(flags))
adornments |= JavaElementImageDescriptor.ABSTRACT;
if (kind == CompletionProposal.FIELD_REF) {
if (Flags.isFinal(flags)) adornments |= JavaElementImageDescriptor.FINAL;
if (Flags.isTransient(flags)) adornments |= JavaElementImageDescriptor.TRANSIENT;
if (Flags.isVolatile(flags)) adornments |= JavaElementImageDescriptor.VOLATILE;
}
return new JavaElementImageDescriptor(
descriptor, adornments /*, JavaElementImageProvider.SMALL_SIZE*/);
}
示例10: getStaticImportFavorites
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
public static String[] getStaticImportFavorites(
ICompilationUnit cu, final String elementName, boolean isMethod, String[] favorites)
throws JavaModelException {
StringBuffer dummyCU = new StringBuffer();
String packName = cu.getParent().getElementName();
IType type = cu.findPrimaryType();
if (type == null) return new String[0];
if (packName.length() > 0) {
dummyCU.append("package ").append(packName).append(';'); // $NON-NLS-1$
}
dummyCU
.append("public class ")
.append(type.getElementName())
.append("{\n static {\n")
.append(elementName); // static initializer //$NON-NLS-1$//$NON-NLS-2$
int offset = dummyCU.length();
dummyCU.append("\n}\n }"); // $NON-NLS-1$
ICompilationUnit newCU = null;
try {
newCU = cu.getWorkingCopy(null);
newCU.getBuffer().setContents(dummyCU.toString());
final HashSet<String> result = new HashSet<String>();
CompletionRequestor requestor =
new CompletionRequestor(true) {
@Override
public void accept(CompletionProposal proposal) {
if (elementName.equals(new String(proposal.getName()))) {
CompletionProposal[] requiredProposals = proposal.getRequiredProposals();
for (int i = 0; i < requiredProposals.length; i++) {
CompletionProposal curr = requiredProposals[i];
if (curr.getKind() == CompletionProposal.METHOD_IMPORT
|| curr.getKind() == CompletionProposal.FIELD_IMPORT) {
result.add(
JavaModelUtil.concatenateName(
Signature.toCharArray(curr.getDeclarationSignature()), curr.getName()));
}
}
}
}
};
if (isMethod) {
requestor.setIgnored(CompletionProposal.METHOD_REF, false);
requestor.setAllowsRequiredProposals(
CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true);
} else {
requestor.setIgnored(CompletionProposal.FIELD_REF, false);
requestor.setAllowsRequiredProposals(
CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true);
}
requestor.setFavoriteReferences(favorites);
newCU.codeComplete(offset, requestor);
return result.toArray(new String[result.size()]);
} finally {
if (newCU != null) {
newCU.discardWorkingCopy();
}
}
}