List of usage examples for org.eclipse.jdt.core CompletionProposal ANONYMOUS_CLASS_DECLARATION
int ANONYMOUS_CLASS_DECLARATION
To view the source code for org.eclipse.jdt.core CompletionProposal ANONYMOUS_CLASS_DECLARATION.
Click Source Link
From source file:com.google.gwt.eclipse.core.editors.java.contentassist.JsniCompletionProposalCollector.java
License:Open Source License
private JsniCompletionProposalCollector(ICompilationUnit cu, int refOffset, int refLength) { super(cu);//from ww w . j a v a2 s. c o m this.refOffset = refOffset; this.refLength = refLength; setIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, true); }
From source file:com.google.gwt.eclipse.core.uibinder.contentassist.computers.ProposalGeneratingCompletionRequestor.java
License:Open Source License
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);//from w w w. jav a 2 s. c om } }
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;/* ww w. ja va2 s . 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:iot.jcypher.eclipse.JCypherCompletionProposalComputer.java
License:Apache License
private List<ICompletionProposal> internalComputeCompletionProposals(int offset, JavaContentAssistInvocationContext context) { ICompilationUnit unit = context.getCompilationUnit(); if (unit == null) return Collections.emptyList(); ITextViewer viewer = context.getViewer(); CompletionProposalCollector collector = createCollector(context); collector.setInvocationContext(context); collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true);//from w w w. j ava2 s. c om collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.TYPE_REF, CompletionProposal.TYPE_REF, true); try { Point selection = viewer.getSelectedRange(); if (selection.y > 0) collector.setReplacementLength(selection.y); unit.codeComplete(offset, collector, fTimeoutProgressMonitor); } catch (OperationCanceledException x) { fErrorMessage = "Code assist took too long and is incomplete. Please close the list and type more characters"; } catch (JavaModelException x) { Shell shell = viewer.getTextWidget().getShell(); if (x.isDoesNotExist() && !unit.getJavaProject().isOnClasspath(unit)) MessageDialog.openInformation(shell, "Cannot Perform Operation", "The compilation unit is not on the build path of a Java project."); else ErrorDialog.openError(shell, "Error Accessing Compilation Unit", "Cannot access compilation unit", x.getStatus()); } ICompletionProposal[] javaProposals = collector.getJavaCompletionProposals(); List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(Arrays.asList(javaProposals)); if (proposals.size() == 0) { String error = collector.getErrorMessage(); if (error.length() > 0) fErrorMessage = error; } return buildJCypherProposals(proposals); }
From source file:org.eclim.plugin.jdt.command.complete.CompletionProposalCollector.java
License:Open Source License
public void accept(CompletionProposal proposal) { try {//from w ww. j a v a 2 s . c o m if (isFiltered(proposal)) { return; } if (proposal.getKind() != CompletionProposal.POTENTIAL_METHOD_DECLARATION) { switch (proposal.getKind()) { case CompletionProposal.KEYWORD: case CompletionProposal.PACKAGE_REF: case CompletionProposal.TYPE_REF: case CompletionProposal.FIELD_REF: case CompletionProposal.METHOD_REF: case CompletionProposal.METHOD_NAME_REFERENCE: case CompletionProposal.METHOD_DECLARATION: case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: case CompletionProposal.LABEL_REF: case CompletionProposal.LOCAL_VARIABLE_REF: case CompletionProposal.VARIABLE_DECLARATION: case CompletionProposal.ANNOTATION_ATTRIBUTE_REF: case CompletionProposal.POTENTIAL_METHOD_DECLARATION: proposals.add(proposal); super.accept(proposal); break; default: // do nothing } } } catch (IllegalArgumentException e) { // all signature processing method may throw IAEs // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84657 // don't abort, but log and show all the valid proposals JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "Exception when processing proposal for: " + String.valueOf(proposal.getCompletion()), e)); } }
From source file:org.eclipse.flux.jdt.services.CompletionProposalDescriptionProvider.java
License:Open Source License
/** * 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./* w ww . ja v a2s . co m*/ * <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 } }
From source file:org.eclipse.flux.jdt.services.CompletionProposalDescriptionProvider.java
License:Open Source License
/** * Creates a display label with styles for a given <code>CompletionProposal</code>. * * @param proposal the completion proposal to create the display label for * @return the display label for <code>proposal</code> * * @since 3.4//from w w w. j a va 2s . co m */ public StringBuilder createDescription(CompletionProposal proposal) { switch (proposal.getKind()) { case CompletionProposal.METHOD_NAME_REFERENCE: case CompletionProposal.METHOD_REF: case CompletionProposal.CONSTRUCTOR_INVOCATION: case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.POTENTIAL_METHOD_DECLARATION: if (fContext != null && fContext.isInJavadoc()) return createJavadocMethodProposalLabel(proposal); return createMethodProposalLabel(proposal); case CompletionProposal.METHOD_DECLARATION: return createOverrideMethodProposalLabel(proposal); case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION: return createAnonymousTypeLabel(proposal); case CompletionProposal.TYPE_REF: return createTypeProposalLabel(proposal); case CompletionProposal.JAVADOC_TYPE_REF: return createJavadocTypeProposalLabel(proposal); case CompletionProposal.JAVADOC_FIELD_REF: case CompletionProposal.JAVADOC_VALUE_REF: case CompletionProposal.JAVADOC_BLOCK_TAG: case CompletionProposal.JAVADOC_INLINE_TAG: case CompletionProposal.JAVADOC_PARAM_REF: return createJavadocSimpleProposalLabel(proposal); case CompletionProposal.JAVADOC_METHOD_REF: return createJavadocMethodProposalLabel(proposal); case CompletionProposal.PACKAGE_REF: return createPackageProposalLabel(proposal); case CompletionProposal.ANNOTATION_ATTRIBUTE_REF: case CompletionProposal.FIELD_REF: case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER: return createLabelWithTypeAndDeclaration(proposal); case CompletionProposal.LOCAL_VARIABLE_REF: case CompletionProposal.VARIABLE_DECLARATION: return createSimpleLabelWithType(proposal); case CompletionProposal.KEYWORD: case CompletionProposal.LABEL_REF: return createSimpleLabel(proposal); default: Assert.isTrue(false); return null; } }
From source file:org.eclipse.flux.jdt.services.ContentAssistService.java
License:Open Source License
protected JSONArray computeContentAssist(String username, String resourcePath, int offset, String prefix) throws JSONException { final List<CompletionProposal> proposals = new ArrayList<CompletionProposal>(); final CompletionContext[] completionContextParam = new CompletionContext[] { null }; ICompilationUnit liveEditUnit = liveEditUnits.getLiveEditUnit(username, resourcePath); try {/* www .ja va2 s . c o m*/ if (liveEditUnit != null) { CompletionRequestor collector = new CompletionRequestor() { @Override public void accept(CompletionProposal proposal) { proposals.add(proposal); } @Override public void acceptContext(CompletionContext context) { super.acceptContext(context); completionContextParam[0] = context; } }; // Allow completions for unresolved types - since 3.3 collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true); collector.setAllowsRequiredProposals(CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, CompletionProposal.TYPE_REF, true); collector.setAllowsRequiredProposals(CompletionProposal.TYPE_REF, CompletionProposal.TYPE_REF, true); liveEditUnit.codeComplete(offset, collector, new NullProgressMonitor()); } } catch (JavaModelException e) { e.printStackTrace(); } List<JSONObject> jsonProposals = new ArrayList<JSONObject>(proposals.size()); CompletionContext completionContext = completionContextParam[0]; for (CompletionProposal proposal : proposals) { JSONObject jsonDescription = getDescription(proposal, completionContext); ProposalReplcamentInfo replacementInfo = new CompletionProposalReplacementProvider(liveEditUnit, proposal, completionContext, offset, prefix).createReplacement(); JSONObject jsonProposal = new JSONObject(); jsonProposal.put("description", jsonDescription); jsonProposal.put("proposal", replacementInfo.replacement); int initOffset = offset - prefix.length(); if (replacementInfo.extraChanges != null) { jsonProposal.put("additionalEdits", Utils.editsToJsonArray(replacementInfo.extraChanges)); initOffset += Utils.getOffsetAdjustment(replacementInfo.extraChanges, initOffset); } if (replacementInfo.positions != null && !replacementInfo.positions.isEmpty()) { jsonProposal.put("positions", getPositions(replacementInfo.positions, initOffset)); } jsonProposal.put("escapePosition", initOffset + replacementInfo.replacement.length()); jsonProposal.put("style", "attributedString"); jsonProposal.put("replace", true); jsonProposal.put("relevance", proposal.getRelevance()); jsonProposals.add(jsonProposal); } Collections.sort(jsonProposals, new Comparator<JSONObject>() { @Override public int compare(JSONObject o1, JSONObject o2) { try { int diff = o2.getInt("relevance") - o1.getInt("relevance"); if (diff == 0) { JSONArray nameDescription1 = o1.getJSONObject("description").getJSONArray("segments"); JSONArray nameDescription2 = o2.getJSONObject("description").getJSONArray("segments"); StringBuilder nameBuffer1 = new StringBuilder(); for (int i = 0; i < nameDescription1.length(); i++) { nameBuffer1.append(nameDescription1.getJSONObject(i).getString("value")); } StringBuilder nameBuffer2 = new StringBuilder(); for (int i = 0; i < nameDescription2.length(); i++) { nameBuffer2.append(nameDescription2.getJSONObject(i).getString("value")); } return nameBuffer1.toString().compareTo(nameBuffer2.toString()); } else { return diff; } } catch (JSONException e) { return -1; } } }); return new JSONArray(jsonProposals); }
From source file:org.eclipse.jst.jsp.ui.internal.contentassist.JSPProposalCollector.java
License:Open Source License
/** * Cacluates the where the cursor should be after applying this proposal. * eg. method(|) if the method proposal chosen had params. * //ww w . ja v a2 s .c om * @param proposal * @param completion * @param currentCursorOffset * @return */ private int calculatePositionAfter(CompletionProposal proposal, String completion, int currentCursorOffset) { // calculate cursor position after // https://bugs.eclipse.org/bugs/show_bug.cgi?id=118398 //int positionAfter = currentCursorOffset+completion.length(); int positionAfter = completion.length(); int kind = proposal.getKind(); // may need better logic here... // put cursor inside parenthesis if there's params // only checking for any kind of declaration if (kind == CompletionProposal.ANONYMOUS_CLASS_DECLARATION || kind == CompletionProposal.METHOD_DECLARATION || kind == CompletionProposal.POTENTIAL_METHOD_DECLARATION || kind == CompletionProposal.METHOD_REF) { String[] params = Signature.getParameterTypes(String.valueOf(proposal.getSignature())); if (completion.length() > 0 && params.length > 0) positionAfter--; } return positionAfter; }
From source file:org.eclipse.objectteams.otdt.tests.model.CompletionTestsRequestor2.java
License:Open Source License
public void allowAllRequiredProposals() { for (int i = CompletionProposal.ANONYMOUS_CLASS_DECLARATION; i <= CompletionProposal.TYPE_IMPORT; i++) { for (int j = CompletionProposal.ANONYMOUS_CLASS_DECLARATION; j <= CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER; j++) { this.setAllowsRequiredProposals(i, j, true); }//w w w .j ava 2 s .c om } }