List of usage examples for org.eclipse.jdt.core CompletionProposal getSignature
public char[] getSignature()
null
if none. From source file:at.bestsolution.fxide.jdt.editor.internal.MethodUtil.java
License:Open Source License
public MethodUtil(CompletionProposal proposal, IType type) { this.type = type; this.name = proposal.getName(); this.methodSignature = proposal.getSignature(); this.constructor = proposal.isConstructor(); this.declSignature = proposal.getDeclarationSignature(); }
From source file:at.bestsolution.javafx.ide.jdt.internal.JavaEditor.java
License:Open Source License
@Inject public JavaEditor(BorderPane pane, IEditorInput input) { editor = new SourceEditor(); pane.setCenter(editor);/*ww w .j av a2s . c om*/ IResourceFileInput fsInput = (IResourceFileInput) input; try { unit = ((ICompilationUnit) JavaCore.create(fsInput.getFile())) .getWorkingCopy(new FXWorkingCopyOwner(new IProblemRequestor() { private List<ProblemMarker> l = new ArrayList<>(); @Override public boolean isActive() { // TODO Auto-generated method stub return true; } @Override public void endReporting() { setMarkers(l); } @Override public void beginReporting() { l.clear(); } @Override public void acceptProblem(IProblem problem) { int linenumber = problem.getSourceLineNumber(); int startCol = problem.getSourceStart(); int endCol = problem.getSourceEnd(); if (endCol == startCol) { endCol++; } String description = problem.getMessage(); ProblemMarker marker = new ProblemMarker( problem.isError() ? at.bestsolution.javafx.ide.editor.ProblemMarker.Type.ERROR : at.bestsolution.javafx.ide.editor.ProblemMarker.Type.WARNING, linenumber, startCol, endCol, description); l.add(marker); } }), new NullProgressMonitor()); } catch (JavaModelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } final Document doc = createDocument(unit); editor.setDocument(doc); editor.setContentProposalComputer(new ContentProposalComputer() { @Override public List<Proposal> computeProposals(String line, String prefix, int offset) { final List<Proposal> l = new ArrayList<ContentProposalComputer.Proposal>(); try { unit.codeComplete(offset, new CompletionRequestor() { @Override public void accept(CompletionProposal proposal) { String completion = new String(proposal.getCompletion()); if (!Flags.isPublic(proposal.getFlags())) { return; } if (proposal.getKind() == CompletionProposal.METHOD_REF) { String sig = Signature.toString(new String(proposal.getSignature()), new String(proposal.getName()), null, false, false); StyledString s = new StyledString(sig + " : " + Signature.getSimpleName(Signature .toString(Signature.getReturnType(new String(proposal.getSignature()))))); s.appendString( " - " + Signature.getSignatureSimpleName( new String(proposal.getDeclarationSignature())), Style.colored("#AAAAAA")); l.add(new Proposal(Type.METHOD, completion, s)); } else if (proposal.getKind() == CompletionProposal.FIELD_REF) { StyledString s = new StyledString( completion + " : " + (proposal.getSignature() != null ? Signature.getSignatureSimpleName( new String(proposal.getSignature())) : "<unknown>")); s.appendString( " - " + (proposal.getDeclarationSignature() != null ? Signature.getSignatureSimpleName( new String(proposal.getDeclarationSignature())) : "<unknown>"), Style.colored("#AAAAAA")); l.add(new Proposal(Type.FIELD, completion, s)); } else if (proposal.getKind() == CompletionProposal.TYPE_REF) { if (proposal.getAccessibility() == IAccessRule.K_NON_ACCESSIBLE) { return; } StyledString s = new StyledString( Signature.getSignatureSimpleName(new String(proposal.getSignature()))); s.appendString(" - " + new String(proposal.getDeclarationSignature()), Style.colored("#AAAAAA")); l.add(new Proposal(Type.TYPE, new String(proposal.getCompletion()), s)); } else { System.err.println(proposal); } } }); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return l; } }); editor.setSaveCallback(new Runnable() { @Override public void run() { try { unit.commitWorkingCopy(true, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); try { unit.reconcile(ICompilationUnit.NO_AST, true, null, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.amashchenko.eclipse.strutsclipse.java.SimpleJavaProposalCollector.java
License:Apache License
@Override protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) { if (collectMethods) { if (CompletionProposal.METHOD_REF == proposal.getKind() && Flags.isPublic(proposal.getFlags())) { char[] sig = proposal.getSignature(); char[] declSig = proposal.getDeclarationSignature(); // collect methods suitable for action methods ignoring Object // methods if (sig != null && declSig != null && ACTION_METHOD_SIGNATURE.equals(String.valueOf(sig)) && !OBJECT_SIGNATURE.equals(String.valueOf(declSig))) { return new SimpleJavaCompletionProposal(proposal, getInvocationContext(), getImage(getLabelProvider().createImageDescriptor(proposal))); }/*from ww w. j av a 2 s . co m*/ } } else { // collect packages and classes suitable for actions if ((CompletionProposal.PACKAGE_REF == proposal.getKind() || CompletionProposal.TYPE_REF == proposal.getKind()) && !Flags.isAbstract(proposal.getFlags()) && !Flags.isInterface(proposal.getFlags()) && !Flags.isEnum(proposal.getFlags())) { return new SimpleJavaCompletionProposal(proposal, getInvocationContext(), getImage(getLabelProvider().createImageDescriptor(proposal))); } } return null; }
From source file:com.google.gdt.eclipse.core.contentassist.JavaContentAssistUtilities.java
License:Open Source License
/** * Gets the fully qualified type name from a java completion proposal for * {@link CompletionProposal#TYPE_REF}.//from ww w.ja va2 s . c om * * @param javaProposal the java type reference completion proposal generated * by a code complete * @return the fully qualified type name */ public static String getFullyQualifiedTypeName(CompletionProposal javaProposal) { char[] signature = javaProposal.getSignature(); return String.valueOf(Signature.toCharArray(signature)); }
From source file:com.google.gwt.eclipse.core.editors.java.contentassist.JsniCompletionProposal.java
License:Open Source License
private static String getParamTypesSignature(CompletionProposal proposal) { String[] paramTypes = Signature.getParameterTypes(new String(proposal.getSignature())); // JSNI refs must use /'s to separate qualifier segments return StringUtilities.join(paramTypes, "").replace('.', '/'); }
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// w ww. j av a2s. co m 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:com.microsoft.javapkgsrv.JavaParser.java
License:MIT License
private List<ParamHelpResponse.Signature> ParamHelp(ITypeRoot cu, int cursorPosition) throws JavaModelException { final List<ParamHelpResponse.Signature> proposals = new ArrayList<ParamHelpResponse.Signature>(); cu.codeComplete(cursorPosition, new CompletionRequestor() { @Override/*from w w w . j a v a 2 s . c o m*/ public void accept(CompletionProposal proposal) { try { System.out.println(proposal.toString()); if (proposal.getKind() == CompletionProposal.METHOD_REF) { char[] javaSig = proposal.getSignature(); ParamHelpResponse.Signature.Builder sig = ParamHelpResponse.Signature.newBuilder() .setName(new String(proposal.getName())).setReturnValue( new String(Signature.toCharArray(Signature.getReturnType(javaSig)))); char[][] javaParamTypes = Signature.getParameterTypes(javaSig); for (char[] javaParamType : javaParamTypes) { sig.addParameters(ParamHelpResponse.Parameter.newBuilder() .setName(new String(Signature.toCharArray(javaParamType))).build()); } proposals.add(sig.build()); } } catch (Exception e) { e.printStackTrace(); } } }); return proposals; }
From source file:de.ovgu.featureide.ui.editors.Completion.java
License:Open Source License
@Override public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext arg0, IProgressMonitor arg1) {/*from w ww.jav a 2 s . co m*/ final IFile file = ((IFileEditorInput) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor().getEditorInput()).getFile(); final IFeatureProject featureProject = CorePlugin.getFeatureProject(file); final ArrayList<ICompletionProposal> list = new ArrayList<ICompletionProposal>(); if (featureProject == null) return list; String featureName = featureProject.getFeatureName(file); JavaContentAssistInvocationContext context = (JavaContentAssistInvocationContext) arg0; String prefix = new String(context.getCoreContext().getToken()); // projectStructure = MPLPlugin.getDefault().extendedModules_getStruct(featureProject, featureName); // if (projectStructure == null) { // return list; // } // List<CompletionProposal> l = MPLPlugin.getDefault().extendedModules(projectStructure); List<CompletionProposal> l = MPLPlugin.getDefault().extendedModules_getCompl(featureProject, featureName); for (CompletionProposal curProp : l) { curProp.setReplaceRange(context.getInvocationOffset() - context.getCoreContext().getToken().length, context.getInvocationOffset()); if (curProp.getKind() == CompletionProposal.TYPE_REF) { LazyJavaCompletionProposal prsss = new LazyJavaCompletionProposal(curProp, context); prsss.setStyledDisplayString(new StyledString(new String(curProp.getCompletion()))); prsss.setReplacementString(new String(curProp.getCompletion())); if (prefix.length() >= 0 && new String(curProp.getCompletion()).startsWith(prefix)) { list.add(prsss); } } else if (curProp.getKind() == CompletionProposal.METHOD_REF) { LazyJavaCompletionProposal meth = new LazyJavaCompletionProposal(curProp, context); String displayString = new String(curProp.getCompletion()); displayString = displayString.concat("("); int paramNr = Signature.getParameterCount(curProp.getSignature()); for (int i = 0; i < paramNr; i++) { displayString = displayString .concat(Signature.getParameterTypes(curProp.getSignature()) + " arg" + i); if (i + 1 < paramNr) { displayString = displayString.concat(", "); } } displayString = displayString.concat(") : "); // displayString = displayString.concat(new // String(Signature.getReturnType(curProp.getSignature()))); StyledString methString = new StyledString(displayString); Styler styler = StyledString.createColorRegistryStyler(JFacePreferences.DECORATIONS_COLOR, JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR); // TextStyle style = new // TextStyle(JFaceResources.getDefaultFont(),JFaceResources.getResources().createColor(new // RGB(10, 10, // 10)),JFaceResources.getResources().createColor(new // RGB(0,0,0))); // styler.applyStyles(style); StyledString infoString = new StyledString( new String(" - " + new String(curProp.getName()) + " " + featureName), styler); methString.append(infoString); meth.setStyledDisplayString(methString); meth.setReplacementString(new String(curProp.getCompletion())); if (prefix.length() >= 0 && new String(curProp.getCompletion()).startsWith(prefix)) { list.add(meth); } } else if (curProp.getKind() == CompletionProposal.FIELD_REF) { LazyJavaCompletionProposal field = new LazyJavaCompletionProposal(curProp, context); StyledString fieldString = new StyledString(new String(curProp.getCompletion())); Styler styler = StyledString.createColorRegistryStyler(JFacePreferences.DECORATIONS_COLOR, JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR); StyledString infoString = new StyledString( new String(" - " + new String(curProp.getName()) + " " + featureName), styler); fieldString.append(infoString); field.setStyledDisplayString(fieldString); field.setReplacementString(new String(curProp.getCompletion())); if (prefix.length() > 0 && new String(curProp.getCompletion()).startsWith(prefix)) { list.add(field); } } } return list; }
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;/*w ww . j ava 2 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:org.drools.eclipse.editors.completion.RuleCompletionProcessor.java
License:Apache License
private static void processJavaMethodCompletionProposal(List list, boolean settersOnly, final Collection set, Object o) {//from w w w . j a v a 2s . c o m LazyJavaCompletionProposal javaProposal = (LazyJavaCompletionProposal) o; //TODO: FIXME: this is very fragile as it uses reflection to access the private completion field. //Yet this is needed to do mvel filtering based on the method signtures, IF we use the richer JDT completion Object field = ReflectionUtils.getField(o, "fProposal"); if (field != null && field instanceof CompletionProposal) { CompletionProposal proposal = (CompletionProposal) field; String completion = new String(proposal.getCompletion()); String propertyOrMethodName = null; boolean isSetter = false; boolean isAccessor = false; if (settersOnly) { // get the eventual writable property name for that method name and signature propertyOrMethodName = CompletionUtil.getWritablePropertyName(completion, proposal.getSignature()); // if we got a property name that differs from the orginal method name //then this is a bean accessor isSetter = !completion.equals(propertyOrMethodName); } else { // get the eventual property name for that method name and signature propertyOrMethodName = CompletionUtil.getPropertyName(completion, proposal.getSignature()); //if we got a property name that differs from the orginal method name //then this is a bean accessor isAccessor = !completion.equals(propertyOrMethodName); } // is the completion for a bean accessor? and do we have already some relevant completion? boolean doesNotContainFieldCompletion = DefaultCompletionProcessor .doesNotContainFieldCompletion(propertyOrMethodName, list); if (((settersOnly && isSetter) || (!settersOnly && isAccessor)) && doesNotContainFieldCompletion) { //TODO: craft a better JDTish display name than just the property name RuleCompletionProposal prop = new RuleCompletionProposal(javaProposal.getReplacementOffset(), javaProposal.getReplacementLength(), propertyOrMethodName); prop.setImage(DefaultCompletionProcessor.VARIABLE_ICON); //set high priority such that the completion for accessors shows up first prop.setPriority(1000); set.add(prop); } else if (!settersOnly) { set.add(o); } } }