Example usage for org.eclipse.jdt.core CompletionProposal getName

List of usage examples for org.eclipse.jdt.core CompletionProposal getName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core CompletionProposal getName.

Prototype

public char[] getName() 

Source Link

Document

Returns the simple name of the method, field, member, or variable relevant in the context, or null if none.

Usage

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.fxide.jdt.editor.JDTJavaDocSupport.java

License:Open Source License

public static HtmlString toHtml(CompletionProposal proposal, IJavaProject jProject) throws JavaModelException {
    String content = null;/*w  w  w. j av  a  2 s .  co  m*/
    if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.FIELD_REF) {
        IType jType = getOwnerType(proposal, jProject);
        if (jType != null) {
            IField field = jType.getField(String.valueOf(proposal.getName()));
            if (field != null && field.exists()) {
                try {
                    content = JavadocContentAccess2.getHTMLContent(field, true);
                } catch (CoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    } else if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.METHOD_REF) {
        IType jType = getOwnerType(proposal, jProject);
        if (jType != null) {
            MethodUtil m = new MethodUtil(proposal, jType);
            IMethod method = m.resolve();
            if (method != null && method.exists()) {
                try {
                    content = JavadocContentAccess2.getHTMLContent(method, true);
                    if (content != null) {
                        content = content.replace("<pre><code>",
                                "<pre class=\"prettyprint\"><code class=\"language-java\">");
                    }
                } catch (CoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }

    if (content != null) {
        return new HtmlString("<html><header><style>"
                + ("theme.dark".equals(themeMgr.getCurrentTheme().getId()) ? darkCSS : defaultCSS)
                + "</style><script>" + prettifyJS + "\n</script></header><body onload='PR.prettyPrint();'>"
                + content + "</body></html>");
    }

    return null;
}

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);/*from   w  ww . j ava  2s. co  m*/

    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.SimpleJavaCompletionProposal.java

License:Apache License

public SimpleJavaCompletionProposal(CompletionProposal proposal, JavaContentAssistInvocationContext context,
        Image img) {/*  w w w.j  a va2  s.c om*/
    if (CompletionProposal.METHOD_REF == proposal.getKind()) {
        this.replacementString = String.valueOf(proposal.getName());
    } else {
        this.replacementString = String.valueOf(proposal.getCompletion());
    }
    this.displayString = context.getLabelProvider().createLabel(proposal);
    this.relevance = proposal.getRelevance();
    this.image = img;
}

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  ww  w.j  av  a2s. c o  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  av  a2  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 w  w  .ja  v  a2 s  .  c  o 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;//from  w ww . j ava2  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.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());//from  w  ww. j a v a2s. c o m
    this.proposal = proposal;
    this.setRelevance(proposal.getRelevance());
    this.setTriggerCharacters(ProposalUtils.VAR_TRIGGER);
}

From source file:org.codehaus.groovy.eclipse.codeassist.tests.CompletionTestCase.java

License:Open Source License

protected void validateProposal(CompletionProposal proposal, String name) {
    assertEquals(proposal.getName(), name);
}