List of usage examples for org.eclipse.jdt.core CompletionProposal getReplaceStart
public int getReplaceStart()
From source file:com.microsoft.javapkgsrv.JavaParser.java
License:MIT License
private AutocompleteResponse.Completion translateToCompletion(CompletionProposal proposal) { AutocompleteResponse.Completion.Builder builder = AutocompleteResponse.Completion.newBuilder() .setKind(AutocompleteResponse.Completion.CompletionKind.valueOf(proposal.getKind())) .setIsConstructor(proposal.isConstructor()) .setCompletionText(String.copyValueOf(proposal.getCompletion())).setFlags(proposal.getFlags()) .setRelevance(proposal.getRelevance()).setReplaceStart(proposal.getReplaceStart()) .setReplaceEnd(proposal.getReplaceEnd()); char[] sig = proposal.getSignature(); if (sig != null) { if (proposal.getKind() == CompletionProposal.METHOD_REF || proposal.getKind() == CompletionProposal.JAVADOC_METHOD_REF) builder.setSignature(new String(Signature.toCharArray(sig, proposal.getName(), null, false, true))); else/*from w ww . jav a 2 s . com*/ builder.setSignature(new String(Signature.toCharArray(sig))); } char[] name = proposal.getName(); if (name == null) builder.setName(builder.getCompletionText()); else builder.setName(String.copyValueOf(name)); return builder.build(); }
From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java
License:Open Source License
/********************************************************************************/ static void outputCompletion(CompletionProposal cp, IvyXmlWriter xw) { xw.begin("COMPLETION"); fieldValue(xw, "ACCESSIBILITY", cp.getAccessibility(), accessibility_types); if (cp.isConstructor()) xw.field("CONSTRUCTOR", true); xw.field("TEXT", cp.getCompletion()); xw.field("INDEX", cp.getCompletionLocation()); xw.field("DECLKEY", cp.getDeclarationKey()); switch (cp.getKind()) { case CompletionProposal.ANNOTATION_ATTRIBUTE_REF: case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: case CompletionProposal.FIELD_IMPORT: case CompletionProposal.FIELD_REF: case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.METHOD_IMPORT: case CompletionProposal.METHOD_REF: case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.METHOD_DECLARATION: case CompletionProposal.POTENTIAL_METHOD_DECLARATION: xw.field("DECLSIGN", cp.getDeclarationSignature()); break;/*from w w w .j a v a 2s . c o m*/ case CompletionProposal.PACKAGE_REF: case CompletionProposal.TYPE_IMPORT: case CompletionProposal.TYPE_REF: xw.field("DOTNAME", cp.getDeclarationSignature()); break; } fieldFlags(xw, "ACCESS", cp.getFlags(), access_flags); xw.field("FLAGS", cp.getFlags()); xw.field("KEY", cp.getKey()); xw.field("NAME", cp.getName()); xw.field("RELEVANCE", cp.getRelevance()); xw.field("REPLACE_START", cp.getReplaceStart()); xw.field("REPLACE_END", cp.getReplaceEnd()); xw.field("SIGNATURE", cp.getSignature()); xw.field("TOKEN_START", cp.getTokenStart()); xw.field("TOKEN_END", cp.getTokenEnd()); fieldValue(xw, "KIND", cp.getKind(), completion_types); if (cp instanceof ICompletionProposalExtension4) { ICompletionProposalExtension4 icp4 = (ICompletionProposalExtension4) cp; xw.field("AUTO", icp4.isAutoInsertable()); } if (CompletionFlags.isStaticImport(cp.getAdditionalFlags())) xw.field("STATICIMPORT", true); if (cp.getKind() == CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER || cp.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) { xw.field("RECEIVER_SIGN", cp.getReceiverSignature()); xw.field("RECEIVER_START", cp.getReceiverStart()); xw.field("RECEIVER_END", cp.getReceiverEnd()); } xw.field("RCVR", cp.getReceiverSignature()); xw.cdataElement("DESCRIPTION", cp.toString()); CompletionProposal[] rq = cp.getRequiredProposals(); if (rq != null) { xw.begin("REQUIRED"); for (CompletionProposal xcp : rq) outputCompletion(xcp, xw); xw.end("REQUIRED"); } xw.end("COMPLETION"); }
From source file:org.bonitasoft.studio.contract.ui.property.constraint.edit.editor.contentassist.ContractInputProposalsCodeVisitorSupport.java
License:Open Source License
private ICompletionProposal createProposalFor(final ContentAssistInvocationContext context, final CharSequence prefix, final ContractInput input) { final String name = input.getName(); final CompletionProposal proposal = CompletionProposal.create(CompletionProposal.FIELD_REF, context.getInvocationOffset()); proposal.setCompletion(name.substring(prefix.length()).toCharArray()); proposal.setName(name.toCharArray()); proposal.setFlags(Flags.AccPublic);//from w w w . j a v a 2 s . c o m proposal.setReplaceRange(context.getInvocationOffset(), context.getInvocationOffset()); final String completion = String.valueOf(proposal.getCompletion()); final int start = proposal.getReplaceStart(); final int end = proposal.getReplaceEnd(); final int length = end - start; final ContractInputLabelProvider labelProvider = new ContractInputLabelProvider(); final Image image = labelProvider.getImage(input); return new JavaCompletionProposal(completion, start, length, image, labelProvider.getStyledString(input), 100, false); }
From source file:org.bonitasoft.studio.groovy.ui.contentassist.VariablesCompletionProposalProvider.java
License:Open Source License
private JavaCompletionProposal getProposalFor(final ContentAssistInvocationContext context, final CompletionProposalLabelProvider fLabelProvider, final CharSequence prefix, final String name, final String typeName) { final CompletionProposal proposal = CompletionProposal.create(CompletionProposal.FIELD_REF, context.getInvocationOffset()); proposal.setCompletion(name.substring(prefix.length()).toCharArray()); proposal.setName(name.toCharArray()); proposal.setFlags(Flags.AccPublic);//w w w . ja va 2 s .c o m proposal.setReplaceRange(context.getInvocationOffset(), context.getInvocationOffset()); // Class type = BonitaSyntaxHighlighting.getTypeForKeyWord(keyWord) ; if (typeName != null) { proposal.setSignature(Signature.createTypeSignature(typeName, true).toCharArray()); } String completion = String.valueOf(proposal.getCompletion()); int start = proposal.getReplaceStart(); int end = proposal.getReplaceEnd(); int length = end - start; StyledString label = fLabelProvider.createStyledLabel(proposal); final Image image = JavaPlugin.getImageDescriptorRegistry() .get(fLabelProvider.createImageDescriptor(proposal)); return new JavaCompletionProposal(completion, start, length, image, label, 100, false); // final CompletionProposal proposal = CompletionProposal.create(CompletionProposal.FIELD_REF, context.getInvocationOffset()); // proposal.setCompletion(name.toCharArray()); // proposal.setName(name.toCharArray()); // proposal.setFlags(Flags.AccPublic); // proposal.setReplaceRange(context.getInvocationOffset() - prefix.length(), context.getInvocationOffset() + name.length() - prefix.length()); // if (typeName != null) { // proposal.setSignature(Signature.createTypeSignature(typeName, true).toCharArray()); // } // final String completion = String.valueOf(proposal.getCompletion()); // final int start = proposal.getReplaceStart(); // final int end = proposal.getReplaceEnd(); // final int length = end - start; // // final StyledString label = fLabelProvider.createStyledLabel(proposal); // // final BonitaConstantsCompletionProposal javaProposal = new BonitaConstantsCompletionProposal( // ((JavaContentAssistInvocationContext) context).getCompilationUnit(), completion, start, length, image, label, 1000, false, // (JavaContentAssistInvocationContext) context); // return javaProposal; }
From source file:org.codehaus.groovy.eclipse.codeassist.proposals.GroovyJavaFieldCompletionProposal.java
License:Apache License
public GroovyJavaFieldCompletionProposal(CompletionProposal proposal, Image image, StyledString displayString) { super(String.valueOf(proposal.getName()), proposal.getReplaceStart(), proposal.getReplaceEnd() - proposal.getReplaceStart(), image, displayString, proposal.getRelevance());/* w ww. j a v a2 s . c o m*/ this.proposal = proposal; this.setRelevance(proposal.getRelevance()); this.setTriggerCharacters(ProposalUtils.VAR_TRIGGER); }
From source file:org.eclipse.ajdt.internal.core.contentassist.ProposalRequestorWrapper.java
License:Open Source License
private void translateReplaceRange(CompletionProposal proposal) { int s = proposal.getReplaceStart(); int e = proposal.getReplaceEnd(); proposal.setReplaceRange(trans(s), trans(e)); /* AJDT 1.7 */ // translate all proposals contained in this one if (proposal instanceof InternalCompletionProposal) { InternalCompletionProposal internalProposal = (InternalCompletionProposal) proposal; if (internalProposal.getRequiredProposals() != null) { for (int i = 0; i < internalProposal.getRequiredProposals().length; i++) { translateReplaceRange(internalProposal.getRequiredProposals()[i]); }//from w w w . j a v a 2 s . co m } } }
From source file:org.eclipse.ajdt.ui.tests.editor.contentassist.Bug273691ContentAssist.java
License:Open Source License
public void testGenericContentAssist() throws Exception { MockCompletionRequestor requestor = new MockCompletionRequestor(); // bar is a generic type that extends Number int offset = cunitContents.indexOf("this.x") + "this.x".length(); cunit.codeComplete(offset, requestor, AJWorkingCopyOwner.INSTANCE); assertEquals("Should have 1 proposal, but found:\n" + requestor.toString(), 1, requestor.accepted.size()); CompletionProposal completionProposal = (CompletionProposal) requestor.accepted.get(0); assertEquals("Signature of proposal should have been the 'x1' field\n" + completionProposal, "x1", new String(completionProposal.getName())); assertEquals("Completion start is wrong", offset - "x".length(), completionProposal.getReplaceStart()); }
From source file:org.eclipse.ajdt.ui.tests.editor.contentassist.Bug280508ContentAssist.java
License:Open Source License
public void testAspectOfInClass() throws Exception { MockCompletionRequestor requestor = new MockCompletionRequestor(); int offset = cunitContents.indexOf("Aspect.a") + "Aspect.a".length(); cunit.codeComplete(offset, requestor, AJWorkingCopyOwner.INSTANCE); assertEquals("Should have 1 proposal, but found:\n" + requestor.toString(), 1, requestor.accepted.size()); CompletionProposal completionProposal = (CompletionProposal) requestor.accepted.get(0); assertEquals("Signature of proposal should have been the 'aspectOf()' method\n" + completionProposal, "aspectOf", new String(completionProposal.getName())); assertEquals("Completion start is wrong", offset - "a".length(), completionProposal.getReplaceStart()); }
From source file:org.eclipse.ajdt.ui.tests.editor.contentassist.Bug280508ContentAssist.java
License:Open Source License
public void testAspectOfTypeInClass() throws Exception { MockCompletionRequestor requestor = new MockCompletionRequestor(); int offset = cunitContents.indexOf("aspectOf().hh") + "aspectOf().hh".length(); cunit.codeComplete(offset, requestor, AJWorkingCopyOwner.INSTANCE); assertEquals("Should have 1 proposal, but found:\n" + requestor.toString(), 1, requestor.accepted.size()); CompletionProposal completionProposal = (CompletionProposal) requestor.accepted.get(0); assertEquals("Signature of proposal should have been the 'hhh' field\n" + completionProposal, "hhh", new String(completionProposal.getName())); assertEquals("Completion start is wrong", offset - "hh".length(), completionProposal.getReplaceStart()); }
From source file:org.eclipse.ajdt.ui.tests.editor.contentassist.Bug280508ContentAssist.java
License:Open Source License
public void testAspectOfInAspect() throws Exception { MockCompletionRequestor requestor = new MockCompletionRequestor(); int offset = ajcunitContents.indexOf("Aspect2.a") + "Aspect2.a".length(); ajcunit.codeComplete(offset, requestor, AJWorkingCopyOwner.INSTANCE); assertEquals("Should have 1 proposal, but found:\n" + requestor.toString(), 1, requestor.accepted.size()); CompletionProposal completionProposal = (CompletionProposal) requestor.accepted.get(0); assertEquals("Signature of proposal should have been the 'aspectOf()' method\n" + completionProposal, "aspectOf", new String(completionProposal.getName())); assertEquals("Completion start is wrong", offset - "a".length(), completionProposal.getReplaceStart()); }