本文整理汇总了Java中org.eclipse.jdt.core.CompletionProposal.getReplaceStart方法的典型用法代码示例。如果您正苦于以下问题:Java CompletionProposal.getReplaceStart方法的具体用法?Java CompletionProposal.getReplaceStart怎么用?Java CompletionProposal.getReplaceStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.CompletionProposal
的用法示例。
在下文中一共展示了CompletionProposal.getReplaceStart方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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;
}
示例4: 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;
}
示例5: createFieldProposal
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
private IJavaCompletionProposal createFieldProposal(CompletionProposal proposal) {
String completion = String.valueOf(proposal.getCompletion());
int start = proposal.getReplaceStart();
int length = getLength(proposal);
StyledString label = fLabelProvider.createStyledLabel(proposal);
Image image = getImage(fLabelProvider.createFieldImageDescriptor(proposal));
int relevance = computeRelevance(proposal);
JavaCompletionProposal javaProposal =
new JavaCompletionProposal(
completion,
start,
length,
image,
label,
relevance,
getContext().isInJavadoc(),
getInvocationContext());
if (fJavaProject != null)
javaProposal.setProposalInfo(new FieldProposalInfo(fJavaProject, proposal));
javaProposal.setTriggerCharacters(VAR_TRIGGER);
return javaProposal;
}
示例6: acceptPotentialMethodDeclaration
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
private void acceptPotentialMethodDeclaration(CompletionProposal proposal) {
try {
IJavaElement enclosingElement = null;
// if (getContext().isExtended()) {
// enclosingElement= getContext().getEnclosingElement();
// } else if (fCompilationUnit != null) {
// kept for backward compatibility: CU is not reconciled at this moment, information is
// missing (bug 70005)
enclosingElement = fCompilationUnit.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 = computeRelevance(proposal);
GetterSetterCompletionProposal.evaluateProposals(
type,
prefix,
completionStart,
completionEnd - completionStart,
relevance + 2,
fSuggestedMethodNames,
fJavaProposals);
MethodDeclarationCompletionProposal.evaluateProposals(
type,
prefix,
completionStart,
completionEnd - completionStart,
relevance,
fSuggestedMethodNames,
fJavaProposals);
}
} catch (CoreException e) {
JavaPlugin.log(e);
}
}
示例7: createAnonymousTypeProposal
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
private IJavaCompletionProposal createAnonymousTypeProposal(
CompletionProposal proposal, JavaContentAssistInvocationContext invocationContext) {
if (fCompilationUnit == null || fJavaProject == null) return null;
char[] declarationKey = proposal.getDeclarationKey();
if (declarationKey == null) return null;
try {
IJavaElement element = fJavaProject.findElement(new String(declarationKey), null);
if (!(element instanceof IType)) return null;
IType type = (IType) element;
String completion = String.valueOf(proposal.getCompletion());
int start = proposal.getReplaceStart();
int length = getLength(proposal);
int relevance = computeRelevance(proposal);
StyledString label = fLabelProvider.createAnonymousTypeLabel(proposal);
JavaCompletionProposal javaProposal =
new AnonymousTypeCompletionProposal(
fJavaProject,
fCompilationUnit,
invocationContext,
start,
length,
completion,
label,
String.valueOf(proposal.getDeclarationSignature()),
type,
relevance);
javaProposal.setProposalInfo(new AnonymousTypeProposalInfo(fJavaProject, proposal));
return javaProposal;
} catch (JavaModelException e) {
return null;
}
}
示例8: createFieldWithCastedReceiverProposal
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
/**
* Creates the Java completion proposal for the JDT Core {@link
* org.eclipse.jdt.core.CompletionProposal#FIELD_REF_WITH_CASTED_RECEIVER} proposal.
*
* @param proposal the JDT Core proposal
* @return the Java completion proposal
* @since 3.4
*/
private IJavaCompletionProposal createFieldWithCastedReceiverProposal(
CompletionProposal proposal) {
String completion = String.valueOf(proposal.getCompletion());
completion =
CodeFormatterUtil.format(
CodeFormatter.K_EXPRESSION, completion, 0, "\n", fJavaProject); // $NON-NLS-1$
int start = proposal.getReplaceStart();
int length = getLength(proposal);
StyledString label = fLabelProvider.createStyledLabel(proposal);
Image image = getImage(fLabelProvider.createFieldImageDescriptor(proposal));
int relevance = computeRelevance(proposal);
JavaCompletionProposal javaProposal =
new JavaFieldWithCastedReceiverCompletionProposal(
completion,
start,
length,
image,
label,
relevance,
getContext().isInJavadoc(),
getInvocationContext(),
proposal);
if (fJavaProject != null)
javaProposal.setProposalInfo(new FieldProposalInfo(fJavaProject, proposal));
javaProposal.setTriggerCharacters(VAR_TRIGGER);
return javaProposal;
}
示例9: createKeywordProposal
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
private IJavaCompletionProposal createKeywordProposal(CompletionProposal proposal) {
String completion = String.valueOf(proposal.getCompletion());
int start = proposal.getReplaceStart();
int length = getLength(proposal);
StyledString label = fLabelProvider.createSimpleLabel(proposal);
int relevance = computeRelevance(proposal);
return new JavaCompletionProposal(completion, start, length, null, label, relevance);
}
示例10: createLabelProposal
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
private IJavaCompletionProposal createLabelProposal(CompletionProposal proposal) {
String completion = String.valueOf(proposal.getCompletion());
int start = proposal.getReplaceStart();
int length = getLength(proposal);
StyledString label = fLabelProvider.createSimpleLabel(proposal);
int relevance = computeRelevance(proposal);
return new JavaCompletionProposal(completion, start, length, null, label, relevance);
}
示例11: createLocalVariableProposal
import org.eclipse.jdt.core.CompletionProposal; //导入方法依赖的package包/类
private IJavaCompletionProposal createLocalVariableProposal(CompletionProposal proposal) {
String completion = String.valueOf(proposal.getCompletion());
int start = proposal.getReplaceStart();
int length = getLength(proposal);
Image image = getImage(fLabelProvider.createLocalImageDescriptor(proposal));
StyledString label = fLabelProvider.createSimpleLabelWithType(proposal);
int relevance = computeRelevance(proposal);
final JavaCompletionProposal javaProposal =
new JavaCompletionProposal(completion, start, length, image, label, relevance);
javaProposal.setTriggerCharacters(VAR_TRIGGER);
return javaProposal;
}